Fisheye: Tag 79a9b03991667bd9cc032f95fd72cac513554c74 refers to a dead (removed) revision in file `README.md'. Fisheye: No comparison available. Pass `N' to diff? Index: readme.md =================================================================== diff -u --- readme.md (revision 0) +++ readme.md (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1 @@ +# leahi-ui.scripts Index: scripts/_errors_ =================================================================== diff -u --- scripts/_errors_ (revision 0) +++ scripts/_errors_ (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1,68 @@ +#!/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 _errors_ +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# Description +# Definition of all the error ID and Descriptions +# Parameters +# No specific parameter +# Retruns +# No specific response +# Considerations +# The error IDs shall not be negative +# The error Messages are assumed as system errors and will not be translated. +# The error Messages returned by the caller script will only be shown on the Application +# if only the exit code of the caller script is non-zero. + +# TODO +# - rearrange the Error IDs by group + +# sources + +# variables +# 0x: General Errors +ERR_GENERAL_SCRIPT_FAIL=1 +ERR_GENERAL_SCRIPT_PARAM_COUNT=2 +ERR_GENERAL_SCRIPT_EMPTY_STRING=3 +ERR_GENERAL_SCRIPT_FILE_EXIST=4 + +# 1x: Empty parameters +ERR_MTPARAM_WIFI_SSID=10 +ERR_MTPARAM_WIFI_PASS=11 +ERR_MTPARAM_BRIGHTNESS_VALUE=12 +ERR_MTPARAM_USB_DEVICE=13 +ERR_MTPARAM_USB_FOLDER=14 + +# 2x: WiFi Errors 2x +ERR_CMDFAIL_WIFI_SCAN=20 +ERR_CMDFAIL_WIFI_CONNECT=21 +ERR_CMDFAIL_WIFI_DISCONNECT=22 +ERR_CMDFAIL_WIFI_INFO_SSID=23 +ERR_CMDFAIL_WIFI_INFO_IPMASK=24 +ERR_CMDFAIL_WIFI_INFO_ADDR=25 +ERR_CMDFAIL_WIFI_INFO_MASK=26 +ERR_CMDFAIL_WIFI_INFO_GATEWAY=27 +ERR_CMDFAIL_WIFI_INFO_DNS=28 + +# 3x: Brightness Errors 3x +ERR_CMDFAIL_BRIGHTNESS_GET=30 +ERR_CMDFAIL_BRIGHTNESS_SET=31 + +# 4x: USB Device Errors +ERR_CMDFAIL_USB_FOLDER_MAKE=40 +ERR_CMDFAIL_USB_DEVICE_MOUNT=41 +ERR_CMDFAIL_USB_FOLDER_REMOVE=42 +ERR_CMDFAIL_USB_DEVICE_UMOUNT=43 Index: scripts/_functions_ =================================================================== diff -u --- scripts/_functions_ (revision 0) +++ scripts/_functions_ (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1,176 @@ +#!/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 _functions_ +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# Description +# Definition of all the globally used functions in scripts. +# Parameters +# No specific parameter +# Retruns +# No specific response +# Considerations +# Any function need to follow the same documentation format, +# to make sure the correct documentation is displayed by vscode editor, +# when used in the caller script. + +# sources +. ./_errors_ + +# functions + +# Description +# Trimms the given string by removing leading spaces +# Parameters +# $1: the given string +# Retruns +# The left trimmed string. +# Considerations +# No specific considerations. +ltrim() { + string="$1" + trimmed="${string#"${string%%[![:space:]]*}"}" + echo """$trimmed""" +} + +# Description +# Trimms the given string by removing trailing spaces +# Parameters +# $1: the given string +# Retruns +# The right trimmed string. +# Considerations +# No specific considerations. +rtrim() { + string="$1" + trimmed="${string%"${string##*[![:space:]]}"}" + echo """$trimmed""" +} + +# Description +# Trimms the given string by removing leading and trailing spaces +# Parameters +# $1: the given string +# Retruns +# The trimmed string. +# Considerations +# No specific consideration. +trim() { + trimmed="$1" + trimmed="${trimmed#"${trimmed%%[![:space:]]*}"}" + trimmed="${trimmed%"${trimmed##*[![:space:]]}"}" + echo """$trimmed""" +} + +# Description +# Checks if the given string is empty +# Parameters +# $1: the given string +# Retruns +# Exits by the $2 if set, on fail, +# or by ERR_GENERAL_SCRIPT_FILE_EXIST by default. +# Considerations +# this function won't trim the given string. +check_empty_string() { + if [ "$1" = "" ]; then + echo "" + if [ "$2" = "" ]; then + exit "$ERR_GENERAL_SCRIPT_EMPTY_STRING" + else + exit "$2" + fi + fi +} + +# Description +# Checks if the given string is empty +# Parameters +# $1: the given string +# Retruns +# returns true if the given string is empty +# Considerations +# this function won't trim the given string. +# this function won't exit if the given string is empty. +is_empty_string() { + if [ "$1" = "" ]; then + echo true + else + echo false + fi +} + +# Checks if the given parameter is more or equal to required number of parameters. +# It also first checks the given parameters to this funcion is correct. +# $1: always the $# of the caller script +# $2: the number of required parameters. +# Exits by ERR_GENERAL_SCRIPT_FILE_EXIST on fail. +check_param_count() { + # first do the self check + PARAM_COUNT=2 + if [ "$#" -lt "$PARAM_COUNT" ]; then + echo "" + exit $ERR_GENERAL_SCRIPT_PARAM_COUNT + fi + + count_act="$1" + count_exp="$2" + if [ "$count_act" -lt "$count_exp" ]; then + echo "" + exit $ERR_GENERAL_SCRIPT_PARAM_COUNT + fi +} + +# Checks if command execution failed +# $1: always the $? of the just executed command +# $2: the exit error number +# Exits by the $2 if set, on fail, +# or by ERR_GENERAL_SCRIPT_FILE_EXIST by default. +check_result() { + PARAM_COUNT=2 + check_param_count "$#" "$PARAM_COUNT" + if [ ! "$1" -eq 0 ]; then + ERR_ID="$2" + if [ "$ERR_ID" = "" ]; then + ERR_ID "$ERR_GENERAL_SCRIPT_FAIL" + fi + # echo $(errorMessage "$ERR_ID") + exit "$ERR_ID" + fi + # echo "" +} + +# Checks if the given file exists +# $1: the file full path +# Exits with ERR_GENERAL_SCRIPT_FILE_EXIST on fail +check_file_exists() { + if [ -f "$FILE" ]; then + echo "" + exit "$ERR_GENERAL_SCRIPT_FILE_EXIST" + fi +} + +errorMessage() { + # this is the minimum required number of parameters + # any error ID can have optional multiple extra parameters to get embedded in the message. + PARAM_COUNT=1 + check_param_count "$#" "$PARAM_COUNT" + + case "$1" in + "$ERR_CMDFAIL_USB_FOLDER_MAKE" ) echo "usb mount point folder '$2' cannot be made." ;; + # "$ERR_CMDFAIL_USB_DEVICE_MOUNT" ) echo "usb device '$2' cannot be mounted." ;; + "$ERR_CMDFAIL_USB_DEVICE_UMOUNT" ) echo "usb drive '$2' cannot be unmounted." ;; + "$ERR_CMDFAIL_USB_FOLDER_REMOVE" ) echo "usb mount point '$2' cannot be removed." ;; + esac +} Index: scripts/_variables_ =================================================================== diff -u --- scripts/_variables_ (revision 0) +++ scripts/_variables_ (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -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 _variables_ +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# Description +# Definition of all the global variables +# Parameters +# No specific parameter +# Retruns +# No specific response +# Considerations +# This gloval variables are different than the error varables and shall not be combinled. +# For error definitions use the _errors_ file. + +# sources + +# variables +BRIGHTNESS_SYSFS="/sys/class/backlight/lvds_backlight/brightness" Index: scripts/brightness.sh =================================================================== diff -u --- scripts/brightness.sh (revision 0) +++ scripts/brightness.sh (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1,47 @@ +#!/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) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# sources +. ./_errors_ +. ./_functions_ +. ./_variables_ + +# local variables +# either set or get a parameter always has to be given. +PARAM_COUNT=1 +BRIGHTNESS_VALUE="$(trim "$1")" + +# local functions + +# checks +check_param_count "$#" "$PARAM_COUNT" +check_file_exists "$BRIGHTNESS_SYSFS" "$BRIGHTNESS_SYSFS" + +# main +# if a value is give update the brightness +if [ "$BRIGHTNESS_VALUE" != "" ]; then + echo "$BRIGHTNESS_VALUE" > "$BRIGHTNESS_SYSFS" + check_result "$?" "$ERR_CMDFAIL_BRIGHTNESS_SET" +fi + +# return the current/updated brightness +BRIGHTNESS_VALUE="$(cat $BRIGHTNESS_SYSFS)" +check_result "$?" "$ERR_CMDFAIL_BRIGHTNESS_GET" + +sleep 0.1 +echo $BRIGHTNESS_VALUE +exit 0 Index: scripts/test.sh =================================================================== diff -u --- scripts/test.sh (revision 0) +++ scripts/test.sh (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1,58 @@ +#!/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 test.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# Description +# TEST ONLY +# Parameters +# No Parameters +# Retruns +# TEST ONLY +# Considerations +# + +# sources +. ./_errors_ +. ./_functions_ + +# variables + +# functions + +# checks + +# main +echo "-" +sleep 0.1 +echo "\\" +sleep 0.1 +echo "|" +sleep 0.1 +echo "/" +sleep 0.1 +echo "-" +sleep 0.1 +echo "\\" +sleep 0.1 +echo "|" +sleep 0.1 +echo "/" +sleep 0.1 + +# exit gracefully +sleep 0.1 +echo "100" +exit 0 \ No newline at end of file Index: scripts/usb_mount.sh =================================================================== diff -u --- scripts/usb_mount.sh (revision 0) +++ scripts/usb_mount.sh (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1,54 @@ +#!/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 usb_mount.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# Description +# Trys to mount the given usb device in the usb drive/location. +# Parameters +# $1: usb device full path +# $2: usb drive full path (mount point) +# Retruns +# No specific response +# Considerations +# No specific considerations. + +# sources +. ./_errors_ +. ./_functions_ + +# variables +PARAM_COUNT=2 +USB_DEVICE="$(trim "$1")" +USB_FOLDER="$(trim "$2")" + +USER=root # leahi - change to leahi user after Cybersecurity implementation + +# functions + +# checks +check_param_count "$#" "$PARAM_COUNT" +check_empty_string "$USB_DEVICE" "$ERR_MTPARAM_USB_DEVICE" +check_empty_string "$USB_FOLDER" "$ERR_MTPARAM_USB_FOLDER" + +mkdir -p "$USB_FOLDER" +check_result "$?" "$ERR_CMDFAIL_USB_FOLDER_MAKE" + +sudo mount -o uid=${USER},gid=${USER},umask=077,noexec,sync,nodev,nosuid "$1" "$2" +check_result "$?" "$ERR_CMDFAIL_USB_DEVICE_MOUNT" + +sleep 0.1 +echo "" +exit 0 \ No newline at end of file Index: scripts/usb_unmount.sh =================================================================== diff -u --- scripts/usb_unmount.sh (revision 0) +++ scripts/usb_unmount.sh (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1,52 @@ +#!/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 usb_mount.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# Description +# Trys to unmount the given usb device from the usb drive/location. +# Parameters +# $1: usb device full path +# $2: usb drive full path (mount point) +# Retruns +# No specific response +# Considerations +# No specific considerations. + +# sources +. ./_errors_ +. ./_functions_ + +# variables +PARAM_COUNT=2 +USB_DEVICE="$(trim "$1")" +USB_FOLDER="$(trim "$2")" + +# functions + +# checks +check_param_count "$#" "$PARAM_COUNT" +check_empty_string "$USB_DEVICE" "$ERR_MTPARAM_USB_DEVICE" +check_empty_string "$USB_FOLDER" "$ERR_MTPARAM_USB_FOLDER" + +sudo umount "$USB_FOLDER" +check_result "$?" "$ERR_CMDFAIL_USB_DEVICE_UMOUNT" + +rmdir "$USB_FOLDER" +check_result "$?" "$ERR_CMDFAIL_USB_FOLDER_REMOVE" + +sleep 0.1 +echo "" +exit 0 \ No newline at end of file Index: scripts/wifi_connect.sh =================================================================== diff -u --- scripts/wifi_connect.sh (revision 0) +++ scripts/wifi_connect.sh (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1,52 @@ +#!/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_connect.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# Description +# Connects to the given SSID with the given password. +# Parameters +# $1: the SSID name +# $2: the SSID password +# Retruns +# No specific response. +# Considerations +# For security reasons the system is not allowed to connect to a passwordless AP. +# Therefore an empty password is an error. + +# TODO +# Add static connection +# The static IP enable shall only be a boolean argument for this script. +# When set to 1(true), the corretly defined connection will be made static. + +# sources +. ./_errors_ +. ./_functions_ + +# variables +PARAM_COUNT=2 +SSID_NAME="$(trim "$1")" +SSID_PASS="$(trim "$2")" + +# functions + +# checks +check_param_count "$#" "$PARAM_COUNT" +check_empty_string "$SSID_NAME" "$ERR_MTPARAM_WIFI_SSID" +check_empty_string "$SSID_PASS" "$ERR_MTPARAM_WIFI_PASS" + +# main +sudo nmcli dev wifi connect "$SSID_NAME" password "$SSID_PASS" +check_result "$?" "$ERR_CMDFAIL_WIFI_CONNECT" Index: scripts/wifi_disconnect.sh =================================================================== diff -u --- scripts/wifi_disconnect.sh (revision 0) +++ scripts/wifi_disconnect.sh (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1,43 @@ +#!/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.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# Description +# Disconnects from the given SSID($1) +# Parameters +# $1: the SSID name +# Returns +# No specific response +# Considerations +# - The system has to be already connected to the given SSID + +# sources +. ./_errors_ +. ./_functions_ + +# variables +PARAM_COUNT=1 +SSID_NAME="$(trim "$1")" + +# functions + +# checks +check_param_count "$#" "$PARAM_COUNT" +check_empty_string "$SSID_NAME" "$ERR_MTPARAM_WIFI_SSID" + +# main +sudo nmcli connection delete "$SSID_NAME" +check_result "$?" "$ERR_CMDFAIL_WIFI_DISCONNECT" Index: scripts/wifi_info.sh =================================================================== diff -u --- scripts/wifi_info.sh (revision 0) +++ scripts/wifi_info.sh (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1,65 @@ +#!/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_info.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# Description +# Gets the active connection information +# Parameters +# No Parameters +# Retruns +# A csv string of the active connection info +# with the columns defined $COLUMNS in order. +# Considerations +# For the Application to work with the List of APs +# - it has to be sorted by SSID +# - it has to use defined columns exactly as has been defined in $COLUMN. + +# sources +. ./_errors_ +. ./_functions_ + +# variables +PARAM_COUNT=0 +COLUMNS="IP4.ADDRESS,IP4.GATEWAY,IP4.DNS" + +# functions + +# checks +check_param_count "$#" "$PARAM_COUNT" + +# main +SSID="$(sudo nmcli -t -f NAME connection show --active)" +check_result "$?" "$ERR_CMDFAIL_WIFI_INFO_SSID" + +IPMASK="$(sudo nmcli -t -g IP4.ADDRESS device show wlan0)" +check_result "$?" "$ERR_CMDFAIL_WIFI_INFO_IPMASK" + +ADDR="$(echo $IPMASK | sed 's/\/.*//g')" +check_result "$?" "$ERR_CMDFAIL_WIFI_INFO_ADDR" + +MASK="$(sudo ipcalc -m "$(echo $IPMASK)" | sed "s/NETMASK=//g")" +check_result "$?" "$ERR_CMDFAIL_WIFI_INFO_MASK" + +GATEWAY="$(sudo nmcli -t -g IP4.GATEWAY device show wlan0)" +check_result "$?" "$ERR_CMDFAIL_WIFI_INFO_GATEWAY" + +DNS="$(sudo nmcli -t -g IP4.DNS device show wlan0 | sed "s/ //g"| sed 's/|/,/g')" +check_result "$?" "$ERR_CMDFAIL_WIFI_INFO_DNS" + +echo "$SSID,$ADDR,$MASK,$GATEWAY,$DNS" +exit 0 + + Index: scripts/wifi_scan.sh =================================================================== diff -u --- scripts/wifi_scan.sh (revision 0) +++ scripts/wifi_scan.sh (revision 79a9b03991667bd9cc032f95fd72cac513554c74) @@ -0,0 +1,49 @@ +#!/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.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 15-Jan-2025 +# @author (original) Behrouz NematiPour +# @date (original) 15-Jan-2025 +# +############################################################################ + +# Description +# Lists all the available Access Points using nmcli command of NetworkManager module. +# Parameters +# No Parameters +# Retruns +# Sorted list of the APs in defined column as specified in the $COLUMNS. +# Considerations +# For the Application to work with the List of APs +# - it has to be sorted by SSID +# - it has to use defined columns exactly as has been defined in $COLUMN. + +# sources +. ./_errors_ +. ./_functions_ + +# variables +PARAM_COUNT=0 +COLUMNS="SSID,BSSID,FREQ,RATE,SIGNAL,SECURITY,WPA-FLAGS,RSN-FLAGS,IN-USE" + +# functions + +# checks +check_param_count "$#" "$PARAM_COUNT" + +# main +OUTPUT="$(sudo nmcli -t -f $COLUMNS dev wifi list --rescan yes | sed 's/:/,/g;s/\\,/:/g' | sort)" +check_result "$?" "$ERR_CMDFAIL_WIFI_SCAN" + +# exit gracefully +sleep 0.1 +echo -e "$OUTPUT" +exit 0 \ No newline at end of file