Skip to content

Commit

Permalink
Merge pull request #1543 from Groovylein/remove_userspecific_installa…
Browse files Browse the repository at this point in the history
…tion

Remove hardcoded homedir in install scritp
  • Loading branch information
MiczFlor authored Feb 27, 2022
2 parents 8bc4957 + f941bdb commit 7b5b956
Show file tree
Hide file tree
Showing 7 changed files with 533 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ jobs:
docker run --rm -i rpi-jukebox-rfid-buster:latest /code/scripts/installscripts/tests/run_installation_tests.sh
docker run --rm -i rpi-jukebox-rfid-buster:latest /code/scripts/installscripts/tests/run_installation_tests2.sh
docker run --rm -i rpi-jukebox-rfid-buster:latest /code/scripts/installscripts/tests/run_installation_tests3.sh
- name: Build Docker image and run tests for alternate user hans
run: |
docker build . --file ./ci/Dockerfile.buster.test_install_altuser.amd64 --tag rpi-jukebox-rfid-buster-altuser:latest
docker run --rm -i rpi-jukebox-rfid-buster-altuser:latest /code/scripts/installscripts/tests/run_installation_tests_altuser.sh
docker run --rm -i rpi-jukebox-rfid-buster-altuser:latest /code/scripts/installscripts/tests/run_installation_tests2_altuser.sh
docker run --rm -i rpi-jukebox-rfid-buster-altuser:latest /code/scripts/installscripts/tests/run_installation_tests3_altuser.sh
33 changes: 33 additions & 0 deletions ci/Dockerfile.buster.test_install_altuser.amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM debian:buster

COPY . /code
WORKDIR /code

RUN groupadd --gid 1000 wurst ;\
useradd -u 1000 -g 1000 -G sudo -d /home/hans -m -s /bin/bash -p '$1$iV7TOwOe$6ojkJQXyEA9bHd/SqNLNj0' hans ;\
chown -R 1000:1000 /code /home/hans ;\
chmod +x /code/scripts/installscripts/buster-install-default.sh ;\
chmod +x /code/scripts/installscripts/tests/run_installation_tests_altuser.sh ;\
chmod +x /code/scripts/installscripts/tests/run_installation_tests2_altuser.sh ;\
chmod +x /code/scripts/installscripts/tests/run_installation_tests3_altuser.sh

RUN export DEBIAN_FRONTEND=noninteractive ;\
apt-get update ;\
apt-get -y install curl gnupg sudo nano systemd apt-utils;\
echo 'deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi' > /etc/apt/sources.list.d/raspi.list ;\
echo 'deb http://archive.raspberrypi.org/debian/ buster main' >> /etc/apt/sources.list.d/raspi.list ;\
curl http://raspbian.raspberrypi.org/raspbian.public.key | apt-key add - ;\
curl http://archive.raspberrypi.org/debian/raspberrypi.gpg.key | apt-key add - ;\
echo 'hans ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/hans ;\
apt-get clean ;\
rm -rf /var/cache/apt/* /var/lib/apt/lists/*

RUN export DEBIAN_FRONTEND=noninteractive ;\
apt-get update ;\
apt-get -y dist-upgrade --auto-remove --purge ;\
apt-get -y install wget build-essential git iw locales wpasupplicant;\
apt-get clean ;\
touch /boot/cmdlinetxt ;\
rm -rf /var/cache/apt/* /var/lib/apt/lists/*

USER hans
59 changes: 47 additions & 12 deletions scripts/installscripts/buster-install-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#
# NOTE: Running automated install (without interaction):
# Each install creates a file called PhonieboxInstall.conf
# in the folder /home/pi/
# 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/pi/
# 3. place the PhonieboxInstall.conf in the folder $HOME
# 4. run the installscript with option -a like this:
# buster-install-default.sh -a

Expand All @@ -28,7 +28,7 @@ DATETIME=$(date +"%Y%m%d_%H%M%S")
SCRIPTNAME="$(basename $0)"
JOB="${SCRIPTNAME}"

HOME_DIR="/home/pi"
HOME_DIR=$(echo $HOME)

JUKEBOX_HOME_DIR="${HOME_DIR}/RPi-Jukebox-RFID"
LOGDIR="${HOME_DIR}"/phoniebox_logs
Expand Down Expand Up @@ -104,9 +104,9 @@ 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/
2. place your PhonieboxInstall.conf in the folder ${HOME_DIR}
3. run the installscript with option -a. For example like this:
./home/pi/buster-install-default.sh -a
.${HOME_DIR}/buster-install-default.sh -a
"
read -rp "Continue interactive installation? [Y/n] " response
case "$response" in
Expand Down Expand Up @@ -545,7 +545,7 @@ config_audio_folder() {

#####################################################
# Folder path for audio files
# default: /home/pi/RPi-Jukebox-RFID/shared/audiofolders
# default: $HOME/RPi-Jukebox-RFID/shared/audiofolders

clear

Expand Down Expand Up @@ -683,7 +683,10 @@ samba_config() {
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
}

Expand All @@ -699,6 +702,8 @@ web_server_config() {
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
Expand Down Expand Up @@ -870,6 +875,8 @@ install_main() {

# 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
Expand Down Expand Up @@ -901,12 +908,30 @@ install_main() {
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
sudo cp "${jukebox_dir}"/misc/sampleconfigs/phoniebox-rfid-reader.service.stretch-default.sample "${systemd_dir}"/phoniebox-rfid-reader.service
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
sudo cp "${jukebox_dir}"/misc/sampleconfigs/phoniebox-startup-scripts.service.stretch-default.sample "${systemd_dir}"/phoniebox-startup-scripts.service
sudo cp "${jukebox_dir}"/misc/sampleconfigs/phoniebox-idle-watchdog.service.sample "${systemd_dir}"/phoniebox-idle-watchdog.service
[[ "${GPIOconfig}" == "YES" ]] && sudo cp "${jukebox_dir}"/misc/sampleconfigs/phoniebox-gpio-control.service.sample "${systemd_dir}"/phoniebox-gpio-control.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
Expand Down Expand Up @@ -940,12 +965,17 @@ install_main() {
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
Expand All @@ -968,6 +998,8 @@ install_main() {
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
Expand Down Expand Up @@ -1087,7 +1119,10 @@ existing_assets() {
# 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
sudo cp -v "${jukebox_dir}"/components/controls/buttons_usb_encoder/phoniebox-buttons-usb-encoder.service.sample /etc/systemd/system/phoniebox-buttons-usb-encoder.service
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
Expand Down Expand Up @@ -1274,7 +1309,7 @@ main() {
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 "python3 ${HOME_DIR}/RPi-Jukebox-RFID/scripts/RegisterDevice.py"
echo " "
echo "Reboot is required to activate all settings!"
fi
Expand Down
34 changes: 34 additions & 0 deletions scripts/installscripts/tests/run_installation_tests2_altuser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

# Install Phoniebox and test it
# Used e.g. for tests on Docker

# Objective: Test installation with script using a RC522 reader

# Print current path
echo $PWD

# Preparations
# Skip interactive Samba WINS config dialog
echo "samba-common samba-common/dhcp boolean false" | sudo debconf-set-selections
# No interactive frontend
export DEBIAN_FRONTEND=noninteractive

# Run installation (in interactive mode)
# y confirm interactive
# n dont configure wifi
# y PCM as iface
# n no spotify
# y configure mpd
# y audio default location
# y use gpio
# y RFID registration
# 2 use RC522 reader
# yes, reader is connected
# n No reboot

# TODO check, how this behaves on branches other than develop
GIT_BRANCH=develop bash ./scripts/installscripts/buster-install-default.sh <<< $'y\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\ny\n2\ny\nn\n'

# Test installation
./scripts/installscripts/tests/test_installation_altuser.sh
32 changes: 32 additions & 0 deletions scripts/installscripts/tests/run_installation_tests3_altuser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Install Phoniebox and test it
# Used e.g. for tests on Docker

# Objective: Test installation with script using a configuration with mopidy

# Print current path
echo $PWD

# Preparations
# Skip interactive Samba WINS config dialog
echo "samba-common samba-common/dhcp boolean false" | sudo debconf-set-selections
# No interactive frontend
export DEBIAN_FRONTEND=noninteractive

# Run installation (in interactive mode)
# y confirm interactive
# n dont configure wifi
# y Headphone as iface
# y spotify with myuser, mypassword, myclient_id, myclient_secret
# y configure mpd
# y audio default location
# y config gpio
# n no RFID registration
# n No reboot

# TODO check, how this behaves on branches other than develop
GIT_BRANCH=develop bash ./scripts/installscripts/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'

# Test installation
./scripts/installscripts/tests/test_installation_altuser.sh
32 changes: 32 additions & 0 deletions scripts/installscripts/tests/run_installation_tests_altuser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Install Phoniebox and test it
# Used e.g. for tests on Docker

# Objective: Test installation with script using a simple configuration

# Print current path
echo $PWD

# Preparations
# Skip interactive Samba WINS config dialog
echo "samba-common samba-common/dhcp boolean false" | sudo debconf-set-selections
# No interactive frontend
export DEBIAN_FRONTEND=noninteractive

# Run installation (in interactive mode)
# y confirm interactive
# n dont configure wifi
# y Headphone as iface
# n no spotify
# y configure mpd
# y audio default location
# y config gpio
# n no RFID registration
# n No reboot

# TODO check, how this behaves on branches other than develop
GIT_BRANCH=develop bash ./scripts/installscripts/buster-install-default.sh <<< $'y\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\nn\nn\n'

# Test installation
./scripts/installscripts/tests/test_installation_altuser.sh
Loading

0 comments on commit 7b5b956

Please sign in to comment.