Skip to content

Commit

Permalink
Move host user specific code within if statement. Test uuid solution
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKahr committed Nov 23, 2023
1 parent 30b936f commit 91ab33e
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions dist/platforms/ubuntu/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 91ab33e

Please sign in to comment.