Files
Server-scripts/quiethost/torrentcopy.sh
T
2026-09-14 12:43:38 +02:00

146 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
IFS=$'\n'; set -f
STUFF="/data/Nextcloud/Filme/New/"
STUFF_ALT="/data/Torrents"
ASSUMEYES=false
FILE_PATH="/torrent/complete/"
usage() {
printf "Usage:
-y\ty Mode
-m\tmega Mode
-f\tCopy to ~/data
-d\tCopy to .
-l\tSelect List
-yt\tYoutube Folder
-help\tDisplay this\n"
}
get_config() {
while [[ ${1:0:1} == - ]]; do
echo "Param: $1"
[[ $1 == -help ]] && {
echo "Help"
usage;
exit;
};
[[ $1 == -y ]] && {
echo "y Mode"
ASSUMEYES=true
shift 1
continue
};
[[ $1 == -yt ]] && {
echo "Youtube Mode"
FILE_PATH="/torrent/youtube/"
shift 1
continue
};
[[ $1 == -m ]] && {
echo "mega Mode"
FILE_PATH="/torrent/mega/"
shift 1
continue
};
[[ $1 == -l ]] && {
echo "List Mode"
LIST_MODE=true
shift 1
continue
};
[[ $1 == -d ]] && {
STUFF="$(pwd)"
echo "Change Folder: $STUFF"
shift 1
continue
};
[[ $1 == -f ]] && {
echo "Change Folder"
STUFF=${STUFF_ALT}
shift 1
continue
};
echo "Parameter $1 discarded"
usage
exit
done
}
get_config "$@"
LIST=($(ssh serverhost ls ${FILE_PATH}))
if [ ${#LIST[@]} -eq 0 ]; then
echo "Nothing to Copy/Delete"
exit
fi
if [ "${LIST_MODE}" == "true" ]; then
for i in "${!LIST[@]}"; do
files=${LIST[$i]}
echo "Copy? ${files} (y/*)"
read -n 10 ans
if [ "$ans" != "y" ]; then
echo "Dont copy $files"
unset 'LIST[i]'
fi
done
echo "NEW LIST:"
echo "${LIST[*]}"
fi
if [ "${ASSUMEYES}" == "false" ]; then
echo "Copy? (y/*)"
echo "${LIST[*]}"
read -n 10 ans
else
ans="y"
fi
if [ "$ans" == "y" ]; then
for files in ${LIST[@]}; do
scp -r deluge-user@serverhost:${FILE_PATH}$(printf "%q" "$files") "${STUFF}"
if [ $? -ne 0 ]; then fail=true; echo "Copy Failure"; exit; fi
done
printf "Torrents Copied\n"
else
printf "Nothing Copied\n"
fi
if [ "${ASSUMEYES}" == "false" ]; then
echo "Rename? (y/*)"
echo "${LIST[*]}"
read -n 10 ans
else
ans="y"
fi
if [ "$ans" == "y" ]; then
for files in ${LIST[@]}; do
echo "Rename $files"
filepath="${STUFF}${files}"
if [ -d "${filepath}" ]; then
echo "${filepath} is a Directory"
bash /home/lucas/scripts/rename_episodes.sh -del -files -dir -repair -path "${filepath}"
elif [ -f "${filepath}" ]; then
echo "${filepath} is a File"
bash /home/lucas/scripts/rename_episodes.sh -files -file "${filepath}"
else
echo "${filepath} neither Directory nor regular file"
fi
done
printf "Rename Complete\n"
else
printf "Nothing Renamed\n"
fi
if [ "${ASSUMEYES}" == "false" ]; then
echo "Delete? (y/*)"
echo "${LIST[*]}"
read -n 10 ans
else
ans="y"
fi
if [ "$ans" == "y" ]; then
for files in ${LIST[@]}; do
echo "Delete $files"
ssh deluge-user@serverhost rm -dr ${FILE_PATH}$(printf "%q" "$files")
done
printf "Torrents Removed\n"
else
printf "Nothing Removed\n"
fi
unset IFS; set +f