aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Stendahl <jakobste@uio.no>2021-10-03 20:03:18 +0200
committerJakob Stendahl <jakobste@uio.no>2021-10-03 20:03:18 +0200
commit8cd4f8523bfe67784f1369eeef33556887e53379 (patch)
tree0921ffa93d5ba2f259bc9abf5b868d03fe4527fc
parent4850c11d87df287beacf5a5bd9012f7b54f13566 (diff)
parentc6b6713e4ca50ecfaf847db1b874f2aec456fbb4 (diff)
downloadLuxcena-Neo-8cd4f8523bfe67784f1369eeef33556887e53379.tar.gz
Luxcena-Neo-8cd4f8523bfe67784f1369eeef33556887e53379.zip
:twisted_rightwards_arrows: Merge in my own changes
-rw-r--r--app.js27
-rwxr-xr-xbin/install.sh142
-rwxr-xr-xbin/luxcena-neo-cli.sh61
-rw-r--r--bin/luxcena-neo.service6
-rwxr-xr-xbin/luxcena-neo.sh4
-rw-r--r--src/NeoRuntimeManager/RuntimeProcess.js4
-rw-r--r--src/NeoRuntimeManager/index.js8
-rw-r--r--src/SSLCert/index.js6
-rw-r--r--src/SelfUpdater/index.js4
-rw-r--r--src/SocketIO/index.js4
-rw-r--r--src/UserData/index.js48
11 files changed, 134 insertions, 180 deletions
diff --git a/app.js b/app.js
index 0196645..30146ea 100644
--- a/app.js
+++ b/app.js
@@ -2,22 +2,27 @@ let fse = require("fs-extra");
let events = require('events');
// Firstly we set up all globals, check that the usrData dir exists, if not, we run the setup
-let userDir = "/home/lux-neo";
-if (process.argv.length >= 3) { userDir = process.argv[2]; }
-if (!fse.existsSync(userDir + "/userdata/")) {
+global.__appdir = "/opt/luxcena-neo";
+global.__configdir = "/etc/luxcena-neo";
+global.__datadir = "/var/luxcena-neo";
+global.__logdir = "/var/log/luxcena-neo";
+
+if ((process.argv.length >= 3) && (process.argv[2] == "dev")) {
+ global.__appdir = __dirname;
+ global.__configdir = __dirname + "/tmp/config";
+ global.__datadir = __dirname + "/tmp/userdata";
+ global.__logdir = __dirname + "/tmp/logs";
+}
+if (!fse.existsSync(global.__datadir)) {
console.log(`CRITICAL UserDir not found '${userDir}'! Exiting...`);
process.exit(1);
}
-// Global path variables
-global.__basedir = __dirname + "";
-global.__datadir = userDir + "/userdata";
-global.__logdir = userDir + "/logs";
// global eventEmitter
global.__event = new events.EventEmitter();
// Secondly we setup the logger,
-let logger = require("./src/logger");
+let logger = require("./src/Logger");
logger.info("Starting Luxcena-Neo...");
let neoModules = {};
@@ -33,14 +38,14 @@ let express = require("express");
let https = require("https");
let app = express();
let server = https.createServer({
- key: fse.readFileSync(__datadir + "/config/certs/privkey.pem"),
- cert: fse.readFileSync(__datadir + "/config/certs/cert.pem")
+ key: fse.readFileSync(__configdir + "/certs/privkey.pem"),
+ cert: fse.readFileSync(__configdir + "/certs/cert.pem")
},
app
);
let io = require("socket.io")(server);
require("./src/SocketIO")(neoModules, io);
-app.use("/", express.static(__basedir + "/public"));
+app.use("/", express.static(__appdir + "/public"));
server.listen(neoModules.userData.config.HTTP.port, () => {
let host = server.address().address;
diff --git a/bin/install.sh b/bin/install.sh
index cd4f07b..a7b811b 100755
--- a/bin/install.sh
+++ b/bin/install.sh
@@ -5,9 +5,6 @@ printf '%s\n' "Luxcena-neo Installer"
tput sgr0
printf '\e[93m%s\e[0m\n\n' "---------------------"
-LOG="/tmp/luxcena-neo.install.log"
-echo "Starting Luxcena-neo installer..." > $LOG
-
if [ "$EUID" -ne 0 ]; then
echo "You need to run this script as root."
echo "Try running with 'sudo ./bin/install.sh'"
@@ -16,139 +13,56 @@ fi
function die() {
tput setaf 1
- printf "\n\nInstall failed.\n"
- printf "Check the logfile at '/tmp/lucxena-neo.install.log'.\n"
- printf "Use this command to see the last 30 lines of the file;\n"
- printf " tail -n 30 /tmp/luxcena-neo.install.log"
+ printf "\n\nInstall failed, successfull steps not reversed.\n"
tput sgr0
exit 1
}
-function dlgYN() {
- tput sc
- tput setaf 4
- printf "$1 (y/n)? "
- while :
- do
- read -n 1 -p "" YNQuestionAnswer
- if [[ $YNQuestionAnswer == "y" ]]; then
- tput rc; tput el
- printf ". $1?: \e[0;32mYes\e[0m\n"
- tput sc
- eval $2=1 # Set parameter 2 of input to the return value
- break
- elif [[ $YNQuestionAnswer == "n" ]]; then
- tput rc; tput el
- printf ". $1?: \e[0;31mNo\e[0m\n"
- eval $2=0 # Set parameter 2 of input to the return value
- break
- fi
- done
-}
-
-# Update system
-dlgYN ". Update your system" res
-if [ $res -eq 1 ]; then
- tput sc
- apt-get -y update &>> $LOG || die
- apt-get -y upgrade &>> $LOG || die
- tput rc; tput ed
-fi
-
-# Install packages
-dlgYN ". Install required packages" res
-if [ $res -eq 1 ]; then
- tput sc
- apt-get -y install nodejs scons python-dev swig &>> $LOG || die
- if [ $? -eq 0 ]; then
- tput rc; tput ed
- printf "โœ“"
- else
- printf "\nInstall failed.\n"
- exit 1
- fi
-else
- tput setaf 2
- printf " We are now assuming that all the following packages exists on your system:\n"
- printf " nodejs scons python-dev swig\n"
- tput sgr0
-fi
-
-# Install led-library
-dlgYN ". Install jgarff's rpi_ws281x library" res
-if [ $res -eq 1 ]; then
- tput sc
- git clone https://github.com/jgarff/rpi_ws281x /tmp/rpi_ws281x # TODO CHANGE PATH
- python /tmp/rpi_ws281x/python/setup.py install # TODO CHANGE PAHT
- if [ $? -eq 0 ]; then
- tput rc; tput ed
- printf "โœ“"
- else
- printf "\nInstall failed.\n"
- exit 1
- fi
-fi
-
-tput setaf 4
-printf ". Installing the app itself...\n"
-tput sgr0
-
# Create user 'luxcena-neo'
tput setaf 8
-printf '%s\n' " - Creating user 'lux-neo'..."
+printf '%s\n' "- Creating user 'lux-neo'..."
tput sgr0
username="lux-neo"
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
- echo "User already exists, continuing..."
+ echo "User already exists, continuing..."
else
- #pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
- useradd -m $username &>> $LOG || die
+ useradd -m $username || die
fi
+usermod -a -G gpio $username
+usermod -a -G spi $username
# First we make our directories
tput setaf 8
-printf '%s\n' " - Making app-dir (/bin/luxcena-neo)..."
-tput sgr0
-userDir=$(eval echo "~$username")
-#mkdir -p "$userDir/install" &>> $LOG || die
-#chown $username:$username "$userDir/install" &>> $LOG || die
-mkdir -p "$userDir/src" &>> $LOG || die
-chown $username:$username "$userDir/src" &>> $LOG || die
-mkdir -p "$userDir/userdata" &>> $LOG || die
-chown $username:$username "$userDir/userdata" &>> $LOG || die
-
-# Third we copy the source into the correct swap-folder
-tput setaf 8
-printf '%s\n' " - Copying sourceCode to app-dir..."
+printf '%s\n' "- Making directories..."
tput sgr0
-cp -r . "$userDir/src" &>> $LOG || die
-chown -R $username:$username "$userDir/src" &>> $LOG || die
-
-# fourth we run npm i
-tput setaf 8
-printf '%s\n' " - Running npm i..."
-tput sgr0
-tput sc
-export NODE_ENV=production &>> $LOG || die
-runuser -l $username -c 'npm --prefix ~/src install ~/src --only=production' &>> $LOG || die # This is probably a bit overkill to have --only=... but better safe than sorry?
-tput rc; tput ed
+[ -d "/opt/luxcena-neo/" ] && echo "Seems like luxcena-neo is already installed, please do update instead" && die
+mkdir -p "/opt/luxcena-neo" || die
+chown $username:$username "/opt/luxcena-neo" || die
+mkdir -p "/var/luxcena-neo" || die
+chown $username:$username "/var/luxcena-neo" || die
+mkdir -p "/etc/luxcena-neo" || die
+chown $username:$username "/etc/luxcena-neo" || die
+mkdir -p "/var/log/luxcena-neo" || die
+chown $username:$username "/var/log/luxcena-neo" || die
+
+printf '%s' "Which branch do you want to install (default: master)? "
+read BRANCH
+if [ -z "$BRANCH" ]; then
+ BRANCH="master"
+fi
-# fourth we copy the cli to our bin folder
+# Get source code
tput setaf 8
-printf '%s\n' " - Adding cli-script..."
+printf '%s\n' "- Fetch source code..."
tput sgr0
-cp bin/luxcena-neo-cli.sh /usr/bin/luxcena-neo-cli.sh &>> $LOG || die
-ln -sf /usr/bin/luxcena-neo-cli.sh /usr/bin/lux-neo &>> $LOG || die
-tput rc; tput ed
+runuser -l $username -c "git clone -b $BRANCH https://github.com/jakobst1n/luxcena-neo /opt/luxcena-neo/" || die
-# Fifth we add the service files
+# Install all packages, build the app, and prepare everything
tput setaf 8
-printf '%s\n' " - Adding service-file to systemd..."
+printf '%s\n' "- Running installer (updater) from newly fetched source code..."
tput sgr0
-cp bin/luxcena-neo.service /etc/systemd/system/luxcena-neo.service &>> $LOG || die
-systemctl daemon-reload &>> $LOG || die
+/opt/luxcena-neo/bin/luxcena-neo-cli.sh update || die
# Installation is done!
printf '\n\e[5m%s\e[0m\n' "๐ŸŽ‰Luxcena-Neo is now installed๐ŸŽ‰"
-printf 'You can now delete this folder'
diff --git a/bin/luxcena-neo-cli.sh b/bin/luxcena-neo-cli.sh
index defb766..872b819 100755
--- a/bin/luxcena-neo-cli.sh
+++ b/bin/luxcena-neo-cli.sh
@@ -65,16 +65,52 @@ if [ "$action" == "update" ]; then
exit 1
fi
+ # Stop the service if it is running already
systemctl stop luxcena-neo
- runuser -l 'lux-neo' -c 'git -C ~/src pull'
+ # Go to source code directory
+ WDIR="/opt/luxcena-neo"
+ #cd "$WDIR"
+
+ # Fetch newest changes on branch
+ runuser -l 'lux-neo' -c "git -C $WDIR pull" || die
+
+ # Add node repo
+ curl -fsSL https://deb.nodesource.com/setup_14.x | bash - || die
+
+ # Make sure nodejs and prerequisites is installed
+ apt -qy install nodejs python-pip || die
+
+ # Make sure we have python virtualenv installed
+ pip3 install virtualenv || die
+
+ # Create and configure python virtualenv
+ runuser -l 'lux-neo' -c "rm -rf $WDIR/NeoRuntime/Runtime/venv" || die
+ runuser -l 'lux-neo' -c "virtualenv -p /usr/bin/python3 $WDIR/NeoRuntime/Runtime/venv" || die
+ runuser -l 'lux-neo' -c "source $WDIR/NeoRuntime/Runtime/venv/bin/activate && pip install rpi_ws281x" || die
+
+ # Build and run all npm scripts
if [ "$2" != "skipNode" ]; then
- runuser -l 'lux-neo' -c 'export NODE_ENV=production; npm --prefix ~/src install ~/src --only=production'
+ runuser -l 'lux-neo' -c "export NODE_ENV=development; npm --prefix $WDIR install $WDIR" || die
fi
+ ##runuser -l 'lux-neo' -c "cd $WDIR && npm run build:frontend" || die
+ ##runuser -l 'lux-neo' -c "cd $WDIR && npm run build:fontawesome" || die
+ ##runuser -l 'lux-neo' -c "cd $WDIR && npm run build:dialog-polyfill" || die
+ runuser -l 'lux-neo' -c "npm --prefix \"$WDIR\" run build:frontend" || die
+ runuser -l 'lux-neo' -c "npm --prefix \"$WDIR\" run build:fontawesome" || die
+ runuser -l 'lux-neo' -c "npm --prefix \"$WDIR\" run build:dialog-polyfill" || die
+
+
+ # Install new cli script
+ cp /opt/luxcena-neo/bin/luxcena-neo-cli.sh /usr/bin/luxcena-neo-cli.sh || die
+
+ # Install updated systemd script
+ cp /opt/luxcena-neo/bin/luxcena-neo.service /etc/systemd/system/luxcena-neo.service || die
+ systemctl daemon-reload || die
- cp /home/lux-neo/src/bin/luxcena-neo-cli.sh /usr/bin/luxcena-neo-cli.sh
printf "Update complete.\n"
systemctl start luxcena-neo
+ systemctl enable luxcena-neo
exit 0
elif [ "$action" == "uninstall" ]; then
@@ -83,13 +119,14 @@ elif [ "$action" == "uninstall" ]; then
tput sgr0
printf '\e[93m%s\e[0m\n' "--------------------------"
tput setaf 8
- printf "By uninstalling Luxcena-Neo you will loose all you data, including your scripts.\n\n"
+ printf "By uninstalling Luxcena-Neo you might loose all data, including your scripts.\n\n"
dlgYN "Are you sure you want to uninstall?" res
if [ $res -eq 1 ]; then
systemctl stop luxcena-neo
deluser lux-neo
rm -rf /home/lux-neo
+ rm -rf /opt/luxcena-neo
rm /etc/systemd/system/luxcena-neo.service
rm /usr/bin/luxcena-neo.sh
rm /usr/bin/lux-neo
@@ -97,6 +134,7 @@ elif [ "$action" == "uninstall" ]; then
tput setaf 2
printf "\nEverything should now be gone.\n"
+ printf "/etc/luxcena-neo and /var/log/luxcena-neo is not removed.\n"
tput sgr0
tput setaf 8
printf "Well, some dependencies still exists. Those are:\n"
@@ -105,9 +143,6 @@ elif [ "$action" == "uninstall" ]; then
tput sgr0
fi
-elif [ "$action" == "conf" ]; then
- nano /home/lux-neo/userdata/config/strip.json
-
elif [ "$action" == "start" ]; then
systemctl start luxcena-neo
if [ "$2" == "boot" ]; then
@@ -141,23 +176,23 @@ elif [ "$action" == "status" ]; then
elif [ "$action" == "log" ]; then
if [ "$2" == "service" ]; then
printf '\e[93m%s\e[0m\n' "โ”โ”โ”Service log (press ctrl+c to exit)โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”"
- tail -F -n 20 /home/lux-neo/logs/service.log
+ tail -F -n 20 /var/log/luxcena-neo/service.log
fi
if [ "$2" == "app" ]; then
printf '\e[93m%s\e[0m\n' "โ”โ”โ”App log (press ctrl+c to exit)โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”"
- tail -F -n 20 /home/lux-neo/logs/logger.log
+ tail -F -n 20 /var/log/luxcena-neo/logger.log
fi
elif [ "$action" == "version" ] || [ "$action" == "v" ]; then
printf "โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ\n"
printf "โ”‚ Version: Unknown โ”‚\n"
- printf "โ”‚ branch : $(git -C /home/lux-neo/src branch | grep \* | cut -d ' ' -f2) โ”‚\n"
+ printf "โ”‚ branch : $(git -C /opt/luxcena-neo branch | grep \* | cut -d ' ' -f2) โ”‚\n"
printf "โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ\n\n"
elif [ "$action" == "selectBranch" ]; then
- printf "Current $(git -C /home/lux-neo/src branch | grep \* | cut -d ' ' -f2)Branch \n"
- runuser -l 'lux-neo' -c "git -C ~/src stash"
- runuser -l 'lux-neo' -c "git -C ~/src checkout $2" || printf "\e[91mYou should now run \e[90m'sudo lux-neo update'\e[91m!\n"
+ printf "Current $(git -C /opt/luxcena-neo branch | grep \* | cut -d ' ' -f2)Branch \n"
+ runuser -l 'lux-neo' -c "git -C /opt/luxcena-neo stash"
+ runuser -l 'lux-neo' -c "git -C /opt/luxcena-neo checkout $2" || printf "\e[91mYou should now run \e[90m'sudo lux-neo update'\e[91m!\n"
else
usage
diff --git a/bin/luxcena-neo.service b/bin/luxcena-neo.service
index efea1ad..b4115be 100644
--- a/bin/luxcena-neo.service
+++ b/bin/luxcena-neo.service
@@ -2,13 +2,13 @@
Description=Luxcena Neo
[Service]
-ExecStart=/home/lux-neo/src/bin/luxcena-neo.sh
+ExecStart=/opt/luxcena-neo/bin/luxcena-neo.sh
Restart=always
RestartSec=10
Environment=PATH=/usr/bin:/usr/local/bin
-Environment=NODE_ENV=production
-WorkingDirectory=/home/lux-neo/src/
+Environment=NODE_ENV=development
+WorkingDirectory=/opt/luxcena-neo/
[Install]
WantedBy=multi-user.target
diff --git a/bin/luxcena-neo.sh b/bin/luxcena-neo.sh
index fc41f75..a861d87 100755
--- a/bin/luxcena-neo.sh
+++ b/bin/luxcena-neo.sh
@@ -5,5 +5,5 @@
# the server needs root as well.
#runuser -l pi -c "export NODE_ENV=production; node ~/luxcena-neo-install/src/app.js"
-export NODE_ENV=production
-node /home/lux-neo/src/app.js >> /home/lux-neo/logs/service.log
+export NODE_ENV=development
+node /opt/luxcena-neo/app.js >> /var/log/luxcena-neo/service.log
diff --git a/src/NeoRuntimeManager/RuntimeProcess.js b/src/NeoRuntimeManager/RuntimeProcess.js
index 60c1de9..562bb0e 100644
--- a/src/NeoRuntimeManager/RuntimeProcess.js
+++ b/src/NeoRuntimeManager/RuntimeProcess.js
@@ -30,8 +30,8 @@ class RuntimeProcess {
"python3",
[
"-u", // This makes us able to get real-time output
- `${__basedir}/NeoRuntime/Runtime/neo_runtime.py`,
- `--strip-config="${__datadir}/config/strip.ini"`,
+ `${__appdir}/NeoRuntime/Runtime/neo_runtime.py`,
+ `--strip-config="${__configdir}/strip.ini"`,
`--mode-path="${this.modePath}"`,
`--mode-entry=script`
]
diff --git a/src/NeoRuntimeManager/index.js b/src/NeoRuntimeManager/index.js
index 6238323..4377b8a 100644
--- a/src/NeoRuntimeManager/index.js
+++ b/src/NeoRuntimeManager/index.js
@@ -9,7 +9,7 @@ const fs = require("fs");
const fsPromises = fs.promises;
const RuntimeProcess = require("./RuntimeProcess");
const IPC = require("./IPC");
-let logger = require(__basedir + "/src/logger");
+const logger = require(__appdir + "/src/Logger");
const EventEmitter = require('events');
/** @type {object} this should be a pointer to a object referencing all neoModules (see app.js) */
@@ -54,7 +54,7 @@ function isMode(path) {
*/
function listModes() {
let modeDirs = [
- ["builtin/", fs.readdirSync(__basedir + "/NeoRuntime/builtin")],
+ ["builtin/", fs.readdirSync(__appdir + "/NeoRuntime/builtin")],
["remote/", fs.readdirSync(__datadir + "/remoteCode")],
["user/", fs.readdirSync(__datadir + "/userCode")]
]
@@ -162,7 +162,7 @@ function getModePath(modeId) {
let location = path.splice(0, 1).toString();
if (location === "user") { path = __datadir + "/userCode/" + path.join("/"); }
if (location === "remote") { path = __datadir + "/remoteCode/" + path.join("/"); }
- if (location === "builtin") { path = __basedir + "/NeoRuntime/builtin/" + path.join("/"); }
+ if (location === "builtin") { path = __appdir + "/NeoRuntime/builtin/" + path.join("/"); }
return path;
}
@@ -308,4 +308,4 @@ module.exports = (_neoModules) => {
startDebugger, stopDebugger, saveModeCode,
startMode, stopMode, restartMode
}
-}; \ No newline at end of file
+};
diff --git a/src/SSLCert/index.js b/src/SSLCert/index.js
index 6dad579..d235c9b 100644
--- a/src/SSLCert/index.js
+++ b/src/SSLCert/index.js
@@ -7,7 +7,7 @@
* @author jakobst1n.
* @since 14.16.2019
*/
- let logger = require(__basedir + "/src/logger");
+ let logger = require(__appdir + "/src/Logger");
const fs = require("fs");
const { execSync } = require("child_process");
@@ -20,7 +20,7 @@ var neoModules;
class CertMon {
constructor(configPath, certPath, httpsConfig) {
- this.certPath = __datadir + "/config/certs/";
+ this.certPath = __configdir + "/certs/";
let valid = this.checkValidity();
if (!valid) {
@@ -141,4 +141,4 @@ module.exports = (_neoModules) => {
neoModules = _neoModules;
return new CertMon();
};
- \ No newline at end of file
+
diff --git a/src/SelfUpdater/index.js b/src/SelfUpdater/index.js
index 3c5546b..5a9baa3 100644
--- a/src/SelfUpdater/index.js
+++ b/src/SelfUpdater/index.js
@@ -2,14 +2,14 @@ let fs = require("fs-extra");
let url = require("url");
let request = require('request');
let exec = require("child_process").exec;
-let logger = require(__basedir + "/src/logger");
+let logger = require(__appdir + "/src/Logger");
let neoModules;
class VersionChecker {
constructor() {
- this.CPackageJson = JSON.parse(fs.readFileSync(__basedir + "/package.json"));
+ this.CPackageJson = JSON.parse(fs.readFileSync(__appdir + "/package.json"));
this.version = this.CPackageJson["version"];
this.repoLink = this.CPackageJson["repository"]["url"];
diff --git a/src/SocketIO/index.js b/src/SocketIO/index.js
index 8d06947..2a625ed 100644
--- a/src/SocketIO/index.js
+++ b/src/SocketIO/index.js
@@ -8,7 +8,7 @@
* @since 19.12.2019
*/
-let logger = require(__basedir + "/src/logger");
+let logger = require(__appdir + "/src/Logger");
var exec = require('child_process').exec;
var CryptoJS = require("crypto-js");
let fs = require("fs");
@@ -350,4 +350,4 @@ module.exports = (_neoModules, io) => {
authorizedNamespace: createAuthorizedNamespace(io)
}
};
- \ No newline at end of file
+
diff --git a/src/UserData/index.js b/src/UserData/index.js
index 704c5d5..751c265 100644
--- a/src/UserData/index.js
+++ b/src/UserData/index.js
@@ -6,7 +6,7 @@
* @since 19.12.2019
*/
-let logger = require(__basedir + "/src/logger");
+let logger = require(__appdir + "/src/Logger");
let fse = require("fs-extra");
let ini = require('ini');
@@ -16,7 +16,7 @@ let neoModules;
* This method will ensure that all required fields are in config.ini
*/
function ensureMainConfig() {
- var config = ini.decode(fse.readFileSync(__datadir + "/config/config.ini", 'utf-8'))
+ var config = ini.decode(fse.readFileSync(__configdir + "/config.ini", 'utf-8'))
if (config.instanceName == null) { config.instanceName = "neoStrip"; }
if (config.activeMode == null) { config.activeMode = "builtin/static"; }
@@ -43,14 +43,14 @@ function ensureMainConfig() {
if (config.neoRuntimeIPC == null) { config.neoRuntimeIPC = {}; }
if (config.neoRuntimeIPC.socketFile == null) { config.neoRuntimeIPC.socketFile = "/tmp/neo_runtime.sock"; }
- fse.writeFileSync(__datadir + "/config/config.ini", ini.encode(config))
+ fse.writeFileSync(__configdir + "/config.ini", ini.encode(config))
}
/**
* This method will ensure that all required fields are in config.ini
*/
function ensureStripConfig() {
- var config = ini.decode(fse.readFileSync(__datadir + "/config/strip.ini", 'utf-8'))
+ var config = ini.decode(fse.readFileSync(__configdir + "/strip.ini", 'utf-8'))
if (config.DEFAULT == null) { config.DEFAULT = {}; }
if (config.DEFAULT.led_pin == null) { config.DEFAULT.led_pin = 18; }
@@ -61,7 +61,7 @@ function ensureStripConfig() {
if (config.DEFAULT.segments == null) { config.DEFAULT.segments = ""; }
if (config.DEFAULT.matrix == null) { config.DEFAULT.matrix = ""; }
- fse.writeFileSync(__datadir + "/config/strip.ini", ini.encode(config))
+ fse.writeFileSync(__configdir + "/strip.ini", ini.encode(config))
}
/**
@@ -73,24 +73,24 @@ function init() {
logger.info("Ensuring all folder in UserDir exists...");
fse.ensureDirSync(__datadir + "/");
- fse.ensureDirSync(__datadir + "/config/");
- fse.ensureDirSync(__datadir + "/config/certs");
+ fse.ensureDirSync(__configdir);
+ fse.ensureDirSync(__configdir + "/certs");
fse.ensureDirSync(__datadir + "/userCode/");
fse.ensureDirSync(__datadir + "/remoteCode/");
// Generate config-files
- if (!fse.existsSync(__datadir + "/config/config.ini")) {
- fse.closeSync(fse.openSync(__datadir + "/config/config.ini", 'w'));
+ if (!fse.existsSync(__configdir + "/config.ini")) {
+ fse.closeSync(fse.openSync(__configdir + "/config.ini", 'w'));
}
ensureMainConfig();
- if (!fse.existsSync(__datadir + "/config/strip.ini")) {
- fse.closeSync(fse.openSync(__datadir + "/config/strip.ini", 'w'));
+ if (!fse.existsSync(__configdir + "/strip.ini")) {
+ fse.closeSync(fse.openSync(__configdir + "/strip.ini", 'w'));
}
ensureStripConfig();
- if (!fse.existsSync(__datadir + "/config/users.ini")) {
- fse.writeFileSync(__datadir + "/config/users.ini", ini.encode({
+ if (!fse.existsSync(__configdir + "/users.ini")) {
+ fse.writeFileSync(__configdir + "/users.ini", ini.encode({
"neo": {
"password": "5adbc90fb4716fff62d9cf634837e22f29b011803ba29cee51f921b920fa941651737bd15d00dc72e4cbeee5e64e06ec99cc50ea917285a029797a98740cce0f",
"salt": "59b6de1040f3ae3c63de984ca5d61ef46f41dc6ecead3a9d5dab69f0bb3636aa49017e179b74dbcdb407f62bc139a7d55aa78fe2bbdd5327609ea124b2fa03b1"
@@ -196,11 +196,11 @@ function getFullConfig(file, addSetters=true) {
* @return {object} Standardform return object
*/
function saveUser(username, salt, password) {
- let config = ini.decode(fse.readFileSync(__datadir + "/config/users.ini", 'utf-8'))
+ let config = ini.decode(fse.readFileSync(__configdir + "/users.ini", 'utf-8'))
config[username] = {}
config[username].salt = salt
config[username].password = password
- fse.writeFileSync(__datadir + "/config/users.ini", ini.encode(config))
+ fse.writeFileSync(__configdir + "/users.ini", ini.encode(config))
return {success: true}
}
@@ -210,7 +210,7 @@ function getFullConfig(file, addSetters=true) {
* @return {object} with username, salt and hash properties.
*/
function getUser(username) {
- let config = ini.decode(fse.readFileSync(__datadir + "/config/users.ini", 'utf-8'))
+ let config = ini.decode(fse.readFileSync(__configdir + "/users.ini", 'utf-8'))
if (Object.prototype.hasOwnProperty.call(config, username)) {
return {...config[username], username: username}
}
@@ -223,7 +223,7 @@ function getUser(username) {
* @return {array} usernames
*/
function getUsers() {
- let config = ini.decode(fse.readFileSync(__datadir + "/config/users.ini", "utf-8"));
+ let config = ini.decode(fse.readFileSync(__configdir + "/users.ini", "utf-8"));
let users = [];
for (const username of Object.keys(config)) {
users.push(username);
@@ -237,11 +237,11 @@ function getUsers() {
* @return {object} Standardform success object.
*/
function deleteUser(username) {
- let config = ini.decode(fse.readFileSync(__datadir + "/config/users.ini", 'utf-8'))
+ let config = ini.decode(fse.readFileSync(__configdir + "/users.ini", 'utf-8'))
if (config.length <= 1) { return {success: false, reason: "cannot delete only user"}; }
if (!Object.prototype.hasOwnProperty.call(config, username)) { return {success: false, reason: "user not found", detail: username}; }
delete config[username];
- fse.writeFileSync(__datadir + "/config/users.ini", ini.encode(config));
+ fse.writeFileSync(__configdir + "/users.ini", ini.encode(config));
return {success: true}
}
@@ -257,7 +257,7 @@ function deleteUser(username) {
function createNewUserMode(name, template) {
source_script = null;
if ((template === "template/base") || (template === "") || (template == null)) {
- source_script = __basedir + "/NeoRuntime/special/template_base/";
+ source_script = __appdir + "/NeoRuntime/special/template_base/";
} else {
source_script = neoModules.neoRuntimeManager.getModePath(template);
}
@@ -313,7 +313,7 @@ module.exports = (_neoModules) => {
},
strip: {
get: () => {
- let c = getFullConfig(`${__datadir}/config/strip.ini`, addSetters=false);
+ let c = getFullConfig(`${__configdir}/strip.ini`, addSetters=false);
c.DEFAULT.matrix = JSON.parse(c.DEFAULT.matrix);
c.DEFAULT.segments = c.DEFAULT.segments.split(" ");
return c.DEFAULT;
@@ -321,13 +321,13 @@ module.exports = (_neoModules) => {
set: (c) => {
c.segments = c.segments.join(" ");
c.matrix = JSON.stringify(c.matrix);
- return saveConfig(`${__datadir}/config/strip.ini`, {DEFAULT: c}, removeSetters=false);
+ return saveConfig(`${__configdir}/strip.ini`, {DEFAULT: c}, removeSetters=false);
},
},
- config: getFullConfig(`${__datadir}/config/config.ini`),
+ config: getFullConfig(`${__configdir}/config.ini`),
mode: {
create: createNewUserMode,
delete: deleteUserMode
}
}
-}; \ No newline at end of file
+};