Skip to content

Instantly share code, notes, and snippets.

@middieNomad
Last active September 22, 2021 08:02
Show Gist options
  • Save middieNomad/59d82b128de30b2114199e77ded93c60 to your computer and use it in GitHub Desktop.
Save middieNomad/59d82b128de30b2114199e77ded93c60 to your computer and use it in GitHub Desktop.
Export Apps from Play Store for use in de-googled phone
adb shell pm list packages | grep <packageName> # Get the package name from package manager.
adb shell pm path <output from line 1> # Get the location of the apk from the filesystem.
adb pull <output from line 3> # Pull the apk
adb install -r base.apk # Disconnect your old android phone, plug the de-googled one in and install the apk. Obviously, you will not get updates for this apk, so be wise and get the updated apk's every month or so. I have this packaged as a script.
#/usr/bin/bash
#
echo "Checking if adb is installed. "
dustbin=$(which adb)
if [ $? -eq 0 ]; then
echo "Good to go"
else
echo "adb is not installed or not in PATH. Please install adb or include it in your path. Exiting."
exit
fi
echo "Checking if device is connected.."
dustbin=$(adb shell ls 2>>/dev/null)
if [ $? -eq 0 ]; then
echo "Device connected".
else
echo "No devices connected. Exiting."
exit
fi
packageList="xrsconnect"
for package in $packageList ; do
packageName=$(adb shell pm list packages | grep $package | awk -F: '{print $2}')
if [ -z "$packageName" ]; then
echo "There is no package like $package, skipping $package"
continue
fi
if [ $(echo "$packageName" | wc -l) -gt 1 ]; then
echo "Multiple packages detected, skipping. Please specify which package you want in the next run. Press a key, any key, to view the package names"
read dustbin
echo "$packageName" | less
continue
else
echo "Single package, going to pull them in"
fi
packageLocation=$(adb shell pm path $packageName | awk -F: '{print $2}' )
if [ -z "$packageLocation" ]; then
echo "Unknown error, quitting"
exit
fi
if [[ $(echo "$packageLocation" | wc -l) -gt 1 ]] ; then
echo "Multiple apks detected $packageLocation, fetching one by one."
[ -d $packageName-multipleInstall ] && rm -rf $packageName-multipleInstall
mkdir $packageName-multipleInstall && cd $packageName-multipleInstall
for individual in $packageLocation ; do
echo $individual
adb pull $individual $packageName-$(shuf -i 1-100 -n 1).apk
done
cd -
else
adb pull $packageLocation $packageName-$(shuf -i 1-100 -n 1).apk
fi
done
if [[ $(find ./ -type f -name '*.apk' | wc -l) -lt 1 ]]; then
echo "No apks downloaded, quiting"
exit;
fi
echo "Proceeding to install the apps. Please connect your new phone. Once ready, press y"
while [ "1" ] ; do
read continueprompt
if [[ "$continueprompt" == "y" || "$continueprompt" == "Y" ]] ; then
echo "Going to install individual apks"
apkList=$(find ./ -maxdepth 1 -type f -name '*.apk')
for apkName in $apkList; do
echo "Installing $apkName"
adb install -r $apkName
done
find ./ -maxdepth 1 -type f -name '*.apk' | xargs -I "{}" rm "{}"
echo "Going to install multi-package apks"
multiInstallList=$(find ./ -maxdepth 1 -type d -name '*multipleInstall' )
for multiInstall in $multiInstallList ; do
echo "Installing $multiInstall" | sed 's/-multipleInstall//g'
cd $multiInstall
adb install-multiple *
cd - && rm -rf $multiInstall
done
break
elif [[ "$continueprompt" == "n" || "$continueprompt" == "N" ]] ; then
echo "Deleting apks and Quitting as per request"
#find ./ -type f -name '*.apk' | xargs -I "{}" rm "{}"
break
else
echo "Y or N?"
continue
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment