-
-
Save gallo-s-chingon/83125358cd6370ce4c6ee93a70a1e95e to your computer and use it in GitHub Desktop.
Sync -edited for my purposed
This file contains 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
#!/bin/bash | |
#### Seedbox Sync | |
# | |
# Sync various directories between home and seedbox, do some other things also. | |
# | |
# To use rsync, this script requires you have ssh key based logins with no passphrase | |
# set up between the user this script runs as and your seedbox. | |
logdir="/home/gyo/.config/log" | |
xferlog="xferlog.log" | |
log="$logdir/$xferlog" | |
# folders where music/videos would be in, used in a grep pattern so separate folder names with a pipe | | |
# only use music/video folder names here you want beets/filebot to process, so if you don't want filebot to | |
# process your porn, dont list it here. | |
#music_tags="flac" # I need the flac folder to go into | |
video_tags="cine|series" | |
host="HIDDEN" | |
user="guess" | |
# leave empty if you use a key | |
pass="**************" | |
# Location of remote files ready for pickup, no trailing slash | |
remote_media="/home/gallo/files/done" | |
# Destination for remote media to be stored for further processing | |
local_media="/datapool/files" | |
# choices are rysnc or lftp | |
sync_method="lftp" | |
# Are there any blackhole torrent directories we want to sync? | |
# 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 | |
sync_blackholes=false | |
local_blackhole="/foo/bar" | |
remote_watch="/remote/watch" | |
# Process video with filebot? | |
use_filebot=true | |
filebot_script="/usr/local/bin/filebot-process.sh" | |
# Process music with beets? | |
use_beets=false | |
beets_script="/usr/local/bin/beets-process.sh" | |
base_name="$(basename "$0")" | |
lock_file="/tmp/$base_name.lock" | |
trap "rm -f $lock_file" SIGINT SIGTERM | |
if [[ -e "$lock_file" ]]; then | |
echo "$base_name is running already." | |
exit | |
fi | |
touch "$lock_file" | |
if [[ -f $log ]]; then | |
mv $log $log.last | |
fi | |
if [[ "$sync_method" == "rsync" ]]; then | |
rsync -av --ignore-existing --remove-source-files --prune-empty-dirs \ | |
--log-file=$log \ | |
--log-file-format="%f - %n" \ | |
${host}:${remote_media}/ \ | |
${local_media}/ | |
elif [[ "$sync_method" == "lftp" ]]; then | |
lftp -p 22 -u ${user},${pass} sftp://"$host" << LFTP | |
set xfer:log true | |
set xfer:log-file "$log" | |
set sftp:auto-confirm yes | |
set mirror:use-pget-n 50 | |
mirror -n -c -P6 --Remove-source-files "$remote_media" "$local_media" | |
quit | |
LFTP | |
else | |
echo "No valid sync method chosen" | |
fi | |
music=1 | |
video=1 | |
# See what got transferred | |
if [[ -f $log ]]; then | |
# log file exists, so something got transferred | |
music=$( cat $log | grep -qE "${music_tags}" ) | |
video=$( cat $log | grep -qE "${video_tags}" ) | |
fi | |
if [[ "$sync_blackholes" == true ]]; then | |
rsync -av --ignore-existing --remove-source-files \ | |
${local_blackhole}/ \ | |
${host}:${remote_watch}/ | |
fi | |
if [[ "$use_filebot" == true && $video -eq 0 ]]; then | |
eval $filebot_script | |
fi | |
if [[ "$use_beets" == true && $music -eq 0 ]]; then | |
eval $beets_script | |
fi | |
rm -f "$lock_file" | |
trap - SIGINT SIGTERM | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment