diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..70ff6d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.xz \ No newline at end of file diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary new file mode 100755 index 0000000..3458b4c --- /dev/null +++ b/META-INF/com/google/android/update-binary @@ -0,0 +1,118 @@ +#!/sbin/sh +# OpenSUSE GSI Backend +# Based on ubports GSI script by erfanoabdi @ xda-developers + +OUTFD=/proc/self/fd/$2; +ZIP="$3"; +DIR=`dirname "$ZIP"`; + +should_mount() { + if cat /proc/mounts | awk '{ print $2 }' | grep -q "^$1\$"; then + # Already mounted + return 1; + else + # Should mount! + return 0; + fi +} + +mount_vendor(){ + # detect vendor partition based on current boot slot for treble devices + current_slot=$(grep -o 'androidboot\.slot_suffix=_[a-b]' /proc/cmdline) + case "${current_slot}" in + "androidboot.slot_suffix=_a") + target_partition="vendor_a" + ;; + "androidboot.slot_suffix=_b") + target_partition="vendor_b" + ;; + "") + # No A/B + target_partition="vendor" + ;; + *) + error "Unknown error while searching for a vendor partition, exiting" + ;; + esac + + partition=$(find /dev/block/platform -name ${target_partition} | head -n 1) + if [ -n "${partition}" ]; then + ui_print "Found vendor partition for current slot ${partition}" + + # mount vendor partition + mount -o ro ${partition} /vendor + + ui_print "Vendor mounted" + fi +} + +ui_print() { + until [ ! "$1" ]; do + echo -e "ui_print $1\nui_print" > $OUTFD; + shift; + done; +} + +show_progress() { echo "progress $1 $2" > $OUTFD; } +set_perm_recursive() { + dirs=$(echo $* | $bb awk '{ print substr($0, index($0,$5)) }'); + for i in $dirs; do + chown -R $1.$2 $i; chown -R $1:$2 $i; + find "$i" -type d -exec chmod $3 {} +; + find "$i" -type f -exec chmod $4 {} +; + done; +} + +abort() { ui_print "$*"; umount /vendor; umount /data; exit 1; } + +show_progress 1.34 4; +ui_print " "; +ui_print "***"; +ui_print "OpenSUSE GSI installer"; +ui_print "***"; +ui_print " "; +ui_print " "; + +# mount vendor and data +if should_mount /vendor; then + mount_vendor; + vendor_mounted="yes"; +fi; + +if should_mount /data; then + mount /data; + data_mounted="yes"; +fi; + +# create tmp directory +mkdir -p /data/opensuse; +cd /data/opensuse; + +# unzip busybox and rootfs +ui_print "Installing GSI..."; +unzip -o "$ZIP"; + +if [ $? != 0 -o -z "$(ls /data/opensuse/tools)" ]; then + abort "Unzip failed. Aborting..."; +fi; + +# set busybox permissions +chmod -R 755 /data/opensuse/tools +bb=/data/opensuse/tools/busybox; + +# run setup.sh on busybox's ash +$bb ash /data/opensuse/setup.sh $2; +if [ $? != "0" ]; then + abort; +fi; + +# delete tmp directory +rm -rf /data/opensuse; + +# umount vendor and data +[ "$vendor_mounted" == "yes" ] && umount /vendor; +[ "$data_mounted" == "yes" ] && umount /data; + +ui_print " "; +ui_print "Done!"; + diff --git a/META-INF/com/google/android/updater-script b/META-INF/com/google/android/updater-script new file mode 100755 index 0000000..8582673 --- /dev/null +++ b/META-INF/com/google/android/updater-script @@ -0,0 +1 @@ +# Dummy file; update-binary is a shell script. diff --git a/data/placeholder b/data/placeholder new file mode 100644 index 0000000..e69de29 diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..7232699 --- /dev/null +++ b/setup.sh @@ -0,0 +1,107 @@ +# OpenSUSE GSI installer Script + +OUTFD=/proc/self/fd/$1; +VENDOR_DEVICE_PROP=`grep ro.product.vendor.device /vendor/build.prop | cut -d "=" -f 2 | awk '{print tolower($0)}'`; + +# ui_print +ui_print() { echo -e "ui_print $1\nui_print" > $OUTFD; } + +## GSI install +mkdir -p /data/halium-rootfs +/data/opensuse/tools/busybox tar -xJf /data/opensuse/data/*.tar.xz -C /data/halium-rootfs/ + +mkdir /s; + +# mount android gsi +mount /data/halium-rootfs/var/lib/lxc/android/android-rootfs.img /s + +# Set udev rules +ui_print "Setting udev rules"; +cat /s/ueventd*.rc /vendor/ueventd*.rc | grep ^/dev | sed -e 's/^\/dev\///' | awk '{printf "ACTION==\"add\", KERNEL==\"%s\", OWNER=\"%s\", GROUP=\"%s\", MODE=\"%s\"\n",$1,$3,$4,$2}' | sed -e 's/\r//' > /data/halium-rootfs/etc/udev/rules.d/70-$VENDOR_DEVICE_PROP.rules; + +# umount android gsi +umount /s; + +# If we should flash the kernel, do it +if [ -e "/data/halium-rootfs/boot/boot.img" ]; then + ui_print "Kernel found, flashing" + + if [ -e "/data/halium-rootfs/boot/dtbo.img" ]; then + has_dtbo="yes" + else + has_dtbo="no" + fi + + if [ -e "/data/halium-rootfs/boot/vbmeta.img" ]; then + has_vbmeta="yes" + else + has_vbmeta="no" + fi + + current_slot=$(grep -o 'androidboot\.slot_suffix=_[a-b]' /proc/cmdline) + case "${current_slot}" in + "androidboot.slot_suffix=_a") + target_partition="boot_a" + target_dtbo_partition="dtbo_a" + target_vbmeta_partition="vbmeta_a" + ;; + "androidboot.slot_suffix=_b") + target_partition="boot_b" + target_dtbo_partition="dtbo_b" + target_vbmeta_partition="vbmeta_b" + ;; + "") + # No A/B + target_partition="boot" + target_dtbo_partition="dtbo" + target_vbmeta_partition="vbmeta" + ;; + *) + error "Unknown error while searching for a boot partition, exiting" + ;; + esac + + partition=$(find /dev/block/platform -name ${target_partition} | head -n 1) + if [ -n "${partition}" ]; then + ui_print "Found boot partition for current slot ${partition}" + + dd if=/data/halium-rootfs/boot/boot.img of=${partition} || error "Unable to flash kernel" + + ui_print "Kernel flashed" + fi + + if [ "${has_dtbo}" = "yes" ]; then + ui_print "DTBO found, flashing" + + partition=$(find /dev/block/platform -name ${target_dtbo_partition} | head -n 1) + if [ -n "${partition}" ]; then + ui_print "Found DTBO partition for current slot ${partition}" + + dd if=/data/halium-rootfs/boot/dtbo.img of=${partition} || error "Unable to flash DTBO" + + ui_print "DTBO flashed" + fi + fi + + if [ "${has_vbmeta}" = "yes" ]; then + ui_print "VBMETA found, flashing" + + partition=$(find /dev/block/platform -name ${target_vbmeta_partition} | head -n 1) + if [ -n "${partition}" ]; then + ui_print "Found VBMETA partition ${partition}" + + dd if=/data/halium-rootfs/boot/vbmeta.img of=${partition} || error "Unable to flash VBMETA" + + ui_print "VBMETA flashed" + fi + fi + +fi + +# halium initramfs workaround, +# create symlink to android-rootfs inside /data +if [ ! -e /data/android-rootfs.img ]; then + ln -s /halium-system/var/lib/lxc/android/android-rootfs.img /data/android-rootfs.img || true +fi + +## end install diff --git a/tools/busybox b/tools/busybox new file mode 100644 index 0000000..b7bbfc4 Binary files /dev/null and b/tools/busybox differ