bash scripts

This commit is contained in:
Lucas Faber authored and Lucas Vivohost committed 2026-09-14 09:20:47 +02:00
1 parent 7ed4fc67d5
commit 7db38ae9f4
25 files changed
+2375

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
# Directory to start from (default is current directory if none given)
DIR="${1:-.}"
# Optional prefix filter (second argument)
PREFIX="${2:-}"
# JPEG/WEBP compression quality (1–100, lower = more compression)
QUALITY=85
# Target max size
MAXSIZE="1920x1040"
# Recursively find images and compress them
find "$DIR" -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.webp' \) | while read -r FILE; do
BASENAME=$(basename "$FILE")
EXT="${FILE##*.}"
EXT_LOWER=$(echo "$EXT" | tr '[:upper:]' '[:lower:]')
# Skip if prefix is set and filename doesn’t start with it
if [ -n "$PREFIX" ] && [[ "$BASENAME" != "$PREFIX"* ]]; then
continue
fi
echo "Processing: $FILE"
TMPFILE="$(mktemp --suffix=".$EXT_LOWER")"
case "$EXT_LOWER" in
jpg|jpeg)
convert "$FILE" -resize "$MAXSIZE"\> -strip -interlace Plane -quality $QUALITY "$TMPFILE"
;;
png|webp)
convert "$FILE" -resize "$MAXSIZE"\> -strip -quality $QUALITY "$TMPFILE"
;;
esac
mv "$TMPFILE" "$FILE"
done
+63
View File
@@ -0,0 +1,63 @@
#!/bin/bash
USER="lucas"
DEST="~/Downloads"
get_config() {
while [[ ${1:0:1} == - ]]; do
echo "Param: $1"
[[ $1 == -h ]] && {
if [ "$2" == "" ]; then echo "Too few arguments"; usage; exit; fi
HOST="$2"
shift 2;
continue;
};
[[ $1 == -f ]] && {
if [ "$2" == "" ]; then echo "Too few arguments"; usage; exit; fi
file="$2"
shift 2;
continue;
};
[[ $1 == -o ]] && {
if [ "$2" == "" ]; then echo "Too few arguments"; usage; exit; fi
opt="$2"
shift 2;
continue;
};
[[ $1 == -d ]] && {
if [ "$2" == "" ]; then echo "Too few arguments"; usage; exit; fi
DEST="$2"
shift 2;
continue;
};
[[ $1 == -p ]] && {
DEST="~/Videos/.stuff"
shift 1;
continue;
};
[[ $1 == --help ]] && {
usage
exit
};
echo "Parameter $1 discarded"
usage
exit
done
}
usage() {
printf "Usage:
-h <hostname>\tRemote Hostname
-f <filename>\tPath of local file
-o <options>\tGive additional Options
-d <dest>\tChoose other Destination Folder
-p\t\tChange Destination
--help\t\tDisplay Usage\n"
exit
}
get_config "$@"
if [ "${HOST}" == "deluge" ]; then
HOST="serverhost"
USER="deluge-user"
DEST="/home/deluge-user/Downloads/Torrents/"
fi
echo "Copy ${file} to ${HOST}:${DEST}"
scp -r ${opt} "${file}" ${USER}@${HOST}:${DEST}
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
scp lucas@serverhost:/etc/update-motd.d/10-help-text ~/Documents/Dokumente/Dokumente/Projekte/Server/motd.serverhost.10-help-text
scp lucas@raspberry:~/.profile ~/Documents/Dokumente/Dokumente/Projekte/Server/motd.raspberry.profile
rm 0
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/expect -f
#Copy Crontab of raspberry and serverhost
set host "raspberry"
array set user { 0 "root" 1 "lucas"}
set port "1160"
for {set j 0} {$j < 2} {incr j 1} {
spawn ssh -p $port lucas@$host
expect {
"No route to host" {
puts "spawn ssh -p $port SendEnv=TERM lucas@$host failed."
exit 0
}
"Login Sucsessfull" {
if {$user($j)=="root"} {
send "sudo crontab -l >> crontab.buf\r"
expect "lucas: "
send "Gina\&1994\&Nonna\r"
} else {
send "crontab -l >> crontab.buf\r"
}
#expect "$ "
#send "cat crontab.buf\r"
expect "$ "
send "scp -P 3032 crontab.buf lucas@serverhost:~/Documents/Dokumente/Dokumente/Projekte/Server/crontab.$host.$user($j)\r"
expect "$ "
send "rm crontab.buf\r"
puts "crontab.$host.$user($j) created."
}
}
}
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/expect -f
#Copy Crontab of raspberry and serverhost
array set host { 0 "serverhost" 1 "raspberry"}
array set user { 0 "root" 1 "lucas"}
array set port { 0 "3032" 1 "1160"}
for {set i 0} {$i < 2} {incr i 1} {
for {set j 0} {$j < 2} {incr j 1} {
spawn ssh -p $port($i) lucas@$host($i)
expect {
"No route to host" {
puts "spawn ssh -p $port($i) lucas@$host($i) failed."
exit 0
}
"Login Sucsessfull" {
if {$user($j)=="root"} {
send "sudo crontab -l >> crontab.buf\r"
expect "lucas: "
send "Gina\&1994\&Nonna\r"
} else {
send "crontab -l >> crontab.buf\r"
}
#expect "$ "
#send "cat crontab.buf\r"
expect "$ "
send "scp -P 1160 crontab.buf lucas@workhost:~/Documents/Dokumente/Dokumente/Projekte/Server/crontab.$host($i).$user($j)\r"
expect "$ "
send "rm crontab.buf\r"
puts "crontab.$host($i).$user($j) created."
}
}
}
}
+183
View File
@@ -0,0 +1,183 @@
#!/bin/bash
set -e
usage(){
printf "Usage:
-i <file>\tInfo
-av <file>\tChange Audio and Video Codec
-v <file>\tChange Video Codec
-a <file>\tChange Audio Codec
-s <file>\tRemove Subtitles
-rm <file>\tRemove First Audio
-subs <file>\tEmbed subtitles
-dir_down\tDownsize all files in dir to 1920x1080
-find\tFind files from file and resize
-d <file>\tDownsize input video
-filter <file> filter video file\n"
}
if [ $# -lt 2 ]; then
echo "Too few arguments <file> <part of filename to remove>"
else
if [ -d "$2" ] || [ ]; then
echo "Argument is directory"
input_dir=$2
elif [ -f "$2" ]; then
echo "Argument is file"
input=$2
else
echo "Argument $2 doesnt exist"
exit
fi
if [ "$1" == "-av" ]; then
ffmpeg -i "$input" -vcodec mpeg4 -acodec mp3 -preset veryslow -qp 0 "_$input"
elif [ "$1" == "-s" ]; then
ffmpeg -i "$input" -sn -c copy "_$input"
elif [ "$1" == "-a" ]; then
ffmpeg -i "$input" -vcodec copy -acodec mp3 -preset veryslow -qp 0 "_$input"
elif [ "$1" == "-v" ]; then
ffmpeg -i "$input" -vcodec mpeg4 -preset veryslow -qp 0 -acodec copy "_$input"
elif [ "$1" == "-rm" ]; then
ffmpeg -i "$input" -map 0 -map -0:a:0 -c copy -y "_$input";
# mv "_$file" "$file";
echo $input
elif [ "$1" == "-i" ]; then
ffmpeg -i "$input"
elif [ "$1" == "-d" ]; then
ffmpeg -i "$input" -c:v libx264 -crf 27 "${input%%.*}_downsize.${input##*.}"
elif [ "$1" == "-subs" ]; then
#for file in *${input}; do ls "subs/$(echo $file | rev | cut -f2- -d'.' | rev).srt" ; done
for file in *${input}; do
ls "$(echo $file | rev | cut -f2- -d'.' | rev).srt"
ffmpeg -i "$file" -f srt -i "$(echo $file | rev | cut -f2- -d'.' | rev).srt" -c copy -c:s mov_text "_$file"
mv "_$file" "$file"
done
elif [ "$1" == "-frame" ]; then
ffmpeg -ss 00:00:05.01 -i myvideo.avi -frames:v 1 myimage.jpg
elif [ "$1" == "-cut" ]; then
ffmpeg -ss 00:00:02 -i GMT20210112-071517_Vorlesung-_1920x1220.mp4 -to 01:28:49 -c copy output.mp4
elif [ "$1" == "-dir-down" ]; then
echo "Resize all files in ${input_dir}"
if [ ! -d "${input_dir}/comp" ];then
mkdir "${input_dir}/comp"
fi
for file in ${input_dir}/*; do
if [ -f "${file}" ]; then
#echo ${file%.*} ${file##*.} ${file##*/}
ffmpeg -i "${file}" -vf scale=1920x1080 "${input_dir}/comp/${file##*/}" 2>/dev/null 1>&2
fi
done
elif [ "$1" == "-find" ]; then
echo "Find files in ${input_dir}"
if [ ! -d "${input_dir}/comp" ];then
mkdir ${input_dir}/comp
fi
while read -r line; do
file=$(find . -name "$line")
if [ -f "${file}" ]; then
#echo ${file%.*}
#echo ${file%/*}
#echo ${file##*.}
ffmpeg -i "${file}" -vf scale=1920x1080 "${input_dir}/comp/${file##*/}"
fi
done<$3
echo "Converted all files in ${input_dir}"
elif [ "$1" == "-file2mp3" ]; then
codec=$3
find "${input_dir}" -name "*$codec" -print0 | while read -d $'\0' file; do
#echo $file
echo ${file%.*}
#ffmpeg -i "$file" -sample_fmt s16 -ar 48000 "${file%.*}_.flac"< /dev/null
#mv "${file%.*}_.flac" "$file"
ffmpeg -i "$file" -vn -ar 44100 -ac 2 -b:a 192k "${file%.*}.mp3"< /dev/null
#ffmpeg -i "$file" -ab 320k -map_metadata 0 -id3v2_version 3 "${file%.*}.mp3"< /dev/null
done
elif [ "$1" == "-filter" ]; then
#!/usr/bin/env bash
file="$2"
selected_stream="$3"
file_new="${file%.*}_processed.${file##*.}"
if [[ -z "$file" ]]; then
echo "Usage: $0 input_file [audio_stream_index]"
exit 1
fi
# Get list of audio streams
mapfile -t streams < <(
ffprobe -v error -select_streams a \
-show_entries stream=index:stream_tags=language \
-of json "$file" |
jq -r '.streams[] | "\(.index),\(.tags.language // "unknown")"'
)
stream_count=${#streams[@]}
if [[ "$stream_count" -eq 0 ]]; then
echo "No audio streams found."
exit 1
fi
echo "Found $stream_count audio stream(s)."
# If not provided, prompt when multiple exist
if [[ -z "$selected_stream" ]]; then
if [[ "$stream_count" -eq 1 ]]; then
selected_stream="${streams[0]%,*}"
echo "Using only audio stream: $selected_stream"
else
echo "Available audio streams:"
i=0
for s in "${streams[@]}"; do
idx="${s%,*}"
lang="${s#*,}"
echo "[$i] stream_index=$idx language=${lang:-unknown}"
((i++))
done
read -rp "Select audio stream index (ffmpeg stream index): " selected_stream
fi
fi
echo "Processing audio stream: $selected_stream"
ffmpeg -i "$file" \
-map 0:v -c:v copy \
-map 0:a:"$selected_stream" \
-filter_complex "[0:a]highpass=f=100,\
acompressor=threshold=-22dB:ratio=4:attack=10:release=150,\
equalizer=f=2500:t=q:w=1:g=5,\
equalizer=f=4000:t=q:w=1:g=4,\
deesser=i=0.4:f=0.25,\
alimiter=limit=0.95,\
dynaudnorm=f=200:g=15[a]" \
-map "[a]" -c:a libvorbis \
"$file_new"
echo "Done: $file_new"
else
usage
exit
fi
fi
#Uncompatible Videocodecs:
# mpeg4 (DX50 / 0x30355844)
#h264 (High) (avc1 / 0x31637661)
#Uncompatible AUdiocodecs:
#Multiple Audiolines
#Subtitles
# ffmpeg -i $input -sn -vcodec copy -acodec copy
#Keep Audio/Video Settings
# ffmpeg -i $input -acodec copy -vcodec copy
#delete audio trach 0:1
#for file in *avi ; do ffmpeg -i "$file" -map 0:0 -map 0:2 -acodec copy -vcodec copy "New_$file"; mv "New_$file" "$file"; done
#ffmpeg -ss 00:00:00 -i Stargate.mp4 -to 02:09:39 -c copy output.mp4
# Embed Subtitles
#for file in Subs/.*srt; do ffmpeg -i "$file" "$(echo $file | sed 's/srt/ass/g')"; done
#for file in *avi; do ffmpeg -i "$file" -vf ass="Subs/$(echo $file | sed 's/avi/ass/g' | sed 's/S01E/s01e/g')" "New1_$file" ;done
+1
View File
@@ -0,0 +1 @@
find . -type f -name '*conflict**' -exec sh -c 'x="{}"; mv "$x" "$(echo "$x" | sed "s/ (conflicted copy 2025-01-06 190022)//g")" ' \;
+98
View File
@@ -0,0 +1,98 @@
#!/bin/bash
commit1=$1
commit2=$2
dir=$3
patches_dir=$4
CHECK=1
APPLY=1
if [ -z "$commit1" ] || [ -z "$commit2" ] || [ -z "$dir" ]; then
echo "Usage: $0 <commit1> <commit2> <directory> [patches_dir]"
exit 1
fi
# Default patches directory if not provided
if [ -z "$patches_dir" ]; then
patches_dir="$(pwd)/patches"
elif [[ "$patches_dir" != /* ]]; then
patches_dir="$(pwd)/${patches_dir}patches"
fi
if [[ "$commit2" == "HEAD" ]]; then
commit2=""
fi
echo "Diffing $dir from $commit1 to ${commit2:-HEAD}..."
echo "Patches will be saved in: $patches_dir"
# Save current directory
orig_dir="$(pwd)"
# Get git root directory relative to $dir
git_root=$(git -C "$dir" rev-parse --show-toplevel) || { echo "Not a git repo: $dir"; exit 1; }
# Compute relative path of $dir from git root
relative_dir=$(realpath --relative-to="$git_root" "$dir")
echo "Relative path of $dir from git root: $relative_dir"
# Change to git root directory
cd "$git_root" || { echo "Failed to cd to git root of $dir"; exit 1; }
echo "Go to $git_root"
mkdir -p "$patches_dir"
# Load list of changed files into an array
mapfile -t diff_files < <(git diff --name-only $commit1..$commit -- $relative_dir )
for file in "${diff_files[@]}"; do
git diff $commit1..$commit2 --stat -- "$file"
done
for file in "${diff_files[@]}"; do
echo $file
git diff $commit1..$commit2 -- "$file" > "$patches_dir/$(basename "$file").patch"
done
for patch in "$patches_dir"/*.patch; do
echo $patch
for patch in "$patches_dir"/*.patch; do
sed -i 's|trixel3_software/||g' "$patch"
done
done
# Get git root directory relative to $dir
git_root_patches_dir=$(git -C "$patches_dir" rev-parse --show-toplevel) || { echo "Not a git repo: $patches_dir"; exit 1; }
# Compute relative path of $dir from git root
relative_dir_patches_dir=$(realpath --relative-to="$git_root_patches_dir" "$patches_dir")
echo "Relative path of $patches_dir from git root: $relative_dir_patches_dir"
# Change to git root directory
cd "$git_root_patches_dir" || { echo "Failed to cd to git root of $patches_dir"; exit 1; }
echo "Go to $git_root_patches_dir"
if [[ $CHECK -eq 1 ]]; then
# check patches
echo "CHECK Patches"
for patch in "$patches_dir"/*.patch; do
echo $patch
git apply --check "$patch"
done
fi
if [[ $APPLY -eq 1 ]]; then
# apply patches
echo "APPLY Patches"
for patch in "$patches_dir"/*.patch; do
if git apply "$patch"; then
echo "Applied $patch successfully."
rm "$patch"
else
echo "Failed to apply $patch. Skipping."
fi
done
fi
# Return to original directory
cd "$orig_dir" || exit 1
+42
View File
@@ -0,0 +1,42 @@
#!/bin/bash
if [ "$2" == "-c" ];then
blue="\e[34m"
red="\e[31m"
norm="\e[0m"
else
blue=""
red=""
norm=""
fi
declare -a hosts=("serverhost" "workhost" "quiethost" "localhost")
if [ "$#" -eq 0 ];then
printf "Arguments: hosts, netw\n"
fi
if [ "$1" == "hosts" ];then
for host in "${hosts[@]}"; do
ping -c 2 -W 1 $host > /dev/null
if [ $? -eq 0 ]; then
printf "%s\t\t[$blue UP$norm ]\n" "$host" | sed "s/localhost/$(hostname)/g"
else
printf "%s\t\t[$red DOWN$norm ]\n" "$host"
fi
done
elif [ "$1" == "netw" ];then
if [ "$(ifconfig | grep -A2 eth0 | grep inet)" != "" ]; then
if="eth0"
elif [ "$(ifconfig | grep -A2 wlan0 | grep inet)" != "" ]; then
if="wlan0"
fi
#netw="$(ifconfig $if | grep -m1 -o -P '(?<=inet ).*(?= netmask)' | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.')"
netw="$( ifconfig $if | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.' | grep -m1 -v 255)"
for i in {1..254}; do
ping -c 1 -W 1 $netw$i > /dev/null
if [ $? -eq 0 ]; then
# hostname="$(ssh 10.0.0.$i hostname)"
# if [ ! $? -eq 0 ]; then
hostname="$(nbtscan 10.0.0.$i | grep -A1 "\-\-\-\-\-" | sed 's/ */ /g' | cut -d' ' -f2 | grep '[A-Za-z]')"
# fi
printf "10.0.0.%s\t[$blue UP$norm ]\t%s\n" "$i" "$hostname"
fi
done
fi
+105
View File
@@ -0,0 +1,105 @@
#!/bin/bash
NEW_TYPE="png"
TYPE_ARR=("jp*g" "tif" "webp" "png")
file=""
folder=""
usage(){
printf "Usage:
-f <file>\tConvert single File
-d <dir>\tConvert all files in Dir
-t <type>\tSet new Type
-h\t\tDisplay this\n"
}
img_convert() {
IMG="$1"
IMG_NEW="$IMG"
for type in ${TYPE_ARR[@]}; do
IMG_NEW="$(echo ${IMG_NEW} | sed 's/\.'"${type}"'/.'"${NEW_TYPE}"'/g')"
done
if [ ! -f "${IMG}" ]; then
echo "${IMG} not found"
return
fi
if [ "${IMG}" == "${IMG_NEW}" ]; then
echo "${IMG} and ${IMG_NEW} are the same"
return
fi
echo "Convert ${IMG} ${IMG_NEW}"
convert -quiet "${IMG}" "${IMG_NEW}" >> /dev/null
rm "${IMG}"
}
folder_magic(){
IMG_FOLDER="$1"
echo "Convert Imgs in ${IMG_FOLDER}"
IMG_ARR=()
IMG_ARR_NEW=()
IFS=$'\n'; set -f
for type in ${TYPE_ARR[@]}; do
if [[ "${type}" != "${NEW_TYPE}" ]]; then
IMG_ARR+=($(find ${IMG_FOLDER} -name "*${type}"))
IMG_ARR_NEW+=($(find ${IMG_FOLDER} -name "*${type}" | sed 's/\.'"${type}"'/.'"${NEW_TYPE}"'/g'))
fi
done
for ((i=0;i<${#IMG_ARR[@]};i++)); do
echo "Convert ${IMG_ARR[$i]} ${IMG_ARR_NEW[$i]}"
convert -quiet "${IMG_ARR[$i]}" "${IMG_ARR_NEW[$i]}" >> /dev/null
rm "${IMG_ARR[$i]}"
done
}
get_config() {
if [ $# -eq 0 ] || [ ${1:0:1} != - ]; then
echo "Too few Arguments"
usage
exit
fi
while [[ ${1:0:1} == - ]]; do
echo "Param: $1"
[[ $1 == -h ]] && {
usage
exit
};
[[ $1 == -f ]] && {
if [ $# -lt 2 ]; then
echo "Too few Arguments"
usage
exit
fi
file="$2";
shift 2;
continue;
}
[[ $1 == -d ]] && {
if [ $# -lt 2 ]; then
echo "Too few Arguments"
usage
exit
fi
folder="$2";
shift 2;
continue;
}
[[ $1 == -t ]] && {
if [ $# -lt 2 ]; then
echo "Too few Arguments"
usage
exit
fi
NEW_TYPE="$2";
shift 2;
continue;
}
echo "Parameter $1 discarded"
shift 1;
done
}
get_config "$@"
if [[ "${file}" != "" ]]; then
img_convert "${file}"
fi
if [[ "${folder}" != "" ]]; then
folder_magic "${folder}"
fi
+31
View File
@@ -0,0 +1,31 @@
#!/bin/bash
PUB_IP=$(wget -T 5 -qO- ifconfig.co)
printf "User: %s\n" "$(whoami)"
if [ "${PUB_IP}" != "" ]; then
LOC=$(wget -T 3 -qO- ifconfig.co/country)
CITY=$(wget -T 3 -qO- ifconfig.co/city)
printf "%s\t%s\t%s\n" "${PUB_IP}" "${LOC}" "${CITY}"
else
printf "No Connection\n"
fi
if [ "$(grep deluge-user /etc/passwd)" != "" ]; then
printf "User: deluge-user\n"
PUB_IP=$(sudo /home/lucas/scripts/deluge_user_cmd.sh wget -T 3 -qO- ifconfig.co)
if [ "${PUB_IP}" == "" ]; then
PUB_IP=$(sudo /home/lucas/scripts/deluge_user_cmd.sh curl --connect-timeout 3 https://ipinfo.io/ip)
fi
if [ "${PUB_IP}" != "" ]; then
LOC=$(sudo /home/lucas/scripts/deluge_user_cmd.sh wget -T 3 -qO- ifconfig.co/country)
if [ "${LOC}" == "" ]; then
LOC=$(sudo /home/lucas/scripts/deluge_user_cmd.sh curl --connect-timeout 3 https://ipinfo.io/country 2>>/dev/null)
fi
CITY=$(sudo /home/lucas/scripts/deluge_user_cmd.sh wget -T 3 -qO- ifconfig.co/city)
if [ "${CITY}" == "" ]; then
CITY=$(sudo /home/lucas/scripts/deluge_user_cmd.sh curl --connect-timeout 3 https://ipinfo.io/city 2>>/dev/null)
fi
printf "%s\t%s\t%s\n" "${PUB_IP}" "${LOC}" "${CITY}"
else
printf "No Connection\n"
fi
fi
+4
View File
@@ -0,0 +1,4 @@
#i!/bin/bash
DISPLAY=:0 sudo -u "$2" notify-send "$1"
echo "$1" > /home/$2/asd
+37
View File
@@ -0,0 +1,37 @@
#!/bin/bash
#echo "TERM: $TERM"
if [ "${TERM}" == "" ] || [ "${TERM}" == "dumb" ]; then
TERM="xterm-256color"
fi
function stars {
width=$(tput cols)
for ((counter = 1; counter < $width; counter++)); do
# /usr/bin/printf "o"
echo -e "*\c"
done
}
function print_string {
width=$(($(tput cols)/2-${#1}/2))
for ((counter = 1; counter < $width; counter++)); do
printf " "
done
printf "%s\n" "$1"
}
HOSTNAME="$HOSTNAME"
time=$(date +%H)
if [ $time -le 12 ]; then
welcomestr="Good Mornig"
elif [ $time -gt 12 ] && [ $time -lt 19 ]; then
welcomestr="Good Afternoon"
elif [ $time -gt 19 ]; then
welcomestr="Good Evening"
fi
stars
printf "\n"
print_string "Server: $HOSTNAME"
stars
printf "\n%s %s!\n\n" "$welcomestr" "$(whoami)"
printf "%s\n" "$(date +"%A, %d %B %Y, %T")"
printf "Uptime: %s\n" "$(uptime)"
cat /home/lucas/.bash_motd
+153
View File
@@ -0,0 +1,153 @@
#!/bin/bash
tab() {
if [ $# -lt 2 ]; then printf "\t"; fi
for ((i_tab=${#2};i_tab<$1;i_tab++)); do printf " "; done
}
if [ "$1" != "-o" ]; then
exec 1>/home/lucas/.bash_motd_buff
fi
if [ "$(/sbin/ip -br link | grep bond0)" != "" ];then
if1="bond0"
ip1="$(/sbin/ip -br link bond0 | grep -o "10\.0\.0\.103")"
if2="$(cat /proc/net/bonding/bond0 | grep 'Currently Active Slave:' | grep -o 'wlan0\|eth0')"
if [ "if2" == "" ]; then
printf "*******************************WTF? No bond IF2?*******************************\n"
fi
ip2="$(ip addr show $if2 | grep -o '10\.0\.0\.27\|10\.0\.0\.103')"
printf "%s:\t%s\t" "$if1" "$ip1"
else
ifx=( $(ip -br link | cut -f1 -d' ' | grep -v lo) )
for i in ${!ifx[@]}; do
ipx[$i]="$(ip addr show ${ifx[$i]} | grep -m1 -o -P '(?<=inet ).*(?=/24 brd)')"
if [ "${ipx[$i]}" == "" ]; then
ipx[$i]="----------"
fi
done
printf "%s:\t%s\t" "${ifx[0]}" "${ipx[0]}"
fi
ip="$(wget -T 5 -qO- ifconfig.co)"
location="$(wget -T 5 -qO- ifconfig.co/country)"
city=$(wget -T 5 -qO- ifconfig.co/city)
if [ "${ip}" == "" ]; then
ip="IP empty"
elif [ "${location}" == "" ]; then
location="No LOC"
elif [ "${city}" == "" ]; then
city="No City"
fi
printf "\tUser: $(whoami)"; tab 14 "$(whoami)"; printf "$ip"; tab 17 "$ip"; printf "$location\n"
if [ "$HOSTNAME" == "quiethost" ]; then
for ((i=1; i<${#ifx[@]}; i++)); do
printf "%s:\t%s" "${ifx[$i]}" "${ipx[$i]}"
if [ $i -eq 1 ]; then printf "\t\t\t\t\t\t${city}\n";
else printf "\n";
fi
done
fi
if [ "$HOSTNAME" == "raspberry" ]; then
printf "%s:\t%s\t\t" "${ifx[1]}" "${ipx[1]}"
fi
if [ "$HOSTNAME" == "quiethost_dep" ]; then
printf "WallpaperChanger: "
if [ "$(ps -elf | grep -v grep | grep wallpaperChanger.sh)" = "" ]; then
printf "[ OFF ]\t\t"
else
time="$(ps -elf | grep -v grep | grep wallpaperChanger.sh | sed 's/ \+/ /g' | cut -f18 -d' ')"
printf "[ ON ]\t%s min\t" "$time"
fi
printf "\n"
KURS1="$(wget -qO- https://www.fondsprofessionell.at/fonds/details/fondsName/Amundi-Komfort-Invest-traditionell-T/ISIN/AT0000801071/fondsID/FU_80107/)"
KURS2="$(wget -qO- https://www.fondsprofessionell.at/fonds/details/ISIN/AT0000A2L443/fondsID/FU_100076607/)"
KURS3="$(wget -qO- https://www.fondsprofessionell.at/fonds/details/fondsName/Amundi-CPR-Climate-Action-T/ISIN/AT0000A28YU4/fondsID/FU_100070247/)"
DATE1="$(printf "%s\n" "${KURS1}" | sed 's/<\/b>/<\/b>\n/g' | grep -o -P '(?<=<b>NAV am ).*(?= </b>)')"
DATE2="$(printf "%s\n" "${KURS2}" | sed 's/<\/b>/<\/b>\n/g' | grep -o -P '(?<=<b>NAV am ).*(?= </b>)')"
DATE3="$(printf "%s\n" "${KURS3}" | sed 's/<\/b>/<\/b>\n/g' | grep -o -P '(?<=<b>NAV am ).*(?= </b>)')"
KURS_EUR1=$(printf "%s\n" "${KURS1}" | sed 's/<\//\n<\//g' | grep -A2 "NAV am" | grep -o -P '(?<=<td> ).*(?=EUR)' | sed 's/ //g' | sed 's/,/./g')
KURS_PER1=$(printf "%s\n" "${KURS1}" | sed 's/<\//\n<\//g' | grep -A3 "Änderung (%)" | grep -o -P '(?<=<td> ).*(?=%\))')
printf "Traditionell:\t%s EUR" "${KURS_EUR1}"; tab 8 "${KURS_EUR1}"; printf "%s%%)\t${DATE1}\n" "${KURS_PER1}"
KURS_EUR2=$(printf "%s\n" "${KURS2}" | sed 's/<\//\n<\//g' | grep -A2 "NAV am" | grep -o -P '(?<=<td> ).*(?=EUR)' | sed 's/ //g' | sed 's/,/./g')
KURS_PER2=$(printf "%s\n" "${KURS2}" | sed 's/<\//\n<\//g' | grep -A3 "Änderung (%)" | grep -o -P '(?<=<td> ).*(?=%\))')
printf "Dynamisch:\t%s EUR" "${KURS_EUR2}"; tab 8 "${KURS_EUR2}"; printf "%s%%)\t${DATE2}\n" "${KURS_PER2}"
KURS_EUR3=$(printf "%s\n" "${KURS3}" | sed 's/<\//\n<\//g' | grep -A2 "NAV am" | grep -o -P '(?<=<td> ).*(?=EUR)' | sed 's/ //g' | sed 's/,/./g')
KURS_PER3=$(printf "%s\n" "${KURS3}" | sed 's/<\//\n<\//g' | grep -A3 "Änderung (%)" | grep -o -P '(?<=<td> ).*(?=%\))')
printf "Climate:\t%s EUR" "${KURS_EUR3}"; tab 8 "${KURS_EUR3}"; printf "%s%%)\t${DATE3}\n" "${KURS_PER3}"
#bash "/home/lucas/Documents/Dokumente/Projekte/Server/scripts/serverhost/update_BA_Data.sh" "${KURS_EUR1}" "${KURS_EUR2}" "${KURS_EUR3}"
fi
if [ "$HOSTNAME" == "raspberry_dep" ]; then
printf "MoistSens: "
if [ "$(pgrep recieveMS)" = "" ]; then
printf "[ OFF ]\t"
else
printf "[ ON ]\t"
fi
printf "BTServer: "
if [ "$(pgrep BTserver)" = "" ]; then
printf "[ OFF ]\n"
else
printf "[ ON ]\n"
fi
fi
if [[ "$HOSTNAME" = "serverhost" ]] || [[ "$HOSTNAME" = "workhost" ]]; then
printf "OpenVPN: "
if [ "$(pgrep openvpn)" = "" ]; then
printf "[ OFF ]\t"
else
printf "[ ON ] PID: %s" "$(pgrep openvpn | tr '\n' ' ')"
fi
if [[ "$HOSTNAME" = "serverhost" ]]; then
printf "\tUser: deluge-user"; tab 14 "deluge-user";
ip=$(sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh wget -T 2 -qO- ifconfig.co)
if [ "$ip" != "" ]; then
location=$(sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh wget -T 2 -qO- ifconfig.co/country)
# city=$(sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh wget -T 2 -qO- ifconfig.co/city)
printf "$ip"; tab 17 "$ip"; printf "$location\n"
else
printf "No Connection\n"
fi
else
printf "\n"
fi
fi
printf "\n"
SPACE_TAB=18
mem="$(free -h | awk 'NR==2 { printf "Total: %sB,\tUsed: %sB,\tFree: %sB",$2,$3,$7; }')"
printf "Memory:"; tab ${SPACE_TAB} "Memory:"; printf "$mem\n";
IFS=$'\n'; set -f
data_dev=($(df -h | grep "/dev/sd[a-f]" | sed 's/ \+/ /g' | cut -f1 -d' '))
unset IFS; set +f
osspace=""
for ((i=0;i<${#data_dev[@]};i++)); do
device="$(df -h "${data_dev[$i]}" | sed 's/ \+/ /g' | tail -1 | cut -f6 -d' ')"
if [ "$device" != "/" ]; then
device="/$(echo $device | rev | cut -f1 -d'/' |rev):"
else
device="/root:"
fi
if [[ "$(echo $device | grep "efi")" != "" ]] || [[ "$(echo $device | grep "win10")" != "" ]]; then continue; fi
osspace="$(df -h "${data_dev[$i]}" | awk 'NR==2 { printf "Total: %sB,\tUsed: %sB,\tFree: %sB\t%s used\n",$2,$3,$4,$5; }')"
printf "%s" "${device}"
tab ${SPACE_TAB} "${device}";
printf "%s\n" "$osspace"
done
tabs -8
if [[ "$HOSTNAME" = "raspberry" ]]; then
temp="$(/opt/vc/bin/vcgencmd measure_temp | cut -c "6-9") ºC"
temp="Temperature...: $temp"
echo $temp
fi
if [[ "$HOSTNAME" = "workhost" ]] || [[ "$HOSTNAME" = "raspberry" ]] && [[ -f /etc/motd ]]; then
cat /etc/motd
fi
if [[ "$HOSTNAME" = "serverhost" ]] || [[ "$HOSTNAME" = "quiethost" ]]; then
sudo /etc/update-motd.d/90-updates-available
if [ -f /etc/motd ]; then cat /etc/motd; fi
sudo /etc/update-motd.d/91-release-upgrade
sudo /etc/update-motd.d/98-fsck-at-reboot
sudo /etc/update-motd.d/98-reboot-required
fi
if [[ "$1" != "-o" ]] && [[ -f /home/lucas/.bash_motd_buff ]]; then
mv /home/lucas/.bash_motd_buff /home/lucas/.bash_motd
fi
+13
View File
@@ -0,0 +1,13 @@
#!/bin/bash
if [ $# -lt 2 ]; then
echo "Missing Arguments rename <OldName> <NewName> (<FilesRegex>)"
exit 0
fi
NewName=$2
OldName=$1
FileRegex=$3
for file in $(ls | grep .*$FileRegex.*); do
mv $file "$(echo $file | sed 's/'"$OldName"'/'"$NewName"'/g')"
done
# for file in $(ls | grep Big_.*_SuicideGirls); do echo $(echo $file | sed 's/Big_\(.*\)_Suicide/Big_SuicideGirls_\1/g'); done
+396
View File
@@ -0,0 +1,396 @@
#!/bin/bash
SR=false
CONFIRM=false
DRY_RUN=false
REPAIR_ONLY=false
FILES_ONLY=false
DIR_ONLY=false
DELETE=false
CAPITALIZE=false
GOTO_PATH=false
FILE_PATH=false
FILE=""
container=("mpg" "avi" "mkv" "mp4" "m4v" "srt")
DAMAGE=("\.\." "-\." "\.-" "\(\." "\.\." "-" "_" "\.\[" "\.\(" " " "\[" " \." "\]" "(" "(\.")
unwanted_filename_parts=("TV\ Series" "x264" "Complete" "10bit" "\[.*\]" "320kbps" "WS" "AC3" "iNT" "NF\.WEB" "bdrip" "RERIP" "DUAL-" "(ENG" "\[320\]" "rus.eng" "LostFilm" "readnfo" "800p" "BluRay" "Jasprr" "KORSUB" "576p" "720p" "1080p" "1080P" "720P" "WEB" "AMZN" "internal" "iNTERNAL" "HDTV" "KILLERS" "web" "hdtv" "REAL" "DVD" "dvd" "PDTV" "PROPER" "BDRip" "HDRip" "DvD" "480" "INTERNAL" "REPACK" "\[m00tv\]" "\[VFUA\]" "\[PiXTV\]" "\[GOTHiC\]" "\[RiVER\]" "EXTENDED" "SWESUB" "DVB" "XviD" "\[FoV\]" "repack" "BRRip" "UEE" "BrRip" "brrip" "\[SubRip" "UNRATED" "Directors Cut")
KNOWN_SHIT_FILES=("www\.YTS*" "Torrent downloaded*\.txt" "Read Me.txt" "WWW.YTS.RE.jpg" "*\.nfo" "RARBG\.com\.txt" "RARBG\.txt" "RARBG\.COM*" "WWW\.YIFY-TORRENTS\.COM\.jpg" "RARBG_DO_NOT_MIRROR\.exe" "Uploaded\ by*")
get_config() {
while [[ ${1:0:1} == - ]]; do
echo "Param: $1"
[[ $1 == -r ]] && {
SR=true
if [ "$2" == "" ] || [ "$3" == "" ]; then echo "Too few arguments"; usage; exit; fi
search="$2"
replace="$3"
shift 3;
continue;
};
[[ $1 == -path ]] && {
GOTO_PATH=true
if [ "$2" == "" ] ; then echo "Too few arguments"; usage; exit; fi
GOTO="$2"
if [ ! -d "${GOTO}" ]; then
echo "${GOTO} no valid Path"
exit 1;
fi
shift 2;
continue;
};
[[ $1 == -file ]] && {
FILE_PATH=true
if [ "$2" == "" ] ; then echo "Too few arguments"; usage; exit; fi
FILE="$2"
if [ ! -f "${FILE}" ]; then
echo "${FILE} no valid File"
exit 1;
fi
shift 2;
continue;
};
[[ $1 == -help ]] && {
usage;
exit;
};
[[ $1 == -cap ]] && {
CAPITALIZE=true
shift 1;
continue;
};
[[ $1 == -conf ]] && {
CONFIRM=true
shift 1;
continue;
};
[[ $1 == -dry ]] && {
DRY_RUN=true;
shift 1;
continue;
};
[[ $1 == -dir ]] && {
DIR_ONLY=true;
shift 1;
continue;
};
[[ $1 == -files ]] && {
FILES_ONLY=true;
shift 1;
continue;
};
[[ $1 == -repair ]] && {
REPAIR_ONLY=true;
shift 1;
continue;
};
[[ $1 == -l ]] && {
find . -name "*${DAM}mkv" -o -name "*${DAM}mp4" -o -name "*${DAM}avi" -o -name "*${DAM}m4v" -o -name "*${DAM}srt"
exit 0;
};
[[ $1 == -del ]] && {
DELETE=true;
shift 1;
continue;
};
echo "Parameter $1 discarded"
usage
exit
done
}
usage() {
printf "Usage:
-r <search> <replace>\tSearch/Replace Phrase
-conf\t\tConfirm before moving
-dry\t\tOnly perform a Dry Run
-files\t\tRename Files in Parh(.)
-file <file>\tRename single File
-dir\t\tRename Directories
-path <path>\tDefine Searchdirectory(Default .)
-repair\t\tRepair broken Filenames
-del\t\tDelete Garbage Torrent add files
-l\t\tList Files
-help\t\tDisplay this\n"
}
capitalize() {
if [[ "$GOTO_PATH" == "true" ]]; then
dir="${PWD##*/}"
parent="${PWD%/*}"
fi
echo $dir
echo "Capitalze Files"
IFS=$'\n'; set -f
FILE_ARR=()
if [ "$1" == "" ]; then
IFS=$'\n'; set -f
for cont in ${container[@]}; do
FILE_ARR=("${FILE_ARR[@]}" $(find . -type f -name "*${cont}"))
done
else
FILE_ARR=("$1")
fi
FILE_ARR+=("$dir")
SEP='[ 0123456789/.,\-_:;#$&()]'
for f in "${FILE_ARR[@]}"; do
dir=$(dirname -- "$f")
filename=$(basename -- "$f")
# ---- function to capitalize a name ----
capitalize() {
local name="$1"
# lowercase
name=$(echo "$name" | sed 's/[A-Z]/\L&/g')
# capitalize first letter
name=$(echo "$name" | sed -E 's/^([a-z])/\u\1/')
# capitalize after separators
name=$(echo "$name" | sed -E "s@(${SEP})([a-z])@\1\u\2@g")
echo "$name"
}
# ---- process directories ----
new_dir=""
IFS='/' read -ra parts <<< "$dir"
# Preserve absolute paths
if [[ "$dir" == /* ]]; then
new_dir="/"
fi
for part in "${parts[@]}"; do
# Skip empty parts and "."
[[ -z "$part" || "$part" == "." ]] && continue
cap_part=$(capitalize "$part")
if [[ "$new_dir" == "" || "$new_dir" == "/" ]]; then
new_dir="${new_dir}${cap_part}"
else
new_dir="$new_dir/$cap_part"
fi
done
# ---- process filename ----
if [[ "$filename" == *.* ]]; then
base="${filename%.*}"
ext="${filename##*.}"
new_base=$(capitalize "$base")
new_filename="$new_base.$ext"
else
new_filename=$(capitalize "$filename")
fi
# ---- build paths ----
old_path="${f#./}"
new_path="$new_dir/$new_filename"
# ---- create directories if needed ----
mkdir -p -- "$new_dir"
# ---- move if different ----
if [[ "$old_path" != "$new_path" ]]; then
echo "$old_path -> $new_path"
if [[ "$old_path" == "${PWD##*/}" ]]; then
mv -- "../$old_path" "../$new_path"
cd "../$new_path"
else
mv -- "$old_path" "$new_path"
fi
fi
done
}
repair_damage() {
IFS=$'\n'; set -f
for DAM in ${DAMAGE[@]}; do
echo "Damage: ${DAM}"
for file_orig in $(find . -name "*${DAM}mkv" -o -name "*${DAM}mp4" -o -name "*${DAM}avi" -o -name "*${DAM}m4v" -o -name "*${DAM}srt"); do
file_path=$(echo ${file_orig} | rev | cut -f2- -d'/' | rev)
file="$(echo $file_orig | rev | cut -f1 -d'/' | rev | sed 's/'"${DAM}"'srt/.srt/g' | sed 's/'"${DAM}"'avi/.avi/g'| sed 's/'"${DAM}"'mkv/.mkv/g' | sed 's/'"${DAM}"'mp4/.mp4/g')"
echo "${file_orig} ${file_path}/${file}"
mv "${file_orig}" "${file_path}/${file}"
done
done
DAM=(" " "\.\." "__" "\[pseudo\]\.")
COR=(" " "\." "_" "")
for ((i = 0 ; i < ${#DAM[@]} ; i++)); do
echo "Damage: ${DAM[$i]}"
for file_orig in $(find . -name "*.mkv" -o -name "*.mp4" -o -name "*.avi" -o -name "*.m4v" -o -name "*.srt" | grep "${DAM[$i]}"); do
file_path=$(echo ${file_orig} | rev | cut -f2- -d'/' | rev)
file="$(echo ${file_orig} | rev | cut -f1 -d'/' | rev | sed 's/'"${DAM[$i]}"'/'"${COR[$i]}"'/g')"
echo "${file_orig} ${file_path}/${file}"
mv "${file_orig}" "${file_path}/${file}"
done
done
for ((i = 0 ; i < ${#DAM[@]} ; i++)); do
echo "Damage: ${DAM[$i]}"
for file_orig in $(find . -type d | grep "${DAM[$i]}"); do
file_path=$(echo ${file_orig} | rev | cut -f2- -d'/' | rev)
file="$(echo ${file_orig} | rev | cut -f1 -d'/' | rev | sed 's/'"${DAM[$i]}"'/'"${COR[$i]}"'/g')"
if [ "$(find ${file_path}/${file} -name *mkv -o -name *mp4 -o -name *avi)" == "" ]; then
echo "${file_path}/${file} is no Media Directory"
continue
fi
echo "${file_orig} ${file_path}/${file}"
mv "${file_orig}" "${file_path}/${file}"
done
done
unset IFS; set +f
}
rename_files() {
echo "Rename Files"
IFS=$'\n'; set -f
FILE_ARR=()
if [ "$1" == "" ]; then
IFS=$'\n'; set -f
for cont in ${container[@]}; do
FILE_ARR=("${FILE_ARR[@]}" $(find . -type f -name "*${cont}"))
done
else
FILE_ARR=("$1")
fi
# echo ${FILE_ARR[*]}
# echo "Rename?"
# if [ "$ans" != "y" ]; then
# exit
# fi
i=0
for file_orig in ${FILE_ARR[@]}; do
file=$(echo ${file_orig} | rev | cut -f1 -d'/' | rev)
file="$(echo "$file" | sed 's/ /./g')"
file="$(echo "$file" | sed 's/s\([0-9]\{2\}\)e/S\1E/g')"
file_path=$(echo ${file_orig} | rev | cut -f2- -d'/' | rev)
for cont in ${container[@]}; do
for part in ${unwanted_filename_parts[@]}; do
file_new="$(echo "$file" | sed "s/${part}.*\.${cont}/\.${cont}/g")"
if [ ${#file_new} -gt 10 ]; then
file=${file_new}
else
echo "Filename without unwanted part too short: $file, $part"
file_new="$(echo "$file" | sed "s/${part}//g")"
if [ ${#file_new} -gt 10 ]; then
file=${file_new}
else
echo "Filename without unwanted part too short: $file, $part"
fi
fi
done
done
if [ "${file:0:1}" == '.' ]; then
file=${file:1:${#file}}
fi
if [ "${SR}" == "true" ] && [ "${search}" != "" ] && [ "${replace}" != "" ]; then
file="$(echo "$file" | sed "s/${search}/${replace}/g")"
fi
if [ "${file_orig}" != "${file_path}/${file}" ]; then
if [ "${DRY_RUN}" == "false" ]; then
echo "${file_orig} ${file_path}/${file}"
if [ "${CONFIRM}" == "true" ]; then
read
fi
mv -i "${file_orig}" "${file_path}/${file}"
else
echo "Dry rename ${file_orig} ${file_path}/${file}"
fi
fi
((i++))
STR="$i/${#FILE_ARR[@]}"
printf "%s" "${STR}"
echo -en "\033[${#STR}D"
done
unset IFS; set +f
}
rename_directories() {
echo "Rename Directories"
IFS=$'\n'; set -f
if [ "$1" == "" ]; then
FILE_ARR=($(find . -type d))
else
FILE_ARR=($(find "$1" -type d))
fi
i=0
if [[ "$GOTO_PATH" == "true" ]]; then
dir="${PWD/}"
FILE_ARR+=("$dir")
fi
#echo "Rename?"
#read -n 10 ans
#if [ "$ans" != "y" ]; then
# exit
#fi
for file_orig in ${FILE_ARR[*]}; do
if [ "${file_orig}" == '.' ]; then
continue
fi
echo ${file_orig}
file="$(echo ${file_orig} | rev | cut -f1 -d'/' | rev)"
file="$(echo "$file" | sed 's/\./ /g')"
file_path=$(echo ${file_orig} | rev | cut -f2- -d'/' | rev)
for part in ${unwanted_filename_parts[@]}; do
file="$(echo "$file" | sed "s/${part}//g")"
done
if [ "${SR}" == "true" ] && [ "${search}" != "" ] && [ "${replace}" != "" ]; then
file="$(echo "$file" | sed "s/${search}/${replace}/g")"
fi
if [[ "${file:${#file}-1:1}" == " " ]] || [[ "${file:${#file}-1:1}" == '.' ]]; then
file="${file:0:${#file}-1}"
fi
if [ "${file:0:1}" == ' ' ]; then
file=${file:1:${#file}}
fi
if [ "${file_orig}" != "${file_path}/${file}" ]; then
if [ "${DRY_RUN}" == "false" ]; then
echo "${file_orig} ${file_path}/${file}"
if [ "${CONFIRM}" == "true" ]; then
read
fi
mv "${file_orig}" "${file_path}/${file}"
if [[ "${file_orig}" == "${PWD}" ]]; then
cd "${file_path}/${file}"
fi
else
echo "${file_orig} ${file_path}/${file}"
fi
fi
((i++))
STR="$i/${#FILE_ARR[@]}"
printf "%s" "${STR}"
echo -en "\033[${#STR}D"
done
unset IFS; set +f
}
delete_shit() {
IFS=$'\n'; set -f
for shit in ${KNOWN_SHIT_FILES[@]}; do
printf "Shit: %s\n" "${shit}"
find . -name "${shit}"
find . -name "${shit}" -exec rm {} \;
done
}
if [ $# -lt 1 ]; then
echo "At least 1 Argument needed"
usage
exit
fi
get_config "$@"
if [ "${GOTO_PATH}" == "true" ]; then
cd "${GOTO}"
fi
if [ "${DIR_ONLY}" == "true" ]; then
rename_directories "${GOTO}"
fi
printf "\n"
if [ "${FILES_ONLY}" == "true" ]; then
rename_files "${FILE}"
fi
printf "\n"
if [ "${REPAIR_ONLY}" == "true" ]; then
repair_damage
fi
if [ "${CAPITALIZE}" == "true" ]; then
capitalize
fi
if [ "${DELETE}" == "true" ]; then
delete_shit
fi
+23
View File
@@ -0,0 +1,23 @@
#!/bin/bash
DEV=$(sudo parted -l | grep "ATA ST1000LM014-1EJ1" -A1 | grep Disk | grep -o "sd[a-f]")
EFI=$(sudo parted -l | grep efi | cut -f2 -d' ')
UBUNTU=$(sudo parted -l | grep ext4 | cut -f2 -d' ')
echo "Ubuntu: ${UBUNTU}"
echo "EFI: ${EFI}"
echo "DEV: ${DEV}"
echo "Continue?"
read -n 1 -t 5 cont
if [ "${cont}" == "y" ]; then
sudo mount /dev/${DEV}${UBUNTU} /mnt
sudo mount /dev/${DEV}${EFI} /mnt/boot/efi
sudo mount -o bind /dev /mnt/dev
sudo mount -o bind /sys /mnt/sys
sudo mount -t proc /proc /mnt/proc
sudo cp /proc/mounts /mnt/etc/mtab
sudo chroot /mnt /bin/bash
grub-install /dev/${DEV}
else
echo "Abort"
exit
fi
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
rsync -rthvue "ssh -p 3032" --delete-delay lucas@serverhost:/home/www/owncloud/owncloud/data/lucas/files/SW/ /media/lucas/LucasFestplatte/SW/
+5
View File
@@ -0,0 +1,5 @@
[sambashare]
comment = HomeAssistant Backup
path = /backup/homeassistant
read only = no
browsable = yes
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
> /etc/motd
sudo apt-get update > /dev/null 2>&1
remove=$(sudo apt-get -s autoremove | grep upgraded, | awk '{ printf "%i",$6; }')
echo "$remove packages can be removed." >> /etc/motd
+60
View File
@@ -0,0 +1,60 @@
#!/bin/bash
home_dir="/home/lucas"
green="\e[32m"
red="\e[31m"
norm="\e[0m"
write_out() {
if [ "${MAIL}" == "true" ]; then
printf "$@\n" >> /tmp/update.txt
else
printf "$@\n"
fi
}
MAIL=false
echo Start Update
date="$(date +"%m%d%H")"
if [ "$1" == "-mail" ]; then
> /tmp/update.txt
exec 3>&1 4>&2 1>"${home_dir}.LOG/log_update_$date.log" 2>&1
MAIL=true
green=""
red=""
norm=""
fi
write_out "Start: $(date)"
CMD=("apt -y update" "apt -y upgrade" "apt -y dist-upgrade" "apt -y autoclean" "apt -y autoremove" "find ${home_dir}/.LOG/ -name log_update_* -mtime +6 -type f -delete")
MSG=("update" "upgrade" "dist-upgrade" "autoclean" "autoremove" "Log File Remove")
for ((i=0;i<${#CMD[@]};i++)); do
if [[ $(echo ${CMD[$i]} | grep pip3) != "" ]] && [[ $(hostname) == "raspberry" ]]; then
continue
fi
printf "${CMD[$i]}\n"
eval ${CMD[$i]}
if [ $? -ne 0 ] ; then
write_out "${MSG[$i]}\t\t\t\t[${red}FAIL${norm}]\n"
else
write_out "${MSG[$i]}\t\t\t\t[${green}OK${norm}]\n"
fi
done
if [[ -f /home/lucas/tools/spotdl_venv/bin/pip3 ]]; then
CMD=("spotdl" "youtube-dl" "yt-dlp")
for ((i=0;i<${#CMD[@]};i++)); do
printf "Package ${CMD[$i]}\n"
if [[ "$(sudo -u lucas /home/lucas/tools/spotdl_venv/bin/pip3 list | grep ${CMD[$i]})" != "" ]]; then
sudo -u lucas /home/lucas/tools/spotdl_venv/bin/pip3 install --upgrade ${CMD[$i]}
fi
if [ $? -ne 0 ] ; then
write_out "${MSG[$i]}\t\t\t\t[${red}FAIL${norm}]\n"
else
write_out "${MSG[$i]}\t\t\t\t[${green}OK${norm}]\n"
fi
done
else
echo No Spotdl venv installed
fi
if [ "${MAIL}" == "true" ]; then
mail_str="$(cat /tmp/update.txt)"
echo "$mail_str" | mail -s "Automated Servermessage - Upgrade" lucas-f@live.at
fi
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
OCDIR="/home/lucas/Documents/Dokumente/Dokumente/Projekte/Server/scripts/"
if [ "$(hostname)" == "raspberry" ];then
DIR="/home/lucas/Raspberry/scripts/"
elif [ "$(hostname)" == "serverhost" ] || [ "$(hostname)" == "workhost" ];then
DIR="/home/lucas/scripts/"
else
printf "Wrong Host! WTF?\n"
fi
scriptname=("hoststatus.sh" "wol.sh" "MSgrep.sh" "shutdown.sh" "deluge-client.sh")
cmdname=("hoststatus" "wake" "MSgrep" "hostdown" "dinfo")
len=${#scriptname[@]}
for (( i=0; i<${#scriptname[@]}; i++ )); do
if [ ! -f "/usr/local/bin/${cmdname[$i]}" ] && [ -f "${DIR}${scriptname[$i]}" ];then
printf "%s%s %s\n" "${DIR}" "${scriptname[$i]}" "${cmdname[$i]}"
ln -s ${DIR}${scriptname[$i]} /usr/local/bin/${cmdname[$i]}
fi
if [ ! -f "/usr/local/bin/${cmdname[$i]}" ] && [ -f "${OCDIR}${scriptname[$i]}" ];then
printf "%s%s %s\n" "${OCDIR}" "${scriptname[$i]}" "${cmdname[$i]}"
ln -s ${OCDIR}${scriptname[$i]} /usr/local/bin/${cmdname[$i]}
fi
done
+827
View File
@@ -0,0 +1,827 @@
#!/bin/bash
## For laptop lid trigger: Write following in /etc/acpi/events/lm_lid
# event=button/lid.*
# action=/data/DatenLucas/Dokumente/Dokumente/Projekte/Server/scripts/quiethost/wallpaperChanger.sh -l -c
LOG_DIR="/home/lucas/.LOG/"
IMG_DIR="/data/DatenLucas/Media/Stuff/Wallpaper/"
PrivKey="file:/home/lucas/Documents/Dokumente/Projekte/Server/quiethost/IMG_privateKey.pem"
MONITOR_FILE="/home/lucas/.config/monitors.xml"
THALES=false
IMG_FOLDER="Desktop1920x1080/"
X_FOLDER="corrupt"
DAEMON=false
LOG=false
DECODE_SINGLE=false
REMOVE=false
CUSTOM_DIR=false
CONFIG=false
CONFIGFILE="wp.conf"
DEVICE_CARD="card0"
NAMING_TABLE="naming_table.txt"
NAMING_TABLE_ENC="naming_table_enc.txt"
EXCLUDE_CONFIG_DEF="XXXDEFAULTXXX"
REPLACE_ENC_IMG=false
WC_USER="lucas"
WC_GROUP="lucas"
EDIT_CONFIG=false
usage(){
printf "Usage:
-u\t\t\tUDEV Mode
-a\t\t\tacapid Mode(Lid Close DAEMON)
-t <min>\t\tStart DAEMON and Change Image every min Interval
-p <path>\t\tPath of Image folder
-s <search>\t\tChose Search Parameters(everything until next -*)
-ex <exclude>\t\tExclude String from Search
-c\t\t\tUse Config File
-l\t\t\tUse Log File
-elements\tInclude Spectral Lines of Elements Pictures
-thales\t\t\tUse thales Config
-e\t\t\tEdit Config File
-h\t\t\tDisplay this\n"
}
usageX(){
printf "UsageX:
-x\t\t\tSwitch Source Folder to X
-X\t\t\tClear Config and change Wallpaper
-dec_all\t\tDecode all Images
-dec_leave\t\tLeave used Images decoded
-dec_arg <pattern>\tDecode certain Images matching pattern *<arg>*
-printNT\t\tDecode NT to stdout
-modifyNT\t\tDecode NT/Encode if decoded NT present
-replace\t\tReplace Image in NT
-insta\t\tInsta Mode\n"
}
change_image(){
SZ="1920x1080"
IMGtype=("Wallpaper" "Screensaver" "Grub" "Login")
valueGnomeOpt=("'stretched'" "'spanned'")
typeGnomeOpt=("background" "screensaver")
MONITOR_num=$((${#screen_width_X[@]} - 1))
EXCLUDE=${EXCLUDE_CONFIG}
for IMG in $(find ${IMG_DIR}${IMG_FOLDER} -name '*.jp*g' -or -name '*.JP*G'); do
if [ "$(identify $IMG | grep -iP "jp[e]?g")" != "" ]; then
convert "$IMG" "$(echo $IMG | sed 's/JP[E]\?G/png/g' | sed 's/jp[e]\?g/png/g')"
rm "$IMG"
IMG="$(echo $IMG | sed 's/JP[E]\?G/png/g' | sed 's/jp[e]\?g/png/g')"
fi
done
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] && [ "${DAEMON}" == "false" ];then
echo "Check Encryprion"
check_encryption
fi
IMG_NUM_TOTAL=$(find ${IMG_DIR}${IMG_FOLDER} -name '*.png' | wc -l)
for (( i=0;i<${#IMGtype[@]};i++ )); do # i = Background/Screensaver/Grub
echo "Change ${IMGtype[${i}]}"
if [ ${i} -ge 2 ]; then
EXCLUDE="Panorama"
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ];then
echo Search
SEARCH=""
IMG_FOLDER="Desktop1920x1080/"
fi
if [[ ${i} -eq 3 ]] && [[ ${THALES} == "false" ]]; then
SEARCH=""
SEARCH[0]="Elements"
EXCLUDE=${EXCLUDE_CONFIG_DEF}
fi
for (( k=0;k<${#SEARCH[@]};k++ )); do
SEARCH[$k]="$(echo "${SEARCH[$k]}" | sed 's/Panorama//g')"
done
fi
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ];then
echo "Decode Naming Table"
file_path="${IMG_DIR}${IMG_FOLDER}/"
if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then
openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -out "${file_path}${NAMING_TABLE}" -pass "${PrivKey}"
fi
fi
ConvertSTR=""
for (( j=0;j<${MONITOR_num};j++ )); do # j = Screen
ind=$((${i}*2+$j))
img_fit_counter=0;
IMG_FIT=false
while ! $IMG_FIT; do
if [ ${#SEARCH[@]} -eq 1 ]; then
SEARCH_PARAMETER=${SEARCH[0]}
else
SEARCH_PARAMETER=${SEARCH[$ind]}
fi
SEARCH_NUM="$(echo ${SEARCH_PARAMETER} | grep -oE "[[:digit:]]{2}")"
SEARCH_STR="$(echo ${SEARCH_PARAMETER} | grep -oE "[^[:digit:]]+")"
echo "Search Parameter: ${SEARCH_STR} - ${SEARCH_NUM}, exclude ${EXCLUDE}"
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ];then
IMG_count=$(cat "${file_path}${NAMING_TABLE}" | cut -f1 -d';' | grep -i "${SEARCH_STR}.*${SEARCH_NUM}" | grep -iv "${EXCLUDE}" | grep -v "_decrypted" | wc -l)
else
IMG_count=$(find ${IMG_DIR}${IMG_FOLDER} -name '*.png' | grep -i "${SEARCH_STR}.*${SEARCH_NUM}" | grep -iv "${EXCLUDE}" | grep -v "_decrypted" | wc -l)
fi
if [ ${IMG_count} -eq 0 ];then
echo "No image found for ${IMGtype[${i}]} ${SEARCH_STR}"
if [ "${SEARCH_STR}" == "" ];then
exit 1
else
SEARCH=""
continue
fi
else
echo "${IMG_count} Images found"
fi
NUM=$(($RANDOM % $IMG_count))
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ];then
IFS=$'\n'; set -f
IMG_ARR=($(cat "${file_path}${NAMING_TABLE}" | cut -f1 -d';' | grep -i "${SEARCH_STR}.*${SEARCH_NUM}" | grep -iv "${EXCLUDE}"))
IMG_ENC_ARR=($(cat "${file_path}${NAMING_TABLE}" | grep "$(echo ${IMG_ARR[@]} | sed 's/ /\\\|/g')" | cut -f2 -d';'))
unset IFS; set +f
else
IFS=$'\n'; set -f
IMG_ARR=($(find ${IMG_DIR}${IMG_FOLDER} -name '*.png' | grep -i "${SEARCH_STR}.*${SEARCH_NUM}" | grep -iv "${EXCLUDE}" | grep -v "_decrypted"))
unset IFS; set +f
fi
IMG=${IMG_ARR[$NUM]}
for (( k=0;k<${#IMAGES[@]};k++ ));do
if [[ ("${SEARCH[0]}" != "${SEARCH_PARAMETER}" && "${SEARCH_NUM}" != "" ) || ("${SEARCH[0]}" == "${SEARCH_PARAMETER}" && "${SEARCH_NUM}" == "") ]]; then
counter=0;
while [[ "${IMG}" == ${IMAGES[$k]} && ${counter} -lt ${IMG_count} ]]; do
echo Disable Same Image
NUM=$(($RANDOM % $IMG_count))
IMG=${IMG_ARR[$NUM]}
((counter++))
done
fi
done
IMAGES[$ind]=$IMG
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ];then
echo "Decrypt Image"
IMG_DEC=${file_path}${IMG}
IMG_ENC=${IMG_ENC_ARR[$NUM]}
if [ -f "${file_path}${IMG_DEC}" ]; then
echo "File Name already present: ${IMG_DEC}"
IMG_DEC="$(echo "${IMG_DEC}" | sed 's/.png/_DOUBLE_'"${RANDOM}"'\.png/g')"
fi
openssl enc -aes-256-cbc -pbkdf2 -d -in "${file_path}${IMG_ENC}" -out "${IMG_DEC}" -pass "${PrivKey}"
if [ $? -eq 0 ]; then
echo "Decryption Succesfull"
else
echo "Decryption failed"
fi
IMG=${IMG_DEC}
fi
if [[ "$(echo ${IMG} | grep "Elements/Elements_")" != "" ]]; then
for ((k=0;k<3;k++)); do
if [ ${i} -lt 3 ]; then
POINTSIZE=12
else
POINTSIZE=24
fi
IFS=$'\n'; set -f
IMG_ARR2=($(find ${IMG_DIR}${IMG_FOLDER} -name '*.png' | grep "Elements/Elements_" | grep -v "${IMG}"))
unset IFS; set +f
IMG_count2=${#IMG_ARR2[@]}
NUM=$(($RANDOM % $IMG_count2))
IMG2=${IMG_ARR2[$NUM]}
convert -append $IMG $IMG2 "${LOG_DIR}NextCombined.png"
NUM=$(echo $IMG | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f1 -d'_')
NUM2=$(echo $IMG2 | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f1 -d'_')
LET=$(echo $IMG | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f2 -d'_')
LET2=$(echo $IMG2 | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f2 -d'_')
NAME=$(echo $IMG | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f3 -d'_')
NAME2=$(echo $IMG2 | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f3 -d'_')
NAME="$(printf "%s %s %s" "$NUM" "$LET" "$NAME")"
if [ "$( echo ${NAME} | grep -o "[A-Za-z]")" == "" ]; then NAME=${NAME_BUF}; fi
NAME2="$(printf "%s %s %s" "$NUM2" "$LET2" "$NAME2")"
if [ $(( ${k}%2 )) -eq 0 ]; then
y_1=$(( 510 + k*540 ));
y_2=$(( 580 + k*540 ));
convert -font helvetica -fill white -pointsize ${POINTSIZE} -draw "text 20,'${y_1}' '${NAME}' text 20,'${y_2}' '${NAME2}'" "${LOG_DIR}NextCombined.png" "${LOG_DIR}NextCombined.png"
fi
IMG="${LOG_DIR}NextCombined.png"
NAME_BUF=${NAME2}
if [ ${i} -lt 3 ]; then break; fi
done
fi
## Aspect Ratio Part
imageAR=$(getAspectRatio ${IMG})
printf "%s%d: $(echo ${IMG} | rev | cut -f1 -d'/' | rev) IAR: %s - SAR: %s\n" "${IMGtype[${i}]}" "${j}" "${imageAR}" "${screen_Aspect_Ratio[$j]}"
if [[ "$IMG" == "" ]]; then exit; fi
BIGIMG=false
AR_tolerance="0.26"
if [ $(echo ${imageAR}'=='${screenAR_ARR[${i}]} | bc -l) -eq 1 ]; then
# if [ ${MONITOR_num} -eq 1 ]; then break; fi
echo "Copy $((${screen_width_X[$j]}*${MONITOR_num}))x${screen_height_Y[$j]} Image"
cp "$IMG" "${LOG_DIR}Next${IMGtype[${i}]}.png"
IMG_FIT=true
BIGIMG=true
j=${MONITOR_num}
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] && ! ${DECODE_SINGLE} ;then
echo "Remove Decrypted Image"
rm ${IMG}
fi
break
elif [[ $(echo ${imageAR}'<'${screenAR_ARR[${i}]}'*(1+'${AR_tolerance}')' | bc -l) -eq 1 && $(echo ${imageAR}'>'${screenAR_ARR[${i}]}'*(1-'${AR_tolerance}')' | bc -l) -eq 1 ]] ;then
# if [ ${MONITOR_num} -eq 1 ]; then break; fi
echo "Convert Image to $((${screen_width_X[$j]}*${MONITOR_num}))x${screen_height_Y[$j]}"
convert "$IMG" -resize $((${screen_width_X[$j]}*${MONITOR_num}))x${screen_height_Y[$j]}\! "${LOG_DIR}Next${IMGtype[${i}]}.png"
IMG_FIT=true
BIGIMG=true
j=${MONITOR_num}
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] && ! ${DECODE_SINGLE} ;then
echo "Remove Decrypted Image"
rm "${IMG}"
fi
break
elif [ $(echo ${imageAR}'=='${screen_Aspect_Ratio[$j]} | bc -l) -eq 1 ]; then
img_height_X="$(identify $IMG | cut -f3 -d' ' | cut -f2 -d'x')"
img_width_Y="$(identify $IMG | cut -f3 -d' ' | cut -f1 -d'x')"
#echo "${img_width_Y}x${img_height_X}:${screen_width_X[$j]}x${screen_height_Y[$j]}"
if [[ "${img_width_Y}" != "${screen_width_X[$j]}" || "${img_height_X}" != "${screen_height_Y[$j]}" ]]; then
echo "Convert Image to ${screen_width_X[$j]}x${screen_height_Y[$j]} Image"
IMG_FIT=true
convert "$IMG" -resize ${screen_width_X[$j]}x${screen_height_Y[$j]}\! "${LOG_DIR}IMG$ind.png"
ConvertSTR="$ConvertSTR ${LOG_DIR}IMG$ind.png"
else
echo "Copy ${screen_width_X[$j]}x${screen_height_Y[$j]} Image"
IMG_FIT=true
cp "$IMG" "${LOG_DIR}IMG$ind.png"
ConvertSTR="$ConvertSTR ${LOG_DIR}IMG$ind.png"
fi
elif [[ $(echo ${imageAR}'<'${screen_Aspect_Ratio[$j]}'*(1+'${AR_tolerance}')' | bc -l) -eq 1 && $(echo ${imageAR}'>'${screen_Aspect_Ratio[$j]}'*(1-'${AR_tolerance}')' | bc -l) -eq 1 ]]; then
echo "Convert Image to ${screen_width_X[$j]}x${screen_height_Y[$j]}"
convert "$IMG" -resize ${screen_width_X[$j]}x${screen_height_Y[$j]}\! "${LOG_DIR}IMG$ind.png"
cp "$IMG" "$( echo "${IMG}_bak" | sed 's/_decrypted//g')"
IMG_FIT=true
cp "${LOG_DIR}IMG$ind.png" "$IMG"
ConvertSTR="$ConvertSTR ${LOG_DIR}IMG$ind.png"
else
echo "Image ${IMG} out of bounds"
fi
((img_fit_counter++))
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] && ! ${DECODE_SINGLE} ;then
echo "Remove Decrypted Image"
rm "${IMG}"
fi
if [ $img_fit_counter -ge $IMG_NUM_TOTAL ]; then
echo "No Images Found. Change Search Parameter"
break
fi
done
done
if ! $BIGIMG; then
convert $ConvertSTR -background black +append ${LOG_DIR}Next${IMGtype[${i}]}.png
fi
mv ${LOG_DIR}Next${IMGtype[${i}]}.png ${LOG_DIR}Current${IMGtype[${i}]}.png
chmod 777 ${LOG_DIR}Current${IMGtype[${i}]}.png
if [[ "$(whoami)" == "root" && ${i} -lt 2 ]]; then
if [ "$(su ${WC_USER} -c "gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri")" != "'file://${LOG_DIR}Current${IMGtype[${i}]}.png'" ]; then
echo Set gsettings ${type[${i}]} picture-uri
su ${WC_USER} -c "gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri file://${LOG_DIR}Current${IMGtype[${i}]}.png"
fi
if [ "$(su ${WC_USER} -c "gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-options")" != "'spanned'" ]; then
echo Set gsettings ${typeGnomeOpt[${i}]} picture-options
su ${WC_USER} -c "gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-options spanned"
fi
chown ${WC_USER}:${WC_GROUP} ${LOG_DIR}*png
elif [ ${i} -lt 2 ]; then
if [ "$(gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri)" != "'file://${LOG_DIR}Current${IMGtype[${i}]}.png'" ]; then
echo Set gsettings ${type[${i}]} picture-uri
gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri file://${LOG_DIR}Current${IMGtype[${i}]}.png
fi
if [ "$(gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-options)" != "'spanned'" ]; then
echo Set gsettings ${typeGnomeOpt[${i}]} picture-options
gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-options spanned
fi
fi
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] ;then
echo "Remove Naming Table"
rm "${file_path}${NAMING_TABLE}"
fi
done
}
getAspectRatio() {
if [ "$1" == "" ]; then return "0"; fi
identify "$1" | perl -ne '/(.+?)\s+[A-Z]{3}\s+(\d+)x(\d+)/; print $3/$2, "\n"'
}
decode_all() {
echo "Decode all Images"
IMG_FOLDER_TMP="${X_FOLDER}"
file_path="${IMG_DIR}${IMG_FOLDER_TMP}/"
if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then
openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -out "${file_path}${NAMING_TABLE}" -pass "${PrivKey}"
fi
for file in $(find ${IMG_DIR}${IMG_FOLDER_TMP} -name '*.png_enc'); do
if [ "$(identify ${file} 2>>/dev/null | grep "PNG")" == "" ]; then
DEC_NAME="${file_path}$(cat "${file_path}${NAMING_TABLE}" | grep "$(echo ${file} | rev | cut -f1 -d'/' | rev)" | cut -f1 -d';')"
if [ -f "${file_path}${DEC_NAME}" ]; then
echo "File Name already present: ${DEC_NAME}"
DEC_NAME="$(echo "${DEC_NAME}" | sed 's/.png/_DOUBLE_'"${RANDOM}"'\.png/g')"
else
echo "Decode ${DEC_NAME}"
fi
openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file}" -out "${DEC_NAME}" -pass "${PrivKey}"
rm ${file}
fi
done
rm "${file_path}${NAMING_TABLE_ENC}"
rm "${file_path}${NAMING_TABLE}"
}
check_encryption() {
IMG_FOLDER="${X_FOLDER}"
ENC_FILE_COUNT=0;
file_path="${IMG_DIR}${IMG_FOLDER}/"
for file in $(find ${IMG_DIR}${IMG_FOLDER} -name '*.png_enc'); do
ENC_FILE_ARR[${ENC_FILE_COUNT}]=${file}
((ENC_FILE_COUNT++))
done
((ENC_FILE_COUNT--))
IFS=$'\n' ENC_FILE_ARR=($(sort <<<"${ENC_FILE_ARR[*]}"))
unset IFS
if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then
openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -out "${file_path}${NAMING_TABLE}" -pass "${PrivKey}"
fi
for file in $(find ${IMG_DIR}${IMG_FOLDER} -name '*.png' | sort); do
if [ "$(identify ${file} 2>>/dev/null | grep "PNG")" != "" ]; then
if [ ${#ENC_FILE_ARR[@]} -eq 0 ]; then
ENC_FILE_COUNT=0
ENC_NAME_CORE="0"
cat "${file_path}${NAMING_TABLE}"
else
ENC_NAME_CORE=$(( $(echo "${ENC_FILE_ARR[${ENC_FILE_COUNT}]}" | cut -d'.' -f1 | rev | cut -f1 -d'/' | rev | bc) + 1))
((ENC_FILE_COUNT++))
fi
ENC_NAME="$(printf "%05d" ${ENC_NAME_CORE}).png_enc"
ENC_FILE_ARR[${ENC_FILE_COUNT}]=${ENC_NAME}
if [ -f "${file_path}${ENC_NAME}" ]; then
echo "File Name already present: ${ENC_NAME}"
ENC_NAME="$(echo "${ENC_NAME_CORE}")_DOUBLE_${RANDOM}.png_enc"
else
echo "Encode ${file} to ${ENC_NAME}"
fi
file_identifier="$( echo "${file}" | rev | cut -f1 -d'/' | rev)"
if [ -f "${file_path}${NAMING_TABLE}" ];then
if [ "$(cat "${file_path}${NAMING_TABLE}" | grep "${file_identifier}")" != "" ] && ! ${REPLACE_ENC_IMG} ; then
echo "Identifier ${file_identifier} already present, changing to"
file_identifier="$(echo "${file_identifier}" | sed 's/\.png/_enc_DOUBLE_'"${RANDOM}"'\.png/g')"
echo "${file_identifier}"
echo "${file_identifier};${ENC_NAME}" >> "${file_path}${NAMING_TABLE}"
elif [ "$(cat "${file_path}${NAMING_TABLE}" | grep "${file_identifier}")" != "" ] && ${REPLACE_ENC_IMG} ; then
ENC_NAME="$(cat "${file_path}${NAMING_TABLE}" | grep "${file_identifier}" | cut -d';' -f2)"
echo "Identifier ${file_identifier} already present, replacing image ${ENC_NAME}"
else
echo "${file_identifier};${ENC_NAME}" >> "${file_path}${NAMING_TABLE}"
fi
fi
openssl enc -aes-256-cbc -pbkdf2 -salt -in "${file}" -out "${file_path}${ENC_NAME}" -pass "${PrivKey}"
rm "${file}"
fi
done
openssl enc -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE}" -out "${file_path}${NAMING_TABLE_ENC}" -pass "${PrivKey}"
rm "${file_path}${NAMING_TABLE}"
IMG_FOLDER="${X_FOLDER}"
}
decode_images() {
echo "Decode All *$1*"
IMG_FOLDER_TMP="${X_FOLDER}"
file_path="${IMG_DIR}${IMG_FOLDER_TMP}/"
if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then
openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -out "${file_path}${NAMING_TABLE}" -pass "${PrivKey}"
fi
files=($(cat "${file_path}${NAMING_TABLE}" | grep -e ".*$1.*" | cut -f2 -d';'))
for file in ${files[@]}; do
if [ "$(identify ${file} 2>>/dev/null | grep "PNG")" == "" ]; then
naming_table_line=$(cat "${file_path}${NAMING_TABLE}" | grep "$(echo ${file} | rev | cut -f1 -d'/' | rev)")
DEC_NAME="${file_path}$(echo ${naming_table_line} | cut -f1 -d';')"
if [ "$(echo ${naming_table_line} | grep -e ".*$1.*")" == "" ]; then
continue
fi
if [ -f "${DEC_NAME}" ]; then
echo "File Name already present: ${DEC_NAME}"
DEC_NAME="$(echo "${DEC_NAME}" | sed 's/.png/_DOUBLE_'"${RANDOM}"'\.png/g')"
else
echo "Decode ${DEC_NAME}"
fi
openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${file}" -out "${DEC_NAME}" -pass "${PrivKey}"
if [[ "${REMOVE}" == "true" ]]; then
echo "Remove line ${naming_table_line} from Naming Table"
sed -i '/'"${naming_table_line}"'/d' ${file_path}${NAMING_TABLE}
echo "Remove ${file_path}${file}"
rm "${file_path}${file}"
fi
fi
done
openssl enc -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE}" -out "${file_path}${NAMING_TABLE_ENC}" -pass "${PrivKey}"
rm "${file_path}${NAMING_TABLE}"
}
printNamingTable() {
IMG_FOLDER_TMP="${X_FOLDER}/"
file_path="${IMG_DIR}${IMG_FOLDER_TMP}/"
if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then
openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -pass "${PrivKey}"
else
echo "No Naming Table under ${file_path}${NAMING_TABLE_ENC}"
fi
}
modifyNT() {
IMG_FOLDER_TMP="${X_FOLDER}/"
file_path="${IMG_DIR}${IMG_FOLDER_TMP}"
NAMING_TABLE="naming_table_mod.txt"
if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then
if [ ! -f "${file_path}${NAMING_TABLE}" ];then
openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -out "${file_path}${NAMING_TABLE}" -pass "${PrivKey}"
echo "Decrypting to ${file_path}${NAMING_TABLE}"
else
openssl enc -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE}" -out "${file_path}${NAMING_TABLE_ENC}" -pass "${PrivKey}"
rm "${file_path}${NAMING_TABLE}"
echo "Encrypting to ${file_path}${NAMING_TABLE_ENC}"
fi
else
echo "No Naming Table under ${file_path}${NAMING_TABLE_ENC}"
fi
}
logfile_cleanup(){
size=$(ls -l $LOG_FILE | cut -f5 -d' ')
echo Logfile Size: $size
if [ $size -gt 10000 ]; then
lines=$(wc -l $LOG_FILE | cut -f1 -d' ')
lines_new=$(($lines / 2))
echo Lines: $lines
echo Lines_new: $lines_new
sed -i "1,${lines_new}d" $LOG_FILE
exec 1>>${LOG_FILE} 2>&1
fi
}
sort_ARR(){
for ((i=0; i <= $((${#screen_pos_X[@]} - 2)); ++i)); do
for ((j=((i + 1)); j <= ((${#screen_pos_X[@]} - 1)); ++j)); do
if [[ ${screen_pos_X[i]} -gt ${screen_pos_X[j]} ]]; then
tmp1=${screen_pos_X[i]}
screen_pos_X[i]=${screen_pos_X[j]}
screen_pos_X[j]=$tmp1
tmp2=${screen_width_X[i]}
screen_width_X[i]=${screen_width_X[j]}
screen_width_X[j]=$tmp2
tmp3=${screen_height_Y[i]}
screen_height_Y[i]=${screen_height_Y[j]}
screen_height_Y[j]=$tmp3
fi
done
done
screen_width_X[${#screen_width_X[@]}]=${screen_width_X[0]}
screen_height_Y[${#screen_height_Y[@]}]=${screen_height_Y[0]}
screen_Aspect_Ratio[${#screen_Aspect_Ratio[@]}]=${screen_Aspect_Ratio[0]}
screenAR_ARR=("${screenAR}" "${screenAR}" "${screen_Aspect_Ratio[0]}" "${screen_Aspect_Ratio[0]}")
}
sum_ARR(){
arr=($@)
if [ ${#arr[@]} -eq 0 ]; then return 0; fi
IFS='+'; set -f
sum=$(echo "scale=1;${arr[*]}"|bc)
unset IFS; set +f
echo $sum
}
get_screensize(){
if [ "$(ls /sys/class/drm/${DEVICE_CARD}/ | grep "${DEVICE_CARD}-")" == "" ]; then
printf "Wrong Device Card: %s -> " "${DEVICE_CARD}"
DEVICE_CARD="card1"
printf "New: %s\n" "${DEVICE_CARD}"
fi
IFS=$'\n'; set -f
devices=($(ls /sys/class/drm/${DEVICE_CARD}/ | grep "${DEVICE_CARD}-" | cut -f2- -d'-'))
unset IFS; set +f
CONN_COUNT=0
for ((i=0;i<${#devices[@]};i++)); do
echo "Device: ${devices[${i}]}"
devices_name[${i}]=$(echo ${devices[${i}]}| grep -o "[[:alpha:]]*" | grep -m1 "[[:alpha:]]*")
devices_num[${i}]=$(echo ${devices[${i}]}|rev| grep -o "[[:digit:]]" | grep -m1 "[[:digit:]]")
status[${i}]=$(cat /sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-"${devices[${i}]}"/status)
enabled[${i}]=$(cat /sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-"${devices[${i}]}"/enabled)
if [ $(echo ${devices[${i}]} | grep "eDP" | wc -l) -ge 1 ]; then
if [ $(grep "wallpaperChanger.sh" /etc/acpi/events/lm_lid 2>/dev/null | wc -l) -eq 0 ]; then
echo "ERROR: No laptop lid trigger file: /etc/acpi/events/lm_lid"
fi
if [ $(grep "open" /proc/acpi/button/lid/LID0/state | wc -l) -eq 0 ]; then
status[${i}]="disconnected"
echo "Laptop Lid closed"
else
echo "Laptop Lid open"
fi
fi
if [ "${status[${i}]}" == "connected" ] && [ "${enabled[${i}]}" == "enabled" ]; then
((CONN_COUNT++))
fi
echo "${devices[${i}]}: ${status[${i}]}, ${enabled[${i}]}"
done
if [ "${THALES}" == "true" ] && [ $(id -u) -eq 0 ];then
echo "Open Monitor File as lfaber"
CONFIG_ARR=($(sudo -u lfaber cat ${MONITOR_FILE} | tr '\n' ';' | sed 's/ \+//g' | sed 's/<\/configuration>/<\/configuration>\n/g' | grep "<configuration>"))
else
echo "Open Monitor File"
CONFIG_ARR=($(cat ${MONITOR_FILE} | tr '\n' ';' | sed 's/ \+//g' | sed 's/<\/configuration>/<\/configuration>\n/g' | grep "<configuration>"))
fi
for ((j=0;j<${#CONFIG_ARR[@]};j++)); do
CONFIG_ARR[$j]="$(echo "${CONFIG_ARR[$j]}" | tr ';' '\n')"
MONITOR_COUNT=$(echo "${CONFIG_ARR[$j]}" | grep -c "<logicalmonitor>")
CONFIG_SUCCESS=true
if [ $CONN_COUNT -eq $MONITOR_COUNT ]; then
echo "Monitors: $MONITOR_COUNT"
for ((i=0;i<${#devices[@]};i++)); do
CONFIG_TEST=${CONFIG_ARR[$j]}
if [ "${status[${i}]}" == "connected" ]; then
SIZE_X="$(cat "/sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-${devices[${i}]}/device/device/graphics/fb0/virtual_size" | cut -f1 -d',')"
SIZE_Y="$(cat "/sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-${devices[${i}]}/device/device/graphics/fb0/virtual_size" | cut -f2 -d',')"
CONFIG_TEST="$(echo "${CONFIG_TEST}" | tr '\n' ';' | sed 's/<\/logicalmonitor>;/<\/logicalmonitor>\n/g' | grep "${devices_name[${i}]}" | grep "${devices_num[${i}]}" | grep ";<width>${SIZE_X}</width>;<height>${SIZE_Y}</height>;")"
fi
if [ "${CONFIG_TEST}" == "" ]; then
CONFIG_SUCCESS=false
echo "Wrong Monitor"
fi
done
if ${CONFIG_SUCCESS}; then
CONFIG_NEW="${CONFIG_ARR[$j]}"
else
echo "Wrong Monitor"
fi
else
echo "Connected Monitors: $CONN_COUNT"
echo "Configured Monitors: $MONITOR_COUNT"
fi
# CONFIG_ARR[$j]="$(echo "${CONFIG_ARR[$j]}" | grep "<connector>${devices[${i}]}")"
done
if [ $CONN_COUNT -eq 1 ]; then
for ((i=0;i<${#devices[@]};i++)); do
if [ "${status[${i}]}" == "connected" ]; then
SIZE_X="$(cat "/sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-${devices[${i}]}/device/device/graphics/fb0/virtual_size" | cut -f1 -d',')"
SIZE_Y="$(cat "/sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-${devices[${i}]}/device/device/graphics/fb0/virtual_size" | cut -f2 -d',')"
POS="<x>0</x>"
CONFIG_NEW="<width>$SIZE_X</width>\n<height>$SIZE_Y</height>\n$POS\n"
fi
done
fi
if [ "$CONFIG_NEW" == "" ]; then
echo "Abort: Monitor Information not consistent"
exit
fi
IFS=$'\n'; set -f
screen_width_X=($(echo -e "$CONFIG_NEW" | grep "width" | grep -o "[[:digit:]]*"))
screen_height_Y=($(echo -e "$CONFIG_NEW" | grep "height" | grep -o "[[:digit:]]*"))
screen_pos_X=($(echo -e "$CONFIG_NEW" | grep "<x>" | grep -o "[[:digit:]]*"))
unset IFS; set +f
for ((i=0; i<${#screen_width_X[@]} ; i++ )); do
screen_Aspect_Ratio[${i}]=$(perl -E "say ${screen_height_Y[${i}]}/${screen_width_X[${i}]}")
done
screenAR=$(perl -E "say ${screen_height_Y[0]}/$(sum_ARR ${screen_width_X[@]})")
}
get_config() {
while [[ ${1:0:1} == - ]]; do
echo "Param: $1"
[[ $1 == -u ]] && {
MODE="udev";
shift 1;
continue;
};
[[ $1 == -a ]] && {
MODE="acpid";
shift 1;
continue;
};
[[ $1 == -t ]] && {
if [ $# -lt 2 ]; then
usage
exit
fi
minutes=$2;
DAEMON=true;
MODE="daemon";
LOG=true;
shift 2;
continue;
};
[[ $1 == -p ]] && {
if [ $# -lt 2 ]; then
usage
exit
fi
CUSTOM_DIR=true;
IMG_DIR=$2;
shift 2;
continue;
};
[[ $1 == -e ]] && {
EDIT_CONFIG=true;
shift 1;
continue;
};
[[ $1 == -s ]] && {
if [ $# -lt 2 ]; then
SEARCH=""
else
counter=0
while (true); do
if [[ "$2" == "-"* || "$2" == "" ]]; then shift 1; break; fi
SEARCH[$counter]=$2
((counter++))
shift 1
done
fi
continue;
};
[[ $1 == -c ]] && {
CONFIG=true;
shift 1;
continue;
};
[[ $1 == -elements ]] && {
EXCLUDE_CONFIG=${EXCLUDE_CONFIG_DEF}
shift 1;
continue;
};
[[ $1 == -l ]] && {
LOG=true;
shift 1;
continue;
};
[[ $1 == -x ]] && {
X_FOLDER="corrupt"
IMG_FOLDER="${X_FOLDER}"
shift 1;
continue;
};
[[ $1 == -h ]] && {
usage
shift 1;
exit 0;
};
[[ $1 == -hX ]] && {
usageX
shift 1;
exit 0;
};
[[ $1 == -ex ]] && {
EXCLUDE_CONFIG="$2"
shift 2;
};
[[ $1 == -X ]] && {
> /home/lucas/.LOG/wp.conf
rm /home/lucas/.LOG/IMG[0-3].png
shift 1;
continue;
};
[[ $1 == -dec_leave ]] && {
DECODE_SINGLE=true
shift 1;
continue;
};
[[ $1 == -insta ]] && {
X_FOLDER="insta"
IMG_FOLDER="${X_FOLDER}"
shift 1;
continue;
};
[[ $1 == -dec_arg ]] && {
arg=$2;
shift 2;
[[ $1 == -rm ]] && {
REMOVE=true
shift 1;
};
decode_images "${arg}"
exit 0;
};
[[ $1 == -rm ]] && {
shift 1;
REMOVE=true
};
[[ $1 == -dec_all ]] && {
decode_all
exit
};
[[ $1 == -printNT ]] && {
printNamingTable
shift 1;
exit 0;
};
[[ $1 == -modifyNT ]] && {
modifyNT
shift 1;
exit 0;
}
[[ $1 == -replace ]] && {
REPLACE_ENC_IMG=true
shift 1;
continue;
}
[[ $1 == -thales ]] && {
THALES=true
shift 1;
continue;
}
echo "Parameter $1 discarded"
shift 1;
done
}
echo Start $0 $@
SEARCH=""
MODE="user";
#EXCLUDE_CONFIG=${EXCLUDE_CONFIG_DEF}
EXCLUDE_CONFIG="elements"
get_config "$@"
if ${THALES}; then
LOG_DIR="/home/diskspace/lfaber/Wallpaper/.LOG/"
IMG_DIR="/home/diskspace/lfaber/Wallpaper/"
MONITOR_FILE="/homes/lfaber/.config/monitors.xml"
WC_USER="lfaber"
WC_GROUP="elektra"
PrivKey=""
count=0
ret=1
while [ ${count} -lt 100 ]; do
sudo -u lfaber id 2>&1 1>>/dev/null
ret=$?
echo $ret
if [ ${ret} -ne 0 ]; then
echo "Wait for user lfaber"
else
break
fi
sleep 10
done
if [ ${ret} -ne 0 ]; then
echo "User lfaber not present, exit."
exit
else
echo "User lfaber loaded"
fi
fi
if $EDIT_CONFIG; then
vim "${LOG_DIR}${CONFIGFILE}"
fi
if $CONFIG; then
IFS=$' '; set -f
get_config $(cat "${LOG_DIR}${CONFIGFILE}")
unset IFS; set +f
fi
if $LOG; then
LOG_FILE="${LOG_DIR}wallpaperchanger_${MODE}.log"
ls $LOG_DIR >> /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "Directory $LOG_DIR not present"
exit 1
fi
exec 1>>${LOG_FILE} 2>&1
date
fi
if $CUSTOM_DIR; then
if [ "$(echo "${IMG_DIR: -1}")" == "/" ]; then
IMG_FOLDER="$(echo ${IMG_DIR} | rev | cut -f2 -d'/' | rev)/"
IMG_DIR="$(echo ${IMG_DIR} | rev | cut -f3- -d'/' | rev)/"
else
IMG_FOLDER="$(echo ${IMG_DIR} | rev | cut -f1 -d'/' | rev)/"
IMG_DIR="$(echo ${IMG_DIR} | rev | cut -f2- -d'/' | rev)/"
fi
echo ${IMG_FOLDER}
echo ${IMG_DIR}
fi
ls ${IMG_DIR}${IMG_FOLDER} >> /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "Directory ${IMG_DIR}${IMG_FOLDER} not present"
exit 1
fi
get_screensize
sort_ARR
if [ "${screenAR}" == "0.5625" ]; then
EXCLUDE_CONFIG="Panorama"
fi
echo "Screen Width: ${screen_width_X[@]}"
echo "Screen Height: ${screen_height_Y[@]}"
echo "Screen Pos: ${screen_pos_X[@]}"
echo "Monitor Aspect Ratio: ${screen_Aspect_Ratio[@]} - Screen: ${screenAR}"
echo "Dir: ${IMG_DIR}${IMG_FOLDER}"
echo "User: $(whoami)"
if ${DAEMON}; then
if [ "`echo $minutes | egrep ^[[:digit:]]+$`" = "" ];then
echo "$minutes is not an Integer"
exit
else
echo "Interval: $minutes min"
fi
echo "Start DAEMON"
sleep_time=$(( $minutes * 60 ))
while [[ 1 -eq 1 ]]; do
if $CONFIG; then
IMG_FOLDER="Desktop1920x1080/"
IFS=$' '; set -f
get_config $(cat "${LOG_DIR}${CONFIGFILE}")
unset IFS; set +f
fi
get_screensize
sort_ARR
change_image
date
logfile_cleanup
echo "DAEMON Mode"
sleep $sleep_time
done
else
change_image
fi
exit 0
+21
View File
@@ -0,0 +1,21 @@
#!/bin/bash
device=$1
if [ "$device" == "serverhost" ]; then
mac="64:51:06:51:cb:39"
elif [ "$device" == "quiethost" ]; then
mac="24:4B:FE:DE:93:3E"
elif [ "$(echo ${device} | grep -E -o "([0-9A-Fa-f]{2}[\:]){5}[0-9A-Fa-f]{2}")" != "" ]; then
mac="${device}"
else
printf "Nonsense Input, hostname needed\n"
exit 0
fi
ifx=( $(/sbin/ip -br l | awk '$1 !~ "lo|vir|wl" { print $1}') )
for i in ${!ifx[@]}; do
sudo /usr/sbin/etherwake -b -i ${ifx[$i]} $mac
printf "%shost succsefully woken via ${ifx[$i]}: ${mac}\n" "$device"
done
if [ "$(echo $SSH_CONNECTION | cut -f1 -d' ')" == "10.0.0.26" ]; then
ssh quiethost notify-send "Woke ${device}"
fi
+175
View File
@@ -0,0 +1,175 @@
#!/bin/bash
LIST=false
RETRIES=""
PL_NAME="Default"
LOG=1
youtubelist="/home/lucas/scripts/youtubelist.txt"
MUSIC=false
VIDEO=true
DATE="$(date +'%m%d%H%M%S')"
log="pl_log_${DATE}.log"
DISABLE_SERVERMODE=false
#pl_options="--playlist-end 11"
pl_options=""
vid_options=""
get_config() {
while [[ ${1:0:1} == - ]]; do
echo "Param: $1"
[[ $1 == -retry ]] && {
echo "Retriy Mode"
RETRIES="--retries 100 --fragment-retries 100"
shift 1;
continue;
};
[[ $1 == -log ]] && {
echo "Playlist Log Mode"
LOG=0
shift 1;
continue;
};
[[ $1 == -pl_name ]] && {
if [ $# -lt 2 ]; then
usage
exit
fi
echo "Playlist Dir Name: $2"
PL_NAME=$2;
shift 2;
continue;
};
[[ $1 == -h ]] && {
usage
shift 1;
exit 0;
};
[[ $1 == -L ]] && {
LIST=true
shift 1;
continue;
};
[[ $1 == -disable ]] && {
DISABLE_SERVERMODE=true
shift 1;
continue;
};
[[ $1 == -M ]] && {
MUSIC=true
VIDEO=false
shift 1;
continue;
};
echo "Parameter $1 discarded"
shift 1;
done
}
write_log() {
echo "$@"
echo "$@" >> "${DL_PATH}${log}"
}
usage(){
printf "Usage:
-pl_name <name>\tGive Playlist name for -log mode
-retry\t\tUse more Retries
-log\t\tDownload Playlist Video Titles to Log File
-h\t\tHelpe
-M Download Music
-disable\tDisable VPN\n"
}
get_config "$@"
if [ ! -d ${DL_PATH} ]; then
mkdir "${DL_PATH}"
fi
if [ ! -f ${youtubelist} ] ; then
echo "No youtubelist present"
fi
if [[ "$(hostname)" == "serverhost" ]] && [[ "${DISABLE_SERVERMODE}" == "false" ]]; then
duser_cmd="sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh"
duser_cmd=""
DL_PATH="/torrent/youtube/"
echo "Serverhost mode - VPN"
elif [[ "$(hostname)" == "serverhost" ]]; then
duser_cmd=""
DL_PATH="/torrent/youtube/"
echo "Serverhost mode - No VPN"
else
duser_cmd=""
DL_PATH="/home/lucas/Downloads/"
fi
echo "IP: $(${duser_cmd} wget -T 5 -qO- ifconfig.co)|$(${duser_cmd} wget -T 5 -qO- ifconfig.co/country) "
count_list=1
vid_num="$(cat ${youtubelist} | wc -l | grep "")"
IFS=$'\n'; set -f
for VID in $(cat ${youtubelist}); do
write_log "$VID"
write_log "********************* VID ${count_list} of ${vid_num} *********************"
if [ "$(echo ${VID} | grep "playlist")" != "" ]; then
write_log "Playlist found"
PL_FAIL=0
if [ ${LOG} -eq 1 ]; then
write_log "Log Mode only, ${VID}"
${duser_cmd} yt-dlp ${RETRIES} -w -i "${VID}" ${pl_options} --output "${DL_PATH}%(uploader)s/%(playlist)s/%(upload_date)s_%(title)s.%(ext)s" --merge-output-format mp4 --remux-video mp4
fi
write_log "Logfile ${log}"
pl_name="$(printf "%s" "${VID}" | rev | cut -f1 -d'=' | rev)"
log_name="${DL_PATH}pl_log_${pl_name}.log"
echo $pl_name
echo $log_name
if [ ! -f ${log_name} ]; then
write_log "New Playlist File ${log_name}"
if ${MUSIC}; then
write_log "Download Music File"
${duser_cmd} yt-dlp -j --flat-playlist "${VID}" ${pl_options} | cut -f4 -d',' | cut -f2- -d':' | tr -d ' "' > ${log_name}
else
${duser_cmd} yt-dlp -j --flat-playlist "${VID}" ${pl_options} | cut -f4 -d',' | cut -f2- -d':' | tr -d ' "' > ${log_name}
fi
else
write_log "${log_name} already present"
fi
while [ $(cat ${log_name} | wc -l) -ne 0 ] ; do
count_playlist=0
count_playlist_fail=0
count_playlist_suc=0
lines=$(cat ${log_name} | wc -l)
write_log "${lines} files to download"
for line in $(cat ${log_name}); do
if ${MUSIC}; then
write_log "Download Music File"
${duser_cmd} yt-dlp ${RETRIES} "${line}" -f bestaudio -x --audio-format mp3 --audio-quality 320k --embed-thumbnail --add-metadata --postprocessor-args "-id3v2_version 3" --output "${DL_PATH}%(uploader)s/%(playlist)s_${pl_name}/%(title)s.%(ext)s"
else
${duser_cmd} yt-dlp ${RETRIES} -w -i "${line}" "${vid_options}" --output "${DL_PATH}%(uploader)s/%(playlist)s_${pl_name}/%(upload_date)s_%(title)s.%(ext)s" --merge-output-format mp4 --remux-video mp4
fi
ret=$?
if [ ${ret} -eq 0 ]; then
((count_playlist_suc++))
write_log "Remove ${line} from file ${log_name}"
cat ${log_name} | tr '\n' ';' | sed 's#'"${line}"';##g' | tr ';' '\n' > buf
mv buf ${log_name}
else
((count_playlist_fail++))
fi
((count_playlist++))
write_log "${count_playlist}/${lines} : ${line} : ${ret} - Sucess: ${count_playlist_suc} : Fail: ${count_playlist_fail}"
done
if [[ ${PL_FAIL} -gt 5 ]];then
break
fi
((PL_FAIL++))
echo "Increase PL_FAIL to ${PL_FAIL}"
done
else
if [ "$(echo ${VID} | grep youtube)" != "" ]; then
write_log "YouTube Video found"
${duser_cmd} yt-dlp ${RETRIES} -w -i "${VID}" ${pl_options} --output "${DL_PATH}%(uploader)s/%(playlist)s/%(upload_date)s_%(title)s.%(ext)s" --merge-output-format mkv
else
write_log "General Video found"
$(${duser_cmd}) yt-dlp -w -i "${VID}" --output "${DL_PATH}%(title)s_${count_list}.%(ext)s" --force-ipv4 --merge-output-format mp4 --remux-video mp4
echo "${duser_cmd} yt-dlp ${RETRIES} -w -i ${VID} --output ${DL_PATH}%(title)s_${count_list}.%(ext)s --force-ipv4 --merge-output-format mp4 --remux-video mp4"
fi
fi
((count_list++))
done