Skip to content

Commit

Permalink
Error handling code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
gitbls committed Jul 15, 2024
1 parent b19be70 commit bd29617
Show file tree
Hide file tree
Showing 26 changed files with 80 additions and 116 deletions.
9 changes: 3 additions & 6 deletions plugins/apps
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ then

if [[ "$apps" == "" ]] && [[ "$remove" == "" ]]
then
logtoboth "? Plugin $pfx: Neither 'apps' nor 'remove' specified; Nothing to do"
exit 1
logtobothex "? Plugin $pfx: Neither 'apps' nor 'remove' specified; Nothing to do"
fi
if [[ -f $assetdir/default ]] && [[ "$name" == "" ]]
then
logtoboth "? Plugin $pfx: Default apps list already set; this and subsequent apps plugins must provide 'name' argument"
exit 1
logtobothex "? Plugin $pfx: Default apps list already set; this and subsequent apps plugins must provide 'name' argument"
else
[ "$name" == "" ] && name="default"
mkdir -p $assetdir
Expand All @@ -53,8 +51,7 @@ then
if [ -f $assetdir/$name ]
then
logtoboth "? Plugin $pfx: Apps list '$name' already exists; Add argument 'name=somename' to this apps plugin invocation"
logtoboth " NOTE: This plugin is not idempotent; Restart with a fresh uncustomized IMG if this IMG is previously customized"
exit 1
logtobothex " NOTE: This plugin is not idempotent; Restart with a fresh uncustomized IMG if this IMG is previously customized"
fi
echo "$apps" > $assetdir/$name
logtoboth "> Plugin $pfx [$name]: Saved apps list: $apps"
Expand Down
10 changes: 4 additions & 6 deletions plugins/apt-addrepo
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ then
if [ -f $SDMPT/etc/apt/sources.list.d/$name.list ]
then
logtoboth "? Plugin $pfx: Repo '$name' already exists; Add argument 'name=somename' to this apps plugin invocation"
logtoboth " NOTE: This plugin is not idempotent; Restart with a fresh uncustomized IMG if this IMG is previously customized"
exit 1
logtobothex " NOTE: This plugin is not idempotent; Restart with a fresh uncustomized IMG if this IMG is previously customized"
fi
echo "$repo" >> $SDMPT/etc/apt/sources.list.d/$name.list
fi
Expand All @@ -47,12 +46,11 @@ then
if [ -f $repofile ]
then
rbn=$(basename $repofile)
[[ "${rbn##*.}" != "list" ]] && errexit "? Plugin $pfx: apt Repo file '$repofile' must have file type '.list'"
[[ "${rbn##*.}" != "list" ]] && logtobothex "? Plugin $pfx: apt Repo file '$repofile' must have file type '.list'"
logtoboth "> Plugin $pfx: Add apt repo sources file '$repofile'"
cp $repofile $SDMPT/etc/apt/sources.list.d
else
logtoboth "? Plugin $pfx: Repo source file '$repofile' not found"
exit 1
logtobothex "? Plugin $pfx: Repo source file '$repofile' not found"
fi
fi
if [[ -v gpgkey ]] && [[ -f $gpgkey ]]
Expand All @@ -62,7 +60,7 @@ then
logtoboth "> Plugin $pfx: Copy gpg key '$gpgkey' to $SDMPT/etc/apt/trusted.gpg.d/$gpgkeyname.gpg"
cp $gpgkey $SDMPT/etc/apt/trusted.gpg.d
else
[[ "$(type -p gpg)" == "" ]] && errexit "? Please sudo apt install gpg"
[[ "$(type -p gpg)" == "" ]] && logtobothex "? Please sudo apt install gpg"
logtoboth "> Plugin $pfx: Download gpg key from $gpgkey and add to apt trusted keys"
curl -sS $gpgkey | gpg --dearmor | tee $SDMPT/etc/apt/trusted.gpg.d/$gpgkeyname.gpg
fi
Expand Down
3 changes: 1 addition & 2 deletions plugins/apt-file
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ else
then
doapt update $showapt apt-file || logapterror
else
logtoboth "? Plugin $pfx: apt-file appears to not be installed"
exit 1
logtobothex "? Plugin $pfx: apt-file appears to not be installed"
fi

