Skip to content

Commit

Permalink
Merge pull request #46 from zebrunner/develop
Browse files Browse the repository at this point in the history
1.1.1 RC
  • Loading branch information
azarouski authored Oct 8, 2024
2 parents e647bdd + b84aff6 commit ee39f50
Showing 1 changed file with 55 additions and 38 deletions.
93 changes: 55 additions & 38 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

logger "INFO" "\n\n\n\t\tMCLOUD-IOS-CONNECTOR\n\n"

#### Preparation steps
# If HOST_OS is null or unset use default value
HOST_OS="${HOST_OS:-"LINUX"}"


#### Establish and check usbmuxd connection
# Check if $USBMUXD_PORT port is free
Expand Down Expand Up @@ -131,7 +135,7 @@ if [[ $isAvailable -eq 0 ]]; then
fi


#### Detect OS version and accordingly run go-ncm
#### Detect device OS version
ios17plus=0
deviceOsVersion=$(echo "$deviceInfo" | sed -n 's/.*"ProductVersion":"\([^"]*\).*/\1/p')
logger "Detected device os version: $deviceOsVersion"
Expand All @@ -141,18 +145,17 @@ if [[ "$majorOsVersion" -gt 0 ]] 2>/dev/null; then
logger "Major os version detected as '$majorOsVersion'"
if [[ "$majorOsVersion" -ge 17 ]]; then
ios17plus=1
logger "Running go-ncm and reporting on 3030 port."
# To check 'curl localhost:3030/metrics'
go-ncm --prometheusport=3030 &
fi
else
logger "WARN" "Can't detect major os version: $majorOsVersion"
fi


#### Check go-ncm connection
if [[ "$ios17plus" -eq 1 ]]; then
logger "Starting ncm (Network Control Model)."
#### Run go-ncm and check connection
if [[ "$ios17plus" -eq 1 ]] && [[ ${HOST_OS^^} = "LINUX" ]]; then
logger "Starting go-ncm and its reporting on 3030 port."
# To check 'curl localhost:3030/metrics'
go-ncm --prometheusport=3030 &
declare -i index=0
isNcmConnected=0
# TODO: adjust timeout based on real usage
Expand All @@ -178,7 +181,7 @@ fi


#### Start and check tunnel
if [[ "$ios17plus" -eq 1 ]]; then
if [[ "$ios17plus" -eq 1 ]] && [[ ${HOST_OS^^} = "LINUX" ]]; then
tunnelLogFile="/tmp/log/tunnel.log"
touch $tunnelLogFile

Expand Down Expand Up @@ -240,36 +243,37 @@ if ios apps --udid="$DEVICE_UDID" | grep -v grep | grep "$WDA_BUNDLEID" > /dev/n
else
logger "'$WDA_BUNDLEID' app is not installed"

if [[ ! -f "$WDA_FILE" ]]; then
logger "ERROR" "'$WDA_FILE' file is not exist or not a regular file. Exiting!"
exit 0
fi
if [[ ${HOST_OS^^} = "LINUX" ]]; then
if [[ ! -f "$WDA_FILE" ]]; then
logger "ERROR" "'$WDA_FILE' file is not exist or not a regular file. Exiting!"
exit 0
fi

logger "Installing WDA application on device:"
wdaInstall=$(ios install --path="$WDA_FILE" --udid="$DEVICE_UDID" 2>&1)
if [[ $wdaInstall == *'"err":'* ]]; then
logger "ERROR" "Error while installing WDA_FILE: '$WDA_FILE'."
echo "$wdaInstall" | jq --raw-input '. as $line | try (fromjson) catch $line'
logger "ERROR" "Trying to uninstall WDA:"
wdaUninstall=$(ios uninstall "$WDA_BUNDLEID" --udid="$DEVICE_UDID" 2>&1)
echo "$wdaUninstall" | jq --raw-input '. as $line | try (fromjson) catch $line'
logger "ERROR" "Exiting!"
logger "Installing WDA application on device:"
wdaInstall=$(ios install --path="$WDA_FILE" --udid="$DEVICE_UDID" 2>&1)
if [[ $wdaInstall == *'"err":'* ]]; then
logger "ERROR" "Error while installing WDA_FILE: '$WDA_FILE'."
echo "$wdaInstall" | jq --raw-input '. as $line | try (fromjson) catch $line'
logger "ERROR" "Trying to uninstall WDA:"
wdaUninstall=$(ios uninstall "$WDA_BUNDLEID" --udid="$DEVICE_UDID" 2>&1)
echo "$wdaUninstall" | jq --raw-input '. as $line | try (fromjson) catch $line'
logger "ERROR" "Exiting!"
exit 0
fi
else
logger "ERROR" "Can't continue without WDA installed. Exiting!"
exit 0
fi
fi


#### Start WDA
# No need to launch springboard as it is already started. Below command doesn't activate it!
# logger "Activating default com.apple.springboard during WDA startup"
# ios launch com.apple.springboard
touch "${WDA_LOG_FILE}"
# verify if wda is already started and reuse this session

runWda() {
touch "${WDA_LOG_FILE}"
tail -f "${WDA_LOG_FILE}" &
# This is temporary solution for modal dialogs which prevent WDA startup.
logger "Resetting springboard process and waiting for 5 seconds."
ios kill com.apple.springboard
ios kill com.apple.springboard --udid="$DEVICE_UDID"
sleep 5

declare -i index=0
Expand Down Expand Up @@ -305,6 +309,7 @@ runWda() {
forwardPort() {
if [[ -n $1 ]]; then
port=$1
logger "Forwarding port: $port"
else
logger "WARN" "Port value is empty or not provided!"
return 1
Expand Down Expand Up @@ -333,30 +338,42 @@ forwardPort() {
fi
}

curl -Is "http://${WDA_HOST}:${WDA_PORT}/status" | head -1 | grep -q '200 OK'
if [[ $? -ne 0 ]]; then
logger "WARN" "Existing WDA not detected."
if [[ ${HOST_OS^^} = "LINUX" ]]; then
curl -Is "http://${WDA_HOST}:${WDA_PORT}/status" | head -1 | grep -q '200 OK'
if [[ $? -ne 0 ]]; then
logger "WARN" "Running WDA not detected."

logger "Starting WebDriverAgent application on port '$WDA_PORT'."
runWda &
sleep 3
logger "Starting WebDriverAgent application on port '$WDA_PORT'."
runWda &
sleep 3

# #148: ios: reuse proxy for redirecting wda requests through appium container
# #148: ios: reuse proxy for redirecting wda requests through appium container
forwardPort "$WDA_PORT" &
sleep 1
forwardPort "$MJPEG_PORT" &
fi
else
# On macOS platform reset springboard only for ios version lower than 17
if [[ "$ios17plus" -eq 1 ]]; then
sleep 1
else
logger "Resetting springboard process and waiting for 5 seconds."
ios kill com.apple.springboard --udid="$DEVICE_UDID"
sleep 5
fi
forwardPort "$WDA_PORT" &
sleep 1
forwardPort "$MJPEG_PORT" &
fi

tail -f "${WDA_LOG_FILE}" &


#### Wait for WDA start
startTime=$(date +%s)
wdaStarted=0
while [[ $((startTime + WDA_WAIT_TIMEOUT)) -gt "$(date +%s)" ]]; do
curl -Is "http://${WDA_HOST}:${WDA_PORT}/status" | head -1 | grep -q '200 OK'
if [[ $? -eq 0 ]]; then
logger "Wda started successfully!"
logger "Wda status is OK!"
wdaStarted=1
break
fi
Expand Down

0 comments on commit ee39f50

Please sign in to comment.