forked from firetech/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·80 lines (69 loc) · 1.64 KB
/
install
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
79
80
#!/usr/bin/env zsh
target="${HOME:A}"
source="${0:A:h}/config"
backup="${0:A:h}/backup/$(date +%Y%m%d_%H%M%S)"
abs_source=$source
source="${source/$target\//}"
[[ "$source" != "$abs_source" ]] && source_note=" (relative to target)"
echo "Dotfiles installation"
echo "====================="
echo
echo "Target directory: $target"
echo "Source directory: $source$source_note"
echo
echo "Backup directory: $backup"
echo "(Conflicting files and directories will be moved here)"
echo
if [[ ! -O $abs_source ]]; then
echo "! $abs_source is not owned by $(id -un)."
echo " You need your own clone of the git repository!"
exit 1
fi
echo -n "Continue? [Y/n] "
read ans
if [[ "${ans:l}" = "n" ]]; then
echo "Abort."
exit 1
fi
check_status() {
if [[ $? != 0 ]]; then
echo "Failed!"
exit 1
elif [[ $1 != -q ]]; then
echo "Done."
fi
}
skipped=()
cd $abs_source
for file in *; do
abs_source_file="$abs_source/$file"
source_file="$source/$file"
target_file="$target/.$file"
if [[ ${target_file:A} != ${abs_source_file:A} ]]; then
echo
echo "* .$file"
if [[ -e $target_file ]]; then
backup_file="$backup/$file"
echo " ! $target_file exists,"
echo -n " moving to $backup_file... "
mkdir -p $backup
check_status -q
mv $target_file $backup_file
check_status
fi
echo -n " - Symlinking $target_file -> $source_file... "
ln -s $source_file $target_file
check_status
else
skipped=($skipped "$target_file -> $source_file")
fi
done
echo
echo "Finished."
if [[ -n $skipped ]]; then
echo
echo "The following files/directories were already linked to the correct target:"
for file in $skipped; do
echo " * $file"
done
fi