diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/install.sh | 182 | ||||
-rwxr-xr-x | bin/luxcena-neo-cli.sh | 84 | ||||
-rw-r--r-- | bin/luxcena-neo.service | 16 | ||||
-rwxr-xr-x | bin/luxcena-neo.sh | 3 | ||||
-rwxr-xr-x | bin/runDev.sh | 12 |
5 files changed, 297 insertions, 0 deletions
diff --git a/bin/install.sh b/bin/install.sh new file mode 100755 index 0000000..c72949b --- /dev/null +++ b/bin/install.sh @@ -0,0 +1,182 @@ +#!/bin/bash + +tput rev +printf '%s\n' "Luxcena-neo Installer" +tput sgr0 +printf '\e[93m%s\e[0m\n\n' "---------------------" + +if [ $USER != "pi" ]; then + printf "Install failed...\nOther user than 'pi' detected. If you want to use another user, you have to install manually." + exit 1 +fi + +# Update system +tput sc +tput setaf 4 +printf ". Update your system (y/n)? " +while : +do + read -n 1 -p "" YNQuestionAnswer + if [[ $YNQuestionAnswer == "y" ]]; then + tput rc; tput el + printf ". Update your system?: \e[0;32mYes\e[0m\n" + tput sc + sudo apt-get -y -qq update || { printf "\n\nInstall failed.\n"; exit 1; } + sudo apt-get -y -qq upgrade || { printf "\n\nInstall failed.\n"; exit 1; } + tput rc; tput ed + break + elif [[ $YNQuestionAnswer == "n" ]]; then + tput rc; tput el + printf ". Update your system?: \e[0;31mNo\e[0m\n" + break + fi +done + +# Install packages +tput sc +tput setaf 4 +printf ". Install required packages (y/n)? " +while : +do + read -n 1 -p "" YNQuestionAnswer + if [[ $YNQuestionAnswer == "y" ]]; then + tput rc; tput el + printf ". Install required packages?: \e[0;32mYes\e[0m\n" + tput sc + sudo apt-get -y -qq install nodejs scons python-dev swig || { printf "\n\nInstall failed.\n"; exit 1; } + if [ $? -eq 0 ]; then + tput rc; tput ed + printf "✓" + else + printf "\nInstall failed.\n" + exit 1 + fi + break + elif [[ $YNQuestionAnswer == "n" ]]; then + tput rc; tput el + printf ". Install required packages?: \e[0;31mNo\e[0m\n" + 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 + break + fi +done + +# Install led-library +tput sc +tput setaf 4 +printf ". Install jgarff's rpi_ws281x library (y/n)? " +while : +do + read -n 1 -p "" YNQuestionAnswer + if [[ $YNQuestionAnswer == "y" ]]; then + tput rc; tput el + printf ". Install jgarff's rpi_ws281x library?: \e[0;32mYes\e[0m\n" + 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 + break + elif [[ $YNQuestionAnswer == "n" ]]; then + tput rc; tput el + printf ". Install jgarff's rpi_ws281x library?: \e[0;31mNo\e[0m\n" + break + fi +done + + +tput setaf 4 +printf ". Which rPi is this? (j:↓, k:↑, ↩:↩)\n" +tput sgr0 +tput sc +tput bel + +piModel=0 +printf "\n\n\n" # So that the menu just erases things it has alredy written +while : +do + tput cuu 3 + tput ed + tput sc + tput setaf 8 + + if [[ piModel -eq 0 ]]; then + tput sgr0; fi + printf '%s\n' "- Raspberry Pi B" + tput setaf 8 + if [[ piModel -eq 1 ]]; then + tput sgr0; fi + printf '%s\n' "- Raspberry Pi B+" + tput setaf 8 + if [[ piModel -eq 2 ]]; then + tput sgr0; fi + printf '%s\n' "- Raspberry Pi Model 2" + tput setaf 8 + + read -sn1 key + if [ "$key" == "j" ]; then + piModel=$((piModel+1)) + if [[ piModel -gt 2 ]]; then + piModel=2 + fi + fi + if [ "$key" == "k" ]; then + piModel=$((piModel-1)) + if [[ piModel -lt 0 ]]; then + piModel=0 + fi + fi + if [ "$key" == "" ]; then + tput cuu 4 + tput ed + tput sgr0 + printf "%s\e[0;34m%s\e[0m\n" ". Which rPi is this? " "ListItem #$piModel" + break + fi + +done + + +tput setaf 4 +printf ". Installing the app itself...\n" +tput sgr0 + +# First we make our directories +tput setaf 8 +printf '%s\n' " - Making app-dir (/bin/luxcena-neo)..." +tput sgr0 +mkdir ~/luxcena-neo-install || { printf "\n\nInstall failed.\n"; exit 1; } +mkdir ~/luxcena-neo-install/src || { printf "\n\nInstall failed.\n"; exit 1; } +mkdir ~/luxcena-neo-install/userdata || { printf "\n\nInstall failed.\n"; exit 1; } + +# 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 . ~/luxcena-neo-install/src || { printf "\n\nInstall failed.\n"; exit 1; } + +# fourth we run npm i +tput setaf 8 +printf '%s\n' " - Running npm i..." +tput sgr0 +tput sc +export NODE_ENV=production || { printf "\n\nInstall failed.\n"; exit 1; } +npm --prefix ~/luxcena-neo-install/src install ~/luxcena-neo-install/src --only=production || { printf "\n\nInstall failed.\n"; exit 1; } # This is probably a bit overkill to have --only=... but better safe than sorry? +tput rc; tput ed + +# Fifth we add the service files +tput setaf 8 +printf '%s\n' " - Adding service-file to systemd..." +tput sgr0 +sudo cp bin/luxcena-neo.service /etc/systemd/system/luxcena-neo.service +sudo systemctl daemon-reload + +# Installation is done! +printf '\n\e[5m%s\e[0m\n' "🎉Luxcena-Neo is now installed🎉" diff --git a/bin/luxcena-neo-cli.sh b/bin/luxcena-neo-cli.sh new file mode 100755 index 0000000..034d713 --- /dev/null +++ b/bin/luxcena-neo-cli.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +usage() { + printf "Usage: $0 update/uninstall/start/stop\n" 1>&2 + exit 1 +} + +while getopts ":a:" o; do + case "${o}" in + a ) + p=${OPTARG} + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) + +action=$1 +if [ "$action" == "update" ]; then + + tput rev + printf '%s\n' "Luxcena-neo Updater" + 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 + +elif [ "$action" == "uninstall" ]; then + tput setab 1 + printf '%s\n' "Luxcena Neo Uninstaller..." + 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" + + 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 + + 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 + +elif [ "$action" == "start" ]; then + sudo systemctl start luxcena-neo +elif [ "$action" == "stop" ]; then + sudo systemctl stop luxcena-neo +else + usage +fi diff --git a/bin/luxcena-neo.service b/bin/luxcena-neo.service new file mode 100644 index 0000000..62111a6 --- /dev/null +++ b/bin/luxcena-neo.service @@ -0,0 +1,16 @@ +[Unit] +Description=Luxcena Neo + +[Service] +ExecStart=/home/pi/luxcena-neo-install/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/pi/luxcena-neo-install/src/ + +[Install] +WantedBy=multi-user.target diff --git a/bin/luxcena-neo.sh b/bin/luxcena-neo.sh new file mode 100755 index 0000000..4467d06 --- /dev/null +++ b/bin/luxcena-neo.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +runuser -l pi -c "export NODE_ENV=production; node ~/luxcena-neo-install/src/app.js" diff --git a/bin/runDev.sh b/bin/runDev.sh new file mode 100755 index 0000000..568f00f --- /dev/null +++ b/bin/runDev.sh @@ -0,0 +1,12 @@ +printf "%s\n" "> webpack" +npx webpack + +printf "%s\n" "> node app.js" +if [ "$#" -gt "1" ]; then + node app.js $1 +else + mkdir -p tmp + mkdir -p tmp/usrData + mkdir -p tmp/logs + node app.js "$PWD/tmp/" +fi |