|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
| 3 | +# Ensure machine ID is randomized |
| 4 | +dbus-uuidgen > /etc/machine-id && mkdir -p /var/lib/dbus/ && ln -sf /etc/machine-id /var/lib/dbus/machine-id |
| 5 | + |
3 | 6 | #
|
4 |
| -# Create directory for license activation |
| 7 | +# Prepare Android SDK, if needed |
| 8 | +# We do this here to ensure it has root permissions |
5 | 9 | #
|
6 | 10 |
|
7 |
| -ACTIVATE_LICENSE_PATH="$GITHUB_WORKSPACE/_activate-license~" |
8 |
| -mkdir -p "$ACTIVATE_LICENSE_PATH" |
| 11 | +fullProjectPath="$GITHUB_WORKSPACE/$PROJECT_PATH" |
9 | 12 |
|
10 |
| -# |
11 |
| -# Run steps |
12 |
| -# |
13 |
| -source /steps/set_extra_git_configs.sh |
14 |
| -source /steps/set_gitcredential.sh |
15 |
| -source /steps/activate.sh |
16 |
| -source /steps/build.sh |
17 |
| -source /steps/return_license.sh |
| 13 | +if [[ "$BUILD_TARGET" == "Android" ]]; then |
| 14 | + export JAVA_HOME="$(awk -F'=' '/JAVA_HOME=/{print $2}' /usr/bin/unity-editor.d/*)" |
| 15 | + ANDROID_HOME_DIRECTORY="$(awk -F'=' '/ANDROID_HOME=/{print $2}' /usr/bin/unity-editor.d/*)" |
| 16 | + SDKMANAGER=$(find $ANDROID_HOME_DIRECTORY/cmdline-tools -name sdkmanager) |
| 17 | + if [ -z "${SDKMANAGER}" ] |
| 18 | + then |
| 19 | + echo "No sdkmanager found" |
| 20 | + exit 1 |
| 21 | + fi |
18 | 22 |
|
19 |
| -# |
20 |
| -# Remove license activation directory |
21 |
| -# |
| 23 | + if [[ -n "$ANDROID_SDK_MANAGER_PARAMETERS" ]]; then |
| 24 | + echo "Updating Android SDK with parameters: $ANDROID_SDK_MANAGER_PARAMETERS" |
| 25 | + $SDKMANAGER "$ANDROID_SDK_MANAGER_PARAMETERS" |
| 26 | + else |
| 27 | + echo "Updating Android SDK with auto detected target API version" |
| 28 | + # Read the line containing AndroidTargetSdkVersion from the file |
| 29 | + targetAPILine=$(grep 'AndroidTargetSdkVersion' "$fullProjectPath/ProjectSettings/ProjectSettings.asset") |
22 | 30 |
|
23 |
| -rm -r "$ACTIVATE_LICENSE_PATH" |
24 |
| -chmod -R 777 "/BlankProject" |
| 31 | + # Extract the number after the semicolon |
| 32 | + targetAPI=$(echo "$targetAPILine" | cut -d':' -f2 | tr -d '[:space:]') |
25 | 33 |
|
26 |
| -# |
27 |
| -# Instructions for debugging |
28 |
| -# |
| 34 | + $SDKMANAGER "platforms;android-$targetAPI" |
| 35 | + fi |
29 | 36 |
|
30 |
| -if [[ $BUILD_EXIT_CODE -gt 0 ]]; then |
31 |
| -echo "" |
32 |
| -echo "###########################" |
33 |
| -echo "# Failure #" |
34 |
| -echo "###########################" |
35 |
| -echo "" |
36 |
| -echo "Please note that the exit code is not very descriptive." |
37 |
| -echo "Most likely it will not help you solve the issue." |
38 |
| -echo "" |
39 |
| -echo "To find the reason for failure: please search for errors in the log above." |
40 |
| -echo "" |
41 |
| -fi; |
| 37 | + echo "Updated Android SDK." |
| 38 | +else |
| 39 | + echo "Not updating Android SDK." |
| 40 | +fi |
42 | 41 |
|
43 |
| -# |
44 |
| -# Exit with code from the build step. |
45 |
| -# |
| 42 | +if [[ "$RUN_AS_HOST_USER" == "true" ]]; then |
| 43 | + echo "Running as host user" |
| 44 | + |
| 45 | + # Stop on error if we can't set up the user |
| 46 | + set -e |
| 47 | + |
| 48 | + # Get host user/group info so we create files with the correct ownership |
| 49 | + USERNAME=$(stat -c '%U' "$fullProjectPath") |
| 50 | + USERID=$(stat -c '%u' "$fullProjectPath") |
| 51 | + GROUPNAME=$(stat -c '%G' "$fullProjectPath") |
| 52 | + GROUPID=$(stat -c '%g' "$fullProjectPath") |
| 53 | + |
| 54 | + groupadd -g $GROUPID $GROUPNAME |
| 55 | + useradd -u $USERID -g $GROUPID $USERNAME |
| 56 | + usermod -aG $GROUPNAME $USERNAME |
| 57 | + mkdir -p "/home/$USERNAME" |
| 58 | + chown $USERNAME:$GROUPNAME "/home/$USERNAME" |
| 59 | + |
| 60 | + # Normally need root permissions to access when using su |
| 61 | + chmod 777 /dev/stdout |
| 62 | + chmod 777 /dev/stderr |
| 63 | + |
| 64 | + # Don't stop on error when running our scripts as error handling is baked in |
| 65 | + set +e |
| 66 | + |
| 67 | + # Switch to the host user so we can create files with the correct ownership |
| 68 | + su $USERNAME -c "$SHELL -c 'source /steps/runsteps.sh'" |
| 69 | +else |
| 70 | + echo "Running as root" |
| 71 | + |
| 72 | + # Run as root |
| 73 | + source /steps/runsteps.sh |
| 74 | +fi |
46 | 75 |
|
47 |
| -exit $BUILD_EXIT_CODE |
| 76 | +exit $? |
0 commit comments