~anjan/public-inbox

start and stop ssh from a userscript. it will ask for sudo password. change "path_of_script" to get toggle knob icon working. v1 SUPERSEDED

magdesign: 1
 start and stop ssh from a userscript. it will ask for sudo password. change "path_of_script" to get toggle knob icon working.

 1 files changed, 34 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~anjan/public-inbox/patches/49279/mbox | git am -3
Learn more about email & git

[PATCH] start and stop ssh from a userscript. it will ask for sudo password. change "path_of_script" to get toggle knob icon working. Export this patch

---
 scripts/ssh_toggle.sh | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 scripts/ssh_toggle.sh

diff --git a/scripts/ssh_toggle.sh b/scripts/ssh_toggle.sh
new file mode 100644
index 0000000..173b215
--- /dev/null
+++ b/scripts/ssh_toggle.sh
@@ -0,0 +1,34 @@
#!/bin/sh
# title="$icon_tof SSH enable"
# Description: Toggles ssh on or off
# Author: magdesign
# License: MIT
# shellcheck source=scripts/core/sxmo_common.sh
. "/usr/bin/sxmo_common.sh"

# check the sshd status
service_status=$(rc-service sshd status)
# path of this script, to toggle name & icon
path_of_script=~/.config/sxmo/userscripts/ssh_toggle.sh

if [[ $service_status == *"started"* ]]; then
    echo "Service sshd is started. Stopping now..."
    # asking for privileges and disabling ssh
    sxmo_terminal.sh -t "Enter password" -- sh -c 'sudo rc-service sshd stop' 'sudo rc-update del sshd'
    # notify that service is stopping
    notify-send "SSH stopped"
     # change the toggle symbol and name of this script
    sed -i 's/^# title="\$icon_ton SSH disable"/# title="\$icon_tof SSH enable"/' $path_of_script

elif [[ $service_status == *"stopped"* ]]; then
    echo "Service sshd is stopped. Starting now..."
    # asking for privileges and enabling ssh
    sxmo_terminal.sh -t "Enter password" -- sh -c 'sudo rc-service sshd start' 'sudo rc-update add sshd'
    # notify that it is starting
    notify-send "SSH started"
    # change the toggle symbol and name of this script
    sed -i 's/^# title="\$icon_tof SSH enable"/# title="\$icon_ton SSH disable"/' $path_of_script

else
    notify-send --urgency=critical "Error: no status"
fi
-- 
2.43.0