Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #!/bin/bash
  2. #### Seedbox Sync
  3. #
  4. # Sync various directories between home and seedbox, do some other things also.
  5. #
  6. # To use rsync, this script requires you have ssh key based logins with no passphrase
  7. # set up between the user this script runs as and your seedbox.
  8.  
  9. logdir="/var/log/nasbox"
  10. xferlog="xferlog.log"
  11.  
  12. log="$logdir/$xferlog"
  13.  
  14. # folders where music/videos would be in, used in a grep pattern so separate folder names with a pipe |
  15. # only use music/video folder names here you want beets/filebot to process, so if you don't want filebot to
  16. # process your porn, dont list it here.
  17. music_tags="flac" # I need the flac folder to go into
  18. video_tags="movie|tv|anime"
  19.  
  20. host="HIDDEN"
  21. user="guess"
  22. # leave empty if you use a key
  23. pass="**************"
  24.  
  25. # Location of remote files ready for pickup, no trailing slash
  26. remote_media="~/complete"
  27. # Destination for remote media to be stored for further processing
  28. local_media="/media/data"
  29.  
  30. # choices are rysnc or lftp
  31. sync_method="lftp"
  32.  
  33. # Are there any blackhole torrent directories we want to sync?
  34. # e.g. - tools like headphones that can't talk to rtorrent can drop torrent files somewhere, we can sync them up to a watch dir
  35. sync_blackholes=false
  36. local_blackhole="/foo/bar"
  37. remote_watch="/remote/watch"
  38.  
  39. # Process video with filebot?
  40. use_filebot=true
  41. filebot_script="/usr/local/bin/filebot-process.sh"
  42.  
  43. # Process music with beets?
  44. use_beets=false
  45. beets_script="/usr/local/bin/beets-process.sh"
  46.  
  47. base_name="$(basename "$0")"
  48. lock_file="/tmp/$base_name.lock"
  49. trap "rm -f $lock_file" SIGINT SIGTERM
  50. if [[ -e "$lock_file" ]]; then
  51. echo "$base_name is running already."
  52. exit
  53. fi
  54.  
  55. touch "$lock_file"
  56.  
  57. if [[ -f $log ]]; then
  58. mv $log $log.last
  59. fi
  60.  
  61. if [[ "$sync_method" == "rsync" ]]; then
  62. rsync -av --ignore-existing --remove-source-files --prune-empty-dirs \
  63. --log-file=$log \
  64. --log-file-format="%f - %n" \
  65. ${host}:${remote_media}/ \
  66. ${local_media}/
  67. elif [[ "$sync_method" == "lftp" ]]; then
  68. lftp -p 22 -u ${user},${pass} sftp://"$host" << LFTP
  69. set xfer:log true
  70. set xfer:log-file "$log"
  71. set sftp:auto-confirm yes
  72. set mirror:use-pget-n 10
  73. mirror -n -c -P10 --Remove-source-files "$remote_media" "$local_media"
  74. quit
  75. LFTP
  76.  
  77. else
  78. echo "No valid sync method chosen"
  79. fi
  80.  
  81. music=1
  82. video=1
  83. # See what got transferred
  84. if [[ -f $log ]]; then
  85. # log file exists, so something got transferred
  86. music=$( cat $log | grep -qE "${music_tags}" )
  87. video=$( cat $log | grep -qE "${video_tags}" )
  88. fi
  89.  
  90. if [[ "$sync_blackholes" == true ]]; then
  91. rsync -av --ignore-existing --remove-source-files \
  92. ${local_blackhole}/ \
  93. ${host}:${remote_watch}/
  94. fi
  95.  
  96. if [[ "$use_filebot" == true && $video -eq 0 ]]; then
  97. eval $filebot_script
  98. fi
  99.  
  100. if [[ "$use_beets" == true && $music -eq 0 ]]; then
  101. eval $beets_script
  102. fi
  103.  
  104. rm -f "$lock_file"
  105. trap - SIGINT SIGTERM
  106. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement