Installs all apk files in a given folder to a connected device.
#!/bin/bash
# Check if directory argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <directory_path>"
exit 1
fi
# Store directory path
APK_DIR="$1"
# Check if directory exists
if [ ! -d "$APK_DIR" ]; then
echo "Error: Directory '$APK_DIR' does not exist"
exit 1
fi
# Check if adb is available
if ! command -v adb &> /dev/null; then
echo "Error: ADB is not installed or not in PATH"
exit 1
fi
# Check if any device is connected
if ! adb devices | grep -q "device$"; then
echo "Error: No Android device connected"
exit 1
fi
# Count total APKs
total_apks=$(find "$APK_DIR" -name "*.apk" | wc -l)
if [ "$total_apks" -eq 0 ]; then
echo "No APK files found in '$APK_DIR'"
exit 1
fi
echo "Found $total_apks APK file(s)"
echo "Starting installation..."
# Counter for successful and failed installations
success=0
failed=0
# Find and install all APK files
find "$APK_DIR" -name "*.apk" | while read -r apk_file; do
echo -n "Installing $(basename "$apk_file")... "
if adb install -r "$apk_file" &> /dev/null; then
echo "SUCCESS"
((success++))
else
echo "FAILED"
((failed++))
fi
done
# Print summary
echo
echo "Installation complete!"
echo "Successfully installed: $success"
echo "Failed installations: $failed"
echo "Total APKs processed: $total_apks"