diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-07-29 11:49:08 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-07-29 11:49:08 +0200 |
commit | eeb2fac3028837fae0db3d816acf6d8bd0050120 (patch) | |
tree | bea1ae72d56ee4ee90c1e043d290f7562b264566 /bin/common | |
parent | 5e466abb6ef19e8be2674d67b94e43ccfbfce33f (diff) |
added sync-install.sh
Diffstat (limited to 'bin/common')
-rwxr-xr-x | bin/common/sync-install.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/bin/common/sync-install.sh b/bin/common/sync-install.sh new file mode 100755 index 0000000..e26c74d --- /dev/null +++ b/bin/common/sync-install.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +die () +{ + echo "$@" >&2 +} + +read_char () +{ + old_stty_cfg=$(stty -g) + stty raw -echo + dd ibs=1 count=1 2> /dev/null + stty $old_stty_cfg +} + +confirm () +{ + printf "$1 " + read_char | grep "[yY]" +} + +usage() +{ + >&2 printf 'Usage: %s <remote> <destination>\n' "${0##*/}" +} + +[ $# -lt 2 ] && usage && exit 1 +REMOTE="$1" +DEST="$2" +SCRIPT="${3:-sync.sh}" + +if ! ssh $REMOTE test -w $DEST 2> /dev/null +then + die "Not a valid remote or destination." + exit 1 +fi + +die "─────────────────────────────────────────────────────────────" +cat <<EOF | tee "$SCRIPT" >&2 +#!/bin/sh + +THISDIR="\$(dirname "\$(readlink -f "\$0")")" +inotifywait -m -e create,modify,delete --format "%f" "\$THISDIR" | +while read FILE +do + rsync -aP "\$THISDIR/" "$REMOTE:$DEST" + sleep 1m +done +EOF +die "─────────────────────────────────────────────────────────────" +die "located at $(readlink -f "$SCRIPT")" + +if confirm "good?" +then + chmod +x "$SCRIPT" +else + rm -f "$SCRIPT" +fi |