diff options
Diffstat (limited to 'ssync-queue')
| -rwxr-xr-x | ssync-queue | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/ssync-queue b/ssync-queue index 25fa1cd..ddc97d3 100755 --- a/ssync-queue +++ b/ssync-queue @@ -2,25 +2,32 @@ USAGE="ssync-queue [options] -l LOCAL_INDEX_FILE -r REMOTE_INDEX_FILE -o QUEUE_OUTPUT_FILE OPTIONS + -k keep temp files -l LOCAL_INDEX_FILE - target local index file - -r REMOTE_INDEX_FILE - target remote index file - -o QUEUE_OUTPUT_FILE - queue output file - -v verbose logging + target local index file + -r REMOTE_INDEX_FILE + target remote index file + -o QUEUE_OUTPUT_FILE + queue output file + -v verbose logging -h print this message" # HELPER FUNCTIONS verbose_log() { if [ ! -z "$VERBOSE_FLAG" ]; then - echo "$@" + echo "$@" fi } lines() { echo $(wc -l $1 | cut -d' ' -f1) } +remove_file() { + if [ -f "$1" ]; then + verbose_log "Removing $1" + rm $1 + fi +} # OPTIONS @@ -32,23 +39,26 @@ CONFIG_FILE_FLAG= LOCAL_FILE_ARG= REMOTE_FILE_ARG= QUEUE_FILE_ARG= +KEEP_FLAG= -while getopts "hvl:r:o:" opt; do +while getopts "hvkl:r:o:" opt; do case "${opt}" in - l) LOCAL_FILE_FLAG=1 - LOCAL_FILE_ARG="${OPTARG}" - ;; - r) REMOTE_FILE_FLAG=1 - REMOTE_FILE_ARG="${OPTARG}" - ;; - o) QUEUE_FILE_FLAG=1 - QUEUE_FILE_ARG="${OPTARG}" - ;; - v) VERBOSE_FLAG=1 - ;; - h) echo "$USAGE" - exit 1 + k) KEEP_FLAG=1 ;; + l) LOCAL_FILE_FLAG=1 + LOCAL_FILE_ARG="${OPTARG}" + ;; + r) REMOTE_FILE_FLAG=1 + REMOTE_FILE_ARG="${OPTARG}" + ;; + o) QUEUE_FILE_FLAG=1 + QUEUE_FILE_ARG="${OPTARG}" + ;; + v) VERBOSE_FLAG=1 + ;; + h) echo "$USAGE" + exit 1 + ;; esac done @@ -103,3 +113,9 @@ verbose_log "Found $(lines $remote_only_filenames_file) remote only files" cat $remote_only_filenames_file | xargs -I{} grep -F "{}" $REMOTE_FILE_ARG >> $QUEUE_FILE_ARG verbose_log "Added $(lines $QUEUE_FILE_ARG) to the queue" +if [ -z "$KEEP_FLAG" ]; then + verbose_log "Clearing temp files" + remove_file $local_sorted + remove_file $remote_sorted + remove_file $remote_only_filenames_file +fi |