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/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.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..d153b35 --- /dev/null +++ b/index.js @@ -0,0 +1,39 @@ +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); + }).catch((err) => { + console.error(err) + }); + } else { + call_plugin_method("set_ssh_state", { state: true }).then((value) => { + setToggleState("sshToggle", value); + }).catch((err) => { + console.error(err) + }); + } +} + +async function handleInitialValue() { + console.log("InitialValue"); + let state = await call_plugin_method("get_ssh_state", {}); + console.log(state); + setToggleState("sshToggle", state); +} 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/main.py b/main.py new file mode 100644 index 0000000..2941774 --- /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.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("sudo systemctl start sshd.service", stdout=subprocess.PIPE, shell=True).communicate()) + else: + print(subprocess.Popen("sudo systemctl stop sshd.service", stdout=subprocess.PIPE, shell=True).communicate()) + + return await self.get_ssh_state() 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) 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 }}