From 0da31f7f55a89fa5c8beb9892f64a16661e6f731 Mon Sep 17 00:00:00 2001 From: Tanner Taylor Date: Fri, 8 Apr 2022 21:52:48 -0500 Subject: [PATCH 1/3] Migrating plugin to new format --- index.html | 36 ++++++++++++++ index.js | 35 ++++++++++++++ main.py | 23 +++++++++ plugin_extra_settings.py | 101 --------------------------------------- 4 files changed, 94 insertions(+), 101 deletions(-) create mode 100644 index.html create mode 100644 index.js create mode 100644 main.py delete mode 100644 plugin_extra_settings.py diff --git a/index.html b/index.html new file mode 100644 index 0000000..74f355e --- /dev/null +++ b/index.html @@ -0,0 +1,36 @@ + + + + + + + + + +
+
+
+
+
+
+
+ + + + + +
+ SSH Server +
+
+
+
+
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..94415c4 --- /dev/null +++ b/index.js @@ -0,0 +1,35 @@ +function setToggleState(id, state) { + const ENABLED_CLASS = "basicdialog_On_1RyF_"; + let toggle = document.getElementById(id); + + if (state && !toggle.classList.contains(ENABLED_CLASS)) { + toggle.classList.add(ENABLED_CLASS); + } + + if (!state && toggle.classList.contains(ENABLED_CLASS)) { + toggle.classList.remove(ENABLED_CLASS); + } +} + +function handleSSHToggle() { + let toggle = document.getElementById("sshToggle"); + + let isActive = toggle.classList.contains("basicdialog_On_1RyF_"); + + if (isActive) { + call_plugin_method("set_ssh_state", { state: false }).then((value) => { + setToggleState("sshToggle", value); + }); + } else { + call_plugin_method("set_ssh_state", { state: true }).then((value) => { + setToggleState("sshToggle", value); + }); + } +} + +async function handleInitialValue() { + console.log("InitialValue"); + let state = await call_plugin_method("get_ssh_state", {}); + console.log(state); + setToggleState("sshToggle", state); +} diff --git a/main.py b/main.py new file mode 100644 index 0000000..5c45999 --- /dev/null +++ b/main.py @@ -0,0 +1,23 @@ +import subprocess + +class Plugin: + name = "Extra Settings" + + author = "WerWolv" + + main_view_html = "index.html" + + tile_view_html = "" + + async def get_ssh_state(self): + return subprocess.Popen("systemctl is-active sshd", stdout=subprocess.PIPE, shell=True).communicate()[0] == b'active\n' + + async def set_ssh_state(self, **kwargs): + print(kwargs["state"]) + + if kwargs["state"]: + print(subprocess.Popen("systemctl start sshd", stdout=subprocess.PIPE, shell=True).communicate()) + else: + print(subprocess.Popen("systemctl stop sshd", stdout=subprocess.PIPE, shell=True).communicate()) + + return await self.get_ssh_state(self) diff --git a/plugin_extra_settings.py b/plugin_extra_settings.py deleted file mode 100644 index 3748216..0000000 --- a/plugin_extra_settings.py +++ /dev/null @@ -1,101 +0,0 @@ -import subprocess - -class Plugin: - name = "Extra Settings" - - author = "WerWolv" - - main_view_html = """ - - - - - - - - - - - -
-
-
-
-
-
-
- - - - - -
- SSH Server -
-
-
-
-
-
-
-
-
-
-
- - - """ - - tile_view_html = "" - - async def get_ssh_state(self): - return subprocess.Popen("systemctl is-active sshd", stdout=subprocess.PIPE, shell=True).communicate()[0] == b'active\n' - - async def set_ssh_state(self, **kwargs): - print(kwargs["state"]) - - if kwargs["state"]: - print(subprocess.Popen("systemctl start sshd", stdout=subprocess.PIPE, shell=True).communicate()) - else: - print(subprocess.Popen("systemctl stop sshd", stdout=subprocess.PIPE, shell=True).communicate()) - - return await self.get_ssh_state(self) From 984d1c880fdf84b8bbcbbef134df3754c8ca0a84 Mon Sep 17 00:00:00 2001 From: Felipe Escoto Date: Sun, 10 Apr 2022 16:01:55 -0700 Subject: [PATCH 2/3] Allow toggling the sshd service by the deck user --- etc/sudoers.d/x-extra-settings-plugin | 4 ++++ index.js | 4 ++++ main.py | 8 ++++---- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 etc/sudoers.d/x-extra-settings-plugin diff --git a/etc/sudoers.d/x-extra-settings-plugin b/etc/sudoers.d/x-extra-settings-plugin new file mode 100644 index 0000000..42a44e8 --- /dev/null +++ b/etc/sudoers.d/x-extra-settings-plugin @@ -0,0 +1,4 @@ +# This file is required to allow the "deck" user to toggle the sshd service +deck ALL=NOPASSWD: /bin/systemctl start sshd.service +deck ALL=NOPASSWD: /bin/systemctl stop sshd.service +deck ALL=NOPASSWD: /bin/systemctl restart sshd.service \ No newline at end of file diff --git a/index.js b/index.js index 94415c4..d153b35 100644 --- a/index.js +++ b/index.js @@ -19,10 +19,14 @@ function handleSSHToggle() { if (isActive) { call_plugin_method("set_ssh_state", { state: false }).then((value) => { setToggleState("sshToggle", value); + }).catch((err) => { + console.error(err) }); } else { call_plugin_method("set_ssh_state", { state: true }).then((value) => { setToggleState("sshToggle", value); + }).catch((err) => { + console.error(err) }); } } diff --git a/main.py b/main.py index 5c45999..2941774 100644 --- a/main.py +++ b/main.py @@ -10,14 +10,14 @@ class Plugin: tile_view_html = "" async def get_ssh_state(self): - return subprocess.Popen("systemctl is-active sshd", stdout=subprocess.PIPE, shell=True).communicate()[0] == b'active\n' + return subprocess.Popen("systemctl is-active sshd.service", stdout=subprocess.PIPE, shell=True).communicate()[0] == b'active\n' async def set_ssh_state(self, **kwargs): print(kwargs["state"]) if kwargs["state"]: - print(subprocess.Popen("systemctl start sshd", stdout=subprocess.PIPE, shell=True).communicate()) + print(subprocess.Popen("sudo systemctl start sshd.service", stdout=subprocess.PIPE, shell=True).communicate()) else: - print(subprocess.Popen("systemctl stop sshd", stdout=subprocess.PIPE, shell=True).communicate()) + print(subprocess.Popen("sudo systemctl stop sshd.service", stdout=subprocess.PIPE, shell=True).communicate()) - return await self.get_ssh_state(self) + return await self.get_ssh_state() From ad781555145bbc1c46706d12c911687173caff06 Mon Sep 17 00:00:00 2001 From: Felipe Escoto Date: Sun, 10 Apr 2022 16:06:09 -0700 Subject: [PATCH 3/3] Add CI --- .gitignore | 1 + bundle.sh | 11 +++++++++++ install.sh | 12 ++++++++++++ workflows/ci.yml | 24 ++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 .gitignore create mode 100755 bundle.sh create mode 100644 install.sh create mode 100644 workflows/ci.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e691441 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +extra-settings-plugin.zip \ No newline at end of file diff --git a/bundle.sh b/bundle.sh new file mode 100755 index 0000000..77e0195 --- /dev/null +++ b/bundle.sh @@ -0,0 +1,11 @@ +# Delete previous bundle if exists +rm -f ./extra-settings-plugin.zip + +# Bundle the plugin +zip ./extra-settings-plugin.zip \ + etc/sudoers.d/x-extra-settings-plugin \ + index.html \ + index.js \ + main.py \ + install.sh + \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..2d5420a --- /dev/null +++ b/install.sh @@ -0,0 +1,12 @@ +plugin_id=com.github.SteamDeckHomebrew.ExtraSettingsPlugin +plugin_dir=/home/deck/homebrew/plugins/$plugin_id + +mkdir -p $plugin_dir + +# Install the plugin-related files +cp ./index.html $plugin_dir +cp ./index.js $plugin_dir +cp ./main.py $plugin_dir + +# Install sudoers file to allow controlling the sshd service +sudo cp ./etc/sudoers.d/x-extra-settings-plugin /etc/sudoers.d/x-extra-settings-plugin \ No newline at end of file diff --git a/workflows/ci.yml b/workflows/ci.yml new file mode 100644 index 0000000..1e8b593 --- /dev/null +++ b/workflows/ci.yml @@ -0,0 +1,24 @@ +name: "CI" + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - run: ./bundle.sh + + - name: Release Plugin + uses: marvinpinto/action-automatic-releases@latest + with: + title: extra-settings-plugin + automatic_release_tag: continuous + prerelease: true + draft: false + files: | + extra-settings-plugin.zip + repo_token: ${{ secrets.GITHUB_TOKEN }}