Skip to content

Instantly share code, notes, and snippets.

@eybisi
Last active January 2, 2024 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eybisi/5ea2a6a3fd0b022074e2ebd9012e66b8 to your computer and use it in GitHub Desktop.
Save eybisi/5ea2a6a3fd0b022074e2ebd9012e66b8 to your computer and use it in GitHub Desktop.
bash script with gum for pulling/installing package
#!/bin/sh
gum style --border normal --border-foreground 55 "Hello, there! Give me the $(gum style --foreground 57 'package name') you would like to install/pull."
package_name=$(gum input --placeholder "Package name")
sleep 0.5; clear
pull_apk(){
gum style --border normal --border-foreground 128 "Looks like $(gum style --foreground 128 $package_name) is installed."
gum input --placeholder "Press any key to pull apk"
path=$(adb shell pm path $package_name)
clear;
if [ ! -z "$path" ]
then
gum style --border normal --border-foreground 76 " $(gum style --foreground 77 $package_name) is installed."
first_path=$(echo ${path:8} | cut -f 1 -d " ")
gum spin -s monkey --title "Pulling apk from device " -- adb pull ${first_path} base.apk > /dev/null
mv base.apk $package_name.apk
echo "Package: $(gum style --foreground 99 $package_name) saved as $(gum style --foreground 77 $package_name.apk)"
else
gum style --border normal --border-foreground 160 " $(gum style --foreground 160 $package_name) is not installed."
echo "Cannot find $(gum style --italic --foreground 160 $package_name) apk"
fi
exit;
}
wait_for_install(){
echo "wait for install"
while [ true ] ; do
path=$(adb shell pm path $package_name)
if [ ! -z "$path" ]
then
break
else
sleep 1
fi
done
}
is_installed(){
path=$(adb shell pm path $1)
if [ ! -z "$path" ]
then
return 55;
else
return 44;
fi
}
is_installed $package_name
if [ $? == 55 ]
then
#installed
pull_apk
else
#not installed
response_code=$(gum spin --show-output -s line --title "Checking $(gum style --foreground "#04B575" "$package_name") in play store" -- curl -s -o /dev/null -w "%{http_code}" https://play.google.com/store/apps/details\?id\=$package_name)
if [ $response_code == "200" ]
then
adb shell am start -a android.intent.action.VIEW -d "market://details?id=$package_name" > /dev/null
gum style --border normal --border-foreground 128 "Waiting you to install opened $(gum style --foreground 128 $package_name)"
gum spin -s globe --title "Opening play store page for $(gum style --foreground "#04B575" "$package_name").." -- /usr/bin/waitforapkinstall $package_name
clear;
pull_apk
else
gum style --border normal --border-foreground 124 " $(gum style --foreground 124 $package_name) is not installed."
echo "Package $(gum style --italic --foreground 124 $package_name) is neither installed nor in play store"
exit;
fi
fi
#!/bin/sh
while [ true ] ; do
path=$(adb shell pm path $1)
echo $path
if [ ! -z "$path" ]
then
exit
else
sleep 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment