You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_QLine/qline_scripts/deploy_qline.sh

206 lines
4.9 KiB
Bash

#!/usr/bin/env bash
# ===== Config =====
APP_NAME="com.example.hmg_qline.hmg_qline/.MainActivity"
TIMEOUT_SECONDS=5
run_with_timeout() {
perl -e 'alarm $ARGV[0]; exec @ARGV[1..$#ARGV]' "$TIMEOUT_SECONDS" "$@"
}
# ===== Parse Arguments =====
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-ipfile)
IP_FILE="$2"
shift # past argument
shift # past value
;;
-version)
APP_VERSION="$2"
shift # past argument
shift # past value
;;
*)
echo "Unknown option: $1"
echo "Usage: sh deploy_qline.sh -ipfile <device_ips.txt> -version <app_version>"
exit 1
;;
esac
done
if [[ -z "$IP_FILE" ]]; then
echo "Usage: sh deploy_qline.sh -ipfile <device_ips.txt> -version <app_version>"
exit 1
fi
if [[ -z "$APP_VERSION" ]]; then
echo "Usage: sh deploy_qline.sh -ipfile <device_ips.txt> -version <app_version>"
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
APK_PATH="$SCRIPT_DIR/apks/qline_opd_v${APP_VERSION}_prod.apk"
# ===== Wi-Fi Check =====
wifi_interface=$(networksetup -listallhardwareports | \
awk '/Wi-Fi|AirPort/{getline; print $2}')
current_ssid=$(networksetup -getairportnetwork "$wifi_interface" 2>/dev/null | \
awk -F': ' '{print $2}' | tr '[:upper:]' '[:lower:]')
expected_ssid="cloud solutions"
if [[ "$current_ssid" != "$expected_ssid" ]]; then
echo "❌ Not connected to required Wi-Fi network: $expected_ssid"
echo "🔌 Current network: ${current_ssid:-Not connected}"
exit 1
fi
echo "✅ Connected to correct Wi-Fi: Cloud Solutions"
# ===== Disconnect All Devices =====
echo "🔌 Disconnecting all devices..."
adb disconnect
# ===== Read IPs =====
if [[ ! -f "$IP_FILE" ]]; then
echo "❌ IP file not found at $IP_FILE"
exit 1
fi
ipList=()
while IFS= read -r line; do
[[ -n "$line" ]] && ipList+=("$line")
done < "$IP_FILE"
if [[ ${#ipList[@]} -eq 0 ]]; then
echo "❌ No IPs found in file"
exit 1
fi
echo "✅ Found ${#ipList[@]} IPs"
printf '%s\n' "${ipList[@]}"
# ===== Connect and Deploy =====
success_ips=()
failed_ips=()
for ip in "${ipList[@]}"; do
cleanIP="${ip%%:*}" # strip port if exists
device="$cleanIP:5555"
echo "🔌 Connecting to $cleanIP..."
output=$(run_with_timeout adb connect "$device" 2>&1)
status=$?
if [[ $status -ne 0 || "$output" != *connected* ]]; then
echo "❌ Failed to connect to $cleanIP: $output"
failed_ips+=("$cleanIP (connect)")
continue
fi
echo "📱 Processing $device..."
echo "📦 Installing APK..."
if ! adb -s "$device" install -r "$APK_PATH"; then
echo "❌ Install failed on $cleanIP"
failed_ips+=("$cleanIP (install)")
continue
fi
echo "🚀 Launching app..."
if ! adb -s "$device" shell am start -n "$APP_NAME"; then
echo "❌ Launch failed on $cleanIP"
failed_ips+=("$cleanIP (launch)")
continue
fi
success_ips+=("$cleanIP")
done
echo "✅ Deployment complete."
echo "\n====== Summary ======"
echo "✅ Success (${#success_ips[@]}):"
if [[ ${#success_ips[@]} -gt 0 ]]; then
printf ' - %s\n' "${success_ips[@]}"
else
echo " - None"
fi
echo "❌ Failed (${#failed_ips[@]}):"
if [[ ${#failed_ips[@]} -gt 0 ]]; then
printf ' - %s\n' "${failed_ips[@]}"
else
echo " - None"
fi
# Calling ==> ./deploy_qline.sh -ipfile device_ips_all.txt -version 9.2
# /Users/zik/Library/Android/sdk/platform-tools
# *********************** WOMEN HEALTH (Riyadh) ***********************
# 1st Floor (OBG)
# 10.71.50.45 - v9
# 10.71.50.50 - v9
# 10.71.50.57 - v9
# 10.71.50.52 - v9
# 2nd Floor (OBG)
# 10.71.50.46 - v9
# 10.71.50.47 - v9
# 10.71.50.48 - v9
# 10.71.50.49 - v9
# 6th Floor (IVF)
# 10.71.50.53 - v9.3 qline_opd_v9.3_bg_fix_prod
# 10.71.50.56 - v9
# *********************** HMG-KHOBAR ***********************
# 10.90.82.236 - v8.9
# *********************** TAKHASSUSI ***********************
# (G-FLOOR) ORTHOPEDIC
# 10.70.194.105 - v9.2
# 10.70.194.87 - v9.2
# *********************** SUWAIDI ***********************
# 10.80.31.37 - v9.3 (SWD Oncology & Family Med WA)
# 10.80.30.220 - v9 (SWD Oncology & Family Med WA)
# 10.80.31.67 - v9 (SWD Internal Med & Other Clinics WA)
# 10.80.31.80 - v9 (SWD Internal Med & Other Clinics WA)
# 10.80.31.100 - v9.3 (SWD PEDIATRIC & Other WA) -> qline_opd_v9.3_android_14.apk
# 10.80.31.103 - v9.3 (SWD PEDIATRIC & Other WA) -> qline_opd_v9.3_android_14.apk
# 10.80.31.104 - v9.3 (SWD OB-GYN & Other Clinics Waiting Area) -> qline_opd_v9.3_android_14.apk
# 10.80.30.234 - v9.3 (SWD OB-GYN & Other Clinics Waiting Area) -> qline_opd_v9.3_android_14.apk
# Deploy version 9 to all devices
# sh deploy_qline.sh -ipfile device_ips_all.txt -version 9
# Deploy to Khobar location only
# sh deploy_qline.sh -ipfile device_ips_khobar.txt -version 8.9
# Deploy to Takhassusi hospital
# sh deploy_qline.sh -ipfile device_ips_tak.txt -version 8.9
# Deploy to Women's Health center
# sh deploy_qline.sh -ipfile device_ips_tak_women.txt -version 9