88# Free Software Foundation; either version 3 of the License, or (at your
99# option) any later version.
1010
11- fatal () { echo " FATAL [$( basename $0 ) ]: $@ " 1>&2 ; exit 1; }
12- warning () { echo " WARNING [$( basename $0 ) ]: $@ " ; }
13- info () { echo " INFO [$( basename $0 ) ]: $@ " ; }
11+ fatal () { echo " FATAL [$( basename " $0 " ) ]: $* " 1>&2 ; exit 1; }
12+ warning () { echo " WARNING [$( basename " $0 " ) ]: $* " 1>&2 ; }
13+ info () { echo " INFO [$( basename " $0 " ) ]: $* " ; }
1414
1515usage () {
1616cat<< EOF
17- Syntax: $( basename $0 ) [ --options ] appname-version
17+ Syntax: $( basename " $0 " ) [ --options ] appname-version
1818Patch appliance appname-version with appname-version patch (if it exists),
1919increment version and repackage as ISO, (re)generating tklbam profile.
2020
@@ -38,49 +38,57 @@ exit 1
3838}
3939
4040unset appver publish secupdates updates bug_num force
41- while [ " $1 " != " " ]; do
41+ while [[ " $1 " != " " ] ]; do
4242 case $1 in
43- --help|-h) usage;;
44- --publish) publish=" yes" ;;
45- --secupdates) secupdates=" yes" ;;
46- --updates) updates=" yes" ;;
47- --bug-number) shift ; bug_num=" $1 " ;;
48- --force) force=" yes" ;;
49- * ) if [ -n " $appver " ]; then usage; else appver=$1 ; fi ;;
43+ --help|-h) usage;;
44+ --publish) publish=" yes" ;;
45+ --secupdates) secupdates=" yes" ;;
46+ --updates) updates=" yes" ;;
47+ --bug-number) shift ; bug_num=" $1 " ;;
48+ --force) force=" yes" ;;
49+ * ) if [[ -n " $appver " ]]; then
50+ usage
51+ else
52+ appver=$1
53+ fi ;;
5054 esac
5155 shift
5256done
5357
54- [ -n " $appver " ] || usage
55- [ -n " $secupdates " ] || warning " --secupdates was not specified"
58+ [[ -n " $appver " ] ] || usage
59+ [[ -n " $secupdates " ] ] || warning " --secupdates was not specified"
5660
57- [ -z " $BT_DEBUG " ] || set -x
61+ [[ -z " $BT_DEBUG " ] ] || set -x
5862
59- export BT=$( dirname $( readlink -f $0 ) )
63+ bt_bugfix_path=$( readlink -f " $0 " )
64+ bt_dir=$( dirname " $bt_bugfix_path " )
65+ export BT=" $bt_dir "
6066export BT_CONFIG=$BT /config
61- . $BT_CONFIG /common.cfg
67+ # shellcheck source=/dev/null
68+ source " $BT_CONFIG /common.cfg"
6269
63- if [ " $publish " == " yes" ]; then
64- [ -n " $BT_PUBLISH_IMGS " ] || fatal " BT_PUBLISH_IMGS not set"
65- [ -n " $BT_PUBLISH_META " ] || fatal " BT_PUBLISH_META not set"
66- [ -n " $BT_PUBLISH_PROFILES " ] || fatal " BT_PUBLISH_PROFILES not set"
70+ if [[ " $publish " == " yes" ] ]; then
71+ [[ -n " $BT_PUBLISH_IMGS " ] ] || fatal " BT_PUBLISH_IMGS not set"
72+ [[ -n " $BT_PUBLISH_META " ] ] || fatal " BT_PUBLISH_META not set"
73+ [[ -n " $BT_PUBLISH_PROFILES " ] ] || fatal " BT_PUBLISH_PROFILES not set"
6774else
6875 warning " --publish was not specified"
6976fi
7077
7178info " Setting up."
79+ [[ -n " $BT_ISOS " ]] || fatal " BT_ISO not set"
7280O=$BT_ISOS
73- mkdir -p $O
74- parsed_appname_version=$( $BT /bin/parse-appname-version $appver )
75- read appname appversion codename arch <<< " $parsed_appname_version"
81+ mkdir -p " $O "
82+ parsed_appname_version=$( " $BT /bin/parse-appname-version" " $appver " )
83+ read -r appname appversion codename arch <<< " $parsed_appname_version"
7684export BT_VERSION=${appversion} -${codename} -${arch}
7785
7886os_arch=$( dpkg --print-architecture)
79- [ " $arch " == " $os_arch " ] || fatal " os_arch mismatch: $arch != $os_arch "
87+ [[ " $arch " == " $os_arch " ] ] || fatal " os_arch mismatch: $arch != $os_arch "
8088
81- major_v=$( echo $appversion | sed -En " s|^([0-9]+)\.[0-9]+|\1|p" )
82- minor_v=$( echo $appversion | sed -En " s|^[0-9]+\.([0-9]+)|\1|p" )
83- new_appversion=" ${major_v} .$(( $ minor_v + 1 )) "
89+ major_v=$( sed -En " s|^([0-9]+)\.[0-9]+|\1|p" <<< " $appversion " )
90+ minor_v=$( sed -En " s|^[0-9]+\.([0-9]+)|\1|p" <<< " $appversion " )
91+ new_appversion=" ${major_v} .$(( minor_v + 1 )) "
8492export NEW_BT_VERSION=${new_appversion} -${codename} -${arch}
8593
8694name=turnkey-${appname} -${BT_VERSION}
@@ -96,20 +104,20 @@ new_changelog=$new_name.changelog
96104
97105_umount () {
98106 info " Unmounting resources from rootfs."
99- umount -l $rootfs /run || true
100- umount -l $rootfs /dev || true
101- umount -l $rootfs /sys || true
102- umount -l $rootfs /proc || true
107+ umount -l " $rootfs /run" || true
108+ umount -l " $rootfs /dev" || true
109+ umount -l " $rootfs /sys" || true
110+ umount -l " $rootfs /proc" || true
103111}
104112
105113_cleanup () {
106114 _umount
107115 if [[ -z " $BT_DEBUG " ]] || [[ " $force " == " yes" ]]; then
108116 info " Cleaning up files and directories."
109- rm -rf $O / $ new_sec_pkg
110- if ! (mount | grep -q $( basename $rootfs ) ); then
111- rm -rf $O / $ rootfs
112- rm -rf $O / $ cdroot
117+ rm -rf " ${O :? } / ${ new_sec_pkg:? } "
118+ if ! (mount | grep -q " $( basename " $rootfs " ) " ); then
119+ rm -rf " ${O :? } / ${ rootfs:? } "
120+ rm -rf " ${O :? } / ${ cdroot:? } "
113121 else
114122 warning " $rootfs not unmounted."
115123 fi
@@ -119,13 +127,13 @@ _cleanup() {
119127# trap _cleanup INT TERM EXIT
120128
121129info " Download and verfiy ISO."
122- $BT /bin/iso-download $BT_ISOS $BT_VERSION $appname \
123- || $BT /bt-iso $appname
124- $BT /bin/iso-verify $BT_ISOS $BT_VERSION $appname
130+ " $BT /bin/iso-download" " $BT_ISOS " " $BT_VERSION " " $appname " \
131+ || " $BT /bt-iso" " $appname "
132+ " $BT /bin/iso-verify" " $BT_ISOS " " $BT_VERSION " " $appname "
125133
126- cd $O
134+ cd " $O "
127135[[ " $force " == " yes" ]] || _cleanup
128- tklpatch-extract-iso $isofile
136+ tklpatch-extract-iso " $isofile "
129137
130138unset patches
131139[[ ! -d " $BT /patches/$BT_VERSION " ]] \
@@ -138,7 +146,7 @@ elif [[ "$secupdates" == "yes" ]]; then
138146 patches=" $patches $BT /patches/secupdates"
139147fi
140148
141- patch_test=$( echo $patches | tr -d ' [[ :space:]] ' )
149+ patch_test=$( tr -d ' [:space:]' <<< " $patches " )
142150if [[ -z " $patch_test " ]]; then
143151 if [[ -z " $BT_DEBUG " ]]; then
144152 fatal " Exiting. No patches to be applied."
@@ -153,89 +161,89 @@ info "Generating updated updated changelog."
153161# update changelog
154162msg=" Patched bugfix release."
155163[[ -z " $bug_num " ]] || msg=" $msg Closes #${bug_num} ."
156- cat > $new_changelog << EOF
164+ cat > " $new_changelog " << EOF
157165${new_sec_pkg} (1) turnkey; urgency=low
158166EOF
159167if [[ " $patches " == * " /updates" * ]]; then
160- cat >> $new_changelog << EOF
168+ cat >> " $new_changelog " << EOF
161169
162170 * Updated all Debian packages to latest.
163171 [ autopatched by buildtasks ]
164172EOF
165173elif [[ " $patches " == * " /secupdates" * ]]; then
166- cat >> $new_changelog << EOF
174+ cat >> " $new_changelog " << EOF
167175
168176 * Pre-installed all latest Debian security updates.
169177 [ autopatched by buildtasks ]
170178EOF
171179fi
172- cat >> $new_changelog << EOF
180+ cat >> " $new_changelog " << EOF
173181
174182 * $msg
175183 [ autopatched by buildtasks ]
176184
177185 -- Jeremy Davis <[email protected] > $( date +" %a, %d %b %Y %H:%M:%S %z" ) 178186
179187EOF
180- cat $old_changelog >> $new_changelog
188+ cat " $old_changelog " >> " $new_changelog "
181189
182190info " Updating turnkey_version and preparing update version package."
183- echo " $new_name " > $rootfs /etc/turnkey_version
184- $BT /bin/generate-release-deb $new_changelog $rootfs
191+ echo " $new_name " > " $rootfs /etc/turnkey_version"
192+ " $BT /bin/generate-release-deb" " $new_changelog " " $rootfs "
185193update_patch=$BT /patches/update-release
186194conf_script=$update_patch /conf
187- mkdir -p $update_patch
188- touch $conf_script
189- cat > $conf_script << EOF
195+ mkdir -p " $update_patch "
196+ touch " $conf_script "
197+ cat > " $conf_script " << EOF
190198#!/bin/bash -e
191199export DEBIAN_FRONTEND=noninteractive
192200apt-get purge -y $old_sec_pkg
193201apt-get install -y /$new_sec_pkg *.deb
194202rm -rf /$new_sec_pkg *.deb
195203EOF
196- chmod +x $conf_script
204+ chmod +x " $conf_script "
197205
198- mount --bind --make-rslave /proc $rootfs /proc
199- mount --bind --make-rslave /sys $rootfs /sys
200- mount --bind --make-rslave /dev $rootfs /dev
201- mount --bind --make-rslave /run $rootfs /run
206+ mount --bind --make-rslave /proc " $rootfs /proc"
207+ mount --bind --make-rslave /sys " $rootfs /sys"
208+ mount --bind --make-rslave /dev " $rootfs /dev"
209+ mount --bind --make-rslave /run " $rootfs /run"
202210
203211info " Applying patches:"
204212info " - $update_patch ."
205- tklpatch-apply-conf $rootfs $conf_script
213+ tklpatch-apply-conf " $rootfs " " $conf_script "
206214info " - $update_patch - done."
207- rm -rf $update_patch
215+ rm -rf " $update_patch "
208216for patch in $patches ; do
209217 info " - $patch ."
210- [[ ! -d " $patch /overlay" ]] || tklpatch-apply-overlay $patch /overlay
211- tklpatch-apply-conf $rootfs $patch /conf
218+ [[ ! -d " $patch /overlay" ]] || tklpatch-apply-overlay " $patch /overlay"
219+ tklpatch-apply-conf " $rootfs " " $patch /conf"
212220 info " - $patch - done."
213221done
214- tklpatch-apply-cleanup $rootfs
222+ tklpatch-apply-cleanup " $rootfs "
215223
216224_umount
217225
218226info " Cleaning up rootfs and rebuilding new ISO."
219- $BT /bin/rootfs-cleanup $rootfs
220- $BT /bin/aptconf-tag $rootfs iso
221- tklpatch-prepare-cdroot $rootfs $cdroot
222- TKLPATCH_ISOLABEL=${appname} tklpatch-geniso $cdroot $new_isofile
227+ " $BT /bin/rootfs-cleanup" " $rootfs "
228+ " $BT /bin/aptconf-tag" " $rootfs " iso
229+ tklpatch-prepare-cdroot " $rootfs " " $cdroot "
230+ TKLPATCH_ISOLABEL=${appname} tklpatch-geniso " $cdroot " " $new_isofile "
223231
224232info " Preparing release files."
225- $BT /bin/generate-signature $O /$new_isofile
226- $BT /bin/generate-manifest $rootfs > $O /$new_name .manifest
227- $BT /bin/generate-buildenv iso $appname > $O /$new_name .iso.buildenv
228- if [ -e $BT_PROFILES /$appname ]; then
229- mkdir -p $O /$new_name .tklbam
233+ " $BT /bin/generate-signature" " $O /$new_isofile "
234+ " $BT /bin/generate-manifest" " $rootfs " > " $O /$new_name .manifest"
235+ " $BT /bin/generate-buildenv" iso " $appname " > " $O /$new_name .iso.buildenv"
236+ if [[ -e " $BT_PROFILES /$appname " ] ]; then
237+ mkdir -p " $O /$new_name .tklbam"
230238 export PROFILES_CONF=$BT_PROFILES
231- $BT /bin/generate-tklbam-profile $O /$new_name .iso $O /$new_name .tklbam
239+ " $BT /bin/generate-tklbam-profile" " $O /$new_name .iso" " $O /$new_name .tklbam"
232240fi
233241_cleanup
234242
235- if [ " $publish " == " yes" ]; then
236- $BT /bin/iso-publish $BT_ISOS /$new_name .iso
237- if [[ -z " BT_DEBUG" ]]; then
238- rm -rf $BT_ISOS /$name .iso*
239- rm -rf $ BT_ISOS/ $ new_name*
243+ if [[ " $publish " == " yes" ] ]; then
244+ " $BT /bin/iso-publish" " $BT_ISOS /$new_name .iso"
245+ if [[ -z " $ BT_DEBUG" ]]; then
246+ rm -rf " $BT_ISOS /$name .iso*"
247+ rm -rf " ${ BT_ISOS:? } / ${ new_name:? } * "
240248 fi
241249fi
0 commit comments