This commit is contained in:
Andrea Cavalli 2021-07-31 19:32:54 +02:00
parent 8845fb6fb2
commit 6a8d21b55e
4 changed files with 105 additions and 57 deletions

View File

@ -11,6 +11,9 @@ fi
mkdir -p "$outdir"
find "$backupdir" -name "data.*.win*" ! -name '*.sha2' ! -name '*.info' -type f -exec tar -xvf {} --directory="$bashdir/$outdir" \;
for i in $(find "$backupdir" -name "data.*.win*" ! -name '*.sha2' ! -name '*.info' -type f); do
echo "Extracting file \"$i\""
pv $i | tar -x --overwrite -C "$bashdir/$outdir"
done
echo "Done."

View File

@ -3,12 +3,14 @@
basedir="$PWD"
echo "Found main user"
ls "$basedir/work/data/data/" --format single-column --indicator-style none > "$basedir/work/packages_list_0.txt"
cd work/data/user
for USERID in *; do
if [ -d "${USERID}" ]; then
echo "${USERID}" # your processing here
echo "Found user ${USERID}"
ls "$basedir/work/data/user/$USERID/" --format single-column --indicator-style none > "$basedir/work/packages_list_${USERID}.txt"
fi
ls "$basedir/work/data/data/" --format single-column --indicator-style none > "$basedir/work/packages_list_0.txt"
done

View File

@ -34,13 +34,13 @@ remotepackages="/data/user/${USER_NUMBER}/"
readarray -t packages < "work/packages_list_${BACKUP_USER_NUMBER}.txt"
if [ -z "$BACKUP_USER_NUMBER" ]
then
then
echo "Syntax: script.sh <old_user_id_number> <new_user_id_number>"
exit 1
fi
if [ -z "$USER_NUMBER" ]
then
then
echo "Syntax: script.sh <old_user_id_number> <new_user_id_number>"
exit 1
fi
@ -57,28 +57,42 @@ printf "=========================================================\n"
for package in ${packages[*]}
do
{
{
printf "=========================================================\n"
if [[ $(curl -oIL -s -w "%{http_code}" "https://play.google.com/store/apps/details?id=$package") -eq 404 ]]; then
echo "Skipping package \"$package\" because it's not on the play store."
else
adb shell am start -a android.intent.action.VIEW -d market://details?id=$package
#while [ -n "$(adb shell "dumpsys activity | grep top-activity | grep 'com.android.vending'")" ]; do
# echo "wait..."
# sleep 1
#done
echo "When you have the app installed, press volume UP to copy the data, press volume DOWN to skip"
if [[ $(adb shell "getevent -l -v4 | grep -m1 --line-buffered KEY_VOLUME") == *"KEY_VOLUMEDOWN"* ]]; then
if [[ $(adb shell "getevent -l -v4 | grep -m1 --line-buffered -E -e \"KEY_VOLUME(UP|DOWN)[ ]+DOWN\"") == *"KEY_VOLUMEDOWN"* ]]; then
adb shell input keyevent KEYCODE_HOME
echo "skipped $package"
else
adb shell input keyevent KEYCODE_HOME
printf "Killing %s\n" $package
adb shell su -c "am force-stop --user $USER_NUMBER $package"
printf "Clearing %s\n" $package
adb shell su -c "pm clear --user $USER_NUMBER $package || true"
userid=$(adb shell su -c "stat -c '%u' $remotepackages$package") || $(adb shell su -c "dumpsys package $package" | grep userId | cut -d "=" -f2- | tr -d [:alpha:] | head -n 1)
groupid=$(adb shell su -c "stat -c '%g' $remotepackages$package") || $(adb shell su -c "dumpsys package $package" | grep userId | cut -d "=" -f2- | tr -d [:alpha:] | head -n 1)
echo "App UserId=$userid"
echo "App GroupId=$groupid"
echo "Local packages=$localpackages"
echo "Remote packages=$remotepackages"
echo "Package=$package"
userid=$(adb shell su -c "stat -c '%U' $remotepackages$package")
groupid=$(adb shell su -c "stat -c '%G' $remotepackages$package")
cacheuserid="${userid}"
cachegroupid="${groupid}_cache"
echo "App Data UserId=$userid"
echo "App Data GroupId=$groupid"
echo "App Cache UserId=$cacheuserid"
echo "App Cache GroupId=$cachegroupid"
printf "Compressing %s\n" $package
rm -r "$localpackages$package/cache" 2>/dev/null
rm -r "$localpackages$package/code_cache" 2>/dev/null
tar cfz .tmp_$package.tar.gz -C $localpackages $package/
printf "Copying %s\n" $package
adb shell su -c "chown -R shell:shell /sdcard/.to_move"
@ -91,10 +105,13 @@ do
# adb shell su -c "mv /sdcard/.to_move/$package $remotepackages"
printf "Correcting package\n"
adb shell su -c "chown -R \"$userid:$groupid\" \"$remotepackages$package\""
adb shell su -c "chown -R \"$cacheuserid:$cachegroupid\" \"$remotepackages$package/cache\" 2>/dev/null"
adb shell su -c "chown -R \"$cacheuserid:$cachegroupid\" \"$remotepackages$package/code_cache\" 2>/dev/null"
adb shell su -c "restorecon -R \"$remotepackages$package\""
printf "Package restored on device\n"
sleep 1
fi
fi
} || {
echo "Error"
}

View File

@ -1,19 +1,45 @@
#!/bin/bash
#!/bin/bash -e
bashdir="$PWD"
outdir="work"
if [ -z "$1" ]
then
echo "You must supply the path of the .ab file"
exit 1
fi
abfile=$(readlink -f "$1")
if [ -z "$abfile" ]
then
echo "You must supply the path of the .ab file"
exit 1
fi
mkdir -p "$outdir"
outdir=$(readlink -f "$outdir")
mkdir -p "$outdir/ab_backup"
#dd if="$1" bs=512 skip=3 | tar -x -C "$outdir/ab_backup"
#java -jar abe.jar unpack "$1" "$outdir/ab_backup.tar"
cd "$outdir/ab_backup"
"$bashdir/twrpabx" "$abfile"
"$bashdir/twrpabx" "$abfile" > /dev/null
cd $bashdir
#tar -xf "$outdir/ab_backup.tar" -C "$outdir/ab_backup"
#Extract
for i in $(find "$outdir/ab_backup" -name "data.*.win*" ! -name '*.sha2' ! -name '*.info' -type f); do
echo "Extracting file \"$i\""
( pv $i | tar -x --overwrite -C "$outdir" ) || true
done
echo "The backup has been extracted to: \"$outdir/ab_backup\""
echo "Please use that path for the next steps"
#Delete extracted backup directory
rm -rf "$outdir/ab_backup"
#Fix directory structure
if [ -d "$outdir/user/0" ]
then
rmdir "$outdir/user/0"
fi
mv "$outdir/data" "$outdir/data_tmp"
mkdir -p "$outdir/data"
mv "$outdir/data_tmp" "$outdir/data/data"
mv "$outdir/user" "$outdir/data/user"
mv "$outdir/app" "$outdir/data/app"