-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-conf.sh
69 lines (49 loc) · 1.65 KB
/
backup-conf.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
#!/bin/bash
declare -a FILES_TO_COPY=(
"$HOME/.ssh"
"$HOME/.gnupg"
"$HOME/.zhistory"
"$HOME/.gitconfig.local"
"$HOME/Library/Application Support/Sublime Text 3/Packages/User/Preferences.sublime-settings"
"/etc/hosts"
"/usr/local/etc/php/5.4/php.ini"
"/usr/local/etc/php/5.4/conf.d/ext-xdebug.ini"
"/etc/apache2/httpd.conf"
"/etc/apache2/extra/httpd-vhosts.conf"
)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
main() {
declare -r MIGRATION_DIR="$HOME/migration"
local sourceFile=""
local targetFile=""
local copyParams=""
# Ensure that the following actions are made
# relative to the dotfiles directory root
# http://mywiki.wooledge.org/BashFAQ/028
cd "$(dirname "${BASH_SOURCE}")";
source ./os/utils.sh
# Prepare migration folder
if [ -d "$MIGRATION_DIR" ]; then
ask_for_confirmation "'$MIGRATION_DIR' already exists, do you want to overwrite it?"
if answer_is_yes; then
rm -r "$MIGRATION_DIR"
else
print_error "Backup interrupted" && exit
fi
fi
mkd "$MIGRATION_DIR"
# Copy files/folders
for sourceFile in "${FILES_TO_COPY[@]}"; do
targetFile="$MIGRATION_DIR/$(printf "%s" "$sourceFile" | sed -e "s/.*\/\(.*\)/\1/g" -e "s/^\.\(.*\)/\1/g")"
copyParams=""
if [ -e "$sourceFile" ]; then
if [ -d "$sourceFile" ]; then
copyParams="-r"
fi
execute "cp $copyParams $sourceFile $targetFile" "$sourceFile → $targetFile"
else
print_error "skipped $sourceFile as non existant"
fi
done
}
main