Skip to content

Commit

Permalink
check for user 'pi' and home '/home/pi'
Browse files Browse the repository at this point in the history
retrieve correct information even if called with sudo
  • Loading branch information
AlvinSchiller committed Oct 9, 2023
1 parent a003088 commit 57e08f9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ DATETIME=$(date +"%Y%m%d_%H%M%S")
SCRIPTNAME="$(basename $0)"
JOB="${SCRIPTNAME}"

HOME_DIR=$(echo $HOME)
CURRENT_USER="${SUDO_USER:-$USER}"
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
Expand Down Expand Up @@ -90,6 +93,25 @@ log_close() {
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
Expand Down Expand Up @@ -1396,6 +1418,8 @@ finish_installation() {
# Main #
########
main() {
checkPrerequisite

if [[ ${INTERACTIVE} == "true" ]]; then
welcome
#reset_install_config_file
Expand Down
24 changes: 23 additions & 1 deletion scripts/installscripts/buster-install-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ DATETIME=$(date +"%Y%m%d_%H%M%S")
SCRIPTNAME="$(basename $0)"
JOB="${SCRIPTNAME}"

HOME_DIR=$(echo $HOME)
CURRENT_USER="${SUDO_USER:-$USER}"
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
Expand Down Expand Up @@ -90,6 +93,23 @@ log_close() {
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 "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 "Please check the wiki for further information"
exit 2
fi
}

welcome() {
clear
Expand Down Expand Up @@ -1286,6 +1306,8 @@ finish_installation() {
# Main #
########
main() {
checkPrerequisite

# Skip interactive Samba WINS config dialog
echo "samba-common samba-common/dhcp boolean false" | sudo debconf-set-selections

Expand Down

0 comments on commit 57e08f9

Please sign in to comment.