Fixes for Apple container.
All checks were successful
Build Docker Image / build (push) Successful in 16s
All checks were successful
Build Docker Image / build (push) Successful in 16s
This commit is contained in:
@@ -3,47 +3,33 @@
|
||||
set -e
|
||||
|
||||
# Setup default values
|
||||
USER_NAME="ubuntu"
|
||||
|
||||
# Parse arguments
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--user|-u)
|
||||
USER_NAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
# Stop parsing arguments
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
USER_NAME="${USER_NAME:-ubuntu}"
|
||||
HOME_DIR="${HOMED_DIR:-/home/${USER_NAME}}"
|
||||
|
||||
# Check, if we are running as root
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
# Check, if the home directory exists for the specified user
|
||||
if [ ! -d "/home/${USER_NAME}" ]; then
|
||||
if [ ! -d "$HOME_DIR" ]; then
|
||||
echo "Error: Home directory for user '${USER_NAME}' does not exist." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Preparing home directory for user '${USER_NAME}' at '${HOME_DIR}'."
|
||||
|
||||
# Check, ownership of the home directory
|
||||
OWNER_UID=$(stat -c '%u' "/home/${USER_NAME}")
|
||||
OWNER_GID=$(stat -c '%g' "/home/${USER_NAME}")
|
||||
if [ "${OWNER_UID}" -ne 0 ] || [ "${OWNER_GID}" -ne 0 ]; then
|
||||
# The home directory is not owned by the specfied user, correct it
|
||||
chown "${USER_NAME}:${USER_NAME}" "/home/${USER_NAME}"
|
||||
if [ "$(stat -c '%u' "$HOME_DIR")" -eq 0 ]; then
|
||||
# The home directory is a fresh volume owned by root, change ownership
|
||||
echo "Changing ownership of home directory to user '${USER_NAME}'."
|
||||
chown "${USER_NAME}:${USER_NAME}" "$HOME_DIR"
|
||||
fi
|
||||
|
||||
# Re-initialize the contents of the home directory
|
||||
su - "${USER_NAME}" -c "cp -a /etc/skel/. /home/${USER_NAME}/"
|
||||
if [ "$USER_NAME " != "root" ]; then
|
||||
# Re-initialize the contents of the home directory
|
||||
su - "${USER_NAME}" -c "cp -a /etc/skel/. $HOME_DIR"
|
||||
|
||||
# We are done as root, quit. The container will be re-run as the specified user.
|
||||
exit 0
|
||||
# We are done as root, quit. The container will be re-run as the specified user.
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Verify that we are running as the user owning the home directory
|
||||
|
||||
Reference in New Issue
Block a user