Index: scripts/factory_reset.sh =================================================================== diff -u -r15f9b824713355427ea8a1de5e0a7ecca5392c28 -rb743e6d20c409d112cfe5a82366dbdf79460203c --- scripts/factory_reset.sh (.../factory_reset.sh) (revision 15f9b824713355427ea8a1de5e0a7ecca5392c28) +++ scripts/factory_reset.sh (.../factory_reset.sh) (revision b743e6d20c409d112cfe5a82366dbdf79460203c) @@ -16,28 +16,29 @@ # ############################################################################ -# @details -# This file is called by UI Software to remove and reset the device +# Description +# - delete WiFi settings +# - delete Bluetooth settings +# - settings.conf to default +# - brightness to default (5) +# - delete logs +# - keep partition password +# - keep service password +# - keep cloudsync tokens +# Parameters +# - None -#TODO This script needs to be integrated with the globals.sh +# sources +. ./_errors_ +. ./_functions_ -ERR_REMOVE_PRM_DIR=150 -ERR_REMOVE_PRM_FIL=151 -ERR_REMOVE_CMD_DIR=152 -ERR_REMOVE_CMD_FIL=153 -ERR_REMOVE_DEL_DIR=154 -ERR_REMOVE_DEL_FIL=155 +# variables +PARAM_COUNT=0 -ERR_CLEAN_SETTINGS_CONF_PASSNOTFOUND=159 -ERR_CLEAN_SETTINGS_CONF_OVERWRITE=160 -ERR_CLEAN_SETTINGS_DFLT_RESTORE=161 - -ERR_CLEAN_LOGS=162 - LOC_SETTINGS_CONF="/opt/leahi/configurations/Settings/System.conf" LOC_SETTINGS_DFLT="/opt/leahi/configurations/Settings/System.dflt" LOC_LOG_BASE_FOLDER="/media/sd-card/" -LOC_TX_LOG_BASE_FOLDER="/var/configurations/treatment/" +LOC_TX_LOG_BASE_FOLDER="/opt/leahi/configurations/treatment/" LOC_SCRIPTS=/opt/leahi/scripts LOC_SCRIPTS_BRIGHTNESS=$LOC_SCRIPTS/brightness.sh @@ -46,34 +47,7 @@ TRUE=1 FALSE=0 -# check if the passed argument is a non-zero number -function isNonZero () - # $1 - mutant: the argument to be detected -{ - local _ok_=$FALSE - if [[ $1 =~ ^[0-9]+$ ]]; then - if (( $1 )); then - _ok_=$TRUE - fi - fi - echo $_ok_ -} - -# exits with the exit code if the condition ($1) is non-zero -function exitError () - # $1 - number: boolean result to exit if non-zero, with exit code - # $1 - number: exit code - # $2 - string: echo message [optional] -{ - if (( $2 )); then - echo "$3" - fi - - if (( $(isNonZero $1) )); then - exit $2 - fi -} - +# functions function deleteWiFi() { $LOC_SCRIPTS/wifi_disconnect_network.sh wlan0 } @@ -83,19 +57,14 @@ } function defaultSettings() { - local _has_error_=$FALSE - servicePasswordLine=$(grep -A1 "\[Service\]" "$LOC_SETTINGS_CONF" | grep Password) # store the service password line - _has_error_= [[ -z "$servicePasswordLine" ]] - exitError $_has_error_ $ERR_CLEAN_SETTINGS_CONF_PASSNOTFOUND "Password not found in '$LOC_SETTINGS_CONF'" + check_result "$?" "$ERR_CMDFAIL_SETTINGS_CONF_PASSNOTFOUND" cp $LOC_SETTINGS_DFLT $LOC_SETTINGS_CONF # reset the settings to default settings - _has_error_=$? - exitError $_has_error_ $ERR_CLEAN_SETTINGS_CONF_OVERWRITE "Service settings overwrite failed" + check_result "$?" "$ERR_CMDFAIL_SETTINGS_CONF_OVERWRITE" - sed -i "s/^.*Password.*$/$servicePasswordLine/" $LOC_SETTINGS_CONF # keep the service password - _has_error_=$? - exitError $_has_error_ $ERR_CLEAN_SETTINGS_DFLT_RESTORE "Service password restore failed" + sed -i "s/^.*Password.*$/$servicePasswordLine/" $LOC_SETTINGS_CONF # keep the service password + check_result "$?" "$ERR_CMDFAIL_SETTINGS_DFLT_RESTORE" } function defaultBrightness() { @@ -110,40 +79,31 @@ # - setting maxDepth to 2 due to path used is root level with sd-card/ folders of logs # NOTE: find command always return true / non-zero! when using with exec # TODO: Checking the file count should be fixed later - + # Remove the contents of the log folder rm "$LOC_LOG_BASE_FOLDER"/log/* _has_error_=!$? - exitError $_has_error_ $ERR_REMOVE_CMD_FIL "Log file deletion" - + check_result $_has_error_ "$ERR_CMDFAIL_SETTINGS_REMOVE_LOG_FOLDER" + # Remove the contents of the service folder rm "$LOC_LOG_BASE_FOLDER"/service/* _has_error_=!$? - exitError $_has_error_ $ERR_REMOVE_CMD_FIL "Service file deletion" + check_result $_has_error_ "$ERR_CMDFAIL_SETTINGS_REMOVE_SERVICE_LOG" fileCount=$(find "$LOC_LOG_BASE_FOLDER" -maxdepth 2 -type f -daystart -mtime +0 | wc -l) _has_error_=$fileCount - exitError $_has_error_ $ERR_REMOVE_DEL_FIL "Remained '$fileCount' file undeleted" + check_result $_has_error_ "$ERR_CMDFAIL_SETTINGS_COUNT_SERVICE_LOG" # Deleting treatment logs in encrypted partition: find "$LOC_TX_LOG_BASE_FOLDER" -maxdepth 2 -type f | xargs rm - _has_error_=!$? - exitError $_has_error_ $ERR_REMOVE_CMD_FIL "Tx Log file deletion" + check_result $_has_error_ "$ERR_CMDFAIL_SETTINGS_REMOVE_TX_LOG" fileCount=$(find "$LOC_TX_LOG_BASE_FOLDER" -maxdepth 2 -type f | wc -l) _has_error_=$fileCount - exitError $_has_error_ $ERR_REMOVE_DEL_FIL "Remained '$fileCount' file undeleted" + check_result $_has_error_ "$ERR_CMDFAIL_SETTINGS_COUNT_TX_LOG" } -# delete WiFi settings -# delete Bluetooth settings -# settings.conf to default -# brightness to default (10) -# delete logs -# keep partition password -# keep service password -# keep cloudsync tokens function main() { deleteWiFi deleteBluetooth @@ -152,6 +112,13 @@ deleteLogFiles } +# checks +check_param_count "$#" "$PARAM_COUNT" + +# main main + +# exit gracefully +sleep 0.1 echo "" -exit 0 +exit 0 \ No newline at end of file