diff --git a/unity-command/Dockerfile b/unity-command/Dockerfile index 03011df..8b999d4 100644 --- a/unity-command/Dockerfile +++ b/unity-command/Dockerfile @@ -2,13 +2,20 @@ ARG IMAGE=unityci/base:latest FROM ${IMAGE} +ARG SERIAL +ARG USERNAME +ARG PASSWORD + RUN apt update RUN apt install -y wget chromium-browser -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh - ADD https://minio.studiowhy.net/hackmd/UnityBuilder /usr/local/bin/ RUN chmod +x /usr/local/bin/UnityBuilder +COPY entrypoint.sh / +RUN chmod +x /entrypoint.sh + +COPY scripts/. /scripts +RUN bash /scripts/activate_license.sh ${SERIAL} ${USERNAME} ${PASSWORD} + ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/unity-command/entrypoint.sh b/unity-command/entrypoint.sh index 624e0bd..d29c2c4 100644 --- a/unity-command/entrypoint.sh +++ b/unity-command/entrypoint.sh @@ -6,28 +6,10 @@ rm -rf $HOME/.config/unity3d rm -rf /home/unity/.config/unity3d #Add ssh key information for resolving packages. -if [[ -n "$SSH_PUBLIC_KEY" && -n "$SSH_PRIVATE_KEY" ]]; then - echo "ADDING SSH KEYS!" - SSH_DIR="/home/$(whoami)/.ssh" - mkdir -p $SSH_DIR +bash /scripts/add_ssh_keys.sh - echo "$SSH_PUBLIC_KEY" > $SSH_DIR/id_rsa.pub - echo "$SSH_PRIVATE_KEY" > $SSH_DIR/id_rsa -cat << EOF > $SSH_DIR/config -Host * - StrictHostKeyChecking no -EOF - - chmod 600 $SSH_DIR/id_rsa - chmod 644 $SSH_DIR/id_rsa.pub - cat $SSH_DIR/config -fi - -#Activate Unity -if [[ "$SERIAL" == "personal" ]]; then - UnityBuilder activate -i /usr/bin/unity-editor -u $EMAIL -p $PASSWORD -else - unity-editor $DEFAULT_ARGS -serial $SERIAL -username $EMAIL -password $PASSWORD +if [[ "$SERIAL" != "activated" ]]; then + bash /scripts/activate_license.sh "$SERIAL" "$EMAIL" "$PASSWORD" fi #Run the command. diff --git a/unity-command/scripts/activate_license.sh b/unity-command/scripts/activate_license.sh new file mode 100644 index 0000000..16589d2 --- /dev/null +++ b/unity-command/scripts/activate_license.sh @@ -0,0 +1,13 @@ +#!/bin/bash +SERIAL=$1; EMAIL=$2; PASSWORD=$3; + +if [[ -z "$SERIAL" || -z "$EMAIL" || -z "$PASSWORD" ]]; then + exit 0 +fi + +#Activate Unity +if [[ "$SERIAL" == "personal" ]]; then + UnityBuilder activate -i /usr/bin/unity-editor -u $EMAIL -p $PASSWORD +else + unity-editor $DEFAULT_ARGS -serial $SERIAL -username $EMAIL -password $PASSWORD +fi \ No newline at end of file diff --git a/unity-command/scripts/add_ssh_keys.sh b/unity-command/scripts/add_ssh_keys.sh new file mode 100644 index 0000000..25da0fa --- /dev/null +++ b/unity-command/scripts/add_ssh_keys.sh @@ -0,0 +1,17 @@ +#!/bin/bash +if [[ -n "$SSH_PUBLIC_KEY" && -n "$SSH_PRIVATE_KEY" ]]; then + echo "ADDING SSH KEYS!" + SSH_DIR="/home/$(whoami)/.ssh" + mkdir -p $SSH_DIR + + echo "$SSH_PUBLIC_KEY" > $SSH_DIR/id_rsa.pub + echo "$SSH_PRIVATE_KEY" > $SSH_DIR/id_rsa +cat << EOF > $SSH_DIR/config +Host * + StrictHostKeyChecking no +EOF + + chmod 600 $SSH_DIR/id_rsa + chmod 644 $SSH_DIR/id_rsa.pub + cat $SSH_DIR/config +fi \ No newline at end of file