refactor: improve torrent transfer workflow
refactor: improve torrent transfer workflow - replace unsafe word splitting with Bash arrays - improve command-line argument parsing - centralize remote and local configuration - replace remote ls parsing with find - simplify confirmation handling - improve SSH and SCP error handling - safely quote local paths and filenames - separate copy, rename, and delete operations - add comprehensive usage documentation
This commit is contained in:
1 parent
081210d3ae
commit
da2981a5be
2 files changed
+376
-145
No files matched your search
@@ -1,145 +0,0 @@
|
||||
#!/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
|
||||
|
||||
Reference in new issue
Block a user