-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
70 lines (61 loc) · 1.12 KB
/
backup.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
set -euo pipefail
help() {
cat << EOF
Usage: bash backup.sh [OPTIONS]
--help Show this message
--linux
--mac
--vm
--windows
EOF
}
PLATFORM=""
for opt in "$@"; do
case $opt in
--linux|--mac|--vm|--windows)
PLATFORM=$opt
;;
--help)
help
exit 0
;;
*)
echo "Unknown option: $opt"
help
exit 1
;;
esac
done
if [[ -z $PLATFORM ]]; then
help
exit 1
fi
# Execute syncing process
DOTFILES_ROOT=$(dirname "$(realpath "$0")")
function run_rsync() {
rsync_file_path="$DOTFILES_ROOT/$1/rsync.conf"
target_folder="$DOTFILES_ROOT/$1/dotfiles"
rsync -avi --recursive --relative --delete --exclude='*.swp' --files-from="$rsync_file_path" "$HOME" "$target_folder"
echo ""
echo "Finished backing up dotfiles to ${target_folder/$HOME/\~}"
echo "========================================================="
echo ""
}
case $PLATFORM in
--linux)
run_rsync shared
run_rsync linux
;;
--mac)
run_rsync shared
run_rsync mac
;;
--vm)
run_rsync vm
;;
--windows)
run_rsync shared
run_rsync windows
;;
esac