From 58b3b1324049aa076c79c761415213993700d649 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:14:21 +0100 Subject: [PATCH 1/3] Bump mopidy-iris from 3.68.0 to 3.69.2 (#2088) Bumps [mopidy-iris](https://github.com/jaedb/iris) from 3.68.0 to 3.69.2. - [Release notes](https://github.com/jaedb/iris/releases) - [Commits](https://github.com/jaedb/iris/compare/3.68.0...3.69.2) --- updated-dependencies: - dependency-name: mopidy-iris dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements-spotify.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-spotify.txt b/requirements-spotify.txt index d53e1221d..b521b6ac6 100644 --- a/requirements-spotify.txt +++ b/requirements-spotify.txt @@ -1,3 +1,3 @@ # Spotify related requirements # You need to install these with `sudo pip install --upgrade --force-reinstall -r requirements-spotify.txt` - Mopidy-Iris==3.68.0 + Mopidy-Iris==3.69.2 From 7c0660862e7510c98ec4f2e2780addb265127322 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:14:43 +0100 Subject: [PATCH 2/3] Bump php-mock/php-mock-phpunit from 2.7.2 to 2.8.0 (#2089) Bumps [php-mock/php-mock-phpunit](https://github.com/php-mock/php-mock-phpunit) from 2.7.2 to 2.8.0. - [Release notes](https://github.com/php-mock/php-mock-phpunit/releases) - [Commits](https://github.com/php-mock/php-mock-phpunit/compare/2.7.2...2.8.0) --- updated-dependencies: - dependency-name: php-mock/php-mock-phpunit dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index 172aa3a0b..9b282dad3 100644 --- a/composer.lock +++ b/composer.lock @@ -496,16 +496,16 @@ }, { "name": "php-mock/php-mock-phpunit", - "version": "2.7.2", + "version": "2.8.0", "source": { "type": "git", "url": "https://github.com/php-mock/php-mock-phpunit.git", - "reference": "33a99c190d078e77864b8d74cdc91cc4e5342598" + "reference": "56edee85ad3232caa0202f98f2a3c899ab16bdb7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-mock/php-mock-phpunit/zipball/33a99c190d078e77864b8d74cdc91cc4e5342598", - "reference": "33a99c190d078e77864b8d74cdc91cc4e5342598", + "url": "https://api.github.com/repos/php-mock/php-mock-phpunit/zipball/56edee85ad3232caa0202f98f2a3c899ab16bdb7", + "reference": "56edee85ad3232caa0202f98f2a3c899ab16bdb7", "shasum": "" }, "require": { @@ -552,7 +552,7 @@ ], "support": { "issues": "https://github.com/php-mock/php-mock-phpunit/issues", - "source": "https://github.com/php-mock/php-mock-phpunit/tree/2.7.2" + "source": "https://github.com/php-mock/php-mock-phpunit/tree/2.8.0" }, "funding": [ { @@ -560,7 +560,7 @@ "type": "github" } ], - "time": "2023-06-13T07:46:04+00:00" + "time": "2023-10-30T07:06:12+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2006,5 +2006,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From c56888279883eeaac500ea8d6a0376f8391657b4 Mon Sep 17 00:00:00 2001 From: Alvin Schiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Sat, 4 Nov 2023 16:41:54 +0100 Subject: [PATCH 3/3] Merge Autohotspot setup into main install script (#2086) * merge autohotspot setup into main install script * added autohotspot config step * fix intendation * fix tests * add "iw" to needed packages. Update docker packages * refactored into sample confs. disable autohotspot service if not selected. remove old docs * use crontab command. reactivate disable powermanagment. update comments. remove obsolete files and calls. * hamonized function calls * only copy original file if not already present. even with multiple invocation we want to keep the first original file. Delete autohotspot service in helperscript * update CODEOWNERS * remove changes for autohotspot if not selected * ignore output on service check * fixes for "clear autohotspot configurations" * added test for autohotsppt installation * fix intendation * check for activated wifi device * moved autohotspot installation to separate script moved autohotspot.sh to sampleconfig * fix remove crontab entry * unified: dont remove autohotspot configuration * fix refactored device / ssid check logic on boot or after unblock of wifi the device can give additional errorcodes (-11) this caused incorrectly a hotspot start * fix conf file copy handling on multiple invocation * update docs * refactored duplications * fix for deactivated wifi on startup also check for hard blocked wifi * add --force-hotspot option for easier testing * update script with changes from original source * extend service handling durin installation * some clean up * fix var checks * update docs * update docs --- .github/CODEOWNERS | 2 +- ci/Dockerfile.debian | 3 +- ...ot.service.stretch-default2-Hotspot.sample | 4 +- ...hotspot.sh.stretch-default2-Hotspot.sample | 219 +++ ...utohotspot.stretch-default2-Hotspot.sample | 164 -- .../dnsmasq.conf.jessie-WlanAP.sample | 655 -------- ...smasq.conf.stretch-default2-Hotspot.sample | 7 + .../hostapd.conf.jessie-WlanAP.sample | 20 - ...stapd.conf.stretch-default2-Hotspot.sample | 8 +- .../hostapd.jessie-WlanAP.sample | 22 - .../hostapd.stretch-default2-Hotspot.sample | 2 +- .../interfaces.jessie-WlanAP.sample | 13 - ...interfaces.stretch-default2-Hotspot.sample | 5 - scripts/helperscripts/DeleteAllConfig.sh | 9 +- scripts/helperscripts/README.md | 21 +- scripts/helperscripts/autohotspot | 169 -- scripts/helperscripts/setup_autohotspot.sh | 170 ++ ...buster-install-default-with-autohotspot.sh | 1477 ----------------- .../installscripts/buster-install-default.sh | 113 +- .../tests/ShellCheck/PhonieboxInstall.conf | 16 - .../tests/run_installation_tests.sh | 4 +- .../tests/run_installation_tests2.sh | 3 +- .../tests/run_installation_tests3.sh | 3 +- .../installscripts/tests/test_installation.sh | 47 + scripts/playout_controls.sh | 4 + scripts/userscripts/addhotspot.sh | 14 +- 26 files changed, 599 insertions(+), 2575 deletions(-) create mode 100644 misc/sampleconfigs/autohotspot.sh.stretch-default2-Hotspot.sample delete mode 100755 misc/sampleconfigs/autohotspot.stretch-default2-Hotspot.sample delete mode 100755 misc/sampleconfigs/dnsmasq.conf.jessie-WlanAP.sample create mode 100644 misc/sampleconfigs/dnsmasq.conf.stretch-default2-Hotspot.sample delete mode 100755 misc/sampleconfigs/hostapd.conf.jessie-WlanAP.sample delete mode 100755 misc/sampleconfigs/hostapd.jessie-WlanAP.sample delete mode 100755 misc/sampleconfigs/interfaces.jessie-WlanAP.sample delete mode 100755 misc/sampleconfigs/interfaces.stretch-default2-Hotspot.sample delete mode 100755 scripts/helperscripts/autohotspot create mode 100644 scripts/helperscripts/setup_autohotspot.sh delete mode 100644 scripts/installscripts/buster-install-default-with-autohotspot.sh delete mode 100644 scripts/installscripts/tests/ShellCheck/PhonieboxInstall.conf diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 526e0fdae..457e8029d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,4 +1,4 @@ /components/controls/buttons_usb_encoder/ @jeripeierSBB /components/synchronisation/sync-shared @AlvinSchiller /scripts/installscripts/buster-install-default.sh @jeripeierSBB -/scripts/installscripts/buster-install-default-with-autohotspot.sh @jeripeierSBB +/scripts/helperscripts/setup_autohotspot.sh @Groovylein diff --git a/ci/Dockerfile.debian b/ci/Dockerfile.debian index ecfca4460..a9123534b 100644 --- a/ci/Dockerfile.debian +++ b/ci/Dockerfile.debian @@ -20,12 +20,13 @@ RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get update \ && apt-get -y upgrade \ && apt-get -y install \ + alsa-utils \ build-essential \ git \ - iw \ locales \ sudo \ systemd \ + wireless-tools \ wget \ wpasupplicant \ # install internally used packages here to speed up GitHub Action diff --git a/misc/sampleconfigs/autohotspot.service.stretch-default2-Hotspot.sample b/misc/sampleconfigs/autohotspot.service.stretch-default2-Hotspot.sample index 743fba2d4..1e6ccc5fd 100755 --- a/misc/sampleconfigs/autohotspot.service.stretch-default2-Hotspot.sample +++ b/misc/sampleconfigs/autohotspot.service.stretch-default2-Hotspot.sample @@ -4,6 +4,6 @@ After=multi-user.target [Service] Type=oneshot RemainAfterExit=yes -ExecStart=/usr/bin/autohotspot +ExecStart=%AUTOHOTSPOT_SCRIPT% [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target diff --git a/misc/sampleconfigs/autohotspot.sh.stretch-default2-Hotspot.sample b/misc/sampleconfigs/autohotspot.sh.stretch-default2-Hotspot.sample new file mode 100644 index 000000000..cdb56bad6 --- /dev/null +++ b/misc/sampleconfigs/autohotspot.sh.stretch-default2-Hotspot.sample @@ -0,0 +1,219 @@ +#!/bin/bash +#version 0.962-N/HS + +#You may share this script on the condition all references to RaspberryConnect.com +#must be included in copies or derivatives of this script. + +#A script to switch between a wifi network and a non internet routed Hotspot +#Works at startup or with a seperate timer or manually without a reboot +#Other setup required find out more at +#http://www.raspberryconnect.com + +#Additions where made for the Phoniebox project +#https://github.com/MiczFlor/RPi-Jukebox-RFID + +if [ $# -gt 0 ] ; then + if [ $# -eq 1 ] && [ "$1" == "--force-hotspot" ]; then + FORCE_HOTSPOT=1 + else + echo "ignoring unrecognized parameter: $*" + fi +fi + +NO_SSID='NoSSid' +ssidChk="$NO_SSID" + +wifidev="wlan0" #device name to use. Default is wlan0. +#use the command: iw dev ,to see wifi interface name + +IFSdef=$IFS +cnt=0 +#These four lines capture the wifi networks the RPi is setup to use +wpassid=$(awk '/ssid="/{ print $0 }' /etc/wpa_supplicant/wpa_supplicant.conf | awk -F'ssid=' '{ print $2 }' | sed 's/\r//g'| awk 'BEGIN{ORS=","} {print}' | sed 's/\"/''/g' | sed 's/,$//') +IFS="," +ssids=($wpassid) +IFS=$IFSdef #reset back to defaults + + +#Note:If you only want to check for certain SSIDs +#Remove the # in in front of ssids=('mySSID1'.... below and put a # infront of all four lines above +# separated by a space, eg ('mySSID1' 'mySSID2') +#ssids=('mySSID1' 'mySSID2' 'mySSID3') + +#Enter the Routers Mac Addresses for hidden SSIDs, seperated by spaces ie +#( '11:22:33:44:55:66' 'aa:bb:cc:dd:ee:ff' ) +mac=() + +ssidsmac=("${ssids[@]}" "${mac[@]}") #combines ssid and MAC for checking + +CreateAdHocNetwork() +{ + echo "Creating Hotspot" + ip link set dev "$wifidev" down + ip a add %AUTOHOTSPOT_IP%/24 brd + dev "$wifidev" + ip link set dev "$wifidev" up + dhcpcd -k "$wifidev" >/dev/null 2>&1 + systemctl start dnsmasq + systemctl start hostapd +} + +KillHotspot() +{ + echo "Shutting Down Hotspot" + ip link set dev "$wifidev" down + systemctl stop hostapd + systemctl stop dnsmasq + ip addr flush dev "$wifidev" + ip link set dev "$wifidev" up + dhcpcd -n "$wifidev" >/dev/null 2>&1 +} + +CheckWifiUp() +{ + echo "Checking WiFi connection ok" + sleep 20 #give time for connection to be completed to router + if ! wpa_cli -i "$wifidev" status | grep 'ip_address' >/dev/null 2>&1 + then #Failed to connect to wifi (check your wifi settings, password etc) + echo 'Wifi failed to connect, falling back to Hotspot.' + wpa_cli terminate "$wifidev" >/dev/null 2>&1 + CreateAdHocNetwork + fi +} + +InitWPA() { + wpa_supplicant -B -i "$wifidev" -c /etc/wpa_supplicant/wpa_supplicant.conf >/dev/null 2>&1 +} + +CheckServices() +{ + #After some system updates hostapd gets masked using Raspbian Buster, and above. This checks and fixes + #the issue and also checks dnsmasq is ok so the hotspot can be generated. + #Check Hostapd is unmasked and disabled + if (systemctl -all list-unit-files hostapd.service | grep "hostapd.service masked") >/dev/null 2>&1 ;then + systemctl unmask hostapd.service >/dev/null 2>&1 + fi + if (systemctl -all list-unit-files hostapd.service | grep "hostapd.service enabled") >/dev/null 2>&1 ;then + systemctl disable hostapd.service >/dev/null 2>&1 + systemctl stop hostapd >/dev/null 2>&1 + fi + #Check dnsmasq is disabled + if (systemctl -all list-unit-files dnsmasq.service | grep "dnsmasq.service masked") >/dev/null 2>&1 ;then + systemctl unmask dnsmasq >/dev/null 2>&1 + fi + if (systemctl -all list-unit-files dnsmasq.service | grep "dnsmasq.service enabled") >/dev/null 2>&1 ;then + systemctl disable dnsmasq >/dev/null 2>&1 + systemctl stop dnsmasq >/dev/null 2>&1 + fi +} + +CheckDevice() +{ + local j=0 + while [ true ] #wait for wifi if busy, usb wifi is slower. + do + echo "Device availability check: try $j" + if [ $j -ge 5 ]; then + #if no wifi device,ie usb wifi removed, activate wifi so when it is + #reconnected wifi to a router will be available + echo "No wifi device connected" + InitWPA + exit 1 + elif (iw dev "$wifidev" info 2>&1 >/dev/null) ; then + echo "wifi device available" + if (rfkill list wifi -rno HARD,SOFT | grep -i "unblocked.*unblocked") >/dev/null 2>&1 ; then + local wifidev_up=$(ip link show "$wifidev" up) + if [ -z "$wifidev_up" ]; then + echo "wifi is down. setting up" + ip link set dev "$wifidev" up + sleep 2 + fi + return + else + echo "wifi is deactivated" + exit 0 + fi + else + j=$((j + 1)) + sleep 2 + fi + done +} + +FindSSID() +{ + if [ -n "$FORCE_HOTSPOT" ]; then return; fi + + #Check to see what SSID's and MAC addresses are in range + local i=0; j=0 + while [ $i -eq 0 ] + do + scanreply=$(iw dev "$wifidev" scan ap-force 2>&1) + ssidreply=$(echo "$scanreply" | egrep "^BSS|SSID:") + echo "SSID availability check: try $j" + if [ $j -ge 5 ]; then + ssidreply="" + i=1 + elif [ -z "$ssidreply" ] ; then + echo "Error scan SSID's: $scanreply" + j=$((j + 1)) + sleep 2 + else + echo "SSID's in range:" + echo "$ssidreply" + i=1 + fi + done + + for ssid in "${ssidsmac[@]}" + do + if (echo "$ssidreply" | grep "$ssid") >/dev/null 2>&1 + then + #Valid SSid found, passing to script + echo "Valid SSID Detected, assesing Wifi status" + ssidChk=$ssid + return 0 + fi + done +} + +CheckSSID() +{ + #Create Hotspot or connect to valid wifi networks + if [ "$ssidChk" != "$NO_SSID" ] + then + if systemctl status hostapd | grep "(running)" >/dev/null 2>&1 + then #hotspot running and ssid in range + KillHotspot + echo "Hotspot Deactivated, Bringing Wifi Up" + InitWPA + CheckWifiUp + elif { wpa_cli -i "$wifidev" status | grep 'ip_address'; } >/dev/null 2>&1 + then #Already connected + echo "Wifi already connected to a network" + else #ssid exists and no hotspot running connect to wifi network + echo "Connecting to the WiFi Network" + InitWPA + CheckWifiUp + fi + else #ssid or MAC address not in range + if systemctl status hostapd | grep "(running)" >/dev/null 2>&1 + then + echo "Hostspot already active" + elif { wpa_cli status | grep "$wifidev"; } >/dev/null 2>&1 + then + echo "Cleaning wifi files and Activating Hotspot" + wpa_cli terminate >/dev/null 2>&1 + ip addr flush "$wifidev" + ip link set dev "$wifidev" down + rm -r /var/run/wpa_supplicant >/dev/null 2>&1 + CreateAdHocNetwork + else #"No SSID, activating Hotspot" + CreateAdHocNetwork + fi + fi +} + +CheckServices +CheckDevice +FindSSID +CheckSSID diff --git a/misc/sampleconfigs/autohotspot.stretch-default2-Hotspot.sample b/misc/sampleconfigs/autohotspot.stretch-default2-Hotspot.sample deleted file mode 100755 index ad63e4665..000000000 --- a/misc/sampleconfigs/autohotspot.stretch-default2-Hotspot.sample +++ /dev/null @@ -1,164 +0,0 @@ -#!/bin/bash -#version 0.95-4-N/HS - -#You may share this script on the condition a reference to RaspberryConnect.com -#must be included in copies or derivatives of this script. - -#A script to switch between a wifi network and a non internet routed Hotspot -#Works at startup or with a seperate timer or manually without a reboot -#Other setup required find out more at -#http://www.raspberryconnect.com - -wifidev="wlan0" #device name to use. Default is wlan0. -#use the command: iw dev ,to see wifi interface name - -IFSdef=$IFS -cnt=0 -#These four lines capture the wifi networks the RPi is setup to use -wpassid=$(awk '/ssid="/{ print $0 }' /etc/wpa_supplicant/wpa_supplicant.conf | awk -F'ssid=' '{ print $2 }' ORS=',' | sed 's/\"/''/g' | sed 's/,$//') -IFS="," -ssids=($wpassid) -IFS=$IFSdef #reset back to defaults - - -#Note:If you only want to check for certain SSIDs -#Remove the # in in front of ssids=('mySSID1'.... below and put a # infront of all four lines above -# separated by a space, eg ('mySSID1' 'mySSID2') -#ssids=('mySSID1' 'mySSID2' 'mySSID3') - -#Enter the Routers Mac Addresses for hidden SSIDs, seperated by spaces ie -#( '11:22:33:44:55:66' 'aa:bb:cc:dd:ee:ff' ) -mac=() - -ssidsmac=("${ssids[@]}" "${mac[@]}") #combines ssid and MAC for checking - -createAdHocNetwork() -{ - echo "Creating Hotspot" - ip link set dev "$wifidev" down - ip a add 10.0.0.10/24 brd + dev "$wifidev" - ip link set dev "$wifidev" up - dhcpcd -k "$wifidev" >/dev/null 2>&1 - systemctl start dnsmasq - systemctl start hostapd -} - -KillHotspot() -{ - echo "Shutting Down Hotspot" - ip link set dev "$wifidev" down - systemctl stop hostapd - systemctl stop dnsmasq - ip addr flush dev "$wifidev" - ip link set dev "$wifidev" up - dhcpcd -n "$wifidev" >/dev/null 2>&1 -} - -ChkWifiUp() -{ - echo "Checking WiFi connection ok" - sleep 20 #give time for connection to be completed to router - if ! wpa_cli -i "$wifidev" status | grep 'ip_address' >/dev/null 2>&1 - then #Failed to connect to wifi (check your wifi settings, password etc) - echo 'Wifi failed to connect, falling back to Hotspot.' - wpa_cli terminate "$wifidev" >/dev/null 2>&1 - createAdHocNetwork - fi -} - - -FindSSID() -{ -#Check to see what SSID's and MAC addresses are in range -ssidChk=('NoSSid') -i=0; j=0 -until [ $i -eq 1 ] #wait for wifi if busy, usb wifi is slower. -do - ssidreply=$((iw dev "$wifidev" scan ap-force | egrep "^BSS|SSID:") 2>&1) >/dev/null 2>&1 - echo "SSid's in range: " $ssidreply - echo "Device Available Check try " $j - if (($j >= 10)); then #if busy 10 times goto hotspot - echo "Device busy or unavailable 10 times, going to Hotspot" - ssidreply="" - i=1 - elif echo "$ssidreply" | grep "No such device (-19)" >/dev/null 2>&1; then - echo "No Device Reported, try " $j - NoDevice - elif echo "$ssidreply" | grep "Network is down (-100)" >/dev/null 2>&1 ; then - echo "Network Not available, trying again" $j - j=$((j + 1)) - sleep 2 - elif echo "$ssidreplay" | grep "Read-only file system (-30)" >/dev/null 2>&1 ; then - echo "Temporary Read only file system, trying again" - j=$((j + 1)) - sleep 2 - elif ! echo "$ssidreply" | grep "resource busy (-16)" >/dev/null 2>&1 ; then - echo "Device Available, checking SSid Results" - i=1 - else #see if device not busy in 2 seconds - echo "Device unavailable checking again, try " $j - j=$((j + 1)) - sleep 2 - fi -done - -for ssid in "${ssidsmac[@]}" -do - if (echo "$ssidreply" | grep "$ssid") >/dev/null 2>&1 - then - #Valid SSid found, passing to script - echo "Valid SSID Detected, assesing Wifi status" - ssidChk=$ssid - return 0 - else - #No Network found, NoSSid issued" - echo "No SSid found, assessing WiFi status" - ssidChk='NoSSid' - fi -done -} - -NoDevice() -{ - #if no wifi device,ie usb wifi removed, activate wifi so when it is - #reconnected wifi to a router will be available - echo "No wifi device connected" - wpa_supplicant -B -i "$wifidev" -c /etc/wpa_supplicant/wpa_supplicant.conf >/dev/null 2>&1 - exit 1 -} - -FindSSID - -#Create Hotspot or connect to valid wifi networks -if [ "$ssidChk" != "NoSSid" ] -then - if systemctl status hostapd | grep "(running)" >/dev/null 2>&1 - then #hotspot running and ssid in range - KillHotspot - echo "Hotspot Deactivated, Bringing Wifi Up" - wpa_supplicant -B -i "$wifidev" -c /etc/wpa_supplicant/wpa_supplicant.conf >/dev/null 2>&1 - ChkWifiUp - elif { wpa_cli -i "$wifidev" status | grep 'ip_address'; } >/dev/null 2>&1 - then #Already connected - echo "Wifi already connected to a network" - else #ssid exists and no hotspot running connect to wifi network - echo "Connecting to the WiFi Network" - wpa_supplicant -B -i "$wifidev" -c /etc/wpa_supplicant/wpa_supplicant.conf >/dev/null 2>&1 - ChkWifiUp - fi -else #ssid or MAC address not in range - if systemctl status hostapd | grep "(running)" >/dev/null 2>&1 - then - echo "Hostspot already active" - elif { wpa_cli status | grep "$wifidev"; } >/dev/null 2>&1 - then - echo "Cleaning wifi files and Activating Hotspot" - wpa_cli terminate >/dev/null 2>&1 - ip addr flush "$wifidev" - ip link set dev "$wifidev" down - rm -r /var/run/wpa_supplicant >/dev/null 2>&1 - createAdHocNetwork - else #"No SSID, activating Hotspot" - createAdHocNetwork - fi -fi \ No newline at end of file diff --git a/misc/sampleconfigs/dnsmasq.conf.jessie-WlanAP.sample b/misc/sampleconfigs/dnsmasq.conf.jessie-WlanAP.sample deleted file mode 100755 index d12324f0b..000000000 --- a/misc/sampleconfigs/dnsmasq.conf.jessie-WlanAP.sample +++ /dev/null @@ -1,655 +0,0 @@ -# Configuration file for dnsmasq. -# -# Format is one option per line, legal options are the same -# as the long options legal on the command line. See -# "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details. - -# Listen on this specific port instead of the standard DNS port -# (53). Setting this to zero completely disables DNS function, -# leaving only DHCP and/or TFTP. -#port=5353 - -# The following two options make you a better netizen, since they -# tell dnsmasq to filter out queries which the public DNS cannot -# answer, and which load the servers (especially the root servers) -# unnecessarily. If you have a dial-on-demand link they also stop -# these requests from bringing up the link unnecessarily. - -# Never forward plain names (without a dot or domain part) -#domain-needed -# Never forward addresses in the non-routed address spaces. -#bogus-priv - -# Uncomment these to enable DNSSEC validation and caching: -# (Requires dnsmasq to be built with DNSSEC option.) -#conf-file=%%PREFIX%%/share/dnsmasq/trust-anchors.conf -#dnssec - -# Replies which are not DNSSEC signed may be legitimate, because the domain -# is unsigned, or may be forgeries. Setting this option tells dnsmasq to -# check that an unsigned reply is OK, by finding a secure proof that a DS -# record somewhere between the root and the domain does not exist. -# The cost of setting this is that even queries in unsigned domains will need -# one or more extra DNS queries to verify. -#dnssec-check-unsigned - -# Uncomment this to filter useless windows-originated DNS requests -# which can trigger dial-on-demand links needlessly. -# Note that (amongst other things) this blocks all SRV requests, -# so don't use it if you use eg Kerberos, SIP, XMMP or Google-talk. -# This option only affects forwarding, SRV records originating for -# dnsmasq (via srv-host= lines) are not suppressed by it. -#filterwin2k - -# Change this line if you want dns to get its upstream servers from -# somewhere other that /etc/resolv.conf -#resolv-file= - -# By default, dnsmasq will send queries to any of the upstream -# servers it knows about and tries to favour servers to are known -# to be up. Uncommenting this forces dnsmasq to try each query -# with each server strictly in the order they appear in -# /etc/resolv.conf -#strict-order - -# If you don't want dnsmasq to read /etc/resolv.conf or any other -# file, getting its servers from this file instead (see below), then -# uncomment this. -#no-resolv - -# If you don't want dnsmasq to poll /etc/resolv.conf or other resolv -# files for changes and re-read them then uncomment this. -#no-poll - -# Add other name servers here, with domain specs if they are for -# non-public domains. -#server=/localnet/192.168.0.1 - -# Example of routing PTR queries to nameservers: this will send all -# address->name queries for 192.168.3/24 to nameserver 10.1.2.3 -#server=/3.168.192.in-addr.arpa/10.1.2.3 - -# Add local-only domains here, queries in these domains are answered -# from /etc/hosts or DHCP only. -#local=/localnet/ - -# Add domains which you want to force to an IP address here. -# The example below send any host in double-click.net to a local -# web-server. -#address=/double-click.net/127.0.0.1 - -# --address (and --server) work with IPv6 addresses too. -#address=/www.thekelleys.org.uk/fe80::20d:60ff:fe36:f83 - -# Add the IPs of all queries to yahoo.com, google.com, and their -# subdomains to the vpn and search ipsets: -#ipset=/yahoo.com/google.com/vpn,search - -# You can control how dnsmasq talks to a server: this forces -# queries to 10.1.2.3 to be routed via eth1 -# server=10.1.2.3@eth1 - -# and this sets the source (ie local) address used to talk to -# 10.1.2.3 to 192.168.1.1 port 55 (there must be a interface with that -# IP on the machine, obviously). -# server=10.1.2.3@192.168.1.1#55 - -# If you want dnsmasq to change uid and gid to something other -# than the default, edit the following lines. -#user= -#group= - -# If you want dnsmasq to listen for DHCP and DNS requests only on -# specified interfaces (and the loopback) give the name of the -# interface (eg eth0) here. -# Repeat the line for more than one interface. -#interface= -# Or you can specify which interface _not_ to listen on -#except-interface= -# Or which to listen on by address (remember to include 127.0.0.1 if -# you use this.) -#listen-address= -# If you want dnsmasq to provide only DNS service on an interface, -# configure it as shown above, and then use the following line to -# disable DHCP and TFTP on it. -#no-dhcp-interface= - -# On systems which support it, dnsmasq binds the wildcard address, -# even when it is listening on only some interfaces. It then discards -# requests that it shouldn't reply to. This has the advantage of -# working even when interfaces come and go and change address. If you -# want dnsmasq to really bind only the interfaces it is listening on, -# uncomment this option. About the only time you may need this is when -# running another nameserver on the same machine. -#bind-interfaces - -# If you don't want dnsmasq to read /etc/hosts, uncomment the -# following line. -#no-hosts -# or if you want it to read another file, as well as /etc/hosts, use -# this. -#addn-hosts=/etc/banner_add_hosts - -# Set this (and domain: see below) if you want to have a domain -# automatically added to simple names in a hosts-file. -#expand-hosts - -# Set the domain for dnsmasq. this is optional, but if it is set, it -# does the following things. -# 1) Allows DHCP hosts to have fully qualified domain names, as long -# as the domain part matches this setting. -# 2) Sets the "domain" DHCP option thereby potentially setting the -# domain of all systems configured by DHCP -# 3) Provides the domain part for "expand-hosts" -#domain=thekelleys.org.uk - -# Set a different domain for a particular subnet -#domain=wireless.thekelleys.org.uk,192.168.2.0/24 - -# Same idea, but range rather then subnet -#domain=reserved.thekelleys.org.uk,192.68.3.100,192.168.3.200 - -# Uncomment this to enable the integrated DHCP server, you need -# to supply the range of addresses available for lease and optionally -# a lease time. If you have more than one network, you will need to -# repeat this for each network on which you want to supply DHCP -# service. -#dhcp-range=192.168.0.50,192.168.0.150,12h - -# This is an example of a DHCP range where the netmask is given. This -# is needed for networks we reach the dnsmasq DHCP server via a relay -# agent. If you don't know what a DHCP relay agent is, you probably -# don't need to worry about this. -#dhcp-range=192.168.0.50,192.168.0.150,255.255.255.0,12h - -# This is an example of a DHCP range which sets a tag, so that -# some DHCP options may be set only for this network. -#dhcp-range=set:red,192.168.0.50,192.168.0.150 - -# Use this DHCP range only when the tag "green" is set. -#dhcp-range=tag:green,192.168.0.50,192.168.0.150,12h - -# Specify a subnet which can't be used for dynamic address allocation, -# is available for hosts with matching --dhcp-host lines. Note that -# dhcp-host declarations will be ignored unless there is a dhcp-range -# of some type for the subnet in question. -# In this case the netmask is implied (it comes from the network -# configuration on the machine running dnsmasq) it is possible to give -# an explicit netmask instead. -#dhcp-range=192.168.0.0,static - -# Enable DHCPv6. Note that the prefix-length does not need to be specified -# and defaults to 64 if missing/ -#dhcp-range=1234::2, 1234::500, 64, 12h - -# Do Router Advertisements, BUT NOT DHCP for this subnet. -#dhcp-range=1234::, ra-only - -# Do Router Advertisements, BUT NOT DHCP for this subnet, also try and -# add names to the DNS for the IPv6 address of SLAAC-configured dual-stack -# hosts. Use the DHCPv4 lease to derive the name, network segment and -# MAC address and assume that the host will also have an -# IPv6 address calculated using the SLAAC alogrithm. -#dhcp-range=1234::, ra-names - -# Do Router Advertisements, BUT NOT DHCP for this subnet. -# Set the lifetime to 46 hours. (Note: minimum lifetime is 2 hours.) -#dhcp-range=1234::, ra-only, 48h - -# Do DHCP and Router Advertisements for this subnet. Set the A bit in the RA -# so that clients can use SLAAC addresses as well as DHCP ones. -#dhcp-range=1234::2, 1234::500, slaac - -# Do Router Advertisements and stateless DHCP for this subnet. Clients will -# not get addresses from DHCP, but they will get other configuration information. -# They will use SLAAC for addresses. -#dhcp-range=1234::, ra-stateless - -# Do stateless DHCP, SLAAC, and generate DNS names for SLAAC addresses -# from DHCPv4 leases. -#dhcp-range=1234::, ra-stateless, ra-names - -# Do router advertisements for all subnets where we're doing DHCPv6 -# Unless overriden by ra-stateless, ra-names, et al, the router -# advertisements will have the M and O bits set, so that the clients -# get addresses and configuration from DHCPv6, and the A bit reset, so the -# clients don't use SLAAC addresses. -#enable-ra - -# Supply parameters for specified hosts using DHCP. There are lots -# of valid alternatives, so we will give examples of each. Note that -# IP addresses DO NOT have to be in the range given above, they just -# need to be on the same network. The order of the parameters in these -# do not matter, it's permissible to give name, address and MAC in any -# order. - -# Always allocate the host with Ethernet address 11:22:33:44:55:66 -# The IP address 192.168.0.60 -#dhcp-host=11:22:33:44:55:66,192.168.0.60 - -# Always set the name of the host with hardware address -# 11:22:33:44:55:66 to be "fred" -#dhcp-host=11:22:33:44:55:66,fred - -# Always give the host with Ethernet address 11:22:33:44:55:66 -# the name fred and IP address 192.168.0.60 and lease time 45 minutes -#dhcp-host=11:22:33:44:55:66,fred,192.168.0.60,45m - -# Give a host with Ethernet address 11:22:33:44:55:66 or -# 12:34:56:78:90:12 the IP address 192.168.0.60. Dnsmasq will assume -# that these two Ethernet interfaces will never be in use at the same -# time, and give the IP address to the second, even if it is already -# in use by the first. Useful for laptops with wired and wireless -# addresses. -#dhcp-host=11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.60 - -# Give the machine which says its name is "bert" IP address -# 192.168.0.70 and an infinite lease -#dhcp-host=bert,192.168.0.70,infinite - -# Always give the host with client identifier 01:02:02:04 -# the IP address 192.168.0.60 -#dhcp-host=id:01:02:02:04,192.168.0.60 - -# Always give the host with client identifier "marjorie" -# the IP address 192.168.0.60 -#dhcp-host=id:marjorie,192.168.0.60 - -# Enable the address given for "judge" in /etc/hosts -# to be given to a machine presenting the name "judge" when -# it asks for a DHCP lease. -#dhcp-host=judge - -# Never offer DHCP service to a machine whose Ethernet -# address is 11:22:33:44:55:66 -#dhcp-host=11:22:33:44:55:66,ignore - -# Ignore any client-id presented by the machine with Ethernet -# address 11:22:33:44:55:66. This is useful to prevent a machine -# being treated differently when running under different OS's or -# between PXE boot and OS boot. -#dhcp-host=11:22:33:44:55:66,id:* - -# Send extra options which are tagged as "red" to -# the machine with Ethernet address 11:22:33:44:55:66 -#dhcp-host=11:22:33:44:55:66,set:red - -# Send extra options which are tagged as "red" to -# any machine with Ethernet address starting 11:22:33: -#dhcp-host=11:22:33:*:*:*,set:red - -# Give a fixed IPv6 address and name to client with -# DUID 00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2 -# Note the MAC addresses CANNOT be used to identify DHCPv6 clients. -# Note also the they [] around the IPv6 address are obilgatory. -#dhcp-host=id:00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2, fred, [1234::5] - -# Ignore any clients which are not specified in dhcp-host lines -# or /etc/ethers. Equivalent to ISC "deny unknown-clients". -# This relies on the special "known" tag which is set when -# a host is matched. -#dhcp-ignore=tag:!known - -# Send extra options which are tagged as "red" to any machine whose -# DHCP vendorclass string includes the substring "Linux" -#dhcp-vendorclass=set:red,Linux - -# Send extra options which are tagged as "red" to any machine one -# of whose DHCP userclass strings includes the substring "accounts" -#dhcp-userclass=set:red,accounts - -# Send extra options which are tagged as "red" to any machine whose -# MAC address matches the pattern. -#dhcp-mac=set:red,00:60:8C:*:*:* - -# If this line is uncommented, dnsmasq will read /etc/ethers and act -# on the ethernet-address/IP pairs found there just as if they had -# been given as --dhcp-host options. Useful if you keep -# MAC-address/host mappings there for other purposes. -#read-ethers - -# Send options to hosts which ask for a DHCP lease. -# See RFC 2132 for details of available options. -# Common options can be given to dnsmasq by name: -# run "dnsmasq --help dhcp" to get a list. -# Note that all the common settings, such as netmask and -# broadcast address, DNS server and default route, are given -# sane defaults by dnsmasq. You very likely will not need -# any dhcp-options. If you use Windows clients and Samba, there -# are some options which are recommended, they are detailed at the -# end of this section. - -# Override the default route supplied by dnsmasq, which assumes the -# router is the same machine as the one running dnsmasq. -#dhcp-option=3,1.2.3.4 - -# Do the same thing, but using the option name -#dhcp-option=option:router,1.2.3.4 - -# Override the default route supplied by dnsmasq and send no default -# route at all. Note that this only works for the options sent by -# default (1, 3, 6, 12, 28) the same line will send a zero-length option -# for all other option numbers. -#dhcp-option=3 - -# Set the NTP time server addresses to 192.168.0.4 and 10.10.0.5 -#dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5 - -# Send DHCPv6 option. Note [] around IPv6 addresses. -#dhcp-option=option6:dns-server,[1234::77],[1234::88] - -# Send DHCPv6 option for namservers as the machine running -# dnsmasq and another. -#dhcp-option=option6:dns-server,[::],[1234::88] - -# Ask client to poll for option changes every six hours. (RFC4242) -#dhcp-option=option6:information-refresh-time,6h - -# Set the NTP time server address to be the same machine as -# is running dnsmasq -#dhcp-option=42,0.0.0.0 - -# Set the NIS domain name to "welly" -#dhcp-option=40,welly - -# Set the default time-to-live to 50 -#dhcp-option=23,50 - -# Set the "all subnets are local" flag -#dhcp-option=27,1 - -# Send the etherboot magic flag and then etherboot options (a string). -#dhcp-option=128,e4:45:74:68:00:00 -#dhcp-option=129,NIC=eepro100 - -# Specify an option which will only be sent to the "red" network -# (see dhcp-range for the declaration of the "red" network) -# Note that the tag: part must precede the option: part. -#dhcp-option = tag:red, option:ntp-server, 192.168.1.1 - -# The following DHCP options set up dnsmasq in the same way as is specified -# for the ISC dhcpcd in -# http://www.samba.org/samba/ftp/docs/textdocs/DHCP-Server-Configuration.txt -# adapted for a typical dnsmasq installation where the host running -# dnsmasq is also the host running samba. -# you may want to uncomment some or all of them if you use -# Windows clients and Samba. -#dhcp-option=19,0 # option ip-forwarding off -#dhcp-option=44,0.0.0.0 # set netbios-over-TCP/IP nameserver(s) aka WINS server(s) -#dhcp-option=45,0.0.0.0 # netbios datagram distribution server -#dhcp-option=46,8 # netbios node type - -# Send an empty WPAD option. This may be REQUIRED to get windows 7 to behave. -#dhcp-option=252,"\n" - -# Send RFC-3397 DNS domain search DHCP option. WARNING: Your DHCP client -# probably doesn't support this...... -#dhcp-option=option:domain-search,eng.apple.com,marketing.apple.com - -# Send RFC-3442 classless static routes (note the netmask encoding) -#dhcp-option=121,192.168.1.0/24,1.2.3.4,10.0.0.0/8,5.6.7.8 - -# Send vendor-class specific options encapsulated in DHCP option 43. -# The meaning of the options is defined by the vendor-class so -# options are sent only when the client supplied vendor class -# matches the class given here. (A substring match is OK, so "MSFT" -# matches "MSFT" and "MSFT 5.0"). This example sets the -# mtftp address to 0.0.0.0 for PXEClients. -#dhcp-option=vendor:PXEClient,1,0.0.0.0 - -# Send microsoft-specific option to tell windows to release the DHCP lease -# when it shuts down. Note the "i" flag, to tell dnsmasq to send the -# value as a four-byte integer - that's what microsoft wants. See -# http://technet2.microsoft.com/WindowsServer/en/library/a70f1bb7-d2d4-49f0-96d6-4b7414ecfaae1033.mspx?mfr=true -#dhcp-option=vendor:MSFT,2,1i - -# Send the Encapsulated-vendor-class ID needed by some configurations of -# Etherboot to allow is to recognise the DHCP server. -#dhcp-option=vendor:Etherboot,60,"Etherboot" - -# Send options to PXELinux. Note that we need to send the options even -# though they don't appear in the parameter request list, so we need -# to use dhcp-option-force here. -# See http://syslinux.zytor.com/pxe.php#special for details. -# Magic number - needed before anything else is recognised -#dhcp-option-force=208,f1:00:74:7e -# Configuration file name -#dhcp-option-force=209,configs/common -# Path prefix -#dhcp-option-force=210,/tftpboot/pxelinux/files/ -# Reboot time. (Note 'i' to send 32-bit value) -#dhcp-option-force=211,30i - -# Set the boot filename for netboot/PXE. You will only need -# this is you want to boot machines over the network and you will need -# a TFTP server; either dnsmasq's built in TFTP server or an -# external one. (See below for how to enable the TFTP server.) -#dhcp-boot=pxelinux.0 - -# The same as above, but use custom tftp-server instead machine running dnsmasq -#dhcp-boot=pxelinux,server.name,192.168.1.100 - -# Boot for Etherboot gPXE. The idea is to send two different -# filenames, the first loads gPXE, and the second tells gPXE what to -# load. The dhcp-match sets the gpxe tag for requests from gPXE. -#dhcp-match=set:gpxe,175 # gPXE sends a 175 option. -#dhcp-boot=tag:!gpxe,undionly.kpxe -#dhcp-boot=mybootimage - -# Encapsulated options for Etherboot gPXE. All the options are -# encapsulated within option 175 -#dhcp-option=encap:175, 1, 5b # priority code -#dhcp-option=encap:175, 176, 1b # no-proxydhcp -#dhcp-option=encap:175, 177, string # bus-id -#dhcp-option=encap:175, 189, 1b # BIOS drive code -#dhcp-option=encap:175, 190, user # iSCSI username -#dhcp-option=encap:175, 191, pass # iSCSI password - -# Test for the architecture of a netboot client. PXE clients are -# supposed to send their architecture as option 93. (See RFC 4578) -#dhcp-match=peecees, option:client-arch, 0 #x86-32 -#dhcp-match=itanics, option:client-arch, 2 #IA64 -#dhcp-match=hammers, option:client-arch, 6 #x86-64 -#dhcp-match=mactels, option:client-arch, 7 #EFI x86-64 - -# Do real PXE, rather than just booting a single file, this is an -# alternative to dhcp-boot. -#pxe-prompt="What system shall I netboot?" -# or with timeout before first available action is taken: -#pxe-prompt="Press F8 for menu.", 60 - -# Available boot services. for PXE. -#pxe-service=x86PC, "Boot from local disk" - -# Loads /pxelinux.0 from dnsmasq TFTP server. -#pxe-service=x86PC, "Install Linux", pxelinux - -# Loads /pxelinux.0 from TFTP server at 1.2.3.4. -# Beware this fails on old PXE ROMS. -#pxe-service=x86PC, "Install Linux", pxelinux, 1.2.3.4 - -# Use bootserver on network, found my multicast or broadcast. -#pxe-service=x86PC, "Install windows from RIS server", 1 - -# Use bootserver at a known IP address. -#pxe-service=x86PC, "Install windows from RIS server", 1, 1.2.3.4 - -# If you have multicast-FTP available, -# information for that can be passed in a similar way using options 1 -# to 5. See page 19 of -# http://download.intel.com/design/archives/wfm/downloads/pxespec.pdf - - -# Enable dnsmasq's built-in TFTP server -#enable-tftp - -# Set the root directory for files available via FTP. -#tftp-root=/var/ftpd - -# Make the TFTP server more secure: with this set, only files owned by -# the user dnsmasq is running as will be send over the net. -#tftp-secure - -# This option stops dnsmasq from negotiating a larger blocksize for TFTP -# transfers. It will slow things down, but may rescue some broken TFTP -# clients. -#tftp-no-blocksize - -# Set the boot file name only when the "red" tag is set. -#dhcp-boot=tag:red,pxelinux.red-net - -# An example of dhcp-boot with an external TFTP server: the name and IP -# address of the server are given after the filename. -# Can fail with old PXE ROMS. Overridden by --pxe-service. -#dhcp-boot=/var/ftpd/pxelinux.0,boothost,192.168.0.3 - -# If there are multiple external tftp servers having a same name -# (using /etc/hosts) then that name can be specified as the -# tftp_servername (the third option to dhcp-boot) and in that -# case dnsmasq resolves this name and returns the resultant IP -# addresses in round robin fasion. This facility can be used to -# load balance the tftp load among a set of servers. -#dhcp-boot=/var/ftpd/pxelinux.0,boothost,tftp_server_name - -# Set the limit on DHCP leases, the default is 150 -#dhcp-lease-max=150 - -# The DHCP server needs somewhere on disk to keep its lease database. -# This defaults to a sane location, but if you want to change it, use -# the line below. -#dhcp-leasefile=/var/lib/misc/dnsmasq.leases - -# Set the DHCP server to authoritative mode. In this mode it will barge in -# and take over the lease for any client which broadcasts on the network, -# whether it has a record of the lease or not. This avoids long timeouts -# when a machine wakes up on a new network. DO NOT enable this if there's -# the slightest chance that you might end up accidentally configuring a DHCP -# server for your campus/company accidentally. The ISC server uses -# the same option, and this URL provides more information: -# http://www.isc.org/files/auth.html -#dhcp-authoritative - -# Run an executable when a DHCP lease is created or destroyed. -# The arguments sent to the script are "add" or "del", -# then the MAC address, the IP address and finally the hostname -# if there is one. -#dhcp-script=/bin/echo - -# Set the cachesize here. -#cache-size=150 - -# If you want to disable negative caching, uncomment this. -#no-negcache - -# Normally responses which come from /etc/hosts and the DHCP lease -# file have Time-To-Live set as zero, which conventionally means -# do not cache further. If you are happy to trade lower load on the -# server for potentially stale date, you can set a time-to-live (in -# seconds) here. -#local-ttl= - -# If you want dnsmasq to detect attempts by Verisign to send queries -# to unregistered .com and .net hosts to its sitefinder service and -# have dnsmasq instead return the correct NXDOMAIN response, uncomment -# this line. You can add similar lines to do the same for other -# registries which have implemented wildcard A records. -#bogus-nxdomain=64.94.110.11 - -# If you want to fix up DNS results from upstream servers, use the -# alias option. This only works for IPv4. -# This alias makes a result of 1.2.3.4 appear as 5.6.7.8 -#alias=1.2.3.4,5.6.7.8 -# and this maps 1.2.3.x to 5.6.7.x -#alias=1.2.3.0,5.6.7.0,255.255.255.0 -# and this maps 192.168.0.10->192.168.0.40 to 10.0.0.10->10.0.0.40 -#alias=192.168.0.10-192.168.0.40,10.0.0.0,255.255.255.0 - -# Change these lines if you want dnsmasq to serve MX records. - -# Return an MX record named "maildomain.com" with target -# servermachine.com and preference 50 -#mx-host=maildomain.com,servermachine.com,50 - -# Set the default target for MX records created using the localmx option. -#mx-target=servermachine.com - -# Return an MX record pointing to the mx-target for all local -# machines. -#localmx - -# Return an MX record pointing to itself for all local machines. -#selfmx - -# Change the following lines if you want dnsmasq to serve SRV -# records. These are useful if you want to serve ldap requests for -# Active Directory and other windows-originated DNS requests. -# See RFC 2782. -# You may add multiple srv-host lines. -# The fields are ,,,, -# If the domain part if missing from the name (so that is just has the -# service and protocol sections) then the domain given by the domain= -# config option is used. (Note that expand-hosts does not need to be -# set for this to work.) - -# A SRV record sending LDAP for the example.com domain to -# ldapserver.example.com port 389 -#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389 - -# A SRV record sending LDAP for the example.com domain to -# ldapserver.example.com port 389 (using domain=) -#domain=example.com -#srv-host=_ldap._tcp,ldapserver.example.com,389 - -# Two SRV records for LDAP, each with different priorities -#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,1 -#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,2 - -# A SRV record indicating that there is no LDAP server for the domain -# example.com -#srv-host=_ldap._tcp.example.com - -# The following line shows how to make dnsmasq serve an arbitrary PTR -# record. This is useful for DNS-SD. (Note that the -# domain-name expansion done for SRV records _does_not -# occur for PTR records.) -#ptr-record=_http._tcp.dns-sd-services,"New Employee Page._http._tcp.dns-sd-services" - -# Change the following lines to enable dnsmasq to serve TXT records. -# These are used for things like SPF and zeroconf. (Note that the -# domain-name expansion done for SRV records _does_not -# occur for TXT records.) - -#Example SPF. -#txt-record=example.com,"v=spf1 a -all" - -#Example zeroconf -#txt-record=_http._tcp.example.com,name=value,paper=A4 - -# Provide an alias for a "local" DNS name. Note that this _only_ works -# for targets which are names from DHCP or /etc/hosts. Give host -# "bert" another name, bertrand -#cname=bertand,bert - -# For debugging purposes, log each DNS query as it passes through -# dnsmasq. -#log-queries - -# Log lots of extra information about DHCP transactions. -#log-dhcp - -# Include another lot of configuration options. -#conf-file=/etc/dnsmasq.more.conf -#conf-dir=/etc/dnsmasq.d - -# interface which is active -interface=wlan0 - -# interface to ignore -no-dhcp-interface=eth0 - -# IPv4 addresses and lease time -dhcp-range=192.168.1.100,192.168.1.200,24h - -# DNS -dhcp-option=option:dns-server,192.168.1.1 - diff --git a/misc/sampleconfigs/dnsmasq.conf.stretch-default2-Hotspot.sample b/misc/sampleconfigs/dnsmasq.conf.stretch-default2-Hotspot.sample new file mode 100644 index 000000000..96674a303 --- /dev/null +++ b/misc/sampleconfigs/dnsmasq.conf.stretch-default2-Hotspot.sample @@ -0,0 +1,7 @@ +#AutoHotspot Config +#stop DNSmasq from using resolv.conf +no-resolv +#Interface to use +interface=wlan0 +bind-interfaces +dhcp-range=%IP_WITHOUT_LAST_SEGMENT%.100,%IP_WITHOUT_LAST_SEGMENT%.200,12h diff --git a/misc/sampleconfigs/hostapd.conf.jessie-WlanAP.sample b/misc/sampleconfigs/hostapd.conf.jessie-WlanAP.sample deleted file mode 100755 index 123287f10..000000000 --- a/misc/sampleconfigs/hostapd.conf.jessie-WlanAP.sample +++ /dev/null @@ -1,20 +0,0 @@ -# interface and driver -interface=wlan0 -#driver=nl80211 - -# WLAN-config -ssid=jukebox -channel=1 -hw_mode=g -ieee80211n=1 -ieee80211d=1 -country_code=DE -wmm_enabled=1 - -# WLAN-encryption -auth_algs=1 -wpa=2 -wpa_key_mgmt=WPA-PSK -rsn_pairwise=CCMP -wpa_passphrase=Pl4yM3N0w - diff --git a/misc/sampleconfigs/hostapd.conf.stretch-default2-Hotspot.sample b/misc/sampleconfigs/hostapd.conf.stretch-default2-Hotspot.sample index 3b2fadbbf..6b2195dc6 100755 --- a/misc/sampleconfigs/hostapd.conf.stretch-default2-Hotspot.sample +++ b/misc/sampleconfigs/hostapd.conf.stretch-default2-Hotspot.sample @@ -1,7 +1,7 @@ #2.4GHz setup wifi 80211 b,g,n interface=wlan0 driver=nl80211 -ssid=Phoniebox +ssid=%AUTOHOTSPOTssid% hw_mode=g channel=8 wmm_enabled=0 @@ -9,12 +9,12 @@ macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 -wpa_passphrase=PlayItLoud +wpa_passphrase=%AUTOHOTSPOTpass% wpa_key_mgmt=WPA-PSK wpa_pairwise=CCMP TKIP rsn_pairwise=CCMP -#80211n - Change GB to your WiFi country code -country_code=%WIFIcountryCode% +#80211n - Change DE to your WiFi country code +country_code=%AUTOHOTSPOTcountryCode% ieee80211n=1 ieee80211d=1 diff --git a/misc/sampleconfigs/hostapd.jessie-WlanAP.sample b/misc/sampleconfigs/hostapd.jessie-WlanAP.sample deleted file mode 100755 index 28a254107..000000000 --- a/misc/sampleconfigs/hostapd.jessie-WlanAP.sample +++ /dev/null @@ -1,22 +0,0 @@ -# Defaults for hostapd initscript -# -# See /usr/share/doc/hostapd/README.Debian for information about alternative -# methods of managing hostapd. -# -# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration -# file and hostapd will be started during system boot. An example configuration -# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz -# -#DAEMON_CONF="" - -# Additional daemon options to be appended to hostapd command:- -# -d show more debug messages (-dd for even more) -# -K include key data in debug messages -# -t include timestamps in some debug messages -# -# Note that -B (daemon mode) and -P (pidfile) options are automatically -# configured by the init.d script and must not be added to DAEMON_OPTS. -# -#DAEMON_OPTS="" -RUN_DAEMON=yes -DAEMON_CONF="/etc/hostapd/hostapd.conf" diff --git a/misc/sampleconfigs/hostapd.stretch-default2-Hotspot.sample b/misc/sampleconfigs/hostapd.stretch-default2-Hotspot.sample index 5783c15eb..3dcd47857 100755 --- a/misc/sampleconfigs/hostapd.stretch-default2-Hotspot.sample +++ b/misc/sampleconfigs/hostapd.stretch-default2-Hotspot.sample @@ -7,7 +7,7 @@ # file and hostapd will be started during system boot. An example configuration # file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz # -DAEMON_CONF="/etc/hostapd/hostapd.conf" +DAEMON_CONF="%HOSTAPD_CONF%" # Additional daemon options to be appended to hostapd command:- # -d show more debug messages (-dd for even more) diff --git a/misc/sampleconfigs/interfaces.jessie-WlanAP.sample b/misc/sampleconfigs/interfaces.jessie-WlanAP.sample deleted file mode 100755 index d24f0022c..000000000 --- a/misc/sampleconfigs/interfaces.jessie-WlanAP.sample +++ /dev/null @@ -1,13 +0,0 @@ -# Localhost -auto lo -iface lo inet loopback - -# Ethernet -auto eth0 -iface eth0 inet manual - -# WLAN-Interface -allow-hotplug wlan0 -iface wlan0 inet static -address 192.168.1.1 -netmask 255.255.255.0 diff --git a/misc/sampleconfigs/interfaces.stretch-default2-Hotspot.sample b/misc/sampleconfigs/interfaces.stretch-default2-Hotspot.sample deleted file mode 100755 index eb9ccfcb2..000000000 --- a/misc/sampleconfigs/interfaces.stretch-default2-Hotspot.sample +++ /dev/null @@ -1,5 +0,0 @@ -# interfaces(5) file used by ifup(8) and ifdown(8) -# Please note that this file is written to be used with dhcpcd -# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' -# Include files from /etc/network/interfaces.d: -source-directory /etc/network/interfaces.d \ No newline at end of file diff --git a/scripts/helperscripts/DeleteAllConfig.sh b/scripts/helperscripts/DeleteAllConfig.sh index dc73e08e2..38081a051 100755 --- a/scripts/helperscripts/DeleteAllConfig.sh +++ b/scripts/helperscripts/DeleteAllConfig.sh @@ -1,7 +1,7 @@ #!/bin/bash -echo "This script will delete all config files" -echo "including mpd.conf and the like." +echo "This script will delete all config files" +echo "including mpd.conf and the like." read -r -p "Do you want to proceed? [y/N] " response case "$response" in [Yy][Ee][Ss]|[Yy]) @@ -34,14 +34,15 @@ sudo rm /home/pi/RPi-Jukebox-RFID/settings/Second_Swipe sudo rm /home/pi/RPi-Jukebox-RFID/settings/Playlists_Folders_Path sudo rm /home/pi/RPi-Jukebox-RFID/settings/ShowCover sudo rm /home/pi/RPi-Jukebox-RFID/scripts/gpio-buttons.py -sudo rm /etc/systemd/system/phoniebox-rfid-reader.service +sudo rm /etc/systemd/system/phoniebox-rfid-reader.service sudo rm /etc/systemd/system/phoniebox-startup-sound.service sudo rm /etc/systemd/system/phoniebox-gpio-buttons.service sudo rm /etc/systemd/system/phoniebox-idle-watchdog.service -sudo rm /etc/systemd/system/rfid-reader.service +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 +sudo rm /etc/systemd/system/autohotspot.service sudo rm /etc/mpd.conf sudo rm /etc/locale.gen sudo rm /etc/default/locale diff --git a/scripts/helperscripts/README.md b/scripts/helperscripts/README.md index be4914a6e..7b22ab890 100644 --- a/scripts/helperscripts/README.md +++ b/scripts/helperscripts/README.md @@ -42,10 +42,6 @@ including mpd.conf and the like. Deletes sample folders with files and streams inside the $AUDIOFOLDERSPATH directory -## autohotspot - -Changed to autohotspot service - ## cli-player.py Command line player to play folders on the Phoniebox. @@ -66,5 +62,22 @@ not bound to any RFID card, and fixing broken links. A command line replacement some functionality of the phoniebox-web-ui, which challenges the raspberry pi zero. Using this small script significantly reduces resource usage on the system. +## setup_autohotspot.sh + +Script to setup the autohotspot feature. It automatically sets up a wifi hotspot if no known network is found. +This is already included in the main install script, but can also be run manually. Please perform a reboot after you changed the configuration. + +usage: +setup_autohotspot.sh \ \ \ \ \ \ +### activate +``` +chmod +x ./scripts/helperscripts/setup_autohotspot.sh +./scripts/helperscripts/setup_autohotspot.sh . YES phoniebox DE PlayItLoud 10.0.0.5 +``` +### deactivate +``` +chmod +x ./scripts/helperscripts/setup_autohotspot.sh +./scripts/helperscripts/setup_autohotspot.sh . NO +``` diff --git a/scripts/helperscripts/autohotspot b/scripts/helperscripts/autohotspot deleted file mode 100755 index af64f1dbf..000000000 --- a/scripts/helperscripts/autohotspot +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/bash -#version 0.95-41-N/HS - -#You may share this script on the condition a reference to RaspberryConnect.com -#must be included in copies or derivatives of this script. - -#A script to switch between a wifi network and a non internet routed Hotspot -#Works at startup or with a seperate timer or manually without a reboot -#Other setup required find out more at -#http://www.raspberryconnect.com - -wifidev="wlan0" #device name to use. Default is wlan0. -#use the command: iw dev ,to see wifi interface name - -IFSdef=$IFS -cnt=0 -#These four lines capture the wifi networks the RPi is setup to use -wpassid=$(awk '/ssid="/{ print $0 }' /etc/wpa_supplicant/wpa_supplicant.conf | awk -F'ssid=' '{ print $2 }' ORS=',' | sed 's/\"/''/g' | sed 's/,$//') -wpassid=$(echo "${wpassid//[$'\r\n']}") -IFS="," -ssids=($wpassid) -IFS=$IFSdef #reset back to defaults - - -#Note:If you only want to check for certain SSIDs -#Remove the # in in front of ssids=('mySSID1'.... below and put a # infront of all four lines above -# separated by a space, eg ('mySSID1' 'mySSID2') -#ssids=('mySSID1' 'mySSID2' 'mySSID3') - -#Enter the Routers Mac Addresses for hidden SSIDs, seperated by spaces ie -#( '11:22:33:44:55:66' 'aa:bb:cc:dd:ee:ff' ) -mac=() - -ssidsmac=("${ssids[@]}" "${mac[@]}") #combines ssid and MAC for checking - -createAdHocNetwork() -{ - echo "Creating Hotspot" - ip link set dev "$wifidev" down - ip a add 10.0.0.5/24 brd + dev "$wifidev" - ip link set dev "$wifidev" up - dhcpcd -k "$wifidev" >/dev/null 2>&1 - systemctl start dnsmasq - systemctl start hostapd -} - -KillHotspot() -{ - echo "Shutting Down Hotspot" - ip link set dev "$wifidev" down - systemctl stop hostapd - systemctl stop dnsmasq - ip addr flush dev "$wifidev" - ip link set dev "$wifidev" up - dhcpcd -n "$wifidev" >/dev/null 2>&1 -} - -ChkWifiUp() -{ - echo "Checking WiFi connection ok" - sleep 20 #give time for connection to be completed to router - if ! wpa_cli -i "$wifidev" status | grep 'ip_address' >/dev/null 2>&1 - then #Failed to connect to wifi (check your wifi settings, password etc) - echo 'Wifi failed to connect, falling back to Hotspot.' - wpa_cli terminate "$wifidev" >/dev/null 2>&1 - createAdHocNetwork - fi -} - - -FindSSID() -{ -#Check to see what SSID's and MAC addresses are in range -ssidChk=('NoSSid') -i=0; j=0 -until [ $i -eq 1 ] #wait for wifi if busy, usb wifi is slower. -do - ssidreply=$((iw dev "$wifidev" scan ap-force | egrep "^BSS|SSID:") 2>&1) >/dev/null 2>&1 - echo "SSid's in range: " $ssidreply - echo "Device Available Check try " $j - if (($j >= 10)); then #if busy 10 times goto hotspot - echo "Device busy or unavailable 10 times, going to Hotspot" - ssidreply="" - i=1 - elif echo "$ssidreply" | grep "No such device (-19)" >/dev/null 2>&1; then - echo "No Device Reported, try " $j - NoDevice - elif echo "$ssidreply" | grep "Network is down (-100)" >/dev/null 2>&1 ; then - echo "Network Not available, trying again" $j - j=$((j + 1)) - sleep 2 - elif echo "$ssidreply" | grep "Read-only file system (-30)" >/dev/null 2>&1 ; then - echo "Temporary Read only file system, trying again" - j=$((j + 1)) - sleep 2 - elif echo "$ssidreply" | grep "Invalid exchange (-52)" >/dev/null 2>&1 ; then - echo "Temporary unavailable, trying again" - j=$((j + 1)) - sleep 2 - elif ! echo "$ssidreply" | grep "resource busy (-16)" >/dev/null 2>&1 ; then - echo "Device Available, checking SSid Results" - i=1 - else #see if device not busy in 2 seconds - echo "Device unavailable checking again, try " $j - j=$((j + 1)) - sleep 2 - fi -done - -for ssid in "${ssidsmac[@]}" -do - if (echo "$ssidreply" | grep "$ssid") >/dev/null 2>&1 - then - #Valid SSid found, passing to script - echo "Valid SSID Detected, assesing Wifi status" - ssidChk=$ssid - return 0 - else - #No Network found, NoSSid issued" - echo "No SSid found, assessing WiFi status" - ssidChk='NoSSid' - fi -done -} - -NoDevice() -{ - #if no wifi device,ie usb wifi removed, activate wifi so when it is - #reconnected wifi to a router will be available - echo "No wifi device connected" - wpa_supplicant -B -i "$wifidev" -c /etc/wpa_supplicant/wpa_supplicant.conf >/dev/null 2>&1 - exit 1 -} - -FindSSID - -#Create Hotspot or connect to valid wifi networks -if [ "$ssidChk" != "NoSSid" ] -then - if systemctl status hostapd | grep "(running)" >/dev/null 2>&1 - then #hotspot running and ssid in range - KillHotspot - echo "Hotspot Deactivated, Bringing Wifi Up" - wpa_supplicant -B -i "$wifidev" -c /etc/wpa_supplicant/wpa_supplicant.conf >/dev/null 2>&1 - ChkWifiUp - elif { wpa_cli -i "$wifidev" status | grep 'ip_address'; } >/dev/null 2>&1 - then #Already connected - echo "Wifi already connected to a network" - else #ssid exists and no hotspot running connect to wifi network - echo "Connecting to the WiFi Network" - wpa_supplicant -B -i "$wifidev" -c /etc/wpa_supplicant/wpa_supplicant.conf >/dev/null 2>&1 - ChkWifiUp - fi -else #ssid or MAC address not in range - if systemctl status hostapd | grep "(running)" >/dev/null 2>&1 - then - echo "Hostspot already active" - elif { wpa_cli status | grep "$wifidev"; } >/dev/null 2>&1 - then - echo "Cleaning wifi files and Activating Hotspot" - wpa_cli terminate >/dev/null 2>&1 - ip addr flush "$wifidev" - ip link set dev "$wifidev" down - rm -r /var/run/wpa_supplicant >/dev/null 2>&1 - createAdHocNetwork - else #"No SSID, activating Hotspot" - createAdHocNetwork - fi -fi diff --git a/scripts/helperscripts/setup_autohotspot.sh b/scripts/helperscripts/setup_autohotspot.sh new file mode 100644 index 000000000..7e546e2cb --- /dev/null +++ b/scripts/helperscripts/setup_autohotspot.sh @@ -0,0 +1,170 @@ +#!/usr/bin/env bash + +JUKEBOX_HOME_DIR="$1" +AUTOHOTSPOTconfig="$2" +AUTOHOTSPOTssid="$3" +AUTOHOTSPOTcountryCode="$4" +AUTOHOTSPOTpass="$5" +AUTOHOTSPOTip="$6" +if [[ "$#" -lt 2 || ( "${AUTOHOTSPOTconfig}" != "NO" && "${AUTOHOTSPOTconfig}" != "YES") || ( "${AUTOHOTSPOTconfig}" == "YES" && "$#" -ne 6 ) ]] ; then + echo "error: missing paramter" + echo "usage: ./setup_autohotspot.sh " + echo "or" + echo "usage: ./setup_autohotspot.sh " + exit 1 +fi + + +apt_get="sudo apt-get -qq --yes" + +systemd_dir="/etc/systemd/system" + +autohotspot_service="autohotspot.service" +autohotspot_service_path="${systemd_dir}/${autohotspot_service}" +autohotspot_script="/usr/bin/autohotspot" + +dnsmasq_conf=/etc/dnsmasq.conf +hostapd_conf=/etc/hostapd/hostapd.conf +hostapd_deamon=/etc/default/hostapd +dhcpcd_conf=/etc/dhcpcd.conf +dhcpcd_conf_nohook_wpa_supplicant="nohook wpa_supplicant" + +if [ "${AUTOHOTSPOTconfig}" == "YES" ]; then + + # adapted from https://www.raspberryconnect.com/projects/65-raspberrypi-hotspot-accesspoints/158-raspberry-pi-auto-wifi-hotspot-switch-direct-connection + + # power management of wifi: switch off to avoid disconnecting + sudo iwconfig wlan0 power off + + # required packages + ${apt_get} install dnsmasq hostapd iw + sudo systemctl unmask hostapd + sudo systemctl disable hostapd + sudo systemctl stop hostapd + sudo systemctl unmask dnsmasq + sudo systemctl disable dnsmasq + sudo systemctl stop dnsmasq + + # configure DNS + # create flag file or copy present conf to orig file + # to correctly handling future deactivation of autohotspot + if [ ! -f "${dnsmasq_conf}" ]; then + sudo touch "${dnsmasq_conf}.remove" + elif [ ! -f "${dnsmasq_conf}.orig" ] && [ ! -f "${dnsmasq_conf}.remove" ]; then + sudo cp "${dnsmasq_conf}" "${dnsmasq_conf}.orig" + fi + + ip_without_last_segment=$(echo $AUTOHOTSPOTip | cut -d'.' -f1-3) + sudo cp "${JUKEBOX_HOME_DIR}"/misc/sampleconfigs/dnsmasq.conf.stretch-default2-Hotspot.sample "${dnsmasq_conf}" + sudo sed -i "s|%IP_WITHOUT_LAST_SEGMENT%|${ip_without_last_segment}|g" "${dnsmasq_conf}" + sudo chown root:root "${dnsmasq_conf}" + sudo chmod 644 "${dnsmasq_conf}" + + # configure hostapd conf + # create flag file or copy present conf to orig file + # to correctly handling future deactivation of autohotspot + if [ ! -f "${hostapd_conf}" ]; then + sudo touch "${hostapd_conf}.remove" + elif [ ! -f "${hostapd_conf}.orig" ] && [ ! -f "${hostapd_conf}.remove" ]; then + sudo cp "${hostapd_conf}" "${hostapd_conf}.orig" + fi + + sudo cp "${JUKEBOX_HOME_DIR}"/misc/sampleconfigs/hostapd.conf.stretch-default2-Hotspot.sample "${hostapd_conf}" + sudo sed -i "s|%AUTOHOTSPOTssid%|${AUTOHOTSPOTssid}|g" "${hostapd_conf}" + sudo sed -i "s|%AUTOHOTSPOTpass%|${AUTOHOTSPOTpass}|g" "${hostapd_conf}" + sudo sed -i "s|%AUTOHOTSPOTcountryCode%|${AUTOHOTSPOTcountryCode}|g" "${hostapd_conf}" + sudo chown root:root "${hostapd_conf}" + sudo chmod 644 "${hostapd_conf}" + + # configure hostapd daemon + # create flag file or copy present conf to orig file + # to correctly handling future deactivation of autohotspot + if [ ! -f "${hostapd_deamon}" ]; then + sudo touch "${hostapd_deamon}.remove" + elif [ ! -f "${hostapd_deamon}.orig" ] && [ ! -f "${hostapd_deamon}.remove" ]; then + sudo cp "${hostapd_deamon}" "${hostapd_deamon}.orig" + fi + + sudo cp "${JUKEBOX_HOME_DIR}"/misc/sampleconfigs/hostapd.stretch-default2-Hotspot.sample "${hostapd_deamon}" + sudo sed -i "s|%HOSTAPD_CONF%|${hostapd_conf}|g" "${hostapd_deamon}" + sudo chown root:root "${hostapd_deamon}" + sudo chmod 644 "${hostapd_deamon}" + + # configure dhcpcd conf + # create flag file or copy present conf to orig file + # to correctly handling future deactivation of autohotspot + if [ ! -f "${dhcpcd_conf}" ]; then + sudo touch "${dhcpcd_conf}.remove" + sudo touch "${dhcpcd_conf}" + sudo chown root:netdev "${dhcpcd_conf}" + sudo chmod 664 "${dhcpcd_conf}" + elif [ ! -f "${dhcpcd_conf}.orig" ] && [ ! -f "${dhcpcd_conf}.remove" ]; then + sudo cp "${dhcpcd_conf}" "${dhcpcd_conf}.orig" + fi + + if [[ ! $(grep -w "${dhcpcd_conf_nohook_wpa_supplicant}" ${dhcpcd_conf}) ]]; then + sudo bash -c "echo ${dhcpcd_conf_nohook_wpa_supplicant} >> ${dhcpcd_conf}" + fi + + # create service to trigger hotspot + sudo cp "${JUKEBOX_HOME_DIR}"/misc/sampleconfigs/autohotspot.sh.stretch-default2-Hotspot.sample "${autohotspot_script}" + sudo sed -i "s|%AUTOHOTSPOT_IP%|${AUTOHOTSPOTip}|g" "${autohotspot_script}" + sudo chmod +x "${autohotspot_script}" + + sudo cp "${JUKEBOX_HOME_DIR}"/misc/sampleconfigs/autohotspot.service.stretch-default2-Hotspot.sample "${autohotspot_service_path}" + sudo sed -i "s|%AUTOHOTSPOT_SCRIPT%|${autohotspot_script}|g" "${autohotspot_service_path}" + sudo chown root:root "${autohotspot_service_path}" + sudo chmod 644 "${autohotspot_service_path}" + + sudo systemctl enable "${autohotspot_service}" + + # create crontab entry + crontab_user=$(crontab -l 2>/dev/null) + if [[ -z "${crontab_user}" || ! $(echo "${crontab_user}" | grep -w "${autohotspot_script}") ]]; then + (echo "${crontab_user}"; echo "*/5 * * * * sudo ${autohotspot_script} >/dev/null 2>&1") | crontab - + fi + +else + # clear autohotspot configurations made from past installation + + # stop services and clear services + if systemctl list-unit-files "${autohotspot_service}" >/dev/null 2>&1 ; then + sudo systemctl stop hostapd + sudo systemctl stop dnsmasq + sudo systemctl stop "${autohotspot_service}" + sudo systemctl disable "${autohotspot_service}" + sudo rm "${autohotspot_service_path}" + fi + + # remove crontab entry and script + crontab_user=$(crontab -l 2>/dev/null) + if [[ ! -z "${crontab_user}" && $(echo "${crontab_user}" | grep -w "${autohotspot_script}") ]]; then + echo "${crontab_user}" | sed "s|^.*\s${autohotspot_script}\s.*$||g" | crontab - + fi + + if [ -f "${autohotspot_script}" ]; then + sudo rm "${autohotspot_script}" + fi + + # remove config files + if [ -f "${dnsmasq_conf}.remove" ]; then + sudo rm "${dnsmasq_conf}.remove" "${dnsmasq_conf}" + elif [ -f "${dnsmasq_conf}.orig" ]; then + sudo mv "${dnsmasq_conf}.orig" "${dnsmasq_conf}" + fi + if [ -f "${hostapd_conf}.remove" ]; then + sudo rm "${hostapd_conf}.remove" "${hostapd_conf}" + elif [ -f "${hostapd_conf}.orig" ]; then + sudo mv "${hostapd_conf}.orig" "${hostapd_conf}" + fi + if [ -f "${hostapd_deamon}.remove" ]; then + sudo rm "${hostapd_deamon}.remove" "${hostapd_deamon}" + elif [ -f "${hostapd_deamon}.orig" ]; then + sudo mv "${hostapd_deamon}.orig" "${hostapd_deamon}" + fi + if [ -f "${dhcpcd_conf}.remove" ]; then + sudo rm "${dhcpcd_conf}.remove" "${dhcpcd_conf}" + elif [ -f "${dhcpcd_conf}.orig" ]; then + sudo mv "${dhcpcd_conf}.orig" "${dhcpcd_conf}" + fi +fi diff --git a/scripts/installscripts/buster-install-default-with-autohotspot.sh b/scripts/installscripts/buster-install-default-with-autohotspot.sh deleted file mode 100644 index 948b3ebbe..000000000 --- a/scripts/installscripts/buster-install-default-with-autohotspot.sh +++ /dev/null @@ -1,1477 +0,0 @@ -#!/usr/bin/env bash -# -# see https://github.com/MiczFlor/RPi-Jukebox-RFID for details -# -# NOTE: Running automated install (without interaction): -# Each install creates a file called PhonieboxInstall.conf -# in you $HOME directory -# You can install the Phoniebox using such a config file -# which means you don't need to run the interactive install: -# -# 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: -# buster-install-default.sh -a - -# The absolute path to the folder which contains this script -PATHDATA="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -GIT_BRANCH=${GIT_BRANCH:-master} -GIT_URL=${GIT_URL:-https://github.com/MiczFlor/RPi-Jukebox-RFID.git} -echo GIT_BRANCH $GIT_BRANCH -echo GIT_URL $GIT_URL - -DATETIME=$(date +"%Y%m%d_%H%M%S") - -SCRIPTNAME="$(basename $0)" -JOB="${SCRIPTNAME}" - -CURRENT_USER="${SUDO_USER:-$(whoami)}" -HOME_DIR=$(getent passwd "$CURRENT_USER" | cut -d: -f6) -echo "Current User: $CURRENT_USER" -echo "User home dir: $HOME_DIR" - -JUKEBOX_HOME_DIR="${HOME_DIR}/RPi-Jukebox-RFID" -LOGDIR="${HOME_DIR}"/phoniebox_logs -JUKEBOX_BACKUP_DIR="${HOME_DIR}/BACKUP" - -# Get the RaspberryPi OS code name (e.g. buster or bullseye) -OS_CODENAME="$( . /etc/os-release; printf '%s\n' "$VERSION_CODENAME"; )" -printf "Used RaspberryPi OS: ${OS_CODENAME}\n" - -INTERACTIVE=true - -usage() { - printf "Usage: ${SCRIPTNAME} [-a] [-h]\n" - printf " -a\tautomatic/non-interactive mode\n" - printf " -h\thelp\n" - exit 0 -} - -while getopts ":ah" opt; -do - case ${opt} in - a ) INTERACTIVE=false - ;; - h ) usage - ;; - \? ) usage - ;; - esac -done - - -# Setup logger functions -# Input from http://www.ludovicocaldara.net/dba/bash-tips-5-output-logfile/ -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 -} - -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 -} - -checkPrerequisite() { - #currently the user 'pi' is mandatory - #https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/1785 - if [ "${CURRENT_USER}" != "pi" ]; then - echo - echo "ERROR: User must be 'pi'!" - echo " Other usernames are currently not supported." - echo " Please check the wiki for further information" - exit 2 - fi - - if [ "${HOME_DIR}" != "/home/pi" ]; then - echo - echo "ERROR: HomeDir must be '/home/pi'!" - echo " Other usernames are currently not supported." - echo " Please check the wiki for further information" - exit 2 - fi -} - -welcome() { - clear - echo "##################################################### -# ___ __ ______ _ __________ ____ __ _ _ # -# / _ \/ // / __ \/ |/ / _/ __/( _ \ / \( \/ ) # -# / ___/ _ / /_/ / // // _/ ) _ (( O )) ( # -# /_/ /_//_/\____/_/|_/___/____/ (____/ \__/(_/\_) # -# # -##################################################### - -You are turning your Raspberry Pi into a Phoniebox. Good choice. -This INTERACTIVE INSTALL script requires you to be online and -will guide you through the configuration. - -If you want to run the AUTOMATED INSTALL (non-interactive) from -an existing configuration file, do the following: -1. exit this install script (press n) -2. place your PhonieboxInstall.conf in the folder ${HOME_DIR} -3. run the installscript with option -a. For example like this: - .${HOME_DIR}/buster-install-default.sh -a - " - read -rp "Continue interactive installation? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - exit - ;; - *) - echo "Installation continues..." - ;; - esac -} - -reset_install_config_file() { - ##################################################### - # 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 "${HOME_DIR}/PhonieboxInstall.conf" - # Create empty config file - #touch "${HOME_DIR}/PhonieboxInstall.conf" - #echo "# Phoniebox config" > "${HOME_DIR}/PhonieboxInstall.conf" - echo "# Phoniebox config" -} - -config_wifi() { - ##################################################### - # 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 -rp "Do you want to configure your WiFi? [Y/n] " response -echo "" -case "$response" in - [nN][oO]|[nN]) - WIFIconfig=NO - echo "You want to configure WiFi later." - # append variables to config file - echo "WIFIconfig=$WIFIconfig" >> "${HOME_DIR}/PhonieboxInstall.conf" - # make a fallback for WiFi Country Code, because we need that even without WiFi config - echo "WIFIcountryCode=DE" >> "${HOME_DIR}/PhonieboxInstall.conf" - ;; - *) - WIFIconfig=YES - #Ask for SSID - read -rp "* Type SSID name: " WIFIssid - #Ask for wifi country code - read -rp "* WiFi Country Code (e.g. DE, GB, CZ or US): " WIFIcountryCode - #Ask for password - read -rp "* Type password: " WIFIpass - #Ask for IP - read -rp "* Static IP (e.g. 192.168.1.199): " WIFIip - #Ask for Router IP - read -rp "* Router IP (e.g. 192.168.1.1): " WIFIipRouter - echo "" - echo "Your WiFi config:" - echo "SSID : $WIFIssid" - echo "WiFi Country Code : $WIFIcountryCode" - echo "Password : $WIFIpass" - echo "Static IP : $WIFIip" - echo "Router IP : $WIFIipRouter" - read -rp "Are these values correct? [Y/n] " response - echo "" - case "$response" in - [nN][oO]|[nN]) - echo "The values are incorrect." - read -rp "Hit ENTER to exit and start over." INPUT; exit - ;; - *) - # append variables to config file - { - echo "WIFIconfig=\"$WIFIconfig\""; - echo "WIFIcountryCode=\"$WIFIcountryCode\""; - echo "WIFIssid=\"$WIFIssid\""; - echo "WIFIpass=\"$WIFIpass\""; - echo "WIFIip=\"$WIFIip\""; - echo "WIFIipRouter=\"$WIFIipRouter\""; - } >> "${HOME_DIR}/PhonieboxInstall.conf" - ;; - esac - ;; -esac -read -rp "Hit ENTER to proceed to the next step." INPUT -} - -check_existing() { - local jukebox_dir="$1" - local backup_dir="$2" - local home_dir="$3" - - ##################################################### - # 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 "${jukebox_dir}" ]; 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 "${jukebox_dir}"/settings/version ]; then - #echo "The version of your installation is: $(cat ${jukebox_dir}/settings/version)" - - # get the current short commit hash of the repo - CURRENT_REMOTE_COMMIT="$(git ls-remote ${GIT_URL} ${GIT_BRANCH} | cut -c1-7)" - fi - echo "IMPORTANT: you can use the existing content and configuration" - echo "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'. - " - - ### - # See if we find the PhonieboxInstall.conf file - # We need to do this first, because if we re-use the .conf file, we need to append - # the variables regarding the found content to the also found configuration file. - # That way, reading the configuration file for the (potentially) non-interactive - # install procedure will: - # a) overwrite whatever variables regarding re-cycling existing content which might - # be stored in the config file - # b) if there are no variables for dealing with re-cycled context, we will append - # them - to have them for this install - if [ -f "${jukebox_dir}"/settings/PhonieboxInstall.conf ]; then - # ask for re-using the found configuration file - echo "The configuration of your last Phoniebox install was found." - read -rp "Use existing configuration for this installation? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - EXISTINGusePhonieboxInstall=NO - ;; - *) - EXISTINGusePhonieboxInstall=YES - # Copy PhonieboxInstall.conf configuration file to settings folder - sudo cp "${jukebox_dir}"/settings/PhonieboxInstall.conf "${home_dir}"/PhonieboxInstall.conf - sudo chown pi:www-data "${home_dir}"/PhonieboxInstall.conf - sudo chmod 775 "${home_dir}"/PhonieboxInstall.conf - echo "The existing configuration will be used." - echo "Just a few more questions to answer." - read -rp "Hit ENTER to proceed to the next step." INPUT - clear - ;; - esac - fi - - # Delete or use existing installation? - read -rp "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." - sudo rm -rf "${jukebox_dir}" - read -rp "Hit ENTER to proceed to the next step." INPUT - ;; - *) - EXISTINGuse=YES - # CREATE BACKUP - # delete existing BACKUP dir if exists - if [ -d "${backup_dir}" ]; then - sudo rm -r "${backup_dir}" - fi - # move install to BACKUP dir - mv "${jukebox_dir}" "${backup_dir}" - # delete .git dir - if [ -d "${backup_dir}"/.git ]; then - sudo rm -r "${backup_dir}"/.git - fi - # delete placeholder files so moving the folder content back later will not create git pull conflicts - rm "${backup_dir}"/shared/audiofolders/placeholder - rm "${backup_dir}"/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 -rp "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" >> "${HOME_DIR}/PhonieboxInstall.conf" - - read -rp "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" >> "${HOME_DIR}/PhonieboxInstall.conf" - - read -rp "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" >> "${HOME_DIR}/PhonieboxInstall.conf" - - read -rp "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" >> "${HOME_DIR}/PhonieboxInstall.conf" - - if [ "$(printf '%s\n' "2.1" "$(cat ~/BACKUP/settings/version-number)" | sort -V | head -n1)" = "2.1" ]; then - read -rp "GPIO: use existing file? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - EXISTINGuseGpio=NO - ;; - *) - EXISTINGuseGpio=YES - ;; - esac - else - echo "" - echo "Warning! -The configuration of GPIO-Devices has changed in the new version -and needs to be reconfigured. For further info check out the wiki: -https://github.com/MiczFlor/RPi-Jukebox-RFID/wiki/Using-GPIO-hardware-buttons" - read -rp "Hit ENTER to proceed to the next step." INPUT - config_gpio - fi - # append variables to config file - echo "EXISTINGuseGpio=$EXISTINGuseGpio" >> "${HOME_DIR}/PhonieboxInstall.conf" - - read -rp "Button USB Encoder: use existing device and button mapping? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - EXISTINGuseButtonUSBEncoder=NO - ;; - *) - EXISTINGuseButtonUSBEncoder=YES - ;; - esac - # append variables to config file - echo "EXISTINGuseButtonUSBEncoder=$EXISTINGuseButtonUSBEncoder" >> "${HOME_DIR}/PhonieboxInstall.conf" - - echo "Thanks. Got it." - echo "The existing install can be found in the BACKUP directory." - read -rp "Hit ENTER to proceed to the next step." INPUT - ;; - esac - fi - # append variables to config file - echo "EXISTINGuse=$EXISTINGuse" >> "${HOME_DIR}/PhonieboxInstall.conf" - - # Check if we found a Phoniebox install configuration earlier and ask if to run this now - if [ "${EXISTINGusePhonieboxInstall}" == "YES" ]; then - clear - echo "Using the existing configuration, you can run a non-interactive install." - echo "This will re-cycle found content (specified just now) as well as the" - echo "system information from last time (wifi, audio interface, spotify, etc.)." - read -rp "Do you want to run a non-interactive installation? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - ;; - *) - cd "${home_dir}" - clear - ./buster-install-default.sh -a - exit - ;; - esac - fi -} - -config_audio_interface() { - ##################################################### - # Audio iFace - - clear - - echo "##################################################### -# -# CONFIGURE AUDIO INTERFACE (iFace) -# -# The default RPi audio interface is 'Headphone'. -# But this does not work for every setup. Here a list of -# available iFace names: -" - amixer scontrols - echo " " - read -rp "Use Headphone as iFace? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - read -rp "Type the iFace name you want to use:" AUDIOiFace - ;; - *) - AUDIOiFace="Headphone" - ;; - esac - # append variables to config file - echo "AUDIOiFace=\"$AUDIOiFace\"" >> "${HOME_DIR}/PhonieboxInstall.conf" - echo "Your iFace is called '$AUDIOiFace'" - read -rp "Hit ENTER to proceed to the next step." INPUT -} - -config_spotify() { - ##################################################### - # Configure spotify - - clear - - echo "##################################################### -# -# OPTIONAL: INCLUDE SPOTIFY -# -# Note: if this is your first time installing a phoniebox -# it might be best to do a test install without Spotify -# to make sure all your hardware works. -# -# If you want to include Spotify, MUST have your -# credentials ready: -# -# * username -# * password -# * client_id -# * client_secret - -" - read -rp "Do you want to enable Spotify? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - SPOTinstall=NO - echo "You don't want spotify support." - ;; - *) - SPOTinstall=YES - clear - echo "##################################################### -# -# CREDENTIALS for Spotify -# -# 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! -# -" - read -rp "Type your Spotify username: " SPOTIuser - read -rp "Type your Spotify password: " SPOTIpass - read -rp "Type your client_id: " SPOTIclientid - read -rp "Type your client_secret: " SPOTIclientsecret - ;; - esac - # append variables to config file - { - echo "SPOTinstall=\"$SPOTinstall\""; - echo "SPOTIuser=\"$SPOTIuser\""; - echo "SPOTIpass=\"$SPOTIpass\""; - echo "SPOTIclientid=\"$SPOTIclientid\""; - echo "SPOTIclientsecret=\"$SPOTIclientsecret\"" - } >> "${HOME_DIR}/PhonieboxInstall.conf" - read -rp "Hit ENTER to proceed to the next step." INPUT -} - -config_mpd() { - ##################################################### - # 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 -rp "Do you want to configure MPD? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - MPDconfig=NO - echo "You want to configure MPD later." - ;; - *) - MPDconfig=YES - echo "MPD will be set up with default values." - ;; - esac - # append variables to config file - echo "MPDconfig=\"$MPDconfig\"" >> "${HOME_DIR}/PhonieboxInstall.conf" - read -rp "Hit ENTER to proceed to the next step." INPUT -} - -config_audio_folder() { - local jukebox_dir="$1" - - ##################################################### - # Folder path for audio files - # default: $HOME/RPi-Jukebox-RFID/shared/audiofolders - - clear - - echo "##################################################### -# -# FOLDER CONTAINING AUDIO FILES -# -# The default location for folders containing audio files: -# ${jukebox_dir}/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 -rp "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: ${jukebox_dir}/shared/audiofolders" - read -r DIRaudioFolders - ;; - *) - DIRaudioFolders="${jukebox_dir}/shared/audiofolders" - ;; - esac - # append variables to config file - echo "DIRaudioFolders=\"$DIRaudioFolders\"" >> "${HOME_DIR}/PhonieboxInstall.conf" - echo "Your audio folders live in this dir:" - echo "${DIRaudioFolders}" - read -rp "Hit ENTER to proceed to the next step." INPUT -} - -check_variable() { - local variable=${1} - # check if variable exist and if it's empty - test -z "${!variable+x}" && echo "ERROR: \$${variable} is missing!" && fail=true && return - test "${!variable}" == "" && echo "ERROR: \$${variable} is empty!" && fail=true -} - -config_gpio() { - ##################################################### - # Configure GPIO - - clear - - echo "##################################################### -# -# ACTIVATE GPIO-Control -# -# Activation of the GPIO-Control-Service, which mangages Buttons -# or a Rotary Encoder for Volume and/or Track control. -# To configure the controls please consult the wiki: -# https://github.com/MiczFlor/RPi-Jukebox-RFID/wiki/Using-GPIO-hardware-buttons -# It's also possible to activate the service later (see wiki). -" - read -rp "Do you want to activate the GPIO-Control-Service? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - GPIOconfig=NO - echo "You don't want to activate GPIO-Controls now." - ;; - *) - GPIOconfig=YES - echo "GPIO-Control-Service will be activated and set to default values." - ;; - esac - # append variables to config file - echo "GPIOconfig=\"$GPIOconfig\"" >> "${HOME_DIR}/PhonieboxInstall.conf" - echo "" - read -rp "Hit ENTER to proceed to the next step." INPUT -} - -check_config_file() { - local install_conf="${HOME_DIR}/PhonieboxInstall.conf" - echo "Checking PhonieboxInstall.conf..." - # check that PhonieboxInstall.conf exists and is not empty - - # check if config file exists - if [[ -f "${install_conf}" ]]; then - # Source config file - source "${install_conf}" - cat "${install_conf}" - echo "" - else - echo "ERROR: ${install_conf} does not exist!" - exit 1 - fi - - fail=false - if [[ -z "${WIFIconfig+x}" ]]; then - echo "ERROR: \$WIFIconfig is missing or not set!" && fail=true - else - if [[ "$WIFIconfig" == "YES" ]]; then - check_variable "WIFIcountryCode" - check_variable "WIFIssid" - check_variable "WIFIpass" - check_variable "WIFIip" - check_variable "WIFIipRouter" - fi - fi - check_variable "EXISTINGuse" - check_variable "AUDIOiFace" - - if [[ -z "${SPOTinstall+x}" ]]; then - echo "ERROR: \$SPOTinstall is missing or not set!" && fail=true - else - if [ "$SPOTinstall" == "YES" ]; then - check_variable "SPOTIuser" - check_variable "SPOTIpass" - check_variable "SPOTIclientid" - check_variable "SPOTIclientsecret" - fi - fi - check_variable "MPDconfig" - check_variable "DIRaudioFolders" - check_variable "GPIOconfig" - - if [ "${fail}" == "true" ]; then - exit 1 - fi - - echo "" -} - -samba_config() { - local smb_conf="/etc/samba/smb.conf" - echo "Configuring Samba..." - # Samba configuration settings - # -rw-r--r-- 1 root root 9416 Apr 30 09:02 /etc/samba/smb.conf - sudo cp "${jukebox_dir}"/misc/sampleconfigs/smb.conf.buster-default.sample ${smb_conf} - sudo chown root:root "${smb_conf}" - sudo chmod 644 "${smb_conf}" - # for $DIRaudioFolders using | as alternate regex delimiter because of the folder path slash - sudo sed -i 's|%DIRaudioFolders%|'"$DIRaudioFolders"'|' "${smb_conf}" - # Replace homedir; double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${smb_conf}" - # Samba: create user 'pi' with password 'raspberry' - # ToDo: use current user with a default password - (echo "raspberry"; echo "raspberry") | sudo smbpasswd -s -a pi -} - -web_server_config() { - local lighthttpd_conf="/etc/lighttpd/lighttpd.conf" - local fastcgi_php_conf="/etc/lighttpd/conf-available/15-fastcgi-php.conf" - local php_ini="/etc/php/$(ls -1 /etc/php)/cgi/php.ini" - local sudoers="/etc/sudoers" - - echo "Configuring web server..." - # Web server configuration settings - # -rw-r--r-- 1 root root 1040 Apr 30 09:19 /etc/lighttpd/lighttpd.conf - sudo cp "${jukebox_dir}"/misc/sampleconfigs/lighttpd.conf.buster-default.sample "${lighthttpd_conf}" - sudo chown root:root "${lighthttpd_conf}" - sudo chmod 644 "${lighthttpd_conf}" - # double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${lighthttpd_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 "${jukebox_dir}"/misc/sampleconfigs/15-fastcgi-php.conf.buster-default.sample ${fastcgi_php_conf} - sudo chown root:root "${fastcgi_php_conf}" - sudo chmod 644 "${fastcgi_php_conf}" - - # settings for php.ini to support upload - # -rw-r--r-- 1 root root 70999 Jun 14 13:50 /etc/php/7.3/cgi/php.ini - sudo cp "${jukebox_dir}"/misc/sampleconfigs/php.ini.buster-default.sample ${php_ini} - sudo chown root:root "${php_ini}" - sudo chmod 644 "${php_ini}" - - # SUDO users (adding web server here) - # -r--r----- 1 root root 703 Nov 17 21:08 /etc/sudoers - sudo cp "${jukebox_dir}"/misc/sampleconfigs/sudoers.buster-default.sample ${sudoers} - sudo chown root:root "${sudoers}" - sudo chmod 440 "${sudoers}" -} - -install_main() { - local jukebox_dir="$1" - local apt_get="sudo apt-get -qq --yes" - local allow_downgrades="--allow-downgrades --allow-remove-essential --allow-change-held-packages" - - 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. -" - - if [[ ${INTERACTIVE} == "true" ]]; then - read -rp "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 "${HOME_DIR}/PhonieboxInstall.conf" - echo - exit - ;; - esac - fi - - # Start logging here - log_open - - # Add conffile into logfile for better debugging - echo "################################################" - grep -v -e "SPOTI" -e "WIFIpass" "${HOME_DIR}/PhonieboxInstall.conf" - echo "################################################" - - ##################################################### - # 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 - . "${HOME_DIR}/PhonieboxInstall.conf" - - # power management of wifi: switch off to avoid disconnecting - sudo iwconfig wlan0 power off - - # in the docker test env fiddling with resolv.conf causes issues, see https://stackoverflow.com/a/60576223 - if [ "$DOCKER_RUNNING" != "true" ]; then - # create backup of /etc/resolv.conf - sudo cp /etc/resolv.conf /etc/resolv.conf.orig - fi - - # Generate locales - sudo locale-gen "${LANG}" - - # Install required packages - sudo mkdir -p /etc/apt/keyrings - - ${apt_get} update - ${apt_get} upgrade - - # some packages are only available on raspberry pi's but not on test docker containers running on x86_64 machines - if [[ $(uname -m) =~ ^armv.+$ ]]; then - ${apt_get} ${allow_downgrades} install raspberrypi-kernel-headers - fi - - ${apt_get} ${allow_downgrades} install samba samba-common-bin gcc lighttpd php-common php-cgi php at mpd mpc mpg123 git ffmpeg resolvconf spi-tools netcat alsa-utils lsof procps - - # in the docker test env fiddling with resolv.conf causes issues, see https://stackoverflow.com/a/60576223 - if [ "$DOCKER_RUNNING" != "true" ]; then - # restore backup of /etc/resolv.conf in case installation of resolvconf cleared it - sudo cp /etc/resolv.conf.orig /etc/resolv.conf - fi - - # prepare python3 - ${apt_get} ${allow_downgrades} install python3 python3-dev python3-pip python3-setuptools python3-wheel python3-mutagen python3-gpiozero python3-spidev - - # use python3.7 as default - sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1 - - # Get github code - cd "${HOME_DIR}" || exit - git clone ${GIT_URL} --branch "${GIT_BRANCH}" - - # VERSION of installation - - # Get version number - VERSION_NO=`cat ${jukebox_dir}/settings/version-number` - - # add used git branch and commit hash to version file - USED_BRANCH="$(git --git-dir=${jukebox_dir}/.git rev-parse --abbrev-ref HEAD)" - - # add git commit hash to version file - COMMIT_NO="$(git --git-dir=${jukebox_dir}/.git describe --always)" - - echo "${VERSION_NO} - ${COMMIT_NO} - ${USED_BRANCH}" > ${jukebox_dir}/settings/version - chmod 777 ${jukebox_dir}/settings/version - - # Install required spotify packages - if [ "${SPOTinstall}" == "YES" ]; then - 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 - - sudo wget -q -O /etc/apt/keyrings/mopidy-archive-keyring.gpg https://apt.mopidy.com/mopidy.gpg - sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/${OS_CODENAME}.list - ${apt_get} update - ${apt_get} upgrade - ${apt_get} install libspotify-dev - ${apt_get} ${allow_downgrades} install mopidy mopidy-mpd mopidy-local mopidy-spotify - ${apt_get} ${allow_downgrades} install libspotify12 python3-cffi python3-ply python3-pycparser python3-spotify - - # Install necessary Python packages - sudo python3 -m pip install --upgrade --force-reinstall -q -r "${jukebox_dir}"/requirements-spotify.txt - fi - - # Install more required packages - echo "Installing additional Python packages..." - sudo python3 -m pip install --upgrade --force-reinstall -q -r "${jukebox_dir}"/requirements.txt - - samba_config - - web_server_config - - # copy shell script for player - cp "${jukebox_dir}"/settings/rfid_trigger_play.conf.sample "${jukebox_dir}"/settings/rfid_trigger_play.conf - - # creating files containing editable values for configuration - echo "$AUDIOiFace" > "${jukebox_dir}"/settings/Audio_iFace_Name - echo "$DIRaudioFolders" > "${jukebox_dir}"/settings/Audio_Folders_Path - echo "3" > "${jukebox_dir}"/settings/Audio_Volume_Change_Step - echo "100" > "${jukebox_dir}"/settings/Max_Volume_Limit - echo "0" > "${jukebox_dir}"/settings/Idle_Time_Before_Shutdown - echo "RESTART" > "${jukebox_dir}"/settings/Second_Swipe - echo "${jukebox_dir}/playlists" > "${jukebox_dir}"/settings/Playlists_Folders_Path - echo "ON" > "${jukebox_dir}"/settings/ShowCover - - # sample file for debugging with all options set to FALSE - sudo cp "${jukebox_dir}"/settings/debugLogging.conf.sample "${jukebox_dir}"/settings/debugLogging.conf - sudo chmod 777 "${jukebox_dir}"/settings/debugLogging.conf - - # 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 "${jukebox_dir}"/htdocs/config.php.sample "${jukebox_dir}"/htdocs/config.php - # double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${jukebox_dir}"/htdocs/config.php - - # Starting web server and php7 - sudo lighttpd-enable-mod fastcgi - sudo lighttpd-enable-mod fastcgi-php - sudo service lighttpd force-reload - - # make sure bash scripts have the right settings - sudo chown pi:www-data "${jukebox_dir}"/scripts/*.sh - sudo chmod +x "${jukebox_dir}"/scripts/*.sh - sudo chown pi:www-data "${jukebox_dir}"/scripts/*.py - sudo chmod +x "${jukebox_dir}"/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) - local systemd_dir="/etc/systemd/system" - 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 phoniebox-startup-sound - sudo systemctl disable gpio-buttons - sudo systemctl disable phoniebox-rotary-encoder - sudo systemctl disable phoniebox-gpio-buttons.service - sudo rm "${systemd_dir}"/rfid-reader.service - sudo rm "${systemd_dir}"/startup-sound.service - sudo rm "${systemd_dir}"/gpio-buttons.service - sudo rm "${systemd_dir}"/idle-watchdog.service - sudo rm "${systemd_dir}"/phoniebox-rotary-encoder.service - sudo rm "${systemd_dir}"/phoniebox-gpio-buttons.service - echo "### Done with erasing old daemons. Stop ignoring errors!" - # 2. install new ones - this is version > 1.1.8-beta - RFID_READER_SERVICE="${systemd_dir}/phoniebox-rfid-reader.service" - sudo cp "${jukebox_dir}"/misc/sampleconfigs/phoniebox-rfid-reader.service.stretch-default.sample "${RFID_READER_SERVICE}" - # Replace homedir; double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${RFID_READER_SERVICE}" - - #startup sound now part of phoniebox-startup-scripts - #sudo cp "${jukebox_dir}"/misc/sampleconfigs/phoniebox-startup-sound.service.stretch-default.sample "${systemd_dir}"/phoniebox-startup-sound.service - STARTUP_SCRIPT_SERVICE="${systemd_dir}/phoniebox-startup-scripts.service" - sudo cp "${jukebox_dir}"/misc/sampleconfigs/phoniebox-startup-scripts.service.stretch-default.sample "${STARTUP_SCRIPT_SERVICE}" - # Replace homedir; double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${STARTUP_SCRIPT_SERVICE}" - - IDLE_WATCHDOG_SERVICE="${systemd_dir}/phoniebox-idle-watchdog.service" - sudo cp "${jukebox_dir}"/misc/sampleconfigs/phoniebox-idle-watchdog.service.sample "${IDLE_WATCHDOG_SERVICE}" - # Replace homedir; double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${IDLE_WATCHDOG_SERVICE}" - - if [[ "${GPIOconfig}" == "YES" ]]; then - GPIO_CONTROL_SERVICE="${systemd_dir}/phoniebox-gpio-control.service" - sudo cp "${jukebox_dir}"/misc/sampleconfigs/phoniebox-gpio-control.service.sample "${GPIO_CONTROL_SERVICE}" - # Replace homedir; double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${GPIO_CONTROL_SERVICE}" - fi - - sudo chown root:root "${systemd_dir}"/phoniebox-*.service - sudo chmod 644 "${systemd_dir}"/phoniebox-*.service - # enable the services needed - sudo systemctl enable phoniebox-idle-watchdog - sudo systemctl enable phoniebox-rfid-reader - #startup sound is part of phoniebox-startup-scripts now - #sudo systemctl enable phoniebox-startup-sound - sudo systemctl enable phoniebox-startup-scripts - # copy mp3s for startup and shutdown sound to the right folder - cp "${jukebox_dir}"/misc/sampleconfigs/startupsound.mp3.sample "${jukebox_dir}"/shared/startupsound.mp3 - cp "${jukebox_dir}"/misc/sampleconfigs/shutdownsound.mp3.sample "${jukebox_dir}"/shared/shutdownsound.mp3 - - # Spotify config - if [ "${SPOTinstall}" == "YES" ]; then - local etc_mopidy_conf="/etc/mopidy/mopidy.conf" - local mopidy_conf="${HOME_DIR}/.config/mopidy/mopidy.conf" - echo "Configuring Spotify support..." - sudo systemctl disable mpd - sudo systemctl enable mopidy - # Install Config Files - sudo cp "${jukebox_dir}"/misc/sampleconfigs/locale.gen.sample /etc/locale.gen - sudo cp "${jukebox_dir}"/misc/sampleconfigs/locale.sample /etc/default/locale - sudo locale-gen - mkdir -p "${HOME_DIR}"/.config/mopidy - sudo cp "${jukebox_dir}"/misc/sampleconfigs/mopidy-etc.sample "${etc_mopidy_conf}" - cp "${jukebox_dir}"/misc/sampleconfigs/mopidy.sample "${mopidy_conf}" - # Change vars to match install config - sudo sed -i 's/%spotify_username%/'"$SPOTIuser"'/' "${etc_mopidy_conf}" - sudo sed -i 's/%spotify_password%/'"$SPOTIpass"'/' "${etc_mopidy_conf}" - sudo sed -i 's/%spotify_client_id%/'"$SPOTIclientid"'/' "${etc_mopidy_conf}" - sudo sed -i 's/%spotify_client_secret%/'"$SPOTIclientsecret"'/' "${etc_mopidy_conf}" - # for $DIRaudioFolders using | as alternate regex delimiter because of the folder path slash - sudo sed -i 's|%DIRaudioFolders%|'"$DIRaudioFolders"'|' "${etc_mopidy_conf}" - # Replace homedir; double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${etc_mopidy_conf}" - - sed -i 's/%spotify_username%/'"$SPOTIuser"'/' "${mopidy_conf}" - sed -i 's/%spotify_password%/'"$SPOTIpass"'/' "${mopidy_conf}" - sed -i 's/%spotify_client_id%/'"$SPOTIclientid"'/' "${mopidy_conf}" - sed -i 's/%spotify_client_secret%/'"$SPOTIclientsecret"'/' "${mopidy_conf}" - # for $DIRaudioFolders using | as alternate regex delimiter because of the folder path slash - sudo sed -i 's|%DIRaudioFolders%|'"$DIRaudioFolders"'|' "${mopidy_conf}" - # Replace homedir; double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${mopidy_conf}" - fi - - # GPIO-Control - if [[ "${GPIOconfig}" == "YES" ]]; then - sudo python3 -m pip install --upgrade --force-reinstall -q -r "${jukebox_dir}"/requirements-GPIO.txt - sudo systemctl enable phoniebox-gpio-control.service - if [[ ! -f "${jukebox_dir}"/settings/gpio_settings.ini ]]; then - cp "${jukebox_dir}"/misc/sampleconfigs/gpio_settings.ini.sample "${jukebox_dir}"/settings/gpio_settings.ini - fi - fi - - if [ "${MPDconfig}" == "YES" ]; then - local mpd_conf="/etc/mpd.conf" - - echo "Configuring MPD..." - # MPD configuration - # -rw-r----- 1 mpd audio 14043 Jul 17 20:16 /etc/mpd.conf - sudo cp "${jukebox_dir}"/misc/sampleconfigs/mpd.conf.buster-default.sample ${mpd_conf} - # Change vars to match install config - sudo sed -i 's/%AUDIOiFace%/'"$AUDIOiFace"'/' "${mpd_conf}" - # for $DIRaudioFolders using | as alternate regex delimiter because of the folder path slash - sudo sed -i 's|%DIRaudioFolders%|'"$DIRaudioFolders"'|' "${mpd_conf}" - # Replace homedir; double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${mpd_conf}" - sudo chown mpd:audio "${mpd_conf}" - sudo chmod 640 "${mpd_conf}" - fi - - # set which version has been installed - if [ "${SPOTinstall}" == "YES" ]; then - echo "plusSpotify" > "${jukebox_dir}"/settings/edition - else - echo "classic" > "${jukebox_dir}"/settings/edition - fi - - # update mpc / mpd DB - mpc update - - # / INSTALLATION - ##################################################### -} - -wifi_settings() { - local sample_configs_dir="$1" - local dhcpcd_conf="$2" - local wpa_supplicant_conf="$3" - - ############################### - # 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 - echo "Setting ${dhcpcd_conf}..." - #-rw-rw-r-- 1 root netdev 0 Apr 17 11:25 /etc/dhcpcd.conf - sudo cp "${sample_configs_dir}"/dhcpcd.conf.buster-default-noHotspot.sample "${dhcpcd_conf}" - # Change IP for router and Phoniebox - sudo sed -i 's/%WIFIip%/'"$WIFIip"'/' "${dhcpcd_conf}" - sudo sed -i 's/%WIFIipRouter%/'"$WIFIipRouter"'/' "${dhcpcd_conf}" - sudo sed -i 's/%WIFIcountryCode%/'"$WIFIcountryCode"'/' "${dhcpcd_conf}" - # Change user:group and access mod - sudo chown root:netdev "${dhcpcd_conf}" - sudo chmod 664 "${dhcpcd_conf}" - - # WiFi SSID & Password - echo "Setting ${wpa_supplicant_conf}..." - # -rw-rw-r-- 1 root netdev 137 Jul 16 08:53 /etc/wpa_supplicant/wpa_supplicant.conf - sudo cp "${sample_configs_dir}"/wpa_supplicant.conf.buster-default.sample "${wpa_supplicant_conf}" - sudo sed -i 's/%WIFIssid%/'"$WIFIssid"'/' "${wpa_supplicant_conf}" - sudo sed -i 's/%WIFIpass%/'"$WIFIpass"'/' "${wpa_supplicant_conf}" - sudo sed -i 's/%WIFIcountryCode%/'"$WIFIcountryCode"'/' "${wpa_supplicant_conf}" - sudo chown root:netdev "${wpa_supplicant_conf}" - sudo chmod 664 "${wpa_supplicant_conf}" - fi - - # start DHCP - echo "Starting dhcpcd service..." - sudo service dhcpcd start - sudo systemctl enable dhcpcd - -# / WiFi settings (SSID password) -############################### -} - -existing_assets() { - local jukebox_dir="$1" - local backup_dir="$2" - - ##################################################### - # 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"'/' "${jukebox_dir}"/settings/rfid_trigger_play.conf - fi - done <"${backup_dir}"/settings/rfid_trigger_play.conf - fi - - # RFID shortcuts for audio folders - if [ "${EXISTINGuseRfidLinks}" == "YES" ]; then - # copy from backup to new install - cp -R "${backup_dir}"/shared/shortcuts/* "${jukebox_dir}"/shared/shortcuts/ - fi - - # Audio folders: use existing - if [ "${EXISTINGuseAudio}" == "YES" ]; then - # copy from backup to new install - cp -R "${backup_dir}"/shared/audiofolders/* "$DIRaudioFolders/" - fi - - # GPIO: use existing file - if [ "${EXISTINGuseGpio}" == "YES" ]; then - # copy from backup to new install - cp "${backup_dir}"/settings/gpio_settings.ini "${jukebox_dir}"/settings/gpio_settings.ini - fi - - # Button USB Encoder: use existing file - if [ "${EXISTINGuseButtonUSBEncoder}" == "YES" ]; then - # copy from backup to new install - cp "${backup_dir}"/components/controls/buttons_usb_encoder/deviceName.txt "${jukebox_dir}"/components/controls/buttons_usb_encoder/deviceName.txt - cp "${backup_dir}"/components/controls/buttons_usb_encoder/buttonMap.json "${jukebox_dir}"/components/controls/buttons_usb_encoder/buttonMap.json - # make buttons_usb_encoder.py ready to be use from phoniebox-buttons-usb-encoder service - sudo chmod +x "${jukebox_dir}"/components/controls/buttons_usb_encoder/buttons_usb_encoder.py - # make sure service is still enabled by registering again - USB_BUTTONS_SERVICE="/etc/systemd/system/phoniebox-buttons-usb-encoder.service" - sudo cp -v "${jukebox_dir}"/components/controls/buttons_usb_encoder/phoniebox-buttons-usb-encoder.service.sample "${USB_BUTTONS_SERVICE}" - # Replace homedir; double quotes for variable expansion - sudo sed -i "s%/home/pi%${HOME_DIR}%g" "${USB_BUTTONS_SERVICE}" - sudo systemctl start phoniebox-buttons-usb-encoder.service - sudo systemctl enable phoniebox-buttons-usb-encoder.service - fi - - # Sound effects: use existing startup / shutdown sounds - if [ "${EXISTINGuseSounds}" == "YES" ]; then - # copy from backup to new install - cp "${backup_dir}"/shared/startupsound.mp3 "${jukebox_dir}"/shared/startupsound.mp3 - cp "${backup_dir}"/shared/shutdownsound.mp3 "${jukebox_dir}"/shared/shutdownsound.mp3 - fi - - fi - - # / EXISTING ASSETS TO USE FROM EXISTING INSTALL - ################################################ -} - - -folder_access() { - local jukebox_dir="$1" - local user_group="$2" - local mod="$3" - - ##################################################### - # Folders and Access Settings - - echo "Setting owner and permissions for directories..." - - # create playlists folder - mkdir -p "${jukebox_dir}"/playlists - sudo chown -R "${user_group}" "${jukebox_dir}"/playlists - sudo chmod -R "${mod}" "${jukebox_dir}"/playlists - - # make sure the shared folder is accessible by the web server - sudo chown -R "${user_group}" "${jukebox_dir}"/shared - sudo chmod -R "${mod}" "${jukebox_dir}"/shared - - # make sure the htdocs folder can be changed by the web server - sudo chown -R "${user_group}" "${jukebox_dir}"/htdocs - sudo chmod -R "${mod}" "${jukebox_dir}"/htdocs - - sudo chown -R "${user_group}" "${jukebox_dir}"/settings - sudo chmod -R "${mod}" "${jukebox_dir}"/settings - - # logs dir accessible by pi and www-data - sudo chown "${user_group}" "${jukebox_dir}"/logs - sudo chmod "${mod}" "${jukebox_dir}"/logs - - # audio folders might be somewhere else, so treat them separately - sudo chown "${user_group}" "${DIRaudioFolders}" - sudo chmod "${mod}" "${DIRaudioFolders}" - - # make sure bash scripts have the right settings - sudo chown "${user_group}" "${jukebox_dir}"/scripts/*.sh - sudo chmod +x "${jukebox_dir}"/scripts/*.sh - sudo chown "${user_group}" "${jukebox_dir}"/scripts/*.py - sudo chmod +x "${jukebox_dir}"/scripts/*.py - - # set audio volume to 100% - # see: https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/54 - sudo amixer cset numid=1 100% - - # delete the global.conf file, in case somebody manually copied stuff back and forth - # this will be created the first time the Phoniebox is put to use by web app or RFID - GLOBAL_CONF="${jukebox_dir}"/settings/global.conf - if [ -f "${GLOBAL_CONF}" ]; then - echo "global.conf needs to be deleted." - rm "${GLOBAL_CONF}" - fi - - # / Access settings - ##################################################### -} - -autohotspot() { - local jukebox_dir="$1" - local apt_get="sudo apt-get -qq --yes" - - # adapted from https://www.raspberryconnect.com/projects/65-raspberrypi-hotspot-accesspoints/158-raspberry-pi-auto-wifi-hotspot-switch-direct-connection - - # required packages - ${apt_get} install dnsmasq hostapd - sudo systemctl unmask hostapd - sudo systemctl disable hostapd - sudo systemctl disable dnsmasq - - # configure DNS - if [ -f /etc/dnsmasq.conf ]; then - sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig - sudo touch /etc/dnsmasq.conf - else - sudo touch /etc/dnsmasq.conf - fi - sudo bash -c 'cat << EOF > /etc/dnsmasq.conf -#AutoHotspot Config -#stop DNSmasq from using resolv.conf -no-resolv -#Interface to use -interface=wlan0 -bind-interfaces -dhcp-range=10.0.0.50,10.0.0.150,12h -EOF' - - # configure hotspot - if [ -f /etc/hostapd/hostapd.conf ]; then - sudo mv /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.orig - sudo touch /etc/hostapd/hostapd.conf - else - sudo touch /etc/hostapd/hostapd.conf - fi - sudo bash -c 'cat << EOF > /etc/hostapd/hostapd.conf -#2.4GHz setup wifi 80211 b,g,n -interface=wlan0 -driver=nl80211 -ssid=phoniebox -hw_mode=g -channel=8 -wmm_enabled=0 -macaddr_acl=0 -auth_algs=1 -ignore_broadcast_ssid=0 -wpa=2 -wpa_passphrase=PlayItLoud -wpa_key_mgmt=WPA-PSK -wpa_pairwise=CCMP TKIP -rsn_pairwise=CCMP - -#80211n - Change DE to your WiFi country code -country_code=DE -ieee80211n=1 -ieee80211d=1 -EOF' - - # configure Hotspot daemon - if [ -f /etc/default/hostapd ]; then - sudo mv /etc/default/hostapd /etc/default/hostapd.orig - sudo touch /etc/default/hostapd - else - sudo touch /etc/default/hostapd - fi - sudo bash -c 'cat << EOF > /etc/default/hostapd -DAEMON_CONF="/etc/hostapd/hostapd.conf" -EOF' - - if [ $(grep -v '^$' /etc/network/interfaces |wc -l) -gt 5 ]; then - sudo cp /etc/network/interfaces /etc/network/interfaces-backup - fi - - # disable powermanagement of wlan0 device - sudo iw wlan0 set power_save off - - if [[ ! $(grep "nohook wpa_supplicant" /etc/dhcpcd.conf) ]]; then - sudo echo -e "nohook wpa_supplicant" >> /etc/dhcpcd.conf - fi - - # create service to trigger hotspot - sudo bash -c 'cat << EOF > /etc/systemd/system/autohotspot.service -[Unit] -Description=Automatically generates an internet Hotspot when a valid ssid is not in range -After=multi-user.target -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/usr/bin/autohotspot -[Install] -WantedBy=multi-user.target -EOF' - - sudo systemctl enable autohotspot.service - - sudo cp "${jukebox_dir}"/scripts/helperscripts/autohotspot /usr/bin/autohotspot - sudo chmod +x /usr/bin/autohotspot - - # create crontab entry - if [[ ! $(grep "autohotspot" /var/spool/cron/crontabs/pi) ]]; then - sudo bash -c 'cat << EOF >> /var/spool/cron/crontabs/pi -*/5 * * * * sudo /usr/bin/autohotspot >/dev/null 2>&1 -EOF' - fi - sudo chown pi:crontab /var/spool/cron/crontabs/pi - sudo chmod 600 /var/spool/cron/crontabs/pi - sudo /usr/bin/crontab /var/spool/cron/crontabs/pi - -} - -finish_installation() { - local jukebox_dir="$1" - echo " -# -# INSTALLATION FINISHED -# -##################################################### -" - - ##################################################### - # Register external device(s) - - echo "If you are using an RFID reader, connect it to your RPi." - echo "(In case your RFID reader required soldering, consult the manual.)" - # Use -e to display response of user in the logfile - read -e -r -p "Have you connected your RFID reader? [Y/n] " response - case "$response" in - [nN][oO]|[nN]) - ;; - *) - echo 'Please select the RFID reader you want to use' - options=("USB-Reader (e.g. Neuftech)" "RC522" "PN532" "Manual configuration" "Multiple RFID reader") - select opt in "${options[@]}"; do - case $opt in - "USB-Reader (e.g. Neuftech)") - cd "${jukebox_dir}"/scripts/ || exit - python3 RegisterDevice.py - sudo chown pi:www-data "${jukebox_dir}"/scripts/deviceName.txt - sudo chmod 644 "${jukebox_dir}"/scripts/deviceName.txt - break - ;; - "RC522") - bash "${jukebox_dir}"/components/rfid-reader/RC522/setup_rc522.sh - break - ;; - "PN532") - bash "${jukebox_dir}"/components/rfid-reader/PN532/setup_pn532.sh - break - ;; - "Manual configuration") - echo "Please configure your reader manually." - break - ;; - "Multiple RFID reader") - cd "${jukebox_dir}"/scripts/ || exit - sudo python3 RegisterDevice.py.Multi - break - ;; - *) - echo "This is not a number" - ;; - esac - done - esac - - 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 "Reboot is needed to activate all settings" - # 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 -} - -######## -# Main # -######## -main() { - checkPrerequisite - - if [[ ${INTERACTIVE} == "true" ]]; then - welcome - #reset_install_config_file - config_wifi - check_existing "${JUKEBOX_HOME_DIR}" "${JUKEBOX_BACKUP_DIR}" "${HOME_DIR}" - config_audio_interface - config_spotify - config_mpd - config_audio_folder "${JUKEBOX_HOME_DIR}" - config_gpio - else - echo "Non-interactive installation!" - check_config_file - # Skip interactive Samba WINS config dialog - echo "samba-common samba-common/dhcp boolean false" | sudo debconf-set-selections - fi - install_main "${JUKEBOX_HOME_DIR}" - wifi_settings "${JUKEBOX_HOME_DIR}/misc/sampleconfigs" "/etc/dhcpcd.conf" "/etc/wpa_supplicant/wpa_supplicant.conf" - existing_assets "${JUKEBOX_HOME_DIR}" "${JUKEBOX_BACKUP_DIR}" - folder_access "${JUKEBOX_HOME_DIR}" "pi:www-data" 775 - autohotspot "${JUKEBOX_HOME_DIR}" - - # Copy PhonieboxInstall.conf configuration file to settings folder - sudo cp "${HOME_DIR}/PhonieboxInstall.conf" "${JUKEBOX_HOME_DIR}/settings/" - sudo chown pi:www-data "${JUKEBOX_HOME_DIR}/settings/PhonieboxInstall.conf" - sudo chmod 775 "${JUKEBOX_HOME_DIR}/settings/PhonieboxInstall.conf" - - if [[ ${INTERACTIVE} == "true" ]]; then - finish_installation "${JUKEBOX_HOME_DIR}" - else - echo "Skipping USB device setup..." - echo "For manual registration of a USB card reader type:" - echo "python3 ${HOME_DIR}/RPi-Jukebox-RFID/scripts/RegisterDevice.py" - echo " " - echo "Reboot is required to activate all settings!" - fi -} - -start=$(date +%s) - -main - -end=$(date +%s) -runtime=$((end-start)) -((h=${runtime}/3600)) -((m=(${runtime}%3600)/60)) -((s=${runtime}%60)) -echo "Done (in ${h}h ${m}m ${s}s)." - -##################################################### -# notes for things to do - -# CLEANUP -## remove dir BACKUP (possibly not, because we do this at the beginning after user confirms for latest config) -##################################################### diff --git a/scripts/installscripts/buster-install-default.sh b/scripts/installscripts/buster-install-default.sh index b5c9108bc..d4b35899e 100644 --- a/scripts/installscripts/buster-install-default.sh +++ b/scripts/installscripts/buster-install-default.sh @@ -229,6 +229,90 @@ esac read -rp "Hit ENTER to proceed to the next step." INPUT } +config_autohotspot() { + ##################################################### + # Ask if an autohotspot should be created if no known network is found. + + clear + + echo "##################################################### +# +# CONFIGURE AUTOHOTSPOT +# +# Automatically sets up a wifi hotspot if no known network is found. +# This enables you to directly connect to your phoniebox +# and change configuration (e.g. while you travel). +# (Note: can be done manually later, if you are unsure.) +" +read -rp "Do you want to configure autohotspot? [y/N] " response +echo "" +case "$response" in + [yY][eE][sS]|[yY]) + AUTOHOTSPOTconfig=YES + AUTOHOTSPOTssid="phoniebox" + AUTOHOTSPOTcountryCode="DE" + AUTOHOTSPOTpass="PlayItLoud" + AUTOHOTSPOTip="10.0.0.5" + echo "" + echo "The autohotspot configuration uses this default values:" + echo "SSID : $AUTOHOTSPOTssid" + echo "WiFi Country Code : $AUTOHOTSPOTcountryCode" + echo "Password : $AUTOHOTSPOTpass" + echo "Static IP : $AUTOHOTSPOTip" + read -rp "Do you want to use this default values? [Y/n] " response + echo "" + case "$response" in + [nN][oO]|[nN]) + #Ask for SSID + read -rp "* Type SSID name: " AUTOHOTSPOTssid + #Ask for wifi country code + read -rp "* Type WiFi Country Code (e.g. DE, GB, CZ or US): " AUTOHOTSPOTcountryCode + #Ask for password + read -rp "* Type password (8 characters at least. max 63 characters): " AUTOHOTSPOTpass + #Ask for IP + read -rp "* Type Static IP (e.g. 10.0.0.5, 192.168.1.199): " AUTOHOTSPOTip + echo "" + echo "Your Autohotspot config:" + echo "SSID : $AUTOHOTSPOTssid" + echo "WiFi Country Code : $AUTOHOTSPOTcountryCode" + echo "Password : $AUTOHOTSPOTpass" + echo "Static IP : $AUTOHOTSPOTip" + read -rp "Are these values correct? [Y/n] " response + echo "" + case "$response" in + [nN][oO]|[nN]) + echo "The values are incorrect." + read -rp "Hit ENTER to exit and start over." INPUT; exit + ;; + *) + # step out and continue + ;; + esac + ;; + *) + # step out and continue + ;; + esac + # append variables to config file + { + echo "AUTOHOTSPOTconfig=\"$AUTOHOTSPOTconfig\""; + echo "AUTOHOTSPOTssid=\"$AUTOHOTSPOTssid\""; + echo "AUTOHOTSPOTcountryCode=\"$AUTOHOTSPOTcountryCode\""; + echo "AUTOHOTSPOTpass=\"$AUTOHOTSPOTpass\""; + echo "AUTOHOTSPOTip=\"$AUTOHOTSPOTip\""; + } >> "${HOME_DIR}/PhonieboxInstall.conf" + ;; + *) + AUTOHOTSPOTconfig=NO + echo "You don't want to configure Autohotspot." + # append variables to config file + echo "AUTOHOTSPOTconfig=$AUTOHOTSPOTconfig" >> "${HOME_DIR}/PhonieboxInstall.conf" + ;; + +esac +read -rp "Hit ENTER to proceed to the next step." INPUT +} + check_existing() { local jukebox_dir="$1" local backup_dir="$2" @@ -796,9 +880,6 @@ install_main() { # 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 . "${HOME_DIR}/PhonieboxInstall.conf" # power management of wifi: switch off to avoid disconnecting @@ -1050,9 +1131,7 @@ install_main() { } wifi_settings() { - local sample_configs_dir="$1" - local dhcpcd_conf="$2" - local wpa_supplicant_conf="$3" + local jukebox_dir="$1" ############################### # WiFi settings (SSID password) @@ -1064,10 +1143,12 @@ wifi_settings() { # $WIFIip # $WIFIipRouter if [ "${WIFIconfig}" == "YES" ]; then + # DHCP configuration settings + local dhcpcd_conf="/etc/dhcpcd.conf" echo "Setting ${dhcpcd_conf}..." #-rw-rw-r-- 1 root netdev 0 Apr 17 11:25 /etc/dhcpcd.conf - sudo cp "${sample_configs_dir}"/dhcpcd.conf.buster-default-noHotspot.sample "${dhcpcd_conf}" + sudo cp "${jukebox_dir}"/misc/sampleconfigs/dhcpcd.conf.buster-default-noHotspot.sample "${dhcpcd_conf}" # Change IP for router and Phoniebox sudo sed -i 's/%WIFIip%/'"$WIFIip"'/' "${dhcpcd_conf}" sudo sed -i 's/%WIFIipRouter%/'"$WIFIipRouter"'/' "${dhcpcd_conf}" @@ -1077,9 +1158,10 @@ wifi_settings() { sudo chmod 664 "${dhcpcd_conf}" # WiFi SSID & Password + local wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf" echo "Setting ${wpa_supplicant_conf}..." # -rw-rw-r-- 1 root netdev 137 Jul 16 08:53 /etc/wpa_supplicant/wpa_supplicant.conf - sudo cp "${sample_configs_dir}"/wpa_supplicant.conf.buster-default.sample "${wpa_supplicant_conf}" + sudo cp "${jukebox_dir}"/misc/sampleconfigs/wpa_supplicant.conf.buster-default.sample "${wpa_supplicant_conf}" sudo sed -i 's/%WIFIssid%/'"$WIFIssid"'/' "${wpa_supplicant_conf}" sudo sed -i 's/%WIFIpass%/'"$WIFIpass"'/' "${wpa_supplicant_conf}" sudo sed -i 's/%WIFIcountryCode%/'"$WIFIcountryCode"'/' "${wpa_supplicant_conf}" @@ -1228,6 +1310,17 @@ folder_access() { ##################################################### } +autohotspot() { + local jukebox_dir="$1" + + # Behave the same as other steps and only add configuration if selected and dont remove + if [ "${AUTOHOTSPOTconfig}" == "YES" ]; then + local setup_script="${jukebox_dir}/scripts/helperscripts/setup_autohotspot.sh" + sudo chmod +x "${setup_script}" + "${setup_script}" "${jukebox_dir}" "${AUTOHOTSPOTconfig}" "${AUTOHOTSPOTssid}" "${AUTOHOTSPOTcountryCode}" "${AUTOHOTSPOTpass}" "${AUTOHOTSPOTip}" + fi +} + finish_installation() { local jukebox_dir="$1" echo " @@ -1318,6 +1411,7 @@ main() { #reset_install_config_file config_wifi check_existing "${JUKEBOX_HOME_DIR}" "${JUKEBOX_BACKUP_DIR}" "${HOME_DIR}" + config_autohotspot config_audio_interface config_spotify config_mpd @@ -1328,7 +1422,8 @@ main() { check_config_file fi install_main "${JUKEBOX_HOME_DIR}" - wifi_settings "${JUKEBOX_HOME_DIR}/misc/sampleconfigs" "/etc/dhcpcd.conf" "/etc/wpa_supplicant/wpa_supplicant.conf" + wifi_settings "${JUKEBOX_HOME_DIR}" + autohotspot "${JUKEBOX_HOME_DIR}" existing_assets "${JUKEBOX_HOME_DIR}" "${JUKEBOX_BACKUP_DIR}" folder_access "${JUKEBOX_HOME_DIR}" "pi:www-data" 775 diff --git a/scripts/installscripts/tests/ShellCheck/PhonieboxInstall.conf b/scripts/installscripts/tests/ShellCheck/PhonieboxInstall.conf deleted file mode 100644 index 494086433..000000000 --- a/scripts/installscripts/tests/ShellCheck/PhonieboxInstall.conf +++ /dev/null @@ -1,16 +0,0 @@ -# Phoniebox config -WIFIconfig="YES" -WIFIcountryCode="EN" -WIFIssid="GatewayToTheWorld" -WIFIpass="NotSoRandomString" -WIFIip="192.168.0.2" -WIFIipRouter="192.168.0.1" -EXISTINGuse=NO -AUDIOiFace="PCM" -SPOTinstall="YES" -SPOTIuser="notsorandomusername" -SPOTIpass="notsorandompassword" -SPOTIclientid="notsorandomclientid" -SPOTIclientsecret="notsorandomclientsecret" -MPDconfig="YES" -DIRaudioFolders="/home/pi/RPi-Jukebox-RFID/shared/audiofolders" diff --git a/scripts/installscripts/tests/run_installation_tests.sh b/scripts/installscripts/tests/run_installation_tests.sh index fb711048b..dbf61c2fb 100644 --- a/scripts/installscripts/tests/run_installation_tests.sh +++ b/scripts/installscripts/tests/run_installation_tests.sh @@ -18,6 +18,8 @@ echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selecti # Run installation (in interactive mode) # y confirm interactive # n dont configure wifi +# y configure autohotspot +# y use autohotspot default config # y Headphone as iface # n no spotify # y configure mpd @@ -26,7 +28,7 @@ echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selecti # n no RFID registration # n No reboot -./../buster-install-default.sh <<< $'y\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\nn\nn\n' +./../buster-install-default.sh <<< $'y\nn\n\ny\ny\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\nn\nn\n' INSTALLATION_EXITCODE=$? # Test installation diff --git a/scripts/installscripts/tests/run_installation_tests2.sh b/scripts/installscripts/tests/run_installation_tests2.sh index 58c2a378d..6523c9dfd 100644 --- a/scripts/installscripts/tests/run_installation_tests2.sh +++ b/scripts/installscripts/tests/run_installation_tests2.sh @@ -18,6 +18,7 @@ echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selecti # Run installation (in interactive mode) # y confirm interactive # n dont configure wifi +# n dont configure autohotspot # y PCM as iface # n no spotify # y configure mpd @@ -28,7 +29,7 @@ echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selecti # yes, reader is connected # n No reboot -./../buster-install-default.sh <<< $'y\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\ny\n2\ny\nn\n' +./../buster-install-default.sh <<< $'y\nn\n\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\ny\n2\ny\nn\n' INSTALLATION_EXITCODE=$? # Test installation diff --git a/scripts/installscripts/tests/run_installation_tests3.sh b/scripts/installscripts/tests/run_installation_tests3.sh index 09340da8e..e177488a2 100644 --- a/scripts/installscripts/tests/run_installation_tests3.sh +++ b/scripts/installscripts/tests/run_installation_tests3.sh @@ -18,6 +18,7 @@ echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selecti # Run installation (in interactive mode) # y confirm interactive # n dont configure wifi +# n dont configure autohotspot # y Headphone as iface # y spotify with myuser, mypassword, myclient_id, myclient_secret # y configure mpd @@ -26,7 +27,7 @@ echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selecti # n no RFID registration # n No reboot -./../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' +./../buster-install-default.sh <<< $'y\nn\n\nn\n\ny\n\ny\nmyuser\nmypassword\nmyclient_id\nmyclient_secret\n\ny\n\ny\n\ny\n\ny\nn\nn\n' INSTALLATION_EXITCODE=$? # Test installation diff --git a/scripts/installscripts/tests/test_installation.sh b/scripts/installscripts/tests/test_installation.sh index 332cfb8cb..da23da9cc 100755 --- a/scripts/installscripts/tests/test_installation.sh +++ b/scripts/installscripts/tests/test_installation.sh @@ -167,6 +167,47 @@ verify_wifi_settings() { check_service_enablement dhcpcd enabled } +verify_autohotspot_settings() { + if [[ "$AUTOHOTSPOTconfig" == "YES" ]]; then + printf "\nTESTING autohotspot settings...\n\n" + + local autohotspot_service="autohotspot.service" + local autohotspot_script="/usr/bin/autohotspot" + + local dnsmasq_conf=/etc/dnsmasq.conf + local hostapd_conf=/etc/hostapd/hostapd.conf + local hostapd_deamon=/etc/default/hostapd + local dhcpcd_conf=/etc/dhcpcd.conf + + check_file_contains_string "${AUTOHOTSPOTip}" "${autohotspot_script}" + local ip_without_last_segment=$(echo $AUTOHOTSPOTip | cut -d'.' -f1-3) + check_file_contains_string "dhcp-range=${ip_without_last_segment}.100,${ip_without_last_segment}.200,12h" "${dnsmasq_conf}" + check_file_contains_string "ssid=${AUTOHOTSPOTssid}" "${hostapd_conf}" + check_file_contains_string "wpa_passphrase=${AUTOHOTSPOTpass}" "${hostapd_conf}" + check_file_contains_string "country_code=${AUTOHOTSPOTcountryCode}" "${hostapd_conf}" + check_file_contains_string "DAEMON_CONF=\"${hostapd_conf}\"" "${hostapd_deamon}" + check_file_contains_string "nohook wpa_supplicant" "${dhcpcd_conf}" + check_file_contains_string "ExecStart=${AUTOHOTSPOT_SCRIPT}" "/etc/systemd/system/${autohotspot_service}" + + local crontab_user=$(crontab -l 2>/dev/null) + if [[ ! $(echo "${crontab_user}" | grep -w "${autohotspot_script}") ]]; then + echo " ERROR: crontab for user not installed" + ((failed_tests++)) + fi + ((tests++)) + + # check owner and permissions + check_chmod_chown 644 root root "/etc" "dnsmasq.conf hostapd/hostapd.conf default/hostapd" + check_chmod_chown 664 root netdev "/etc" "dhcpcd.conf" + check_chmod_chown 644 root root "/etc/systemd/system" "${autohotspot_service}" + + # check that the services are activ + check_service_enablement "${autohotspot_service}" enabled + check_service_enablement hostapd disabled + check_service_enablement dnsmasq disabled + fi +} + verify_apt_packages(){ local phpver="$(ls -1 /etc/php)" local packages="samba @@ -176,6 +217,7 @@ python3-spidev netcat alsa-utils" local packages_raspberrypi="raspberrypi-kernel-headers" local packages_spotify="libspotify-dev mopidy mopidy-mpd mopidy-local mopidy-spotify libspotify12 python3-cffi python3-ply python3-pycparser python3-spotify" + local packages_autohotspot="dnsmasq hostapd iw" printf "\nTESTING installed packages...\n\n" @@ -184,6 +226,10 @@ python3-cffi python3-ply python3-pycparser python3-spotify" packages="${packages} ${packages_spotify}" fi + if [[ "$AUTOHOTSPOTconfig" == "YES" ]]; then + packages="${packages} ${packages_autohotspot}" + fi + # check for raspberry pi packages only on raspberry pi's but not on test docker containers running on x86_64 machines if [[ $(uname -m) =~ ^armv.+$ ]]; then packages="${packages} ${packages_raspberrypi}" @@ -346,6 +392,7 @@ main() { verify_spotify_config fi verify_mpd_config + verify_autohotspot_settings verify_folder_access } diff --git a/scripts/playout_controls.sh b/scripts/playout_controls.sh index a02ba9fd5..908655ff8 100755 --- a/scripts/playout_controls.sh +++ b/scripts/playout_controls.sh @@ -120,6 +120,8 @@ if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo "VAR VALUE: ${VALUE}" # speed of these commands. shortcutCommands="^(setvolume|volumedown|volumeup|mute)$" +autohotspot_script="/usr/bin/autohotspot" + # Run the code from this block only, if the current command is not in "shortcutCommands" if [[ ! "$COMMAND" =~ $shortcutCommands ]] then @@ -1005,6 +1007,7 @@ case $COMMAND in enablewifi) if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo " ${COMMAND}" >> ${PATHDATA}/../logs/debug.log; fi rfkill unblock wifi + if [ -f "$autohotspot_script" ]; then sudo "$autohotspot_script"; fi ;; disablewifi) if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo " ${COMMAND}" >> ${PATHDATA}/../logs/debug.log; fi @@ -1030,6 +1033,7 @@ case $COMMAND in if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo " Wifi will now be activated" >> ${PATHDATA}/../logs/debug.log; fi echo "Wifi will now be activated" rfkill unblock wifi + if [ -f "$autohotspot_script" ]; then sudo "$autohotspot_script"; fi fi ;; randomcard) diff --git a/scripts/userscripts/addhotspot.sh b/scripts/userscripts/addhotspot.sh index 038fd6957..6e8e63a4e 100644 --- a/scripts/userscripts/addhotspot.sh +++ b/scripts/userscripts/addhotspot.sh @@ -1,10 +1,14 @@ -#!/bin/bash +#!/usr/bin/env bash + +if [[ -z "$1" || -z "$2" ]]; then + echo "usage: addhotspot.sh " + exit 1 +fi # addhotspot.sh newssid newpassword wpa_passphrase "$1" $2 >> /etc/wpa_supplicant/wpa_supplicant.conf # /etc/dhcpcd.conf -echo ssid $1 >> /etc/dhcpcd.conf - - - +if [[ ! $(grep -w "ssid $1" /etc/dhcpcd.conf) ]]; then + echo "ssid $1" >> /etc/dhcpcd.conf +fi