Simpleupdates Phase 1

-Moved several installation functions to individual scripts that will run as systemd processes for updating/installing; This is phase 1 in creating an automatic update system
-Merged ttyd into simpleadmin as it is now part of simpleadmin as "console"
This commit is contained in:
iamromulan
2024-04-13 21:56:39 -04:00
parent 406e586702
commit 7f17818a9c
15 changed files with 817 additions and 654 deletions

View File

@@ -0,0 +1,101 @@
#!/bin/sh
# Configuration
DEVICE_FILE="/dev/smd7"
ICCID_FILE="/path/to/iccid_master_file" # Path to the ICCID-APN-IPType master file
TMP_DIR="/tmp"
TIMEOUT=4
# Start listening to device file
start_listening() {
cat "$DEVICE_FILE" > "$TMP_DIR/device_readout" &
CAT_PID=$!
}
# Send AT command
send_at_command() {
local command=$1
echo -e "${command}\r" > "$DEVICE_FILE"
}
# Wait for and process response
wait_for_response() {
local start_time=$(date +%s)
local current_time
local elapsed_time
while true; do
if grep -q "OK" "$TMP_DIR/device_readout" || grep -q "ERROR" "$TMP_DIR/device_readout"; then
RESPONSE=$(cat "$TMP_DIR/device_readout")
echo "Response received: $RESPONSE"
return 0
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -ge "$TIMEOUT" ]; then
echo "Error: Response timed out."
return 1
fi
sleep 1
done
}
# Cleanup function
cleanup() {
kill "$CAT_PID"
wait "$CAT_PID" 2>/dev/null
rm -f "$TMP_DIR/device_readout"
}
# Function to send AT command and wait for response
send_and_wait() {
send_at_command "$1"
wait_for_response
}
# Function to update the APN
update_apn() {
local slot=$1
local apn=$2
local iptype=$3
send_and_wait "AT+CGDCONT=$slot,\"$iptype\",\"$apn\""
if [ $? -eq 0 ]; then
echo "APN updated successfully."
else
echo "Failed to update APN."
fi
}
# Main Execution
if [ -c "$DEVICE_FILE" ]; then
start_listening
# Get ICCID
send_and_wait "AT+CCID"
ICCID=$(echo "$RESPONSE" | grep "+CCID" | cut -d ':' -f2 | tr -d '[:space:]')
echo "ICCID: $ICCID"
# Check ICCID in master file
if grep -q "$ICCID" "$ICCID_FILE"; then
APN=$(grep "$ICCID" "$ICCID_FILE" | cut -d ',' -f2)
IP_TYPE=$(grep "$ICCID" "$ICCID_FILE" | cut -d ',' -f3)
IP_TYPE=${IP_TYPE:-"IPV4V6"} # Default to IPV4V6 if not specified
# Get current APN settings
send_and_wait "AT+CGDCONT?"
CURRENT_APN=$(echo "$RESPONSE" | grep "+CGDCONT: 1" | cut -d ',' -f3 | tr -d '"')
# Compare and update APN if necessary
if [ "$APN" != "$CURRENT_APN" ]; then
update_apn 1 "$APN" "$IP_TYPE"
else
echo "No APN update needed."
fi
else
echo "ICCID not found in the master file."
fi
cleanup
else
echo "Error: Device $DEVICE_FILE does not exist or is not a character special file."
fi

View File

@@ -0,0 +1,21 @@
edit_iccid_file() {
local iccid_file="/path/to/iccid_master_file" # Path to the ICCID-APN-IPType master file
echo "Enter ICCID to add or edit:"
read iccid
echo "Enter APN for $iccid:"
read apn
echo "Enter IP Type (IPV4, IPV6, IPV4V6) for $iccid [Default: IPV4V6]:"
read iptype
iptype=${iptype:-"IPV4V6"} # Default to IPV4V6 if not specified
# Check if ICCID already exists
if grep -q "$iccid" "$iccid_file"; then
# Update existing ICCID's APN and IP Type
sed -i "/$iccid/c\\$iccid,$apn,$iptype" "$iccid_file"
else
# Add new ICCID, APN, and IP Type
echo "$iccid,$apn,$iptype" >> "$iccid_file"
fi
echo "ICCID file updated."
}

View File

