-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·116 lines (99 loc) · 1.68 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
#! /bin/sh -
set -eu
err() {
printf '%s\n' "$*" >&2
exit 1
}
## Environment.
: "${DRYRUN="yes"}"
if [ "$DRYRUN" != yes ]; then
export _DRE=""
else
export _DRE="echo"
echo "This is a dry run..."
fi
BECOME=
require() {
if ! command -v "$1" >/dev/null; then
echo "$0: Missing dependency: $1" >&2
exit 1
fi
}
block() {
require makaron
require realpath
file="$1"
input="$(realpath -- "$2")"
if [ ! -e "$file" ]; then
$_DRE $BECOME touch -- "$file"
$_DRE $BECOME chmod 0644 "$file"
fi
$_DRE $BECOME makaron --marker "# {mark} $input" \
--path "$file" --in < "$input"
}
process_() {
destdir="$1"
for file in *; do
spec=${file%%_*}
if [ "$spec" = "$file" ]; then
err "Missing spec: $file"
fi
target="${file#*_}"
case $spec in
*h*)
target=".$target"
;;
esac
src="$PWD/$file"
dest="$destdir/$target"
case $spec in
*[bc]*[bc]*)
err "Invalid spec: $file"
;;
*b*)
block "$dest" "$src"
;;
*c*)
"$src" "$dest"
;;
esac
case $spec in
*[dls]*[dls]*)
err "Invalid spec: $file"
;;
*d*)
$_DRE $BECOME mkdir -p "$dest"
(cd "$file" && process_ "$dest")
;;
*D*)
$_DRE $BECOME mkdir -p "$dest"
(cd "$file" && process_ "$dest")
;;
*l*)
$_DRE $BECOME ln -Ffnv -- "$src" "$dest"
;;
*s*)
$_DRE $BECOME ln -Ffnsv -- "$src" "$dest"
;;
esac
case $spec in
*m[0-7][0-7][0-7]*)
mode=$(expr -- "$spec" : '.*m\([0-7][0-7][0-7]\).*')
$_DRE $BECOME chmod -- "$mode" "$dest"
;;
*m*)
err "Invalid spec: $file"
;;
esac
done
}
case $1 in
freebsd-laptop|freebsd-system)
require sudo
export BECOME=sudo
cd "$1" && process_ "/"
;;
*)
err "Invalid installation target: $1"
;;
esac