-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall
More file actions
executable file
·103 lines (93 loc) · 2.72 KB
/
install
File metadata and controls
executable file
·103 lines (93 loc) · 2.72 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env zsh
repo="${0:A:h}"
src="$repo/config"
backup="$repo/backup/$(date +%Y%m%d_%H%M%S)"
. "$repo/.parse_config_map.zsh"
echo "Dotfiles installation"
echo "====================="
echo
echo "Target directory (~): $home_dir"
echo " - XDG config: ${xdg_config_dir/#$home_dir\//~/}"
echo " - XDG data: ${xdg_data_dir/#$home_dir\//~/}"
echo "Source directory: $src"
echo
echo "Backup directory: $backup"
echo "(Conflicting configs will be moved here.)"
echo
if [[ ! -O $src ]]; then
echo "! $src 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 $src
for file in *; do
src_file="$src/$file"
if (( ${+config_map[$file]} )); then
target_file="${config_map[$file]}"
else
target_file="$home_dir/.$file"
fi
if [[ ${target_file:A} != ${src_file:A} ]]; then
echo
echo "* ${target_file/#$target\//~/}"
if [[ -e $target_file || -L $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
src_rel_steps=()
target_parent="${target_file:h}"
while [[ $target_parent != "/" && $target_parent != $home_dir ]]; do
src_rel_steps+=("..")
target_parent="${target_parent:h}"
done
if [[ $target_parent != "/" ]]; then
if [[ -n $src_rel_steps ]]; then
src_rel_path="${(j:/:)src_rel_steps}/"
else
src_rel_path=
fi
src_file=${src_file/#$home_dir\//$src_rel_path}
else
echo " ! Failed to construct relative path, using an absolute symlink instead."
fi
echo -n " - Symlinking ${target_file/#$home_dir\//~/} -> ${src_file/#$home_dir\//~/}... "
target_dir="${target_file:h}"
if [[ "$target_dir" != "$home_dir" && ! -d "$target_dir" ]]; then
mkdir -p "$target_dir"
check_status -q
fi
ln -s "$src_file" "$target_file"
check_status
else
skipped+=("${target_file/#$home_dir\//~/} -> ${src_file/#$home_dir\//~/}")
fi
done
echo
echo "Finished."
if [[ -n $skipped ]]; then
echo
echo "The following configs were already linked to the correct target:"
for file in $skipped; do
echo " * $file"
done
fi