diff --git a/dist/platforms/ubuntu/entrypoint.sh b/dist/platforms/ubuntu/entrypoint.sh index 04cab042..9934343d 100755 --- a/dist/platforms/ubuntu/entrypoint.sh +++ b/dist/platforms/ubuntu/entrypoint.sh @@ -1,22 +1,7 @@ #!/usr/bin/env bash -fullProjectPath="$GITHUB_WORKSPACE/$PROJECT_PATH" - -# Get host user/group info so we create files with the correct ownership -USERNAME=$(stat -c '%U' "$fullProjectPath") -USERID=$(stat -c '%u' "$fullProjectPath") -GROUPNAME=$(stat -c '%G' "$fullProjectPath") -GROUPID=$(stat -c '%g' "$fullProjectPath") - -groupadd -g $GROUPID $GROUPNAME -useradd -u $USERID -g $GROUPID $USERNAME -usermod -aG $GROUPNAME $USERNAME -mkdir -p "/home/$USERNAME" -chown $USERNAME:$GROUPNAME "/home/$USERNAME" - -# Normally need root permissions to access when using su -chmod 777 /dev/stdout -chmod 777 /dev/stderr +# Ensure machine ID is randomized +dbus-uuidgen > /etc/machine-id && mkdir -p /var/lib/dbus/ && ln -sf /etc/machine-id /var/lib/dbus/machine-id # # Prepare Android SDK, if needed @@ -53,6 +38,30 @@ else fi if [[ "RUN_AS_HOST_USER" == "true" ]]; then + # Stop on error if we can't set up the user + set -e + + fullProjectPath="$GITHUB_WORKSPACE/$PROJECT_PATH" + + # Get host user/group info so we create files with the correct ownership + USERNAME=$(stat -c '%U' "$fullProjectPath") + USERID=$(stat -c '%u' "$fullProjectPath") + GROUPNAME=$(stat -c '%G' "$fullProjectPath") + GROUPID=$(stat -c '%g' "$fullProjectPath") + + groupadd -g $GROUPID $GROUPNAME + useradd -u $USERID -g $GROUPID $USERNAME + usermod -aG $GROUPNAME $USERNAME + mkdir -p "/home/$USERNAME" + chown $USERNAME:$GROUPNAME "/home/$USERNAME" + + # Normally need root permissions to access when using su + chmod 777 /dev/stdout + chmod 777 /dev/stderr + + # Don't stop on error when running our scripts as error handling is baked in + set +e + # Switch to the host user so we can create files with the correct ownership su $USERNAME -c "$SHELL -c 'source /steps/runsteps.sh'" else