aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/scripts
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2018-01-13 23:25:25 -0900
committerDavid M. Syzdek <david@syzdek.net>2018-01-13 23:25:25 -0900
commit675c2c437c432c2534c1e3884d641c363e3b7c36 (patch)
tree6e2e544a5601bf1cdb67cebb366d7adeab211a0f /src/scripts
parent87e722e33346e06eb6d3bb0eace528582d318469 (diff)
downloadiperd-675c2c437c432c2534c1e3884d641c363e3b7c36.tar.gz
iperd-675c2c437c432c2534c1e3884d641c363e3b7c36.tar.bz2
iperd-675c2c437c432c2534c1e3884d641c363e3b7c36.tar.xz
iperd-675c2c437c432c2534c1e3884d641c363e3b7c36.zip
Refactoring configure.sh script
Diffstat (limited to 'src/scripts')
-rw-r--r--src/scripts/configure.sh443
1 files changed, 350 insertions, 93 deletions
diff --git a/src/scripts/configure.sh b/src/scripts/configure.sh
index 273f343..c8355ec 100644
--- a/src/scripts/configure.sh
+++ b/src/scripts/configure.sh
@@ -1,7 +1,7 @@
1#!/bin/sh 1#!/bin/sh
2# 2#
3# IP Engineering Rescue Disk 3# IP Engineering Rescue Disk
4# Copyright (C) 2017 David M. Syzdek <david@syzdek.net>. 4# Copyright (C) 2017, 2018 David M. Syzdek <david@syzdek.net>.
5# 5#
6# @SYZDEK_BSD_LICENSE_START@ 6# @SYZDEK_BSD_LICENSE_START@
7# 7#
@@ -35,133 +35,310 @@
35 35
36# set base directory 36# set base directory
37ACTION="${1,,}" 37ACTION="${1,,}"
38BASEDIR="${2:-$(pwd)}"
39 38
40 39
41# set defaults 40# set defaults
42PROG_NAME="$(basename "${0}")" 41PROG_NAME="$(basename "${0}")"
42BASEDIR="$(dirname "${0}")/../../"
43DISTRODIR="${DISTRODIR:-${BASEDIR}/src/distros}" 43DISTRODIR="${DISTRODIR:-${BASEDIR}/src/distros}"
44CONFIGDIR="${CONFIGDIR:-${BASEDIR}/var/config}" 44CONFIGDIR="${CONFIGDIR:-${BASEDIR}/var/config}"
45CONFIG="${CONFIG:-${CONFIGDIR}/iperd.conf}" 45CONFIG="${CONFIG:-${CONFIGDIR}/iperd.conf}"
46OPTIONS="${OPTIONS:-${CONFIGDIR}/iperd.opts}"
47 46
48 47
48# set exit codes to trigger specific xargs exit codes
49DIALOG_OK=0 # xargs => 0
50DIALOG_CANCEL=255 # xargs => 124
51DIALOG_ESC=255 # xargs => 124
52DIALOG_EXTRA=126 # xargs => 126
53DIALOG_HELP=0 # xargs => 0
54export DIALOG_OK DIALOG_CANCEL DIALOG_HELP DIALOG_EXTRA DIALOG_ESC
55
56
57###############
58# #
59# Functions #
60# #
61###############
62
49cleanup() 63cleanup()
50{ 64{
51 rm -f "${OPTIONS}"
52 rm -f "${CONFIGDIR}/*.new" 65 rm -f "${CONFIGDIR}/*.new"
66 rm -f "${CONFIG}.new"
67 rm -f "${CONFIG}.new.tmp"
53} 68}
54trap cleanup EXIT
55 69
56 70
57configure() 71configure()
58{ 72{
59 # remove stale files 73 # enter main loop
60 rm -f "${OPTIONS}" 74 CONTINUE=0
61 rm -f "${CONFIG}.dist" 75 while test ${CONTINUE} -eq 0;do
62 rm -f "${CONFIG}.vers" 76
63 77 # display main menu
64 78 exec 3>&1
65 # prepare options 79 #"disk" "Change disk image options" \
66 mkdir -p "$(dirname "${OPTIONS}")" 80 RESULT="$(echo "" | xargs dialog \
67 cat \ 81 --title " Main Menu " \
68 ${DISTRODIR}/*/options \ 82 --backtitle "IP Engineering Rescue Disk Setup" \
69 ${DISTRODIR}/*/option \ 83 --ok-label "Select" \
70 |sort \ 84 --extra-button \
71 > "${OPTIONS}" \ 85 --extra-label "Save" \
72 || exit 1 86 --cancel-label "Exit" \
73 sed -i \ 87 --menu "Select item to configure:" \
74 -e 's/[[:space:]]\{2,\}/ /g' \
75 -e 's/^ //g' \
76 -e 's/ $//g' \
77 -e 's/ @[[:alnum:][:punct:]]\{1,\}@$//g' \
78 -e 's/^\(\([[:alnum:][:punct:]]\{1,\}\) [[:print:]]\{1,\}$\)/\1 @\2@/g' \
79 "${OPTIONS}" \
80 || exit 1
81 if test -f "${CONFIG}";then
82 for IMAGE in $(cat "${CONFIG}");do
83 sed -i -e "s/@${IMAGE}@/on/g" "${OPTIONS}"
84 done
85 sed -i -e "s/@[-.a-zA-Z0-9]\{1,\}@/off/g" "${OPTIONS}"
86 fi
87 sed \
88 -i \
89 -e "s/@[-.a-zA-Z0-9]\{1,\}@/on/g" \
90 -e "s/^[[:space:]]\{1,\}//g" \
91 -e "s/[[:space:]]\{2,\}/ /g" \
92 "${OPTIONS}"
93
94
95 # prompt for OS distributions
96 egrep '^[a-zA-Z0-9]{1,} ' "${OPTIONS}" \
97 |xargs dialog \
98 --no-tags \
99 --title "Distros" \
100 --backtitle "Select distros to install." \
101 --checklist "Choose distros to install:" \
102 20 70 13 \ 88 20 70 13 \
103 2> "${CONFIG}.dist.new" \ 89 "images" "Select individual boot images" \
104 || { echo " "; exit 1; } 90 "all" "Select all available images" \
105 for DISTRO in $(cat "${CONFIG}.dist.new");do 91 "defaults" "Load defaults" \
106 echo "${DISTRO}" 92 "revert" "Revert changes" \
107 done |sort -n > "${CONFIG}.dist" 93 2>&1 1>&3)"
108 rm -f "${CONFIG}.dist.new" 94 RC=$?
109 95 exec 3>&-
110 96
111 # prompt for OS distribution versions 97 # inteprets selection
112 for DISTRO in $(cat "${CONFIG}.dist");do 98 if test $RC -eq 124;then # (exit)
113 echo -n ' ' >> "${CONFIG}.vers.new" 99 dialog \
114 COUNT=$(egrep "^${DISTRO}-" "${OPTIONS}" |wc -l) 100 --title " Exit Setup " \
115 if test $COUNT == 1;then 101 --backtitle "IP Engineering Rescue Disk Setup" \
116 egrep "^${DISTRO}-" "${OPTIONS}" \ 102 --defaultno \
117 |awk '{print$1}' \ 103 --yesno "Exit without saving?" \
118 >> "${CONFIG}.vers.new" 104 6 30
105 if test $? -eq 0;then
106 CONTINUE=1
107 else
108 CONTINUE=0
109 fi
110 elif test $RC -eq 126;then # (save)
111 deps
112 CONTINUE=1
113 elif test $RC -eq 0 && test "x${RESULT}" == "xdisk";then
114 configure_disk
115 CONTINUE=0
116 elif test $RC -eq 0 && test "x${RESULT}" == "ximages";then
117 configure_distros
118 CONTINUE=0
119 elif test $RC -eq 0 && test "x${RESULT}" == "xall";then
120 configure_all
121 CONTINUE=0
122 elif test $RC -eq 0 && test "x${RESULT}" == "xdefaults";then
123 cat /dev/null > ${CONFIG}.new
124 dialog \
125 --backtitle "IP Engineering Rescue Disk Setup" \
126 --no-tags \
127 --msgbox "Defaults loaded." \
128 6 30
129 CONTINUE=0
130 elif test $RC -eq 0 && test "x${RESULT}" == "xrevert";then
131 prereqs
132 dialog \
133 --backtitle "IP Engineering Rescue Disk Setup" \
134 --no-tags \
135 --msgbox "Changes reverted." \
136 6 30
137 CONTINUE=0
138 else
139 CONTINUE=0
140 fi
141 done
142
143 return 0;
144}
145
146
147configure_all()
148{
149 # enable all options
150 for DISTRO in $(list_distros);do
151 if test -f ${DISTRODIR}/${DISTRO}/options;then
152 list_vers ${DISTRODIR}/${DISTRO}/options
119 elif test -f ${DISTRODIR}/${DISTRO}/option;then 153 elif test -f ${DISTRODIR}/${DISTRO}/option;then
120 egrep "^${DISTRO}-" "${OPTIONS}" \ 154 list_vers_opts ${DISTRODIR}/${DISTRO}/option |grep ' on$'
121 |xargs dialog \ 155 if test $? -ne 0;then
122 --no-tags \ 156 list_vers_opts ${DISTRODIR}/${DISTRO}/option |tail -1
123 --title "Boot Image" \ 157 fi
124 --backtitle "Select image to install." \ 158 fi
125 --radiolist "Choose image to install:" \ 159 done |awk '{print$1}' |sort -n > ${CONFIG}.new.tmp
126 20 70 13 \ 160 mv ${CONFIG}.new.tmp ${CONFIG}.new
127 2>> "${CONFIG}.vers.new" \ 161
128 || { echo " "; exit 1; } 162 # confirm change
163 dialog \
164 --backtitle "IP Engineering Rescue Disk Setup" \
165 --no-tags \
166 --msgbox "All images configured." \
167 6 30
168}
169
170
171configure_disk()
172{
173 # enter main loop
174 CONTINUE=0
175 while test ${CONTINUE} -eq 0;do
176
177 # display main menu
178 exec 3>&1
179 RESULT="$(echo "" | xargs dialog \
180 --title " Disk Options " \
181 --backtitle "IP Engineering Rescue Disk Setup" \
182 --ok-label "Change" \
183 --cancel-label "Back" \
184 --menu "Select option to configure:" \
185 20 70 13 \
186 "usb" "USB partition type (hybrid)" \
187 "size" "USB disk image size (2048 MB)" \
188 "iso" "USB partition type (legacy)" \
189 2>&1 1>&3)"
190 RC=$?
191 exec 3>&-
192
193 # inteprets selection
194 if test $RC -eq 124;then # (exit)
195 CONTINUE=1
196 elif test $RC -eq 0 && test "x${RESULT}" == "xusb";then
197 exec 3>&1
198 RESULT="$(echo "" | xargs dialog \
199 --title " USB Disk Partition Type " \
200 --backtitle "IP Engineering Rescue Disk Setup" \
201 --radiolist "Choose parition type:" \
202 20 70 13 \
203 "uefi" "UEFI" off \
204 "legacy" "Legacy BIOS" off \
205 "hybrid" "Hybrid (UEFI and Legacy BIOS)" off \
206 2>&1 1>&3)"
207 RC=$?
208 exec 3>&-
209 CONTINUE=0
210 elif test $RC -eq 0 && test "x${RESULT}" == "xsize";then
211 exec 3>&1
212 RESULT="$(echo "" | xargs dialog \
213 --title " USB Disk Image Size " \
214 --backtitle "IP Engineering Rescue Disk Setup" \
215 --inputbox "Enter size of disk image file:" \
216 9 40 2048 \
217 2>&1 1>&3)"
218 RC=$?
219 exec 3>&-
220 CONTINUE=0
221 elif test $RC -eq 0 && test "x${RESULT}" == "xiso";then
222 exec 3>&1
223 RESULT="$(echo "" | xargs dialog \
224 --title " ISO Disk Type " \
225 --backtitle "IP Engineering Rescue Disk Setup" \
226 --radiolist "Choose disk image type:" \
227 20 70 13 \
228 "uefi" "UEFI" off \
229 "legacy" "Legacy BIOS" off \
230 "hybrid" "Hybrid (UEFI and Legacy BIOS)" off \
231 2>&1 1>&3)"
232 RC=$?
233 exec 3>&-
234 CONTINUE=0
129 else 235 else
130 egrep "^${DISTRO}-" "${OPTIONS}" \ 236 CONTINUE=0
131 |xargs dialog \
132 --no-tags \
133 --title "Boot Images" \
134 --backtitle "Select images to install." \
135 --checklist "Choose images to install:" \
136 20 70 13 \
137 2>> "${CONFIG}.vers.new" \
138 || { echo " "; exit 1; }
139 fi 237 fi
140 done 238 done
141 for VERS in $(cat "${CONFIG}.vers.new");do 239}
142 echo "${VERS}"
143 done |sort -n > "${CONFIG}.vers"
144 rm -f "${CONFIG}.vers.new"
145 240
146 241
147 # update cached config 242configure_distros()
148 rm -f "${CONFIG}" 243{
149 cat "${CONFIG}.dist" "${CONFIG}.vers" > "${CONFIG}" 244 # loop until exit
245 CONTINUE=0
246 while test $CONTINUE -eq 0;do
247 # prompt for OS distributions
248 exec 3>&1
249 RESULT="$(list_distros \
250 |xargs dialog \
251 --title " Boot Distributions " \
252 --backtitle "IP Engineering Rescue Disk Setup" \
253 --no-tags \
254 --ok-label "Configure" \
255 --cancel-label "Back" \
256 --menu "Choose distributions to install:" \
257 20 70 13 \
258 2>&1 1>&3)"
259 RC=$?
260 exec 3>&-
150 261
262 # intepret the result
263 if test $RC -eq 0;then
264 configure_image "${RESULT}"
265 CONTINUE=0
266 else
267 CONTINUE=1
268 fi
269 done
270}
151 271
152 # generate dependencies 272
153 deps 273configure_image()
274{
275 DISTRO="${1}"
276
277 # determine option file
278 if test -f ${DISTRODIR}/${DISTRO}/option;then
279 COUNT=$(grep "^${DISTRO}-" ${CONFIG}.new |wc -l)
280 if test $COUNT -eq 0;then
281 SKIP=on
282 else
283 SKIP=off
284 fi
285 exec 3>&1
286 RESULT="$(list_vers_opts ${DISTRODIR}/${DISTRO}/option \
287 |xargs dialog \
288 --no-tags \
289 --title " Boot Images " \
290 --backtitle "IP Engineering Rescue Disk Setup" \
291 --radiolist "Choose image to install:" \
292 20 70 13 \
293 "____SKIP____" "Do not install" $SKIP \
294 2>&1 1>&3)"
295 RC=$?
296 exec 3>&-
297 elif test -f ${DISTRODIR}/${DISTRO}/options;then
298 exec 3>&1
299 RESULT="$(list_vers_opts ${DISTRODIR}/${DISTRO}/options \
300 |xargs dialog \
301 --no-tags \
302 --title " Boot Images " \
303 --backtitle "IP Engineering Rescue Disk Setup" \
304 --checklist "Choose images to install:" \
305 20 70 13 \
306 2>&1 1>&3)"
307 RC=$?
308 exec 3>&-
309 else
310 return 0
311 fi
312
313 # test result
314 if test $RC -ne 0;then
315 return 0;
316 fi
317 if test "${RESULT}" == "____SKIP____";then
318 return 0;
319 fi
320
321 # update configuration
322 grep -v "^${DISTRO}-" "${CONFIG}.new" > "${CONFIG}.new.tmp"
323 for IMAGE in ${RESULT};do
324 echo $IMAGE >> "${CONFIG}.new.tmp"
325 done
326 sort -n "${CONFIG}.new.tmp" > "${CONFIG}.new"
154} 327}
155 328
156 329
157deps() 330deps()
158{ 331{
332 # save new config
333 mv "${CONFIG}.new" "${CONFIG}"
334
159 # build Makefile configuration 335 # build Makefile configuration
160 for DISTRO in $(cat "${CONFIG}.dist");do 336 rm -f ${BASEDIR}/Makefile.config
337 for DISTRO in $(cut -d- -f1 "${CONFIG}" |sort |uniq);do
161 if test -f "${DISTRODIR}/${DISTRO}/make.header";then 338 if test -f "${DISTRODIR}/${DISTRO}/make.header";then
162 cat "${DISTRODIR}/${DISTRO}/make.header" 339 cat "${DISTRODIR}/${DISTRO}/make.header"
163 fi 340 fi
164 for VERS in $(egrep "^${DISTRO}-" "${CONFIG}.vers");do 341 for VERS in $(egrep "^${DISTRO}-" "${CONFIG}");do
165 VERSION=$(echo "${VERS}" |cut -d- -f2) 342 VERSION=$(echo "${VERS}" |cut -d- -f2)
166 CODENAME=$(echo "${VERS}" |cut -d- -f3) 343 CODENAME=$(echo "${VERS}" |cut -d- -f3)
167 ARCH=$(echo "${VERS}" |cut -d- -f4) 344 ARCH=$(echo "${VERS}" |cut -d- -f4)
@@ -182,16 +359,96 @@ deps()
182} 359}
183 360
184 361
362list_distros()
363{
364 egrep '^[[:space:]]{0,}[a-zA-Z0-9]{1,}[[:space:]]' ${DISTRODIR}/*/option* \
365 |sed \
366 -e 's/^[a-zA-Z0-9/]\{1,\}://g' \
367 -e 's/ @[[:alnum:][:punct:]]\{1,\}@$//g' \
368 -e "s/[[:space:]]\{2,\}/ /g" \
369 -e 's/^ //g' \
370 -e 's/ $//g' \
371 |cut -d: -f2 \
372 |sort -n \
373 |uniq
374}
375
376
377list_vers()
378{
379 egrep '^[[:space:]]{0,}[a-zA-Z0-9]{1,}-' "${1}" \
380 |sed \
381 -e 's/[[:space:]]\{1,\}/ /g' \
382 -e 's/[-a-z0-9_/]\{1,\}: //g' \
383 -e 's/^ //g' \
384 |cut -d\ -f1 \
385 |sort -n \
386 |uniq
387}
388
389
390list_vers_opts()
391{
392 OPTFILE="${1}"
393
394 # generate list of options
395 for VERS in $(list_vers ${OPTFILE});do
396 grep "^${VERS}$" "${CONFIG}.new" > /dev/null 2> /dev/null
397 if test $? -eq 0;then
398 STATE=on
399 else
400 STATE=off
401 fi
402 egrep "^[[:space:]]{0,}${VERS}[[:space:]]" ${OPTFILE} |sed -e "s/$/ ${STATE}/g"
403 done \
404 |sed \
405 -e "s/[[:space:]]\{1,\}/ /g" \
406 -e 's/^ //g' \
407 -e 's/ $//g' \
408 |sort -n
409}
410
411
412prereqs()
413{
414 trap cleanup EXIT
415
416 rm -f "${CONFIG}.new" || exit 1
417 if test -f "${CONFIG}";then
418 egrep -i "^[[:space:]]{0,}[a-z0-9_]{1,}-" "${CONFIG}" \
419 |awk '{print$1}' \
420 |sort \
421 |uniq \
422 > "${CONFIG}.new"
423 else
424 touch "${CONFIG}.new" || exit 1
425 fi
426
427 if test ! -f "${CONFIG}.new";then
428 exit 1
429 fi
430}
431
432
433####################
434# #
435# Body of Script #
436# #
437####################
438
439
185# prompt for images to install 440# prompt for images to install
186case "${ACTION}" in 441case "${ACTION}" in
187 442
188 configure) 443 configure)
444 prereqs
189 configure 445 configure
190 exit $? 446 exit $?
191 ;; 447 ;;
192 448
193 449
194 deps) 450 deps)
451 prereqs
195 deps 452 deps
196 exit $? 453 exit $?
197 ;; 454 ;;