-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsync.sh
executable file
·50 lines (43 loc) · 1.06 KB
/
sync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env sh
set -eu
_VERSION='1.5.0'
# Show usage.
_usage() {
echo "usage: ${0##*/} [-t|--tty] [-p|--port num] <server>..."
}
# Main entry point.
_main() {
SSH_CMD=ssh
hosts=''
for arg; do
case "$arg" in
-t|--tty) SSH_CMD="${SSH_CMD} -tt";;
-p|--port) shift; SSH_CMD="${SSH_CMD} -p $arg";;
-h|--help) _usage; exit ;;
-v|--version) echo "${0##*/} v${_VERSION}"; exit ;;
-*) echo "Warning, unrecognized option $arg" >&2;;
*) hosts="$hosts $arg";;
esac
shift
done
# shellcheck disable=SC2086
set -- $hosts
# Validate
if [ -z "${1+set}" ]; then
_usage
exit 1
fi
for host; do
echo ":: [${host}] copy dotfiles to remote"
if ! rsync -rltz -e "${SSH_CMD}" ./.files/ "$host":./ || \
! rsync -rltzP -e "${SSH_CMD}" ./bin "$host":./.local/
then
echo "[ERROR] failed rsync dotfiles to '${host}'" && exit 2
fi
echo ":: [${host}] bootstrap remote"
${SSH_CMD} "$host" NO_DOWNLOAD=1 NO_INTRO=1 sh -- \
< "$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)"/sync.lib.sh
done
echo ':: sync completed'
}
_main "$@"