Blog Hoch
Jun 2019·1 tup leghDe'wI' ghItlhta'

Autopush - changed files upload simple

#auf-server-hochladen#auto-upload#automatisch-hochladen#autopush-to-server#autoupload#dateien-aktualisieren#hochladen#upload#upload-to-server

webdesign/webdevelopment workflow simplify vaD small Autopush script vIghItlh. script specific folder 'ej subfolders Hoch changes watch, changed files SCP remote server Daq upload. local develop 'ej changes server Daq direct push neH (manual upload reH pagh) vaj script Dun :) reH: damage liability pagh.

qatlh:

  1. SSH key server authenticate poQ (pagh vaj Bash script minimal adapt).
  2. fswatch install poQ.

Autopush Qu': ini-format Autopush config file chenmoH (Bash script first parameter). Autopush file:

  • remote_host= files push host. domain pagh IP. SSH keys qaw.
  • remote_username= server authenticate username.
  • remote_mapping= mapping path. local_source changes remote_mapping relative upload.
  • local_source= local path (watch 'ej push).
  • exclude=source,_Server files push pagh, watch exclude.

legh: .DS_Store files programmatically exclude (explicitly specify poQ pagh).

local_source folder script watch, file choH vaj

scp local_file_path remote_username@remote_host:/remote_mapping/absolute_local_path

server Daq load. Bash script call:

autopush.sh /Pfad/zur/Config.ini

complete script:

#!/bin/sh
if [ $# -eq 1 ]; then
    CONFIGFILE=$1
    . $1
    echo "Autopushing '$local_source' now..."
    /usr/local/bin/fswatch -0 "$local_source" | xargs -0 -n 1 sh $0 0 $CONFIGFILE
elif [ $# -eq 2 ] && [ $2="--fullsync" ]; then
    CONFIGFILE=$1
    . $1
    echo "Fullsyncing '$local_source' now..."
    scp -r $local_source/* $remote_username@$remote_host:$remote_mapping
else
    CONFIGFILE=$2
    FILE=$3
    . $CONFIGFILE
    length_local_source=${#local_source}
    length_changed_file_absolute=${#FILE}
    length_changed_file_relative=$((0-length_local_source-length_changed_file_absolute))
    relative_path=${FILE:$length_local_source}
    donotpush=(${exclude//,/ })
    donotpush+=($CONFIGFILE)
    donotpush+=(".DS_Store")
    for i in "${donotpush[@]}"
    do
        if [[ $FILE == *$i* ]]; then
            echo "[STOP] DO NOT PUSH $FILE (MATCHES '$i')"
            exit
        fi
    done
    remote_target="$remote_mapping$relative_path"
    if [ -d "$FILE" ] || [ -f "$FILE" ]; then
        echo "[CHANGE] `date '+%Y-%m-%d %H:%M:%S'` $relative_path -> $remote_target";
        scp -r $FILE $remote_username@$remote_host:$remote_target
    else
        echo "[DELETE] rm -rf $remote_target";
        ssh $remote_username@$remote_host "rm -rf $remote_target"
    fi
fi
chu'Brand-new MacBook silently offqanCentOS - Server essentials