From 6cd09c0f10ae9667925cb03491ee5992bd6875aa Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 19:06:50 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20simpleadmin/www/inde?= =?UTF-8?q?x.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add system status card. --- simpleadmin/www/index.html | 99 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/simpleadmin/www/index.html b/simpleadmin/www/index.html index 7c19596..126e217 100644 --- a/simpleadmin/www/index.html +++ b/simpleadmin/www/index.html @@ -278,6 +278,76 @@
+
+
系统状态
+
+
+ + + + + + + + + + + +
CPU使用率 +
+
+ +
+
+
内存使用率 +
+
+ +
+
+
+
+
+
+
信号
@@ -649,6 +719,12 @@ nonNrUpload: "0", downloadStat: "0", uploadStat: "0", + cpuUsage: "0", + memoryUsage: "0", + cacheUsage: "0", + memoryTotal: "0", + memoryUsed: "0", + cacheUsed: "0", fetchAllInfo() { this.atcmd = @@ -1952,6 +2028,29 @@ console.log("Refreshed"); }, this.refreshRate * 1000); }, + + fetchSystemStats() { + fetch("/cgi-bin/get_system_stats") + .then(response => response.text()) + .then(data => { + const lines = data.split("\n"); + // 跳过空行和Content-Type行 + const validLines = lines.filter(line => line.trim() !== '' && line.includes(": ")).map(line => line.trim()); + + this.cpuUsage = parseFloat(validLines[0].split(": ")[1]).toFixed(1); + this.memoryUsage = parseFloat(validLines[1].split(": ")[1]).toFixed(1); + this.memoryTotal = parseInt(validLines[2].split(": ")[1]); + this.memoryUsed = parseInt(validLines[3].split(": ")[1]); + }); + }, + + formatBytes(bytes) { + if (bytes === 0) return '0 B'; + const k = 1024; + const sizes = ['B', 'KB', 'MB', 'GB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; + }, }; } -- 2.45.2 From 7a6328f97f492e7011e5c2668e07722defc6fe08 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 19:08:25 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20simpleadmin/www/cgi-?= =?UTF-8?q?bin/get=5Fsystem=5Fstats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add get_system_stats --- simpleadmin/www/cgi-bin/get_system_stats | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 simpleadmin/www/cgi-bin/get_system_stats diff --git a/simpleadmin/www/cgi-bin/get_system_stats b/simpleadmin/www/cgi-bin/get_system_stats new file mode 100644 index 0000000..4049e9f --- /dev/null +++ b/simpleadmin/www/cgi-bin/get_system_stats @@ -0,0 +1,41 @@ +#!/bin/sh + +# Send HTTP header for plain text content +echo "Content-Type: text/plain" +echo "" + +# Read first CPU statistics +read cpu user nice system idle iowait irq softirq steal guest guest_nice < /proc/stat + +# Record first total usage time and idle time +prev_total=$((user+nice+system+idle+iowait+irq+softirq+steal)) +prev_idle=$idle + +# Wait for a short time to capture CPU usage +sleep 0.5 + +# Read second CPU statistics +read cpu user nice system idle iowait irq softirq steal guest guest_nice < /proc/stat + +# Calculate second total usage time +total=$((user+nice+system+idle+iowait+irq+softirq+steal)) +idle=$idle + +# Calculate time differences +total_diff=$((total-prev_total)) +idle_diff=$((idle-prev_idle)) + +# Calculate CPU usage percentage +cpu_usage=$(awk -v total_diff="$total_diff" -v idle_diff="$idle_diff" 'BEGIN{printf "%.1f", (total_diff-idle_diff)*100/total_diff}') + +# Get memory information +mem_info=$(free -m | grep "Mem:") +mem_total=$(echo "$mem_info" | awk '{print $2}') +mem_used=$(echo "$mem_info" | awk '{print $3}') +mem_usage=$(awk "BEGIN {printf \"%.1f\", ($mem_used * 100) / $mem_total}") + +# Output results +echo "CPU Usage: $cpu_usage" +echo "Memory Usage: $mem_usage" +echo "Memory Total: $((mem_total * 1024 * 1024))" +echo "Memory Used: $((mem_used * 1024 * 1024))" \ No newline at end of file -- 2.45.2 From e18e39db35fd0ad9f627e324f72cb3d0904aaf80 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 20:02:27 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20simpleadmin/www/inde?= =?UTF-8?q?x.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simpleadmin/www/index.html | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/simpleadmin/www/index.html b/simpleadmin/www/index.html index 126e217..aaa60f6 100644 --- a/simpleadmin/www/index.html +++ b/simpleadmin/www/index.html @@ -2006,13 +2006,11 @@ // Set the refresh rate for interval this.intervalId = setInterval(() => { this.fetchUpTime(); - this.fetchAllInfo(); - + this.fetchSystemStats(); this.requestPing() .then((data) => { const response = data.trim(); - // Trim any leading/trailing spaces if (response === "OK") { this.internetConnectionStatus = "已连接"; } else { @@ -2023,7 +2021,6 @@ console.error("Error:", error); this.internetConnectionStatus = "已断开"; }); - this.lastUpdate = new Date().toLocaleString(); console.log("Refreshed"); }, this.refreshRate * 1000); -- 2.45.2 From d3abaf78101ccba26ab54f38bcebf66d3361d10a Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 20:03:41 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20simpleadmin/www/inde?= =?UTF-8?q?x.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simpleadmin/www/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleadmin/www/index.html b/simpleadmin/www/index.html index aaa60f6..38cd0eb 100644 --- a/simpleadmin/www/index.html +++ b/simpleadmin/www/index.html @@ -2031,7 +2031,7 @@ .then(response => response.text()) .then(data => { const lines = data.split("\n"); - // 跳过空行和Content-Type行 + // Skip blank lines and Content-Type lines. const validLines = lines.filter(line => line.trim() !== '' && line.includes(": ")).map(line => line.trim()); this.cpuUsage = parseFloat(validLines[0].split(": ")[1]).toFixed(1); -- 2.45.2 From bc05c4db58fdb4b6b3495ebd0e61d1f1795c2e47 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 20:56:36 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20simpleupdates/script?= =?UTF-8?q?s/update=5Fsimpleadmin.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simpleupdates/scripts/update_simpleadmin.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/simpleupdates/scripts/update_simpleadmin.sh b/simpleupdates/scripts/update_simpleadmin.sh index a23cd42..d05551d 100644 --- a/simpleupdates/scripts/update_simpleadmin.sh +++ b/simpleupdates/scripts/update_simpleadmin.sh @@ -209,6 +209,7 @@ echo -e "\e[1;31m2) Installing simpleadmin from the $GITTREE branch\e[0m" wget $GITROOT/simpleadmin/www/cgi-bin/user_atcommand wget $GITROOT/simpleadmin/www/cgi-bin/get_ping wget $GITROOT/simpleadmin/www/cgi-bin/get_sms + wget $GITROOT/simpleadmin/www/cgi-bin/get_system_stats wget $GITROOT/simpleadmin/www/cgi-bin/get_ttl_status wget $GITROOT/simpleadmin/www/cgi-bin/set_ttl wget $GITROOT/simpleadmin/www/cgi-bin/send_sms -- 2.45.2 From fa098833b12922a3ebde77ddc8eb8e1ecb07d0e7 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 21:23:20 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20simpleupdates/script?= =?UTF-8?q?s/update=5Fsimpleadmin.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simpleupdates/scripts/update_simpleadmin.sh | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/simpleupdates/scripts/update_simpleadmin.sh b/simpleupdates/scripts/update_simpleadmin.sh index d05551d..b758ca5 100644 --- a/simpleupdates/scripts/update_simpleadmin.sh +++ b/simpleupdates/scripts/update_simpleadmin.sh @@ -90,6 +90,28 @@ remount_rw uninstall_simpleadmin() { echo "Uninstalling Simpleadmin..." + # Clean up Tailscale if present + if [ -d "/usrdata/tailscale" ]; then + echo "Cleaning up Tailscale..." + # Stop and logout from Tailscale + if [ -f "/usrdata/tailscale/tailscale" ]; then + /usrdata/tailscale/tailscale logout + /usrdata/tailscale/tailscale down + fi + + systemctl stop tailscale 2>/dev/null + systemctl stop tailscale-webui 2>/dev/null + rm -f /lib/systemd/system/tailscale.service + + # Remove Tailscale files and directories + rm -rf /usrdata/tailscale + rm -f /bin/tailscale + rm -f /bin/tailscaled + + # Reload systemd + systemctl daemon-reload + fi + # Check if Lighttpd service is installed and remove it if present if [ -f "/lib/systemd/system/lighttpd.service" ]; then echo "Lighttpd detected, uninstalling Lighttpd webserver and its modules..." -- 2.45.2 From 5364e18b148d7a017cbab8f93f70a5c4f1c7e7eb Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 21:25:35 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20RMxxx=5Frgmii=5Ftool?= =?UTF-8?q?kit.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RMxxx_rgmii_toolkit.sh | 61 ++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/RMxxx_rgmii_toolkit.sh b/RMxxx_rgmii_toolkit.sh index 2e49f46..b6e24f5 100644 --- a/RMxxx_rgmii_toolkit.sh +++ b/RMxxx_rgmii_toolkit.sh @@ -456,15 +456,17 @@ uninstall_simpleadmin_components() { tailscale_menu() { while true; do echo -e "\e[1;32mTailscale Menu\e[0m" - echo -e "\e[1;32m1) Install/Update Tailscale\e[0m" - echo -e "\e[1;36m2) Configure Tailscale\e[0m" - echo -e "\e[1;31m3) Return to Main Menu\e[0m" + echo -e "\e[1;32m1) Install/Update Tailscale\e[0m" + echo -e "\e[1;36m2) Configure Tailscale\e[0m" + echo -e "\e[1;31m3) Uninstall Tailscale\e[0m" + echo -e "\e[1;31m4) Return to Main Menu\e[0m" read -p "Enter your choice: " tailscale_choice case $tailscale_choice in 1) install_update_tailscale;; 2) configure_tailscale;; - 3) break;; + 3) uninstall_tailscale;; + 4) break;; *) echo "Invalid option";; esac done @@ -472,16 +474,47 @@ tailscale_menu() { # Function to install, update, or remove Tailscale install_update_tailscale() { -echo -e "\e[1;31m2) Installing tailscale from the $GITTREE branch\e[0m" - ensure_entware_installed - mkdir /usrdata/simpleupdates > /dev/null 2>&1 - mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 - wget -O /usrdata/simpleupdates/scripts/update_tailscale.sh $GITROOT/simpleupdates/scripts/update_tailscale.sh && chmod +x /usrdata/simpleupdates/scripts/update_tailscale.sh - echo -e "\e[1;32mInstalling/updating: Tailscale\e[0m" - echo -e "\e[1;32mPlease Wait....\e[0m" - remount_rw - /usrdata/simpleupdates/scripts/update_tailscale.sh - echo -e "\e[1;32m Tailscale has been updated/installed.\e[0m" + echo -e "\e[1;31m2) Installing tailscale from the $GITTREE branch\e[0m" + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_tailscale.sh $GITROOT/simpleupdates/scripts/update_tailscale.sh && chmod +x /usrdata/simpleupdates/scripts/update_tailscale.sh + echo -e "\e[1;32mInstalling/updating: Tailscale\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + remount_rw + /usrdata/simpleupdates/scripts/update_tailscale.sh + echo -e "\e[1;32m Tailscale has been updated/installed.\e[0m" +} + +# Function to uninstall Tailscale +uninstall_tailscale() { + echo -e "\e[1;31mUninstalling Tailscale...\e[0m" + + # Stop and logout from Tailscale + if [ -f "/usrdata/tailscale/tailscale" ]; then + /usrdata/tailscale/tailscale logout + /usrdata/tailscale/tailscale down + fi + + # Stop services + systemctl stop tailscale 2>/dev/null + systemctl stop tailscale-webui 2>/dev/null + + # Remove service files + rm -f /lib/systemd/system/tailscale.service + rm -f /lib/systemd/system/tailscale-webui.service + rm -f /lib/systemd/system/tailscale-webui-trigger.service + rm -f /lib/systemd/system/multi-user.target.wants/tailscale-webui-trigger.service + + # Remove Tailscale files and directories + rm -rf /usrdata/tailscale + rm -f /bin/tailscale + rm -f /bin/tailscaled + + # Reload systemd + systemctl daemon-reload + + echo -e "\e[1;32mTailscale has been uninstalled.\e[0m" } # Function to Configure Tailscale -- 2.45.2 From 8548078982d53c38dc87a204ef2251881beb1d3c Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 22:08:15 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20simpleadmin/console/?= =?UTF-8?q?ttyd.bash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simpleadmin/console/ttyd.bash | 102 ++++++++-------------------------- 1 file changed, 24 insertions(+), 78 deletions(-) diff --git a/simpleadmin/console/ttyd.bash b/simpleadmin/console/ttyd.bash index 1cdd786..795ce16 100644 --- a/simpleadmin/console/ttyd.bash +++ b/simpleadmin/console/ttyd.bash @@ -11,89 +11,35 @@ else 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 "//////////////////////////////////////////////////////////////////"; +echo "// //"; +echo "// //"; +echo "// :'######::'####:'##::::'##:'########::'##:::::::'########: //"; +echo "// '##... ##:. ##:: ###::'###: ##.... ##: ##::::::: ##.....:: //"; +echo "// ##:::..::: ##:: ####'####: ##:::: ##: ##::::::: ##::::::: //"; +echo "// . ######::: ##:: ## ### ##: ########:: ##::::::: ######::: //"; +echo "// :..... ##:: ##:: ##. #: ##: ##.....::: ##::::::: ##...:::: //"; +echo "// '##::: ##:: ##:: ##:.:: ##: ##:::::::: ##::::::: ##::::::: //"; +echo "// . ######::'####: ##:::: ##: ##:::::::: ########: ########: //"; +echo "// :......:::....::..:::::..::..:::::::::........::........:: //"; +echo "// :::'###::::'########::'##::::'##:'####:'##::: ##: //"; +echo "// ::'## ##::: ##.... ##: ###::'###:. ##:: ###:: ##: //"; +echo "// :'##:. ##:: ##:::: ##: ####'####:: ##:: ####: ##: //"; +echo "// '##:::. ##: ##:::: ##: ## ### ##:: ##:: ## ## ##: //"; +echo "// #########: ##:::: ##: ##. #: ##:: ##:: ##. ####: //"; +echo "// ##.... ##: ##:::: ##: ##:.:: ##:: ##:: ##:. ###: //"; +echo "// ##:::: ##: ########:: ##:::: ##:'####: ##::. ##: //"; +echo "// ..:::::..::........:::..:::::..::....::..::::..:: //"; +echo "// //"; +echo "// By iamromulan //"; +echo "//////////////////////////////////////////////////////////////////"; +echo "===================================================================" echo "TTYd session file by iamromulan v1.1" echo "Firmware Revision: $firmware_revision" echo "Serial Number: $serial_number" -echo "==============================================================" +echo "===================================================================" # Start a login session exec /bin/login -- 2.45.2 From 3cf93ede5f1df424e84ea1057a6a8694d8fbea8a Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 22:09:20 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20RMxxx=5Frgmii=5Ftool?= =?UTF-8?q?kit.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RMxxx_rgmii_toolkit.sh | 81 ++++++++++++------------------------------ 1 file changed, 22 insertions(+), 59 deletions(-) diff --git a/RMxxx_rgmii_toolkit.sh b/RMxxx_rgmii_toolkit.sh index b6e24f5..cb93bd3 100644 --- a/RMxxx_rgmii_toolkit.sh +++ b/RMxxx_rgmii_toolkit.sh @@ -801,65 +801,28 @@ else fi while true; do -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 "// //"; +echo "// //"; +echo "// :'######::'####:'##::::'##:'########::'##:::::::'########: //"; +echo "// '##... ##:. ##:: ###::'###: ##.... ##: ##::::::: ##.....:: //"; +echo "// ##:::..::: ##:: ####'####: ##:::: ##: ##::::::: ##::::::: //"; +echo "// . ######::: ##:: ## ### ##: ########:: ##::::::: ######::: //"; +echo "// :..... ##:: ##:: ##. #: ##: ##.....::: ##::::::: ##...:::: //"; +echo "// '##::: ##:: ##:: ##:.:: ##: ##:::::::: ##::::::: ##::::::: //"; +echo "// . ######::'####: ##:::: ##: ##:::::::: ########: ########: //"; +echo "// :......:::....::..:::::..::..:::::::::........::........:: //"; +echo "// :::'###::::'########::'##::::'##:'####:'##::: ##: //"; +echo "// ::'## ##::: ##.... ##: ###::'###:. ##:: ###:: ##: //"; +echo "// :'##:. ##:: ##:::: ##: ####'####:: ##:: ####: ##: //"; +echo "// '##:::. ##: ##:::: ##: ## ### ##:: ##:: ## ## ##: //"; +echo "// #########: ##:::: ##: ##. #: ##:: ##:: ##. ####: //"; +echo "// ##.... ##: ##:::: ##: ##:.:: ##:: ##:: ##:. ###: //"; +echo "// ##:::: ##: ########:: ##:::: ##:'####: ##::. ##: //"; +echo "// ..:::::..::........:::..:::::..::....::..::::..:: //"; +echo "// //"; +echo "// By iamromulan //"; +echo "//////////////////////////////////////////////////////////////////"; echo -e "\e[92m" echo "Welcome to iamromulan's RGMII Toolkit script for Quectel RMxxx Series modems!" -- 2.45.2 From e3441aafaed7f451d8c5ea03a4bd92ec05f2f722 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 8 Dec 2024 22:23:43 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20RMxxx=5Frgmii=5Ftool?= =?UTF-8?q?kit.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RMxxx_rgmii_toolkit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RMxxx_rgmii_toolkit.sh b/RMxxx_rgmii_toolkit.sh index cb93bd3..a34a53e 100644 --- a/RMxxx_rgmii_toolkit.sh +++ b/RMxxx_rgmii_toolkit.sh @@ -459,7 +459,7 @@ tailscale_menu() { echo -e "\e[1;32m1) Install/Update Tailscale\e[0m" echo -e "\e[1;36m2) Configure Tailscale\e[0m" echo -e "\e[1;31m3) Uninstall Tailscale\e[0m" - echo -e "\e[1;31m4) Return to Main Menu\e[0m" + echo -e "\e[1;93m4) Return to Main Menu\e[0m" read -p "Enter your choice: " tailscale_choice case $tailscale_choice in -- 2.45.2 From f1824ea8a01c6cfdb661d82907e976a7ad34f0dd Mon Sep 17 00:00:00 2001 From: sky Date: Tue, 10 Dec 2024 22:33:01 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20simpleupdates/script?= =?UTF-8?q?s/update=5Ftailscale.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simpleupdates/scripts/update_tailscale.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/simpleupdates/scripts/update_tailscale.sh b/simpleupdates/scripts/update_tailscale.sh index e394128..79fc313 100644 --- a/simpleupdates/scripts/update_tailscale.sh +++ b/simpleupdates/scripts/update_tailscale.sh @@ -101,12 +101,12 @@ install_update_tailscale() { mkdir -p "$TAILSCALE_DIR" "$TAILSCALE_SYSD_DIR" echo "Downloading binary files..." cd /usrdata - curl -O https://pkgs.tailscale.com/stable/tailscale_1.76.1_arm.tgz - tar -xzf tailscale_1.76.1_arm.tgz - rm tailscale_1.76.1_arm.tgz - cd /usrdata/tailscale_1.76.1_arm + curl -O https://pkgs.tailscale.com/stable/tailscale_1.78.1_arm.tgz + tar -xzf tailscale_1.78.1_arm.tgz + rm tailscale_1.78.1_arm.tgz + cd /usrdata/tailscale_1.78.1_arm mv tailscale tailscaled "$TAILSCALE_DIR/" - rm -rf /usrdata/tailscale_1.76.1_arm + rm -rf /usrdata/tailscale_1.78.1_arm echo "Downloading systemd files..." cd "$TAILSCALE_SYSD_DIR" wget $GITROOT/tailscale/systemd/tailscaled.service -- 2.45.2 From c96a6f66f9c5be1159157790d88dabeece5bfc09 Mon Sep 17 00:00:00 2001 From: sky Date: Thu, 12 Dec 2024 03:06:49 +0800 Subject: [PATCH 12/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20RMxxx=5Frgmii=5Ftool?= =?UTF-8?q?kit=5Fdev.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RMxxx_rgmii_toolkit_dev.sh | 1039 ++++++++++++++++++++++++++++++++++++ 1 file changed, 1039 insertions(+) create mode 100644 RMxxx_rgmii_toolkit_dev.sh diff --git a/RMxxx_rgmii_toolkit_dev.sh b/RMxxx_rgmii_toolkit_dev.sh new file mode 100644 index 0000000..1de1ed8 --- /dev/null +++ b/RMxxx_rgmii_toolkit_dev.sh @@ -0,0 +1,1039 @@ +#!/bin/sh + +##################################################################### +# RMxxx RGMII Toolkit +# Author: iamromulan +# Description: Toolkit for Quectel RMxxx Series modems +# Repository: https://github.com/iamromulan +##################################################################### + +##################################################################### +# Environment Configuration +##################################################################### + +# Define toolkit paths +export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:/usrdata/root/bin + +# Define Gitea repository configuration +GITEA_HOST="code.example.com" +GITUSER="sky" +REPONAME="simple-admin" +GITTREE="main" +GITMAINTREE="main" +GITDEVTREE="dev" + +# Construct Gitea URLs +# Format: https://[host]/[user]/[repo]/raw/branch/[branch]/[file] +GITROOT="https://$GITEA_HOST/$GITUSER/$REPONAME/raw/branch/$GITTREE" +GITROOTMAIN="https://$GITEA_HOST/$GITUSER/$REPONAME/raw/branch/$GITMAINTREE" +GITROOTDEV="https://$GITEA_HOST/$GITUSER/$REPONAME/raw/branch/$GITDEVTREE" + +##################################################################### +# Directory Configuration +##################################################################### + +# System directories +TMP_DIR="/tmp" +USRDATA_DIR="/usrdata" + +# Application directories +SOCAT_AT_DIR="/usrdata/socat-at-bridge" +SOCAT_AT_SYSD_DIR="/usrdata/socat-at-bridge/systemd_units" +SIMPLE_ADMIN_DIR="/usrdata/simpleadmin" +SIMPLE_FIREWALL_DIR="/usrdata/simplefirewall" +SIMPLE_FIREWALL_SCRIPT="$SIMPLE_FIREWALL_DIR/simplefirewall.sh" +SIMPLE_FIREWALL_SYSTEMD_DIR="$SIMPLE_FIREWALL_DIR/systemd" +TAILSCALE_DIR="/usrdata/tailscale" +TAILSCALE_SYSD_DIR="/usrdata/tailscale/systemd" +LIGHTTPD_DIR="/usrdata/lighttpd" + +# AT Command configuration +DEVICE_FILE="/dev/smd7" +TIMEOUT=4 # Set a timeout for the response + +##################################################################### +# Basic Utility Functions +##################################################################### + +# Function to remount file system as read-write +remount_rw() { + mount -o remount,rw / +} + +# Function to remount file system as read-only +remount_ro() { + mount -o remount,ro / +} + +##################################################################### +# AT Command Functions +##################################################################### + +# Basic AT commands without socat bridge for fast response commands only +start_listening() { + cat "$DEVICE_FILE" > /tmp/device_readout & + CAT_PID=$! +} + +send_at_command() { + echo -e "\e[1;31mThis only works for basic quick responding commands!\e[0m" # Red + echo -e "\e[1;36mType 'install' to simply type atcmd in shell from now on\e[0m" + echo -e "\e[1;36mThe installed version is much better than this portable version\e[0m" + echo -e "\e[1;32mEnter AT command (or type 'exit' to quit): \e[0m" + read at_command + if [ "$at_command" = "exit" ]; then + return 1 + fi + + if [ "$at_command" = "install" ]; then + install_update_at_socat + echo -e "\e[1;32mInstalled. Type atcmd from adb shell or ssh to start an AT Command session\e[0m" + return 1 + fi + echo -e "${at_command}\r" > "$DEVICE_FILE" +} + +wait_for_response() { + local start_time=$(date +%s) + local current_time + local elapsed_time + + echo -e "\e[1;32mCommand sent, waiting for response...\e[0m" + while true; do + if grep -qe "OK" -e "ERROR" /tmp/device_readout; then + echo -e "\e[1;32mResponse received:\e[0m" + cat /tmp/device_readout + return 0 + fi + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) + if [ "$elapsed_time" -ge "$TIMEOUT" ]; then + echo -e "\e[1;31mError: Response timed out.\e[0m" # Red + echo -e "\e[1;32mIf the responce takes longer than a second or 2 to respond this will not work\e[0m" # Green + echo -e "\e[1;36mType install to install the better version of this that will work.\e[0m" # Cyan + return 1 + fi + sleep 1 + done +} + +cleanup() { + kill "$CAT_PID" + wait "$CAT_PID" 2>/dev/null + rm -f /tmp/device_readout +} + +send_at_commands() { + if [ -c "$DEVICE_FILE" ]; then + while true; do + start_listening + send_at_command + if [ $? -eq 1 ]; then + cleanup + break + fi + wait_for_response + cleanup + done + else + echo -e "\e[1;31mError: Device $DEVICE_FILE does not exist!\e[0m" + fi +} + +##################################################################### +# Installation and Package Management Functions +##################################################################### + +# Check for existing Entware/opkg installation, install if not installed +ensure_entware_installed() { + remount_rw + if [ ! -f "/opt/bin/opkg" ]; then + echo -e "\e[1;32mInstalling Entware/OPKG\e[0m" + cd /tmp && wget -O installentware.sh "$GITROOT/installentware.sh" && chmod +x installentware.sh && ./installentware.sh + if [ "$?" -ne 0 ]; then + echo -e "\e[1;31mEntware/OPKG installation failed. Please check your internet connection or the repository URL.\e[0m" + exit 1 + fi + cd / + else + echo -e "\e[1;32mEntware/OPKG is already installed.\e[0m" + if [ "$(readlink /bin/login)" != "/opt/bin/login" ]; then + opkg update && opkg install shadow-login shadow-passwd shadow-useradd + if [ "$?" -ne 0 ]; then + echo -e "\e[1;31mPackage installation failed. Please check your internet connection and try again.\e[0m" + exit 1 + fi + + # Replace the login and passwd binaries and set home for root to a writable directory + rm /opt/etc/shadow + rm /opt/etc/passwd + cp /etc/shadow /opt/etc/ + cp /etc/passwd /opt/etc + mkdir -p /usrdata/root/bin + touch /usrdata/root/.profile + echo "# Set PATH for all shells" > /usrdata/root/.profile + echo "export PATH=/bin:/usr/sbin:/usr/bin:/sbin:/opt/sbin:/opt/bin:/usrdata/root/bin" >> /usrdata/root/.profile + chmod +x /usrdata/root/.profile + sed -i '1s|/home/root:/bin/sh|/usrdata/root:/bin/bash|' /opt/etc/passwd + rm /bin/login /usr/bin/passwd + ln -sf /opt/bin/login /bin + ln -sf /opt/bin/passwd /usr/bin/ + ln -sf /opt/bin/useradd /usr/bin/ + echo -e "\e[1;31mPlease set the root password.\e[0m" + /opt/bin/passwd + + # Install basic and useful utilities + opkg install mc htop dfc lsof + ln -sf /opt/bin/mc /bin + ln -sf /opt/bin/htop /bin + ln -sf /opt/bin/dfc /bin + ln -sf /opt/bin/lsof /bin + fi + + if [ ! -f "/usrdata/root/.profile" ]; then + opkg update && opkg install shadow-useradd + mkdir -p /usrdata/root/bin + touch /usrdata/root/.profile + echo "# Set PATH for all shells" > /usrdata/root/.profile + echo "export PATH=/bin:/usr/sbin:/usr/bin:/sbin:/opt/sbin:/opt/bin:/usrdata/root/bin" >> /usrdata/root/.profile + chmod +x /usrdata/root/.profile + sed -i '1s|/home/root:/bin/sh|/usrdata/root:/bin/bash|' /opt/etc/passwd + fi + fi + if [ ! -f "/opt/sbin/useradd" ]; then + echo "useradd does not exist. Installing shadow-useradd..." + opkg install shadow-useradd + else + echo "useradd already exists. Continuing..." + fi + + if [ ! -f "/usr/bin/curl" ] && [ ! -f "/opt/bin/curl" ]; then + echo "curl does not exist. Installing curl..." + opkg update && opkg install curl + if [ "$?" -ne 0 ]; then + echo -e "\e[1;31mFailed to install curl. Please check your internet connection and try again.\e[0m" + exit 1 + fi + else + echo "curl already exists. Continuing..." + fi +} + +# Uninstall Entware if the Users chooses +uninstall_entware() { + echo -e '\033[31mInfo: Starting Entware/OPKG uninstallation...\033[0m' + + # Stop services + systemctl stop rc.unslung.service + /opt/etc/init.d/rc.unslung stop + rm /lib/systemd/system/multi-user.target.wants/rc.unslung.service + rm /lib/systemd/system/rc.unslung.service + + systemctl stop opt.mount + rm /lib/systemd/system/multi-user.target.wants/start-opt-mount.service + rm /lib/systemd/system/opt.mount + rm /lib/systemd/system/start-opt-mount.service + + # Unmount /opt if mounted + mountpoint -q /opt && umount /opt + + # Remove Entware installation directory + rm -rf /usrdata/opt + rm -rf /opt + + # Reload systemctl daemon + systemctl daemon-reload + + # Optionally, clean up any modifications to /etc/profile or other system files + # Restore original link to login binary compiled by Quectel + rm /bin/login + ln /bin/login.shadow /bin/login + + echo -e '\033[32mInfo: Entware/OPKG has been uninstalled successfully.\033[0m' +} + +##################################################################### +# System Service and Configuration Functions +##################################################################### + +# Function to manage Daily Reboot Timer +manage_reboot_timer() { + # Remount root filesystem as read-write + mount -o remount,rw / + + # Check if the rebootmodem service, timer, or trigger already exists + if [ -f /lib/systemd/system/rebootmodem.service ] || [ -f /lib/systemd/system/rebootmodem.timer ] || [ -f /lib/systemd/system/rebootmodem-trigger.service ]; then + echo -e "\e[1;32mThe rebootmodem service/timer/trigger is already installed.\e[0m" + echo -e "\e[1;32m1) Change\e[0m" # Green + echo -e "\e[1;31m2) Remove\e[0m" # Red + read -p "Enter your choice (1 for Change, 2 for Remove): " reboot_choice + + case $reboot_choice in + 2) + # Stop and disable timer and trigger service by removing symlinks + systemctl stop rebootmodem.timer + systemctl stop rebootmodem-trigger.service + + # Remove symbolic links and files + rm -f /lib/systemd/system/multi-user.target.wants/rebootmodem-trigger.service + rm -f /lib/systemd/system/rebootmodem.service + rm -f /lib/systemd/system/rebootmodem.timer + rm -f /lib/systemd/system/rebootmodem-trigger.service + rm -f "$USRDATA_DIR/reboot_modem.sh" + + # Reload systemd to apply changes + systemctl daemon-reload + + echo -e "\e[1;32mRebootmodem service, timer, trigger, and script removed successfully.\e[0m" + ;; + 1) + printf "Enter the new time for daily reboot (24-hour format in Coordinated Universal Time, HH:MM): " + read new_time + + # Validate the new time format using grep + if ! echo "$new_time" | grep -qE '^([01]?[0-9]|2[0-3]):[0-5][0-9]$'; then + echo "Invalid time format. Exiting." + exit 1 + else + # Remove old symlinks and script + rm -f /lib/systemd/system/multi-user.target.wants/rebootmodem-trigger.service + rm -f "$USRDATA_DIR/reboot_modem.sh" + + # Set the user time to the new time and recreate the service, timer, trigger, and script + user_time=$new_time + create_service_and_timer + fi + ;; + *) + echo -e "\e[1;31mInvalid choice. Exiting.\e[0m" + exit 1 + ;; + esac + else + printf "Enter the time for daily reboot (24-hour format in UTC, HH:MM): " + read user_time + + # Validate the time format using grep + if ! echo "$user_time" | grep -qE '^([01]?[0-9]|2[0-3]):[0-5][0-9]$'; then + echo "Invalid time format. Exiting." + exit 1 + else + create_service_and_timer + fi + fi + + # Remount root filesystem as read-only + mount -o remount,ro / +} + +# Function to create systemd service and timer files +create_service_and_timer() { + remount_rw + # Define the path for the modem reboot script + MODEM_REBOOT_SCRIPT="$USRDATA_DIR/reboot_modem.sh" + + # Create the modem reboot script + echo "#!/bin/sh +/bin/echo -e 'AT+CFUN=1,1 \r' > /dev/smd7" > "$MODEM_REBOOT_SCRIPT" + + # Make the script executable + chmod +x "$MODEM_REBOOT_SCRIPT" + + # Create the systemd service file for reboot + echo "[Unit] +Description=Reboot Modem Daily + +[Service] +Type=oneshot +ExecStart=/bin/sh /usrdata/reboot_modem.sh +Restart=no +RemainAfterExit=no" > /lib/systemd/system/rebootmodem.service + + # Create the systemd timer file with the user-specified time + echo "[Unit] +Description=Starts rebootmodem.service daily at the specified time + +[Timer] +OnCalendar=*-*-* $user_time:00 +Persistent=false" > /lib/systemd/system/rebootmodem.timer + + # Create a trigger service that starts the timer at boot + echo "[Unit] +Description=Trigger the rebootmodem timer at boot + +[Service] +Type=oneshot +ExecStart=/bin/systemctl start rebootmodem.timer +RemainAfterExit=yes" > /lib/systemd/system/rebootmodem-trigger.service + + # Create symbolic links for the trigger service in the wanted directory + ln -sf /lib/systemd/system/rebootmodem-trigger.service /lib/systemd/system/multi-user.target.wants/ + + # Reload systemd to recognize the new timer and trigger service + systemctl daemon-reload + sleep 2s + + # Start the trigger service, which will start the timer + systemctl start rebootmodem-trigger.service + remount_ro + + # Confirmation + echo -e "\e[1;32mRebootmodem-trigger service created and started successfully.\e[0m" + echo -e "\e[1;32mReboot schedule set successfully. The modem will reboot daily at $user_time UTC.\e[0m" +} + +# Function to manage CFUN fix +manage_cfun_fix() { + cfun_service_path="/lib/systemd/system/cfunfix.service" + cfun_fix_script="/usrdata/cfun_fix.sh" + + mount -o remount,rw / + + if [ -f "$cfun_service_path" ]; then + echo -e "\e[1;32mThe CFUN fix is already installed. Do you want to remove it?\e[0m" # Green + echo -e "\e[1;32m1) Yes\e[0m" # Green + echo -e "\e[1;31m2) No\e[0m" # Red + read -p "Enter your choice: " choice + + if [ "$choice" = "1" ]; then + echo "Removing CFUN fix..." + systemctl stop cfunfix.service + rm -f /lib/systemd/system/multi-user.target.wants/cfunfix.service + rm -f "$cfun_service_path" + rm -f "$cfun_fix_script" + systemctl daemon-reload + echo "CFUN fix has been removed." + else + echo "Returning to main menu..." + fi + else + echo -e "\e[1;32mInstalling CFUN fix...\e[0m" + + # Create the CFUN fix script + echo "#!/bin/sh +/bin/echo -e 'AT+CFUN=1 \r' > /dev/smd7" > "$cfun_fix_script" + chmod +x "$cfun_fix_script" + + # Create the systemd service file to execute the CFUN fix script at boot + echo "[Unit] +Description=CFUN Fix Service +After=network.target + +[Service] +Type=oneshot +ExecStart=$cfun_fix_script +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target" > "$cfun_service_path" + + ln -sf "$cfun_service_path" "/lib/systemd/system/multi-user.target.wants/" + systemctl daemon-reload + mount -o remount,ro / + echo -e "\e[1;32mCFUN fix has been installed and will execute at every boot.\e[0m" + fi +} + +##################################################################### +# SimpleAdmin Functions +##################################################################### + +# Function to set SimpleAdmin password +set_simpleadmin_passwd(){ + ensure_entware_installed + opkg update + opkg install libaprutil + wget -O /usrdata/root/bin/htpasswd $GITROOT/simpleadmin/htpasswd && chmod +x /usrdata/root/bin/htpasswd + wget -O /usrdata/root/bin/simplepasswd $GITROOT/simpleadmin/simplepasswd && chmod +x /usrdata/root/bin/simplepasswd + echo -e "\e[1;32mTo change your simpleadmin (admin) password in the future...\e[0m" + echo -e "\e[1;32mIn the console type simplepasswd and press enter\e[0m" + /usrdata/root/bin/simplepasswd +} + +# Function to set root password +set_root_passwd() { + echo -e "\e[1;31mPlease set the root/console password.\e[0m" + /opt/bin/passwd +} + +# Function to install/update Simple Admin +install_simple_admin() { + echo -e "\e[1;32mInstalling Simpleadmin 2.0\e[0m" + ensure_entware_installed + echo -e "\e[1;31m2) Installing Simpleadmin 2.0\e[0m" + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh $GITROOT/simpleupdates/scripts/update_socat-at-bridge.sh && chmod +x /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh + echo -e "\e[1;32mInstalling/updating dependency: socat-at-bridge\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh + echo -e "\e[1;32m Dependency: socat-at-bridge has been updated/installed.\e[0m" + sleep 1 + wget -O /usrdata/simpleupdates/scripts/update_simplefirewall.sh $GITROOT/simpleupdates/scripts/update_simplefirewall.sh && chmod +x /usrdata/simpleupdates/scripts/update_simplefirewall.sh + echo -e "\e[1;32mInstalling/updating dependency: simplefirewall\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_simplefirewall.sh + echo -e "\e[1;32m Dependency: simplefirewall has been updated/installed.\e[0m" + sleep 1 + set_simpleadmin_passwd + wget -O /usrdata/simpleupdates/scripts/update_simpleadmin.sh $GITROOT/simpleupdates/scripts/update_simpleadmin.sh && chmod +x /usrdata/simpleupdates/scripts/update_simpleadmin.sh + echo -e "\e[1;32mInstalling/updating: Simpleadmin content\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_simpleadmin.sh + echo -e "\e[1;32mSimpleadmin content has been updated/installed.\e[0m" + sleep 1 +} + +# Function to configure Simple Firewall +configure_simple_firewall() { + if [ ! -f "$SIMPLE_FIREWALL_SCRIPT" ]; then + echo -e "\033[0;31mSimplefirewall is not installed, would you like to install it?\033[0m" + echo -e "\033[0;32m1) Yes\033[0m" + echo -e "\033[0;31m2) No\033[0m" + read -p "Enter your choice (1-2): " install_choice + + case $install_choice in + 1) + install_simple_firewall + ;; + 2) + return + ;; + *) + echo -e "\033[0;31mInvalid choice. Please select either 1 or 2.\033[0m" + ;; + esac + fi + + echo -e "\e[1;32mConfigure Simple Firewall:\e[0m" + echo -e "\e[38;5;208m1) Configure incoming port block\e[0m" + echo -e "\e[38;5;27m2) Configure TTL\e[0m" + read -p "Enter your choice (1-2): " menu_choice + + case $menu_choice in + 1) + # Original ports configuration code with exit option + current_ports_line=$(grep '^PORTS=' "$SIMPLE_FIREWALL_SCRIPT") + ports=$(echo "$current_ports_line" | cut -d'=' -f2 | tr -d '()' | tr ' ' '\n' | grep -o '[0-9]\+') + echo -e "\e[1;32mCurrent configured ports:\e[0m" + echo "$ports" | awk '{print NR") "$0}' + + while true; do + echo -e "\e[1;32mEnter a port number to add/remove, or type 'done' or 'exit' to finish:\e[0m" + read port + if [ "$port" = "done" ] || [ "$port" = "exit" ]; then + if [ "$port" = "exit" ]; then + echo -e "\e[1;31mExiting without making changes...\e[0m" + return + fi + break + elif ! echo "$port" | grep -qE '^[0-9]+$'; then + echo -e "\e[1;31mInvalid input: Please enter a numeric value.\e[0m" + elif echo "$ports" | grep -q "^$port\$"; then + ports=$(echo "$ports" | grep -v "^$port\$") + echo -e "\e[1;32mPort $port removed.\e[0m" + else + ports=$(echo "$ports"; echo "$port" | grep -o '[0-9]\+') + echo -e "\e[1;32mPort $port added.\e[0m" + fi + done + + if [ "$port" != "exit" ]; then + new_ports_line="PORTS=($(echo "$ports" | tr '\n' ' '))" + sed -i "s/$current_ports_line/$new_ports_line/" "$SIMPLE_FIREWALL_SCRIPT" + fi + ;; + 2) + # TTL configuration code + ttl_value=$(cat /usrdata/simplefirewall/ttlvalue) + if [ "$ttl_value" -eq 0 ]; then + echo -e "\e[1;31mTTL is not set.\e[0m" + else + echo -e "\e[1;32mTTL value is set to $ttl_value.\e[0m" + fi + + echo -e "\e[1;31mType 'exit' to cancel.\e[0m" + read -p "What do you want the TTL value to be: " new_ttl_value + if [ "$new_ttl_value" = "exit" ]; then + echo -e "\e[1;31mExiting TTL configuration...\e[0m" + return + elif ! echo "$new_ttl_value" | grep -qE '^[0-9]+$'; then + echo -e "\e[1;31mInvalid input: Please enter a numeric value.\e[0m" + return + else + /usrdata/simplefirewall/ttl-override stop + echo "$new_ttl_value" > /usrdata/simplefirewall/ttlvalue + /usrdata/simplefirewall/ttl-override start + echo -e "\033[0;32mTTL value updated to $new_ttl_value.\033[0m" + fi + ;; + *) + echo -e "\e[1;31mInvalid choice. Please select either 1 or 2.\e[0m" + ;; + esac + + systemctl restart simplefirewall + echo -e "\e[1;32mFirewall configuration updated.\e[0m" +} + +# Function to Uninstall Simpleadmin and dependencies +uninstall_simpleadmin_components() { + echo -e "\e[1;32mStarting the uninstallation process for Simpleadmin components.\e[0m" + echo -e "\e[1;32mNote: Uninstalling certain components may affect the functionality of others.\e[0m" + remount_rw + + # Uninstall Simple Firewall + echo -e "\e[1;32mDo you want to uninstall Simplefirewall?\e[0m" + echo -e "\e[1;31mIf you do, the TTL part of simpleadmin will no longer work.\e[0m" + echo -e "\e[1;32m1) Yes\e[0m" + echo -e "\e[1;31m2) No\e[0m" + read -p "Enter your choice (1 or 2): " choice_simplefirewall + if [ "$choice_simplefirewall" -eq 1 ]; then + echo "Uninstalling Simplefirewall..." + systemctl stop simplefirewall + systemctl stop ttl-override + rm -f /lib/systemd/system/simplefirewall.service + rm -f /lib/systemd/system/ttl-override.service + systemctl daemon-reload + rm -rf "$SIMPLE_FIREWALL_DIR" + echo "Simplefirewall uninstalled." + fi + + # Uninstall socat-at-bridge + echo -e "\e[1;32mDo you want to uninstall socat-at-bridge?\e[0m" + echo -e "\e[1;31mIf you do, AT commands and the stat page will no longer work. atcmd won't either.\e[0m" + echo -e "\e[1;32m1) Yes\e[0m" + echo -e "\e[1;31m2) No\e[0m" + read -p "Enter your choice (1 or 2): " choice_socat_at_bridge + if [ "$choice_socat_at_bridge" -eq 1 ]; then + echo -e "\033[0;32mRemoving installed AT Socat Bridge services...\033[0m" + systemctl stop at-telnet-daemon > /dev/null 2>&1 + systemctl disable at-telnet-daemon > /dev/null 2>&1 + systemctl stop socat-smd11 > /dev/null 2>&1 + systemctl stop socat-smd11-to-ttyIN > /dev/null 2>&1 + systemctl stop socat-smd11-from-ttyIN > /dev/null 2>&1 + systemctl stop socat-smd7 > /dev/null 2>&1 + systemctl stop socat-smd7-to-ttyIN2 > /dev/null 2>&1 + systemctl stop socat-smd7-to-ttyIN > /dev/null 2>&1 + systemctl stop socat-smd7-from-ttyIN2 > /dev/null 2>&1 + systemctl stop socat-smd7-from-ttyIN > /dev/null 2>&1 + rm /lib/systemd/system/at-telnet-daemon.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd11.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd11-to-ttyIN.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd11-from-ttyIN.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd7.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd7-to-ttyIN2.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd7-to-ttyIN.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd7-from-ttyIN.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd7-from-ttyIN2.service > /dev/null 2>&1 + systemctl daemon-reload > /dev/null 2>&1 + rm -rf "$SOCAT_AT_DIR" > /dev/null 2>&1 + rm -rf "$SOCAT_AT_DIR" > /dev/null 2>&1 + rm -rf "/usrdata/micropython" > /dev/null 2>&1 + rm -rf "/usrdata/at-telnet" > /dev/null 2>&1 + echo -e "\033[0;32mAT Socat Bridge services removed!...\033[0m" + fi + + # Uninstall ttyd + echo -e "\e[1;32mDo you want to uninstall ttyd (simpleadmin console)?\e[0m" + echo -e "\e[1;31mWarning: Do not uninstall if you are currently using ttyd to do this!!!\e[0m" + echo -e "\e[1;32m1) Yes\e[0m" + echo -e "\e[1;31m2) No\e[0m" + read -p "Enter your choice (1 or 2): " choice_simpleadmin + if [ "$choice_simpleadmin" -eq 1 ]; then + echo -e "\e[1;34mUninstalling ttyd...\e[0m" + systemctl stop ttyd + rm -rf /usrdata/ttyd + rm /lib/systemd/system/ttyd.service + rm /lib/systemd/system/multi-user.target.wants/ttyd.service + rm /bin/ttyd + echo -e "\e[1;32mttyd has been uninstalled.\e[0m" + fi + + echo "Uninstalling the rest of Simpleadmin..." + + # Check if Lighttpd service is installed and remove it if present + if [ -f "/lib/systemd/system/lighttpd.service" ]; then + echo "Lighttpd detected, uninstalling Lighttpd and its modules..." + systemctl stop lighttpd + opkg --force-remove --force-removal-of-dependent-packages remove lighttpd-mod-authn_file lighttpd-mod-auth lighttpd-mod-cgi lighttpd-mod-openssl lighttpd-mod-proxy lighttpd + rm -rf $LIGHTTPD_DIR + fi + + systemctl stop simpleadmin_generate_status + systemctl stop simpleadmin_httpd + rm -f /lib/systemd/system/simpleadmin_httpd.service + rm -f /lib/systemd/system/simpleadmin_generate_status.service + systemctl daemon-reload + rm -rf "$SIMPLE_ADMIN_DIR" + echo "The rest of Simpleadmin and Lighttpd (if present) uninstalled." + remount_ro + + echo "Uninstallation process completed." +} + +##################################################################### +# Tailscale Management Functions +##################################################################### + +# Function for Tailscale Submenu +tailscale_menu() { + while true; do + echo -e "\e[1;32mTailscale Menu\e[0m" + echo -e "\e[1;32m1) Install/Update Tailscale\e[0m" + echo -e "\e[1;36m2) Configure Tailscale\e[0m" + echo -e "\e[1;31m3) Uninstall Tailscale\e[0m" + echo -e "\e[1;93m4) Return to Main Menu\e[0m" + read -p "Enter your choice: " tailscale_choice + + case $tailscale_choice in + 1) install_update_tailscale;; + 2) configure_tailscale;; + 3) uninstall_tailscale;; + 4) break;; + *) echo "Invalid option";; + esac + done +} + +# Function to install or update Tailscale +install_update_tailscale() { + echo -e "\e[1;31m2) Installing tailscale from the $GITTREE branch\e[0m" + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_tailscale.sh $GITROOT/simpleupdates/scripts/update_tailscale.sh && chmod +x /usrdata/simpleupdates/scripts/update_tailscale.sh + echo -e "\e[1;32mInstalling/updating: Tailscale\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + remount_rw + /usrdata/simpleupdates/scripts/update_tailscale.sh + echo -e "\e[1;32m Tailscale has been updated/installed.\e[0m" +} + +# Function to uninstall Tailscale +uninstall_tailscale() { + echo -e "\e[1;31mUninstalling Tailscale...\e[0m" + + # Stop and logout from Tailscale + if [ -f "/usrdata/tailscale/tailscale" ]; then + /usrdata/tailscale/tailscale logout + /usrdata/tailscale/tailscale down + fi + + # Stop services + systemctl stop tailscale 2>/dev/null + systemctl stop tailscale-webui 2>/dev/null + + # Remove service files + rm -f /lib/systemd/system/tailscale.service + rm -f /lib/systemd/system/tailscale-webui.service + rm -f /lib/systemd/system/tailscale-webui-trigger.service + rm -f /lib/systemd/system/multi-user.target.wants/tailscale-webui-trigger.service + + # Remove Tailscale files and directories + rm -rf /usrdata/tailscale + rm -f /bin/tailscale + rm -f /bin/tailscaled + + # Reload systemd + systemctl daemon-reload + + echo -e "\e[1;32mTailscale has been uninstalled.\e[0m" +} + +# Function to Configure Tailscale +configure_tailscale() { + while true; do + echo "Configure Tailscale" + echo -e "\e[38;5;40m1) Enable Tailscale Web UI at http://192.168.225.1:8088 (Gateway on port 8088)\e[0m" # Green + echo -e "\e[38;5;196m2) Disable Tailscale Web UI\e[0m" # Red + echo -e "\e[38;5;27m3) Connect to Tailnet\e[0m" # Brown + echo -e "\e[38;5;87m4) Connect to Tailnet with SSH ON\e[0m" # Light cyan + echo -e "\e[38;5;105m5) Reconnect to Tailnet with SSH OFF\e[0m" # Light magenta + echo -e "\e[38;5;172m6) Disconnect from Tailnet (reconnects at reboot)\e[0m" # Light yellow + echo -e "\e[1;31m7) Logout from tailscale account\e[0m" + echo -e "\e[38;5;27m8) Return to Tailscale Menu\e[0m" + read -p "Enter your choice: " config_choice + + case $config_choice in + 1) + remount_rw + cd /lib/systemd/system/ + wget -O tailscale-webui.service $GITROOT/tailscale/systemd/tailscale-webui.service + wget -O tailscale-webui-trigger.service $GITROOT/tailscale/systemd/tailscale-webui-trigger.service + ln -sf /lib/systemd/system/tailscale-webui-trigger.service /lib/systemd/system/multi-user.target.wants/ + systemctl daemon-reload + echo "Tailscale Web UI Enabled" + echo "Starting Web UI..." + systemctl start tailscale-webui + echo "Web UI started!" + remount_ro + ;; + 2) + remount_rw + systemctl stop tailscale-webui + systemctl disable tailscale-webui-trigger + rm /lib/systemd/system/multi-user.target.wants/tailscale-webui.service + rm /lib/systemd/system/multi-user.target.wants/tailscale-webui-trigger.service + rm /lib/systemd/system/tailscale-webui.service + rm /lib/systemd/system/tailscale-webui-trigger.service + systemctl daemon-reload + echo "Tailscale Web UI Stopped and Disabled" + remount_ro + ;; + 3) $TAILSCALE_DIR/tailscale up --accept-dns=false --reset --accept-routes;; + 4) $TAILSCALE_DIR/tailscale up --ssh --accept-dns=false --reset --accept-routes;; + 5) $TAILSCALE_DIR/tailscale up --accept-dns=false --reset --accept-routes;; + 6) $TAILSCALE_DIR/tailscale down;; + 7) $TAILSCALE_DIR/tailscale logout;; + 8) break;; + *) echo "Invalid option";; + esac + done +} + +##################################################################### +# Tool Installation Functions +##################################################################### + +# Function to install OpenSSH Server +install_sshd() { + if [ -d "/usrdata/sshd" ]; then + echo -e "\e[1;31mSSHD is currently installed.\e[0m" + echo -e "Do you want to update or uninstall?" + echo -e "1.) Update" + echo -e "2.) Uninstall" + read -p "Select an option (1 or 2): " sshd_choice + + case $sshd_choice in + 1) + echo -e "\e[1;31m2) Installing sshd from the $GITTREE branch\e[0m" + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_sshd.sh $GITROOT/simpleupdates/scripts/update_sshd.sh && chmod +x /usrdata/simpleupdates/scripts/update_sshd.sh + echo -e "\e[1;32mUpdating: SSHd\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_sshd.sh + echo -e "\e[1;32m SSHd has been updated.\e[0m" + ;; + 2) + echo -e "\e[1;31mUninstalling SSHD...\e[0m" + systemctl stop sshd + rm /lib/systemd/system/sshd.service + opkg remove openssh-server-pam + echo -e "\e[1;32mSSHD has been uninstalled successfully.\e[0m" + return 0 + ;; + *) + echo -e "\e[1;31mInvalid option. Please select 1 or 2.\e[0m" + return 1 + ;; + esac + fi + + # Proceed with installation if not installed + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_sshd.sh $GITROOT/simpleupdates/scripts/update_sshd.sh && chmod +x /usrdata/simpleupdates/scripts/update_sshd.sh + echo -e "\e[1;32mInstalling: SSHd\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_sshd.sh + echo -e "\e[1;32m SSHd has been installed.\e[0m" +} + +# Function to install Speedtest CLI +install_speedtest_cli() { + ensure_entware_installed + echo -e "\e[1;32mInstalling Speedtest.net CLI (speedtest command)\e[0m" + remount_rw + mkdir /usrdata/root + mkdir /usrdata/root/bin + cd /usrdata/root/bin + wget https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-linux-armhf.tgz + tar -xzf ookla-speedtest-1.2.0-linux-armhf.tgz + rm ookla-speedtest-1.2.0-linux-armhf.tgz + rm speedtest.md + cd / + ln -sf /usrdata/root/bin/speedtest /bin + remount_ro + echo -e "\e[1;32mSpeedtest CLI (speedtest command) installed!!\e[0m" + echo -e "\e[1;32mTry running the command 'speedtest'\e[0m" + echo -e "\e[1;32mNote that it will not work unless you login to the root account first\e[0m" + echo -e "\e[1;32mNormaly only an issue in adb, ttyd and ssh you are forced to login\e[0m" + echo -e "\e[1;32mIf in adb just type login and then try to run the speedtest command\e[0m" +} + +# Function to install Fast.com CLI +install_fast_cli() { + echo -e "\e[1;32mInstalling fast.com CLI (fast command)\e[0m" + remount_rw + mkdir /usrdata/root + mkdir /usrdata/root/bin + cd /usrdata/root/bin + wget -O fast https://code.example.com/sky/simple-admin/raw/branch/main/tools/fast_linux_arm && chmod +x fast + cd / + ln -sf /usrdata/root/bin/fast /bin + remount_ro + echo -e "\e[1;32mFast.com CLI (speedtest command) installed!!\e[0m" + echo -e "\e[1;32mTry running the command 'fast'\e[0m" + echo -e "\e[1;32mThe fast.com test tops out at 40Mbps on the modem\e[0m" +} + +##################################################################### +# AT Command Bridge Functions +##################################################################### + +# Function to install/update AT command socat bridge +install_update_at_socat() { + local current_dir=$(pwd) + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh $GITROOT/simpleupdates/scripts/update_socat-at-bridge.sh && chmod +x /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh + echo -e "\e[1;32mInstalling/updating: AT Socat Bridge\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh + echo -e "\e[1;32mAT Socat Bridge has been updated/installed.\e[0m" + cd "$current_dir" +} + +##################################################################### +# Firewall Functions +##################################################################### + +# Function to install Simple Firewall +install_simple_firewall() { + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_simplefirewall.sh $GITROOT/simpleupdates/scripts/update_simplefirewall.sh && chmod +x /usrdata/simpleupdates/scripts/update_simplefirewall.sh + echo -e "\e[1;32mInstalling/updating: Simple Firewall\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_simplefirewall.sh + echo -e "\e[1;32mSimple Firewall has been updated/installed.\e[0m" +} + +##################################################################### +# Main Menu and Program Flow +##################################################################### + +# Check system architecture and proceed accordingly +check_architecture() { + ARCH=$(uname -a) + if echo "$ARCH" | grep -q "aarch64"; then + cd /tmp && wget -O RM55x_rcPCIe_toolkit.sh https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/SDXPINN/RM55x_rcPCIe_toolkit.sh && chmod +x RM55x_rcPCIe_toolkit.sh && ./RM55x_rcPCIe_toolkit.sh && cd / + exit 0 + elif echo "$ARCH" | grep -q "armv7l"; then + # Continue if architecture is armv7l + echo "Architecture is armv7l, continuing..." + else + uname -a + echo "Unsupported architecture." + exit 1 + fi +} + +# Display the main menu +display_main_menu() { + echo "//////////////////////////////////////////////////////////////////" + echo "// //" + echo "// //" + echo "// :'######::'####:'##::::'##:'########::'##:::::::'########: //" + echo "// '##... ##:. ##:: ###::'###: ##.... ##: ##::::::: ##.....:: //" + echo "// ##:::..::: ##:: ####'####: ##:::: ##: ##::::::: ##::::::: //" + echo "// . ######::: ##:: ## ### ##: ########:: ##::::::: ######::: //" + echo "// :..... ##:: ##:: ##. #: ##: ##.....::: ##::::::: ##...:::: //" + echo "// '##::: ##:: ##:: ##:.:: ##: ##:::::::: ##::::::: ##::::::: //" + echo "// . ######::'####: ##:::: ##: ##:::::::: ########: ########: //" + echo "// :......:::....::..:::::..::..:::::::::........::........:: //" + echo "// :::'###::::'########::'##::::'##:'####:'##::: ##: //" + echo "// ::'## ##::: ##.... ##: ###::'###:. ##:: ###:: ##: //" + echo "// :'##:. ##:: ##:::: ##: ####'####:: ##:: ####: ##: //" + echo "// '##:::. ##: ##:::: ##: ## ### ##:: ##:: ## ## ##: //" + echo "// #########: ##:::: ##: ##. #: ##:: ##:: ##. ####: //" + echo "// ##.... ##: ##:::: ##: ##:.:: ##:: ##:: ##:. ###: //" + echo "// ##:::: ##: ########:: ##:::: ##:'####: ##::. ##: //" + echo "// ..:::::..::........:::..:::::..::....::..::::..:: //" + echo "// //" + echo "// By iamromulan //" + echo "//////////////////////////////////////////////////////////////////" + + echo -e "\e[92m" + echo "Welcome to iamromulan's RGMII Toolkit script for Quectel RMxxx Series modems!" + echo "Visit https://github.com/iamromulan for more!" + echo -e "\e[0m" + echo "Select an option:" + echo -e "\e[0m" + echo -e "\e[96m1) Send AT Commands\e[0m" # Cyan + echo -e "\e[93m2) Install Simple Admin\e[0m" # Yellow + echo -e "\e[95m3) Set Simpleadmin (admin) password\e[0m" # Light Purple + echo -e "\e[94m4) Set Console/ttyd (root) password\e[0m" # Light Blue + echo -e "\e[91m5) Uninstall Simple Admin\e[0m" # Light Red + echo -e "\e[95m6) Simple Firewall Management\e[0m" # Light Purple + echo -e "\e[94m7) Tailscale Management\e[0m" # Light Blue + echo -e "\e[92m8) Install/Change or remove Daily Reboot Timer\e[0m" # Light Green + echo -e "\e[96m9) Install/Uninstall CFUN 0 Fix\e[0m" # Cyan + echo -e "\e[91m10) Uninstall Entware/OPKG\e[0m" # Light Red + echo -e "\e[92m11) Install Speedtest.net CLI app (speedtest command)\e[0m" # Light Green + echo -e "\e[92m12) Install Fast.com CLI app (fast command)(tops out at 40Mbps)\e[0m" # Light Green + echo -e "\e[92m13) Install OpenSSH Server\e[0m" # Light Green + echo -e "\e[93m14) Exit\e[0m" # Yellow +} + +# Main program loop +main() { + check_architecture + + while true; do + display_main_menu + read -p "Enter your choice: " choice + + case $choice in + 1) send_at_commands;; + 2) install_simple_admin;; + 3) set_simpleadmin_passwd;; + 4) set_root_passwd;; + 5) uninstall_simpleadmin_components;; + 6) configure_simple_firewall;; + 7) tailscale_menu;; + 8) manage_reboot_timer;; + 9) manage_cfun_fix;; + 10) + echo -e "\033[31mAre you sure you want to uninstall entware?\033[0m" + echo -e "\033[31m1) Yes\033[0m" + echo -e "\033[31m2) No\033[0m" + read -p "Select an option (1 or 2): " user_choice + + case $user_choice in + 1) + echo -e "\033[31mUninstalling existing entware...\033[0m" + uninstall_entware + echo -e "\033[31mEntware has been uninstalled.\033[0m" + ;; + 2) + echo -e "\033[31mUninstallation cancelled.\033[0m" + exit + ;; + *) + echo -e "\033[31mInvalid option. Please select 1 or 2.\033[0m" + ;; + esac + ;; + 11) install_speedtest_cli;; + 12) install_fast_cli;; + 13) install_sshd;; + 14) + echo -e "\e[1;32mGoodbye!\e[0m" + break + ;; + *) + echo -e "\e[1;31mInvalid option\e[0m" + ;; + esac + done +} + +# Start the program +main -- 2.45.2 From 0392d614b1c83345e251a47c3812bc814633205a Mon Sep 17 00:00:00 2001 From: sky Date: Thu, 12 Dec 2024 03:08:04 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20RMxxx=5Frgmii=5Ftool?= =?UTF-8?q?kit=5Fdev.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RMxxx_rgmii_toolkit_dev.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RMxxx_rgmii_toolkit_dev.sh b/RMxxx_rgmii_toolkit_dev.sh index 1de1ed8..df9bf4f 100644 --- a/RMxxx_rgmii_toolkit_dev.sh +++ b/RMxxx_rgmii_toolkit_dev.sh @@ -15,7 +15,7 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:/usrdata/root/bin # Define Gitea repository configuration -GITEA_HOST="code.example.com" +GITEA_HOST="code.060070.xyz" GITUSER="sky" REPONAME="simple-admin" GITTREE="main" @@ -872,7 +872,7 @@ install_fast_cli() { mkdir /usrdata/root mkdir /usrdata/root/bin cd /usrdata/root/bin - wget -O fast https://code.example.com/sky/simple-admin/raw/branch/main/tools/fast_linux_arm && chmod +x fast + wget -O fast https://code.060070.xyz/sky/simple-admin/raw/branch/main/tools/fast_linux_arm && chmod +x fast cd / ln -sf /usrdata/root/bin/fast /bin remount_ro -- 2.45.2 From 9357f5b17ddee77d0b4f78116695716b3100a954 Mon Sep 17 00:00:00 2001 From: sky Date: Thu, 12 Dec 2024 04:03:33 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E5=88=A0=E9=99=A4=20RMxxx=5Frgmii=5Ftool?= =?UTF-8?q?kit=5Fdev.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RMxxx_rgmii_toolkit_dev.sh | 1039 ------------------------------------ 1 file changed, 1039 deletions(-) delete mode 100644 RMxxx_rgmii_toolkit_dev.sh diff --git a/RMxxx_rgmii_toolkit_dev.sh b/RMxxx_rgmii_toolkit_dev.sh deleted file mode 100644 index df9bf4f..0000000 --- a/RMxxx_rgmii_toolkit_dev.sh +++ /dev/null @@ -1,1039 +0,0 @@ -#!/bin/sh - -##################################################################### -# RMxxx RGMII Toolkit -# Author: iamromulan -# Description: Toolkit for Quectel RMxxx Series modems -# Repository: https://github.com/iamromulan -##################################################################### - -##################################################################### -# Environment Configuration -##################################################################### - -# Define toolkit paths -export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:/usrdata/root/bin - -# Define Gitea repository configuration -GITEA_HOST="code.060070.xyz" -GITUSER="sky" -REPONAME="simple-admin" -GITTREE="main" -GITMAINTREE="main" -GITDEVTREE="dev" - -# Construct Gitea URLs -# Format: https://[host]/[user]/[repo]/raw/branch/[branch]/[file] -GITROOT="https://$GITEA_HOST/$GITUSER/$REPONAME/raw/branch/$GITTREE" -GITROOTMAIN="https://$GITEA_HOST/$GITUSER/$REPONAME/raw/branch/$GITMAINTREE" -GITROOTDEV="https://$GITEA_HOST/$GITUSER/$REPONAME/raw/branch/$GITDEVTREE" - -##################################################################### -# Directory Configuration -##################################################################### - -# System directories -TMP_DIR="/tmp" -USRDATA_DIR="/usrdata" - -# Application directories -SOCAT_AT_DIR="/usrdata/socat-at-bridge" -SOCAT_AT_SYSD_DIR="/usrdata/socat-at-bridge/systemd_units" -SIMPLE_ADMIN_DIR="/usrdata/simpleadmin" -SIMPLE_FIREWALL_DIR="/usrdata/simplefirewall" -SIMPLE_FIREWALL_SCRIPT="$SIMPLE_FIREWALL_DIR/simplefirewall.sh" -SIMPLE_FIREWALL_SYSTEMD_DIR="$SIMPLE_FIREWALL_DIR/systemd" -TAILSCALE_DIR="/usrdata/tailscale" -TAILSCALE_SYSD_DIR="/usrdata/tailscale/systemd" -LIGHTTPD_DIR="/usrdata/lighttpd" - -# AT Command configuration -DEVICE_FILE="/dev/smd7" -TIMEOUT=4 # Set a timeout for the response - -##################################################################### -# Basic Utility Functions -##################################################################### - -# Function to remount file system as read-write -remount_rw() { - mount -o remount,rw / -} - -# Function to remount file system as read-only -remount_ro() { - mount -o remount,ro / -} - -##################################################################### -# AT Command Functions -##################################################################### - -# Basic AT commands without socat bridge for fast response commands only -start_listening() { - cat "$DEVICE_FILE" > /tmp/device_readout & - CAT_PID=$! -} - -send_at_command() { - echo -e "\e[1;31mThis only works for basic quick responding commands!\e[0m" # Red - echo -e "\e[1;36mType 'install' to simply type atcmd in shell from now on\e[0m" - echo -e "\e[1;36mThe installed version is much better than this portable version\e[0m" - echo -e "\e[1;32mEnter AT command (or type 'exit' to quit): \e[0m" - read at_command - if [ "$at_command" = "exit" ]; then - return 1 - fi - - if [ "$at_command" = "install" ]; then - install_update_at_socat - echo -e "\e[1;32mInstalled. Type atcmd from adb shell or ssh to start an AT Command session\e[0m" - return 1 - fi - echo -e "${at_command}\r" > "$DEVICE_FILE" -} - -wait_for_response() { - local start_time=$(date +%s) - local current_time - local elapsed_time - - echo -e "\e[1;32mCommand sent, waiting for response...\e[0m" - while true; do - if grep -qe "OK" -e "ERROR" /tmp/device_readout; then - echo -e "\e[1;32mResponse received:\e[0m" - cat /tmp/device_readout - return 0 - fi - current_time=$(date +%s) - elapsed_time=$((current_time - start_time)) - if [ "$elapsed_time" -ge "$TIMEOUT" ]; then - echo -e "\e[1;31mError: Response timed out.\e[0m" # Red - echo -e "\e[1;32mIf the responce takes longer than a second or 2 to respond this will not work\e[0m" # Green - echo -e "\e[1;36mType install to install the better version of this that will work.\e[0m" # Cyan - return 1 - fi - sleep 1 - done -} - -cleanup() { - kill "$CAT_PID" - wait "$CAT_PID" 2>/dev/null - rm -f /tmp/device_readout -} - -send_at_commands() { - if [ -c "$DEVICE_FILE" ]; then - while true; do - start_listening - send_at_command - if [ $? -eq 1 ]; then - cleanup - break - fi - wait_for_response - cleanup - done - else - echo -e "\e[1;31mError: Device $DEVICE_FILE does not exist!\e[0m" - fi -} - -##################################################################### -# Installation and Package Management Functions -##################################################################### - -# Check for existing Entware/opkg installation, install if not installed -ensure_entware_installed() { - remount_rw - if [ ! -f "/opt/bin/opkg" ]; then - echo -e "\e[1;32mInstalling Entware/OPKG\e[0m" - cd /tmp && wget -O installentware.sh "$GITROOT/installentware.sh" && chmod +x installentware.sh && ./installentware.sh - if [ "$?" -ne 0 ]; then - echo -e "\e[1;31mEntware/OPKG installation failed. Please check your internet connection or the repository URL.\e[0m" - exit 1 - fi - cd / - else - echo -e "\e[1;32mEntware/OPKG is already installed.\e[0m" - if [ "$(readlink /bin/login)" != "/opt/bin/login" ]; then - opkg update && opkg install shadow-login shadow-passwd shadow-useradd - if [ "$?" -ne 0 ]; then - echo -e "\e[1;31mPackage installation failed. Please check your internet connection and try again.\e[0m" - exit 1 - fi - - # Replace the login and passwd binaries and set home for root to a writable directory - rm /opt/etc/shadow - rm /opt/etc/passwd - cp /etc/shadow /opt/etc/ - cp /etc/passwd /opt/etc - mkdir -p /usrdata/root/bin - touch /usrdata/root/.profile - echo "# Set PATH for all shells" > /usrdata/root/.profile - echo "export PATH=/bin:/usr/sbin:/usr/bin:/sbin:/opt/sbin:/opt/bin:/usrdata/root/bin" >> /usrdata/root/.profile - chmod +x /usrdata/root/.profile - sed -i '1s|/home/root:/bin/sh|/usrdata/root:/bin/bash|' /opt/etc/passwd - rm /bin/login /usr/bin/passwd - ln -sf /opt/bin/login /bin - ln -sf /opt/bin/passwd /usr/bin/ - ln -sf /opt/bin/useradd /usr/bin/ - echo -e "\e[1;31mPlease set the root password.\e[0m" - /opt/bin/passwd - - # Install basic and useful utilities - opkg install mc htop dfc lsof - ln -sf /opt/bin/mc /bin - ln -sf /opt/bin/htop /bin - ln -sf /opt/bin/dfc /bin - ln -sf /opt/bin/lsof /bin - fi - - if [ ! -f "/usrdata/root/.profile" ]; then - opkg update && opkg install shadow-useradd - mkdir -p /usrdata/root/bin - touch /usrdata/root/.profile - echo "# Set PATH for all shells" > /usrdata/root/.profile - echo "export PATH=/bin:/usr/sbin:/usr/bin:/sbin:/opt/sbin:/opt/bin:/usrdata/root/bin" >> /usrdata/root/.profile - chmod +x /usrdata/root/.profile - sed -i '1s|/home/root:/bin/sh|/usrdata/root:/bin/bash|' /opt/etc/passwd - fi - fi - if [ ! -f "/opt/sbin/useradd" ]; then - echo "useradd does not exist. Installing shadow-useradd..." - opkg install shadow-useradd - else - echo "useradd already exists. Continuing..." - fi - - if [ ! -f "/usr/bin/curl" ] && [ ! -f "/opt/bin/curl" ]; then - echo "curl does not exist. Installing curl..." - opkg update && opkg install curl - if [ "$?" -ne 0 ]; then - echo -e "\e[1;31mFailed to install curl. Please check your internet connection and try again.\e[0m" - exit 1 - fi - else - echo "curl already exists. Continuing..." - fi -} - -# Uninstall Entware if the Users chooses -uninstall_entware() { - echo -e '\033[31mInfo: Starting Entware/OPKG uninstallation...\033[0m' - - # Stop services - systemctl stop rc.unslung.service - /opt/etc/init.d/rc.unslung stop - rm /lib/systemd/system/multi-user.target.wants/rc.unslung.service - rm /lib/systemd/system/rc.unslung.service - - systemctl stop opt.mount - rm /lib/systemd/system/multi-user.target.wants/start-opt-mount.service - rm /lib/systemd/system/opt.mount - rm /lib/systemd/system/start-opt-mount.service - - # Unmount /opt if mounted - mountpoint -q /opt && umount /opt - - # Remove Entware installation directory - rm -rf /usrdata/opt - rm -rf /opt - - # Reload systemctl daemon - systemctl daemon-reload - - # Optionally, clean up any modifications to /etc/profile or other system files - # Restore original link to login binary compiled by Quectel - rm /bin/login - ln /bin/login.shadow /bin/login - - echo -e '\033[32mInfo: Entware/OPKG has been uninstalled successfully.\033[0m' -} - -##################################################################### -# System Service and Configuration Functions -##################################################################### - -# Function to manage Daily Reboot Timer -manage_reboot_timer() { - # Remount root filesystem as read-write - mount -o remount,rw / - - # Check if the rebootmodem service, timer, or trigger already exists - if [ -f /lib/systemd/system/rebootmodem.service ] || [ -f /lib/systemd/system/rebootmodem.timer ] || [ -f /lib/systemd/system/rebootmodem-trigger.service ]; then - echo -e "\e[1;32mThe rebootmodem service/timer/trigger is already installed.\e[0m" - echo -e "\e[1;32m1) Change\e[0m" # Green - echo -e "\e[1;31m2) Remove\e[0m" # Red - read -p "Enter your choice (1 for Change, 2 for Remove): " reboot_choice - - case $reboot_choice in - 2) - # Stop and disable timer and trigger service by removing symlinks - systemctl stop rebootmodem.timer - systemctl stop rebootmodem-trigger.service - - # Remove symbolic links and files - rm -f /lib/systemd/system/multi-user.target.wants/rebootmodem-trigger.service - rm -f /lib/systemd/system/rebootmodem.service - rm -f /lib/systemd/system/rebootmodem.timer - rm -f /lib/systemd/system/rebootmodem-trigger.service - rm -f "$USRDATA_DIR/reboot_modem.sh" - - # Reload systemd to apply changes - systemctl daemon-reload - - echo -e "\e[1;32mRebootmodem service, timer, trigger, and script removed successfully.\e[0m" - ;; - 1) - printf "Enter the new time for daily reboot (24-hour format in Coordinated Universal Time, HH:MM): " - read new_time - - # Validate the new time format using grep - if ! echo "$new_time" | grep -qE '^([01]?[0-9]|2[0-3]):[0-5][0-9]$'; then - echo "Invalid time format. Exiting." - exit 1 - else - # Remove old symlinks and script - rm -f /lib/systemd/system/multi-user.target.wants/rebootmodem-trigger.service - rm -f "$USRDATA_DIR/reboot_modem.sh" - - # Set the user time to the new time and recreate the service, timer, trigger, and script - user_time=$new_time - create_service_and_timer - fi - ;; - *) - echo -e "\e[1;31mInvalid choice. Exiting.\e[0m" - exit 1 - ;; - esac - else - printf "Enter the time for daily reboot (24-hour format in UTC, HH:MM): " - read user_time - - # Validate the time format using grep - if ! echo "$user_time" | grep -qE '^([01]?[0-9]|2[0-3]):[0-5][0-9]$'; then - echo "Invalid time format. Exiting." - exit 1 - else - create_service_and_timer - fi - fi - - # Remount root filesystem as read-only - mount -o remount,ro / -} - -# Function to create systemd service and timer files -create_service_and_timer() { - remount_rw - # Define the path for the modem reboot script - MODEM_REBOOT_SCRIPT="$USRDATA_DIR/reboot_modem.sh" - - # Create the modem reboot script - echo "#!/bin/sh -/bin/echo -e 'AT+CFUN=1,1 \r' > /dev/smd7" > "$MODEM_REBOOT_SCRIPT" - - # Make the script executable - chmod +x "$MODEM_REBOOT_SCRIPT" - - # Create the systemd service file for reboot - echo "[Unit] -Description=Reboot Modem Daily - -[Service] -Type=oneshot -ExecStart=/bin/sh /usrdata/reboot_modem.sh -Restart=no -RemainAfterExit=no" > /lib/systemd/system/rebootmodem.service - - # Create the systemd timer file with the user-specified time - echo "[Unit] -Description=Starts rebootmodem.service daily at the specified time - -[Timer] -OnCalendar=*-*-* $user_time:00 -Persistent=false" > /lib/systemd/system/rebootmodem.timer - - # Create a trigger service that starts the timer at boot - echo "[Unit] -Description=Trigger the rebootmodem timer at boot - -[Service] -Type=oneshot -ExecStart=/bin/systemctl start rebootmodem.timer -RemainAfterExit=yes" > /lib/systemd/system/rebootmodem-trigger.service - - # Create symbolic links for the trigger service in the wanted directory - ln -sf /lib/systemd/system/rebootmodem-trigger.service /lib/systemd/system/multi-user.target.wants/ - - # Reload systemd to recognize the new timer and trigger service - systemctl daemon-reload - sleep 2s - - # Start the trigger service, which will start the timer - systemctl start rebootmodem-trigger.service - remount_ro - - # Confirmation - echo -e "\e[1;32mRebootmodem-trigger service created and started successfully.\e[0m" - echo -e "\e[1;32mReboot schedule set successfully. The modem will reboot daily at $user_time UTC.\e[0m" -} - -# Function to manage CFUN fix -manage_cfun_fix() { - cfun_service_path="/lib/systemd/system/cfunfix.service" - cfun_fix_script="/usrdata/cfun_fix.sh" - - mount -o remount,rw / - - if [ -f "$cfun_service_path" ]; then - echo -e "\e[1;32mThe CFUN fix is already installed. Do you want to remove it?\e[0m" # Green - echo -e "\e[1;32m1) Yes\e[0m" # Green - echo -e "\e[1;31m2) No\e[0m" # Red - read -p "Enter your choice: " choice - - if [ "$choice" = "1" ]; then - echo "Removing CFUN fix..." - systemctl stop cfunfix.service - rm -f /lib/systemd/system/multi-user.target.wants/cfunfix.service - rm -f "$cfun_service_path" - rm -f "$cfun_fix_script" - systemctl daemon-reload - echo "CFUN fix has been removed." - else - echo "Returning to main menu..." - fi - else - echo -e "\e[1;32mInstalling CFUN fix...\e[0m" - - # Create the CFUN fix script - echo "#!/bin/sh -/bin/echo -e 'AT+CFUN=1 \r' > /dev/smd7" > "$cfun_fix_script" - chmod +x "$cfun_fix_script" - - # Create the systemd service file to execute the CFUN fix script at boot - echo "[Unit] -Description=CFUN Fix Service -After=network.target - -[Service] -Type=oneshot -ExecStart=$cfun_fix_script -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target" > "$cfun_service_path" - - ln -sf "$cfun_service_path" "/lib/systemd/system/multi-user.target.wants/" - systemctl daemon-reload - mount -o remount,ro / - echo -e "\e[1;32mCFUN fix has been installed and will execute at every boot.\e[0m" - fi -} - -##################################################################### -# SimpleAdmin Functions -##################################################################### - -# Function to set SimpleAdmin password -set_simpleadmin_passwd(){ - ensure_entware_installed - opkg update - opkg install libaprutil - wget -O /usrdata/root/bin/htpasswd $GITROOT/simpleadmin/htpasswd && chmod +x /usrdata/root/bin/htpasswd - wget -O /usrdata/root/bin/simplepasswd $GITROOT/simpleadmin/simplepasswd && chmod +x /usrdata/root/bin/simplepasswd - echo -e "\e[1;32mTo change your simpleadmin (admin) password in the future...\e[0m" - echo -e "\e[1;32mIn the console type simplepasswd and press enter\e[0m" - /usrdata/root/bin/simplepasswd -} - -# Function to set root password -set_root_passwd() { - echo -e "\e[1;31mPlease set the root/console password.\e[0m" - /opt/bin/passwd -} - -# Function to install/update Simple Admin -install_simple_admin() { - echo -e "\e[1;32mInstalling Simpleadmin 2.0\e[0m" - ensure_entware_installed - echo -e "\e[1;31m2) Installing Simpleadmin 2.0\e[0m" - mkdir /usrdata/simpleupdates > /dev/null 2>&1 - mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 - wget -O /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh $GITROOT/simpleupdates/scripts/update_socat-at-bridge.sh && chmod +x /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh - echo -e "\e[1;32mInstalling/updating dependency: socat-at-bridge\e[0m" - echo -e "\e[1;32mPlease Wait....\e[0m" - /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh - echo -e "\e[1;32m Dependency: socat-at-bridge has been updated/installed.\e[0m" - sleep 1 - wget -O /usrdata/simpleupdates/scripts/update_simplefirewall.sh $GITROOT/simpleupdates/scripts/update_simplefirewall.sh && chmod +x /usrdata/simpleupdates/scripts/update_simplefirewall.sh - echo -e "\e[1;32mInstalling/updating dependency: simplefirewall\e[0m" - echo -e "\e[1;32mPlease Wait....\e[0m" - /usrdata/simpleupdates/scripts/update_simplefirewall.sh - echo -e "\e[1;32m Dependency: simplefirewall has been updated/installed.\e[0m" - sleep 1 - set_simpleadmin_passwd - wget -O /usrdata/simpleupdates/scripts/update_simpleadmin.sh $GITROOT/simpleupdates/scripts/update_simpleadmin.sh && chmod +x /usrdata/simpleupdates/scripts/update_simpleadmin.sh - echo -e "\e[1;32mInstalling/updating: Simpleadmin content\e[0m" - echo -e "\e[1;32mPlease Wait....\e[0m" - /usrdata/simpleupdates/scripts/update_simpleadmin.sh - echo -e "\e[1;32mSimpleadmin content has been updated/installed.\e[0m" - sleep 1 -} - -# Function to configure Simple Firewall -configure_simple_firewall() { - if [ ! -f "$SIMPLE_FIREWALL_SCRIPT" ]; then - echo -e "\033[0;31mSimplefirewall is not installed, would you like to install it?\033[0m" - echo -e "\033[0;32m1) Yes\033[0m" - echo -e "\033[0;31m2) No\033[0m" - read -p "Enter your choice (1-2): " install_choice - - case $install_choice in - 1) - install_simple_firewall - ;; - 2) - return - ;; - *) - echo -e "\033[0;31mInvalid choice. Please select either 1 or 2.\033[0m" - ;; - esac - fi - - echo -e "\e[1;32mConfigure Simple Firewall:\e[0m" - echo -e "\e[38;5;208m1) Configure incoming port block\e[0m" - echo -e "\e[38;5;27m2) Configure TTL\e[0m" - read -p "Enter your choice (1-2): " menu_choice - - case $menu_choice in - 1) - # Original ports configuration code with exit option - current_ports_line=$(grep '^PORTS=' "$SIMPLE_FIREWALL_SCRIPT") - ports=$(echo "$current_ports_line" | cut -d'=' -f2 | tr -d '()' | tr ' ' '\n' | grep -o '[0-9]\+') - echo -e "\e[1;32mCurrent configured ports:\e[0m" - echo "$ports" | awk '{print NR") "$0}' - - while true; do - echo -e "\e[1;32mEnter a port number to add/remove, or type 'done' or 'exit' to finish:\e[0m" - read port - if [ "$port" = "done" ] || [ "$port" = "exit" ]; then - if [ "$port" = "exit" ]; then - echo -e "\e[1;31mExiting without making changes...\e[0m" - return - fi - break - elif ! echo "$port" | grep -qE '^[0-9]+$'; then - echo -e "\e[1;31mInvalid input: Please enter a numeric value.\e[0m" - elif echo "$ports" | grep -q "^$port\$"; then - ports=$(echo "$ports" | grep -v "^$port\$") - echo -e "\e[1;32mPort $port removed.\e[0m" - else - ports=$(echo "$ports"; echo "$port" | grep -o '[0-9]\+') - echo -e "\e[1;32mPort $port added.\e[0m" - fi - done - - if [ "$port" != "exit" ]; then - new_ports_line="PORTS=($(echo "$ports" | tr '\n' ' '))" - sed -i "s/$current_ports_line/$new_ports_line/" "$SIMPLE_FIREWALL_SCRIPT" - fi - ;; - 2) - # TTL configuration code - ttl_value=$(cat /usrdata/simplefirewall/ttlvalue) - if [ "$ttl_value" -eq 0 ]; then - echo -e "\e[1;31mTTL is not set.\e[0m" - else - echo -e "\e[1;32mTTL value is set to $ttl_value.\e[0m" - fi - - echo -e "\e[1;31mType 'exit' to cancel.\e[0m" - read -p "What do you want the TTL value to be: " new_ttl_value - if [ "$new_ttl_value" = "exit" ]; then - echo -e "\e[1;31mExiting TTL configuration...\e[0m" - return - elif ! echo "$new_ttl_value" | grep -qE '^[0-9]+$'; then - echo -e "\e[1;31mInvalid input: Please enter a numeric value.\e[0m" - return - else - /usrdata/simplefirewall/ttl-override stop - echo "$new_ttl_value" > /usrdata/simplefirewall/ttlvalue - /usrdata/simplefirewall/ttl-override start - echo -e "\033[0;32mTTL value updated to $new_ttl_value.\033[0m" - fi - ;; - *) - echo -e "\e[1;31mInvalid choice. Please select either 1 or 2.\e[0m" - ;; - esac - - systemctl restart simplefirewall - echo -e "\e[1;32mFirewall configuration updated.\e[0m" -} - -# Function to Uninstall Simpleadmin and dependencies -uninstall_simpleadmin_components() { - echo -e "\e[1;32mStarting the uninstallation process for Simpleadmin components.\e[0m" - echo -e "\e[1;32mNote: Uninstalling certain components may affect the functionality of others.\e[0m" - remount_rw - - # Uninstall Simple Firewall - echo -e "\e[1;32mDo you want to uninstall Simplefirewall?\e[0m" - echo -e "\e[1;31mIf you do, the TTL part of simpleadmin will no longer work.\e[0m" - echo -e "\e[1;32m1) Yes\e[0m" - echo -e "\e[1;31m2) No\e[0m" - read -p "Enter your choice (1 or 2): " choice_simplefirewall - if [ "$choice_simplefirewall" -eq 1 ]; then - echo "Uninstalling Simplefirewall..." - systemctl stop simplefirewall - systemctl stop ttl-override - rm -f /lib/systemd/system/simplefirewall.service - rm -f /lib/systemd/system/ttl-override.service - systemctl daemon-reload - rm -rf "$SIMPLE_FIREWALL_DIR" - echo "Simplefirewall uninstalled." - fi - - # Uninstall socat-at-bridge - echo -e "\e[1;32mDo you want to uninstall socat-at-bridge?\e[0m" - echo -e "\e[1;31mIf you do, AT commands and the stat page will no longer work. atcmd won't either.\e[0m" - echo -e "\e[1;32m1) Yes\e[0m" - echo -e "\e[1;31m2) No\e[0m" - read -p "Enter your choice (1 or 2): " choice_socat_at_bridge - if [ "$choice_socat_at_bridge" -eq 1 ]; then - echo -e "\033[0;32mRemoving installed AT Socat Bridge services...\033[0m" - systemctl stop at-telnet-daemon > /dev/null 2>&1 - systemctl disable at-telnet-daemon > /dev/null 2>&1 - systemctl stop socat-smd11 > /dev/null 2>&1 - systemctl stop socat-smd11-to-ttyIN > /dev/null 2>&1 - systemctl stop socat-smd11-from-ttyIN > /dev/null 2>&1 - systemctl stop socat-smd7 > /dev/null 2>&1 - systemctl stop socat-smd7-to-ttyIN2 > /dev/null 2>&1 - systemctl stop socat-smd7-to-ttyIN > /dev/null 2>&1 - systemctl stop socat-smd7-from-ttyIN2 > /dev/null 2>&1 - systemctl stop socat-smd7-from-ttyIN > /dev/null 2>&1 - rm /lib/systemd/system/at-telnet-daemon.service > /dev/null 2>&1 - rm /lib/systemd/system/socat-smd11.service > /dev/null 2>&1 - rm /lib/systemd/system/socat-smd11-to-ttyIN.service > /dev/null 2>&1 - rm /lib/systemd/system/socat-smd11-from-ttyIN.service > /dev/null 2>&1 - rm /lib/systemd/system/socat-smd7.service > /dev/null 2>&1 - rm /lib/systemd/system/socat-smd7-to-ttyIN2.service > /dev/null 2>&1 - rm /lib/systemd/system/socat-smd7-to-ttyIN.service > /dev/null 2>&1 - rm /lib/systemd/system/socat-smd7-from-ttyIN.service > /dev/null 2>&1 - rm /lib/systemd/system/socat-smd7-from-ttyIN2.service > /dev/null 2>&1 - systemctl daemon-reload > /dev/null 2>&1 - rm -rf "$SOCAT_AT_DIR" > /dev/null 2>&1 - rm -rf "$SOCAT_AT_DIR" > /dev/null 2>&1 - rm -rf "/usrdata/micropython" > /dev/null 2>&1 - rm -rf "/usrdata/at-telnet" > /dev/null 2>&1 - echo -e "\033[0;32mAT Socat Bridge services removed!...\033[0m" - fi - - # Uninstall ttyd - echo -e "\e[1;32mDo you want to uninstall ttyd (simpleadmin console)?\e[0m" - echo -e "\e[1;31mWarning: Do not uninstall if you are currently using ttyd to do this!!!\e[0m" - echo -e "\e[1;32m1) Yes\e[0m" - echo -e "\e[1;31m2) No\e[0m" - read -p "Enter your choice (1 or 2): " choice_simpleadmin - if [ "$choice_simpleadmin" -eq 1 ]; then - echo -e "\e[1;34mUninstalling ttyd...\e[0m" - systemctl stop ttyd - rm -rf /usrdata/ttyd - rm /lib/systemd/system/ttyd.service - rm /lib/systemd/system/multi-user.target.wants/ttyd.service - rm /bin/ttyd - echo -e "\e[1;32mttyd has been uninstalled.\e[0m" - fi - - echo "Uninstalling the rest of Simpleadmin..." - - # Check if Lighttpd service is installed and remove it if present - if [ -f "/lib/systemd/system/lighttpd.service" ]; then - echo "Lighttpd detected, uninstalling Lighttpd and its modules..." - systemctl stop lighttpd - opkg --force-remove --force-removal-of-dependent-packages remove lighttpd-mod-authn_file lighttpd-mod-auth lighttpd-mod-cgi lighttpd-mod-openssl lighttpd-mod-proxy lighttpd - rm -rf $LIGHTTPD_DIR - fi - - systemctl stop simpleadmin_generate_status - systemctl stop simpleadmin_httpd - rm -f /lib/systemd/system/simpleadmin_httpd.service - rm -f /lib/systemd/system/simpleadmin_generate_status.service - systemctl daemon-reload - rm -rf "$SIMPLE_ADMIN_DIR" - echo "The rest of Simpleadmin and Lighttpd (if present) uninstalled." - remount_ro - - echo "Uninstallation process completed." -} - -##################################################################### -# Tailscale Management Functions -##################################################################### - -# Function for Tailscale Submenu -tailscale_menu() { - while true; do - echo -e "\e[1;32mTailscale Menu\e[0m" - echo -e "\e[1;32m1) Install/Update Tailscale\e[0m" - echo -e "\e[1;36m2) Configure Tailscale\e[0m" - echo -e "\e[1;31m3) Uninstall Tailscale\e[0m" - echo -e "\e[1;93m4) Return to Main Menu\e[0m" - read -p "Enter your choice: " tailscale_choice - - case $tailscale_choice in - 1) install_update_tailscale;; - 2) configure_tailscale;; - 3) uninstall_tailscale;; - 4) break;; - *) echo "Invalid option";; - esac - done -} - -# Function to install or update Tailscale -install_update_tailscale() { - echo -e "\e[1;31m2) Installing tailscale from the $GITTREE branch\e[0m" - ensure_entware_installed - mkdir /usrdata/simpleupdates > /dev/null 2>&1 - mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 - wget -O /usrdata/simpleupdates/scripts/update_tailscale.sh $GITROOT/simpleupdates/scripts/update_tailscale.sh && chmod +x /usrdata/simpleupdates/scripts/update_tailscale.sh - echo -e "\e[1;32mInstalling/updating: Tailscale\e[0m" - echo -e "\e[1;32mPlease Wait....\e[0m" - remount_rw - /usrdata/simpleupdates/scripts/update_tailscale.sh - echo -e "\e[1;32m Tailscale has been updated/installed.\e[0m" -} - -# Function to uninstall Tailscale -uninstall_tailscale() { - echo -e "\e[1;31mUninstalling Tailscale...\e[0m" - - # Stop and logout from Tailscale - if [ -f "/usrdata/tailscale/tailscale" ]; then - /usrdata/tailscale/tailscale logout - /usrdata/tailscale/tailscale down - fi - - # Stop services - systemctl stop tailscale 2>/dev/null - systemctl stop tailscale-webui 2>/dev/null - - # Remove service files - rm -f /lib/systemd/system/tailscale.service - rm -f /lib/systemd/system/tailscale-webui.service - rm -f /lib/systemd/system/tailscale-webui-trigger.service - rm -f /lib/systemd/system/multi-user.target.wants/tailscale-webui-trigger.service - - # Remove Tailscale files and directories - rm -rf /usrdata/tailscale - rm -f /bin/tailscale - rm -f /bin/tailscaled - - # Reload systemd - systemctl daemon-reload - - echo -e "\e[1;32mTailscale has been uninstalled.\e[0m" -} - -# Function to Configure Tailscale -configure_tailscale() { - while true; do - echo "Configure Tailscale" - echo -e "\e[38;5;40m1) Enable Tailscale Web UI at http://192.168.225.1:8088 (Gateway on port 8088)\e[0m" # Green - echo -e "\e[38;5;196m2) Disable Tailscale Web UI\e[0m" # Red - echo -e "\e[38;5;27m3) Connect to Tailnet\e[0m" # Brown - echo -e "\e[38;5;87m4) Connect to Tailnet with SSH ON\e[0m" # Light cyan - echo -e "\e[38;5;105m5) Reconnect to Tailnet with SSH OFF\e[0m" # Light magenta - echo -e "\e[38;5;172m6) Disconnect from Tailnet (reconnects at reboot)\e[0m" # Light yellow - echo -e "\e[1;31m7) Logout from tailscale account\e[0m" - echo -e "\e[38;5;27m8) Return to Tailscale Menu\e[0m" - read -p "Enter your choice: " config_choice - - case $config_choice in - 1) - remount_rw - cd /lib/systemd/system/ - wget -O tailscale-webui.service $GITROOT/tailscale/systemd/tailscale-webui.service - wget -O tailscale-webui-trigger.service $GITROOT/tailscale/systemd/tailscale-webui-trigger.service - ln -sf /lib/systemd/system/tailscale-webui-trigger.service /lib/systemd/system/multi-user.target.wants/ - systemctl daemon-reload - echo "Tailscale Web UI Enabled" - echo "Starting Web UI..." - systemctl start tailscale-webui - echo "Web UI started!" - remount_ro - ;; - 2) - remount_rw - systemctl stop tailscale-webui - systemctl disable tailscale-webui-trigger - rm /lib/systemd/system/multi-user.target.wants/tailscale-webui.service - rm /lib/systemd/system/multi-user.target.wants/tailscale-webui-trigger.service - rm /lib/systemd/system/tailscale-webui.service - rm /lib/systemd/system/tailscale-webui-trigger.service - systemctl daemon-reload - echo "Tailscale Web UI Stopped and Disabled" - remount_ro - ;; - 3) $TAILSCALE_DIR/tailscale up --accept-dns=false --reset --accept-routes;; - 4) $TAILSCALE_DIR/tailscale up --ssh --accept-dns=false --reset --accept-routes;; - 5) $TAILSCALE_DIR/tailscale up --accept-dns=false --reset --accept-routes;; - 6) $TAILSCALE_DIR/tailscale down;; - 7) $TAILSCALE_DIR/tailscale logout;; - 8) break;; - *) echo "Invalid option";; - esac - done -} - -##################################################################### -# Tool Installation Functions -##################################################################### - -# Function to install OpenSSH Server -install_sshd() { - if [ -d "/usrdata/sshd" ]; then - echo -e "\e[1;31mSSHD is currently installed.\e[0m" - echo -e "Do you want to update or uninstall?" - echo -e "1.) Update" - echo -e "2.) Uninstall" - read -p "Select an option (1 or 2): " sshd_choice - - case $sshd_choice in - 1) - echo -e "\e[1;31m2) Installing sshd from the $GITTREE branch\e[0m" - ensure_entware_installed - mkdir /usrdata/simpleupdates > /dev/null 2>&1 - mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 - wget -O /usrdata/simpleupdates/scripts/update_sshd.sh $GITROOT/simpleupdates/scripts/update_sshd.sh && chmod +x /usrdata/simpleupdates/scripts/update_sshd.sh - echo -e "\e[1;32mUpdating: SSHd\e[0m" - echo -e "\e[1;32mPlease Wait....\e[0m" - /usrdata/simpleupdates/scripts/update_sshd.sh - echo -e "\e[1;32m SSHd has been updated.\e[0m" - ;; - 2) - echo -e "\e[1;31mUninstalling SSHD...\e[0m" - systemctl stop sshd - rm /lib/systemd/system/sshd.service - opkg remove openssh-server-pam - echo -e "\e[1;32mSSHD has been uninstalled successfully.\e[0m" - return 0 - ;; - *) - echo -e "\e[1;31mInvalid option. Please select 1 or 2.\e[0m" - return 1 - ;; - esac - fi - - # Proceed with installation if not installed - ensure_entware_installed - mkdir /usrdata/simpleupdates > /dev/null 2>&1 - mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 - wget -O /usrdata/simpleupdates/scripts/update_sshd.sh $GITROOT/simpleupdates/scripts/update_sshd.sh && chmod +x /usrdata/simpleupdates/scripts/update_sshd.sh - echo -e "\e[1;32mInstalling: SSHd\e[0m" - echo -e "\e[1;32mPlease Wait....\e[0m" - /usrdata/simpleupdates/scripts/update_sshd.sh - echo -e "\e[1;32m SSHd has been installed.\e[0m" -} - -# Function to install Speedtest CLI -install_speedtest_cli() { - ensure_entware_installed - echo -e "\e[1;32mInstalling Speedtest.net CLI (speedtest command)\e[0m" - remount_rw - mkdir /usrdata/root - mkdir /usrdata/root/bin - cd /usrdata/root/bin - wget https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-linux-armhf.tgz - tar -xzf ookla-speedtest-1.2.0-linux-armhf.tgz - rm ookla-speedtest-1.2.0-linux-armhf.tgz - rm speedtest.md - cd / - ln -sf /usrdata/root/bin/speedtest /bin - remount_ro - echo -e "\e[1;32mSpeedtest CLI (speedtest command) installed!!\e[0m" - echo -e "\e[1;32mTry running the command 'speedtest'\e[0m" - echo -e "\e[1;32mNote that it will not work unless you login to the root account first\e[0m" - echo -e "\e[1;32mNormaly only an issue in adb, ttyd and ssh you are forced to login\e[0m" - echo -e "\e[1;32mIf in adb just type login and then try to run the speedtest command\e[0m" -} - -# Function to install Fast.com CLI -install_fast_cli() { - echo -e "\e[1;32mInstalling fast.com CLI (fast command)\e[0m" - remount_rw - mkdir /usrdata/root - mkdir /usrdata/root/bin - cd /usrdata/root/bin - wget -O fast https://code.060070.xyz/sky/simple-admin/raw/branch/main/tools/fast_linux_arm && chmod +x fast - cd / - ln -sf /usrdata/root/bin/fast /bin - remount_ro - echo -e "\e[1;32mFast.com CLI (speedtest command) installed!!\e[0m" - echo -e "\e[1;32mTry running the command 'fast'\e[0m" - echo -e "\e[1;32mThe fast.com test tops out at 40Mbps on the modem\e[0m" -} - -##################################################################### -# AT Command Bridge Functions -##################################################################### - -# Function to install/update AT command socat bridge -install_update_at_socat() { - local current_dir=$(pwd) - ensure_entware_installed - mkdir /usrdata/simpleupdates > /dev/null 2>&1 - mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 - wget -O /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh $GITROOT/simpleupdates/scripts/update_socat-at-bridge.sh && chmod +x /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh - echo -e "\e[1;32mInstalling/updating: AT Socat Bridge\e[0m" - echo -e "\e[1;32mPlease Wait....\e[0m" - /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh - echo -e "\e[1;32mAT Socat Bridge has been updated/installed.\e[0m" - cd "$current_dir" -} - -##################################################################### -# Firewall Functions -##################################################################### - -# Function to install Simple Firewall -install_simple_firewall() { - ensure_entware_installed - mkdir /usrdata/simpleupdates > /dev/null 2>&1 - mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 - wget -O /usrdata/simpleupdates/scripts/update_simplefirewall.sh $GITROOT/simpleupdates/scripts/update_simplefirewall.sh && chmod +x /usrdata/simpleupdates/scripts/update_simplefirewall.sh - echo -e "\e[1;32mInstalling/updating: Simple Firewall\e[0m" - echo -e "\e[1;32mPlease Wait....\e[0m" - /usrdata/simpleupdates/scripts/update_simplefirewall.sh - echo -e "\e[1;32mSimple Firewall has been updated/installed.\e[0m" -} - -##################################################################### -# Main Menu and Program Flow -##################################################################### - -# Check system architecture and proceed accordingly -check_architecture() { - ARCH=$(uname -a) - if echo "$ARCH" | grep -q "aarch64"; then - cd /tmp && wget -O RM55x_rcPCIe_toolkit.sh https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/SDXPINN/RM55x_rcPCIe_toolkit.sh && chmod +x RM55x_rcPCIe_toolkit.sh && ./RM55x_rcPCIe_toolkit.sh && cd / - exit 0 - elif echo "$ARCH" | grep -q "armv7l"; then - # Continue if architecture is armv7l - echo "Architecture is armv7l, continuing..." - else - uname -a - echo "Unsupported architecture." - exit 1 - fi -} - -# Display the main menu -display_main_menu() { - echo "//////////////////////////////////////////////////////////////////" - echo "// //" - echo "// //" - echo "// :'######::'####:'##::::'##:'########::'##:::::::'########: //" - echo "// '##... ##:. ##:: ###::'###: ##.... ##: ##::::::: ##.....:: //" - echo "// ##:::..::: ##:: ####'####: ##:::: ##: ##::::::: ##::::::: //" - echo "// . ######::: ##:: ## ### ##: ########:: ##::::::: ######::: //" - echo "// :..... ##:: ##:: ##. #: ##: ##.....::: ##::::::: ##...:::: //" - echo "// '##::: ##:: ##:: ##:.:: ##: ##:::::::: ##::::::: ##::::::: //" - echo "// . ######::'####: ##:::: ##: ##:::::::: ########: ########: //" - echo "// :......:::....::..:::::..::..:::::::::........::........:: //" - echo "// :::'###::::'########::'##::::'##:'####:'##::: ##: //" - echo "// ::'## ##::: ##.... ##: ###::'###:. ##:: ###:: ##: //" - echo "// :'##:. ##:: ##:::: ##: ####'####:: ##:: ####: ##: //" - echo "// '##:::. ##: ##:::: ##: ## ### ##:: ##:: ## ## ##: //" - echo "// #########: ##:::: ##: ##. #: ##:: ##:: ##. ####: //" - echo "// ##.... ##: ##:::: ##: ##:.:: ##:: ##:: ##:. ###: //" - echo "// ##:::: ##: ########:: ##:::: ##:'####: ##::. ##: //" - echo "// ..:::::..::........:::..:::::..::....::..::::..:: //" - echo "// //" - echo "// By iamromulan //" - echo "//////////////////////////////////////////////////////////////////" - - echo -e "\e[92m" - echo "Welcome to iamromulan's RGMII Toolkit script for Quectel RMxxx Series modems!" - echo "Visit https://github.com/iamromulan for more!" - echo -e "\e[0m" - echo "Select an option:" - echo -e "\e[0m" - echo -e "\e[96m1) Send AT Commands\e[0m" # Cyan - echo -e "\e[93m2) Install Simple Admin\e[0m" # Yellow - echo -e "\e[95m3) Set Simpleadmin (admin) password\e[0m" # Light Purple - echo -e "\e[94m4) Set Console/ttyd (root) password\e[0m" # Light Blue - echo -e "\e[91m5) Uninstall Simple Admin\e[0m" # Light Red - echo -e "\e[95m6) Simple Firewall Management\e[0m" # Light Purple - echo -e "\e[94m7) Tailscale Management\e[0m" # Light Blue - echo -e "\e[92m8) Install/Change or remove Daily Reboot Timer\e[0m" # Light Green - echo -e "\e[96m9) Install/Uninstall CFUN 0 Fix\e[0m" # Cyan - echo -e "\e[91m10) Uninstall Entware/OPKG\e[0m" # Light Red - echo -e "\e[92m11) Install Speedtest.net CLI app (speedtest command)\e[0m" # Light Green - echo -e "\e[92m12) Install Fast.com CLI app (fast command)(tops out at 40Mbps)\e[0m" # Light Green - echo -e "\e[92m13) Install OpenSSH Server\e[0m" # Light Green - echo -e "\e[93m14) Exit\e[0m" # Yellow -} - -# Main program loop -main() { - check_architecture - - while true; do - display_main_menu - read -p "Enter your choice: " choice - - case $choice in - 1) send_at_commands;; - 2) install_simple_admin;; - 3) set_simpleadmin_passwd;; - 4) set_root_passwd;; - 5) uninstall_simpleadmin_components;; - 6) configure_simple_firewall;; - 7) tailscale_menu;; - 8) manage_reboot_timer;; - 9) manage_cfun_fix;; - 10) - echo -e "\033[31mAre you sure you want to uninstall entware?\033[0m" - echo -e "\033[31m1) Yes\033[0m" - echo -e "\033[31m2) No\033[0m" - read -p "Select an option (1 or 2): " user_choice - - case $user_choice in - 1) - echo -e "\033[31mUninstalling existing entware...\033[0m" - uninstall_entware - echo -e "\033[31mEntware has been uninstalled.\033[0m" - ;; - 2) - echo -e "\033[31mUninstallation cancelled.\033[0m" - exit - ;; - *) - echo -e "\033[31mInvalid option. Please select 1 or 2.\033[0m" - ;; - esac - ;; - 11) install_speedtest_cli;; - 12) install_fast_cli;; - 13) install_sshd;; - 14) - echo -e "\e[1;32mGoodbye!\e[0m" - break - ;; - *) - echo -e "\e[1;31mInvalid option\e[0m" - ;; - esac - done -} - -# Start the program -main -- 2.45.2 From 0633a7eea475a4626a96a115015f233c23dd7b3d Mon Sep 17 00:00:00 2001 From: sky Date: Thu, 12 Dec 2024 04:15:10 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20RMxxx=5Frgmii=5Ftool?= =?UTF-8?q?kit=5Fdev.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RMxxx_rgmii_toolkit_dev.sh | 1039 ++++++++++++++++++++++++++++++++++++ 1 file changed, 1039 insertions(+) create mode 100644 RMxxx_rgmii_toolkit_dev.sh diff --git a/RMxxx_rgmii_toolkit_dev.sh b/RMxxx_rgmii_toolkit_dev.sh new file mode 100644 index 0000000..547cfb8 --- /dev/null +++ b/RMxxx_rgmii_toolkit_dev.sh @@ -0,0 +1,1039 @@ +#!/bin/sh + +##################################################################### +# RMxxx RGMII Toolkit +# Author: iamromulan +# Description: Toolkit for Quectel RMxxx Series modems +# Repository: https://github.com/iamromulan +##################################################################### + +##################################################################### +# Environment Configuration +##################################################################### + +# Define toolkit paths +export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:/usrdata/root/bin + +# Define Gitea repository configuration +GITEA_HOST="code.example.com" +GITUSER="sky" +REPONAME="simple-admin" +GITTREE="main" +GITMAINTREE="main" +GITDEVTREE="dev" + +# Construct Gitea URLs +# Format: https://[host]/[user]/[repo]/raw/branch/[branch]/[file] +GITROOT="https://$GITEA_HOST/$GITUSER/$REPONAME/raw/branch/$GITTREE" +GITROOTMAIN="https://$GITEA_HOST/$GITUSER/$REPONAME/raw/branch/$GITMAINTREE" +GITROOTDEV="https://$GITEA_HOST/$GITUSER/$REPONAME/raw/branch/$GITDEVTREE" + +##################################################################### +# Directory Configuration +##################################################################### + +# System directories +TMP_DIR="/tmp" +USRDATA_DIR="/usrdata" + +# Application directories +SOCAT_AT_DIR="/usrdata/socat-at-bridge" +SOCAT_AT_SYSD_DIR="/usrdata/socat-at-bridge/systemd_units" +SIMPLE_ADMIN_DIR="/usrdata/simpleadmin" +SIMPLE_FIREWALL_DIR="/usrdata/simplefirewall" +SIMPLE_FIREWALL_SCRIPT="$SIMPLE_FIREWALL_DIR/simplefirewall.sh" +SIMPLE_FIREWALL_SYSTEMD_DIR="$SIMPLE_FIREWALL_DIR/systemd" +TAILSCALE_DIR="/usrdata/tailscale" +TAILSCALE_SYSD_DIR="/usrdata/tailscale/systemd" +LIGHTTPD_DIR="/usrdata/lighttpd" + +# AT Command configuration +DEVICE_FILE="/dev/smd7" +TIMEOUT=4 # Set a timeout for the response + +##################################################################### +# Basic Utility Functions +##################################################################### + +# Function to remount file system as read-write +remount_rw() { + mount -o remount,rw / +} + +# Function to remount file system as read-only +remount_ro() { + mount -o remount,ro / +} + +##################################################################### +# AT Command Functions +##################################################################### + +# Basic AT commands without socat bridge for fast response commands only +start_listening() { + cat "$DEVICE_FILE" > /tmp/device_readout & + CAT_PID=$! +} + +send_at_command() { + echo -e "\e[1;31mThis only works for basic quick responding commands!\e[0m" # Red + echo -e "\e[1;36mType 'install' to simply type atcmd in shell from now on\e[0m" + echo -e "\e[1;36mThe installed version is much better than this portable version\e[0m" + echo -e "\e[1;32mEnter AT command (or type 'exit' to quit): \e[0m" + read at_command + if [ "$at_command" = "exit" ]; then + return 1 + fi + + if [ "$at_command" = "install" ]; then + install_update_at_socat + echo -e "\e[1;32mInstalled. Type atcmd from adb shell or ssh to start an AT Command session\e[0m" + return 1 + fi + echo -e "${at_command}\r" > "$DEVICE_FILE" +} + +wait_for_response() { + local start_time=$(date +%s) + local current_time + local elapsed_time + + echo -e "\e[1;32mCommand sent, waiting for response...\e[0m" + while true; do + if grep -qe "OK" -e "ERROR" /tmp/device_readout; then + echo -e "\e[1;32mResponse received:\e[0m" + cat /tmp/device_readout + return 0 + fi + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) + if [ "$elapsed_time" -ge "$TIMEOUT" ]; then + echo -e "\e[1;31mError: Response timed out.\e[0m" # Red + echo -e "\e[1;32mIf the responce takes longer than a second or 2 to respond this will not work\e[0m" # Green + echo -e "\e[1;36mType install to install the better version of this that will work.\e[0m" # Cyan + return 1 + fi + sleep 1 + done +} + +cleanup() { + kill "$CAT_PID" + wait "$CAT_PID" 2>/dev/null + rm -f /tmp/device_readout +} + +send_at_commands() { + if [ -c "$DEVICE_FILE" ]; then + while true; do + start_listening + send_at_command + if [ $? -eq 1 ]; then + cleanup + break + fi + wait_for_response + cleanup + done + else + echo -e "\e[1;31mError: Device $DEVICE_FILE does not exist!\e[0m" + fi +} + +##################################################################### +# Installation and Package Management Functions +##################################################################### + +# Check for existing Entware/opkg installation, install if not installed +ensure_entware_installed() { + remount_rw + if [ ! -f "/opt/bin/opkg" ]; then + echo -e "\e[1;32mInstalling Entware/OPKG\e[0m" + cd /tmp && wget -O installentware.sh "$GITROOT/installentware.sh" && chmod +x installentware.sh && ./installentware.sh + if [ "$?" -ne 0 ]; then + echo -e "\e[1;31mEntware/OPKG installation failed. Please check your internet connection or the repository URL.\e[0m" + exit 1 + fi + cd / + else + echo -e "\e[1;32mEntware/OPKG is already installed.\e[0m" + if [ "$(readlink /bin/login)" != "/opt/bin/login" ]; then + opkg update && opkg install shadow-login shadow-passwd shadow-useradd + if [ "$?" -ne 0 ]; then + echo -e "\e[1;31mPackage installation failed. Please check your internet connection and try again.\e[0m" + exit 1 + fi + + # Replace the login and passwd binaries and set home for root to a writable directory + rm /opt/etc/shadow + rm /opt/etc/passwd + cp /etc/shadow /opt/etc/ + cp /etc/passwd /opt/etc + mkdir -p /usrdata/root/bin + touch /usrdata/root/.profile + echo "# Set PATH for all shells" > /usrdata/root/.profile + echo "export PATH=/bin:/usr/sbin:/usr/bin:/sbin:/opt/sbin:/opt/bin:/usrdata/root/bin" >> /usrdata/root/.profile + chmod +x /usrdata/root/.profile + sed -i '1s|/home/root:/bin/sh|/usrdata/root:/bin/bash|' /opt/etc/passwd + rm /bin/login /usr/bin/passwd + ln -sf /opt/bin/login /bin + ln -sf /opt/bin/passwd /usr/bin/ + ln -sf /opt/bin/useradd /usr/bin/ + echo -e "\e[1;31mPlease set the root password.\e[0m" + /opt/bin/passwd + + # Install basic and useful utilities + opkg install mc htop dfc lsof + ln -sf /opt/bin/mc /bin + ln -sf /opt/bin/htop /bin + ln -sf /opt/bin/dfc /bin + ln -sf /opt/bin/lsof /bin + fi + + if [ ! -f "/usrdata/root/.profile" ]; then + opkg update && opkg install shadow-useradd + mkdir -p /usrdata/root/bin + touch /usrdata/root/.profile + echo "# Set PATH for all shells" > /usrdata/root/.profile + echo "export PATH=/bin:/usr/sbin:/usr/bin:/sbin:/opt/sbin:/opt/bin:/usrdata/root/bin" >> /usrdata/root/.profile + chmod +x /usrdata/root/.profile + sed -i '1s|/home/root:/bin/sh|/usrdata/root:/bin/bash|' /opt/etc/passwd + fi + fi + if [ ! -f "/opt/sbin/useradd" ]; then + echo "useradd does not exist. Installing shadow-useradd..." + opkg install shadow-useradd + else + echo "useradd already exists. Continuing..." + fi + + if [ ! -f "/usr/bin/curl" ] && [ ! -f "/opt/bin/curl" ]; then + echo "curl does not exist. Installing curl..." + opkg update && opkg install curl + if [ "$?" -ne 0 ]; then + echo -e "\e[1;31mFailed to install curl. Please check your internet connection and try again.\e[0m" + exit 1 + fi + else + echo "curl already exists. Continuing..." + fi +} + +# Uninstall Entware if the Users chooses +uninstall_entware() { + echo -e '\033[31mInfo: Starting Entware/OPKG uninstallation...\033[0m' + + # Stop services + systemctl stop rc.unslung.service + /opt/etc/init.d/rc.unslung stop + rm /lib/systemd/system/multi-user.target.wants/rc.unslung.service + rm /lib/systemd/system/rc.unslung.service + + systemctl stop opt.mount + rm /lib/systemd/system/multi-user.target.wants/start-opt-mount.service + rm /lib/systemd/system/opt.mount + rm /lib/systemd/system/start-opt-mount.service + + # Unmount /opt if mounted + mountpoint -q /opt && umount /opt + + # Remove Entware installation directory + rm -rf /usrdata/opt + rm -rf /opt + + # Reload systemctl daemon + systemctl daemon-reload + + # Optionally, clean up any modifications to /etc/profile or other system files + # Restore original link to login binary compiled by Quectel + rm /bin/login + ln /bin/login.shadow /bin/login + + echo -e '\033[32mInfo: Entware/OPKG has been uninstalled successfully.\033[0m' +} + +##################################################################### +# System Service and Configuration Functions +##################################################################### + +# Function to manage Daily Reboot Timer +manage_reboot_timer() { + # Remount root filesystem as read-write + mount -o remount,rw / + + # Check if the rebootmodem service, timer, or trigger already exists + if [ -f /lib/systemd/system/rebootmodem.service ] || [ -f /lib/systemd/system/rebootmodem.timer ] || [ -f /lib/systemd/system/rebootmodem-trigger.service ]; then + echo -e "\e[1;32mThe rebootmodem service/timer/trigger is already installed.\e[0m" + echo -e "\e[1;32m1) Change\e[0m" # Green + echo -e "\e[1;31m2) Remove\e[0m" # Red + read -p "Enter your choice (1 for Change, 2 for Remove): " reboot_choice + + case $reboot_choice in + 2) + # Stop and disable timer and trigger service by removing symlinks + systemctl stop rebootmodem.timer + systemctl stop rebootmodem-trigger.service + + # Remove symbolic links and files + rm -f /lib/systemd/system/multi-user.target.wants/rebootmodem-trigger.service + rm -f /lib/systemd/system/rebootmodem.service + rm -f /lib/systemd/system/rebootmodem.timer + rm -f /lib/systemd/system/rebootmodem-trigger.service + rm -f "$USRDATA_DIR/reboot_modem.sh" + + # Reload systemd to apply changes + systemctl daemon-reload + + echo -e "\e[1;32mRebootmodem service, timer, trigger, and script removed successfully.\e[0m" + ;; + 1) + printf "Enter the new time for daily reboot (24-hour format in Coordinated Universal Time, HH:MM): " + read new_time + + # Validate the new time format using grep + if ! echo "$new_time" | grep -qE '^([01]?[0-9]|2[0-3]):[0-5][0-9]$'; then + echo "Invalid time format. Exiting." + exit 1 + else + # Remove old symlinks and script + rm -f /lib/systemd/system/multi-user.target.wants/rebootmodem-trigger.service + rm -f "$USRDATA_DIR/reboot_modem.sh" + + # Set the user time to the new time and recreate the service, timer, trigger, and script + user_time=$new_time + create_service_and_timer + fi + ;; + *) + echo -e "\e[1;31mInvalid choice. Exiting.\e[0m" + exit 1 + ;; + esac + else + printf "Enter the time for daily reboot (24-hour format in UTC, HH:MM): " + read user_time + + # Validate the time format using grep + if ! echo "$user_time" | grep -qE '^([01]?[0-9]|2[0-3]):[0-5][0-9]$'; then + echo "Invalid time format. Exiting." + exit 1 + else + create_service_and_timer + fi + fi + + # Remount root filesystem as read-only + mount -o remount,ro / +} + +# Function to create systemd service and timer files +create_service_and_timer() { + remount_rw + # Define the path for the modem reboot script + MODEM_REBOOT_SCRIPT="$USRDATA_DIR/reboot_modem.sh" + + # Create the modem reboot script + echo "#!/bin/sh +/bin/echo -e 'AT+CFUN=1,1 \r' > /dev/smd7" > "$MODEM_REBOOT_SCRIPT" + + # Make the script executable + chmod +x "$MODEM_REBOOT_SCRIPT" + + # Create the systemd service file for reboot + echo "[Unit] +Description=Reboot Modem Daily + +[Service] +Type=oneshot +ExecStart=/bin/sh /usrdata/reboot_modem.sh +Restart=no +RemainAfterExit=no" > /lib/systemd/system/rebootmodem.service + + # Create the systemd timer file with the user-specified time + echo "[Unit] +Description=Starts rebootmodem.service daily at the specified time + +[Timer] +OnCalendar=*-*-* $user_time:00 +Persistent=false" > /lib/systemd/system/rebootmodem.timer + + # Create a trigger service that starts the timer at boot + echo "[Unit] +Description=Trigger the rebootmodem timer at boot + +[Service] +Type=oneshot +ExecStart=/bin/systemctl start rebootmodem.timer +RemainAfterExit=yes" > /lib/systemd/system/rebootmodem-trigger.service + + # Create symbolic links for the trigger service in the wanted directory + ln -sf /lib/systemd/system/rebootmodem-trigger.service /lib/systemd/system/multi-user.target.wants/ + + # Reload systemd to recognize the new timer and trigger service + systemctl daemon-reload + sleep 2s + + # Start the trigger service, which will start the timer + systemctl start rebootmodem-trigger.service + remount_ro + + # Confirmation + echo -e "\e[1;32mRebootmodem-trigger service created and started successfully.\e[0m" + echo -e "\e[1;32mReboot schedule set successfully. The modem will reboot daily at $user_time UTC.\e[0m" +} + +# Function to manage CFUN fix +manage_cfun_fix() { + cfun_service_path="/lib/systemd/system/cfunfix.service" + cfun_fix_script="/usrdata/cfun_fix.sh" + + mount -o remount,rw / + + if [ -f "$cfun_service_path" ]; then + echo -e "\e[1;32mThe CFUN fix is already installed. Do you want to remove it?\e[0m" # Green + echo -e "\e[1;32m1) Yes\e[0m" # Green + echo -e "\e[1;31m2) No\e[0m" # Red + read -p "Enter your choice: " choice + + if [ "$choice" = "1" ]; then + echo "Removing CFUN fix..." + systemctl stop cfunfix.service + rm -f /lib/systemd/system/multi-user.target.wants/cfunfix.service + rm -f "$cfun_service_path" + rm -f "$cfun_fix_script" + systemctl daemon-reload + echo "CFUN fix has been removed." + else + echo "Returning to main menu..." + fi + else + echo -e "\e[1;32mInstalling CFUN fix...\e[0m" + + # Create the CFUN fix script + echo "#!/bin/sh +/bin/echo -e 'AT+CFUN=1 \r' > /dev/smd7" > "$cfun_fix_script" + chmod +x "$cfun_fix_script" + + # Create the systemd service file to execute the CFUN fix script at boot + echo "[Unit] +Description=CFUN Fix Service +After=network.target + +[Service] +Type=oneshot +ExecStart=$cfun_fix_script +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target" > "$cfun_service_path" + + ln -sf "$cfun_service_path" "/lib/systemd/system/multi-user.target.wants/" + systemctl daemon-reload + mount -o remount,ro / + echo -e "\e[1;32mCFUN fix has been installed and will execute at every boot.\e[0m" + fi +} + +##################################################################### +# SimpleAdmin Functions +##################################################################### + +# Function to set SimpleAdmin password +set_simpleadmin_passwd(){ + ensure_entware_installed + opkg update + opkg install libaprutil + wget -O /usrdata/root/bin/htpasswd $GITROOT/simpleadmin/htpasswd && chmod +x /usrdata/root/bin/htpasswd + wget -O /usrdata/root/bin/simplepasswd $GITROOT/simpleadmin/simplepasswd && chmod +x /usrdata/root/bin/simplepasswd + echo -e "\e[1;32mTo change your simpleadmin (admin) password in the future...\e[0m" + echo -e "\e[1;32mIn the console type simplepasswd and press enter\e[0m" + /usrdata/root/bin/simplepasswd +} + +# Function to set root password +set_root_passwd() { + echo -e "\e[1;31mPlease set the root/console password.\e[0m" + /opt/bin/passwd +} + +# Function to install/update Simple Admin +install_simple_admin() { + echo -e "\e[1;32mInstalling Simpleadmin 2.0\e[0m" + ensure_entware_installed + echo -e "\e[1;31m2) Installing Simpleadmin 2.0\e[0m" + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh $GITROOT/simpleupdates/scripts/update_socat-at-bridge.sh && chmod +x /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh + echo -e "\e[1;32mInstalling/updating dependency: socat-at-bridge\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh + echo -e "\e[1;32m Dependency: socat-at-bridge has been updated/installed.\e[0m" + sleep 1 + wget -O /usrdata/simpleupdates/scripts/update_simplefirewall.sh $GITROOT/simpleupdates/scripts/update_simplefirewall.sh && chmod +x /usrdata/simpleupdates/scripts/update_simplefirewall.sh + echo -e "\e[1;32mInstalling/updating dependency: simplefirewall\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_simplefirewall.sh + echo -e "\e[1;32m Dependency: simplefirewall has been updated/installed.\e[0m" + sleep 1 + set_simpleadmin_passwd + wget -O /usrdata/simpleupdates/scripts/update_simpleadmin.sh $GITROOT/simpleupdates/scripts/update_simpleadmin.sh && chmod +x /usrdata/simpleupdates/scripts/update_simpleadmin.sh + echo -e "\e[1;32mInstalling/updating: Simpleadmin content\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_simpleadmin.sh + echo -e "\e[1;32mSimpleadmin content has been updated/installed.\e[0m" + sleep 1 +} + +# Function to configure Simple Firewall +configure_simple_firewall() { + if [ ! -f "$SIMPLE_FIREWALL_SCRIPT" ]; then + echo -e "\033[0;31mSimplefirewall is not installed, would you like to install it?\033[0m" + echo -e "\033[0;32m1) Yes\033[0m" + echo -e "\033[0;31m2) No\033[0m" + read -p "Enter your choice (1-2): " install_choice + + case $install_choice in + 1) + install_simple_firewall + ;; + 2) + return + ;; + *) + echo -e "\033[0;31mInvalid choice. Please select either 1 or 2.\033[0m" + ;; + esac + fi + + echo -e "\e[1;32mConfigure Simple Firewall:\e[0m" + echo -e "\e[38;5;208m1) Configure incoming port block\e[0m" + echo -e "\e[38;5;27m2) Configure TTL\e[0m" + read -p "Enter your choice (1-2): " menu_choice + + case $menu_choice in + 1) + # Original ports configuration code with exit option + current_ports_line=$(grep '^PORTS=' "$SIMPLE_FIREWALL_SCRIPT") + ports=$(echo "$current_ports_line" | cut -d'=' -f2 | tr -d '()' | tr ' ' '\n' | grep -o '[0-9]\+') + echo -e "\e[1;32mCurrent configured ports:\e[0m" + echo "$ports" | awk '{print NR") "$0}' + + while true; do + echo -e "\e[1;32mEnter a port number to add/remove, or type 'done' or 'exit' to finish:\e[0m" + read port + if [ "$port" = "done" ] || [ "$port" = "exit" ]; then + if [ "$port" = "exit" ]; then + echo -e "\e[1;31mExiting without making changes...\e[0m" + return + fi + break + elif ! echo "$port" | grep -qE '^[0-9]+$'; then + echo -e "\e[1;31mInvalid input: Please enter a numeric value.\e[0m" + elif echo "$ports" | grep -q "^$port\$"; then + ports=$(echo "$ports" | grep -v "^$port\$") + echo -e "\e[1;32mPort $port removed.\e[0m" + else + ports=$(echo "$ports"; echo "$port" | grep -o '[0-9]\+') + echo -e "\e[1;32mPort $port added.\e[0m" + fi + done + + if [ "$port" != "exit" ]; then + new_ports_line="PORTS=($(echo "$ports" | tr '\n' ' '))" + sed -i "s/$current_ports_line/$new_ports_line/" "$SIMPLE_FIREWALL_SCRIPT" + fi + ;; + 2) + # TTL configuration code + ttl_value=$(cat /usrdata/simplefirewall/ttlvalue) + if [ "$ttl_value" -eq 0 ]; then + echo -e "\e[1;31mTTL is not set.\e[0m" + else + echo -e "\e[1;32mTTL value is set to $ttl_value.\e[0m" + fi + + echo -e "\e[1;31mType 'exit' to cancel.\e[0m" + read -p "What do you want the TTL value to be: " new_ttl_value + if [ "$new_ttl_value" = "exit" ]; then + echo -e "\e[1;31mExiting TTL configuration...\e[0m" + return + elif ! echo "$new_ttl_value" | grep -qE '^[0-9]+$'; then + echo -e "\e[1;31mInvalid input: Please enter a numeric value.\e[0m" + return + else + /usrdata/simplefirewall/ttl-override stop + echo "$new_ttl_value" > /usrdata/simplefirewall/ttlvalue + /usrdata/simplefirewall/ttl-override start + echo -e "\033[0;32mTTL value updated to $new_ttl_value.\033[0m" + fi + ;; + *) + echo -e "\e[1;31mInvalid choice. Please select either 1 or 2.\e[0m" + ;; + esac + + systemctl restart simplefirewall + echo -e "\e[1;32mFirewall configuration updated.\e[0m" +} + +# Function to Uninstall Simpleadmin and dependencies +uninstall_simpleadmin_components() { + echo -e "\e[1;32mStarting the uninstallation process for Simpleadmin components.\e[0m" + echo -e "\e[1;32mNote: Uninstalling certain components may affect the functionality of others.\e[0m" + remount_rw + + # Uninstall Simple Firewall + echo -e "\e[1;32mDo you want to uninstall Simplefirewall?\e[0m" + echo -e "\e[1;31mIf you do, the TTL part of simpleadmin will no longer work.\e[0m" + echo -e "\e[1;32m1) Yes\e[0m" + echo -e "\e[1;31m2) No\e[0m" + read -p "Enter your choice (1 or 2): " choice_simplefirewall + if [ "$choice_simplefirewall" -eq 1 ]; then + echo "Uninstalling Simplefirewall..." + systemctl stop simplefirewall + systemctl stop ttl-override + rm -f /lib/systemd/system/simplefirewall.service + rm -f /lib/systemd/system/ttl-override.service + systemctl daemon-reload + rm -rf "$SIMPLE_FIREWALL_DIR" + echo "Simplefirewall uninstalled." + fi + + # Uninstall socat-at-bridge + echo -e "\e[1;32mDo you want to uninstall socat-at-bridge?\e[0m" + echo -e "\e[1;31mIf you do, AT commands and the stat page will no longer work. atcmd won't either.\e[0m" + echo -e "\e[1;32m1) Yes\e[0m" + echo -e "\e[1;31m2) No\e[0m" + read -p "Enter your choice (1 or 2): " choice_socat_at_bridge + if [ "$choice_socat_at_bridge" -eq 1 ]; then + echo -e "\033[0;32mRemoving installed AT Socat Bridge services...\033[0m" + systemctl stop at-telnet-daemon > /dev/null 2>&1 + systemctl disable at-telnet-daemon > /dev/null 2>&1 + systemctl stop socat-smd11 > /dev/null 2>&1 + systemctl stop socat-smd11-to-ttyIN > /dev/null 2>&1 + systemctl stop socat-smd11-from-ttyIN > /dev/null 2>&1 + systemctl stop socat-smd7 > /dev/null 2>&1 + systemctl stop socat-smd7-to-ttyIN2 > /dev/null 2>&1 + systemctl stop socat-smd7-to-ttyIN > /dev/null 2>&1 + systemctl stop socat-smd7-from-ttyIN2 > /dev/null 2>&1 + systemctl stop socat-smd7-from-ttyIN > /dev/null 2>&1 + rm /lib/systemd/system/at-telnet-daemon.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd11.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd11-to-ttyIN.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd11-from-ttyIN.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd7.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd7-to-ttyIN2.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd7-to-ttyIN.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd7-from-ttyIN.service > /dev/null 2>&1 + rm /lib/systemd/system/socat-smd7-from-ttyIN2.service > /dev/null 2>&1 + systemctl daemon-reload > /dev/null 2>&1 + rm -rf "$SOCAT_AT_DIR" > /dev/null 2>&1 + rm -rf "$SOCAT_AT_DIR" > /dev/null 2>&1 + rm -rf "/usrdata/micropython" > /dev/null 2>&1 + rm -rf "/usrdata/at-telnet" > /dev/null 2>&1 + echo -e "\033[0;32mAT Socat Bridge services removed!...\033[0m" + fi + + # Uninstall ttyd + echo -e "\e[1;32mDo you want to uninstall ttyd (simpleadmin console)?\e[0m" + echo -e "\e[1;31mWarning: Do not uninstall if you are currently using ttyd to do this!!!\e[0m" + echo -e "\e[1;32m1) Yes\e[0m" + echo -e "\e[1;31m2) No\e[0m" + read -p "Enter your choice (1 or 2): " choice_simpleadmin + if [ "$choice_simpleadmin" -eq 1 ]; then + echo -e "\e[1;34mUninstalling ttyd...\e[0m" + systemctl stop ttyd + rm -rf /usrdata/ttyd + rm /lib/systemd/system/ttyd.service + rm /lib/systemd/system/multi-user.target.wants/ttyd.service + rm /bin/ttyd + echo -e "\e[1;32mttyd has been uninstalled.\e[0m" + fi + + echo "Uninstalling the rest of Simpleadmin..." + + # Check if Lighttpd service is installed and remove it if present + if [ -f "/lib/systemd/system/lighttpd.service" ]; then + echo "Lighttpd detected, uninstalling Lighttpd and its modules..." + systemctl stop lighttpd + opkg --force-remove --force-removal-of-dependent-packages remove lighttpd-mod-authn_file lighttpd-mod-auth lighttpd-mod-cgi lighttpd-mod-openssl lighttpd-mod-proxy lighttpd + rm -rf $LIGHTTPD_DIR + fi + + systemctl stop simpleadmin_generate_status + systemctl stop simpleadmin_httpd + rm -f /lib/systemd/system/simpleadmin_httpd.service + rm -f /lib/systemd/system/simpleadmin_generate_status.service + systemctl daemon-reload + rm -rf "$SIMPLE_ADMIN_DIR" + echo "The rest of Simpleadmin and Lighttpd (if present) uninstalled." + remount_ro + + echo "Uninstallation process completed." +} + +##################################################################### +# Tailscale Management Functions +##################################################################### + +# Function for Tailscale Submenu +tailscale_menu() { + while true; do + echo -e "\e[1;32mTailscale Menu\e[0m" + echo -e "\e[1;32m1) Install/Update Tailscale\e[0m" + echo -e "\e[1;36m2) Configure Tailscale\e[0m" + echo -e "\e[1;31m3) Uninstall Tailscale\e[0m" + echo -e "\e[1;93m4) Return to Main Menu\e[0m" + read -p "Enter your choice: " tailscale_choice + + case $tailscale_choice in + 1) install_update_tailscale;; + 2) configure_tailscale;; + 3) uninstall_tailscale;; + 4) break;; + *) echo "Invalid option";; + esac + done +} + +# Function to install or update Tailscale +install_update_tailscale() { + echo -e "\e[1;31m2) Installing tailscale from the $GITTREE branch\e[0m" + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_tailscale.sh $GITROOT/simpleupdates/scripts/update_tailscale.sh && chmod +x /usrdata/simpleupdates/scripts/update_tailscale.sh + echo -e "\e[1;32mInstalling/updating: Tailscale\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + remount_rw + /usrdata/simpleupdates/scripts/update_tailscale.sh + echo -e "\e[1;32m Tailscale has been updated/installed.\e[0m" +} + +# Function to uninstall Tailscale +uninstall_tailscale() { + echo -e "\e[1;31mUninstalling Tailscale...\e[0m" + + # Stop and logout from Tailscale + if [ -f "/usrdata/tailscale/tailscale" ]; then + /usrdata/tailscale/tailscale logout + /usrdata/tailscale/tailscale down + fi + + # Stop services + systemctl stop tailscale 2>/dev/null + systemctl stop tailscale-webui 2>/dev/null + + # Remove service files + rm -f /lib/systemd/system/tailscale.service + rm -f /lib/systemd/system/tailscale-webui.service + rm -f /lib/systemd/system/tailscale-webui-trigger.service + rm -f /lib/systemd/system/multi-user.target.wants/tailscale-webui-trigger.service + + # Remove Tailscale files and directories + rm -rf /usrdata/tailscale + rm -f /bin/tailscale + rm -f /bin/tailscaled + + # Reload systemd + systemctl daemon-reload + + echo -e "\e[1;32mTailscale has been uninstalled.\e[0m" +} + +# Function to Configure Tailscale +configure_tailscale() { + while true; do + echo "Configure Tailscale" + echo -e "\e[38;5;40m1) Enable Tailscale Web UI at http://192.168.225.1:8088 (Gateway on port 8088)\e[0m" # Green + echo -e "\e[38;5;196m2) Disable Tailscale Web UI\e[0m" # Red + echo -e "\e[38;5;27m3) Connect to Tailnet\e[0m" # Brown + echo -e "\e[38;5;87m4) Connect to Tailnet with SSH ON\e[0m" # Light cyan + echo -e "\e[38;5;105m5) Reconnect to Tailnet with SSH OFF\e[0m" # Light magenta + echo -e "\e[38;5;172m6) Disconnect from Tailnet (reconnects at reboot)\e[0m" # Light yellow + echo -e "\e[1;31m7) Logout from tailscale account\e[0m" + echo -e "\e[38;5;27m8) Return to Tailscale Menu\e[0m" + read -p "Enter your choice: " config_choice + + case $config_choice in + 1) + remount_rw + cd /lib/systemd/system/ + wget -O tailscale-webui.service $GITROOT/tailscale/systemd/tailscale-webui.service + wget -O tailscale-webui-trigger.service $GITROOT/tailscale/systemd/tailscale-webui-trigger.service + ln -sf /lib/systemd/system/tailscale-webui-trigger.service /lib/systemd/system/multi-user.target.wants/ + systemctl daemon-reload + echo "Tailscale Web UI Enabled" + echo "Starting Web UI..." + systemctl start tailscale-webui + echo "Web UI started!" + remount_ro + ;; + 2) + remount_rw + systemctl stop tailscale-webui + systemctl disable tailscale-webui-trigger + rm /lib/systemd/system/multi-user.target.wants/tailscale-webui.service + rm /lib/systemd/system/multi-user.target.wants/tailscale-webui-trigger.service + rm /lib/systemd/system/tailscale-webui.service + rm /lib/systemd/system/tailscale-webui-trigger.service + systemctl daemon-reload + echo "Tailscale Web UI Stopped and Disabled" + remount_ro + ;; + 3) $TAILSCALE_DIR/tailscale up --accept-dns=false --reset --accept-routes;; + 4) $TAILSCALE_DIR/tailscale up --ssh --accept-dns=false --reset --accept-routes;; + 5) $TAILSCALE_DIR/tailscale up --accept-dns=false --reset --accept-routes;; + 6) $TAILSCALE_DIR/tailscale down;; + 7) $TAILSCALE_DIR/tailscale logout;; + 8) break;; + *) echo "Invalid option";; + esac + done +} + +##################################################################### +# Tool Installation Functions +##################################################################### + +# Function to install OpenSSH Server +install_sshd() { + if [ -d "/usrdata/sshd" ]; then + echo -e "\e[1;31mSSHD is currently installed.\e[0m" + echo -e "Do you want to update or uninstall?" + echo -e "1.) Update" + echo -e "2.) Uninstall" + read -p "Select an option (1 or 2): " sshd_choice + + case $sshd_choice in + 1) + echo -e "\e[1;31m2) Installing sshd from the $GITTREE branch\e[0m" + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_sshd.sh $GITROOT/simpleupdates/scripts/update_sshd.sh && chmod +x /usrdata/simpleupdates/scripts/update_sshd.sh + echo -e "\e[1;32mUpdating: SSHd\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_sshd.sh + echo -e "\e[1;32m SSHd has been updated.\e[0m" + ;; + 2) + echo -e "\e[1;31mUninstalling SSHD...\e[0m" + systemctl stop sshd + rm /lib/systemd/system/sshd.service + opkg remove openssh-server-pam + echo -e "\e[1;32mSSHD has been uninstalled successfully.\e[0m" + return 0 + ;; + *) + echo -e "\e[1;31mInvalid option. Please select 1 or 2.\e[0m" + return 1 + ;; + esac + fi + + # Proceed with installation if not installed + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_sshd.sh $GITROOT/simpleupdates/scripts/update_sshd.sh && chmod +x /usrdata/simpleupdates/scripts/update_sshd.sh + echo -e "\e[1;32mInstalling: SSHd\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_sshd.sh + echo -e "\e[1;32m SSHd has been installed.\e[0m" +} + +# Function to install Speedtest CLI +install_speedtest_cli() { + ensure_entware_installed + echo -e "\e[1;32mInstalling Speedtest.net CLI (speedtest command)\e[0m" + remount_rw + mkdir /usrdata/root + mkdir /usrdata/root/bin + cd /usrdata/root/bin + wget https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-linux-armhf.tgz + tar -xzf ookla-speedtest-1.2.0-linux-armhf.tgz + rm ookla-speedtest-1.2.0-linux-armhf.tgz + rm speedtest.md + cd / + ln -sf /usrdata/root/bin/speedtest /bin + remount_ro + echo -e "\e[1;32mSpeedtest CLI (speedtest command) installed!!\e[0m" + echo -e "\e[1;32mTry running the command 'speedtest'\e[0m" + echo -e "\e[1;32mNote that it will not work unless you login to the root account first\e[0m" + echo -e "\e[1;32mNormaly only an issue in adb, ttyd and ssh you are forced to login\e[0m" + echo -e "\e[1;32mIf in adb just type login and then try to run the speedtest command\e[0m" +} + +# Function to install Fast.com CLI +install_fast_cli() { + echo -e "\e[1;32mInstalling fast.com CLI (fast command)\e[0m" + remount_rw + mkdir /usrdata/root + mkdir /usrdata/root/bin + cd /usrdata/root/bin + wget -O fast https://code.example.com/sky/simple-admin/raw/branch/main/tools/fast_linux_arm && chmod +x fast + cd / + ln -sf /usrdata/root/bin/fast /bin + remount_ro + echo -e "\e[1;32mFast.com CLI (speedtest command) installed!!\e[0m" + echo -e "\e[1;32mTry running the command 'fast'\e[0m" + echo -e "\e[1;32mThe fast.com test tops out at 40Mbps on the modem\e[0m" +} + +##################################################################### +# AT Command Bridge Functions +##################################################################### + +# Function to install/update AT command socat bridge +install_update_at_socat() { + local current_dir=$(pwd) + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh $GITROOT/simpleupdates/scripts/update_socat-at-bridge.sh && chmod +x /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh + echo -e "\e[1;32mInstalling/updating: AT Socat Bridge\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_socat-at-bridge.sh + echo -e "\e[1;32mAT Socat Bridge has been updated/installed.\e[0m" + cd "$current_dir" +} + +##################################################################### +# Firewall Functions +##################################################################### + +# Function to install Simple Firewall +install_simple_firewall() { + ensure_entware_installed + mkdir /usrdata/simpleupdates > /dev/null 2>&1 + mkdir /usrdata/simpleupdates/scripts > /dev/null 2>&1 + wget -O /usrdata/simpleupdates/scripts/update_simplefirewall.sh $GITROOT/simpleupdates/scripts/update_simplefirewall.sh && chmod +x /usrdata/simpleupdates/scripts/update_simplefirewall.sh + echo -e "\e[1;32mInstalling/updating: Simple Firewall\e[0m" + echo -e "\e[1;32mPlease Wait....\e[0m" + /usrdata/simpleupdates/scripts/update_simplefirewall.sh + echo -e "\e[1;32mSimple Firewall has been updated/installed.\e[0m" +} + +##################################################################### +# Main Menu and Program Flow +##################################################################### + +# Check system architecture and proceed accordingly +check_architecture() { + ARCH=$(uname -a) + if echo "$ARCH" | grep -q "aarch64"; then + cd /tmp && wget -O RM55x_rcPCIe_toolkit.sh https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/SDXPINN/RM55x_rcPCIe_toolkit.sh && chmod +x RM55x_rcPCIe_toolkit.sh && ./RM55x_rcPCIe_toolkit.sh && cd / + exit 0 + elif echo "$ARCH" | grep -q "armv7l"; then + # Continue if architecture is armv7l + echo "Architecture is armv7l, continuing..." + else + uname -a + echo "Unsupported architecture." + exit 1 + fi +} + +# Display the main menu +display_main_menu() { + echo "//////////////////////////////////////////////////////////////////" + echo "// //" + echo "// //" + echo "// :'######::'####:'##::::'##:'########::'##:::::::'########: //" + echo "// '##... ##:. ##:: ###::'###: ##.... ##: ##::::::: ##.....:: //" + echo "// ##:::..::: ##:: ####'####: ##:::: ##: ##::::::: ##::::::: //" + echo "// . ######::: ##:: ## ### ##: ########:: ##::::::: ######::: //" + echo "// :..... ##:: ##:: ##. #: ##: ##.....::: ##::::::: ##...:::: //" + echo "// '##::: ##:: ##:: ##:.:: ##: ##:::::::: ##::::::: ##::::::: //" + echo "// . ######::'####: ##:::: ##: ##:::::::: ########: ########: //" + echo "// :......:::....::..:::::..::..:::::::::........::........:: //" + echo "// :::'###::::'########::'##::::'##:'####:'##::: ##: //" + echo "// ::'## ##::: ##.... ##: ###::'###:. ##:: ###:: ##: //" + echo "// :'##:. ##:: ##:::: ##: ####'####:: ##:: ####: ##: //" + echo "// '##:::. ##: ##:::: ##: ## ### ##:: ##:: ## ## ##: //" + echo "// #########: ##:::: ##: ##. #: ##:: ##:: ##. ####: //" + echo "// ##.... ##: ##:::: ##: ##:.:: ##:: ##:: ##:. ###: //" + echo "// ##:::: ##: ########:: ##:::: ##:'####: ##::. ##: //" + echo "// ..:::::..::........:::..:::::..::....::..::::..:: //" + echo "// //" + echo "// By iamromulan //" + echo "//////////////////////////////////////////////////////////////////" + + echo -e "\e[92m" + echo "Welcome to iamromulan's RGMII Toolkit script for Quectel RMxxx Series modems!" + echo "Visit https://github.com/iamromulan for more!" + echo -e "\e[0m" + echo "Select an option:" + echo -e "\e[0m" + echo -e "\e[96m1) Send AT Commands\e[0m" # Cyan + echo -e "\e[93m2) Install Simple Admin\e[0m" # Yellow + echo -e "\e[95m3) Set Simpleadmin (admin) password\e[0m" # Light Purple + echo -e "\e[94m4) Set Console/ttyd (root) password\e[0m" # Light Blue + echo -e "\e[91m5) Uninstall Simple Admin\e[0m" # Light Red + echo -e "\e[95m6) Simple Firewall Management\e[0m" # Light Purple + echo -e "\e[94m7) Tailscale Management\e[0m" # Light Blue + echo -e "\e[92m8) Install/Change or remove Daily Reboot Timer\e[0m" # Light Green + echo -e "\e[96m9) Install/Uninstall CFUN 0 Fix\e[0m" # Cyan + echo -e "\e[91m10) Uninstall Entware/OPKG\e[0m" # Light Red + echo -e "\e[92m11) Install Speedtest.net CLI app (speedtest command)\e[0m" # Light Green + echo -e "\e[92m12) Install Fast.com CLI app (fast command)(tops out at 40Mbps)\e[0m" # Light Green + echo -e "\e[92m13) Install OpenSSH Server\e[0m" # Light Green + echo -e "\e[93m14) Exit\e[0m" # Yellow +} + +# Main program loop +main() { + check_architecture + + while true; do + display_main_menu + read -p "Enter your choice: " choice + + case $choice in + 1) send_at_commands;; + 2) install_simple_admin;; + 3) set_simpleadmin_passwd;; + 4) set_root_passwd;; + 5) uninstall_simpleadmin_components;; + 6) configure_simple_firewall;; + 7) tailscale_menu;; + 8) manage_reboot_timer;; + 9) manage_cfun_fix;; + 10) + echo -e "\033[31mAre you sure you want to uninstall entware?\033[0m" + echo -e "\033[31m1) Yes\033[0m" + echo -e "\033[31m2) No\033[0m" + read -p "Select an option (1 or 2): " user_choice + + case $user_choice in + 1) + echo -e "\033[31mUninstalling existing entware...\033[0m" + uninstall_entware + echo -e "\033[31mEntware has been uninstalled.\033[0m" + ;; + 2) + echo -e "\033[31mUninstallation cancelled.\033[0m" + exit + ;; + *) + echo -e "\033[31mInvalid option. Please select 1 or 2.\033[0m" + ;; + esac + ;; + 11) install_speedtest_cli;; + 12) install_fast_cli;; + 13) install_sshd;; + 14) + echo -e "\e[1;32mGoodbye!\e[0m" + break + ;; + *) + echo -e "\e[1;31mInvalid option\e[0m" + ;; + esac + done +} + +# Start the program +main \ No newline at end of file -- 2.45.2 From 0a17979bad061bf44af60339f9dc7930b910c0d6 Mon Sep 17 00:00:00 2001 From: sky Date: Thu, 12 Dec 2024 04:18:53 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README=5Fzh.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README_zh.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README_zh.md b/README_zh.md index d0e5aa9..eac0a31 100644 --- a/README_zh.md +++ b/README_zh.md @@ -62,6 +62,7 @@ adb shell cd /tmp && wget -O RMxxx_rgmii_toolkit.sh https://code.060070.xyz/sky/simple-admin/raw/branch/main/RMxxx_rgmii_toolkit.sh && chmod +x RMxxx_rgmii_toolkit.sh && ./RMxxx_rgmii_toolkit.sh && cd / ``` **您应该看到:** + ![工具包](https://github.com/iamromulan/quectel-rgmii-configuration-notes/blob/main/images/iamromulantoolkit.png?raw=true) ## Tailscale安装和配置 -- 2.45.2