From da745e212f502f9069780d2196be1d6004692416 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 12 Jan 2023 18:34:58 -0500 Subject: [PATCH] New tests --- functions.js | 21 +++++++++-- hestia.sh | 81 +++++++++++++++++++++++++++++++++++++++++++ quit | 0 templates/config.json | 3 +- 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100755 hestia.sh create mode 100644 quit diff --git a/functions.js b/functions.js index 8c97de9..e25e03f 100644 --- a/functions.js +++ b/functions.js @@ -24,14 +24,18 @@ const main = (gpio) => { functions.auger.cycle(gpio).then(res => { if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); // Recursion ecursion cursion ursion rsion sion ion on n - main(gpio); + functions.checkForQuit().then(n => { + main(gpio); + }); }).catch(err => { if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`); }); } else { // If the auger is disabled functions.commands.pause().then(res => { - main(gpio); + functions.checkForQuit().then(n => { + main(gpio); + }); }).catch(err => { if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`); main(gpio); @@ -234,6 +238,19 @@ const functions = { } }); }, + checkForQuit() { + if (config.status.shutdownNextCycle == 1) process.exit(); + return new Promise((resolve, reject) => { + if (fs.existsSync('./quit')) { + fs.unlink('./quit', err => { + if (err) console.log('Error removing the quit file: ' + err); + config.status.shutdownNextCycle = 1; + config.status.auger = 0; + resolve(); + }); + } + }); + }, time(stamp) { const time = new Date(stamp); return `${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`; diff --git a/hestia.sh b/hestia.sh new file mode 100755 index 0000000..83ca09c --- /dev/null +++ b/hestia.sh @@ -0,0 +1,81 @@ +#!/bin/bash +##################################################### +# Interactive script for managing Hestia Web Portal # +##################################################### +# Formatting Tips: +# https://misc.flogisoft.com/bash/tip_colors_and_formatting +# +# Formatting: +# \e[1m - Bold +# \e[2m - Dim +# \e[8m - Hidden (passwords) +# +# Reset: +# \e[0m - Reset All Attributes +# \e[21m - Reset Bold/Bright +# \e[22m - Reset Dim +# \e[28m - Reset Hidden +# +# Colors: +# \e[39m - Default Foreground Color +# \e[30m - Black +# \e[31m - Red +# \e[32m - Green +# \e[34m - Blue +##################################################### + +# Some initial variables to work with +timestamp=$(date "+%Y%m%d_%H%M") +filename="backup_$timestamp.tar.gz" + +# Initial Prompt +# Bash allows for linebreaks in string literals and will +# break lines accordingly in the shell +echo -e " +[ Hestia Control Panel ] + +This script is being run from: '$(pwd)' + +Please enter an option from below: + + [1] Launch Hestia Web Portal + [2] Quit Hestia Web Portal + [3] View the logs + + [0] Quit Control Panel" + +# Wait for input +read -p " Option: " opt + +# Execute the correct commands based on input. +case "$opt" in + 1) + # Launch Hestia Web Portal + clear + echo "Launching Hestia Web Portal" + nohup node websvr.js > log.txt & + ;; + 2) + # Quit Hestia Web Portal + clear + echo "Quitting Hestia Web Portal Gracefully" + touch quit + ;; + 3) + # View logs + clear + cat log.txt | less + ;; + 0) + # Exit the script + clear + echo "Quitting..." + exit + ;; + *) + clear + echo "Invalid Option!" + ;; +esac + +exec ./hestia.sh diff --git a/quit b/quit new file mode 100644 index 0000000..e69de29 diff --git a/templates/config.json b/templates/config.json index c1193ff..95b304b 100644 --- a/templates/config.json +++ b/templates/config.json @@ -7,7 +7,8 @@ "igniterFinished": false, "shutdown": 0, "vacuum": 0, - "pof": 0 + "pof": 0, + "shutdownNextCycle": 0 }, "timestamps": { "procStart": 0,