11#! /bin/bash
22
3+ # avoid silent failures
4+ set -e
5+
36# # error codes
47# 1 Generic error
58# 2 Invalid RENDERER_MODE value
69# 3 Invalid argument
710
11+ # show how the image was built
12+ build_mode=` cat /app/conf/build_mode.txt`
13+ echo " Image build mode: [${build_mode} ]"
14+
815# display upmpdcli version.
916upmpdcli -v
1017
@@ -17,6 +24,20 @@ if [[ "${current_user_id}" != "0" ]]; then
1724 echo " Not running as root, will not be able to create users"
1825fi
1926
27+ DEFAULT_UID=1000
28+ DEFAULT_GID=1000
29+
30+ if [[ -z " ${PUID} " ]]; then
31+ PUID=$DEFAULT_UID
32+ echo " Setting default value for PUID: [" $PUID " ]"
33+ fi
34+ if [[ -z " ${PGID} " ]]; then
35+ PGID=$DEFAULT_GID
36+ echo " Setting default value for PGID: [" $PGID " ]"
37+ fi
38+
39+ echo " PUID=[${PUID} ] PGID=[${PGID} ]"
40+
2041if [[ -n " ${RADIO_PARADISE_DOWNLOAD_PLUGIN} " ]] ||
2142 [[ -n " ${TIDAL_DOWNLOAD_PLUGIN} " ]] ||
2243 [[ -n " ${SUBSONIC_DOWNLOAD_PLUGIN} " ]] ||
@@ -278,7 +299,6 @@ set_parameter $CONFIG_FILE PLG_MICRO_HTTP_HOST "$PLG_MICRO_HTTP_HOST" plgmicroht
278299set_parameter $CONFIG_FILE PLG_MICRO_HTTP_PORT " $PLG_MICRO_HTTP_PORT " plgmicrohttpport
279300set_parameter $CONFIG_FILE PLG_PROXY_METHOD " $PLG_PROXY_METHOD " plgproxymethod
280301
281-
282302echo " CHECK_CONTENT_FORMAT=[${CHECK_CONTENT_FORMAT} ]"
283303if [[ -n " ${CHECK_CONTENT_FORMAT} " ]]; then
284304 if [[ " ${CHECK_CONTENT_FORMAT^^} " == " YES" || " ${CHECK_CONTENT_FORMAT^^} " == " Y" ]]; then
@@ -641,23 +661,45 @@ if [[ "${UPRCL_ENABLE^^}" == "YES" ]]; then
641661 fi
642662fi
643663
664+ cache_dir_created=0
644665cache_directory=/cache
645666if [[ ! -w " $cache_directory " ]]; then
646667 echo " Cache directory [${cache_directory} ] is not writable"
647668 cache_directory=" /tmp/cache"
669+ echo " Creating cache directory [$cache_directory ] ..."
648670 mkdir -p /tmp/cache
671+ cache_dir_created=1
672+ echo " Cache directory [$cache_directory ] created successfully"
673+ if [ $current_user_id -eq 0 ]; then
674+ echo " Setting ownership to [$cache_directory ] ..."
675+ chown -R $PUID :$PGID $cache_directory
676+ echo " Setting ownership to [$cache_directory ] Done"
677+ else
678+ echo " Not setting ownership to [$cache_directory ] (uid is [$current_user_id ])."
679+ fi
649680else
650- echo " Cache directory [${ cache_directory} ] is writable"
681+ echo " Cache directory [$cache_directory ] is writable"
651682fi
652683echo " cachedir = $cache_directory " >> $CONFIG_FILE
653684
685+ log_dir_created=0
654686log_directory=/log
655687if [[ ! -w " $log_directory " ]]; then
656- echo " Log directory [${log_directory} ] is not writable"
688+ echo " Log directory [$log_directory ] is not writable"
689+ echo " Creating log directory [$log_directory ] ..."
657690 mkdir -p /tmp/log
691+ log_dir_created=1
658692 log_directory=" /tmp/log"
693+ echo " Log directory [$log_directory ] created successfully."
694+ if [ $current_user_id -eq 0 ]; then
695+ echo " Setting ownership to [$log_directory ] ..."
696+ chown -R $PUID :$PGID $log_directory
697+ echo " Setting ownership to [$log_directory ] Done"
698+ else
699+ echo " Not setting ownership to [$log_directory ] (uid is [$current_user_id ])."
700+ fi
659701else
660- echo " Log directory [${ log_directory} ] is writable"
702+ echo " Log directory [$log_directory ] is writable"
661703fi
662704
663705# log file support
@@ -687,7 +729,9 @@ if [[ -f $UPMPDCLI_ADDITIONAL_FILE ]]; then
687729 echo " Done."
688730fi
689731
732+ echo " === <Configuration file> [$CONFIG_FILE ] ==="
690733cat $CONFIG_FILE
734+ echo " === EOF <Configuration file> [$CONFIG_FILE ] EOF ==="
691735
692736if [[ $current_user_id == 0 ]]; then
693737
@@ -698,16 +742,6 @@ if [[ $current_user_id == 0 ]]; then
698742 echo " Created directory [${WEBSERVER_DOCUMENT_ROOT} ]."
699743 fi
700744
701- DEFAULT_UID=1000
702- DEFAULT_GID=1000
703-
704- if [[ -z " ${PUID} " ]]; then
705- PUID=$DEFAULT_UID
706- fi
707- if [[ -z " ${PGID} " ]]; then
708- PGID=$DEFAULT_GID
709- fi
710-
711745 DEFAULT_USER_NAME=upmpd-user
712746 DEFAULT_GROUP_NAME=upmpd-user
713747 DEFAULT_HOME_DIR=/home/$DEFAULT_USER_NAME
@@ -716,16 +750,6 @@ if [[ $current_user_id == 0 ]]; then
716750 GROUP_NAME=$DEFAULT_GROUP_NAME
717751 HOME_DIR=$DEFAULT_HOME_DIR
718752
719- if [[ -z " ${PUID} " ]]; then
720- PUID=$DEFAULT_UID ;
721- echo " Setting default value for PUID: [" $PUID " ]"
722- fi
723-
724- if [[ -z " ${PGID} " ]]; then
725- PGID=$DEFAULT_GID ;
726- echo " Setting default value for PGID: [" $PGID " ]"
727- fi
728-
729753 echo " Ensuring user with uid:[$PUID ] gid:[$PGID ] exists ..." ;
730754
731755 # ## create group if it does not exist
@@ -797,6 +821,15 @@ if [[ $current_user_id == 0 ]]; then
797821 chown -R $USER_NAME :$GROUP_NAME /uprcl/confdir
798822 chown -R $USER_NAME :$GROUP_NAME /user/config
799823 chown -R $USER_NAME :$GROUP_NAME /log
824+ if [[ $cache_dir_created -eq 1 ]]; then
825+ echo " Changing ownership of /tmp/cache ..."
826+ chown -R $USER_NAME :$GROUP_NAME /tmp/cache
827+ fi
828+ if [[ $log_dir_created -eq 1 ]]; then
829+ echo " Changing ownership of /tmp/log ..."
830+ chown -R $USER_NAME :$GROUP_NAME /tmp/log
831+ fi
832+
800833 echo " . done."
801834
802835 # Correct permissions for WEBSERVER_DOCUMENT_ROOT if set
@@ -807,19 +840,19 @@ if [[ $current_user_id == 0 ]]; then
807840 fi
808841fi
809842
810- build_mode= ` cat /app/conf/build_mode.txt `
811-
812- echo " About to sleep for $STARTUP_DELAY_SEC second(s) "
813- sleep $STARTUP_DELAY_SEC
814- echo " Ready to start. "
843+ if [[ -n " ${STARTUP_DELAY_SEC} " ]] && [[ ${STARTUP_DELAY_SEC} != " 0 " ]] ; then
844+ echo " About to sleep for $STARTUP_DELAY_SEC second(s) "
845+ sleep $STARTUP_DELAY_SEC
846+ echo " Ready to start. "
847+ fi
815848
816849CMD_LINE=" /usr/bin/upmpdcli -c $CONFIG_FILE "
817850echo " CMD_LINE=[${CMD_LINE} ]"
818851
819852if [[ $current_user_id -eq 0 ]]; then
820- echo " USER MODE [$USER_NAME ]"
853+ echo " Running in USER MODE [$USER_NAME ] ( $PUID : $PGID ) ... "
821854 exec su - $USER_NAME -c " $CMD_LINE "
822855else
823856 echo " Running as current uid [$current_user_id ] ..."
824- eval " exec $CMD_LINE "
857+ exec $CMD_LINE
825858fi
0 commit comments