#!/bin/bash script_path=$(dirname "${0}") . "${script_path}/lib/common" arguments=( "h|help#This help text." ) declare -i parse_error=0 declare command="" declare XVNC_ARGS="-depth 24 -geometry 1280x1024 -ac" # # Parse command line arguments # if ! parse_arguments "${@}"; then parse_error=1 fi # # Process command line options # eval set -- "${opts}" remaining=$# while (( $# > 0 )); do if [[ ${remaining} == 0 ]]; then fail "case statement is not shifting off values correctly." fi remaining=$((remaining-1)) # Uncomment to help debug case statement: # echo "Processing: \$1='$1' \$2='$2'" case "${1}" in -h|--help) # Help / usage usage_extra="[COMMAND [OPTIONS]]" default_usage exit 0 ;; --) shift break ;; esac shift done declare command declare -a options=() if (( ${#} > 0 )); then command="${1}" shift options=("${@}") fi if [[ "${command}" == "" ]]; then echo "COMMAND must be supplied." >&2 exit 1 fi if (( parse_error )); then exit 1 fi case "${command}" in init) if [[ "${CONTAINER_MODE}" != "android-sdk-manager" ]]; then fail "'${command}' must be run on android-sdk-manager not android-dev-container" fi if [[ ! -e "${ANDROID_HOME}"/license/android-sdk-license ]]; then if ! cp -a "${ANDROID_HOME}"/. /sdk; then fail "Unable to copy ${ANDROID_HOME} to /sdk" fi fi echo "AndroidSDK transfered to host bind mount." ;; seed-project) if [[ "${CONTAINER_MODE}" == "android-sdk-manager" ]]; then fail "'${command}' must be run on android-dev-container not android-sdk-manager" fi seed-project "${options[@]}" exit $? ;; develop) if [[ "${CONTAINER_MODE}" == "android-sdk-manager" ]]; then fail "'${command}' must be run on android-dev-container not android-sdk-manager" fi project="${1}" project_type=$(cat "/projects/${project}/project_type") cd "/projects/${project}" if [[ -d ".git" ]]; then git config --global --add safe.directory "$(pwd)" fi case "${project_type}" in "expo") echo "Launching web app in ${project}" npm run web ;; "flutter") cat << EOF > ~/.flutter { "firstRun": false, "clientId": "b88ac7f3-4d6f-41e0-bef6-f377e4eaceb7", "enabled": false } EOF Xvnc ${DISPLAY} ${XVNC_ARGS} >/dev/null 2>&1 & fluxbox >/dev/null 2>&1 & echo "X11 VNC running on ${DISPLAY} with password '${CONTAINER}'" if [[ ! -d "/opt/devices/pixel-6a" ]]; then echo "Creating Pixel 6A with Android 35 and Google APIs" avdmanager create avd --force --path /opt/devices/pixel-6a --name Pixel-6a -k "system-images;android-34;google_apis_playstore;x86_64" --device pixel_6a fi echo "Launching emulator. Connect via vnc to view." emulator -avd Pixel-6a & echo "Launching terminal in ${project}" /bin/bash ;; esac ;; run) if [[ "${CONTAINER_MODE}" == "android-sdk-manager" ]]; then fail "'${command}' must be run on android-dev-container not android-sdk-manager" fi project="${1}" cd "/projects/${project}" if [[ -d ".git" ]]; then git config --global --add safe.directory "$(pwd)" fi project_type=$(cat "/projects/${project}/project_type") case "${project_type}" in "expo") echo "Starting web app in ${project}" while true; do npm run web; sleep 5; done ;; "flutter") cat << EOF > ~/.flutter { "firstRun": false, "clientId": "b88ac7f3-4d6f-41e0-bef6-f377e4eaceb7", "enabled": false } EOF Xvnc ${DISPLAY} ${XVNC_ARGS} >/dev/null 2>&1 & fluxbox >/dev/null 2>&1 & echo "X11 VNC running on ${DISPLAY} with password '${CONTAINER}'" if [[ ! -d "/opt/devices/pixel-6a" ]]; then echo "Creating Pixel 6A with Android 35 and Google APIs" avdmanager create avd --force --path /opt/devices/pixel-6a --name Pixel-6a -k "system-images;android-34;google_apis_playstore;x86_64" --device pixel_6a fi echo "Launching emulator. Connect via vnc to view." emulator -avd Pixel-6a & echo "Launching terminal in ${project}" /bin/bash ;; esac ;; *bash|shell) /bin/bash "${options[@]}" exit $? ;; *) if [[ "${CONTAINER_MODE}" == "android-sdk-manager" ]] && [[ "${command}" =~ .*sdkmanager$ ]]; then echo "'${command}' detected. Updating container copy of Android SDK from the host." cp -a /sdk/. $ANDROID_HOME/ fi ${command} "${@}" if [[ "${CONTAINER_MODE}" == "android-sdk-manager" ]] && [[ "${command}" =~ .*sdkmanager$ ]]; then echo "'${command}' detected. Updating host copy of Android SDK" cp -a $ANDROID_HOME/. /sdk/ fi ;; esac