#
Expand Down
8 changes: 3 additions & 5 deletions plugins/bootconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function loadparams() {

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

Expand Down Expand Up @@ -53,8 +53,7 @@ function updateconfigtxt() {
fi
else
logtoboth "? ${pfx}Error detected in updateconfigtxt. Please report error along with command line on GitHub"
logtoboth " Details: c:|$c| value:|$value|"
exit 1
logtobothex " Details: c:|$c| value:|$value|"
fi
sname="${c}=${dnm}"
sval="${drest}"
Expand Down Expand Up @@ -147,8 +146,7 @@ then
cp -a $reset $cfgdir/config.txt
setfileownmode $cfgdir/config.txt 644 #Doesn't matter on FAT, but wth
else
logtoboth "? Plugin $pfx: $cfgdir/config.txt reset file '$reset' not found"
exit 1
logtobothex "? Plugin $pfx: $cfgdir/config.txt reset file '$reset' not found"
fi
else
logtoboth "% Plugin $pfx: Reset $cfgdir/config.txt to null file"
Expand Down
6 changes: 3 additions & 3 deletions plugins/btwifiset
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function installreqs() {
logtoboth "> Plugin $pfx: Install required Python components: $pycomponents"
doaptrpterror "install --yes $pycomponents"
sts=$?
[ $sts -ne 0 ] && errexit "? Error returned from apt install ($sts)"
[ $sts -ne 0 ] && logtobothex "? Error returned from apt install ($sts)"
fi

# Create the venv if installing cryptography or dbus with pip
Expand All @@ -117,12 +117,12 @@ function installreqs() {
if [ $pipcrypto -eq 1 ]
then
sts=$(installviapip cryptography $vpip3 "" "> Plugin $pfx: Install 'cryptography' in the btwifiset venv via pip3")
[ $sts -ne 0 ] && errexit "? Error returned from '$vpip3 install cryptography' ($sts)"
[ $sts -ne 0 ] && logtobothex "? Error returned from '$vpip3 install cryptography' ($sts)"
fi
if [ $pipdbus -eq 1 ]
then
sts=$(installviapip dbus-python $vpip3 "" "> Plugin $pfx: Install 'dbus-python' in the btwifiset venv via pip3")
[ $sts -ne 0 ] && errexit "? Error returned from '$vpip3 install dbus-python' ($sts)"
[ $sts -ne 0 ] && logtobothex "? Error returned from '$vpip3 install dbus-python' ($sts)"
fi
fi
# ^^ Above code from btwifisetInstall.sh
Expand Down
3 changes: 1 addition & 2 deletions plugins/chrony
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ then
mkdir -p $assetdir/$did
cp -a $idf $assetdir/$did
else
logtoboth "? Plugin $pfx: '$id' config file '$idf' not found"
exit 1
logtobothex "? Plugin $pfx: '$id' config file '$idf' not found"
fi
fi
done
Expand Down
10 changes: 4 additions & 6 deletions plugins/copyfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ if [ ! -d $dest ]
then
if [ -f $dest ]
then
logtoboth "? Plugin $pfx: Destination '$dest' is a file but must be a directory"
exit 1
logtobothex "? Plugin $pfx: Destination '$dest' is a file but must be a directory"
else
dirflag="mkdir-${dest//\/}" # strip slashes to make a nice flag file name
[ -f /etc/sdm/assets/copyfile/$dirflag ] || { logtoboth "? Plugin $pfx: Destination directory '$dest' does not exist and mkdirif not specified" ; exit 1 ; }
[ -f /etc/sdm/assets/copyfile/$dirflag ] || logtobothex "? Plugin $pfx: Destination directory '$dest' does not exist and mkdirif not specified"
fi
logtoboth "> Plugin $pfx: Create destination directory '$dest'"
fi
Expand Down Expand Up @@ -114,7 +113,7 @@ then
plugin_printkeys
if [ "$filelist" == "" ]
then
[[ "$from" == "" ]] || [[ "$to" == "" ]] && logtoboth "? Plugin $pfx: Nothing to do! One or both of 'from' or 'to' missing and no 'filelist' provided" && exit 1
[[ "$from" == "" ]] || [[ "$to" == "" ]] && logtobothex "? Plugin $pfx: Nothing to do! One or both of 'from' or 'to' missing and no 'filelist' provided"
fi
if [ "$runphase" != "" ]
then
Expand Down Expand Up @@ -156,8 +155,7 @@ then
p0copyfile "$from" "$to" "$chown" "$chmod" "$mkdirif" $runphase
done < $filelist
else
logtoboth "? Plugin $pfx: File for filelist '$filelist' not found"
exit 1
logtobothex "? Plugin $pfx: File for filelist '$filelist' not found"
fi
fi
logtoboth "* Plugin $pfx: Complete Phase 0"
Expand Down
11 changes: 5 additions & 6 deletions plugins/cryptroot
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,22 @@ then
logtoboth "> Plugin $pfx: Copy authkeys file '$authkeys' to $assetdir"
cp -a $authkeys $assetdir
else
logtoboth "? Plugin $pfx: authkeys file '$authkeys' not found"
exit 1
logtobothex "? Plugin $pfx: authkeys file '$authkeys' not found"
fi
else
[ "$ssh" == "y" ] && { logtoboth "? Plugin $pfx: 'ssh' requires 'authkeys'" ; exit 1 ; }
[ "$ssh" == "y" ] && logtobothex "? Plugin $pfx: 'ssh' requires 'authkeys'"
fi
if [ "$keyfile" != "" ]
then
[ -f $keyfile ] || { logtoboth "? Plugin $pfx: keyfile '$keyfile' not found" ; exit 1 ; }
[ -f $keyfile ] || logtobothex "? Plugin $pfx: keyfile '$keyfile' not found"
logtoboth "> Plugin $pfx: Save keyfile to /etc/sdm/assets/cryptroot (deleted later)"
cp $keyfile $assetdir
else
[ "$nopwd" == "y" ] && { logtoboth "? Plugin $pfx: 'nopwd' requires 'keyfile'" ; exit 1 ; }
[ "$nopwd" == "y" ] && logtobothex "? Plugin $pfx: 'nopwd' requires 'keyfile'"
fi
if [ "$crypto" != "" ]
then
[[ "aes|xchacha" =~ "$crypto" ]] || [[ "$crypto" =~ "aes-" ]] || { logtoboth "? Plugin $pfx: Supported cryptos: aes and xchacha" ; exit 1 ; }
[[ "aes|xchacha" =~ "$crypto" ]] || [[ "$crypto" =~ "aes-" ]] || logtobothex "? Plugin $pfx: Supported cryptos: aes and xchacha"
fi
logtoboth "* Plugin $pfx: Complete Phase 0"
elif [ "$phase" == "1" ]
Expand Down
4 changes: 2 additions & 2 deletions plugins/extractfs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ then
# Print the keys found (example usage). plugin_getargs returns the list of found keys in $foundkeys
#
plugin_printkeys
[ -d $bootfs ] || { logtoboth "? Plugin $pfx: bootfs target '$bootfs' must be a directory" ; exit 1 ; }
[ -d $rootfs ] || { logtoboth "? Plugin $pfx: rootfs target '$rootfs' must be a directory" ; exit 1 ; }
[ -d $bootfs ] || logtobothex "? Plugin $pfx: bootfs target '$bootfs' must be a directory"
[ -d $rootfs ] || logtobothex "? Plugin $pfx: rootfs target '$rootfs' must be a directory"
dimg=$burndev
[ "$dimg" == "" ] && dimg="$burnfilefile"
declare -x SDMPT=$(makemtpt)
Expand Down
6 changes: 3 additions & 3 deletions plugins/git-clone
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ then
logtoboth "> Plugin $pfx: Copy preclone file '$fn' to $assetdir"
cp $fn $assetdir
else
errexit "? preclone file '$fn' not found"
logtobothex "? preclone file '$fn' not found"
fi
fi
if [ "${postclone:0:1}" == "@" ]
Expand All @@ -101,7 +101,7 @@ then
logtoboth "> Plugin $pfx: Copy postclone file '$fn' to $assetdir"
cp $fn $assetdir
else
errexit "? postclone file '$fn' not found"
logtobothex "? postclone file '$fn' not found"
fi
fi
if [ "$cert" != "" ]
Expand All @@ -113,7 +113,7 @@ then
logtoboth "> Plugin $pfx: Copy cert '$cert' to $assetdir"
cp -a $cert $assetdir
else
errexit "? Cert '$cert' not found"
logtobothex "? Cert '$cert' not found"
fi
fi
logtoboth "* Plugin $pfx: Complete Phase 0"
Expand Down
3 changes: 1 addition & 2 deletions plugins/hotspot
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ function parsehsconfig() {
printf -v "$rpifun" "%s" "$value"
;;
*)
logtoboth "? Plugin $pfx: Unrecognized hotspot option '$rpifun' in '$fhotspot'"
exit 1
logtobothex "? Plugin $pfx: Unrecognized hotspot option '$rpifun' in '$fhotspot'"
;;
esac
fi
Expand Down
3 changes: 1 addition & 2 deletions plugins/knockd
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ then
done
if [ $gsts -ne 0 ]
then
logtoboth "? Plugin $pfx: Unable to download pktables from $srcurl"
exit 1
logtobothex "? Plugin $pfx: Unable to download pktables from $srcurl"
fi
fi
logtoboth "* Plugin $pfx: Complete Phase 0"
Expand Down
15 changes: 5 additions & 10 deletions plugins/lxde
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ then
logtoboth "> Plugin $pfx: Copy '$lxfname' to $assetdir/$lxname/$username"
cp -a $lxfname $assetdir/$lxname/$username
else
logtoboth "? Plugin $pfx: lxde-config type '$lxname' file '$lxfname' not found"
exit 1
logtobothex "? Plugin $pfx: lxde-config type '$lxname' file '$lxfname' not found"
fi
;;
*) logtoboth "? Plugin $pfx: lxde-config item '$lxname' is unknown"
exit 1
*) logtobothex "? Plugin $pfx: lxde-config item '$lxname' is unknown"
;;
esac
done
Expand All @@ -63,8 +61,7 @@ then
logtoboth "> Plugin $pfx: copy '$wayfire__ini' to $assetdir/wayfire-ini/$username"
cp -a $wayfire__ini $assetdir/wayfire-ini/$username/wayfire.ini
else
logtoboth "? Plugin $pfx: wayfire-ini file '$wayfire__ini' not found"
exit 1
logtobothex "? Plugin $pfx: wayfire-ini file '$wayfire__ini' not found"
fi
fi
if [ "$wf__panel__pi" != "" ]
Expand All @@ -75,8 +72,7 @@ then
logtoboth "> Plugin $pfx: copy '$wf__panel__pi' to $assetdir/wf-panel-pi/$username"
cp -a $wf__panel__pi $assetdir/wf-panel-pi/$username/wf-panel-pi.ini
else
logtoboth "? Plugin $pfx: wf-panel-pi file '$wf__panel__pi' not found"
exit 1
logtobothex "? Plugin $pfx: wf-panel-pi file '$wf__panel__pi' not found"
fi
fi
logtoboth "* Plugin $pfx: Complete Phase 0"
Expand Down Expand Up @@ -106,8 +102,7 @@ else
[ "$dstuser" == "" ] && dstuser=$myuser
if [ "$dstuser" == "" ]
then
logtoboth "% Plugin $pfx: No users created with user plugin"
exit 1
logtobothex "? Plugin $pfx: No users created with user plugin"
fi
#logfreespace "at start of Plugin $pfx Phase post-install"

Expand Down
4 changes: 2 additions & 2 deletions plugins/modattr
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ assetdir="$SDMPT/etc/sdm/assets/$pfx"

logtoboth "* Plugin $pfx: Start Phase $phase"
plugin_getargs $pfx "$args" "$vldargs" "$rqdargs" || exit
[[ "$chmod" == "" ]] && [[ "$chown" == "" ]] && errexit "? Plugin $pfx: At least one of chmod or chown must be specified"
[[ "$chmod" == "" ]] && [[ "$chown" == "" ]] && logtobothex "? Plugin $pfx: At least one of chmod or chown must be specified"
if [ "$runphase" != "" ]
then
runphase="${runphase,,}"
Expand All @@ -125,7 +125,7 @@ fi

if [ "$verbose" != "" ]
then
[[ "changes|silent|verbose" =~ "$verbose" ]] || errexit "? Plugin $pfx: Invalid 'verbose' keyword value '$verbose'"
[[ "changes|silent|verbose" =~ "$verbose" ]] || logtobothex "? Plugin $pfx: Invalid 'verbose' keyword value '$verbose'"
fi
[ -v R ] || [ -v recursive ] && recurs="-R" || recurs=""

Expand Down
3 changes: 1 addition & 2 deletions plugins/ndm
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ then
logtoboth "> Plugin $pfx: copy ndm config '$config' to $SDMPT/etc/dbndm.json"
cp -a $config $SDMPT/etc/dbndm.json
else
logtoboth "? Plugin $pfx: config file '$config' not found"
exit 1
logtobothex "? Plugin $pfx: config file '$config' not found"
fi
fi

Expand Down
12 changes: 4 additions & 8 deletions plugins/network
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ function cfgdhcpcdwifi() {
then
IFS="=" read a wificountry <<< $(grep 'country=' $assetdir/wpa.conf | head -n 1)
else
logtoboth "? Plugin $pfx: Cannot find $assetdir/wpa.conf"
exit 1
logtobothex "? Plugin $pfx: Cannot find $assetdir/wpa.conf"
fi
else
if [ "$wifissid" != "" -a "$wifipassword" != "" -a "$wificountry" != "" ]
Expand Down Expand Up @@ -135,8 +134,7 @@ then
logtoboth "> Plugin $pfx: Copy wpa_supplicant config file '$wpa' to $assetdir/wpa.conf"
tr -d '\r' < $wpa > $assetdir/wpa.conf
else
logtoboth "? Plugin $pfx: wpa file '$wpa' not found"
exit 1
logtobothex "? Plugin $pfx: wpa file '$wpa' not found"
fi
fi
case "${netman}" in
Expand All @@ -148,8 +146,7 @@ then
logtoboth "> Plugin $pfx: Copy dhcpcdappend file '$dhcpcdappend' to $assetdir/dhcpcd-append.conf"
cp -a $dhcpcdappend $assetdir/dhcpcd-append.conf
else
logtoboth "? Plugin $pfx: dhcpcdappend file '$dhcpcdappend' not found"
exit 1
logtobothex "? Plugin $pfx: dhcpcdappend file '$dhcpcdappend' not found"
fi
fi
cfgdhcpcdwifi
Expand All @@ -171,8 +168,7 @@ then
logtoboth "> Plugin $pfx: Copy $conf '$c' to $assetdir/$conf"
cp -a $c $assetdir/$conf
else
logtoboth "% Plugin $pfx: $conf file '$c' not found"
exit 1
logtobothex "? Plugin $pfx: $conf file '$c' not found"
fi
done
fi
Expand Down
Loading

0 comments on commit bd29617

Please sign in to comment.