From c8dd249e221f771be0049282c03ad0c46146f84c Mon Sep 17 00:00:00 2001 From: binhex Date: Tue, 8 May 2018 13:40:01 +0100 Subject: [PATCH] chmod during build, chown with check --- build/root/install.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/build/root/install.sh b/build/root/install.sh index 8b818e9..f13cf6d 100644 --- a/build/root/install.sh +++ b/build/root/install.sh @@ -54,13 +54,29 @@ done # convert comma separated string of install paths to space separated, required for chmod/chown processing install_paths=$(echo "${install_paths}" | tr ',' ' ') +# set permissions for container during build - Do NOT double quote variable for install_paths otherwise this will wrap space separated paths as a single string +chmod -R 775 ${install_paths} + # create file with contents of here doc, note EOF is NOT quoted to allow us to expand current variable 'install_paths' # we use escaping to prevent variable expansion for PUID and PGID, as we want these expanded at runtime of init.sh -# note - do NOT double quote variable for install_paths otherwise this will wrap space separated paths as a single string cat < /tmp/permissions_heredoc -# set permissions inside container -chown -R "\${PUID}":"\${PGID}" ${install_paths} -chmod -R 775 ${install_paths} + +# get previous puid/pgid (if first run then will be empty string) +previous_puid=$(cat "/tmp/puid" 2>/dev/null) +previous_pgid=$(cat "/tmp/pgid" 2>/dev/null) + +# if first run (no puid or pgid files in /tmp) or the PUID or PGID env vars are different +# from the previous run then re-apply chown with current PUID and PGID values. +if [[ ! -f "/tmp/puid" || ! -f "/tmp/pgid" || "\${previous_puid}" != "\${PUID}" || "\${previous_pgid}" != "\${PGID}" ]]; then + + # set permissions inside container - Do NOT double quote variable for install_paths otherwise this will wrap space separated paths as a single string + chown -R "\${PUID}":"\${PGID}" ${install_paths} + +fi + +# write out current PUID and PGID to files in /tmp (used to compare on next run) +echo "\${PUID}" > /tmp/puid +echo "\${PGID}" > /tmp/pgid EOF