Skip to content

Commit bd29617

Browse files
committed
Error handling code improvement
1 parent b19be70 commit bd29617

File tree

26 files changed

+80
-116
lines changed

26 files changed

+80
-116
lines changed

plugins/apps

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ then
3535

3636
if [[ "$apps" == "" ]] && [[ "$remove" == "" ]]
3737
then
38-
logtoboth "? Plugin $pfx: Neither 'apps' nor 'remove' specified; Nothing to do"
39-
exit 1
38+
logtobothex "? Plugin $pfx: Neither 'apps' nor 'remove' specified; Nothing to do"
4039
fi
4140
if [[ -f $assetdir/default ]] && [[ "$name" == "" ]]
4241
then
43-
logtoboth "? Plugin $pfx: Default apps list already set; this and subsequent apps plugins must provide 'name' argument"
44-
exit 1
42+
logtobothex "? Plugin $pfx: Default apps list already set; this and subsequent apps plugins must provide 'name' argument"
4543
else
4644
[ "$name" == "" ] && name="default"
4745
mkdir -p $assetdir
@@ -53,8 +51,7 @@ then
5351
if [ -f $assetdir/$name ]
5452
then
5553
logtoboth "? Plugin $pfx: Apps list '$name' already exists; Add argument 'name=somename' to this apps plugin invocation"
56-
logtoboth " NOTE: This plugin is not idempotent; Restart with a fresh uncustomized IMG if this IMG is previously customized"
57-
exit 1
54+
logtobothex " NOTE: This plugin is not idempotent; Restart with a fresh uncustomized IMG if this IMG is previously customized"
5855
fi
5956
echo "$apps" > $assetdir/$name
6057
logtoboth "> Plugin $pfx [$name]: Saved apps list: $apps"

plugins/apt-addrepo

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ then
3737
if [ -f $SDMPT/etc/apt/sources.list.d/$name.list ]
3838
then
3939
logtoboth "? Plugin $pfx: Repo '$name' already exists; Add argument 'name=somename' to this apps plugin invocation"
40-
logtoboth " NOTE: This plugin is not idempotent; Restart with a fresh uncustomized IMG if this IMG is previously customized"
41-
exit 1
40+
logtobothex " NOTE: This plugin is not idempotent; Restart with a fresh uncustomized IMG if this IMG is previously customized"
4241
fi
4342
echo "$repo" >> $SDMPT/etc/apt/sources.list.d/$name.list
4443
fi
@@ -47,12 +46,11 @@ then
4746
if [ -f $repofile ]
4847
then
4948
rbn=$(basename $repofile)
50-
[[ "${rbn##*.}" != "list" ]] && errexit "? Plugin $pfx: apt Repo file '$repofile' must have file type '.list'"
49+
[[ "${rbn##*.}" != "list" ]] && logtobothex "? Plugin $pfx: apt Repo file '$repofile' must have file type '.list'"
5150
logtoboth "> Plugin $pfx: Add apt repo sources file '$repofile'"
5251
cp $repofile $SDMPT/etc/apt/sources.list.d
5352
else
54-
logtoboth "? Plugin $pfx: Repo source file '$repofile' not found"
55-
exit 1
53+
logtobothex "? Plugin $pfx: Repo source file '$repofile' not found"
5654
fi
5755
fi
5856
if [[ -v gpgkey ]] && [[ -f $gpgkey ]]
@@ -62,7 +60,7 @@ then
6260
logtoboth "> Plugin $pfx: Copy gpg key '$gpgkey' to $SDMPT/etc/apt/trusted.gpg.d/$gpgkeyname.gpg"
6361
cp $gpgkey $SDMPT/etc/apt/trusted.gpg.d
6462
else
65-
[[ "$(type -p gpg)" == "" ]] && errexit "? Please sudo apt install gpg"
63+
[[ "$(type -p gpg)" == "" ]] && logtobothex "? Please sudo apt install gpg"
6664
logtoboth "> Plugin $pfx: Download gpg key from $gpgkey and add to apt trusted keys"
6765
curl -sS $gpgkey | gpg --dearmor | tee $SDMPT/etc/apt/trusted.gpg.d/$gpgkeyname.gpg
6866
fi

plugins/apt-file

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ else
5555
then
5656
doapt update $showapt apt-file || logapterror
5757
else
58-
logtoboth "? Plugin $pfx: apt-file appears to not be installed"
59-
exit 1
58+
logtobothex "? Plugin $pfx: apt-file appears to not be installed"
6059
fi
6160

6261
#

