diff --git a/scripts/installscripts/buster-install-default.sh b/scripts/installscripts/buster-install-default.sh index b5c9108bc..c7ca7bbd2 100644 --- a/scripts/installscripts/buster-install-default.sh +++ b/scripts/installscripts/buster-install-default.sh @@ -10,7 +10,6 @@ # # 1. download the install file from github # https://github.com/MiczFlor/RPi-Jukebox-RFID/tree/develop/scripts/installscripts -# (note: currently only works for buster and newer OS) # 2. make the file executable: chmod +x # 3. place the PhonieboxInstall.conf in the folder $HOME # 4. run the installscript with option -a like this: @@ -523,15 +522,46 @@ config_spotify() { read -rp "Type your Spotify password: " SPOTIpass read -rp "Type your client_id: " SPOTIclientid read -rp "Type your client_secret: " SPOTIclientsecret + clear + echo "##################################################### +# +# Swapfile creation +# +# With the current way Spotify support is build, a lot of RAM needs +# to be available in order for the required components to build +# correctly. This includes even recent Raspberry Pi versions. +# In general: If less than 2 GB RAM is available in your system, the +# build of gst-plugin-spotify will most certainly fail. +# +# This script can detect if a swapfile is required and have one +# created for you if needed. +# +" + read -rp "Would you like to have a swapfile created and activated now? [Y/n] " response + case "${response,,}" in + yes|y) + SPOTIcreateswap=YES + ;; + *) + SPOTIcreateswap=NO + ;; + esac + if [ "${SPOTIcreateswap}" == "NO" ]; then + echo "You don't want a swapfile to be created." + else + echo "A swapfile will be created and activated for you." + fi ;; esac + # append variables to config file { echo "SPOTinstall=\"$SPOTinstall\""; echo "SPOTIuser=\"$SPOTIuser\""; echo "SPOTIpass=\"$SPOTIpass\""; echo "SPOTIclientid=\"$SPOTIclientid\""; - echo "SPOTIclientsecret=\"$SPOTIclientsecret\"" + echo "SPOTIclientsecret=\"$SPOTIclientsecret\""; + echo "SPOTIcreateswap=\"$SPOTIcreateswap\"" } >> "${HOME_DIR}/PhonieboxInstall.conf" read -rp "Hit ENTER to proceed to the next step." INPUT } @@ -686,6 +716,7 @@ check_config_file() { check_variable "SPOTIpass" check_variable "SPOTIclientid" check_variable "SPOTIclientsecret" + check_variable "SPOTIcreateswap" fi fi check_variable "MPDconfig" @@ -858,6 +889,9 @@ install_main() { # Install required spotify packages if [ "${SPOTinstall}" == "YES" ]; then + echo "Creating and activating SWAP file if requested..." + create_swap "${SPOTIcreateswap}" + echo "Installing dependencies for Spotify support..." # keep major verson 3 of mopidy echo -e "Package: mopidy\nPin: version 3.*\nPin-Priority: 1001" | sudo tee /etc/apt/preferences.d/mopidy @@ -1304,6 +1338,80 @@ finish_installation() { esac } +create_swap() { + # If Available memory is less than 2 GB (which is round about what's required during + # gst-plugin-spotify compilation later, ask if another 2 GB swap should be created and + # activated. + local CREATE_SWAPFILE=${1:-NO} + + # Install required tools not yet installed + local apt_get="sudo apt-get -qq --yes" + for app in awk bc; do + if ! compgen -A function -abck | grep -Eq '^'"${app}"'$'; then + ${apt_get} install ${app} + fi + done + + # Get Available memory in GB + local MEM_AVAILABLE + MEM_AVAILABLE=$(awk '/MemAvailable/ { printf "%.3f\n", $2/1024/1024 }' /proc/meminfo) + # Get free swap in GB + local SWAP_FREE + SWAP_FREE=$(awk '/SwapFree/ { printf "%.3f\n", $2/1024/1024 }' /proc/meminfo) + # Get available storage space on '/' + local ROOT_FREE + ROOT_FREE=$(df -BG -P / | tail -n 1 | awk '{print $4}') + + # If available memory + free swap is less than 2 GB + if (( $(echo "(${MEM_AVAILABLE} + ${SWAP_FREE}) < 2" | bc -l) )); then + clear + + cat </dev/null + fi + ;; + esac + else + echo -e "\nWARNING: '/swapfile' already exists. Not changing it, just activating all swaps.\n" + fi + fi + fi + + sudo swapon -a +} + ######## # Main # ######## diff --git a/scripts/installscripts/tests/run_installation_tests3.sh b/scripts/installscripts/tests/run_installation_tests3.sh index 09340da8e..bd0a524ba 100644 --- a/scripts/installscripts/tests/run_installation_tests3.sh +++ b/scripts/installscripts/tests/run_installation_tests3.sh @@ -13,21 +13,40 @@ echo $PWD echo "samba-common samba-common/dhcp boolean false" | sudo debconf-set-selections # No interactive frontend export DEBIAN_FRONTEND=noninteractive -echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections # Run installation (in interactive mode) -# y confirm interactive -# n dont configure wifi -# y Headphone as iface +# y confirm interactive mode +# n dont configure wifi (extra ENTER) +# y Headphone as iface (extra ENTER) # y spotify with myuser, mypassword, myclient_id, myclient_secret -# y configure mpd -# y audio default location -# y config gpio -# n no RFID registration -# n No reboot +# y swapfile creation (extra ENTER) +# y configure mpd (extra ENTER) +# y audio default location (extra ENTER) +# y config gpio (extra ENTER) +# n start installation -./../buster-install-default.sh <<< $'y\nn\n\ny\n\ny\nmyuser\nmypassword\nmyclient_id\nmyclient_secret\n\ny\n\ny\n\ny\n\ny\nn\nn\n' -INSTALLATION_EXITCODE=$? +# TODO check, how this behaves on branches other than develop +GIT_BRANCH=develop bash ./scripts/installscripts/buster-install-default.sh <<< "y +n + +y + +y +myuser +mypassword +myclient_id +myclient_secret + +y + +y + +y + +y +n +n +" # Test installation -./test_installation.sh $INSTALLATION_EXITCODE +./scripts/installscripts/tests/test_installation.sh