-
Notifications
You must be signed in to change notification settings - Fork 48
/
EZsdmInstaller
executable file
·293 lines (280 loc) · 7.45 KB
/
EZsdmInstaller
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/bash
#
# V9.0
#
# EZ Installer. Run from the bash command line:
#
# curl -L https://raw.githubusercontent.com/gitbls/sdm/master/EZsdmInstaller | bash
#
# $1: Branch to install from (D:master)
# $2: Target install directory (D:/usr/local/sdm)
# ** To use either of these arguments you must download this script to your system
# and start it from the command line:
# e.g., bash$ EZsdmInstaller V9.0 # Install V9.0 release to /usr/local/sdm
# bash$ EZsdmInstaller "" /home/$(whoami)/sdm # Install master branch to /home/$(whoami)/sdm
# $3: Source Github repo (D:gitbls/sdm)
#
# NOTE: Using this version on the master branch requires that the master branch is updated to V9.0 (NYI)
#
# At the moment requires apt-based package installs. Easy to fix, of course. It's only code...
#
function errexit() {
echo "$1"
exit 1
}
function askyn() {
local ans
echo -n "$1" '[y/n]? ' ; read $2 ans
case "$ans" in
y*|Y*) return 0 ;;
*) return 1 ;;
esac
}
function getosdistro() {
local osdistro osversion
if [ -f "/etc/os-release" ]
then
osdistro=$(grep ^ID= /etc/os-release | (IFS='='; read a b ; echo $b))
osversion=$(grep ^VERSION_ID= /etc/os-release | (IFS='='; read a b ; echo $b))
[ "$osversion" == "" ] && osversion=$(grep ^VERSION= /etc/os-release | (IFS='='; read a b ; echo $b))
else
osdistro="unknown"
osversion="unknown"
fi
osdistro=${osdistro%\"} #Strip leading and trailing quotes
osdistro=${osdistro#\"}
osdistro=${osdistro,,} #Lower case
[ "$osdistro" == "raspbian" ] && osdistro="raspios"
osversion=${osversion%\"}
osversion=${osversion#\"}
echo "$osdistro:$osversion"
}
#
# Check OS Distro and version
#
myscript="$0 $@"
#IFS=":" read osdistro osversion <<< $(getosdistro)
[ "$(type -p apt)" == "" ] && errexit "? apt not found; cannot install on this system"
#
# Create directories and download sdm
#
[ "$1" == "" ] && branch="master" || branch="$1"
[ "$2" != "" ] && dir="$2" || dir="/usr/local/sdm"
[ "$3" != "" ] && repo="$3" || repo="gitbls/sdm"
if [ "$SDMLAN" != "" ]
then
src=$SDMLAN
curl="scp"
else
src="https://github.com/$repo/raw/$branch"
curl="curl"
fi
sudo=""
if [ -d $dir ]
then
[ ! -w $dir ] && sudo="sudo" # Directory exists; do we have write access?
else
[ ! -w ${dir%/*} ] && sudo="sudo" # Directory does not exist; do we have write access to where it will be created?
fi
# Can get here without using curl so ensure curl installed
if [[ "$curl" == "curl" ]] && [[ "$(type -p curl)" == "" ]]
then
echo "* Install curl"
$sudo apt-get install --yes --no-install-recommends curl
fi
echo "* Make directory '$dir' and download sdm files to it"
$sudo mkdir -p $dir $dir/1piboot $dir/plugins $dir/local-plugins
dlerrors=0
for f in sdm sdm-phase0 \
sdm-phase1 \
sdm-cparse \
sdm-cmdsubs \
sdm-readparams \
sdm-rpcsubs \
sdm-firstboot \
sdm-collect-labwc-config \
sdm-cryptconfig \
sdmcryptfs \
sdm-apt-cacher \
sdm-apt \
sdm-customphase \
sdm-apps-example \
sdm-xapps-example \
sdm-cportal \
sdm-logmsg \
sdm-gburn \
sdm-make-luks-usb-key \
sdm-add-luks-key \
sdm-ssh-initramfs \
plugins/apps \
plugins/apt-addrepo \
plugins/apt-cacher-ng \
plugins/apt-file \
plugins/bootconfig \
plugins/btwifiset \
plugins/chrony \
plugins/clockfake \
plugins/copydir \
plugins/copyfile \
plugins/cryptroot \
plugins/disables \
plugins/dovecot-imap \
plugins/explore \
plugins/extractfs \
plugins/gadgetmode \
plugins/git-clone \
plugins/graphics \
plugins/hotspot \
plugins/imon \
plugins/knockd \
plugins/L10n \
plugins/labwc \
plugins/logwatch \
plugins/lxde \
plugins/mkdir \
plugins/modattr \
plugins/ndm \
plugins/network \
plugins/parted \
plugins/piapps \
plugins/pistrong \
plugins/postburn \
plugins/postfix \
plugins/quietness \
plugins/raspiconfig \
plugins/runatboot \
plugins/runscript \
plugins/rxapp \
plugins/samba \
plugins/serial \
plugins/sshd \
plugins/sshkey \
plugins/sdm-plugin-template \
plugins/syncthing \
plugins/system \
plugins/trim-enable \
plugins/ufw \
plugins/user \
plugins/vnc \
plugins/wificonfig \
plugins/wsdd \
1piboot/1piboot.conf
do
echo "Downloading '$f' to '$dir/$f'"
if [ "$SDMLAN" == "" ]
then
$sudo curl --fail --silent --show-error -L $src/$f -o $dir/$f
sts=$?
else
scp $SDMLAN/$f $dir/$f
sts=$?
fi
if [ ! -f $dir/$f -o $sts -ne 0 ]
then
echo "? Error downloading '$src/$f' to $dir"
dlerrors=$((dlerrors+1))
fi
done
if [ "$dir" == "/usr/local/sdm" ]
then
echo "* Create link for sdm: /usr/local/bin/sdm"
[ -L /usr/local/bin/sdm ] && $sudo rm -f /usr/local/bin/sdm
$sudo ln -s /usr/local/sdm/sdm /usr/local/bin/sdm
fi
$sudo chmod -R 755 $dir/*
$sudo chmod 644 $dir/{sdm-apps-example,sdm-xapps-example} $dir/1piboot/1piboot.conf
$sudo mkdir -p /etc/sdm/0piboot /etc/sdm/1piboot /etc/sdm/xpiboot /etc/sdm/assets /etc/sdm/local-assets
$sudo chmod 700 /etc/sdm
$sudo rm -f /etc/sdm/sdm-readparams
$sudo cp -a $dir/sdm-readparams /etc/sdm
if [ "$($sudo bash -c '[ -f /etc/sdm/cparams ] || echo "no"')" == "no" ]
then
myuser=$(whoami)
hostname=$(hostname)
cat <<EOF | $sudo tee /etc/sdm/cparams >/dev/null
# Written by EZsdmInstaller $(date +'%Y-%m-%d %H:%M:%S')
version:"V12.6"
thishost:""
aptcache:""
aptdistupgrade:""
autologin:"0"
fbatch:"0"
b0script:""
b1script:""
bootscripts:"0"
burnplugins:""
cscript:""
csrc:""
datefmt:"%Y-%m-%d %H:%M:%S"
debugs:""
dimg:""
dimgdev:"0"
dimgdevname:""
domain:""
ecolors:"blue:gray:red"
expandroot:""
exports:""
fchroot:"0"
fdirtree:"0"
fnoexpandroot:"0"
hname:""
hostname:"$hostname"
loadlocal:""
logwidth:"192"
dgroups:"dialout,cdrom,floppy,audio,video,plugdev,users,adm,sudo,users,input,netdev,spi,i2c,gpio"
myuser:"$myuser"
nowaittimesync:"0"
os:""
pi1bootconf:""
plugindebug:"0"
poptions:""
raspiosver:""
reboot:""
fredact:"0"
regensshkeys:""
noreboot:"0"
rebootwait:"20"
redocustomize:"0"
sdmdir:"$dir"
sdmflist:"sdm sdm-phase0 sdm-phase1 sdm-cparse sdm-readparams sdm-cmdsubs sdm-firstboot sdm-apt sdm-apt-cacher sdm-cportal sdm-logmsg sdm-gburn"
showapt:"0"
src:"$dir"
swapsize:"0"
timezone:""
virtmode:"nspawn"
vqemu:""
wificountry:""
custom1:""
custom2:""
custom3:""
custom4:""
plugins:""
allplugins:""
EOF
else
echo "* /etc/sdm/cparams exists; Not overwriting"
fi
pkgs="binfmt-support gdisk keyboard-configuration parted qemu-user-static rsync systemd-container uuid"
echo "* Ensure required packages are installed: $pkgs"
[[ $EUID -ne 0 ]] && sudo="sudo"
$sudo apt-get install --yes --no-install-recommends $pkgs
echo ""
if [ "$dir" == "/usr/local/sdm" -a "$(type -p sdm)" != "" ]
then
echo "* Invoke sdm with 'sudo sdm'"
else
echo "* Invoke sdm with 'sudo $dir/sdm'"
echo "* You can make an ease-of-use link with: sudo ln -s $dir/sdm /usr/local/bin/sdm"
echo " so you can invoke sdm with 'sudo sdm'"
fi
echo $"
Complete sdm documentation: https://github.com/$repo/tree/$branch/Docs
"
if [ $dlerrors -ne 0 ]
then
echo $"%% The sdm download was not complete
$dlerrors file(s) not downloaded
This must be corrected before you can use sdm
If you need help, open an issue at https://github.com/$repo
"
fi