Last active
January 18, 2021 02:42
-
-
Save CoreyVidal/1c5118ea9bcfae12de988c1ec05fd310 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/bash | |
dev=0 | |
dir=$(pwd) | |
dirp1="$(dirname "$dir")" | |
dirp2="$(dirname "$dirp1")" | |
dirp3="$(dirname "$dirp2")" | |
echo | |
clear | |
if [[ "$dev" == 1 ]] | |
then | |
echo "**************************" | |
echo "* *" | |
echo -e "* \033[33mYou are in dev mode.\e[0m *" | |
echo "* *" | |
echo "**************************" | |
echo | |
fi | |
echo "The current folder is" | |
echo -e "\033[34m$dir\e[0m" | |
echo | |
if [[ "$dir" =~ .*Movies($|\/$|\$) ]] # /Movies | |
then # exits if you are in /Movies | |
echo "You are in the \"Movies\" folder." | |
echo | |
echo "ERROR:" | |
echo "Do not run this script here." | |
echo | |
echo -e "\033[33mPlease change the directory to a specific movie.\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
elif [[ "$dir" =~ (.*Movies \(HDR\)($|\/$|\$)) ]] # /Movies | |
then # exits if you are in /Movies (HDR) | |
echo "You are in the \"Movies (HDR)\" folder." | |
echo | |
echo "ERROR:" | |
echo "Do not run this script here." | |
echo | |
echo -e "\033[33mPlease change the directory to a specific movie.\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
elif [[ "$dir" =~ (.*Movies \(HDR\)\/[\-A-Za-z0-9\ \.\(\)]+($|\/$|\$)) ]] # /Movies/Title (2021) | |
then # success (movie) | |
echo "You are in an HDR movie folder." | |
echo -e "\033[32mYou can run this script here!\e[0m" | |
echo | |
elif [[ "$dir" =~ (.*Movies\/[\-A-Za-z0-9\ \.\(\)]+($|\/$|\$)) ]] # /Movies/Title (2021) | |
then # success (movie) | |
echo "You are in a movie folder." | |
echo -e "\033[32mYou can run this script here!\e[0m" | |
echo | |
elif [[ "$dir" =~ .*Shows($|\/$|\$) ]] # /TV Shows | |
then # exits if you are in /TV Shows | |
echo "You are in the \"TV Shows\" folder." | |
echo | |
echo "ERROR:" | |
echo "Do not run this script here." | |
echo | |
echo -e "\033[33mPlease change the directory to a specific show and season.\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
elif [[ "$dir" =~ (.*Shows\/[\-A-Za-z0-9\ \.\(\)]+($|\/$|\$)) ]] # /TV Shows/Title | |
then # exits if you are in /TV Shows/Title | |
echo "You are in the top folder for a specific show." | |
echo | |
echo "ERROR:" | |
echo "Do not run this script here." | |
echo | |
echo -e "\033[33mPlease change the directory to a specific season.\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
elif [[ "$dir" =~ (.*Shows\/[\-A-Za-z0-9\ \.\(\)]+\/[\-A-Za-z0-9\ \.\(\)]+($|\/$|\$)) ]] # /TV Shows/Title/Season 01 | |
then # success (TV show) | |
echo "You are in a season folder for a specific show." | |
echo -e "\033[32mYou can run this script here!\e[0m" | |
echo | |
else # exits if you are not in any compatible folder | |
echo "ERROR:" | |
echo "I am lost..." | |
echo | |
echo -e "\033[33mMaybe try running in a different folder?\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
fi | |
echo "Here is everything in this folder:" | |
echo | |
echo "inode links filesize filename" | |
LANG=en_US.UTF-8 ls -Alip, --color | awk '{printf "%-6s | ", $1} {printf "%s | ", $3} {printf ("%*.*-s", 18, 18, $6 " B")} {printf "%s", $10} {if ($11 ~ /^.+/) printf " " $11} {if ($12 ~ /^.+/) printf " " $12} {if ($13 ~ /^.+/) printf " " $13} {if ($14 ~ /^.+/) printf " " $14} {if ($15 ~ /^.+/) printf " " $15} {if ($16 ~ /^.+/) printf " " $16} {if ($17 ~ /^.+/) printf " " $17} {if ($18 ~ /^.+/) printf " " $18} {if ($19 ~ /^.+/) printf " " $19} {if ($20 ~ /^.+/) printf "\033[0m.../"} {printf "\033[0m\n"}' | tail -n+2 | |
echo | |
echo -n "Do you want to get started (y/n)? " # the first time a question is asked | |
old_stty_cfg=$(stty -g) | |
stty raw -echo | |
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) | |
stty $old_stty_cfg | |
if echo "$answer" | grep -iq "^y" # does the user want to get started? | |
then # yes - the user wants to get started | |
echo $answer | |
echo | |
echo "----------" | |
echo | |
echo "What is the name of the torrent?" | |
read -r torrentname | |
if [[ "$torrentname" =~ (^.*(\\|\/|\:|\*|\?|\"|\<|\>|\|).*$) ]] | |
then | |
echo | |
echo -e "\033[33mYou've used an illegal character.\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
elif [[ "$torrentname" = "" ]] | |
then | |
echo -e "\033[33mYou didn't enter anything!\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
fi | |
torrentnamebk=$torrentname | |
changes=0 | |
echo | |
echo "You entered:" | |
echo "$torrentname" | |
echo | |
echo -n "Is that correct (y/n)? " | |
old_stty_cfg=$(stty -g) | |
stty raw -echo | |
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) | |
stty $old_stty_cfg | |
if echo "$answer" | grep -iq "^y" # did user confirm torrentname? | |
then # yes - user confirmed torrentname | |
echo $answer | |
echo | |
echo "----------" | |
echo | |
if [[ $torrentname == *.torrent ]] # Does torrentname end with ".torrent"? | |
then # yes - torrentname ends with ".torrent" | |
if [[ "$dev" == 1 ]]; then echo "WARN: It ended with \"torrent\"." # only show this if we're in dev mode | |
fi | |
rmtorrentend=${torrentname%.torrent*} | |
((changes++)) | |
torrentname=${rmtorrentend} | |
else # no - torrentname does not end with ".torrent" | |
if [[ "$dev" == 1 ]]; then echo "INFO: I did not need to remove \".torrent\" from the ending." # only show this if we're in dev mode | |
fi | |
fi # end: Does torrentname end with ".torrent"? | |
if [[ $torrentname == \[BeyondHD\]* ]] # Does torrentname start with "[BeyondHD]"?" | |
then # yes - torrentname starts with "[BeyondHD]" | |
if [[ "$dev" == 1 ]]; then echo "WARN: It started with \"[BeyondHD]\"." # only show this if we're in dev mode | |
fi | |
rmBHDstart=${torrentname#*\[BeyondHD\]} | |
((changes++)) | |
torrentname=${rmBHDstart} | |
else # no - torrentname does not start with "[BeyondHD]" | |
if [[ "$dev" == 1 ]]; then echo "INFO: I did not need to remove \"[BeyondHD]\" from the beginning." # only show this if we're in dev mode | |
fi | |
fi # end: Does torrentname start with "[BeyondHD]"?" | |
if [[ $torrentname == *-12948 ]] # does torrentname end with "-12948"? | |
then # yes - torrentname ends with "-12948" | |
if [[ "$dev" == 1 ]]; then echo "WARN: It ended with \"-12948\"." # only show this if we're in dev mode | |
fi | |
rmBHDend=${torrentname%-12948*} | |
((changes++)) | |
torrentname=${rmBHDend} | |
else # no - the torrent name did not end with "-12948" | |
if [[ "$dev" == 1 ]]; then echo "INFO: I did not need to remove \"-12948\" from the ending." # only show this if we're in dev mode | |
fi | |
fi # end: does the torrent name end with "-12948"? | |
if [[ $changes = "0" ]] # were any changes made? | |
then # no - changes were not made | |
if [[ "$dev" == 1 ]]; then echo # only show this if we're in dev mode | |
fi | |
if [[ "$dev" == 1 ]]; then echo "I did not make any changes." # only show this if we're in dev mode | |
fi | |
elif [[ $changes = "1" ]] | |
then # yes - 1 change was made | |
if [[ "$dev" == 1 ]]; then echo # only show this if we're in dev mode | |
fi | |
echo -e "\033[33mI made $changes change.\e[0m" | |
else # yes - more than 1 change was made | |
if [[ "$dev" == 1 ]]; then echo # only show this if we're in dev mode | |
fi | |
echo -e "\033[33mI made $changes changes.\e[0m" | |
fi # end: were any changes made? | |
echo | |
if [[ "$dir" =~ .*\/Movies.*$ ]] # | |
then | |
dirdown=$dirp2"/Downloads/torrents/seeding" | |
if [[ "$dev" == 1 ]] # only show this if we're in dev mode | |
then | |
echo "We know that this is a movie in a \"Movies\" folder." | |
echo | |
fi | |
elif [[ "$dir" =~ .*\/TV\ Shows.*$ ]] # | |
then | |
dirdown=$dirp3"/Downloads/torrents/seeding" | |
if [[ "$dev" == 1 ]] | |
then | |
echo "We know that this is a season of a show in a \"TV Shows\" folder." # only show this if we're in dev mode | |
echo | |
fi | |
else | |
echo "ERROR:" | |
echo "I am lost..." | |
echo | |
echo -e "\033[33mMaybe try running in a different folder?\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
fi | |
dirfinal=$dirdown"/"$torrentname | |
echo "The current directory is" | |
echo -e "\033[34m$dir\e[0m" | |
if [[ "$dev" == 1 ]] # we only do this if we are in dev mode | |
then | |
if [[ "$dir" =~ .*\/Movies.*$ ]] # | |
then | |
echo "First, I am going to up 2 folders" | |
echo -e "\033[34m$dirp2\e[0m" | |
echo "Then I am going to go down in to" | |
echo -e "\033[34m$dirdown\e[0m" | |
elif [[ "$dir" =~ .*\/TV\ Shows.*$ ]] # | |
then | |
echo "First, I am going to up 3 folders" | |
echo -e "\033[34m$dirp3\e[0m" | |
echo "Then I am going to go down in to" | |
echo -e "\033[34m$dirdown\e[0m" | |
else | |
echo "ERROR:" | |
echo "I am lost..." | |
echo | |
echo -e "\033[33mMaybe try running in a different folder?\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
fi | |
echo "Then I am going to create this new folder:" | |
echo -e "\033[34m$torrentname\e[0m" | |
echo | |
echo "----------" | |
fi # end: we only do this if we are in dev mode | |
echo | |
if [[ -d $dirfinal ]] # does the destination folder already exist? | |
then # yes - the destination folder already exists | |
echo -e "\033[31mCRITICAL ERROR!\e[0m" | |
echo -e "\033[34m$dirfinal\e[0m" | |
echo "This folder already exists!" | |
echo | |
echo -e "\033[33mPlease fix this manually.\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
else # no - the final destination does not exist | |
echo "The final destination will be" | |
echo -e "\033[34m$dirfinal\e[0m" | |
echo | |
echo -n "Shall I create that new folder now (y/n)? " | |
old_stty_cfg=$(stty -g) | |
stty raw -echo | |
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) | |
stty $old_stty_cfg | |
if echo "$answer" | grep -iq "^y" # are we going to create a new folder? | |
then # yes - let's create a new folder | |
echo $answer | |
echo "Creating new folder..." | |
if [[ "$dev" == 1 ]] # check if we're in dev mode - if not?: make new folder | |
then # we are in dev mode | |
echo -e "\033[33m(You are in dev mode. The folder will not be created.)\e[0m" | |
else # we are not in dev mode | |
mkdir $dirfinal | |
fi # end: check if we're in dev mode - if not?: make new folder | |
echo "DONE" | |
echo | |
echo -e "\033[34m$dirfinal\e[0m now exists." | |
else # user has decided not to create a new folder | |
echo $answer | |
echo | |
echo -e "\033[33mWhat an enormous waste of time.\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
fi # end: are we going to create a new folder? | |
fi # end: does the destination folder already exist? | |
echo | |
echo "In that new folder I am going to hardlink these files:" | |
echo | |
ls -1 --color | |
echo | |
echo -n "Do you want to make the hardlinks now (y/n)? " | |
old_stty_cfg=$(stty -g) | |
stty raw -echo | |
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) | |
stty $old_stty_cfg | |
if echo "$answer" | grep -iq "^y" # are we actually going to hardlink the files? | |
then # yes - we are actually going to hardlink the files | |
echo $answer | |
echo | |
if [[ "$dev" == 1 ]]; # check if we're in dev mode - if not?: hardlink! | |
then # yes - we are in dev mode - do not hardlink | |
echo -e "\033[33mYou are in dev mode.\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
else # n0 - we are not in dev mode - let's hardlink | |
ln * "$dirfinal" | |
echo "It is done." | |
echo | |
echo -n "Do you want to check to see if the inodes match (y/n)? " | |
old_stty_cfg=$(stty -g) | |
stty raw -echo | |
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) | |
stty $old_stty_cfg | |
if echo "$answer" | grep -iq "^y" # are we going to test? | |
then # yes - we're going to test | |
echo $answer | |
echo | |
echo "OK, let's do some testing!" | |
echo "Here is the file information from the original directory:" | |
echo | |
echo -e "\033[34m$dir\e[0m" | |
echo "inode links filesize filename" | |
LANG=en_US.UTF-8 ls -Alip, --color "$dir" | awk '{printf "%-6s | ", $1} {printf "%s | ", $3} {printf ("%*.*-s", 18, 18, $6 " B")} {printf "%s", $10} {if ($11 ~ /^.+/) printf " " $11} {if ($12 ~ /^.+/) printf " " $12} {if ($13 ~ /^.+/) printf " " $13} {if ($14 ~ /^.+/) printf " " $14} {if ($15 ~ /^.+/) printf " " $15} {if ($16 ~ /^.+/) printf " " $16} {if ($17 ~ /^.+/) printf " " $17} {if ($18 ~ /^.+/) printf " " $18} {if ($19 ~ /^.+/) printf " " $19} {if ($20 ~ /^.+/) printf "\033[0m.../"} {printf "\033[0m\n"}' | tail -n+2 | |
echo | |
echo "And here is the file information from the new (seeding) directory:" | |
echo | |
echo -e "\033[34m$dirfinal\e[0m" | |
LANG=en_US.UTF-8 ls -Alip, --color "$dirfinal" | awk '{printf "%-6s | ", $1} {printf "%s | ", $3} {printf ("%*.*-s", 18, 18, $6 " B")} {printf "%s", $10} {if ($11 ~ /^.+/) printf " " $11} {if ($12 ~ /^.+/) printf " " $12} {if ($13 ~ /^.+/) printf " " $13} {if ($14 ~ /^.+/) printf " " $14} {if ($15 ~ /^.+/) printf " " $15} {if ($16 ~ /^.+/) printf " " $16} {if ($17 ~ /^.+/) printf " " $17} {if ($18 ~ /^.+/) printf " " $18} {if ($19 ~ /^.+/) printf " " $19} {if ($20 ~ /^.+/) printf "\033[0m.../"} {printf "\033[0m\n"}' | tail -n+2 | |
echo | |
echo "Goodbye." | |
exit | |
else # no - user has decided not to test | |
echo $answer | |
echo "OK, no testing." | |
echo "Goodbye." | |
exit | |
fi # end: are we going to test? | |
fi # end: check if we're in dev mode - if not?: hardlink! | |
else # no - no - user has decided not to hardlink the files | |
echo "What is wrong with you?" | |
exit | |
fi # end: are we actually going to hardlink the files?" | |
else # no - user did not confir torrentname | |
echo $answer | |
echo | |
echo -e "\033[33mOops! You screwed up.\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
fi # end: did user confirm torrentname? | |
else # no - the user does not want to get started | |
echo $answer | |
echo | |
echo -e "\033[33mCome back when you are ready.\e[0m" | |
echo -e "\033[31mTerminated.\e[0m" | |
echo | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment