Skip to content

Commit

Permalink
Merge pull request #1 from MiczFlor/develop
Browse files Browse the repository at this point in the history
Merge latest changes form MiczFlor
  • Loading branch information
BerniPi authored May 3, 2020
2 parents 90eab5b + f251f88 commit 3691c42
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 102 deletions.
Binary file modified misc/sampleconfigs/shutdownsound.mp3.sample
Binary file not shown.
Binary file modified misc/sampleconfigs/startupsound.mp3.sample
Binary file not shown.
197 changes: 153 additions & 44 deletions scripts/installscripts/buster-install-default.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
#!/usr/bin/env bash
#
# see https://github.com/MiczFlor/RPi-Jukebox-RFID for details
# Especially the docs folder for documentation
#
# NOTE: Running automated install (without interaction):
# Each install creates a file called PhonieboxInstall.conf
# in the folder /home/pi/
# 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/pi/
# 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 )"
Expand All @@ -18,6 +31,28 @@ HOME_DIR="/home/pi"
JUKEBOX_HOME_DIR="${HOME_DIR}/RPi-Jukebox-RFID"
JUKEBOX_BACKUP_DIR="${HOME_DIR}/BACKUP"

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() {
Expand Down Expand Up @@ -59,19 +94,26 @@ welcome() {
# #
#####################################################
Welcome to the installation script.
This script will install Phoniebox on your Raspberry Pi.
To do so, you must be online. The install script can
automatically configure:
* WiFi settings (SSID, password and static IP)
All these are optional and can also be done later
manually.
If you are ready, hit ENTER"
read -r INPUT
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/pi/
3. run the installscript with option -a. For example like this:
./home/pi/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() {
Expand Down Expand Up @@ -183,7 +225,7 @@ check_existing() {
"
# 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)"
#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 https://github.com/MiczFlor/RPi-Jukebox-RFID.git ${GIT_BRANCH} | cut -c1-7)"
Expand Down Expand Up @@ -460,6 +502,64 @@ config_audio_folder() {
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
}

check_config_file() {
local install_conf="${PATHDATA}/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"

if [ "${fail}" == "true" ]; then
exit 1
fi

echo ""
}

samba_config() {
local smb_conf="/etc/samba/smb.conf"
echo "Configuring Samba..."
Expand Down Expand Up @@ -527,16 +627,18 @@ install_main() {
# You will be prompted later to complete the installation.
"

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 "${PATHDATA}/PhonieboxInstall.conf"
echo
exit
;;
esac
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 "${PATHDATA}/PhonieboxInstall.conf"
echo
exit
;;
esac
fi

# Start logging here
log_open
Expand Down Expand Up @@ -698,7 +800,7 @@ install_main() {
# enable the services needed
sudo systemctl enable phoniebox-idle-watchdog
sudo systemctl enable phoniebox-rfid-reader
#startup sound now part of phoniebox-startup-scripts
#startup sound is part of phoniebox-startup-scripts now
#sudo systemctl enable phoniebox-startup-sound
sudo systemctl enable phoniebox-startup-scripts
sudo systemctl enable phoniebox-gpio-buttons
Expand Down Expand Up @@ -972,19 +1074,34 @@ finish_installation() {
# Main #
########
main() {
welcome
reset_install_config_file
config_wifi
check_existing "${JUKEBOX_HOME_DIR}" "${JUKEBOX_BACKUP_DIR}"
config_audio_interface
config_spotify
config_mpd
config_audio_folder "${JUKEBOX_HOME_DIR}"
if [[ ${INTERACTIVE} == "true" ]]; then
welcome
reset_install_config_file
config_wifi
check_existing "${JUKEBOX_HOME_DIR}" "${JUKEBOX_BACKUP_DIR}"
config_audio_interface
config_spotify
config_mpd
config_audio_folder "${JUKEBOX_HOME_DIR}"
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
finish_installation "${JUKEBOX_HOME_DIR}"
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/pi/RPi-Jukebox-RFID/scripts/RegisterDevice.py"
echo " "
echo "Reboot is required to activate all settings!"
fi
}

start=$(date +%s)
Expand All @@ -1001,14 +1118,6 @@ echo "Done (in ${h}h ${m}m ${s}s)."
#####################################################
# notes for things to do

# Soundcard
# PCM is currently set
# This needs to be done for mpd and in settings folder

#Ask ssh password

# get existing install
# new config should be done with sed using existing conf and user input

# CLEANUP
## remove dir BACKUP (possibly not, because we do this at the beginning after user confirms for latest config)
#####################################################
Loading

0 comments on commit 3691c42

Please sign in to comment.