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.
112 lines
2.6 KiB
Bash
112 lines
2.6 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# ===== Config =====
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
APP_PACKAGE="com.example.hmg_qline.hmg_qline"
|
|
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
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
echo "Usage: sh kill_qline.sh -ipfile <device_ips.txt>"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$IP_FILE" ]]; then
|
|
echo "Usage: sh kill_qline.sh -ipfile <device_ips.txt>"
|
|
exit 1
|
|
fi
|
|
|
|
# ===== 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"
|
|
|
|
# ===== 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 Kill App =====
|
|
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 "❌ Force-stopping app..."
|
|
if ! adb -s "$device" shell am force-stop "$APP_PACKAGE"; then
|
|
echo "❌ Force-stop failed on $cleanIP"
|
|
failed_ips+=("$cleanIP (kill)")
|
|
continue
|
|
fi
|
|
|
|
success_ips+=("$cleanIP")
|
|
done
|
|
|
|
echo "✅ Kill operation 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
|