Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.19 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # v1.0.3 nwgat
  4. #
  5. # Credits: A heavily modified version of this idea and script http://www.torrent-invites.com/showthread.php?t=132965 towards a simplified end user experience.
  6. # Authors: Lordhades - Adamaze - userdocs
  7. # Script URL: https://git.io/v6Mza
  8. # wget -qO ~/lftpsync.sh https://git.io/v6Mza
  9. #
  10. #### Editing option 0 is only required if you need to specify the tmp directory. This is the location the lock file, PID file and log file are created and checked by this script.
  11. ### Editing options 1 is only required if you have set have a private key you wish to use
  12. ## Editing options 2 - 5 is required.
  13. # Editing options 6 - 10 is optional.
  14. #
  15. # 0: Optional - This variable specifies the location of the tmp folder to use for the lock, PID and log file. This default should be working on both linux and windows at the same time. On Linux by using the /tmp folder and Windows by using the included tmp folder in the lftp directory. You should not need to change this unless you want to specify the tmp directory for debugging.
  16. tmpdir="/tmp"
  17. # 1: Optional - This variable will specify the path to the key folder where the script will look for your ssh private keyfiles. You will probably need to change this on linux if you are using private keys to something relative like ~/.ssh
  18. keydirectory="/keys"
  19. # If you place a private key in the key folder you can give the script the exact name of this file here including the file extension if applicable.
  20. keyname=""
  21. # 2: Your sftp/ftp username goes here replacing username inside the double quotes.
  22. username="USERNAME"
  23. # 3: Your sftp/ftp password. If you have set up a private key file then you can ignore this variable and leave it as it is.
  24. password="PASSWORD"
  25. # 4: Your seedbox server URL/hostname
  26. hostname="SERVER.SEEDBOX.COM"
  27. # 5: The remote directory on the seedbox you wish to mirror from. Can now be passed to the script directly using "$1". It must exist on the remote server.
  28. remote_dir='/REMOTE/DIR'
  29. # 6: Optional - The local directory your files will be mirrored to. It is relative to the portable folder and will be created if it does not exist so the default setting will work.
  30. local_dir="/LOCAL/DIR"
  31. # 7: Optional - Set the SSH port if yours is not the default.
  32. port="22"
  33. # 8: Optional - The number of parallel files to download. It is set to download 1 file at a time.
  34. parallel="1"
  35. # 9: Optional - set maximum number of connections lftp can open
  36. default_pget="20"
  37. # 10: Optional - Set the number of connections per file lftp can open
  38. pget_mirror="20"
  39. # 11: Optional - Add custom arguments or flags here.
  40. #args="-c -e --only-newer --ignore-time"
  41. #
  42. [[ ! -z "$1" ]] && remote_dir="$1"
  43. #
  44. base_name="$(basename "$0")"
  45. lock_file="$tmpdir/$base_name.lock"
  46. #
  47. # This checks to see if LFTP is actually running and if the lock file exists. It LFTP is not running and there is a lock file it will be automatically cleared allowing the script to run.
  48. [[ -z $(ps -p $(sed -rn 's/\[(.*)\](.*)/\1/p;1q' $tmpdir/$base_name.PID 2> /dev/null) 2> /dev/null | awk 'FNR==2{print $1}') ]] && rm -f "$tmpdir/$base_name.PID" "$lock_file" "$tmpdir/$base_name.log"
  49. #
  50. trap "rm -f $lock_file" SIGINT SIGTERM
  51. #
  52. if [[ -f "$lock_file" ]]
  53. #
  54. then
  55.     echo "$base_name is running already."
  56.     exit
  57. else
  58.     touch "$lock_file"
  59.     lftp -e "debug -Tpo $tmpdir/$base_name.PID 0;set sftp:connect-program ssh -a -x -i $keydirectory/$keyname" -p "$port" -u "$username,$password" "sftp://$hostname" <<-EOF
  60.     set sftp:auto-confirm yes
  61.     set mirror:parallel-transfer-count "$parallel"
  62.     set pget:default-n $default_pget
  63.     set mirror:use-pget-n $pget_mirror
  64.     mirror $args --log="$tmpdir/$base_name.log" "$remote_dir/Games" "$local_dir/Games"
  65.     mirror $args --log="$tmpdir/$base_name.log" "$remote_dir/Misc" "$local_dir/Misc"
  66.     mirror $args --log="$tmpdir/$base_name.log" "$remote_dir/Movies" "$local_dir/Movies"
  67.     mirror $args --log="$tmpdir/$base_name.log" "$remote_dir/Music" "$local_dir/Music"
  68.     mirror $args --log="$tmpdir/$base_name.log" "$remote_dir/Software" "$local_dir/Software"
  69.     mirror $args --log="$tmpdir/$base_name.log" "$remote_dir/TV Shows" "$local_dir/TV Shows"
  70.     quit
  71.     EOF
  72.     #
  73.     rm -f "$tmpdir/$base_name.PID" "$lock_file" "$tmpdir/$base_name.log"
  74.     #
  75.     trap - SIGINT SIGTERM
  76.     exit
  77. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement