Skip to content

Commit

Permalink
change owner when creating settings files #980
Browse files Browse the repository at this point in the history
  • Loading branch information
MiczFlor committed May 27, 2020
1 parent 33814f2 commit b457bf9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
73 changes: 67 additions & 6 deletions scripts/installscripts/buster-install-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ reset_install_config_file() {
# from such a config file with no user input.

# Remove existing config file
rm "${HOME_DIR}/PhonieboxInstall.conf"
#rm "${HOME_DIR}/PhonieboxInstall.conf"
# Create empty config file
touch "${HOME_DIR}/PhonieboxInstall.conf"
echo "# Phoniebox config" > "${HOME_DIR}/PhonieboxInstall.conf"
#touch "${HOME_DIR}/PhonieboxInstall.conf"
#echo "# Phoniebox config" > "${HOME_DIR}/PhonieboxInstall.conf"
echo "# Phoniebox config"
}

config_wifi() {
Expand Down Expand Up @@ -202,6 +203,7 @@ 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
Expand Down Expand Up @@ -230,10 +232,44 @@ check_existing() {
# get the current short commit hash of the repo
CURRENT_REMOTE_COMMIT="$(git ls-remote https://github.com/MiczFlor/RPi-Jukebox-RFID.git ${GIT_BRANCH} | cut -c1-7)"
fi
echo "IMPORTANT: you can use the existing content and configuration files for your new install."
echo "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
Expand Down Expand Up @@ -331,6 +367,25 @@ check_existing() {
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() {
Expand Down Expand Up @@ -1089,9 +1144,9 @@ finish_installation() {
main() {
if [[ ${INTERACTIVE} == "true" ]]; then
welcome
reset_install_config_file
#reset_install_config_file
config_wifi
check_existing "${JUKEBOX_HOME_DIR}" "${JUKEBOX_BACKUP_DIR}"
check_existing "${JUKEBOX_HOME_DIR}" "${JUKEBOX_BACKUP_DIR}" "${HOME_DIR}"
config_audio_interface
config_spotify
config_mpd
Expand All @@ -1106,6 +1161,12 @@ main() {
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

# 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
Expand Down
1 change: 1 addition & 0 deletions scripts/playout_controls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ case $COMMAND in

# write latest folder played to settings file
sudo echo ${FOLDER} > ${PATHDATA}/../settings/Latest_Folder_Played
sudo chown pi:www-data ${PATHDATA}/../settings/Latest_Folder_Played
sudo chmod 777 ${PATHDATA}/../settings/Latest_Folder_Played
if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo " echo ${FOLDER} > ${PATHDATA}/../settings/Latest_Folder_Played" >> ${PATHDATA}/../logs/debug.log; fi
if [ "${DEBUG_playout_controls_sh}" == "TRUE" ]; then echo " VAR Latest_Folder_Played: ${FOLDER}" >> ${PATHDATA}/../logs/debug.log; fi
Expand Down
1 change: 1 addition & 0 deletions scripts/rfid_trigger_play.sh
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ if [ ! -z "$FOLDER" -a ! -z ${FOLDER+x} -a -d "${AUDIOFOLDERSPATH}/${FOLDER}" ];
if [ "${DEBUG_rfid_trigger_play_sh}" == "TRUE" ]; then echo " Command: $PATHDATA/playout_controls.sh -c=playlistaddplay -v=\"${PLAYLISTNAME}\" -d=\"${FOLDER}\"" >> $PATHDATA/../logs/debug.log; fi
# save latest playlist not to file
sudo echo ${PLAYLISTNAME} > $PATHDATA/../settings/Latest_Playlist_Played
sudo chown pi:www-data $PATHDATA/../settings/Latest_Playlist_Played
sudo chmod 777 $PATHDATA/../settings/Latest_Playlist_Played
fi
if [ "$PLAYPLAYLIST" == "skipnext" ]
Expand Down

3 comments on commit b457bf9

@themorlan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the option to use an existing PhonieboxInstall.conf intended not to be backwards compatible, because older versions of the install-script don't place the PhonieboxInstall.conf in the settings folder? Just stumbled across it when testing to update an existing master branch install with current develop install.

@MiczFlor
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find it now, but there was the discussion: how to make an update easier? And one thing was: not to have to specify the configuration each time you update. So the config file moved to settings. That was for the latest version on master or after master, I think.

@themorlan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried updating current master with develop and had exactly the issue that the option to use existing PhonieboxInstall.conf was not possible due to it missing in the settings folder. It was added with this commit.
Maybe also check the home directory for an existing PhonieboxInstall.conf to provide downwards compatibility?!

Please sign in to comment.