From 1538a12ab67664b48770b5f61386996f19693d2d Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:27:46 +0000 Subject: [PATCH 01/11] Add basic dependency functionality --- docs/js_plugins.md | 4 ++++ docs/plugin_dev.md | 6 +++++ helper/js/murkmod.js | 52 ++++++++++++++++++++++++++++++++++++++++++-- mush.sh | 21 +++++++++++++++--- 4 files changed, 78 insertions(+), 5 deletions(-) diff --git a/docs/js_plugins.md b/docs/js_plugins.md index 6b547d8..467278b 100644 --- a/docs/js_plugins.md +++ b/docs/js_plugins.md @@ -16,6 +16,8 @@ var PLUGIN_FUNCTION = "Click me!!!"; var PLUGIN_DESCRIPTION = "An example JS plugin" var PLUGIN_AUTHOR = "Me!"; var PLUGIN_VERSION = 1; +// optionally: +var PLUGIN_DEPENDENCIES = []; function plugin_init() { // this is run on plugin initialization, when a helper tab is opened @@ -29,6 +31,8 @@ function plugin_main() { } ``` +Optionally, you can add an array of strings, `PLUGIN_DEPENDENCIES`, to provide a list of plugins published in murkmod that your plugin requires to run correctly. Plugin dependencies are resolved recursively, so be careful about creating deep dependency trees that may increase installation times. + Otherwise, publishing of a JS plugin is identical to that of a bash plugin - fork the murkmod repo, add the file to `/plugins`, and make a PR. ## APIs and Methods diff --git a/docs/plugin_dev.md b/docs/plugin_dev.md index 1f1daad..258143f 100644 --- a/docs/plugin_dev.md +++ b/docs/plugin_dev.md @@ -17,6 +17,12 @@ echo "Hello, World!" Of course, you should change this to match your plugin. Every time you update your plugin, you should increment `PLUGIN_VERSION`. Everything below the initial variables, though, is what is executed when you run the plugin from the mush menu. +Optionally, you can specify a array of plugin names, `PLUGIN_DEPENDENCIES`. These plugins will be installed automatically when this plugin is installed. + +```sh +PLUGIN_DEPENDENCIES=("plugin_1.sh" "plugin_2.sh") +``` + To add a plugin to this repository (for easy download from mush), just fork the repo, add the file in `/plugins/` and make a PR. I'll review it and merge it if it doesn't do anything malicious. The second comment at the top defines the type of the plugin. There are threeplugin types: diff --git a/helper/js/murkmod.js b/helper/js/murkmod.js index 091f897..e3906c8 100644 --- a/helper/js/murkmod.js +++ b/helper/js/murkmod.js @@ -513,6 +513,34 @@ document.addEventListener("DOMContentLoaded", function () { const match = script.match(regex); return match ? match[1] : null; }; + const extractValueUnquoted = (variable, script) => { + const regex = new RegExp(`${variable}=(.*?)\n`); + const match = script.match(regex); + return match ? match[1] : null; + }; + + function handle_js_dep(plugin) { + fetch(`https://api.github.com/repos/rainestorme/murkmod/contents/plugins/${plugin}`) + .then(response => {return response.json()}) + .then(file => { + var file_content = atob(file.content); + var trimmed = { + "name": file.name, + "path": file.path, + "sha": file.sha, + "size": file.size, + "url": file.url, + "download_url": file.download_url, + "type": file.type, + }; + installed_plugins.push({ + file: trimmed, + text: file_content + }); + localStorage.setItem("plugins", JSON.stringify(installed_plugins)); + }); + } + document.querySelector("#store").addEventListener("click", function() { Swal.fire({ title: 'Loading plugin store...', @@ -554,7 +582,15 @@ document.addEventListener("DOMContentLoaded", function () { const PLUGIN_FUNCTION = extractValue("PLUGIN_FUNCTION", text); const PLUGIN_DESCRIPTION = extractValue("PLUGIN_DESCRIPTION", text); const PLUGIN_AUTHOR = extractValue("PLUGIN_AUTHOR", text); - console.log(PLUGIN_NAME, PLUGIN_FUNCTION, PLUGIN_DESCRIPTION, PLUGIN_AUTHOR); + const PLUGIN_VERSION = extractValueUnquoted("PLUGIN_VERSION", text); + var _PLUGIN_DEPENDENCIES = extractValueUnquoted("PLUGIN_DEPENDENCIES", text); + if (!_PLUGIN_DEPENDENCIES){ + _PLUGIN_DEPENDENCIES = "[]" + } else { + _PLUGIN_DEPENDENCIES = _PLUGIN_DEPENDENCIES.replace("(", "[").replace(")", "]").replace(" ", ", ") + } + const PLUGIN_DEPENDENCIES = JSON.parse(_PLUGIN_DEPENDENCIES); + console.log(PLUGIN_NAME, PLUGIN_FUNCTION, PLUGIN_DESCRIPTION, PLUGIN_AUTHOR, PLUGIN_DEPENDENCIES); var install_btn = "Install"; var installed = false; for (let i in window.legacy_plugins) { @@ -564,7 +600,7 @@ document.addEventListener("DOMContentLoaded", function () { } } card.innerHTML = `
${PLUGIN_NAME}
-
By ${PLUGIN_AUTHOR} - Bash
+
By ${PLUGIN_AUTHOR} - v${PLUGIN_VERSION} - Bash
${PLUGIN_DESCRIPTION}
`; document.querySelector(`#card-${file.name.split(".")[0]}-${file.name.split(".")[1]}-installbtn`).addEventListener("click", function(){ @@ -578,6 +614,13 @@ document.addEventListener("DOMContentLoaded", function () { }, false, ""); return; } + PLUGIN_DEPENDENCIES.forEach(plugin=>{ + window.run_task("114\n", "", "> (1-", function (output) { + if (output.includes("Enter the name of a plugin (including the .sh) to install it (or q to quit):")) { + window.send(`${plugin}\n`); + } + }, function () {}, false, ""); + }); window.run_task("114\n", "", "> (1-", function (output) { if (output.includes("Enter the name of a plugin (including the .sh) to install it (or q to quit):")) { window.send(`${file.name}\n`); @@ -605,6 +648,11 @@ document.addEventListener("DOMContentLoaded", function () { if (already_installed) { install_btn = "Uninstall"; } + if (typeof PLUGIN_DEPENDENCIES !== 'undefined') { + PLUGIN_DEPENDENCIES.forEach(plugin => { + handle_js_dep(plugin); + }); + } card.innerHTML = `
${PLUGIN_NAME}
By ${PLUGIN_AUTHOR} - JavaScript
${PLUGIN_DESCRIPTION}
diff --git a/mush.sh b/mush.sh index 6ca76bc..e768cec 100644 --- a/mush.sh +++ b/mush.sh @@ -166,7 +166,7 @@ EOF 24) runjob attempt_dev_install ;; 25) runjob do_updates && exit 0 ;; 26) runjob do_dev_updates && exit 0 ;; - 101) runjob hard_disable_nokill ;; + 101) runjob hard_disable_nokill ;; # anything prefixed with a 1 is for the helper extension, you can safely ignore these as a user 111) runjob hard_enable_nokill ;; 112) runjob ext_purge ;; 113) runjob list_plugins ;; @@ -178,6 +178,21 @@ EOF done } +do_install_plugin() { + local url=$1 + local filename="$(echo "${url}" | rev | cut -d/ -f1 | rev)" + if [! -f /mnt/stateful_partition/murkmod/plugins/$filename ]; then + doas "pushd /mnt/stateful_partition/murkmod/plugins + curl $url -O + chmod 775 /mnt/stateful_partition/murkmod/plugins/$filename + popd" > /dev/null + local dependencies=($(grep -oP '(?<=PLUGIN_DEPENDENCIES\+=\()[^)]*' "$filename")) + for dep in "${dependencies[@]}"; do + do_install_plugin "$dep" + done + fi +} + install_plugin_legacy() { local raw_url="https://raw.githubusercontent.com/rainestorme/murkmod/main/plugins" @@ -193,7 +208,7 @@ install_plugin_legacy() { echo "Plugin not found" else echo "Installing..." - doas "pushd /mnt/stateful_partition/murkmod/plugins && curl https://raw.githubusercontent.com/rainestorme/murkmod/main/plugins/$plugin_name -O && popd" > /dev/null + do_install_plugin "https://raw.githubusercontent.com/rainestorme/murkmod/main/plugins/$plugin_name" echo "Installed $plugin_name" fi } @@ -480,7 +495,7 @@ install_plugins() { "") clear echo "Using URL: ${download_urls[$selected_option]}" echo "Installing plugin..." - doas "pushd /mnt/stateful_partition/murkmod/plugins && curl ${download_urls[$selected_option]} -O && popd" > /dev/null + do_install_plugin "${download_urls[$selected_option]}" echo "Done!" ;; esac From 67d519e0cc0107af681d73426383cd173b3f7be5 Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Sat, 27 Jan 2024 20:50:27 +0000 Subject: [PATCH 02/11] Add delay for debugging - revert me later --- mush.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/mush.sh b/mush.sh index e768cec..0f4bd61 100644 --- a/mush.sh +++ b/mush.sh @@ -191,6 +191,7 @@ do_install_plugin() { do_install_plugin "$dep" done fi + read -r -p "Press enter to continue." throwaway } install_plugin_legacy() { From 4313f7b2886df3762d34e4f6bb2618e6f112931c Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Sat, 27 Jan 2024 20:52:25 +0000 Subject: [PATCH 03/11] Fix syntax error --- mush.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mush.sh b/mush.sh index 0f4bd61..bb27f7f 100644 --- a/mush.sh +++ b/mush.sh @@ -181,7 +181,7 @@ EOF do_install_plugin() { local url=$1 local filename="$(echo "${url}" | rev | cut -d/ -f1 | rev)" - if [! -f /mnt/stateful_partition/murkmod/plugins/$filename ]; then + if [ ! -f /mnt/stateful_partition/murkmod/plugins/$filename ]; then doas "pushd /mnt/stateful_partition/murkmod/plugins curl $url -O chmod 775 /mnt/stateful_partition/murkmod/plugins/$filename From 1a813ca910d66df631d6310cf63bc37a4bf7bf2b Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Sat, 27 Jan 2024 20:55:44 +0000 Subject: [PATCH 04/11] Remove perl dependency from grep --- mush.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mush.sh b/mush.sh index bb27f7f..d63e22f 100644 --- a/mush.sh +++ b/mush.sh @@ -186,7 +186,7 @@ do_install_plugin() { curl $url -O chmod 775 /mnt/stateful_partition/murkmod/plugins/$filename popd" > /dev/null - local dependencies=($(grep -oP '(?<=PLUGIN_DEPENDENCIES\+=\()[^)]*' "$filename")) + local dependencies=($(grep -o '(PLUGIN_DEPENDENCIES\+=\()[^)]*' "$filename")) for dep in "${dependencies[@]}"; do do_install_plugin "$dep" done From f2c371917f4ac48f69dbf1019b4c4f0e2642a2ee Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Sat, 27 Jan 2024 20:58:13 +0000 Subject: [PATCH 05/11] Fix filepath --- mush.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mush.sh b/mush.sh index d63e22f..b5ea2d4 100644 --- a/mush.sh +++ b/mush.sh @@ -186,7 +186,7 @@ do_install_plugin() { curl $url -O chmod 775 /mnt/stateful_partition/murkmod/plugins/$filename popd" > /dev/null - local dependencies=($(grep -o '(PLUGIN_DEPENDENCIES\+=\()[^)]*' "$filename")) + local dependencies=($(grep -o '(PLUGIN_DEPENDENCIES\+=\()[^)]*' "/mnt/stateful_partition/murkmod/plugins/$filename")) for dep in "${dependencies[@]}"; do do_install_plugin "$dep" done From 3a3dfa8b5177bd667db4539a0249e03572e8d4eb Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:16:09 +0000 Subject: [PATCH 06/11] Damn you chatgpt --- mush.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mush.sh b/mush.sh index b5ea2d4..6365527 100644 --- a/mush.sh +++ b/mush.sh @@ -186,7 +186,7 @@ do_install_plugin() { curl $url -O chmod 775 /mnt/stateful_partition/murkmod/plugins/$filename popd" > /dev/null - local dependencies=($(grep -o '(PLUGIN_DEPENDENCIES\+=\()[^)]*' "/mnt/stateful_partition/murkmod/plugins/$filename")) + local dependencies=($(grep -o 'PLUGIN_DEPENDENCIES\+=([^)]*)' "$filename" | sed 's/PLUGIN_DEPENDENCIES\+=//; s/[()]//g')) for dep in "${dependencies[@]}"; do do_install_plugin "$dep" done From 6be52d1a9e85b02b5a6eae2387e0a8054579602e Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:28:22 +0000 Subject: [PATCH 07/11] Chatgpt does it again --- mush.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mush.sh b/mush.sh index 6365527..6427f60 100644 --- a/mush.sh +++ b/mush.sh @@ -186,7 +186,7 @@ do_install_plugin() { curl $url -O chmod 775 /mnt/stateful_partition/murkmod/plugins/$filename popd" > /dev/null - local dependencies=($(grep -o 'PLUGIN_DEPENDENCIES\+=([^)]*)' "$filename" | sed 's/PLUGIN_DEPENDENCIES\+=//; s/[()]//g')) + local dependencies=($(grep -o 'PLUGIN_DEPENDENCIES\+=([^)]*)' "/mnt/stateful_partition/murkmod/plgins/$filename" | sed 's/PLUGIN_DEPENDENCIES\+=//; s/[()]//g')) for dep in "${dependencies[@]}"; do do_install_plugin "$dep" done From 0cf465fc0dbb2b711dc50259b639a77198cd47fe Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:30:24 +0000 Subject: [PATCH 08/11] This is why this is a draft PR --- mush.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mush.sh b/mush.sh index 6427f60..de07643 100644 --- a/mush.sh +++ b/mush.sh @@ -186,7 +186,7 @@ do_install_plugin() { curl $url -O chmod 775 /mnt/stateful_partition/murkmod/plugins/$filename popd" > /dev/null - local dependencies=($(grep -o 'PLUGIN_DEPENDENCIES\+=([^)]*)' "/mnt/stateful_partition/murkmod/plgins/$filename" | sed 's/PLUGIN_DEPENDENCIES\+=//; s/[()]//g')) + local dependencies=($(grep -o 'PLUGIN_DEPENDENCIES\+=([^)]*)' "/mnt/stateful_partition/murkmod/plugins/$filename" | sed 's/PLUGIN_DEPENDENCIES\+=//; s/[()]//g')) for dep in "${dependencies[@]}"; do do_install_plugin "$dep" done From 9bd679420d3de9e3ba9ad0b3eabcec8d2ec9a6ba Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:34:20 +0000 Subject: [PATCH 09/11] Debug logging, remove quotes from sub-dependencies --- mush.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mush.sh b/mush.sh index de07643..d932987 100644 --- a/mush.sh +++ b/mush.sh @@ -188,7 +188,10 @@ do_install_plugin() { popd" > /dev/null local dependencies=($(grep -o 'PLUGIN_DEPENDENCIES\+=([^)]*)' "/mnt/stateful_partition/murkmod/plugins/$filename" | sed 's/PLUGIN_DEPENDENCIES\+=//; s/[()]//g')) for dep in "${dependencies[@]}"; do - do_install_plugin "$dep" + echo "$dep" + local dep_fixed=$(echo "$dep" | tr -d '"') + echo "$dep_fixed" + do_install_plugin "$dep_fixed" done fi read -r -p "Press enter to continue." throwaway From 676ad08a97329ce9fdbee06d2995a3529726713c Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:37:27 +0000 Subject: [PATCH 10/11] Fix URL resolving for dependencies --- mush.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mush.sh b/mush.sh index d932987..bb8e10e 100644 --- a/mush.sh +++ b/mush.sh @@ -188,10 +188,9 @@ do_install_plugin() { popd" > /dev/null local dependencies=($(grep -o 'PLUGIN_DEPENDENCIES\+=([^)]*)' "/mnt/stateful_partition/murkmod/plugins/$filename" | sed 's/PLUGIN_DEPENDENCIES\+=//; s/[()]//g')) for dep in "${dependencies[@]}"; do - echo "$dep" local dep_fixed=$(echo "$dep" | tr -d '"') - echo "$dep_fixed" - do_install_plugin "$dep_fixed" + echo "Installing $dep_fixed..." + do_install_plugin "https://raw.githubusercontent.com/rainestorme/murkmod/main/plugins/$dep_fixed" done fi read -r -p "Press enter to continue." throwaway From 1a8e55dc8131bcfbbf59d133c942f4e7b01cd8b7 Mon Sep 17 00:00:00 2001 From: rainestorme <115757568+rainestorme@users.noreply.github.com> Date: Wed, 13 Mar 2024 23:12:42 +0000 Subject: [PATCH 11/11] Install sh plugins even when depended on by js plugin --- helper/js/murkmod.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/helper/js/murkmod.js b/helper/js/murkmod.js index e3906c8..c0100b8 100644 --- a/helper/js/murkmod.js +++ b/helper/js/murkmod.js @@ -520,7 +520,8 @@ document.addEventListener("DOMContentLoaded", function () { }; function handle_js_dep(plugin) { - fetch(`https://api.github.com/repos/rainestorme/murkmod/contents/plugins/${plugin}`) + if (plugin.endsWith(".js")){ + fetch(`https://api.github.com/repos/rainestorme/murkmod/contents/plugins/${plugin}`) .then(response => {return response.json()}) .then(file => { var file_content = atob(file.content); @@ -539,6 +540,13 @@ document.addEventListener("DOMContentLoaded", function () { }); localStorage.setItem("plugins", JSON.stringify(installed_plugins)); }); + } else { + window.run_task("114\n", "", "> (1-", function (output) { + if (output.includes("Enter the name of a plugin (including the .sh) to install it (or q to quit):")) { + window.send(`${plugin}\n`); + } + }, function () {}, false, ""); + } } document.querySelector("#store").addEventListener("click", function() {