diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2018-10-18 16:26:26 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2018-10-18 16:26:26 +0200 |
commit | 4a4a950ea94d460c9afd3d8062b377c18e977963 (patch) | |
tree | 6eda86d39f0223481a021da3c654beb27f3fcb4a /bin | |
parent | fd8c13982dd46008de7258676f06cfca3d80b953 (diff) | |
download | Luxcena-Neo-4a4a950ea94d460c9afd3d8062b377c18e977963.tar.gz Luxcena-Neo-4a4a950ea94d460c9afd3d8062b377c18e977963.zip |
:hammer: Move yes/no dialog to function
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/install.sh | 141 |
1 files changed, 60 insertions, 81 deletions
diff --git a/bin/install.sh b/bin/install.sh index 4ba4e45..289f48e 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -5,93 +5,70 @@ printf '%s\n' "Luxcena-neo Installer" tput sgr0 printf '\e[93m%s\e[0m\n\n' "---------------------" +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 + 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 +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 + 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 -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" @@ -138,7 +115,9 @@ printf '%s\n' " - Running npm i..." tput sgr0 tput sc export NODE_ENV=production || { printf "\n\nInstall failed.\n"; exit 1; } -sudo runuser -l $username -c "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? +sudo runuser -l $username -c '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? +if [ $? -eq 0 ]; then +fi tput rc; tput ed # Fifth we add the service files |