Index: scripts/factory_reset.sh =================================================================== diff -u -r171d48df58e510ae24a2abed14c52af564b375ee -r7d194844bb325200b78da21ae7457bb7f7543ec7 --- scripts/factory_reset.sh (.../factory_reset.sh) (revision 171d48df58e510ae24a2abed14c52af564b375ee) +++ scripts/factory_reset.sh (.../factory_reset.sh) (revision 7d194844bb325200b78da21ae7457bb7f7543ec7) @@ -45,7 +45,6 @@ DEFAULT_BRIGHTNESS_LEVEL=10 - TRUE=1 FALSE=0 function false() { echo $FALSE; } @@ -64,50 +63,6 @@ echo $_ok_ } -# checks if the passed argument is a number -function isNumber () - # $1 - mutant: the argument to be detected -{ - local _ok_=$FALSE - if [[ $1 =~ ^[0-9]+$ ]]; then - _ok_=$TRUE - fi - echo $_ok_ -} - -# checks if the passed argument is a directory -function isDirectory() - # $1 - string: the argument to be detected -{ - local _ok_=$FALSE - if [[ -d $1 ]]; then - _ok_=$TRUE - fi - echo $_ok_ -} - -# checks if the passed argument is a file -function isFile() - # $1 - string: the argument to be detected -{ - local _ok_=$FALSE - if [[ -f $1 ]]; then - _ok_=$TRUE - fi - echo $_ok_ -} - -# checks if the passed argument exists -function exists() - # $1 - string: the argument to be detected -{ - local _ok_=$FALSE - if [[ -e $1 ]]; then - _ok_=$TRUE - 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 @@ -123,47 +78,14 @@ fi } -# removes all the files in the directory and sub-directory in a recursive manner -function clearFolderContent() - # $1 - Directory path - # $2 - Directory alias name -{ - local _has_error_=$[ ! $(isDirectory $1)] - exitError $_has_error_ $ERR_REMOVE_PRM_DIR "'$1' is not a directory" - - rm -rf "$1/*/*" - _has_error_=$? - exitError $_has_error_ $ERR_REMOVE_CMD_DIR "Failed $2 folder deletion" - - list=("$1"/*) - fileCount=${#list[@]} - _has_error_=$fileCount - exitError $_has_error_ $ERR_REMOVE_DEL_DIR "Remained '$fileCount' file(s) undeleted" -} - -# exits rm command fails or if file was not removed -function removeSingleFile() - # $1 - path to file - # $2 - file alias name -{ - local _has_error_=$[ ! $(isFile $1)] - exitError $_has_error_ $ERR_REMOVE_PRM_FIL "'$1' is not a file" - - rm -f "$1" - _has_error_=$? - exitError $_has_error_ $ERR_REMOVE_CMD_FIL "Failed $2 file deletion" - - _has_error_=$(exists $1) - exitError $_has_error_ $ERR_REMOVE_DEL_FIL "Remained $2 file undeleted" -} - function deleteWiFi() { - SCRIPTS=/home/$(whoami)/scripts + SCRIPTS=/home/$(whoami)/ + # $SCRIPTS/wifi_disconnect.sh $SCRIPTS/wifi_disconnect_network.sh wlan0 } function deleteBluetooth() { - SCRIPTS=/home/$(whoami)/scripts + SCRIPTS=/home/$(whoami) $SCRIPTS/bluetooth_paired_clear.sh } Index: scripts/rootsshaccess.sh =================================================================== diff -u -r171d48df58e510ae24a2abed14c52af564b375ee -r7d194844bb325200b78da21ae7457bb7f7543ec7 --- scripts/rootsshaccess.sh (.../rootsshaccess.sh) (revision 171d48df58e510ae24a2abed14c52af564b375ee) +++ scripts/rootsshaccess.sh (.../rootsshaccess.sh) (revision 7d194844bb325200b78da21ae7457bb7f7543ec7) @@ -1,76 +1,76 @@ #!/bin/sh ########################################################################### # -# Copyright (c) 2021-2023 Diality Inc. - All Rights Reserved. +# Copyright (c) 2021-2025 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # -# @file ssh_access.sh +# @file rootsshaccess.sh # -# @author (last) Behrouz NematiPour -# @date (last) 23-aug-2023 -# @author (original) Behrouz NematiPour -# @date (original) 23-aug-2023 +# @author (last) Nico Ramirez +# @date (last) 4-Nov-2025 +# @author (original) Nico Ramirez +# @date (original) 4-Nov-2025 # ############################################################################ -TERM=dumb +SSHD_CONFIG="/etc/default/dropbear" +SSH_SERVICE="system-dropbear.slice" -ECHO_STRING="ssh connection" -SSHD_CONFIG="/etc/ssh/sshd_config" ERR_EXECUTION=201 _enable=1 _disable=0 #TODO Move to globals.sh function check_num() { - if [ $1 != 0 ]; then - echo "$1" + if [[ $1 != 0 ]]; then + # echo "execution failed $1" exit $ERR_EXECUTION fi } - function sshd_set() { - if [ $_enable == $1 ]; then - sudo systemctl start sshd.socket + if [[ $_enable == $1 ]]; then + sudo systemctl start $SSH_SERVICE check_num $? ", started" else - # is is always disabled but to make sure and be backward compatible will do it again. - sudo systemctl disable sshd.socket - check_num $? ", disabled" # stop the ssh service - sudo systemctl stop sshd.socket + sudo systemctl stop $SSH_SERVICE check_num $? ", stopped" fi } function sshd_get() { - out=$(sudo systemctl status sshd.socket | grep "Active: active (listening)") - if [ -n "$out" ]; then + if sudo systemctl is-active --quiet "$SSH_SERVICE"; then echo $_enable else echo $_disable fi } function root_set() { - if [ $_enable == $1 ]; then - sudo sed -i '/PermitRootLogin/c\PermitRootLogin yes' $SSHD_CONFIG + if [[ $_enable == $1 ]]; then + # Remove -w from DROPBEAR_EXTRA_ARGS if present + sudo sed -i 's/-w//g' $SSHD_CONFIG check_num $? " enabled" else - sudo sed -i '/PermitRootLogin/c\PermitRootLogin no' $SSHD_CONFIG - check_num $? " disalbed" + # Add -w if not already present + if ! grep -q '\-w' $SSHD_CONFIG; then + # Append to DROPBEAR_EXTRA_ARGS + sudo sed -i '/^DROPBEAR_EXTRA_ARGS=/ s/"$/ -w"/' $SSHD_CONFIG + fi + check_num $? " disabled" fi } function root_get() { - if [ "$(grep -ir "^PermitRootLogin" $SSHD_CONFIG | tr -s ' ' | cut -f2 -d' ')" == "yes" ]; then - echo $_enable - else + # Dropbear disables root login if the -w flag is present in DROPBEAR_EXTRA_ARGS. + if grep -q '\-w' $SSHD_CONFIG; then echo $_disable + else + echo $_enable fi } @@ -100,12 +100,13 @@ function toCheckState() { local sshd=$(sshd_get) local root=$(root_get) + case $sshd in $_disable) echo 0 ;; $_enable) - echo $(( $sshd + $root )) + echo $(( $sshd + $root )) ;; esac } @@ -116,6 +117,7 @@ ;; 1) handleCommand $1 + echo $(toCheckState) ;; esac