fant0men

Remote rip bash script

Oct 20th, 2019
159
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # This script creates an infinite while loop, which checks ~/rip
  4. # every 1 second, to see if 'switch.txt' has been changed from
  5. # '0' to '1'. If the text file has been changed to 1, then feed the
  6. # other file in the directory to 'bluray_remux2hevc.sh'.
  7. # If 'grain.txt' is set to 1, then use the '-grain' flag to
  8. # 'bluray_remux2hevc.sh'.
  9.  
  10. # I'm running this script on a laptop. To prevent it from
  11. # suspending when the lid is closed:
  12. # You may want to change '/etc/systemd/logind.conf',
  13. # specifically the line: HandleLidSwitch=ignore
  14. # Then reload logind.conf: systemctl restart systemd-logind
  15.  
  16. # If you run Ubuntu, or a flavor thereof, you may also want to change
  17. # '/etc/sysctl.d/10-magic-sysrq.conf', specifically the line:
  18. # kernel.sysrq = 1
  19. # This is needed for all Magic SysRq commands to work. For example,
  20. # you may freeze your keyboard, and need to reset it using
  21. # alt+prntscrn+r
  22.  
  23. # If set, bash matches filenames in a case-insensitive fashion
  24. # when performing pathname expansion.
  25. shopt -s nocaseglob
  26.  
  27. # Changes into 'lucifer', in the home directory of the current user.
  28. cd ~/lucifer
  29.  
  30. # Stops the ACPI (power saving) daemon.
  31. #sudo systemctl mask acpid acpid.path acpid.socket
  32.  
  33. # Stops the login manager.
  34. sudo service lightdm stop
  35. killall -9 xiccd
  36.  
  37. # Sets the TTY to blank the screen after 1 minute of inactivity.
  38. # Turns off powersave features of the TTY.
  39. setterm --blank 1 --powersave off --powerdown 0
  40.  
  41. # This function uses a directory as input, finds the biggest M2TS file,
  42. # and echoes it.
  43. m2ts () {
  44.  
  45.     big=0
  46.  
  47.     for m2ts_tmp in "${1}"/BDMV/STREAM/*.m2ts; do
  48.  
  49.         size=$(du -b "$m2ts_tmp" | tr '[:space:]' ' ' | cut -d' ' -f1)
  50.  
  51.         if [[ $size -gt $big ]]; then
  52.  
  53.             big="$size"
  54.             out_f="$m2ts_tmp"
  55.         fi
  56.     done
  57.  
  58.     echo "$out_f"
  59. }
  60.  
  61. while true; do
  62.  
  63.     sleep 1
  64.  
  65.     # Sets the $switch variable to the content of 'switch.txt'.
  66.     switch=$(cat 'switch.txt')
  67.  
  68.     # If $switch is set to '1', then...
  69.     if [[ $switch -eq 1 ]]; then
  70.  
  71.         mapfile -t files < <(find . -type f -iname "*.mkv" -o -type f -iname "*.m2ts" -o -type d -iname "*" | tail -n +2 | sed 's|^./||')
  72.  
  73.         # Loops through the files in the current directory.
  74.         for (( i = 0; i < ${#files[@]}; i++ )); do
  75.  
  76.             f="${files[${i}]}"
  77.  
  78.             # Set 'switch.txt' to 0.
  79.             echo '0' > 'switch.txt'
  80.  
  81.             # If file is actually a directory, run the 'm2ts'
  82.             # function, which will echo a filename.
  83.             if [[ -d $f ]]; then
  84.  
  85.                 f_tmp=$(m2ts "$f")
  86.                 f="$f_tmp"
  87.             fi
  88.  
  89.             # Sets the $grain variable to the content of
  90.             # 'grain.txt'.
  91.             grain=$(cat 'grain.txt')
  92.             anime=$(cat 'anime.txt')
  93.  
  94.             # If the $grain variable is set to 1, use the '-grain'
  95.             # flag to 'bluray_remux2hevc.sh'. Otherwise, don't.
  96.             if [[ $grain -eq 1 ]]; then
  97.  
  98.                 # Set 'grain.txt' to 0.
  99.                 echo '0' > 'grain.txt'
  100.  
  101.                 ~/bin/bluray_remux2hevc.sh "$f" -grain
  102.             elif [[ $anime -eq 1 ]]; then
  103.  
  104.                 # Set 'anime.txt' to 0.
  105.                 echo '0' > 'anime.txt'
  106.  
  107.                 ~/bin/bluray_remux2hevc.sh "$f" -anime
  108.             else
  109.  
  110.                 ~/bin/bluray_remux2hevc.sh "$f"
  111.             fi
  112.  
  113.             # Breaks this for loop, since we're done here.
  114.             break
  115.         done
  116.     fi
  117. done
RAW Paste Data