@@ -0,0 +1,99 @@
#!/bin/bash
# Check if /usrdata/socat-at-bridge/atcmd exists
if [ -f "/usrdata/socat-at-bridge/atcmd" ]; then
# Read the serial number
serial_number=$(/usrdata/socat-at-bridge/atcmd 'AT+EGMR=0,5' | grep '+EGMR:' | cut -d '"' -f2)
# Read the firmware revision
firmware_revision=$(/usrdata/socat-at-bridge/atcmd 'AT+CGMR' | grep -o 'RM[0-9A-Z]*' | head -1)
else
serial_number="UNKNOWN"
firmware_revision="UNKNOWN"
fi
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
echo "=============================================================="
# Start your Actual echo output here, 17 lines omitted for mobile compatibility. ttyd font needs to be size 25.
# Echo "Logo"
echo " .%+: "
echo " .*@@@-. "
echo " :@@@@- "
echo " @@@@#. "
echo " -@@@@#. "
echo " :. %@@@@: -# "
echo " .+- #@@@@%.+@- "
echo " .#- . +@@@@# #@- "
echo " -@*@*@% @@@@@::@@= "
echo ".+%@@@@@@@@@%=. =@@@@# #@@- .. "
echo " .@@@@@: :@@@@@ =@@@..%= "
echo " -::@-.+. @@@@@.=@@@- =@- "
echo " .@- .@@@@@:.@@@* @@. "
echo " .%- -@@@@@:=@@@@ @@# "
echo " .#- .%@@@@@@#. +@@@@@.#@@@@ @@@."
echo " .*- .@@@@@@@@@@=. @@@@@@ @@@@@ @@@:"
echo " :. .%@@@@@@@@@@@%. .@@@@@+:@@@@@ @@@-"
echo " -@@@@@@@@@@@@@@@..@@@@@@.-@@@@@ .@@@-"
echo " -@@@@@@@@@@%. .@@@@@@. @@@@@+ =@@@="
echo " =@@@@@@@@* .@@@@@@. @@@@@@..@@@@-"
echo " #@@@@@@@@-*@@@@@%..@@@@@@+ #@@@@-"
echo " @@@@@@:.-@@@@@@. @@@@@@= %@@@@@."
echo " .@@@@. *@@@@@@- .+@@@@@@-.@@@@@@+ "
echo " %@@. =@@@@@*. +@@@@@@%.-@@@@@@% "
echo " .@@ .@@@@@= :@@@@@@@@..@@@@@@@= "
echo " =@.+@@@@@. -@@@@@@@*.:@@@@@@@*. "
echo " %.*@@@@= .@@@@@@@-.:@@@@@@@+. "
echo " ..@@@@= .@@@@@@: #@@@@@@@: "
echo " .@@@@ +@@@@..%@@@@@+. "
echo " .@@@. @@@@.:@@@@+. "
echo " @@@. @@@. @@@* .@. "
echo " :@@@ %@@..@@#. *@ "
echo " -*: .@@* :@@. @@. -..@@ "
echo " =@@@@@@.*@- :@% @* =@:=@# "
echo " .@@@-+@@@@:%@..%- ...@%:@@: "
echo " .@@. @@-%@: .%@@*@@%. "
echo " :@@ :+ *@ *@@#*@@@. "
echo " =@@@.@@@@ "
echo " .*@@@:=@@@@: "
echo " .@@@@:.@@@@@: "
echo " .@@@@#.-@@@@@. "
echo " #@@@@: =@@@@@- "
echo " .@@@@@..@@@@@@* "
echo " -@@@@@. @@@@@@#. "
echo " -@@@@@ @@@@@@% "
echo " @@@@@. #@@@@@@. "
echo " :@@@@# =@@@@@@% "
echo " @@@@@: @@@@@@@: "
echo " *@@@@ @@@@@@@. "
echo " .@@@@ @@@@@@@ "
echo " #@@@. @@@@@@* "
echo " @@@# @@@@@@@ "
echo " .@@+=@@@@@@. "
echo " *@@@@@@ "
echo " :@@@@@= "
echo " .@@@@@@. "
echo " :@@@@@*. "
echo " .=@@@@@- "
echo " :+##+. "
echo "=============================================================="
echo "TTYd session file by iamromulan v1.1"
echo "Firmware Revision: $firmware_revision"
echo "Serial Number: $serial_number"
echo "=============================================================="
# Start a login session
exec /bin/login