Skip to content

Commit

Permalink
gen: add support for generating twrp flashable zips
Browse files Browse the repository at this point in the history
ghazzor committed May 29, 2024
1 parent be7c6c6 commit dafb304
Showing 4 changed files with 69 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nuke.sh
*.zip
nuke*.sh
20 changes: 19 additions & 1 deletion gen.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash

# File paths
WKDIR="$PWD"
DEBLOATED_PACKAGES_FILE="debloated_rom_packages"
PACKAGES_TO_REMOVE_FILE="packages_to_remove"
STOCK_PACKAGES_FILE="stock_rom_packages"
REMOVE_SCRIPT="nuke.sh"
PACKAGE_DIR="package"
REMOVE_SCRIPT_TWRP="$PACKAGE_DIR/nuke_twrp.sh"
PACKAGES_TO_REPLACE_FILE="packages_to_replace"

# Source the blacklist definitions
@@ -33,7 +36,7 @@ is_blacklisted_dir() {
}

# Clean up previous files
rm -rf $REMOVE_SCRIPT $PACKAGES_TO_REMOVE_FILE $PACKAGES_TO_REPLACE_FILE
rm -rf $REMOVE_SCRIPT $PACKAGES_TO_REMOVE_FILE $PACKAGES_TO_REPLACE_FILE $REMOVE_SCRIPT_TWRP $PACKAGE_DIR/twrpdblt*.zip

# Get the list of installed packages from the stock phone
if [ "$SPG" = "1" ]; then
@@ -54,6 +57,9 @@ fi
cat << 'EOF' > $REMOVE_SCRIPT
#!/system/bin/sh
echo 'GENERATED BY universal-debloat-script-generator'
echo 'AUTHOR : @ghzzor (github)'
echo ' '
echo 'WARNING: This script will remove packages from your device.'
echo ' I am not responsible for bricked devices.'
echo ' Ensure you have backed up your data.'
@@ -82,22 +88,26 @@ EOF

# Add commands to remove packages to the script
echo 'packages_to_nuke=(' >> $REMOVE_SCRIPT
echo 'packages_to_nuke=(' >> $REMOVE_SCRIPT_TWRP

while IFS= read -r package_path; do
if [[ -n "$package_path" ]] && ! is_blacklisted_apk "$package_path" && ! is_blacklisted_dir "$package_path"; then
if [[ $package_path == /system/* ]]; then
echo "$package_path" >> $PACKAGES_TO_REPLACE_FILE
echo "\"\$systempath$package_path\"" >> $REMOVE_SCRIPT
echo "\"/system_root$package_path\"" >> $REMOVE_SCRIPT_TWRP
else
echo "/system$package_path" >> $PACKAGES_TO_REPLACE_FILE
echo "\"$package_path\"" >> $REMOVE_SCRIPT
echo "\"$package_path\"" >> $REMOVE_SCRIPT_TWRP
fi
fi


done < $PACKAGES_TO_REMOVE_FILE

echo ')' >> $REMOVE_SCRIPT
echo ')' >> $REMOVE_SCRIPT_TWRP
cat << 'EOF' >> $REMOVE_SCRIPT
for bloat in "${packages_to_nuke[@]}"; do
@@ -117,3 +127,11 @@ echo "$PACKAGES_TO_REPLACE_FILE has been generated."
chmod +x $REMOVE_SCRIPT

echo "$REMOVE_SCRIPT has been generated."
echo "$REMOVE_SCRIPT_TWRP has been generated."

export TIME="$(date "+%Y%m%d")"
cd $PACKAGE_DIR
zip -r9 twrpdblt-${TIME}.zip * -x .git README.md *placeholder
cd $WKDIR

echo "twrpdblt-${TIME}.zip has been generated."
47 changes: 47 additions & 0 deletions package/META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/sbin/sh

OUTFD=$2
ZIP=$3

ui_print() {
echo -n -e "ui_print $1\n" > /proc/self/fd/$OUTFD
echo -n -e "ui_print\n" > /proc/self/fd/$OUTFD
}

cd /tmp
rm -rf tmpdir
mkdir tmpdir
cd tmpdir
unzip -o "$ZIP"

zipdir=/tmp/tmpdir

echo 'GENERATED BY universal-debloat-script-generator'
echo 'AUTHOR : @ghzzor (github)'
echo ' '
echo 'WARNING: This script will remove packages from your device.'
echo ' I am not responsible for bricked devices.'
echo ' Ensure you have backed up your data.'
echo ' '

# mount stuff
mount /system_root
mount /product
mount /prism

mount -o rw,remount -t auto /system_root
mount -o rw,remount -t auto /product
mount -o rw,remount -t auto /prism

# source the package list
. $zipdir/nuke_twrp.sh

# Remove bloat if it exists
for bloat in "${packages_to_nuke[@]}"; do
if [ -e "$bloat" ]; then
rm -rf "$bloat"
ui_print "Removed $bloat"
else
ui_print "Skipping $bloat (NOT FOUND)"
fi
done
1 change: 1 addition & 0 deletions package/META-INF/com/google/android/updater-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# this is a dummy file, the magic is in update-binary, which is a shell script

0 comments on commit dafb304

Please sign in to comment.