-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathINSTALL.sh
executable file
·67 lines (58 loc) · 1.57 KB
/
INSTALL.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
#!/usr/bin/env bash
LANG=C
fixpath () (
if [[ -d $1 ]]; then
OLDPWD=- CDPATH= cd -P -- "$1" && pwd
else
OLDPWD=- CDPATH= cd -P -- "${1%/*}" && printf '%s/%s\n' "$PWD" "${1##*/}"
fi
)
install_dir() {
local source="${1}"
local destination="${2}"
local prefix="${3:-}"
for name in "${source}"/*; do
[[ "$name" =~ /\*$ ]] && break
[[ "$name" =~ /[A-Z]*\.[a-z0-9]*$ ]] && continue
local base="${name#${source}/}"
local destname=${base#DIR-}
local indest="${destination}/${prefix}${destname}"
if [[ -d "${name}" && "${base}" != "${destname}" ]]; then
[[ -L "${indest}" ]] && rm "${indest}"
mkdir -p "${indest}"
install_dir "${name}" "${indest}"
else
install_file "${name}" "${indest}"
fi
done
}
install_file() {
local source="${1}"
local destination="${2}"
if [[ -e "${destination}" ]]; then
if [[ -L ${destination} && "$(readlink "${destination}")" == "$(fixpath "${source}")" ]]; then
return
fi
echo -n "${destination#$HOME/} already exists. What now? Diff / Replace / Skip [drs]: "
read R
case $R in
d|D)
diff -sudw "${destination}" "${source}"
install_file "${source}" "${destination}"
return
;;
r|R)
local newdest="${destination}.dotfile-$$"
mv "${destination}" "${newdest}"
echo "Storing '${destination}' as '${newdest}'"
;;
s|S)
return
;;
esac
fi
test -e "${destination}" || ln -s "${source}" "${destination}"
}
cd "${0%/*}"
install_dir "$PWD" "$HOME" "."
touch $HOME/.gitconfig