diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-08-04 22:45:56 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-08-04 22:45:56 +0200 |
commit | 1914d16f1693a3c31f8ad9e07b1469df1604d690 (patch) | |
tree | a8a623823adc077f7371de379b9e70eb7a7b485c /bin/common/sync-install.sh | |
parent | 49bbf6906089b5d957e2a781002d32b811ae630d (diff) | |
parent | e850f3a1702b4d8b9d0cfec5c07d710b5201ed29 (diff) |
Merge branch 'main' of /var/git/dotfiles
Diffstat (limited to 'bin/common/sync-install.sh')
-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 |