-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestore.sh
executable file
·52 lines (44 loc) · 1.15 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
#!/bin/bash
readlinkorreal() { readlink "$1" || echo "$1"; }
backup_path="${backup_path:=$1}"
: "${backup_path:?Missing backup_path, provide as argument (relative to home dir)}"
d=$(dirname "$0")
files_from=$(readlinkorreal "$d")/restore.bom
backup_path_resolved=$(readlinkorreal "$backup_path")
shift
function doIt() {
echo "Restoring from ${backup_path_resolved} to $HOME...";
echo "";
mkdir .tmp-backup-dir
cd .tmp-backup-dir && tar -xzf ${backup_path_resolved};
rsync \
--rsync-path="sudo rsync" \
--perms \
--recursive \
--compress \
--numeric-ids \
--links \
--hard-links \
--files-from="$files_from" \
-avh . ~;
if which gpg > /dev/null && [ -f "./key_public.asc" ]; then
gpg --import --armor ./key_public.asc
rm ./key_public.asc
fi
if which gpg > /dev/null && [ -f "./key_secret.asc" ]; then
gpg --import --armor ./key_secret.asc
rm ./key_secret.asc
fi
cd - && rm -rf .tmp-backup-dir;
echo "Restored";
}
if [ "$1" == "--force" ] || [ "$1" == "-f" ]; then
doIt;
else
read -rp "Do you want to restore ${backup_path} to ~? (y/n) " -n 1;
echo "";
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
doIt;
fi;
fi;
unset doIt;