aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJakob Stendahl <14180120+JakobST1n@users.noreply.github.com>2018-10-18 21:22:18 +0200
committerGitHub <noreply@github.com>2018-10-18 21:22:18 +0200
commit1098c63adb9aee5d7f416ede1065f3dc4cb8d67e (patch)
tree1ac3328e1c5d2e3454d30476390e28e3233f28cf /bin
parent02413fdd5f1b75db42a116a4187428922f49f28a (diff)
parent8df5b03aa53d9e5db21b697ee60e8e53c95218a1 (diff)
downloadLuxcena-Neo-1098c63adb9aee5d7f416ede1065f3dc4cb8d67e.tar.gz
Luxcena-Neo-1098c63adb9aee5d7f416ede1065f3dc4cb8d67e.zip
:sparkles: Finish v1 of installer
:sparkles: Finish v1 of installer
Diffstat (limited to 'bin')
-rwxr-xr-xbin/install.sh190
-rw-r--r--bin/luxcena-neo.service4
-rwxr-xr-xbin/luxcena-neo.sh3
3 files changed, 93 insertions, 104 deletions
diff --git a/bin/install.sh b/bin/install.sh
index 25c5dc8..2ccb7e0 100755
--- a/bin/install.sh
+++ b/bin/install.sh
@@ -5,98 +5,89 @@ 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."
+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'"
exit 1
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"
+ 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
-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
+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
-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
+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
-done
+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
-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
+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
-done
-
-
-tput setaf 4
-printf ". Which rPi is this? (j:↓, k:↑, ↩:↩)\n"
-tput sgr0
-tput sc
-tput bel
+fi
tput setaf 4
printf ". Installing the app itself...\n"
@@ -105,53 +96,50 @@ tput sgr0
# Create user 'luxcena-neo'
tput setaf 8
printf '%s\n' " - Creating user 'lux-neo'..."
+tput sgr0
username="lux-neo"
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
- echo "$username exists!"
- exit 1
+ echo "User already exists, continuing..."
else
#pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
- useradd -m $username
- [ $? -eq 0 ] && echo "User has been added to system!" || { printf "\n\nInstall failed.\n"; exit 1; }
+ useradd -m $username &>> $LOG || die
fi
-tput sgr0
-
-# Change to the new user
-tput setaf 8
-printf '%s\n' " - Changing to new user..."
-sudo su lux-neo
-tput sgr0
# First we make our directories
tput setaf 8
printf '%s\n' " - Making app-dir (/bin/luxcena-neo)..."
tput sgr0
-mkdir ~/install || { printf "\n\nInstall failed.\n"; exit 1; }
-mkdir ~/install/src || { printf "\n\nInstall failed.\n"; exit 1; }
-mkdir ~/install/userdata || { printf "\n\nInstall failed.\n"; exit 1; }
+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
# 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 . ~/install/src || { printf "\n\nInstall failed.\n"; exit 1; }
+cp -r . "$userDir/install/src" &>> $LOG || die
+chown -R $username:$username "$userDir/install/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 || { printf "\n\nInstall failed.\n"; exit 1; }
-npm --prefix ~/install/src install ~/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?
+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?
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
+cp bin/luxcena-neo.service /etc/systemd/system/luxcena-neo.service &>> $LOG || die
+systemctl daemon-reload &>> $LOG || die
# Installation is done!
printf '\n\e[5m%s\e[0m\n' "🎉Luxcena-Neo is now installed🎉"
diff --git a/bin/luxcena-neo.service b/bin/luxcena-neo.service
index 62111a6..c20a844 100644
--- a/bin/luxcena-neo.service
+++ b/bin/luxcena-neo.service
@@ -2,7 +2,7 @@
Description=Luxcena Neo
[Service]
-ExecStart=/home/pi/luxcena-neo-install/src/bin/luxcena-neo.sh
+ExecStart=/home/lux-neo/install/src/bin/luxcena-neo.sh
Restart=always
RestartSec=10
User=nobody
@@ -10,7 +10,7 @@ User=nobody
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
-WorkingDirectory=/home/pi/luxcena-neo-install/src/
+WorkingDirectory=/home/lux-neo/install/src/
[Install]
WantedBy=multi-user.target
diff --git a/bin/luxcena-neo.sh b/bin/luxcena-neo.sh
index 9bcf125..8455bf3 100755
--- a/bin/luxcena-neo.sh
+++ b/bin/luxcena-neo.sh
@@ -5,4 +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/pi/luxcena-neo-install/src/app.js
+export NODE_ENV=production
+node /home/lux-neo/install/src/app.js