diff --git a/.github/ISSUE_TEMPLATE/bug_template.md b/.github/ISSUE_TEMPLATE/bug_template.md index 4c26ca404..7b555ca31 100644 --- a/.github/ISSUE_TEMPLATE/bug_template.md +++ b/.github/ISSUE_TEMPLATE/bug_template.md @@ -28,6 +28,8 @@ i.e. `I would have expected that this command would magically fix itself when it ### Further information that might help diff --git a/components/smart-home-automation/MQTT-protocol/README.md b/components/smart-home-automation/MQTT-protocol/README.md index 1cf536c10..4c763fe65 100644 --- a/components/smart-home-automation/MQTT-protocol/README.md +++ b/components/smart-home-automation/MQTT-protocol/README.md @@ -109,6 +109,12 @@ Sending empty payload to `phoniebox/cmd/help` will be responded by a list of all # Installation +Install missing python packages for MQTT: + +~~~ +sudo pip3 install paho-mqtt +~~~ + All relevant files can be found in the folder: ~~~ diff --git a/htdocs/inc.viewFolderTree.php b/htdocs/inc.viewFolderTree.php index 6d2f41d20..434db47fe 100755 --- a/htdocs/inc.viewFolderTree.php +++ b/htdocs/inc.viewFolderTree.php @@ -117,18 +117,18 @@ // this is for loading spotify informations! $track = file_get_contents($subfolder."/spotify.txt"); $url = "https://open.spotify.com/oembed/?url=".trim($track)."&format=json"; - + $context = stream_context_create(array()); + if (!file_exists($check1)) { - $str = file_get_contents($url); + $str = file_get_contents($url, false, $context); $json = json_decode($str, true); $cover = $json['thumbnail_url']; $coverdl = file_get_contents($cover); file_put_contents($check1, $coverdl); } - if (!file_exists($check2)) { - $str = file_get_contents($url); + $str = file_get_contents($url, false, $context); $json = json_decode($str, true); $title = $json['title']; diff --git a/misc/sampleconfigs/gpio-buttons.py.sample b/misc/sampleconfigs/gpio-buttons.py.sample index 69c669c45..fb9070e01 100644 --- a/misc/sampleconfigs/gpio-buttons.py.sample +++ b/misc/sampleconfigs/gpio-buttons.py.sample @@ -31,6 +31,7 @@ from time import sleep # I have not yet had the time to test is, so I placed it in the misc folder. # If anybody has ideas or tests or experience regarding this solution, please create pull requests or contact me. + # This function takes a holding time (fractional seconds), a channel, a GPIO state and an action reference (function). # It checks if the GPIO is in the state since the function was called. If the state # changes it return False. If the time is over the function returns True. @@ -41,39 +42,59 @@ def checkGpioStaysInState(holdingTime, gpioChannel, gpioHoldingState): while(holdingTime >= (time.perf_counter() - startTime)): # Return if state does not match holding state if(gpioHoldingState != GPIO.input(gpioChannel)): - return False + return False # Else: Wait return True + # Actions that call other processes of the phoniebox (Channel Parameter needed by RPi.GPIO) def shutdown_action(channel): check_call("./scripts/playout_controls.sh -c=shutdown", shell=True) + + def vol0_action(channel): check_call("./scripts/playout_controls.sh -c=mute", shell=True) + + def volD_action(channel): check_call("./scripts/playout_controls.sh -c=volumedown", shell=True) + + def volU_action(channel): check_call("./scripts/playout_controls.sh -c=volumeup", shell=True) + + def next_action(channel): check_call("./scripts/playout_controls.sh -c=playernext", shell=True) + + def prev_action(channel): check_call("./scripts/playout_controls.sh -c=playerprev", shell=True) + + def halt_action(channel): check_call("./scripts/playout_controls.sh -c=playerpause", shell=True) + + def recordstart_action(channel): check_call("./scripts/playout_controls.sh -c=recordstart", shell=True) + + def recordstop_action(channel): check_call("./scripts/playout_controls.sh -c=recordstop", shell=True) + + def recordplaylatest_action(channel): check_call("./scripts/playout_controls.sh -c=recordplaylatest", shell=True) -def rfidoff_action(): +def rfidoff_action(channel): check_call("./scripts/playout_controls.sh -c=playerpauseforce", shell=True) + # Handlers that handle special behavior of the push of a button -# When the shutdown button was held for more than 2 seconds LED flashed and afterwards +# When the shutdown button was held for more than 2 seconds LED flashed and afterwards def shutdown_handler(channel): # Detect holding of button - if True == checkGpioStaysInState(shutdownHoldTime, btn_shut, GPIO.LOW): + if checkGpioStaysInState(shutdownHoldTime, btn_shut, GPIO.LOW) is True: # Blink LED for x in range(0, 10): GPIO.output(led_power, x & 1) @@ -82,7 +103,8 @@ def shutdown_handler(channel): GPIO.output(led_power, GPIO.HIGH) # Shutdown afterwards shutdown_action(channel) - + + # When the Volume Down button was held for more than 0.3 seconds every 0.3 seconds he will lower t$ def volU_handler(channel): # Rise volume as requested @@ -91,6 +113,7 @@ def volU_handler(channel): while checkGpioStaysInState(volumeHoldTime, btn_volU, GPIO.LOW): volU_action(channel) + # When the Volume Up button was held for more than 0.3 seconds every 0.3 seconds he will call a ra$ def volD_handler(channel): # Rise volume as requested @@ -99,6 +122,7 @@ def volD_handler(channel): while checkGpioStaysInState(volumeHoldTime, btn_volD, GPIO.LOW): volD_action(channel) + # Define the used pins of the raspberry board btn_shut = 3 btn_vol0 = 13 @@ -108,28 +132,29 @@ btn_next = 26 btn_prev = 20 btn_halt = 21 led_power = 12 -#reco = -#play = +# btn_rfidoff = +# reco = +# play = # Set GPIO numbering to BCM instead of board numbering GPIO.setmode(GPIO.BCM) # Bounce tolerance time for buttons bouncetime = 500 -volumeHoldTime = 0.3 # Seconds -shutdownHoldTime = 2 # Seconds +volumeHoldTime = 0.3 # Seconds +shutdownHoldTime = 2 # Seconds PledBlinkTime = 0.3 # Seconds # Set up GPIO pins and the power led -GPIO.setup(btn_shut , GPIO.IN, pull_up_down=GPIO.PUD_UP) -GPIO.setup(btn_vol0 , GPIO.IN, pull_up_down=GPIO.PUD_UP) -GPIO.setup(btn_volU , GPIO.IN, pull_up_down=GPIO.PUD_UP) -GPIO.setup(btn_volD , GPIO.IN, pull_up_down=GPIO.PUD_UP) -GPIO.setup(btn_next , GPIO.IN, pull_up_down=GPIO.PUD_UP) -GPIO.setup(btn_prev , GPIO.IN, pull_up_down=GPIO.PUD_UP) -GPIO.setup(btn_halt , GPIO.IN, pull_up_down=GPIO.PUD_UP) -#GPIO.setup(btn_rfidoff, GPIO.IN, pull_up_down=GPIO.PUD_UP) -GPIO.setup(led_power , GPIO.OUT) -# btn_rfidoff = Button(12,pull_up=True) +GPIO.setup(btn_shut, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(btn_vol0, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(btn_volU, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(btn_volD, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(btn_next, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(btn_prev, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(btn_halt, GPIO.IN, pull_up_down=GPIO.PUD_UP) +# GPIO.setup(btn_rfidoff, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) +GPIO.setup(led_power, GPIO.OUT) + # Set standard events for the buttons. Callback functions define the actions of the events (THey are defined above) GPIO.add_event_detect(btn_shut, GPIO.FALLING, callback=shutdown_handler, bouncetime=bouncetime) @@ -139,10 +164,11 @@ GPIO.add_event_detect(btn_volD, GPIO.FALLING, callback=volD_handler, bouncetime= GPIO.add_event_detect(btn_next, GPIO.FALLING, callback=next_action, bouncetime=bouncetime) GPIO.add_event_detect(btn_prev, GPIO.FALLING, callback=prev_action, bouncetime=bouncetime) GPIO.add_event_detect(btn_halt, GPIO.FALLING, callback=halt_action, bouncetime=bouncetime) +#GPIO.add_event_detect(btn_rfidoff, GPIO.FALLING, callback=rfidoff_action, bouncetime=bouncetime) #reco.when_pressed = recordstart_action #reco.when_released = recordstop_action #play.when_pressed = recordplaylatest_action -#GPIO.add_event_detect(btn_rfidoff, GPIO.FALLING, callback=rfidoff_action, bouncetime=bouncetime) + # Switch on power led after boot to indicate state "on" for phoniebox GPIO.output(led_power, GPIO.HIGH) diff --git a/scripts/installscripts/buster-install-default.sh b/scripts/installscripts/buster-install-default.sh index e073e3583..0bc76a230 100755 --- a/scripts/installscripts/buster-install-default.sh +++ b/scripts/installscripts/buster-install-default.sh @@ -7,6 +7,44 @@ PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" GIT_BRANCH=${GIT_BRANCH:-master} +LOGDIR=${PATHDATA}/logfiles +DATE=$(date +"%Y%m%d") +DATETIME=$(date +"%Y%m%d_%H%M%S") + +SCRIPTNAME="$(basename $0)" +JOB="${SCRIPTNAME}" + +# Setup logger functions +# Input from http://www.ludovicocaldara.net/dba/bash-tips-5-output-logfile/ +function Log_Open() { + [[ -d ${LOGDIR} ]] || mkdir -p ${LOGDIR} + PIPE=${LOGDIR}/${JOB}_${DATETIME}.pipe + mkfifo -m 700 ${PIPE} + LOGFILE=${LOGDIR}/${JOB}_${DATETIME}.log + exec 3>&1 + tee ${LOGFILE} <${PIPE} >&3 & + TEEPID=$! + exec 1>${PIPE} 2>&1 + PIPE_OPENED=1 +} + +function Log_Close() { + if [ ${PIPE_OPENED} ] ; then + exec 1<&3 + sleep 0.2 + ps --pid ${TEEPID} >/dev/null + if [ $? -eq 0 ] ; then + # a wait ${TEEPID} whould be better but some + # commands leave file descriptors open + sleep 1 + kill ${TEEPID} + fi + rm ${PIPE} + unset PIPE_OPENED + fi +} + + clear echo "##################################################### # ___ __ ______ _ __________ ____ __ _ _ # @@ -139,6 +177,9 @@ echo "##################################################### # check if we find the version number if [ -f /home/pi/RPi-Jukebox-RFID/settings/version ]; then echo "The version of your installation is: $(cat RPi-Jukebox-RFID/settings/version)" + + # get the current short commit hash of the repo + CURRENT_REMOTE_COMMIT="$(git ls-remote https://github.com/MiczFlor/RPi-Jukebox-RFID.git ${GIT_BRANCH} | cut -c1-7)" fi echo "IMPORTANT: you can use the existing content and configuration files for your new install." echo "Whatever you chose to keep will be moved to the new install." @@ -456,6 +497,14 @@ case "$response" in ;; esac +# Start logging here +Log_Open + +# Add conffile into logfile for better debugging +echo "################################################" +grep -v -e "SPOTI" -e "WIFIpass" "${PATHDATA}/PhonieboxInstall.conf" +echo "################################################" + ##################################################### # INSTALLATION @@ -507,6 +556,10 @@ git clone https://github.com/MiczFlor/RPi-Jukebox-RFID.git --branch "${GIT_BRANC # check, which branch was cloned git --work-tree=/home/pi/RPi-Jukebox-RFID --git-dir=/home/pi/RPi-Jukebox-RFID/.git status | head -2 +# add git commit hash to version file +COMMIT_NO="$(git describe --always)" +sudo sed -i 's/%GIT_COMMIT%/'"$COMMIT_NO"'/' /home/pi/RPi-Jukebox-RFID/settings/version + # Install required spotify packages if [ $SPOTinstall == "YES" ] then @@ -811,9 +864,6 @@ mkdir /home/pi/RPi-Jukebox-RFID/playlists sudo chown -R pi:www-data /home/pi/RPi-Jukebox-RFID/playlists sudo chmod -R 775 /home/pi/RPi-Jukebox-RFID/playlists -sudo chown -R pi:www-data /home/pi/RPi-Jukebox-RFID/playlists -sudo chmod -R 775 /home/pi/RPi-Jukebox-RFID/playlists - # make sure the shared folder is accessible by the web server sudo chown -R pi:www-data /home/pi/RPi-Jukebox-RFID/shared sudo chmod -R 775 /home/pi/RPi-Jukebox-RFID/shared @@ -864,7 +914,8 @@ echo " echo "If you are using an USB RFID reader, connect it to your RPi." echo "(In case your RFID reader required soldering, consult the manual.)" -read -r -p "Have you connected your USB Reader? [Y/n] " response +# Use -e to display response of user in the logfile +read -e -r -p "Have you connected your USB Reader? [Y/n] " response case "$response" in [nN][oO]|[nN]) ;; @@ -882,11 +933,16 @@ echo "Find more information and documentation on the github account:" echo "https://github.com/MiczFlor/RPi-Jukebox-RFID/wiki/" echo "Reboot is needed to activate all settings" -read -r -p "Would you like to reboot now? [Y/n] " response +# Use -e to display response of user in the logfile +read -e -r -p "Would you like to reboot now? [Y/n] " response case "$response" in [nN][oO]|[nN]) + # Close logging + Log_Close ;; *) + # Close logging + Log_Close sudo shutdown -r now ;; esac diff --git a/scripts/installscripts/stretch-install-default.sh b/scripts/installscripts/stretch-install-default.sh index 2a20e40d7..fea321b8c 100755 --- a/scripts/installscripts/stretch-install-default.sh +++ b/scripts/installscripts/stretch-install-default.sh @@ -277,6 +277,79 @@ echo "Your iFace is called'$AUDIOiFace'" echo "Hit ENTER to proceed to the next step." read -r INPUT +##################################################### +# Configure spotify + +clear + +echo "##################################################### +# +# OPTIONAL: INCLUDE SPOTIFY SUPPORT +# +# Spotify uses Mopidy for audio output and must +# be configured. Do it now, or never. +# (Note: To add this later, you must re-install phoniebox) +" +read -r -p "Do you want to install Mopidy? [Y/n] " response +case "$response" in + [nN][oO]|[nN]) + SPOTinstall=NO + echo "You don't want spotify support." + echo "Hit ENTER to proceed to the next step." + read -r INPUT + ;; + *) + SPOTinstall=YES + clear + echo "This was a great decision! Mopidy will be set up." + echo "##################################################### +# +# CONFIGURE MOPIDY +# +# Requires spotify username, password, client_id and client_secret +# to get connection to Spotify. +# +# (Note: You need a device with browser to generate ID and SECRET) +# +# Please go to this website: +# https://www.mopidy.com/authenticate/ +# and follow the instructions. +# +# Your credential will appear on the site below the login button. +# Please note your client_id and client_secret! +# +" + echo "" + echo "Type your Spotify username:" + read -r INPUT + SPOTIuser="$INPUT" + echo "" + echo "Type your Spotify password:" + read -r INPUT + SPOTIpass="$INPUT" + echo "" + echo "Type your client_id:" + read -r INPUT + SPOTIclientid="$INPUT" + echo "" + echo "Type your client_secret:" + read -r INPUT + SPOTIclientsecret="$INPUT" + echo "" + echo "Hit ENTER to proceed to the next step." + read -r INPUT + ;; +esac +# append variables to config file +{ + echo "SPOTinstall=\"$SPOTinstall\""; + echo "SPOTIuser=\"$SPOTIuser\""; + echo "SPOTIpass=\"$SPOTIpass\""; + echo "SPOTIclientid=\"$SPOTIclientid\""; + echo "SPOTIclientsecret=\"$SPOTIclientsecret\"" +} >> "${PATHDATA}/PhonieboxInstall.conf" + +if [ $SPOTinstall == "NO" ]; then ##################################################### # Configure MPD @@ -307,6 +380,7 @@ case "$response" in esac # append variables to config file echo "MPDconfig=\"$MPDconfig\"" >> "${PATHDATA}/PhonieboxInstall.conf" +fi ##################################################### # Folder path for audio files @@ -382,7 +456,7 @@ esac # (this might look stupid so far, but makes sense once # the option to install from config file is introduced.) # shellcheck source=scripts/installscripts/tests/ShellCheck/PhonieboxInstall.conf -. "$PATHDATA/PhonieboxInstall.conf" +. "${PATHDATA}/PhonieboxInstall.conf" # power management of wifi: switch off to avoid disconnecting sudo iwconfig wlan0 power off @@ -397,6 +471,30 @@ sudo apt-get --yes --force-yes install python3-dev python3-pip python3-mutagen p # use python3.5 as default sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1 +# Install required spotify packages +if [ $SPOTinstall == "YES" ] +then + wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add - + sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/stretch.list + sudo apt-get update + sudo apt-get --yes --force-yes install mopidy + sudo apt-get --yes --force-yes install libspotify12 python-cffi python-ply python-pycparser python-spotify + sudo apt-get --yes --force-yes install libspotify12 python3-cffi python3-ply python3-pycparser + sudo python3 -m pip install spotify + sudo rm -rf /usr/lib/python2.7/dist-packages/mopidy_spotify* + sudo rm -rf /usr/lib/python2.7/dist-packages/Mopidy_Spotify-* + cd || exit + sudo rm -rf mopidy-spotify + git clone -b fix/web_api_playlists --single-branch https://github.com/princemaxwell/mopidy-spotify.git + cd mopidy-spotify || exit + sudo python setup.py install + cd || exit + # should be removed, if Mopidy-Iris can be installed normally + # pylast >= 3.0.0 removed the python2 support + sudo pip install pylast==2.4.0 + sudo pip install Mopidy-Iris +fi + # Get github code cd /home/pi/ || exit git clone https://github.com/MiczFlor/RPi-Jukebox-RFID.git --branch "${GIT_BRANCH}" @@ -412,7 +510,7 @@ git fetch sudo pip install -r requirements.txt sudo pip3 install -r /home/pi/RPi-Jukebox-RFID/components/rfid-reader/PN532/requirements.txt -# actually, for the time being most of the requirements are run here. +# actually, for the time being most of the requirements are run here (again). # the requirements.txt version seems to throw errors. Help if you can to fix this: sudo pip install "evdev == 0.7.0" @@ -534,18 +632,45 @@ sudo systemctl enable phoniebox-gpio-buttons cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/startupsound.mp3.sample /home/pi/RPi-Jukebox-RFID/shared/startupsound.mp3 cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/shutdownsound.mp3.sample /home/pi/RPi-Jukebox-RFID/shared/shutdownsound.mp3 -# MPD configuration -# -rw-r----- 1 mpd audio 14043 Jul 17 20:16 /etc/mpd.conf -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/mpd.conf.sample /etc/mpd.conf -# Change vars to match install config -sudo sed -i 's/%AUDIOiFace%/'"$AUDIOiFace"'/' /etc/mpd.conf -# for $DIRaudioFolders using | as alternate regex delimiter because of the folder path slash -sudo sed -i 's|%DIRaudioFolders%|'"$DIRaudioFolders"'|' /etc/mpd.conf -echo "classic" > /home/pi/RPi-Jukebox-RFID/settings/edition -sudo chown mpd:audio /etc/mpd.conf -sudo chmod 640 /etc/mpd.conf -# update mpc / mpd DB -mpc update +if [ $SPOTinstall == "NO" ] +then + # MPD configuration + # -rw-r----- 1 mpd audio 14043 Jul 17 20:16 /etc/mpd.conf + sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/mpd.conf.sample /etc/mpd.conf + # Change vars to match install config + sudo sed -i 's/%AUDIOiFace%/'"$AUDIOiFace"'/' /etc/mpd.conf + # for $DIRaudioFolders using | as alternate regex delimiter because of the folder path slash + sudo sed -i 's|%DIRaudioFolders%|'"$DIRaudioFolders"'|' /etc/mpd.conf + echo "classic" > /home/pi/RPi-Jukebox-RFID/settings/edition + sudo chown mpd:audio /etc/mpd.conf + sudo chmod 640 /etc/mpd.conf + # update mpc / mpd DB + mpc update +fi + +if [ $SPOTinstall == "YES" ] +then + sudo systemctl disable mpd + sudo systemctl enable mopidy + # Install Config Files + sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/locale.gen.sample /etc/locale.gen + sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/locale.sample /etc/default/locale + sudo locale-gen + sudo mkdir /home/pi/.config + sudo mkdir /home/pi/.config/mopidy + sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/mopidy-etc.sample /etc/mopidy/mopidy.conf + sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/mopidy.sample ~/.config/mopidy/mopidy.conf + echo "plusSpotify" > /home/pi/RPi-Jukebox-RFID/settings/edition + # Change vars to match install config + sudo sed -i 's/%spotify_username%/'"$SPOTIuser"'/' /etc/mopidy/mopidy.conf + sudo sed -i 's/%spotify_password%/'"$SPOTIpass"'/' /etc/mopidy/mopidy.conf + sudo sed -i 's/%spotify_client_id%/'"$SPOTIclientid"'/' /etc/mopidy/mopidy.conf + sudo sed -i 's/%spotify_client_secret%/'"$SPOTIclientsecret"'/' /etc/mopidy/mopidy.conf + sudo sed -i 's/%spotify_username%/'"$SPOTIuser"'/' ~/.config/mopidy/mopidy.conf + sudo sed -i 's/%spotify_password%/'"$SPOTIpass"'/' ~/.config/mopidy/mopidy.conf + sudo sed -i 's/%spotify_client_id%/'"$SPOTIclientid"'/' ~/.config/mopidy/mopidy.conf + sudo sed -i 's/%spotify_client_secret%/'"$SPOTIclientsecret"'/' ~/.config/mopidy/mopidy.conf +fi ############################### # WiFi settings (SSID password) @@ -577,7 +702,6 @@ then sudo sed -i 's/%WIFIcountryCode%/'"$WIFIcountryCode"'/' /etc/wpa_supplicant/wpa_supplicant.conf sudo chown root:netdev /etc/wpa_supplicant/wpa_supplicant.conf sudo chmod 664 /etc/wpa_supplicant/wpa_supplicant.conf - fi # start DHCP @@ -716,21 +840,26 @@ echo echo "DONE. Let the sounds begin." echo "Find more information and documentation on the github account:" echo "https://github.com/MiczFlor/RPi-Jukebox-RFID/wiki/" +echo "" ##################################################### + +read -r -p "Reboot now? [Y/n] " response +case "$response" in + [nN][oO]|[nN]) + echo "You have to reboot manually!" + ;; + *) + sudo reboot + ;; +esac + # notes for things to do # Soundcard # PCM is currently set # This needs to be done for mpd and in settings folder - - -#Ask if Spotify config -#If Spotify -#Ask for user -#Ask for password - #Ask ssh password # get existing install diff --git a/scripts/installscripts/stretch-install-spotify.sh b/scripts/installscripts/stretch-install-spotify.sh deleted file mode 100755 index a2df60d01..000000000 --- a/scripts/installscripts/stretch-install-spotify.sh +++ /dev/null @@ -1,870 +0,0 @@ -#!/bin/bash -# -# see https://github.com/MiczFlor/RPi-Jukebox-RFID for details -# Especially the docs folder for documentation - -# The absolute path to the folder which contains this script -PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -GIT_BRANCH=${GIT_BRANCH:-master} - -clear -echo "##################################################### -# ___ __ ______ _ __________ ____ __ _ _ # -# / _ \/ // / __ \/ |/ / _/ __/( _ \ / \( \/ ) # -# / ___/ _ / /_/ / // // _/ ) _ (( O )) ( # -# /_/ /_//_/\____/_/|_/___/____/ (____/ \__/(_/\_) # -# +Spotify # -# # -##################################################### - -Welcome to the installation script. - -This script will install Phoniebox on your Raspberry Pi. -To do so, you must be online. The install script can -automatically configure: - -* WiFi settings (SSID, password and static IP) - -All these are optional and can also be done later -manually. - -If you are ready, hit ENTER" -read -r INPUT - -##################################################### -# CONFIG FILE -# This file will contain all the data given in the -# following dialogue -# At a later stage, the install should also be done -# from such a config file with no user input. - -# Remove existing config file -rm PhonieboxInstall.conf -# Create empty config file -touch PhonieboxInstall.conf -echo "# Phoniebox config" > "${PATHDATA}/PhonieboxInstall.conf" - -##################################################### -# Ask if wifi config - -clear - -echo "##################################################### -# -# CONFIGURE WIFI -# -# Requires SSID, WiFi password and the static IP you want -# to assign to your Phoniebox. -# (Note: can be done manually later, if you are unsure.) -" -read -r -p "Do you want to configure your WiFi? [Y/n] " response -case "$response" in - [nN][oO]|[nN]) - WIFIconfig=NO - echo "You want to configure WiFi later." - echo "Hit ENTER to proceed to the next step." - read -r INPUT - # append variables to config file - echo "WIFIconfig=$WIFIconfig" >> "${PATHDATA}/PhonieboxInstall.conf" - # make a fallback for WiFi Country Code, because we need that even without WiFi config - echo "WIFIcountryCode=GB" >> "${PATHDATA}/PhonieboxInstall.conf" - ;; - *) - WIFIconfig=YES - #Ask for ssid - echo "* Type SSID name" - read -r INPUT - WIFIssid="$INPUT" - #Ask for wifi country code - echo "* WiFi Country Code (e.g. DE, GB, CZ or US)" - read -r INPUT - WIFIcountryCode="$INPUT" - #Ask for password - echo "* Type password" - read -r INPUT - WIFIpass="$INPUT" - #Ask for IP - echo "* Static IP (e.g. 192.168.1.199)" - read -r INPUT - WIFIip="$INPUT" - #Ask for Router IP - echo "* Router IP (e.g. 192.168.1.1)" - read -r INPUT - WIFIipRouter="$INPUT" - echo "Your WiFi config:" - echo "SSID : $WIFIssid" - echo "WiFi Country Code : $WIFIcountryCode" - echo "Password : $WIFIpass" - echo "Static IP : $WIFIip" - echo "Router IP : $WIFIipRouter" - read -r -p "Are these values correct? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - echo "The values are incorrect." - echo "Hit ENTER to exit and start over." - read -r INPUT; exit - ;; - *) - # append variables to config file - echo "WIFIconfig=\"$WIFIconfig\"" >> "${PATHDATA}/PhonieboxInstall.conf" - echo "WIFIcountryCode=\"$WIFIcountryCode\"" >> "${PATHDATA}/PhonieboxInstall.conf" - echo "WIFIssid=\"$WIFIssid\"" >> "${PATHDATA}/PhonieboxInstall.conf" - echo "WIFIpass=\"$WIFIpass\"" >> "${PATHDATA}/PhonieboxInstall.conf" - echo "WIFIip=\"$WIFIip\"" >> "${PATHDATA}/PhonieboxInstall.conf" - echo "WIFIipRouter=\"$WIFIipRouter\"" >> "${PATHDATA}/PhonieboxInstall.conf" - ;; - esac - ;; -esac - -##################################################### -# Check for existing Phoniebox -# -# In case there is no existing install, -# set the var now for later use: -EXISTINGuse=NO - -# The install will be in the home dir of user pi -# Move to home directory now to check -cd || exit -if [ -d /home/pi/RPi-Jukebox-RFID ]; then - # Houston, we found something! - clear -echo "##################################################### -# -# . . . * alert * alert * alert * alert * . . . -# -# WARNING: an existing Phoniebox installation was found. -# -" - # check if we find the version number - if [ -f /home/pi/RPi-Jukebox-RFID/settings/version ]; then - echo "The version of your installation is: $(cat RPi-Jukebox-RFID/settings/version)" - fi - echo "IMPORTANT: you can use the existing content and configuration files for your new install." - echo "Whatever you chose to keep will be moved to the new install." - echo "Everything else will remain in a folder called 'BACKUP'. - " - # Delete or use existing installation? - read -r -p "Re-use config, audio and RFID codes for the new install? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - EXISTINGuse=NO - echo "Phoniebox will be a fresh install. The existing version will be dropped." - echo "Hit ENTER to proceed to the next step." - sudo rm -rf RPi-Jukebox-RFID - read -r INPUT - ;; - *) - EXISTINGuse=YES - # CREATE BACKUP - # delete existing BACKUP dir if exists - if [ -d BACKUP ]; then - sudo rm -r BACKUP - fi - # move install to BACKUP dir - mv RPi-Jukebox-RFID BACKUP - # delete .git dir - if [ -d BACKUP/.git ]; then - sudo rm -r BACKUP/.git - fi - # delete placeholder files so moving the folder content back later will not create git pull conflicts - rm BACKUP/shared/audiofolders/placeholder - rm BACKUP/shared/shortcuts/placeholder - - # ask for things to use - echo "Ok. You want to use stuff from the existing installation." - echo "What would you want to keep? Answer now." - read -r -p "RFID config for system control (e.g. 'volume up' etc.)? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - EXISTINGuseRfidConf=NO - ;; - *) - EXISTINGuseRfidConf=YES - ;; - esac - # append variables to config file - echo "EXISTINGuseRfidConf=$EXISTINGuseRfidConf" >> "${PATHDATA}/PhonieboxInstall.conf" - - read -r -p "RFID shortcuts to play audio folders? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - EXISTINGuseRfidLinks=NO - ;; - *) - EXISTINGuseRfidLinks=YES - ;; - esac - # append variables to config file - echo "EXISTINGuseRfidLinks=$EXISTINGuseRfidLinks" >> "${PATHDATA}/PhonieboxInstall.conf" - - read -r -p "Audio folders: use existing? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - EXISTINGuseAudio=NO - ;; - *) - EXISTINGuseAudio=YES - ;; - esac - # append variables to config file - echo "EXISTINGuseAudio=$EXISTINGuseAudio" >> "${PATHDATA}/PhonieboxInstall.conf" - - read -r -p "GPIO: use existing file? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - EXISTINGuseGpio=NO - ;; - *) - EXISTINGuseGpio=YES - ;; - esac - # append variables to config file - echo "EXISTINGuseGpio=$EXISTINGuseGpio" >> "${PATHDATA}/PhonieboxInstall.conf" - - read -r -p "Sound effects: use existing startup / shutdown sounds? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - EXISTINGuseSounds=NO - ;; - *) - EXISTINGuseSounds=YES - ;; - esac - # append variables to config file - echo "EXISTINGuseSounds=$EXISTINGuseSounds" >> "${PATHDATA}/PhonieboxInstall.conf" - - echo "Thanks. Got it." - echo "The existing install can be found in the BACKUP directory." - echo "Hit ENTER to proceed to the next step." - read -r INPUT - ;; - esac -fi -# append variables to config file -echo "EXISTINGuse=$EXISTINGuse" >> "${PATHDATA}/PhonieboxInstall.conf" - -##################################################### -# Audio iFace - -clear - -echo "##################################################### -# -# CONFIGURE AUDIO INTERFACE (iFace) -# -# By default for the RPi the audio interface would be 'PCM'. -# But this does not work for every setup, alternatives are -# 'Master' or 'Speaker'. Other external sound cards might -# use different interface names. -# To list all available iFace names, type 'amixer scontrols' -# in the terminal. -" -read -r -p "Use PCM as iFace? [Y/n] " response -case "$response" in - [nN][oO]|[nN]) - echo "Type the iFace name you want to use:" - read -r INPUT - AUDIOiFace="$INPUT" - ;; - *) - AUDIOiFace="PCM" - ;; -esac -# append variables to config file -echo "AUDIOiFace=\"$AUDIOiFace\"" >> "${PATHDATA}/PhonieboxInstall.conf" -echo "Your iFace ist called'$AUDIOiFace'" -echo "Hit ENTER to proceed to the next step." -read -r INPUT - -##################################################### -# Configure spotify - -clear - -echo "##################################################### -# -# OPTIONAL: INCLUDE SPOTIFY SUPPORT -# -# Spotify uses Mopidy for audio output and must -# be configured. Do it now, or never. -# (Note: To add this later, you must re-install phoniebox) -" -read -r -p "Do you want to install Mopidy? [Y/n] " response -case "$response" in - [nN][oO]|[nN]) - SPOTinstall=NO - echo "You don't want spotify support." - echo "Hit ENTER to proceed to the next step." - read -r INPUT - ;; - *) - SPOTinstall=YES - clear - echo "This was a great decision! Mopidy will be set up." - echo "##################################################### -# -# CONFIGURE MOPIDY -# -# Requires spotify username, password, client_id and client_secret -# to get connection to Spotify. -# -# (Note: You need a device with browser to generate ID and SECRET) -# -# Please go to this website: -# https://www.mopidy.com/authenticate/ -# and follow the instructions. -# -# Your credential will appear on the site below the login button. -# Please note your client_id and client_secret! -# -" - echo "" - echo "Type your Spotify username:" - read -r INPUT - SPOTIuser="$INPUT" - echo "" - echo "Type your Spotify password:" - read -r INPUT - SPOTIpass="$INPUT" - echo "" - echo "Type your client_id:" - read -r INPUT - SPOTIclientid="$INPUT" - echo "" - echo "Type your client_secret:" - read -r INPUT - SPOTIclientsecret="$INPUT" - echo "" - echo "Hit ENTER to proceed to the next step." - read -r INPUT - ;; -esac -# append variables to config file -{ - echo "SPOTinstall=\"$SPOTinstall\""; - echo "SPOTIuser=\"$SPOTIuser\""; - echo "SPOTIpass=\"$SPOTIpass\""; - echo "SPOTIclientid=\"$SPOTIclientid\""; - echo "SPOTIclientsecret=\"$SPOTIclientsecret\"" -} >> "${PATHDATA}/PhonieboxInstall.conf" - -if [ $SPOTinstall == "NO" ]; then -##################################################### -# Configure MPD - -clear - -echo "##################################################### -# -# CONFIGURE MPD -# -# MPD (Music Player Daemon) runs the audio output and must -# be configured. Do it now, if you are unsure. -# (Note: can be done manually later.) -" -read -r -p "Do you want to configure MPD? [Y/n] " response -case "$response" in - [nN][oO]|[nN]) - MPDconfig=NO - echo "You want to configure MPD later." - echo "Hit ENTER to proceed to the next step." - read -r INPUT - ;; - *) - MPDconfig=YES - echo "MPD will be set up with default values." - echo "Hit ENTER to proceed to the next step." - read -r INPUT - ;; -esac -# append variables to config file -echo "MPDconfig=\"$MPDconfig\"" >> "${PATHDATA}/PhonieboxInstall.conf" -fi - -##################################################### -# Folder path for audio files -# default: /home/pi/RPi-Jukebox-RFID/shared/audiofolders - -clear - -echo "##################################################### -# -# FOLDER CONTAINING AUDIO FILES -# -# The default location for folders containing audio files: -# /home/pi/RPi-Jukebox-RFID/shared/audiofolders -# -# If unsure, keep it like this. If your files are somewhere -# else, you can specify the folder in the next step. -# IMPORTANT: the folder will not be created, only the path -# will be remembered. If you use a custom folder, you must -# create it. -" - -read -r -p "Do you want to use the default location? [Y/n] " response -case "$response" in - [nN][oO]|[nN]) - echo "Please type the absolute path here (no trailing slash)." - echo "Default would be for example:" - echo "/home/pi/RPi-Jukebox-RFID/shared/audiofolders" - read -r INPUT - DIRaudioFolders="$INPUT" - ;; - *) - DIRaudioFolders="/home/pi/RPi-Jukebox-RFID/shared/audiofolders" - ;; -esac -# append variables to config file -echo "DIRaudioFolders=\"$DIRaudioFolders\"" >> "${PATHDATA}/PhonieboxInstall.conf" -echo "Your audio folders live in this dir:" -echo $DIRaudioFolders -echo "Hit ENTER to proceed to the next step." -read -r INPUT - -clear - -echo "##################################################### -# -# START INSTALLATION -# -# Good news: you completed the input. -# Let the install begin. -# -# Get yourself a cup of something. The install takes -# between 15 minutes to half an hour, depending on -# your Raspberry Pi and Internet connectivity. -# -# You will be prompted later to complete the installation. -" - -read -r -p "Do you want to start the installation? [Y/n] " response -case "$response" in - [nN][oO]|[nN]) - echo "Exiting the installation." - echo "Your configuration data was saved in this file:" - echo "${PATHDATA}/PhonieboxInstall.conf" - echo - exit - ;; -esac - -##################################################### -# INSTALLATION - -# Read install config as written so far -# (this might look stupid so far, but makes sense once -# the option to install from config file is introduced.) -# shellcheck source=scripts/installscripts/tests/ShellCheck/PhonieboxInstall.conf -. "${PATHDATA}/PhonieboxInstall.conf" - -# power management of wifi: switch off to avoid disconnecting -sudo iwconfig wlan0 power off - -# Install required packages -sudo apt-get update -sudo apt-get --yes --force-yes install apt-transport-https samba samba-common-bin gcc linux-headers-4.9 lighttpd php7.0-common php7.0-cgi php7.0 at mpd mpc mpg123 git ffmpeg - -# prepare for python2 and python3 -sudo apt-get --yes --force-yes install python-dev python-pip python-mutagen python-gpiozero python-spidev -sudo apt-get --yes --force-yes install python3-dev python3-pip python3-mutagen python3-gpiozero python3-spidev - -# use python3.5 as default -sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1 -# Install required spotify packages -if [ $SPOTinstall == "YES" ] -then - wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add - - sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/stretch.list - sudo apt-get update - sudo apt-get --yes --force-yes install mopidy - sudo apt-get --yes --force-yes install libspotify12 python-cffi python-ply python-pycparser python-spotify - sudo apt-get --yes --force-yes install libspotify12 python3-cffi python3-ply python3-pycparser - sudo python3 -m pip install spotify - sudo rm -rf /usr/lib/python2.7/dist-packages/mopidy_spotify* - sudo rm -rf /usr/lib/python2.7/dist-packages/Mopidy_Spotify-* - cd || exit - sudo rm -rf mopidy-spotify - git clone -b fix/web_api_playlists --single-branch https://github.com/princemaxwell/mopidy-spotify.git - cd mopidy-spotify || exit - sudo python setup.py install - cd || exit - # should be removed, if Mopidy-Iris can be installed normally - # pylast >= 3.0.0 removed the python2 support - sudo pip install pylast==2.4.0 - sudo pip install Mopidy-Iris -fi - -# Get github code -cd /home/pi/ || exit -git clone https://github.com/MiczFlor/RPi-Jukebox-RFID.git --branch "${GIT_BRANCH}" - -# check, which branch was cloned -git status - -# the following three lines are needed as long as this is not the master branch: -cd /home/pi/RPi-Jukebox-RFID || exit -git fetch - -# Install more required packages -sudo pip install -r requirements.txt -sudo pip3 install -r /home/pi/RPi-Jukebox-RFID/components/rfid-reader/PN532/requirements.txt - -# actually, for the time being most of the requirements are run here (again). -# the requirements.txt version seems to throw errors. Help if you can to fix this: - -sudo pip install "evdev == 0.7.0" -sudo pip install --upgrade youtube_dl -sudo pip install spidev -sudo pip install git+git://github.com/lthiery/SPI-Py.git#egg=spi-py -sudo pip install pyserial -sudo pip install RPi.GPIO -sudo pip install pi-rc522 - -sudo python3 -m pip install "evdev == 0.7.0" - -# Switch of WiFi power management -sudo iwconfig wlan0 power off - -# Samba configuration settings -# -rw-r--r-- 1 root root 9416 Apr 30 09:02 /etc/samba/smb.conf -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/smb.conf.stretch-default2.sample /etc/samba/smb.conf -sudo chown root:root /etc/samba/smb.conf -sudo chmod 644 /etc/samba/smb.conf -# for $DIRaudioFolders using | as alternate regex delimiter because of the folder path slash -sudo sed -i 's|%DIRaudioFolders%|'"$DIRaudioFolders"'|' /etc/samba/smb.conf -# Samba: create user 'pi' with password 'raspberry' -(echo "raspberry"; echo "raspberry") | sudo smbpasswd -s -a pi - -# Web server configuration settings -# -rw-r--r-- 1 root root 1040 Apr 30 09:19 /etc/lighttpd/lighttpd.conf -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/lighttpd.conf.stretch-default.sample /etc/lighttpd/lighttpd.conf -sudo chown root:root /etc/lighttpd/lighttpd.conf -sudo chmod 644 /etc/lighttpd/lighttpd.conf - -# Web server PHP7 fastcgi conf -# -rw-r--r-- 1 root root 398 Apr 30 09:35 /etc/lighttpd/conf-available/15-fastcgi-php.conf -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/15-fastcgi-php.conf.stretch-default.sample /etc/lighttpd/conf-available/15-fastcgi-php.conf -sudo chown root:root /etc/lighttpd/conf-available/15-fastcgi-php.conf -sudo chmod 644 /etc/lighttpd/conf-available/15-fastcgi-php.conf -# settings for php.ini to support upload -# -rw-r--r-- 1 root root 70999 Jun 14 13:50 /etc/php/7.0/fpm/php.ini -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/php.ini.stretch-default.sample /etc/php/7.0/fpm/php.ini -sudo chown root:root /etc/php/7.0/fpm/php.ini -sudo chmod 644 /etc/php/7.0/fpm/php.ini - -# SUDO users (adding web server here) -# -r--r----- 1 root root 703 Nov 17 21:08 /etc/sudoers -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/sudoers.stretch-default.sample /etc/sudoers -sudo chown root:root /etc/sudoers -sudo chmod 440 /etc/sudoers - -# copy shell script for player -cp /home/pi/RPi-Jukebox-RFID/settings/rfid_trigger_play.conf.sample /home/pi/RPi-Jukebox-RFID/settings/rfid_trigger_play.conf - -# creating files containing editable values for configuration -# DISCONTINUED: now done by MPD? echo "PCM" > /home/pi/RPi-Jukebox-RFID/settings/Audio_iFace_Name -echo "$AUDIOiFace" > /home/pi/RPi-Jukebox-RFID/settings/Audio_iFace_Name -echo "$DIRaudioFolders" > /home/pi/RPi-Jukebox-RFID/settings/Audio_Folders_Path -echo "3" > /home/pi/RPi-Jukebox-RFID/settings/Audio_Volume_Change_Step -echo "100" > /home/pi/RPi-Jukebox-RFID/settings/Max_Volume_Limit -echo "0" > /home/pi/RPi-Jukebox-RFID/settings/Idle_Time_Before_Shutdown -echo "RESTART" > /home/pi/RPi-Jukebox-RFID/settings/Second_Swipe -echo "/home/pi/RPi-Jukebox-RFID/playlists" > /home/pi/RPi-Jukebox-RFID/settings/Playlists_Folders_Path -echo "ON" > /home/pi/RPi-Jukebox-RFID/settings/ShowCover - -# The new way of making the bash daemon is using the helperscripts -# creating the shortcuts and script from a CSV file. -# see scripts/helperscripts/AssignIDs4Shortcuts.php - -# create config file for web app from sample -sudo cp /home/pi/RPi-Jukebox-RFID/htdocs/config.php.sample /home/pi/RPi-Jukebox-RFID/htdocs/config.php - -# Starting web server and php7 -sudo lighttpd-enable-mod fastcgi -sudo lighttpd-enable-mod fastcgi-php -sudo service lighttpd force-reload -sudo service php7.0-fpm restart - -# create copy of GPIO script -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/gpio-buttons.py.sample /home/pi/RPi-Jukebox-RFID/scripts/gpio-buttons.py -sudo chmod +x /home/pi/RPi-Jukebox-RFID/scripts/gpio-buttons.py - -# make sure bash scripts have the right settings -sudo chown pi:www-data /home/pi/RPi-Jukebox-RFID/scripts/*.sh -sudo chmod +x /home/pi/RPi-Jukebox-RFID/scripts/*.sh -sudo chown pi:www-data /home/pi/RPi-Jukebox-RFID/scripts/*.py -sudo chmod +x /home/pi/RPi-Jukebox-RFID/scripts/*.py - -# services to launch after boot using systemd -# -rw-r--r-- 1 root root 304 Apr 30 10:07 phoniebox-rfid-reader.service -# 1. delete old services (this is legacy, might throw errors but is necessary. Valid for versions < 1.1.8-beta) -echo "### Deleting older versions of service daemons. This might throw errors, ignore them" -sudo systemctl disable idle-watchdog -sudo systemctl disable rfid-reader -sudo systemctl disable startup-sound -sudo systemctl disable gpio-buttons -sudo rm /etc/systemd/system/rfid-reader.service -sudo rm /etc/systemd/system/startup-sound.service -sudo rm /etc/systemd/system/gpio-buttons.service -sudo rm /etc/systemd/system/idle-watchdog.service -echo "### Done with erasing old daemons. Stop ignoring errors!" -# 2. install new ones - this is version > 1.1.8-beta -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/phoniebox-rfid-reader.service.stretch-default.sample /etc/systemd/system/phoniebox-rfid-reader.service -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/phoniebox-startup-sound.service.stretch-default.sample /etc/systemd/system/phoniebox-startup-sound.service -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/phoniebox-gpio-buttons.service.stretch-default.sample /etc/systemd/system/phoniebox-gpio-buttons.service -sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/phoniebox-idle-watchdog.service.sample /etc/systemd/system/phoniebox-idle-watchdog.service -sudo chown root:root /etc/systemd/system/phoniebox-rfid-reader.service -sudo chown root:root /etc/systemd/system/phoniebox-startup-sound.service -sudo chown root:root /etc/systemd/system/phoniebox-gpio-buttons.service -sudo chown root:root /etc/systemd/system/phoniebox-idle-watchdog.service -sudo chmod 644 /etc/systemd/system/phoniebox-rfid-reader.service -sudo chmod 644 /etc/systemd/system/phoniebox-startup-sound.service -sudo chmod 644 /etc/systemd/system/phoniebox-gpio-buttons.service -sudo chmod 644 /etc/systemd/system/phoniebox-idle-watchdog.service -# enable the services needed -sudo systemctl enable phoniebox-idle-watchdog -sudo systemctl enable phoniebox-rfid-reader -sudo systemctl enable phoniebox-startup-sound -sudo systemctl enable phoniebox-gpio-buttons - -# copy mp3s for startup and shutdown sound to the right folder -cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/startupsound.mp3.sample /home/pi/RPi-Jukebox-RFID/shared/startupsound.mp3 -cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/shutdownsound.mp3.sample /home/pi/RPi-Jukebox-RFID/shared/shutdownsound.mp3 - -if [ $SPOTinstall == "NO" ] -then - # MPD configuration - # -rw-r----- 1 mpd audio 14043 Jul 17 20:16 /etc/mpd.conf - sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/mpd.conf.sample /etc/mpd.conf - # Change vars to match install config - sudo sed -i 's/%AUDIOiFace%/'"$AUDIOiFace"'/' /etc/mpd.conf - # for $DIRaudioFolders using | as alternate regex delimiter because of the folder path slash - sudo sed -i 's|%DIRaudioFolders%|'"$DIRaudioFolders"'|' /etc/mpd.conf - echo "classic" > /home/pi/RPi-Jukebox-RFID/settings/edition - sudo chown mpd:audio /etc/mpd.conf - sudo chmod 640 /etc/mpd.conf - # update mpc / mpd DB - mpc update -fi - -if [ $SPOTinstall == "YES" ] -then - sudo systemctl disable mpd - sudo systemctl enable mopidy - # Install Config Files - sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/locale.gen.sample /etc/locale.gen - sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/locale.sample /etc/default/locale - sudo locale-gen - sudo mkdir /home/pi/.config - sudo mkdir /home/pi/.config/mopidy - sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/mopidy-etc.sample /etc/mopidy/mopidy.conf - sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/mopidy.sample ~/.config/mopidy/mopidy.conf - echo "plusSpotify" > /home/pi/RPi-Jukebox-RFID/settings/edition - # Change vars to match install config - sudo sed -i 's/%spotify_username%/'"$SPOTIuser"'/' /etc/mopidy/mopidy.conf - sudo sed -i 's/%spotify_password%/'"$SPOTIpass"'/' /etc/mopidy/mopidy.conf - sudo sed -i 's/%spotify_client_id%/'"$SPOTIclientid"'/' /etc/mopidy/mopidy.conf - sudo sed -i 's/%spotify_client_secret%/'"$SPOTIclientsecret"'/' /etc/mopidy/mopidy.conf - sudo sed -i 's/%spotify_username%/'"$SPOTIuser"'/' ~/.config/mopidy/mopidy.conf - sudo sed -i 's/%spotify_password%/'"$SPOTIpass"'/' ~/.config/mopidy/mopidy.conf - sudo sed -i 's/%spotify_client_id%/'"$SPOTIclientid"'/' ~/.config/mopidy/mopidy.conf - sudo sed -i 's/%spotify_client_secret%/'"$SPOTIclientsecret"'/' ~/.config/mopidy/mopidy.conf -fi - -############################### -# WiFi settings (SSID password) -# -# https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md -# -# $WIFIssid -# $WIFIpass -# $WIFIip -# $WIFIipRouter -if [ $WIFIconfig == "YES" ] -then - # DHCP configuration settings - #-rw-rw-r-- 1 root netdev 0 Apr 17 11:25 /etc/dhcpcd.conf - sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/dhcpcd.conf.stretch-default2-noHotspot.sample /etc/dhcpcd.conf - # Change IP for router and Phoniebox - sudo sed -i 's/%WIFIip%/'"$WIFIip"'/' /etc/dhcpcd.conf - sudo sed -i 's/%WIFIipRouter%/'"$WIFIipRouter"'/' /etc/dhcpcd.conf - sudo sed -i 's/%WIFIcountryCode%/'"$WIFIcountryCode"'/' /etc/dhcpcd.conf - # Change user:group and access mod - sudo chown root:netdev /etc/dhcpcd.conf - sudo chmod 664 /etc/dhcpcd.conf - - # WiFi SSID & Password - # -rw-rw-r-- 1 root netdev 137 Jul 16 08:53 /etc/wpa_supplicant/wpa_supplicant.conf - sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/wpa_supplicant.conf.stretch.sample /etc/wpa_supplicant/wpa_supplicant.conf - sudo sed -i 's/%WIFIssid%/'"$WIFIssid"'/' /etc/wpa_supplicant/wpa_supplicant.conf - sudo sed -i 's/%WIFIpass%/'"$WIFIpass"'/' /etc/wpa_supplicant/wpa_supplicant.conf - sudo sed -i 's/%WIFIcountryCode%/'"$WIFIcountryCode"'/' /etc/wpa_supplicant/wpa_supplicant.conf - sudo chown root:netdev /etc/wpa_supplicant/wpa_supplicant.conf - sudo chmod 664 /etc/wpa_supplicant/wpa_supplicant.conf -fi - -# start DHCP -sudo service dhcpcd start -sudo systemctl enable dhcpcd - -# / WiFi settings (SSID password) -############################### - -# / INSTALLATION -##################################################### - -##################################################### -# EXISTING ASSETS TO USE FROM EXISTING INSTALL - -if [ $EXISTINGuse == "YES" ] -then - - # RFID config for system control - if [ $EXISTINGuseRfidConf == "YES" ] - then - # read old values and write them into new file (copied above already) - # do not overwrite but use 'sed' in case there are new vars in new version installed - - # Read the existing RFID config file line by line and use - # only lines which are separated (IFS) by '='. - while IFS='=' read -r key val ; do - # $var should be stripped of possible leading or trailing " - val=${val%\"} - val=${val#\"} - key=${key} - # Additional error check: key should not start with a hash and not be empty. - if [ ! "${key:0:1}" == '#' ] && [ -n "$key" ] - then - # Replace the matching value in the newly created conf file - sed -i 's/%'"$key"'%/'"$val"'/' /home/pi/RPi-Jukebox-RFID/settings/rfid_trigger_play.conf - fi - done