This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·204 lines (186 loc) · 3.1 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env bash
cd $(dirname ${BASH_SOURCE})/
OS="null"
KERNEL="null"
ARCH="null"
DEFSFILE="defs.tml"
find_linux_distro() {
[ -e /etc/os-release ] && relfile="/etc/os-release" || relfile="/usr/lib/os-release"
if [ -n "$relfile" ]; then
OS=$( cat /etc/os-release|grep -G '^ID='|cut -d= -f2|tr -d \" )
else
OS="unknown-linux"
fi
}
find_os() {
case $( uname -s | tr [:upper:] [:lower:] ) in
cygwin*)
KERNEL="windows"
OS="cygwin"
;;
linux)
KERNEL="linux"
find_linux_distro
;;
darwin)
KERNEL="darwin"
OS="macosx"
;;
sunos)
KERNEL="sunos"
OS="sunos"
;;
freebsd)
KERNEL="freebsd"
OS="freebsd"
;;
*)
OS="unknown"
;;
esac
}
find_arch() {
case $(uname -m) in
x86_64)
ARCH="amd64"
;;
i86pc)
ARCH="amd64"
;;
armv5tel)
ARCH="arm"
;;
*)
ARCH=$(uname -m)
;;
esac
}
find_exe_suffix() {
if [ $KERNEL == "windows" ]; then
SUFFIX=".exe"
else
SUFFIX=""
fi
}
install_tasks() {
find_os
find_arch
find_exe_suffix
BINNAME=homemaker_${KERNEL}_${ARCH}${SUFFIX}
ARGS=()
if [ $DRY -eq 1 ]; then
ARGS+=("-nocmds")
ARGS+=("-nolinks")
ARGS+=("-notemplates")
fi
if [ $VERBOSE -eq 1 ]; then
ARGS+=("-verbose")
fi
for i in "$@"; do
HM_OVERLAY=${OVERLAY} homemaker/$BINNAME ${ARGS[@]} -variant $OS -task package_$i $DEFSFILE .
HM_OVERLAY=${OVERLAY} homemaker/$BINNAME ${ARGS[@]} -variant $OVERLAY -task setup_$i $DEFSFILE .
done
}
queue_install() {
PACKAGES+=($1)
}
list_packages() {
awk -F. '/^\[tasks\.package/ { print substr($2, 9, length($2)-9) }' $DEFSFILE
}
list_overlays() {
awk -F_ '/^\[tasks\.setup_.+__.+]/ { print substr($4, 1, length($4)-1) }' $DEFSFILE|sort|uniq
}
system_report() {
find_os
find_arch
find_exe_suffix
cat <<- EOM
Your OS: $OS
Your kernel: $KERNEL
Your architecture: $ARCH
Your executable suffix: $SUFFIX
This means we want to use: homemaker_${KERNEL}_${ARCH}${SUFFIX}
EOM
}
verbose_log() {
if [ $VERBOSE -eq 1 ]; then
echo $@
fi
}
show_usage() {
cat <<HELP
Usage: $0 <option>
One of:
-d Dry run
-h Show this message
-i Install packages. Can be used more than once for multiple packages
-l List packages
-L List overlays
-o Set an overlay for the configs we lay down (default: $OVERLAY)
-r Report OS/architecture
-s Setup dotfiles
-v Verbose output
HELP
}
# Plan
DRY=0
VERBOSE=0
PACKAGES=()
OVERLAY="sno"
while getopts ":dhi:Llo:rsv" opts; do
case $opts in
d)
DRY=1
;;
h)
show_usage
exit 0
;;
i)
queue_install $OPTARG
;;
l)
list_packages
exit 0
;;
L)
list_overlays
exit 0
;;
o)
OVERLAY=$OPTARG
;;
r)
system_report
exit 0
;;
s)
# Setup dotfiles w/o install
echo "Not yet implemented on its own"
exit 0
;;
v)
VERBOSE=1
;;
:)
echo "Error: -$OPTARG requires an argument"
show_usage
exit 1
;;
*)
echo "Error: Unknown option -$OPTARG"
show_usage
exit 1
;;
esac
done
# Do it
if [ ${#PACKAGES[@]} -eq 0 ]; then
echo "Nothing to do. Exiting..."
exit 0
fi
if [ $DRY -eq 1 ]; then
echo "Doing dry run..."
fi
verbose_log "Set overlay to $OVERLAY"
install_tasks ${PACKAGES[@]}