Skip to content

Commit

Permalink
chmod during build, chown with check
Browse files Browse the repository at this point in the history
  • Loading branch information
binhex committed May 8, 2018
1 parent a716056 commit c8dd249
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions build/root/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF > /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

Expand Down

0 comments on commit c8dd249

Please sign in to comment.