forked from nevesnunes/env
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·50 lines (42 loc) · 850 Bytes
/
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
#!/usr/bin/env bash
set -ux
role=$1
[ -d "$role" ]
target=${2:-/home/$USER/}
git add -A
git commit -m 'sync'
git pull
set -e
dirty_name=$(date +%s)
git checkout -b "$dirty_name"
cleanup() {
err=$?
git branch -D "$dirty_name"
trap '' EXIT
exit $err
}
trap cleanup EXIT INT QUIT TERM
repo_path=$(realpath .)
while read -r role_file; do
local_role_file="${role_file//$repo_path/}"
local_file="$target/${local_role_file//$role/}"
[ -f "$local_file" ] || continue
git diff \
--no-index \
--quiet \
"$local_file" \
"$role_file" || \
cp "$local_file" "$role_file"
done < <(find "$(realpath ./"$role")" -type f)
set +e
git add -A
git commit -m 'sync'
set -e
git checkout master
git merge \
--allow-unrelated-histories \
--no-edit \
-Xignore-all-space \
-Xpatience \
"$dirty_name"
#git push origin master