-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestore.sh
78 lines (68 loc) · 1.32 KB
/
restore.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
71
72
73
74
75
76
77
78
#!/bin/bash
set -euo pipefail
help() {
cat <<- EOF
Usage: bash restore.sh [OPTIONS] [TARGET_FOLDER]
--help Show this message
--linux
--mac
--vm
--windows
EOF
}
PLATFORM=''
while getopts ':-:' flag; do
case "${flag}" in
-)
case "${OPTARG}" in
linux|mac|vm|windows)
PLATFORM=$OPTARG
;;
help)
help
exit 0
;;
esac;;
*)
echo "Unknown option: $flag"
help
exit 1
;;
esac
done
# Last args
shift $((OPTIND - 1))
TARGET_FOLDER="$*"
if [[ -z $PLATFORM || $# -gt 1 ]]; then
help
exit 1
fi
# Execute syncing process
TARGET_FOLDER="${TARGET_FOLDER:-$HOME}"
DOTFILES_ROOT=$(dirname "$(realpath "$0")")
function run_rsync() {
rsync_file_path="$DOTFILES_ROOT/$1/rsync.conf"
source_folder="$DOTFILES_ROOT/$1/dotfiles"
rsync -avi --recursive --relative --exclude='*.swp' --files-from="$rsync_file_path" "$source_folder" "$TARGET_FOLDER"
echo ""
echo "Finished restoring ${source_folder/$HOME/\~} to $TARGET_FOLDER"
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