Index: scripts/autostart =================================================================== diff -u --- scripts/autostart (revision 0) +++ scripts/autostart (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,30 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2019-2023 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 autostart +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Dec-2022 +# @author (original) Behrouz NematiPour +# @date (original) 28-Oct-2019 +# +############################################################################ +case "$1" in + start) + logger "Starting autostart scripts" + HOME="/home/root" + cd "$HOME" + ./run.sh "$HOME" + logger $? + exit 0 + ;; + *) + echo "It's just a startup script and has no arguments or commands" + exit 1 + ;; +esac Index: scripts/bluetooth_main.conf =================================================================== diff -u --- scripts/bluetooth_main.conf (revision 0) +++ scripts/bluetooth_main.conf (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,130 @@ +[General] + +# Default adapter name +# Defaults to 'BlueZ X.YZ' +Name = 'DEVICE_NAME' + +# Default device class. Only the major and minor device class bits are +# considered. Defaults to '0x000000'. +#Class = 0x000100 + +# How long to stay in discoverable mode before going back to non-discoverable +# The value is in seconds. Default is 180, i.e. 3 minutes. +# 0 = disable timer, i.e. stay discoverable forever +#DiscoverableTimeout = 0 + +# Always allow pairing even if there are no agent registered +# Possible values: true, false +# Default: false +AlwaysPairable = true + +# How long to stay in pairable mode before going back to non-discoverable +# The value is in seconds. Default is 0. +# 0 = disable timer, i.e. stay pairable forever +#PairableTimeout = 0 + +# Use vendor id source (assigner), vendor, product and version information for +# DID profile support. The values are separated by ":" and assigner, VID, PID +# and version. +# Possible vendor id source values: bluetooth, usb (defaults to usb) +#DeviceID = bluetooth:1234:5678:abcd + +# Do reverse service discovery for previously unknown devices that connect to +# us. For BR/EDR this option is really only needed for qualification since the +# BITE tester doesn't like us doing reverse SDP for some test cases, for LE +# this disables the GATT client functionally so it can be used in system which +# can only operate as peripheral. +# Defaults to 'true'. +#ReverseServiceDiscovery = true + +# Enable name resolving after inquiry. Set it to 'false' if you don't need +# remote devices name and want shorter discovery cycle. Defaults to 'true'. +#NameResolving = true + +# Enable runtime persistency of debug link keys. Default is false which +# makes debug link keys valid only for the duration of the connection +# that they were created for. +DebugKeys = true + +# Restricts all controllers to the specified transport. Default value +# is "dual", i.e. both BR/EDR and LE enabled (when supported by the HW). +# Possible values: "dual", "bredr", "le" +#ControllerMode = dual + +# Enables Multi Profile Specification support. This allows to specify if +# system supports only Multiple Profiles Single Device (MPSD) configuration +# or both Multiple Profiles Single Device (MPSD) and Multiple Profiles Multiple +# Devices (MPMD) configurations. +# Possible values: "off", "single", "multiple" +# CHANGE_THIS_VALUE_TO: multiple +MultiProfile = "multiple" + +# Permanently enables the Fast Connectable setting for adapters that +# support it. When enabled other devices can connect faster to us, +# however the tradeoff is increased power consumptions. This feature +# will fully work only on kernel version 4.1 and newer. Defaults to +# 'false'. +#FastConnectable = false + +# Default privacy setting. +# Enables use of private address. +# Possible values: "off", "device", "network" +# "network" option not supported currently +# Defaults to "off" +# Privacy = off + +# Specify the policy to the JUST-WORKS repairing initiated by peer +# Possible values: "never", "confirm", "always" +# Defaults to "never" +JustWorksRepairing = always + +[GATT] +# GATT attribute cache. +# Possible values: +# always: Always cache attributes even for devices not paired, this is +# recommended as it is best for interoperability, with more consistent +# reconnection times and enables proper tracking of notifications for all +# devices. +# yes: Only cache attributes of paired devices. +# no: Never cache attributes +# Default: always +#Cache = always + +# Minimum required Encryption Key Size for accessing secured characteristics. +# Possible values: 0 and 7-16. 0 means don't care. +# Defaults to 0 +#KeySize = 0 + +# Exchange MTU size. +# Possible values: 23-517 +# Defaults to 517 +#ExchangeMTU = 517 + +# Number of ATT channels +# Possible values: 1-5 (1 disables EATT) +# Default to 3 +#Channels = 3 + +[Policy] +# +# The ReconnectUUIDs defines the set of remote services that should try +# to be reconnected to in case of a link loss (link supervision +# timeout). The policy plugin should contain a sane set of values by +# default, but this list can be overridden here. By setting the list to +# empty the reconnection feature gets disabled. +#ReconnectUUIDs=00001112-0000-1000-8000-00805f9b34fb,0000111f-0000-1000-8000-00805f9b34fb,0000110a-0000-1000-8000-00805f9b34fb + +# ReconnectAttempts define the number of attempts to reconnect after a link +# lost. Setting the value to 0 disables reconnecting feature. +#ReconnectAttempts=7 + +# ReconnectIntervals define the set of intervals in seconds to use in between +# attempts. +# If the number of attempts defined in ReconnectAttempts is bigger than the +# set of intervals the last interval is repeated until the last attempt. +#ReconnectIntervals=1,2,4,8,16,32,64 + +# AutoEnable defines option to enable all controllers when they are found. +# This includes adapters present on start as well as adapters that are plugged +# in later on. Defaults to 'false'. +AutoEnable=true Index: scripts/bluetooth_paired_clear.sh =================================================================== diff -u --- scripts/bluetooth_paired_clear.sh (revision 0) +++ scripts/bluetooth_paired_clear.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,39 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 bluetooth_paired_clear.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-Nov-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-Nov-2021 +# +############################################################################ + +# @details +# This file is called by UI Software to removed all the currnelty paired or cached devices. +# This is done before each scan to clean up and start a fresh scan. + +DEVICES=$(echo "devices" | bluetoothctl | grep ^Device | cut -b 8-25) +if [ ! -z "$DEVICES" ]; then + for device in $DEVICES; do + if [ ! -z "$device" ]; then + echo "remove $device" | bluetoothctl + fi + done +fi + +PAIRED_DEVICES=$(echo "paired-devices" | bluetoothctl | grep ^Device | cut -b 8-25) +if [ ! -z "$PAIRED_DEVICES" ]; then + for paired_device in $PAIRED_DEVICES; do + if [ ! -z "$paired_device" ]; then + echo "remove $paired_device" | bluetoothctl + fi + done +fi + Index: scripts/bluetooth_paired_query.sh =================================================================== diff -u --- scripts/bluetooth_paired_query.sh (revision 0) +++ scripts/bluetooth_paired_query.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,30 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 bluetooth_paired_query.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 12-Dec-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-Nov-2021 +# +############################################################################ + +# @details +# This file is called by UI Software to query the Blood Pressure paired Bluetooth device. +# There should be only one device paired at a time regarding our design. +# The returned value is the devive mac address and the name assigned to it in the system. + +#test code +#PAIRED_DEVICE_INFO="28:FF:B2:78:5B:BF BP7000" +#PAIRED_DEVICE_INFO="" + +PAIRED_DEVICE_INFO=$(echo "paired-devices" | bluetoothctl | grep ^Device | cut -b 8-125) + +echo $PAIRED_DEVICE_INFO + Index: scripts/brightness_get.sh =================================================================== diff -u --- scripts/brightness_get.sh (revision 0) +++ scripts/brightness_get.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,18 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 brightness_get.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 07-Jun-2021 +# @author (original) Behrouz NematiPour +# @date (original) 07-Jun-2021 +# +############################################################################ + +echo "$(cat /sys/class/backlight/backlight-mipi/brightness)" Index: scripts/brightness_set.sh =================================================================== diff -u --- scripts/brightness_set.sh (revision 0) +++ scripts/brightness_set.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,26 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 brightness_set.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 16-Dec-2021 +# @author (original) Behrouz NematiPour +# @date (original) 23-May-2021 +# +############################################################################ + +if [ "$#" -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile ''" + exit 0 +fi + +echo "$1" > /sys/class/backlight/backlight-mipi/brightness # realtime +echo "$1" > /var/lib/systemd/backlight/platform-backlight-mipi\:backlight\:backlight-mipi # preserve for reboot + Index: scripts/crypt_setup.sh =================================================================== diff -u --- scripts/crypt_setup.sh (revision 0) +++ scripts/crypt_setup.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,130 @@ +#!/bin/bash +########################################################################### +# +# Copyright (c) 2022-2023 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 crypt_setup.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 15-May-2023 +# @author (original) Behrouz NematiPour +# @date (original) 15-May-2023 +# +############################################################################ + +ERR_CRYPTSETUP_UNKNOWN=100 + +ERR_CRYPTSETUP_USAGE=101 +ERR_CRYPTSETUP_PASSWORD=102 + +ERR_CRYPTSETUP_UMOUNT=111 +ERR_CRYPTSETUP_CLOSE=112 + +ERR_CRYPTSETUP_CREATE_MKDIR=121 +ERR_CRYPTSETUP_CREATE_FORMAT=122 +ERR_CRYPTSETUP_CREATE_OPEN=123 +ERR_CRYPTSETUP_CREATE_MKFS=124 +ERR_CRYPTSETUP_CREATE_MOUNT=125 + +ERR_CRYPTSETUP_MOUNT_TYPE=131 +ERR_CRYPTSETUP_MOUNT_OPEN=132 +ERR_CRYPTSETUP_MOUNT_MOUNT=133 +ERR_CRYPTSETUP_MOUNT_MOUNT=134 + +LOC_DEV="/dev/mmcblk0p7" +LOC_DIR="configurations" +LOC_MAP="/dev/mapper/"$LOC_DIR +LOC_VAR="/var/"$LOC_DIR + +DEV_TYP="crypto_LUKS" +DEV_MNT="/dev/mapper/configurations on /var/configurations type ext4 (rw,relatime)" + +function isEncrypted () { + if [ "$( blkid | grep "$LOC_DEV" | grep "TYPE=$DEV_TYP" )" != "" ]; then + echo "not an encrypted partition" + exit $ERR_CRYPTSETUP_MOUNT_TYPE + fi +} + +function isMounted() { + if [ "$( mount | grep "$DEV_MNT" )" != "" ]; then + echo "partition already mounted" + exit $ERR_CRYPTSETUP_MOUNT_MOUNT + fi +} + +function checkPassword() { + if [ "$PASSWORD" == "" ]; then + echo "setup command missing password argument" + exit $ERR_CRYPTSETUP_PASSWORD + fi +} + +function checkOutput() { + if [ "$3" == "" ]; then + out=` eval "$1" 2>&1` + else + out=`echo $3 | eval "$1" 2>&1` + fi + if [ "$?" -ne 0 ]; then + echo $out + exit $2 + fi +} + +function unmount_luks_partition() +{ + checkOutput "umount $LOC_VAR " $ERR_CRYPTSETUP_UMOUNT + checkOutput "cryptsetup luksClose $LOC_DIR " $ERR_CRYPTSETUP_CLOSE +} + +function create_luks_partition() +{ + umount_luks_partition + + checkOutput "mkdir -p $LOC_VAR " $ERR_CRYPTSETUP_CREATE_MKDIR + checkOutput "cryptsetup luksFormat $LOC_DEV " $ERR_CRYPTSETUP_CREATE_FORMAT $PASSWORD + checkOutput "cryptsetup luksOpen $LOC_DEV $LOC_DIR" $ERR_CRYPTSETUP_CREATE_OPEN $PASSWORD + checkOutput "mkfs.ext4 $LOC_MAP " $ERR_CRYPTSETUP_CREATE_MKFS + checkOutput "mount -t ext4 $LOC_MAP $LOC_VAR" $ERR_CRYPTSETUP_CREATE_MOUNT +} + +function mount_luks_partition() +{ + isEncrypted # if encrypted will continue else will exit with error + isMounted # if not mounted will continue else will exit with error + checkOutput "cryptsetup luksOpen $LOC_DEV $LOC_DIR" $ERR_CRYPTSETUP_MOUNT_OPEN $PASSWORD + checkOutput "mount -t ext4 $LOC_MAP $LOC_VAR" $ERR_CRYPTSETUP_MOUNT_MOUNT +} + +function handleCommand() { + # Handle the first argument to script, one of start, stop, erase, restart, force-reload or status + case $1 in + setup) + checkPassword + create_luks_partition + ;; + + mount) + checkPassword + mount_luks_partition + ;; + + umount) + unmount_luks_partition + ;; + + *) + echo "unknown command" + exit $ERR_CRYPTSETUP_UNKNOWN + ;; + + esac +} + +handleCommand $1 $2 + +exit 0 Index: scripts/date_time_set.sh =================================================================== diff -u --- scripts/date_time_set.sh (revision 0) +++ scripts/date_time_set.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,28 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 date_time_set.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 20-Apr-2021 +# @author (original) Behrouz NematiPour +# @date (original) 20-Apr-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile 'yyyy-mm-dd HH:MM:SS'" + exit 0 +fi + +date -s "$1" + +# set the hwclock from the system time +hwclock -w + Index: scripts/decommission.sh =================================================================== diff -u --- scripts/decommission.sh (revision 0) +++ scripts/decommission.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,111 @@ +#!/bin/sh + +########################################################################### +# +# Copyright (c) 2021-2023 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 decommission.sh +# +# @author (last) Vy Duong +# @date (last) 26-May-2023 +# @author (original) Vy Duong +# @date (original) 26-May-2023 +# +############################################################################ + +# @details +# This file is called by UI Software to decommission the device + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 1 +fi + +ERR_FAILED_RM_WIFI_CONF=150 +ERR_FAILED_CLEAR_BT_CACHE=151 +ERR_FAILED_RESET_SETTINGS_CONF=152 +ERR_FAILED_CLEAR_LOGS=153 +ERR_FAILED_RM_SSH=154 +ERR_FAILED_CLEAR_CLOUDSYNC_TOKEN=155 + + +LOC_CLOUDSYNC_TOKEN=%1 +LOC_SETTINGS_CONF="/home/root/.config/Settings/System.conf" +LOC_DEFAULT_SETTINGS_CONF="/home/root/scripts/default_settings.conf" #TODO update to reflect real location +LOC_WIFI_CONF="/etc/wpa_supplicant/wpa_supplicant-wlan0.conf" +LOC_BLUETOOTH_CACHE_FOLDER="/var/lib/bluetooth/" +LOC_SSH_FOLDER="$HOME/.ssh/" +LOC_LOG_PARENT_FOLDER="/media/sd-card/" + +# removes all the files in the directory and subdirectory in a recursive manner +# exits with passed error code if either rm command fails or folder is not empty of files +# %1 - Directory path +# %2 - Error message string/msg +# %3 - Error code to return on exit in case of error +function clearFolderContent() { + if [ -f $1 ]; then + rm -rf "$1/*/*" + fi + + rmCommandReturn=$? + fileCount=$(find $1 -type f | wc -l) + + if [ "$fileCount" -ne 0 ] || [ "$rmCommandReturn" -ne 0 ]; then + echo "Error : $2 ($fileCount)" + exit $3 + fi +} + +# Removes a single file +# exits with passed error code if either rm command fails or if file was not removed +# %1 - path to file +# %2 - Error message string/msg +# %3 - Error code to return on exit in case of error +function removeSingleFile() { + if [ -f $1 ]; then + rm "$1" + fi + if [ -f $1 ]; then + echo "Error: $2" + # the file still exists, exit with error message + exit $3 + fi +} + +# ------------------------------ Remove Wifi Conf +removeSingleFile $LOC_WIFI_CONF "Failed to remove WiFi conf file" $ERR_FAILED_RM_WIFI_CONF + +# ------------------------------ Remove Bluetooth cache +clearFolderContent $LOC_BLUETOOTH_CACHE_FOLDER "Failed to remove Bluetooth cache" $ERR_FAILED_CLEAR_BT_CACHE + +# ------------------------------ Reset Settings Conf +cp $LOC_DEFAULT_SETTINGS_CONF $LOC_SETTINGS_CONF + +# ------------------------------ Remove Logs +#TODO this will always fail due to the fact UI is not pausing on it's writing of log when we attempt a removal, causing the count to always be >0 +clearFolderContent $LOC_LOG_PARENT_FOLDER "Failed to remove logs" $ERR_FAILED_CLEAR_LOGS + +# ------------------------------ Format Encrypted Partition +umountExitCode=$(source ./crypt_setup.sh umount) +if [ "$umountExitCode" -ne 0 ]; then + echo "Error: Failed to unmount partition" + exit $umountExitCode +fi + +setupExitCode=$(source ./crypt_setup.sh setup) +if [ "$setupExitCode" -ne 0 ]; then + echo "Error: format the partition" + exit $setupExitCode +fi + +# ------------------------------ Remove CloudSync Token +clearFolderContent $LOC_CLOUDSYNC_TOKEN "Failed to remove CloudSync token" $ERR_FAILED_CLEAR_CLOUDSYNC_TOKEN + +# ------------------------------ Remove ssh +clearFolderContent $LOC_SSH_FOLDER "Failed to remove ssh" $ERR_FAILED_RM_SSH + +exit 0 Index: scripts/export_logs.sh =================================================================== diff -u --- scripts/export_logs.sh (revision 0) +++ scripts/export_logs.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,54 @@ +#!/bin/bash +########################################################################### +# +# Copyright (c) 2022-2023 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 export_logs.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 14-Jan-2022 +# @author (original) Behrouz NematiPour +# @date (original) 14-Jan-2022 +# +############################################################################ + +CURRNET_DATE=$(date +%Y_%m_%d) +PATH_SRC="$1" +PATH_DST="$2" +PASS_HAS="$3" + +function echo_usage() { + if [[ -z "$PATH_SRC" || -z "$PATH_DST" ]]; then + echo "Usage:" + echo "./export_logs.sh " + echo "" + fi +} + +function export_logs() { + OPTP="" + PASS="Empty Password" + if [[ -n "$PASS_HAS" ]]; then + PASS=$(pwgen -ABcsnv1 16) + OPTP=--password="$PASS" + fi + + EXPORT_FILE=$CURRNET_DATE"_logs" + + echo "$PATH_DST"/"$EXPORT_FILE".zip # echo the out zip + rm -frd "$PATH_DST"/"$EXPORT_FILE".zip && # remove the old zip from dest + rm -frd $HOME/"$EXPORT_FILE".zip && # remove the old zip from home + zip -jr9 $HOME/"$EXPORT_FILE".zip "$PATH_SRC" "$OPTP" && # compress the new zip to home neesd to change to 7zzs + cp $HOME/"$EXPORT_FILE".zip "$PATH_DST" && # copy the new zip to dest + echo $PASS > "$PATH_DST"/"$EXPORT_FILE".pas && # copy the new pas to dest + rm -frd $HOME/"$EXPORT_FILE".zip # remove the tmp zip from home +} + +if [[ "$1" == "" ]]; then + echo_usage +fi + +export_logs Index: scripts/factory_reset.sh =================================================================== diff -u --- scripts/factory_reset.sh (revision 0) +++ scripts/factory_reset.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,89 @@ +#!/bin/sh + +########################################################################### +# +# Copyright (c) 2021-2023 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 factory_reset.sh +# +# @author (last) Vy Duong +# @date (last) 26-May-2023 +# @author (original) Vy Duong +# @date (original) 26-May-2023 +# +############################################################################ + +# @details +# This file is called by UI Software to remove and reset the device + +ERR_FAILED_RM_WIFI_CONF=150 +ERR_FAILED_CLEAR_BT_CACHE=151 +ERR_FAILED_RESET_SETTINGS_CONF=152 +ERR_FAILED_CLEAR_LOGS=153 +ERR_FAILED_RM_SSH=154 + +LOC_SETTINGS_CONF="/home/root/.config/Settings/System.conf" +LOC_DEFAULT_SETTINGS_CONF="/home/root/scripts/default_settings.conf" #TODO update to reflect real location +LOC_WIFI_CONF="/etc/wpa_supplicant/wpa_supplicant-wlan0.conf" +LOC_BLUETOOTH_CACHE_FOLDER="/var/lib/bluetooth/" +LOC_SSH_FOLDER="$HOME/.ssh/" +LOC_LOG_PARENT_FOLDER="/media/sd-card/" + +# removes all the files in the directory and subdirectory in a recursive manner +# exits with passed error code if either rm command fails or folder is not empty of files +# %1 - Directory path +# %2 - Error message string/msg +# %3 - Error code to return on exit in case of error +function clearFolderContent() { + if [ -f $1 ]; then + rm -rf "$1/*/*" + fi + + rmCommandReturn=$? + fileCount=$(find $1 -type f | wc -l) + + if [ "$fileCount" -ne 0 ] || [ "$rmCommandReturn" -ne 0 ]; then + echo "Error : $2 ($fileCount)" + exit $3 + fi +echo "$2 success" +} + +# Removes a single file +# exits with passed error code if either rm command fails or if file was not removed +# %1 - path to file +# %2 - Error message string/msg +# %3 - Error code to return on exit in case of error +function removeSingleFile() { + if [ -f $1 ]; then + rm "$1" + fi + if [ -f $1 ]; then + echo "Error: $2" + # the file still exists, exit with error message + exit $3 + fi +} + +# ------------------------------ Remove Wifi Conf +removeSingleFile $LOC_WIFI_CONF "Failed to remove WiFi conf file" $ERR_FAILED_RM_WIFI_CONF + +# ------------------------------ Remove Bluetooth cache +clearFolderContent $LOC_BLUETOOTH_CACHE_FOLDER "Failed to remove Bluetooth cache" $ERR_FAILED_CLEAR_BT_CACHE + +# ------------------------------ Reset Settings Conf +storedPassword=$(grep Password $LOC_SETTINGS_CONF) +cp $LOC_DEFAULT_SETTINGS_CONF $LOC_SETTINGS_CONF +sed -i "s/^.*Password.*$/$storedPassword/" $LOC_SETTINGS_CONF + +# ------------------------------ Remove Logs +#TODO this will always fail due to the fact UI is not pausing on it's writing of log when we attempt a removal, causing the count to always be >0 +clearFolderContent $LOC_LOG_PARENT_FOLDER "Failed to remove logs" $ERR_FAILED_CLEAR_LOGS + +# ------------------------------ Remove ssh +clearFolderContent $LOC_SSH_FOLDER "Failed to remove ssh" $ERR_FAILED_RM_SSH + +exit Index: scripts/globals.sh =================================================================== diff -u --- scripts/globals.sh (revision 0) +++ scripts/globals.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,461 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2022-2023 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 globals.sh +# +# @author (last) Vy +# @date (last) 20-May-2023 +# @author (original) Behrouz NematiPour +# @date (original) 15-Dec-2022 +# +############################################################################ + +# @details +# This script includes the global variables and functions to be used in the setup and start scripts. + +TRUE=1 +FALSE=0 + +COMMENT_STAR="********************************************************************************" +COMMENT_DASH="--------------------------------------------------------------------------------" + +DATETIME="$1 $2" + +#DO NOT MODIFY VARIABLES, unless the denali applicaiton is updated as well to match. +SDCARD_DEV=/dev/mmcblk1 +SDCARD_PRT=/dev/mmcblk1p1 +SDCARD_MNT=/media/sd-card +SDCARD_TYP_NAME=ext4 +SDCARD_TYP_NUMB=83 + +USB_DEV=/dev/sda1 +USB_MNT=/media/usb + +CLOUDSYNC_FOLDER=cloudsync # both for log and application + +LOG_LOCATION=$HOME/Desktop +LOG_OUT_FILE="" +LOG_ERR_FILE="" + +ERR_MISSING_FOLDER=101 +ERR_MISSING_FILE=102 +ERR_CONNECTION=103 +ERR_DENALI_BIN=104 +ERR_FONTS_EMTY=105 +ERR_FONTS_PATH=106 +ERR_KILLPROMPT=107 +ERR_MISSING_KEY=109 +ERR_SCP_FAIL=110 +ERR_INVALID_IP=111 +ERR_SD_CARD=112 + +SRC_FILE_SSHKEY="$HOME/.ssh/id_rsa" +SRC_FILE_SSHKEY_PUB=$SRC_FILE_SSHKEY.pub +SRC_PATH_SCRIPTS="scripts" +SRC_PATH_CONFIG="settings" +SRC_PATH_CLOUDSYNC="cloudsync" +SRC_PATH_FONTS="fonts" + +DST_IP="" +DST_USER=root +DST_PATH_CONFIG="/home/$DST_USER/.config" +DST_PATH_HOME="/home/$DST_USER" +DST_PATH_SCRIPTS="/home/$DST_USER/scripts" +DST_PATH_CLOUDSYNC="/home/$DST_USER/cloudsync" +DST_PATH_FONTS="/usr/share/fonts/truetype" +DST_PATH_BT_CONF="/etc/bluetooth/" + +POSTLOG=/tmp/post.log +POSTERR=/tmp/post.err +POSTOUT=/tmp/post.out +POSTMSG_POSTFIX_PASSED=" passed" +POSTMSG_POSTFIX_FAILED=" failed" +POSTMSG_CANBUS="CANBus" +POSTMSG_SDCARD="SD-CARD" +POSTMSG_TOUCH="Touch" +POSTMSG_RTC="RTC" +POSTMSG_WIFI="WiFi" +POSTMSG_BLUETOOTH="Bluetooth" +POSTMSG_SHASUM="App shasum" +POSTMSG_CLOUDSYNC="CloudSync" +POSTMSG_CLOUDSYNC_RUNNING="CloudSync app IS running" + +TDCTL_NTP_USED=$FALSE +TDCTL_RTC_LOCL=$TRUE +TDCTL_TIMEZONE=America/Los_Angeles + +IP_SEG_MAX_LEN=3 +IP_EMT="192.168.10." +SSH_PARAM="-oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -oLogLevel=ERROR -oConnectTimeout=2" + +CMD_RTC_EPOCH="cat /sys/class/rtc/rtc0/since_epoch" +CMD_SDCARD_DEV="ls $SDCARD_DEV" +CMD_SDCARD_PRT="ls $SDCARD_PRT" +CMD_LINUX_TYPE="sfdisk --part-type $SDCARD_DEV 1" + +INITD_LOCATION=/etc/init.d/ +INITD_AUTOSTART=autostart +DENALI_BIN=denali +LAUNCH_SCR=run.sh + +SETUP_CONF_FILE="setup.conf" +SETUP_ENABLE_MANUFACTURING_MODE="ManufacturingMode 1" + +APPLICATION_PARAMS="&" + +function confirm() { + read -p "$1? [y,n]" -n 1 -r CONTINUE + if [ "$CONTINUE" == "y" ]; then + echo "" + return $TRUE + else + echo "" + return $FALSE + fi +} + +function string_trim() { + local var="$*" + # remove leading whitespace characters + var="${var#"${var%%[![:space:]]*}"}" + # remove trailing whitespace characters + var="${var%"${var##*[![:space:]]}"}" + printf '%s' "$var" +} + +function echo_star_comment() { + echo "$COMMENT_STAR"" $1 " +} + +function echo_star_message() { + echo " * $1" +} + +function echo_dash_comment() { + echo "$COMMENT_DASH"" $1 " +} + +function echo_dash_message() { + echo " $1" +} + +function timestamp() { + echo $(date +"%Y%m%d-%H%M%S") +} + +function validIP() +{ + local ip=$1 + if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + OIFS=$IFS + IFS='.' + ip=($ip) + IFS=$OIFS + if [[ ${ip[0]} -gt 255 && \ + ${ip[1]} -gt 255 && \ + ${ip[2]} -gt 255 && \ + ${ip[3]} -gt 255 ]]; then + return $ERR_INVALID_IP + fi + else + return $ERR_INVALID_IP + fi + return 0 +} + +function existsFolder() { + if [ ! -d "$1" ]; then + return "$ERR_MISSING_FOLDER" + fi +} + +function existsFile() { + if [ ! -f "$1" ]; then + return "$ERR_MISSING_FILE" + fi +} + +COUT="/dev/null" +function setupConsoleout() { + # /dev/ttymxc1 + COUT="/dev/$(echo $(dmesg | grep "printk: console") | sed 's/.*printk: console.*\(tty.*\)].*/\1/')" +} + +function post_log_clear () { echo "" > $POSTLOG; } +function post_err_clear () { echo "" > $POSTERR; } +function post_out_clear () { echo "" > $POSTOUT; } + +function post_log_pass () { echo "$1" >> $POSTLOG; echo "[ OK ] $1" > "$COUT"; } +function post_log_fail () { echo "$1" >> $POSTLOG; echo "[FAILED] $1" > "$COUT"; } +function post_log_dash () { echo "$COMMENT_DASH$1" >> $POSTLOG; echo "$COMMENT_DASH$1" > "$COUT"; } +function post_log_star () { echo "$COMMENT_DASH$1" >> $POSTLOG; echo "$COMMENT_STAR$1" > "$COUT"; } +function post_log () { echo "$1" >> $POSTLOG; echo " $1" > "$COUT"; } + +function post_err () { echo "$1" >> $POSTERR; } +function post_err_dash () { echo "$COMMENT_DASH$1" >> $POSTERR; } + +function post_out () { echo "$1" >> $POSTOUT; } +function post_out_dash () { echo "$COMMENT_DASH$1" >> $POSTOUT; } + +function debug () { + echo_dash_comment + echo_dash_message "$1" + echo_dash_comment +} + + +function setupResolved() { + echo nameserver 8.8.8.8 > /etc/resolv.conf + echo nameserver 192.168.10.20 >> /etc/resolv.conf # these need to be removed when/if the IoT WiFi doens't need them + echo nameserver 192.168.10.21 >> /etc/resolv.conf # these need to be removed when/if the IoT WiFi doens't need them + systemctl start systemd-resolved.service +} + +function cleanupPOSTLogs() { + # cleanup the POST log file + post_log_clear + post_err_clear + post_out_clear + + post_log_star " ***** " + post_log "Start: $(timestamp)" # log the current date, time +} + +function killApplication() { + # ---------------------------------------- STOP denali in case running (sys not rebooted) + killall $DENALI_BIN +} + +function setupEthernet() { + #setting up ethernet----------------------- Ethernet + post_log_dash " Ethernet " + ieth=eth0 + udhcpc --timeout=5 --retries=2 -n -i $ieth + post_log "$(ip addr show $ieth)" # -details -statistics +} + +function setupCANBus() { + #setting up can interface ----------------- CANBus + post_log_dash " CANBus " + #current settings can be retrieved by the command below + #$ ip -details -statistics link show can0 + ip link set can0 up type can bitrate 250000 restart-ms 100 + ifconfig can0 txqueuelen 4000 + candump can0 -T1 # check if candump can successfully use the port. will terminate in 1ms + if [ $? -eq 0 ]; then + post_log_pass "$POSTMSG_CANBUS$POSTMSG_POSTFIX_PASSED" + post_log "$(ip link show can0)" # -details -statistics + else + post_log_fail "$POSTMSG_CANBUS$POSTMSG_POSTFIX_FAILED" + fi +} + +function setupSDCard() { + #mounting sdcard -------------------------- SD-CARD + post_log_dash " SD-CARD " + mkdir -p $SDCARD_MNT + mount $SDCARD_PRT $SDCARD_MNT + SDCTEST="$(mount | grep "$SDCARD_PRT on $SDCARD_MNT type $SDCARD_TYP_NAME (rw,")" + if ! [ -z "$SDCTEST" ]; then + SDINFO="$(df -h | grep -i $SDCARD_MNT)" + post_log_pass "$POSTMSG_SDCARD$POSTMSG_POSTFIX_PASSED" + post_log "$SDCTEST" + post_log "$SDINFO" + else + post_log_fail "$POSTMSG_SDCARD$POSTMSG_POSTFIX_FAILED" + fi +} + +function testRTC() { + #test the RTC ----------------------------- RTC + post_log_dash " RTC" + #may not be an accurate test but sufficient for now + #and could not find a way to get the rtc clock with the higher resolusion + #it should not be confused with date command which is system date/time and not hwclock + hwclock -r # if there is any issue with rtc hwclock will show errors + if [ $? -eq 0 ]; then + RTC1=$($CMD_RTC_EPOCH) + sleep 1 + RTC2=$($CMD_RTC_EPOCH) + if [ $(($RTC2 - $RTC1)) -eq 1 ]; then + post_log_pass "$POSTMSG_RTC$POSTMSG_POSTFIX_PASSED" + else + post_log_fail "$POSTMSG_RTC$POSTMSG_POSTFIX_FAILED" + fi + fi +} + +function setupWiFi() { + # ----------------------------------------- WiFi + post_log_dash " WiFi " + + # create the wpa supplicant folder for conf storing + iwlan=wlan0 + WPA_SUPPLICANT_DIR="/etc/wpa_supplicant/" + WPA_SUPPLICANT_CNF="wpa_supplicant-$iwlan.conf" + mkdir -p $WPA_SUPPLICANT_DIR + + # remove any software blocks + rfkill unblock wlan + + if [[ ! -z $(dmesg | grep "wlan: driver loaded") ]]; then + post_log_pass "$POSTMSG_WIFI$POSTMSG_POSTFIX_PASSED [driver]" + post_log "$(dmesg | grep -i wlan:)" + + # start the wpa_supplicant service + post_log "start wpa_supplicant service" + systemctl start wpa_supplicant@$iwlan.service + if [ $? -eq 0 ]; then + post_log_pass "$POSTMSG_WIFI$POSTMSG_POSTFIX_PASSED [service]" + # try to connect to WiFi + if [ -f $WPA_SUPPLICANT_DIR$WPA_SUPPLICANT_CNF ]; then + post_log_dash " WiFi Connection " + killall udhcpc + post_log "connecting to WiFi" + # run this manually in terminal if didn't work on bootup + udhcpc --timeout=5 --retries=2 -n -i $iwlan + fi + post_log "$(ip link show $iwlan)" # -details -statistics + else + post_log_fail "$POSTMSG_WIFI$POSTMSG_POSTFIX_FAILED" + post_log "$(systemctl --failed | grep wpa)" + fi + else + post_log_fail "$POSTMSG_WIFI$POSTMSG_POSTFIX_FAILED" + fi +} + +function setupBluetooth() { + # ----------------------------------------- Bluetooth + post_log_dash " Bluetooth " + /usr/share/silex-uart/silex-uart.sh stop 1>> $POSTOUT 2>> $POSTERR + sleep 1 + /usr/share/silex-uart/silex-uart.sh start 1>> $POSTOUT 2>> $POSTERR + sleep 5 + hciconfig hci0 up + if [ $? -eq 0 ]; then + post_log_pass "$POSTMSG_BLUETOOTH$POSTMSG_POSTFIX_PASSED" + post_log "$(hciconfig hci0)" + else + post_log_fail "$POSTMSG_BLUETOOTH$POSTMSG_POSTFIX_FAILED" + fi +} + +function testTouchscreen() { + #test the touch screen -------------------- Touch + post_log_dash " Touch " + # when successfully connected and can be loaded + # Sitronix touch driver 2.10.2 Release date: 20180809 + # atmel_mxt_ts 3-004a: Direct firmware load for maxtouch.cfg failed with error -2 + # atmel_mxt_ts 3-004a: Touchscreen size X1279Y799 + # input: Atmel maXTouch Touchscreen as /devices/platform/soc@0/soc@0:bus@30800000/30a50000.i2c/i2c-3/3-004a/input/input2 + # When NOT connected + # Sitronix touch driver 2.10.2 Release date: 20180809 + TSTEST="$(dmesg | grep "input: Atmel maXTouch Touchscreen as ")" + if [ "$?" -eq 0 ]; then + post_log_pass "$POSTMSG_TOUCH$POSTMSG_POSTFIX_PASSED" + post_log "$TSTEST" + else + post_log_fail "$POSTMSG_TOUCH$POSTMSG_POSTFIX_FAILED" + fi +} + +function testApplicationShasum() { + # ----------------------------------------- Sha256Sum + post_log_dash " Sha256Sum " + #check the denali applicatoin checksum + SHA_ACT=$(tail -c 83 $HOME/$DENALI_BIN | cut -c19-82) + SHA_EXP=$(head -c -83 $HOME/$DENALI_BIN | sha256sum -b --tag | cut -c14-77) + if [ "$SHA_ACT" == "$SHA_EXP" ]; then + post_log_pass "$POSTMSG_SHASUM$POSTMSG_POSTFIX_PASSED" + else + post_log_fail "$POSTMSG_SHASUM$POSTMSG_POSTFIX_FAILED" + fi +} + +function testCloudSystem() { + # ----------------------------------------- CloudSystem + post_log_dash " CloudSystem " + post_log "$(ip addr show $iwlan)" # -details -statistics + post_log "$(ping www.diality.com -I $iwlan -c 3 -4)" +} + +function startCloudSync() { + # ----------------------------------------- CloudSync + post_log_dash " CloudSync " + if [ -d $HOME/$CLOUDSYNC_FOLDER ]; then + # moving/ backing up the previous treatment logs so the new buff starts with fresh sequence + echo "Backing up CloudSync I/O buff" + CLOUDSYNC_PATH="$SDCARD_MNT"/"$CLOUDSYNC_FOLDER" + CLOUDSYNC_BACKUP="$CLOUDSYNC_PATH"_backup/$(timestamp)/ + mkdir -p $CLOUDSYNC_BACKUP + mv $CLOUDSYNC_PATH/* $CLOUDSYNC_BACKUP 1>> $POSTOUT 2>> $POSTERR + rm $HOME/$CLOUDSYNC_FOLDER/data/* 1>> $POSTOUT 2>> $POSTERR + cd $HOME/$CLOUDSYNC_FOLDER/ + python3 ./cs.py start & + sleep 2 + CLOUDSYNC_STATUS="$(python3 ./cs.py status)" + if [ "$CLOUDSYNC_STATUS" == "$POSTMSG_CLOUDSYNC_RUNNING" ]; then + post_log_pass "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_PASSED" + else + post_log_fail "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED" + fi + post_log "$CLOUDSYNC_STATUS" + cd + else + post_log_fail "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED" + fi +} + +function startApplication() { + # ----------------------------------------- Denali + post_log_dash " Denali " + #launching denali application + DENALI_VERSION="$($HOME/$DENALI_BIN -v)" + if [[ -n "$DENALI_VERSION" ]]; then + post_log_pass "$($HOME/$DENALI_BIN -v)" # log UI Software version + if [[ "$APPLICATION_PARAMS" == *"-E"* ]]; then + $HOME/$DENALI_BIN $APPLICATION_PARAMS # do not enclose the APPLICATION_PARAMS in "", then it becomes an empty parameter to the denali which is not accepted. + else + $HOME/$DENALI_BIN $APPLICATION_PARAMS & + fi + else + post_log_fail "Unknown Applicaion Version" + fi +} + +function timerStart() { + time_start=$(date +%s) +} + +function timerEndLog() { + # ----------------------------------------- END + # tag the end time in the POST log file + post_log "End: $(timestamp)" + time_end=$(date +%s) + post_log "time spent: "$(( $time_end - $time_start ))" seconds" + post_log_star " ***** " +} + +function applicationPOST() { + setupConsoleout + cleanupPOSTLogs + setupCANBus + setupResolved + killApplication + setupEthernet + setupSDCard + testRTC + setupWiFi + setupBluetooth + testTouchscreen + testApplicationShasum + testCloudSystem + startCloudSync + startApplication +} Index: scripts/lockdown.sh =================================================================== diff -u --- scripts/lockdown.sh (revision 0) +++ scripts/lockdown.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,109 @@ +#!/bin/bash +########################################################################### +# +# Copyright (c) 2023 Diality Inc. - All Rights Reserved. +# +# This is inpart based on scripts developed by Sunrise Labs Inc. +# +# 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 start.sh +# +# @author (last) Philip Braica +# @date (last) 22-Mar-2023 +# @author (original) Philip Braica +# @date (original) 22-Mar-2023 +# +############################################################################ + +# @details +# This file sets up and verifies some of the SOM security. + +# Does the file contain a string? if +# not, add a line at end. +# If $1 not in $2 then append line $3 to end. +# $1 What to look for. +# $2 File name. +# $3 What to add. +function appendIfMissing() { + # q for quiet, F for regular string match, not -x because not full line. + # Done as one command because this is done remotely. + grep -qF $1 $2 || echo $3 >> $2 +} + +# Remove all lines that contain $1 in file $2 then append $3. +# $1 What to look for. +# $2 File name. +function removeIfFound() { + sed -i /${1}/d $2 +} + +# Turn on some ssh security. +function secureSsh() { + local fileTarget="${PWD}/../../etc/ssh/sshd_config" + + # + chown -R root.denali ${fileTarget} + chmod -R g+rw ${fileTarget} + + # Remove add PermitRootLogin settings then add one to turn it off. + removeIfFound "PermitRootLogin" ${fileTarget} + appendIfMissing "PermitRootLogin" ${fileTarget} "PermitRootLogin no" + + # Restart service on remote. + systemctl restart system-sshd.slice +} + +# Move the customers app files to the app users home directories, +# changed the owner, and set the immutable attribute. +function moveCustomerAppFiles() { + # Move the files + mv ${PWD}/cloudsync ${PWD}/../cloudsync/ + mv ${PWD}/denali ${PWD}/../denali/ + + # Change the file owners. + chown -R cloudsync.cloudsync ${PWD}/../cloudsync + chmod -R o-rwx ${PWD}/../cloudsync + chown -R denali.denali ${PWD}/../denali + chmod -R o-rwx ${PWD}/../denali +} + +# Set all permissions for our users that +# are not root. +function setPermissionsCustomerAppFiles() { + + # Make sure the the other users have no access to these directories. + chmod -R o-rwx ${PWD}/../cloudsync + chmod -R o-rwx ${PWD}/../denali + + # Give read-only access to denali by making the group owner. + mkdir -p ${PWD}/../../var/configuration/CloudSync + chown -R cloudsync.denali ${PWD}/../../var/configuration/CloudSync + chmod -R g-w,g+r,o-rwx ${PWD}/../../var/configuration/CloudSync + + # Give read-only access to denali by making the group owner. + mkdir -p ${PWD}/../../media/sd-card/cloudsync + chown -R cloudsync.denali ${PWD}/../../media/sd-card/cloudsync + chmod -R g-w,g+r,o-rwx ${PWD}/../../media/sd-card/cloudsync + + # Set the immutable attribute for all of the files. + chattr -R +i ${PWD}/../cloudsync/* + chattr -R +i ${PWD}/../denali/* +} + +function main() { + + # Move the App Files to their home directories and setup the file + # permissions needed to make them work. + moveCustomerAppFiles + setPermissionsCustomerAppFiles + + # Turn off root login in by ssh. + secureSsh +} + +# Running the main function +main + +exit 0 Index: scripts/rootsshaccess_get.sh =================================================================== diff -u --- scripts/rootsshaccess_get.sh (revision 0) +++ scripts/rootsshaccess_get.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,25 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 rootsshaccess_get.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 17-Jun-2023 +# @author (original) Behrouz NematiPour +# @date (original) 17-Jun-2023 +# +############################################################################ + +SSHD_CONFIG="/etc/ssh/sshd_config" + +if [ "$(grep -ir "^PermitRootLogin" $SSHD_CONFIG | tr -s ' ' | cut -f2 -d' ')" == "yes" ]; then + echo 1 +else + echo 0 +fi +exit 0 Index: scripts/rootsshaccess_set.sh =================================================================== diff -u --- scripts/rootsshaccess_set.sh (revision 0) +++ scripts/rootsshaccess_set.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,34 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 rootsshaccess_set.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 17-Jun-2023 +# @author (original) Behrouz NematiPour +# @date (original) 17-Jun-2023 +# +############################################################################ + + +SSHD_CONFIG="/etc/ssh/sshd_config" +ERR_EXECUTION=201 + +if [ "$1" == "YES" ]; then + sed -i '/PermitRootLogin/c\PermitRootLogin yes' $SSHD_CONFIG +else + sed -i '/PermitRootLogin/c\PermitRootLogin no' $SSHD_CONFIG +fi + +if [ $? != 0 ]; then + echo "Execution Failed" + exit $ERR_EXECUTION +fi + +echo "" +exit 0 Index: scripts/run.sh =================================================================== diff -u --- scripts/run.sh (revision 0) +++ scripts/run.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,27 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2019-2023 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 run.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 05-Apr-2023 +# @author (original) Behrouz NematiPour +# @date (original) 28-Oct-2019 +# +############################################################################ + +# globals.sh needs to be initialized by the user home path +# otherwise creates the post.log in the / folder instead of home. +HOME=/home/$(whoami) +source ./globals.sh + +timerStart +applicationPOST +timerEndLog + + Index: scripts/setup.sh =================================================================== diff -u --- scripts/setup.sh (revision 0) +++ scripts/setup.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,169 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2020-2023 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 setup.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 16-Dec-2022 +# @author (original) Behrouz NematiPour +# @date (original) 13-Mar-2020 +# +############################################################################ + +# @details +# This script is part of setting up the newly flashed SoM which will run on the device +# after the start.sh script is done copying files on the device. + +source ./globals.sh "$1" "$2" + +function check_sdcard() { + while true; do + if [ ! "$($CMD_SDCARD_DEV)" == "$SDCARD_DEV" ];then # if no SD-Card found ask operator to install on and retry after power-cycle. + echo_dash_comment + echo_dash_message "No SD-Card detected" + echo_dash_message "UI Software logging will not work without a SD-Card" + echo_dash_message "Insert a SD-Card and continue when ready" + echo_dash_comment + confirm "Continue" + if [ $? -eq $FALSE ]; then + # Since the UI will still work without the SD-Card, but won't log, + #exit $ERR_SD_CARD # Do not exit the setup for now, + return $FALSE # And let the user to format and insert the sd-card later. + fi + else + break + fi + done + + if [ ! "$($CMD_SDCARD_PRT)" == "$SDCARD_PRT" ]; then return $FALSE; fi # if partition 1 doesn't exist , do the format + if [ ! "$($CMD_LINUX_TYPE)" == "$SDCARD_TYP_NUMB" ]; then return $FALSE; fi # if partition 1 type is not Linux(83) , do the format + return $TRUE # otherwise , do not format +} + +function format_sdcard() { + check_sdcard + if [ $? -eq $TRUE ]; then # if sd-card is OK + echo "Found the SD-Card $SDCARD_DEV" + confirm "Do you want to format the SD-Card" + if [ $? -eq $FALSE ]; then # give user an option to skip the format + return $? + fi + fi + + echo "Unmount the SD-Card if is in use" + umount "$SDCARD_PRT" + echo "Removing current partitions" + sfdisk --delete $SDCARD_DEV 1>/dev/null 2>/dev/null + echo "Create new partition" + echo "label:MBR" | sfdisk $SDCARD_DEV 1>/dev/null 2>/dev/null + echo "type=83" | sfdisk $SDCARD_DEV 1>/dev/null 2>/dev/null + echo "Create a ext4 file system" + mkfs.ext4 $SDCARD_PRT -L "Denali_Log" -F # 1>/dev/null 2>/dev/null + + check_sdcard + if [ $? -eq $TRUE ]; then + echo "SD-Card format PASSED" + else + echo "SD-Card format FAILED !!!" + fi +} + +function set_timezone() { + echo "setup the time/date controller" + # to use the system time/date and not use the network time protocol + timedatectl set-ntp $TDCTL_NTP_USED + + echo "Setup the timezone (PDT Pacific)" + timedatectl set-timezone $TDCTL_TIMEZONE + timedatectl set-local-rtc $TDCTL_RTC_LOCL +} + +function set_datetime() { + echo "Setup the time/date" + while true; do + timedatectl set-time "$DATETIME" 1>/dev/null 2>/dev/null + if [ $? -eq 0 ]; then + break + else + read -p "please enter the date (yyyy-MM-dd HH:mm): " -e -i "$DATETIME" -r DATETIME + fi + done +} + +function diable_b2qt_services() { + echo "Disabling boot2Qt setvices" + systemctl disable b2qt + systemctl disable connman + systemctl disable qtlauncher + systemctl disable ebikedata +} + +function setup_denali() { + echo "Setting denali as default auto start application" + + chmod a+x $HOME/$INITD_AUTOSTART + chmod a+x $HOME/$LAUNCH_SCR + chmod a+x $HOME/$DENALI_BIN + + rm -f "$POSTLOG" "$POSTERR" "$POSTOUT" + + echo "Syncing file system updates" + sync;sync;sync +} + +function disable_autostart() { + # in case the device is alread setup, disable the autostart of the application until the setup script enables it. + rm -f $INITD_LOCATION$INITD_AUTOSTART +} + +function enable_autostart() { + mkdir -p $INITD_LOCATION + mv $INITD_AUTOSTART $INITD_LOCATION + update-rc.d $INITD_AUTOSTART defaults +} + +function manufacturingMode() { + if [ "$(grep $SETUP_ENABLE_MANUFACTURING_MODE $SETUP_CONF_FILE)" != "" ]; then + # -E for Maunufacturing mode + # -a for disabling the non-minimizable Alarms + APPLICATION_PARAMS="-E -a" # don't use '&', we have to wait until user is done with UI + applicationPOST + fi +} + +function confirm_reboot() { + read -p "ready to reboot? [y,n]" -n 1 -r CONFIRM + if [ "$CONFIRM" == "y" ]; then + rm $0 + reboot + fi + echo "" +} + +function cleanup() { + rm $SETUP_CONF_FILE + rm $(basename $0) + rm -frd $HOME/.ssh +} + +function main() { + disable_autostart + format_sdcard + set_timezone + set_datetime "$1" "$2" + diable_b2qt_services + setup_denali + enable_autostart + manufacturingMode + cleanup +} + +main "$1" "$2" +confirm_reboot + +exit 0 Index: scripts/start.sh =================================================================== diff -u --- scripts/start.sh (revision 0) +++ scripts/start.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,283 @@ +#!/bin/bash +########################################################################### +# +# Copyright (c) 2021-2023 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 start.sh +# +# @author (last) Vy +# @date (last) 20-May-2023 +# @author (original) Behrouz NematiPour +# @date (original) 11-Aug-2021 +# +############################################################################ + +# @details +# This file is used to setup newly flashed SoM to copy everythin on the device. + +source ./globals.sh + +function displayHelp() { + if [ "$1" = "-h" -o "$1" = "--help" ]; then + echo -e "-h \t This help" + echo "usage start.sh [ [xxx] or [xxx.xxx.xxx.xxx] or [] ]" + exit 0 + fi +} + +function exitConfirm() { + read -p "Continue? [y,n]" -n 1 -r CONTINUE + if [ "$CONTINUE" != "y" ]; then + echo "" + exit "$1" + else + echo "" + fi +} + +function defaultIP() { + if [ -n "$1" ]; then + if [ ${#1} -gt $IP_SEG_MAX_LEN ]; then + DST_IP=$1 + else + DST_IP=$IP_EMT"$1" + fi + fi +} + +function setupLogs() { + local log_location=$LOG_LOCATION/$DST_IP + mkdir -p $log_location + LOG_OUT_FILE="$log_location/update-$(timestamp).log" + LOG_ERR_FILE="$log_location/update-$(timestamp).err" + touch $LOG_OUT_FILE + touch $LOG_ERR_FILE +} + +function sshKeyExists() { + existsFile $SRC_FILE_SSHKEY_PUB + return $? +} + +function sshKeyGen() { + sshKeyExists + if [ ! $? -eq 0 ]; then + echo "No ssh key found,Generating ssh key" + ssh-keygen -N "" -f $SRC_FILE_SSHKEY 1>>$LOG_OUT_FILE 2>>$LOG_ERR_FILE + return $? + else + echo "Found ssh key " $SRC_FILE_SSHKEY_PUB + fi + return 0 +} + +function sshKeyCopy() { + echo "Registering the ssh key on the device $DST_IP" + echo "Please wait ..." + ssh-copy-id $SSH_PARAM -f -i $SRC_FILE_SSHKEY_PUB $DST_USER@$DST_IP 1>>$LOG_OUT_FILE 2>>$LOG_ERR_FILE + if [ ! $? -eq 0 ]; then + echo "Connection to host $DST_IP failed." | tee -a $LOG_OUT_FILE + exitConfirm $? + return $? + fi +} + +function sshRun() { + ssh $SSH_PARAM $DST_USER@$DST_IP $1 + return $? +} + +function copyFolderTo() { + existsFolder "$1" + if [ $? -eq 0 ]; then + echo -n "Copy folder" >> $LOG_OUT_FILE + scp -r $SSH_PARAM $1/* $DST_USER@$DST_IP:$2 + if [ $? -eq 0 ]; then + echo " Successfull - $1" >> $LOG_OUT_FILE + else + echo " Failed" >> $LOG_OUT_FILE + exitConfirm $? + return $? + fi + else + echo "File '$1' doesn't exist" | tee -a $LOG_OUT_FILE + exitConfirm $? + fi + return 0 +} + +function copyFileTo() { + existsFile "$1" + if [ $? -eq 0 ]; then + echo -n "Copy file" >> $LOG_OUT_FILE + scp $SSH_PARAM $1 $DST_USER@$DST_IP:$2 + if [ $? -eq 0 ]; then + echo " Successfull - $1" >> $LOG_OUT_FILE + else + echo " Failed" >> $LOG_OUT_FILE + exitConfirm $? + return $? + fi + else + echo "File '$1' doesn't exist" | tee -a $LOG_OUT_FILE + exitConfirm $? + fi + return 0 +} + +function killPrompt() { + echo_star_comment + echo_star_message "Current running UI Software on the device will be stopped." + echo_star_message "All the settings, configurations and binaries will be overwritten" + echo_star_comment + exitConfirm $ERR_KILLPROMPT +} + +function manufacturingModePrompt() { +# I set to always enabled for now to always go to the manufacturing mode +# 1 - Even for normal setup start is moving files to /home/root, so the lockdown needs to run to move files. +# 2 - The UI still needs to be executed to decrypt the /var/configurations, otherwise the configurations can not be updated, +# and I don't have the ability to just decrypt and exit right now. +# Note: after the Cybersecurity release I will improve the user experience and will make it easier for manufacturing. + CONTINUE="y" + +# echo_star_comment +# echo_star_message "Do you want to run in the Manufacturing Mode?" +# echo_star_comment +# read -p "Continue? [y,n]" -n 1 -r CONTINUE +# echo "" # to echo prompts on new line + if [ "$CONTINUE" == "y" ]; then + sshRun "echo $SETUP_ENABLE_MANUFACTURING_MODE > $SETUP_CONF_FILE" + echo_star_message "Set the setup in manufacturing mode" + else + sshRun "echo '' > $SETUP_CONF_FILE" + echo_star_message "Continueing the setup in normal mode" + fi +} + +function getDeviceIP() { + while true; do + validIP "$DST_IP" + if [ $? -eq 0 ]; then + break + else + read -p "Please enter the device Ip address: " -e -i "$IP_EMT" -r DST_IP + validIP "$DST_IP" + if [ $? -eq 0 ]; then + break + else + echo "The entered IP address is not valid [$DST_IP]" + exitConfirm $? + fi + fi + done +} + +function setupBootupScripts() { + echo_dash_comment + echo_dash_message "Installing bootup scripts" | tee -a $LOG_OUT_FILE + echo_dash_comment + copyFileTo "globals.sh" $DST_PATH_HOME + copyFileTo "autostart" $DST_PATH_HOME + copyFileTo "run.sh" $DST_PATH_HOME + copyFileTo "setup.sh" $DST_PATH_HOME +} + +#TODO to be removed when yocto recipes updated +function setupBluetoothConfFile() { + echo_dash_comment + echo_dash_message "Installing bluetooth conf file" | tee -a $LOG_OUT_FILE + echo_dash_comment + copyFileTo $SRC_PATH_SCRIPTS/"bluetooth_main.conf" $DST_PATH_BT_CONF/main.conf + +} + +function setupSettingsScripts() { + echo_dash_comment + echo_dash_message "Installing settings scripts" | tee -a $LOG_OUT_FILE + echo_dash_comment + sshRun "rm -frd $DST_PATH_SCRIPTS;" + sshRun "mkdir -p $DST_PATH_SCRIPTS;" + copyFolderTo $SRC_PATH_SCRIPTS $DST_PATH_SCRIPTS + sshRun "cd $1; chmod a+x *.sh;" +} + +function setupConfigurations() { + echo_dash_comment + echo_dash_message "Installing configurations" | tee -a $LOG_OUT_FILE + echo_dash_comment + sshRun "rm -frd $DST_PATH_CONFIG;" + sshRun "mkdir -p $DST_PATH_CONFIG;" + copyFolderTo $SRC_PATH_CONFIG $DST_PATH_CONFIG +} + +function setupCloudSync() { + echo_dash_comment + echo_dash_message "Installing CloudSync" | tee -a $LOG_OUT_FILE + echo_dash_comment + sshRun "killall python3" + sshRun "rm -frd $DST_PATH_CLOUDSYNC;" + sshRun "mkdir -p $DST_PATH_CLOUDSYNC;" + copyFolderTo $SRC_PATH_CLOUDSYNC $DST_PATH_CLOUDSYNC +} + +function setupFonts() { + echo_dash_comment + echo_dash_message "Installing fonts" | tee -a $LOG_OUT_FILE + echo_dash_comment + copyFolderTo $SRC_PATH_FONTS $DST_PATH_FONTS +} + +function setupApplication() { + echo_dash_comment + echo_dash_message "Installing UI Software" | tee -a $LOG_OUT_FILE + echo_dash_comment + sshRun "killall $DENALI_BIN" + copyFileTo $DENALI_BIN $DST_PATH_HOME +} + +function connect() { + echo_dash_comment + echo_dash_message "please ssh into device $DST_IP and run ./setup.sh " + echo_dash_comment + read -p "Hit enter to continue" + sshRun # the setup.sh has to run on the device while user has logged into the device. +} + +function wipe_device() { + WIPEOUT="wiped.out" + sshRun "find -maxdepth 1 ! \( -name '.ssh' -o -name $SETUP_CONF_FILE -o -name . -o -name .. \) > $WIPEOUT" + sshRun "xargs -a $WIPEOUT rm -frd" +} + +function main() { + displayHelp "$1" + + defaultIP "$1" + getDeviceIP + setupLogs + + sshKeyGen + sshKeyCopy + + killPrompt + manufacturingModePrompt + wipe_device + + setupBootupScripts + setupSettingsScripts + setupConfigurations + setupBluetoothConfFile + setupCloudSync + setupFonts + setupApplication +} + +# running the main function +main "$1" +connect + +exit 0 Index: scripts/wifi_disconnect_network.sh =================================================================== diff -u --- scripts/wifi_disconnect_network.sh (revision 0) +++ scripts/wifi_disconnect_network.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,35 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_disconnect_network.sh +# +# @author (last) Vy +# @date (last) 26-Jan-2023 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +iface=$1 + +# stop the wpa service +systemctl stop wpa_supplicant@"$iface".service + +#remove the wpa configuration file +rm -f /etc/wpa_supplicant/wpa_supplicant-"$iface".conf + +#Shutoff wifi interface +ip link set $iface down + + Index: scripts/wifi_generate_wpa_supplicant.sh =================================================================== diff -u --- scripts/wifi_generate_wpa_supplicant.sh (revision 0) +++ scripts/wifi_generate_wpa_supplicant.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,57 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_generate_wpa_supplicant.sh +# +# @author (last) Vy +# @date (last) 30-Jan-2023 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +ssid=$1 +password=$2 +dest=$3 +securityType=$4 +psk=$(wpa_passphrase "$ssid" "$password" | grep "psk=" | grep -v "#psk" | sed -nr 's/.*psk=(.*)/\1/p') +case $securityType in + wpa2) + echo "Security: wpa2"; + echo "ctrl_interface=/var/run/wpa_supplicant +ctrl_interface_group=0 +update_config=1 + +network={ + ssid=\"$ssid\" + key_mgmt=WPA-PSK + pairwise=CCMP TKIP + group=CCMP TKIP + scan_ssid=1 + #psk=\"\" + psk="$psk" +}" > $dest;; + wpa) + echo "Security: wpa"; + echo "ctrl_interface=/var/run/wpa_supplicant +ctrl_interface_group=0 +update_config=1 + +network={ + ssid=\"$ssid\" + #psk=\"\" + psk="$psk" +}" > $dest;; + +esac Index: scripts/wifi_read_dns.sh =================================================================== diff -u --- scripts/wifi_read_dns.sh (revision 0) +++ scripts/wifi_read_dns.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,22 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_read_dns.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ +if [ "$1" == "-h" ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile" + exit 0 +fi +cat /etc/resolv.conf | grep "nameserver" Index: scripts/wifi_read_gateway.sh =================================================================== diff -u --- scripts/wifi_read_gateway.sh (revision 0) +++ scripts/wifi_read_gateway.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,24 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_read_gateway.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ "$1" == "-h" ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile" + exit 0 +fi + +ip route show | grep "default via" Index: scripts/wifi_read_ip_settings.sh =================================================================== diff -u --- scripts/wifi_read_ip_settings.sh (revision 0) +++ scripts/wifi_read_ip_settings.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,25 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_read_ip_settings.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +iface=$1 +ifconfig $iface | grep "inet " Index: scripts/wifi_read_network_info.sh =================================================================== diff -u --- scripts/wifi_read_network_info.sh (revision 0) +++ scripts/wifi_read_network_info.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,26 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2023-2023 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 wifi_read_network_info.sh +# +# @author (last) Vy +# @date (last) 16-May-2023 +# @author (original) Vy +# @date (original) 16-May-2023 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +iface=$1 +iwconfig wlan0 + Index: scripts/wifi_request_auto_assigned_ip.sh =================================================================== diff -u --- scripts/wifi_request_auto_assigned_ip.sh (revision 0) +++ scripts/wifi_request_auto_assigned_ip.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,26 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_request_auto_assigned_ip.sh +# +# @author (last) Vy +# @date (last) 24-Jan-2023 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +iface=$1 +killall udhcpc +udhcpc --timeout=5 --retries=1 -n -i $iface Index: scripts/wifi_reset_adapter.sh =================================================================== diff -u --- scripts/wifi_reset_adapter.sh (revision 0) +++ scripts/wifi_reset_adapter.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,25 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_reset_adapter.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ "$1" == "-h" ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile" + exit 0 +fi + +rfkill block wifi +rfkill unblock wifi Index: scripts/wifi_reset_interface.sh =================================================================== diff -u --- scripts/wifi_reset_interface.sh (revision 0) +++ scripts/wifi_reset_interface.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,25 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_reset_interface.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +ip link set $1 down +ip link set $1 up Index: scripts/wifi_save_dhcp_interface.sh =================================================================== diff -u --- scripts/wifi_save_dhcp_interface.sh (revision 0) +++ scripts/wifi_save_dhcp_interface.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,28 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_save_dhcp_interface.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 25-Feb-2022 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +iface=$1 +echo "auto $iface +iface $iface inet dhcp + wpa-driver wext + wpa-conf /etc/wpa_supplicant.conf" > /etc/network/interfaces Index: scripts/wifi_save_static_interface_assignments.sh =================================================================== diff -u --- scripts/wifi_save_static_interface_assignments.sh (revision 0) +++ scripts/wifi_save_static_interface_assignments.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,35 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_save_static_interface_assignments.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +iface=$1 +ip=$2 +gateway=$3 +subnet_mask=$4 + +echo "auto $iface +iface $iface inet static + address $ip + netmask $subnet_mask + gateway $3" > /etc/network/interfaces + +./wifi_set_gateway.sh $gateway Index: scripts/wifi_scan_for_networks.sh =================================================================== diff -u --- scripts/wifi_scan_for_networks.sh (revision 0) +++ scripts/wifi_scan_for_networks.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,24 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_scan_for_networks.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +iwlist $1 scan Index: scripts/wifi_set_auto_assigned_ip.sh =================================================================== diff -u --- scripts/wifi_set_auto_assigned_ip.sh (revision 0) +++ scripts/wifi_set_auto_assigned_ip.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,27 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_set_auto_assigned_ip.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +iface=$1 + +echo "auto $iface +iface $iface inet dhcp" >> /etc/network/interfaces Index: scripts/wifi_set_dns.sh =================================================================== diff -u --- scripts/wifi_set_dns.sh (revision 0) +++ scripts/wifi_set_dns.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,24 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_set_dns.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +echo "nameserver $1" >> /etc/resolv.conf Index: scripts/wifi_set_gateway.sh =================================================================== diff -u --- scripts/wifi_set_gateway.sh (revision 0) +++ scripts/wifi_set_gateway.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,25 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_set_gateway.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +ip route del default +ip route add default via $1 Index: scripts/wifi_set_static_ip.sh =================================================================== diff -u --- scripts/wifi_set_static_ip.sh (revision 0) +++ scripts/wifi_set_static_ip.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,24 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_set_static_ip.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +ifconfig $1 $2 \ No newline at end of file Index: scripts/wifi_set_subnetmask.sh =================================================================== diff -u --- scripts/wifi_set_subnetmask.sh (revision 0) +++ scripts/wifi_set_subnetmask.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,24 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_set_subnetmask.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +ifconfig $1 netmask $2 \ No newline at end of file Index: scripts/wifi_start_wpa_supplicant.sh =================================================================== diff -u --- scripts/wifi_start_wpa_supplicant.sh (revision 0) +++ scripts/wifi_start_wpa_supplicant.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,31 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_start_wpa_supplicant.sh +# +# @author (last) Vy +# @date (last) 07-Feb-2023 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ $# -eq 0 ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +iface=$1 +wpa_supplicant_path=$2 + +# make sure hardware is up +ip link set $iface up + +# restart the wpa_supplicant service for wifi +systemctl restart wpa_supplicant@"$iface".service Index: scripts/wifi_test_internet.sh =================================================================== diff -u --- scripts/wifi_test_internet.sh (revision 0) +++ scripts/wifi_test_internet.sh (revision 990607e8bd6afe907d1b5b42a13092663e84a70e) @@ -0,0 +1,25 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2021-2023 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 wifi_test_internet.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 11-May-2021 +# @author (original) Behrouz NematiPour +# @date (original) 11-May-2021 +# +############################################################################ + +if [ "$1" == "-h" ]; then + currentFile=$(basename "$0") + echo "Usage: ./$currentFile " + exit 0 +fi + +iface=$1 +ping -I $iface -c 4 www.linuxfoundation.org