diff --git a/entrypoint.sh b/entrypoint.sh index 16f471a..89bae1c 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,10 +6,11 @@ if [[ -n "$UNITY_LICENSE" ]]; then # # This will activate Unity, using a license file # - # Note that this is the ONLY WAY for PERSONAL LICENSES in 2019. + # Note that this is the ONLY WAY for PERSONAL LICENSES in 2020. # * See for more details: https://gitlab.com/gableroux/unity3d-gitlab-ci-example/issues/5#note_72815478 # # The license file can be acquired using `webbertakken/request-manual-activation-file` action. + echo "Requesting activation (personal license)" # Set the license file path FILE_PATH=UnityLicenseFile.ulf @@ -17,52 +18,36 @@ if [[ -n "$UNITY_LICENSE" ]]; then # Copy license file from Github variables echo "$UNITY_LICENSE" | tr -d '\r' > $FILE_PATH - ## - ## Activate license - ## - echo "Requesting activation" - xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ + # Activate license + ACTIVATION_OUTPUT=$(xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ /opt/Unity/Editor/Unity \ -batchmode \ -nographics \ -logFile /dev/stdout \ -quit \ - -manualLicenseFile $FILE_PATH - # This is expected to always exit with code 1 (both success and failure). - # Convert to exit code 0 by echoing the current exit code. - echo $? - # Exit code is now 0 - - ## - ## Verify activated license - ## - echo "Verifying activation" - # Run any command that requires activation to verify - xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ - /opt/Unity/Editor/Unity \ - -batchmode \ - -nographics \ - -logFile /dev/stdout \ - -quit + -manualLicenseFile $FILE_PATH) # Store the exit code from the verify command UNITY_EXIT_CODE=$? - # Display information about the result - if [ $UNITY_EXIT_CODE -eq 0 ]; then - echo "Activation (personal) complete." - else - echo "Unclassified error occured while trying to activate (personal) license." - echo "Exit code was: $UNITY_EXIT_CODE" - fi + # The exit code for personal activation is always 1; + # Determine whether activation was successful. + # + # Successful output should include the following: + # + # "LICENSE SYSTEM [2020120 18:51:20] Next license update check is after 2019-11-25T18:23:38" + # + ACTIVATION_SUCCESSFUL=$(echo $ACTIVATION_OUTPUT | grep 'Next license update check is after' | wc -l) + + # Set exit code to 0 if activation was successful + if [[ $ACTIVATION_SUCCESSFUL -eq 1 ]]; then + UNITY_EXIT_CODE=0 + fi; # Remove license file rm -f $FILE_PATH - # Exit with the code from the license verification step - exit $UNITY_EXIT_CODE - -else +elif [[ -n "$UNITY_SERIAL" && -n "$UNITY_EMAIL" && -n "$UNITY_PASSWORD" ]]; then # # PROFESSIONAL (SERIAL) LICENSE MODE # @@ -70,6 +55,9 @@ else # # Note: This is the preferred way for PROFESSIONAL LICENSES. # + echo "Requesting activation (professional license)" + + # Activate license xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ /opt/Unity/Editor/Unity \ -batchmode \ @@ -83,15 +71,31 @@ else # Store the exit code from the verify command UNITY_EXIT_CODE=$? - # Display information about the result - if [ $UNITY_EXIT_CODE -eq 0 ]; then - echo "Activation (professional) complete." - else - echo "Unclassified error occured while trying to activate (professional) license." - echo "Exit code was: $UNITY_EXIT_CODE" - fi +else + # + # NO LICENSE ACTIVATION STRATEGY MATCHED + # + # This will exit since no activation strategies could be matched. + # + echo "License activation strategy could not be determined." + echo "" + echo "Visit https://github.com/webbertakken/unity-builder#usage for more" + echo "details on how to set up one of the possible activation strategies." - # Exit with the code from the license verification step - exit $UNITY_EXIT_CODE + # Immediately exit as no UNITY_EXIT_CODE can be derrived. + exit 1; fi + +# +# Display information about the result +# +if [ $UNITY_EXIT_CODE -eq 0 ]; then + # Activation was a success + echo "Activation complete." +else + # Activation failed so exit with the code from the license verification step + echo "Unclassified error occured while trying to activate license." + echo "Exit code was: $UNITY_EXIT_CODE" + exit $UNITY_EXIT_CODE +fi