plugins/bootconfig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function loadparams() {
1111

1212
function writecfg() {
1313
local msg="$1"
14-
[ ${#msg} -gt 96 ] && { logtoboth "? Plugin $pfx: config.txt line too long (${#msg}>96): $msg" ; exit 1 ; }
14+
[ ${#msg} -gt 96 ] && logtobothex "? Plugin $pfx: config.txt line too long (${#msg}>96): $msg"
1515
printf "$1" >>$cfgdir/config.txt
1616
}
1717

@@ -53,8 +53,7 @@ function updateconfigtxt() {
5353
fi
5454
else
5555
logtoboth "? ${pfx}Error detected in updateconfigtxt. Please report error along with command line on GitHub"
56-
logtoboth " Details: c:|$c| value:|$value|"
57-
exit 1
56+
logtobothex " Details: c:|$c| value:|$value|"
5857
fi
5958
sname="${c}=${dnm}"
6059
sval="${drest}"
@@ -147,8 +146,7 @@ then
147146
cp -a $reset $cfgdir/config.txt
148147
setfileownmode $cfgdir/config.txt 644 #Doesn't matter on FAT, but wth
149148
else
150-
logtoboth "? Plugin $pfx: $cfgdir/config.txt reset file '$reset' not found"
151-
exit 1
149+
logtobothex "? Plugin $pfx: $cfgdir/config.txt reset file '$reset' not found"
152150
fi
153151
else
154152
logtoboth "% Plugin $pfx: Reset $cfgdir/config.txt to null file"

plugins/btwifiset

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function installreqs() {
105105
logtoboth "> Plugin $pfx: Install required Python components: $pycomponents"
106106
doaptrpterror "install --yes $pycomponents"
107107
sts=$?
108-
[ $sts -ne 0 ] && errexit "? Error returned from apt install ($sts)"
108+
[ $sts -ne 0 ] && logtobothex "? Error returned from apt install ($sts)"
109109
fi
110110

111111
# Create the venv if installing cryptography or dbus with pip
@@ -117,12 +117,12 @@ function installreqs() {
117117
if [ $pipcrypto -eq 1 ]
118118
then
119119
sts=$(installviapip cryptography $vpip3 "" "> Plugin $pfx: Install 'cryptography' in the btwifiset venv via pip3")
120-
[ $sts -ne 0 ] && errexit "? Error returned from '$vpip3 install cryptography' ($sts)"
120+
[ $sts -ne 0 ] && logtobothex "? Error returned from '$vpip3 install cryptography' ($sts)"
121121
fi
122122
if [ $pipdbus -eq 1 ]
123123
then
124124
sts=$(installviapip dbus-python $vpip3 "" "> Plugin $pfx: Install 'dbus-python' in the btwifiset venv via pip3")
125-
[ $sts -ne 0 ] && errexit "? Error returned from '$vpip3 install dbus-python' ($sts)"
125+
[ $sts -ne 0 ] && logtobothex "? Error returned from '$vpip3 install dbus-python' ($sts)"
126126
fi
127127
fi
128128
# ^^ Above code from btwifisetInstall.sh

plugins/chrony

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ then
4848
mkdir -p $assetdir/$did
4949
cp -a $idf $assetdir/$did
5050
else
51-
logtoboth "? Plugin $pfx: '$id' config file '$idf' not found"
52-
exit 1
51+
logtobothex "? Plugin $pfx: '$id' config file '$idf' not found"
5352
fi
5453
fi
5554
done

plugins/copyfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ if [ ! -d $dest ]
5151
then
5252
if [ -f $dest ]
5353
then
54-
logtoboth "? Plugin $pfx: Destination '$dest' is a file but must be a directory"
55-
exit 1
54+
logtobothex "? Plugin $pfx: Destination '$dest' is a file but must be a directory"
5655
else
5756
dirflag="mkdir-${dest//\/}" # strip slashes to make a nice flag file name
58-
[ -f /etc/sdm/assets/copyfile/$dirflag ] || { logtoboth "? Plugin $pfx: Destination directory '$dest' does not exist and mkdirif not specified" ; exit 1 ; }
57+
[ -f /etc/sdm/assets/copyfile/$dirflag ] || logtobothex "? Plugin $pfx: Destination directory '$dest' does not exist and mkdirif not specified"
5958
fi
6059
logtoboth "> Plugin $pfx: Create destination directory '$dest'"
6160
fi
@@ -114,7 +113,7 @@ then
114113
plugin_printkeys
115114
if [ "$filelist" == "" ]
116115
then
117-
[[ "$from" == "" ]] || [[ "$to" == "" ]] && logtoboth "? Plugin $pfx: Nothing to do! One or both of 'from' or 'to' missing and no 'filelist' provided" && exit 1
116+
[[ "$from" == "" ]] || [[ "$to" == "" ]] && logtobothex "? Plugin $pfx: Nothing to do! One or both of 'from' or 'to' missing and no 'filelist' provided"
118117
fi
119118
if [ "$runphase" != "" ]
120119
then
@@ -156,8 +155,7 @@ then
156155
p0copyfile "$from" "$to" "$chown" "$chmod" "$mkdirif" $runphase
157156
done < $filelist
158157
else
159-
logtoboth "? Plugin $pfx: File for filelist '$filelist' not found"
160-
exit 1
158+
logtobothex "? Plugin $pfx: File for filelist '$filelist' not found"
161159
fi
162160
fi
163161
logtoboth "* Plugin $pfx: Complete Phase 0"

plugins/cryptroot

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,22 @@ then
4747
logtoboth "> Plugin $pfx: Copy authkeys file '$authkeys' to $assetdir"
4848
cp -a $authkeys $assetdir
4949
else
50-
logtoboth "? Plugin $pfx: authkeys file '$authkeys' not found"
51-
exit 1
50+
logtobothex "? Plugin $pfx: authkeys file '$authkeys' not found"
5251
fi
5352
else
54-
[ "$ssh" == "y" ] && { logtoboth "? Plugin $pfx: 'ssh' requires 'authkeys'" ; exit 1 ; }
53+
[ "$ssh" == "y" ] && logtobothex "? Plugin $pfx: 'ssh' requires 'authkeys'"
5554
fi
5655
if [ "$keyfile" != "" ]
5756
then
58-
[ -f $keyfile ] || { logtoboth "? Plugin $pfx: keyfile '$keyfile' not found" ; exit 1 ; }
57+
[ -f $keyfile ] || logtobothex "? Plugin $pfx: keyfile '$keyfile' not found"
5958
logtoboth "> Plugin $pfx: Save keyfile to /etc/sdm/assets/cryptroot (deleted later)"
6059
cp $keyfile $assetdir
6160
else
62-
[ "$nopwd" == "y" ] && { logtoboth "? Plugin $pfx: 'nopwd' requires 'keyfile'" ; exit 1 ; }
61+
[ "$nopwd" == "y" ] && logtobothex "? Plugin $pfx: 'nopwd' requires 'keyfile'"
6362
fi
6463
if [ "$crypto" != "" ]
6564
then
66-
[[ "aes|xchacha" =~ "$crypto" ]] || [[ "$crypto" =~ "aes-" ]] || { logtoboth "? Plugin $pfx: Supported cryptos: aes and xchacha" ; exit 1 ; }
65+
[[ "aes|xchacha" =~ "$crypto" ]] || [[ "$crypto" =~ "aes-" ]] || logtobothex "? Plugin $pfx: Supported cryptos: aes and xchacha"
6766
fi
6867
logtoboth "* Plugin $pfx: Complete Phase 0"
6968
elif [ "$phase" == "1" ]

plugins/extractfs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ then
3232
# Print the keys found (example usage). plugin_getargs returns the list of found keys in $foundkeys
3333
#
3434
plugin_printkeys
35-
[ -d $bootfs ] || { logtoboth "? Plugin $pfx: bootfs target '$bootfs' must be a directory" ; exit 1 ; }
36-
[ -d $rootfs ] || { logtoboth "? Plugin $pfx: rootfs target '$rootfs' must be a directory" ; exit 1 ; }
35+
[ -d $bootfs ] || logtobothex "? Plugin $pfx: bootfs target '$bootfs' must be a directory"
36+
[ -d $rootfs ] || logtobothex "? Plugin $pfx: rootfs target '$rootfs' must be a directory"
3737
dimg=$burndev
3838
[ "$dimg" == "" ] && dimg="$burnfilefile"
3939
declare -x SDMPT=$(makemtpt)

plugins/git-clone

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ then
9090
logtoboth "> Plugin $pfx: Copy preclone file '$fn' to $assetdir"
9191
cp $fn $assetdir
9292
else
93-
errexit "? preclone file '$fn' not found"
93+
logtobothex "? preclone file '$fn' not found"
9494
fi
9595
fi
9696
if [ "${postclone:0:1}" == "@" ]
@@ -101,7 +101,7 @@ then
101101
logtoboth "> Plugin $pfx: Copy postclone file '$fn' to $assetdir"
102102
cp $fn $assetdir
103103
else
104-
errexit "? postclone file '$fn' not found"
104+
logtobothex "? postclone file '$fn' not found"
105105
fi
106106
fi
107107
if [ "$cert" != "" ]
@@ -113,7 +113,7 @@ then
113113
logtoboth "> Plugin $pfx: Copy cert '$cert' to $assetdir"
114114
cp -a $cert $assetdir
115115
else
116-
errexit "? Cert '$cert' not found"
116+
logtobothex "? Cert '$cert' not found"
117117
fi
118118
fi
119119
logtoboth "* Plugin $pfx: Complete Phase 0"

0 commit comments

Comments
 (0)