aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-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
4 files changed, 81 insertions, 132 deletions
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