Skip to content

Commit

Permalink
Update script (#1)
Browse files Browse the repository at this point in the history
* update script

* update readme

* update addon.d script to v3
  • Loading branch information
2shrestha22 authored Dec 22, 2022
1 parent 3fbbd5c commit 9af2576
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 43 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "bashdb",
"request": "launch",
"name": "Bash-Debug (simplest configuration)",
"program": "${file}"
}
]
}
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,20 @@ Align the APK.
* After all the files have been copied, reboot the device:
`adb reboot`

### Installation with Flashable zip (not tested/recommended)
### Installation with Flashable zip
* Create zip:
`7za a -tzip -r lineage-dialer-rro.zip ./flashable/*`

* Sign:
`java -jar ./bin/zipsigner.jar lineage-dialer-rro.zip lineage-dialer-rro-signed.zip`

* Reboot to sideload mode:
`adb reboot sideload`

* Sideload zip:
`adb sideload lineage-dialer-rro-signed.zip`

## Resources:
update-binary: https://github.com/arovlad/bromite-webview-overlay
update-binary: MindTheGapps (http://downloads.codefi.re/jdcteam/javelinanddart/gapps)

zip-signer: https://forum.xda-developers.com/t/dev-template-complete-shell-script-flashable-zip-replacement-signing-script.2934449/
zipsigner: https://github.com/topjohnwu/Magisk/tree/v20.4/signing, https://forum.xda-developers.com/t/dev-template-complete-shell-script-flashable-zip-replacement-signing-script.2934449/
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
7za a -tzip -r lineage-dialer-rro.zip ./flashable/*
java -jar ./bin/zipsigner.jar lineage-dialer-rro.zip lineage-dialer-rro-signed.zip
201 changes: 170 additions & 31 deletions flashable/META-INF/com/google/android/update-binary
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,46 +1,185 @@
#!/sbin/sh

# Exit immediately if the device is not Treble-enabled
if [ ! $(getprop ro.treble.enabled) ]
then echo -e "ui_print Your device is not Treble-enabled!" >> /proc/self/fd/${2}
exit 1
# SCRIPT FROM MINDTHEGAPPS FLASHABLE ZIP

OUTFD="/proc/self/fd/$2"
ZIP=$3

set_con() {
chcon -h u:object_r:"$1":s0 $2
chcon u:object_r:"$1":s0 $2
}

set_perm() {
chmod $1 $2
}

set_owner() {
chown $1:$2 $3
}

ui_print() {
echo "ui_print $1" > "$OUTFD";
echo "ui_print" > "$OUTFD";
}

cleanup() {
ui_print "Cleaning up files"
rm -rf $TMP/system
rm -rf $TMP/bin

ui_print "Unmounting partitions"
umount -l "$SYSTEM_MNT"
umount -l /vendor || true
}

error() {
ui_print "$1"
cleanup
exit 1
}

error_mounting() {
error "Could not mount $1! Aborting"
}

get_block_for_mount_point() {
grep -v "^#" /etc/recovery.fstab | grep "[[:blank:]]$1[[:blank:]]" | tail -n1 | tr -s [:blank:] ' ' | cut -d' ' -f1
}

find_block() {
local name="$1"
local fstab_entry=$(get_block_for_mount_point "/$name")
# P-SAR hacks
[ -z "$fstab_entry" ] && [ "$name" = "system" ] && fstab_entry=$(get_block_for_mount_point "/")
[ -z "$fstab_entry" ] && [ "$name" = "system" ] && fstab_entry=$(get_block_for_mount_point "/system_root")

local dev
if [ "$DYNAMIC_PARTITIONS" = "true" ]; then
if [ -n "$fstab_entry" ]; then
dev="${BLK_PATH}/${fstab_entry}${SLOT_SUFFIX}"
else
dev="${BLK_PATH}/${name}${SLOT_SUFFIX}"
fi
else
if [ -n "$fstab_entry" ]; then
dev="${fstab_entry}${SLOT_SUFFIX}"
else
dev="${BLK_PATH}/${name}${SLOT_SUFFIX}"
fi
fi

if [ -b "$dev" ]; then
echo "$dev"
fi
}


ui_print "****************************"
ui_print "Lineage Dialer RRO installer"
ui_print "****************************"

ui_print "Extracting files"
TMP=/tmp
cd "$TMP" || exit 1
unzip -o "$ZIP"
rm -rf META-INF

ui_print "Mounting partitions"

# Ensure system is unmounted so mounting succeeds
umount /system || umount /mnt/system || true
umount /vendor || true

# Find partitions
DYNAMIC_PARTITIONS=$(getprop ro.boot.dynamic_partitions)
if [ "$DYNAMIC_PARTITIONS" = "true" ]; then
BLK_PATH="/dev/block/mapper"
else
BLK_PATH=/dev/block/bootdevice/by-name
fi

# Exit immediately if a command fails
set -e
CURRENTSLOT=$(getprop ro.boot.slot_suffix)
if [ ! -z "$CURRENTSLOT" ]; then
if [ "$CURRENTSLOT" == "_a" ]; then
SLOT_SUFFIX="_a"
else
SLOT_SUFFIX="_b"
fi
fi

# Extract the package to a temporary location
unzip -oq ${3} -d "/tmp/LineageDialerRRO"
SYSTEM_BLOCK=$(find_block "system")
VENDOR_BLOCK=$(find_block "vendor")

# Create faux mountpoints
mkdir /picodroid_system
mkdir /picodroid_vendor
# Disable rw protection on dynamic partitions
if [ "$DYNAMIC_PARTITIONS" = "true" ]; then
blockdev --setrw "$SYSTEM_BLOCK"
if [ -n "$VENDOR_BLOCK" ]; then
blockdev --setrw "$VENDOR_BLOCK"
fi
fi

# Mount and define SYSTEM_OUT
SYSTEM_MNT=/mnt/system
mkdir -p "$SYSTEM_MNT" || true
if mount -o rw "$SYSTEM_BLOCK" "$SYSTEM_MNT"; then
ui_print "$SYSTEM_MNT mounted"
else
error_mounting "$SYSTEM_MNT"
fi
# System out is actual /system when devices is booted,
# while or recovery it can be /mnt/system/system, so the file structure look like
# /mnt/system/system -> /system
# /mnt/system/system/bin -> /system/bin
# /mnt/system/vendor -> /vendor

# Mount the neccesary partitions
mount -o rw $(readlink -f $(cd /dev && find /dev/block -type l -name system$(getprop ro.boot.slot_suffix) | head -n 1 )) /picodroid_system
mount -o rw $(readlink -f $(cd /dev && find /dev/block -type l -name vendor$(getprop ro.boot.slot_suffix) | head -n 1 )) /picodroid_vendor
SYSTEM_OUT="${SYSTEM_MNT}/system"

# Copy the overlay to the appropriate location
cp /tmp/LineageDialerRRO/vendor/overlay/lineage-dialer-rro.apk /picodroid_vendor/overlay
# Ignore {vendor} block devices in case they are symlinks
# This is common on devices where maintainers have chosen not to use
# real partitions because of their size being too small to be useful
if [ -L "${SYSTEM_MNT}/vendor" ]; then
VENDOR_BLOCK=""
fi

# Copy the OTA survival script to the appropriate location
if [ -d /picodroid_system/system/addon.d ]
then cp /tmp/LineageDialerRRO/system/addon.d/99-lineage-dialer-rro.sh /picodroid_system/system/addon.d
if [ -n "$VENDOR_BLOCK" ]; then
mkdir /vendor || true
if mount -o rw "$VENDOR_BLOCK" /vendor; then
ui_print "/vendor mounted"
else
error_mounting "/vendor"
fi
fi

# Make the script executable
chmod 755 /picodroid_system/system/addon.d/99-lineage-dialer-rro.sh
# Enter inside Flashable system.
cd system || exit 1

ui_print "Preparing files for copying"
# Set correct permission for dirs
for d in $(find . -mindepth 1 -type d -type d); do
set_perm 0755 $d
set_owner root root $d
done
# Set correct permission for files
for f in $(find . -type f); do
type=$(echo "$f" | sed 's/.*\.//')
if [ "$type" == "sh" ] || [ "$type" == "$f" ]; then
set_perm 0755 $f
else
set_perm 0644 $f
fi
set_owner root root $f
set_con system_file $f
done

# Unmount the previously mounted partitions
umount -l /picodroid_system
umount -l /picodroid_vendor
ui_print "Copying files"
cp --preserve=a -r ./* "${SYSTEM_OUT}/"
if [ -n "$VENDOR_BLOCK" ]; then
cp --preserve=a -r ./vendor/* /vendor
fi

# Delete de faux mountpoints
rmdir /picodroid_system
rmdir /picodroid_vendor

# Clean up the installation files
rm -rf /tmp/LineageDialerRRO
cleanup

# Inform the user that the update has been successful
echo -e "ui_print Update successfully installed!" >> /proc/self/fd/${2}
ui_print "Done!"
exit 0
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#!/sbin/sh
#
# ADDOND_VERSION=2
# ADDOND_VERSION=3
#
# /system/addon.d/99-lineage-dialer-rro.sh
# During a LineageOS upgrade, this script backs up /vendor/overlay/lineage-dialer-rro.apk,
# /system is formatted and reinstalled, then the file is restored.
# /system/addon.d/20-lineage-dialer-rro.sh
#
# Copied from 50-lineage.sh

. /tmp/backuptool.functions

list_files() {
Expand All @@ -19,14 +15,14 @@ EOF
case "$1" in
backup)
list_files | while read FILE DUMMY; do
backup_file $S/"$FILE"
backup_file $S/$FILE
done
;;
restore)
list_files | while read FILE REPLACEMENT; do
R=""
[ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
[ -f "$C/$S/$FILE" ] && restore_file $S/"$FILE" "$R"
[ -f "$C/$S/$FILE" ] && restore_file $S/$FILE $R
done
;;
pre-backup)
Expand All @@ -39,6 +35,11 @@ case "$1" in
# Stub
;;
post-restore)
# Stub
for i in $(list_files); do
f=$(get_output_path "$S/$i")
chown root:root $f
chmod 644 $f
chmod 755 $(dirname $f)
done
;;
esac

0 comments on commit 9af2576

Please sign in to comment.