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" 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." echo "Done."

View File

@ -3,12 +3,14 @@
basedir="$PWD" 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 cd work/data/user
for USERID in *; do for USERID in *; do
if [ -d "${USERID}" ]; then 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" ls "$basedir/work/data/user/$USERID/" --format single-column --indicator-style none > "$basedir/work/packages_list_${USERID}.txt"
fi fi
ls "$basedir/work/data/data/" --format single-column --indicator-style none > "$basedir/work/packages_list_0.txt"
done done

View File

@ -34,13 +34,13 @@ remotepackages="/data/user/${USER_NUMBER}/"
readarray -t packages < "work/packages_list_${BACKUP_USER_NUMBER}.txt" readarray -t packages < "work/packages_list_${BACKUP_USER_NUMBER}.txt"
if [ -z "$BACKUP_USER_NUMBER" ] if [ -z "$BACKUP_USER_NUMBER" ]
then then
echo "Syntax: script.sh <old_user_id_number> <new_user_id_number>" echo "Syntax: script.sh <old_user_id_number> <new_user_id_number>"
exit 1 exit 1
fi fi
if [ -z "$USER_NUMBER" ] if [ -z "$USER_NUMBER" ]
then then
echo "Syntax: script.sh <old_user_id_number> <new_user_id_number>" echo "Syntax: script.sh <old_user_id_number> <new_user_id_number>"
exit 1 exit 1
fi fi
@ -57,28 +57,42 @@ printf "=========================================================\n"
for package in ${packages[*]} for package in ${packages[*]}
do do
{ {
printf "=========================================================\n" 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 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 #while [ -n "$(adb shell "dumpsys activity | grep top-activity | grep 'com.android.vending'")" ]; do
# echo "wait..." # echo "wait..."
# sleep 1 # sleep 1
#done #done
echo "When you have the app installed, press volume UP to copy the data, press volume DOWN to skip" 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" echo "skipped $package"
else else
adb shell input keyevent KEYCODE_HOME
printf "Killing %s\n" $package printf "Killing %s\n" $package
adb shell su -c "am force-stop --user $USER_NUMBER $package" adb shell su -c "am force-stop --user $USER_NUMBER $package"
printf "Clearing %s\n" $package printf "Clearing %s\n" $package
adb shell su -c "pm clear --user $USER_NUMBER $package || true" 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) echo "Local packages=$localpackages"
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 "Remote packages=$remotepackages"
echo "App UserId=$userid" echo "Package=$package"
echo "App GroupId=$groupid" 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 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/ tar cfz .tmp_$package.tar.gz -C $localpackages $package/
printf "Copying %s\n" $package printf "Copying %s\n" $package
adb shell su -c "chown -R shell:shell /sdcard/.to_move" 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" # adb shell su -c "mv /sdcard/.to_move/$package $remotepackages"
printf "Correcting package\n" printf "Correcting package\n"
adb shell su -c "chown -R \"$userid:$groupid\" \"$remotepackages$package\"" 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\"" adb shell su -c "restorecon -R \"$remotepackages$package\""
printf "Package restored on device\n" printf "Package restored on device\n"
sleep 1 sleep 1
fi fi
fi
} || { } || {
echo "Error" echo "Error"
} }

View File

@ -1,19 +1,45 @@
#!/bin/bash #!/bin/bash -e
bashdir="$PWD" bashdir="$PWD"
outdir="work" outdir="work"
if [ -z "$1" ]
then
echo "You must supply the path of the .ab file"
exit 1
fi
abfile=$(readlink -f "$1") abfile=$(readlink -f "$1")
if [ -z "$abfile" ]
then
echo "You must supply the path of the .ab file"
exit 1
fi
mkdir -p "$outdir" mkdir -p "$outdir"
outdir=$(readlink -f "$outdir") outdir=$(readlink -f "$outdir")
mkdir -p "$outdir/ab_backup" 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" 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\"" #Delete extracted backup directory
echo "Please use that path for the next steps" 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"