aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/install.sh27
-rwxr-xr-xbin/luxcena-neo-cli.sh115
-rw-r--r--bin/luxcena-neo.service6
-rwxr-xr-xbin/luxcena-neo.sh2
-rwxr-xr-xbin/post-update.sh7
5 files changed, 102 insertions, 55 deletions
diff --git a/bin/install.sh b/bin/install.sh
index 2ccb7e0..cd4f07b 100755
--- a/bin/install.sh
+++ b/bin/install.sh
@@ -111,19 +111,19 @@ 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/install/src" &>> $LOG || die
-chown $username:$username "$userDir/install/src" &>> $LOG || die
-mkdir -p "$userDir/install/userdata" &>> $LOG || die
-chown $username:$username "$userDir/install/userdata" &>> $LOG || die
+#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..."
tput sgr0
-cp -r . "$userDir/install/src" &>> $LOG || die
-chown -R $username:$username "$userDir/install/src" &>> $LOG || die
+cp -r . "$userDir/src" &>> $LOG || die
+chown -R $username:$username "$userDir/src" &>> $LOG || die
# fourth we run npm i
tput setaf 8
@@ -131,7 +131,15 @@ printf '%s\n' " - Running npm i..."
tput sgr0
tput sc
export NODE_ENV=production &>> $LOG || die
-runuser -l $username -c 'npm --prefix ~/install/src install ~/install/src --only=production' &>> $LOG || die # This is probably a bit overkill to have --only=... but better safe than sorry?
+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
+
+# fourth we copy the cli to our bin folder
+tput setaf 8
+printf '%s\n' " - Adding cli-script..."
+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
# Fifth we add the service files
@@ -143,3 +151,4 @@ systemctl daemon-reload &>> $LOG || 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 034d713..180b0c4 100755
--- a/bin/luxcena-neo-cli.sh
+++ b/bin/luxcena-neo-cli.sh
@@ -5,6 +5,38 @@ usage() {
exit 1
}
+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"
+ 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
+}
+
while getopts ":a:" o; do
case "${o}" in
a )
@@ -25,14 +57,21 @@ if [ "$action" == "update" ]; then
tput sgr0
printf '\e[93m%s\e[0m\n\n' "-------------------"
- sudo systemctl stop lxucena-neo
- oldDir=$PWD
- cd ~/luxcena-neo-install
- git pull
- export NODE_ENV=production
- npm i --only=production
- cd $oldDir
- sudo systemctl start luxcena-neo
+ if [ "$EUID" -ne 0 ]; then
+ echo "You need to run this script as root."
+ echo "Try running with 'sudo ./bin/install.sh'"
+ exit 1
+ fi
+
+ systemctl stop luxcena-neo
+ runuser -l 'lux-neo' -c 'git -C ~/src pull'
+ runuser -l 'lux-neo' -c 'export NODE_ENV=production; npm --prefix ~/src install ~/src --only=production'
+ cp /home/lux-neo/src/bin/luxcena-neo-cli.sh /usr/bin/luxcena-neo-cli.sh
+ printf "Update complete.\n"
+ #printf "Update complete, run these commands to finish it completly:\n"
+ #printf "sudo /home/lux-neo/src/bin/post-update.sh\n"
+ #printf "sudo systemctl luxcena-neo start\n"
+ systemctl start luxcena-neo
elif [ "$action" == "uninstall" ]; then
tput setab 1
@@ -42,43 +81,37 @@ elif [ "$action" == "uninstall" ]; then
tput setaf 8
printf "By uninstalling Luxcena-Neo you will loose all you data, including your scripts.\n\n"
- tput sc
- tput setaf 4
- printf ". Are you sure you want to uninstall (y/n)? "
- while :
- do
- read -n 1 -p "" YNQuestionAnswer
- if [[ $YNQuestionAnswer == "y" ]]; then
- tput rc; tput el
- printf ". Are you sure you want to uninstall? \e[0;32mYes\e[0m\n"
- tput sc
- sudo systemctl stop luxcena-neo || { printf "\n\nUninstall failed.\n"; exit 1; }
- rm -rf ~/luxcena-neo-install || { printf "\n\nUninstall failed.\n"; exit 1; }
- sudo rm /etc/systemd/system/luxcena-neo.service || { printf "\n\nUninstall failed.\n"; exit 1; }
- tput rc; tput ed
+ 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 /etc/systemd/system/luxcena-neo.service
+ rm /usr/bin/luxcena-neo.sh
+ rm /usr/bin/lux-neo
- tput setaf 2
- printf "\nEverything should now be gone. To remove the last piece, enter this command:\n"
- tput sgr0
- tput smso
- printf "sudo rm /bin/luxcena-neo\n\n"
- tput sgr0
- tput setaf 8
- printf "Well, some dependencies still exists. Those are:\n"
- printf " - rpi_ws281x-library\n"
- printf " - packages (nodejs scons python-dev swig)\n"
- break
- elif [[ $YNQuestionAnswer == "n" ]]; then
- tput rc; tput el
- printf ". Are you sure you want to uninstall? \e[0;31mNo\e[0m\n"
- break
- fi
- done
+
+ tput setaf 2
+ printf "\nEverything should now be gone.\n"
+ tput sgr0
+ tput setaf 8
+ printf "Well, some dependencies still exists. Those are:\n"
+ printf " - rpi_ws281x-library\n"
+ printf " - packages (nodejs scons python-dev swig)\n"
+ tput sgr0
+ fi
+
+elif [ "$action" == "conf" ]; then
+ nano /home/lux-neo/userdata/config/strip.json
elif [ "$action" == "start" ]; then
- sudo systemctl start luxcena-neo
+ systemctl start luxcena-neo
elif [ "$action" == "stop" ]; then
- sudo systemctl stop luxcena-neo
+ systemctl stop luxcena-neo
+elif [ "$action" == "status" ]; then
+ printf '\e[93m%s\e[0m\n' "---Service status------------------"
+ systemctl status luxcena-neo
+ printf '\e[93m%s\e[0m\n' "-----------------------------------"
else
usage
fi
diff --git a/bin/luxcena-neo.service b/bin/luxcena-neo.service
index c20a844..efea1ad 100644
--- a/bin/luxcena-neo.service
+++ b/bin/luxcena-neo.service
@@ -2,15 +2,13 @@
Description=Luxcena Neo
[Service]
-ExecStart=/home/lux-neo/install/src/bin/luxcena-neo.sh
+ExecStart=/home/lux-neo/src/bin/luxcena-neo.sh
Restart=always
RestartSec=10
-User=nobody
-Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
-WorkingDirectory=/home/lux-neo/install/src/
+WorkingDirectory=/home/lux-neo/src/
[Install]
WantedBy=multi-user.target
diff --git a/bin/luxcena-neo.sh b/bin/luxcena-neo.sh
index 8455bf3..fc41f75 100755
--- a/bin/luxcena-neo.sh
+++ b/bin/luxcena-neo.sh
@@ -6,4 +6,4 @@
#runuser -l pi -c "export NODE_ENV=production; node ~/luxcena-neo-install/src/app.js"
export NODE_ENV=production
-node /home/lux-neo/install/src/app.js
+node /home/lux-neo/src/app.js >> /home/lux-neo/logs/service.log
diff --git a/bin/post-update.sh b/bin/post-update.sh
new file mode 100755
index 0000000..01b0fee
--- /dev/null
+++ b/bin/post-update.sh
@@ -0,0 +1,7 @@
+oldDir=$PWD
+cd /home/lux-neo/src
+
+cp bin/luxcena-neo-cli.sh /usr/bin/luxcena-neo-cli.sh
+
+cd $oldDir
+echo "Post-update done..."