Skip to content

Instantly share code, notes, and snippets.

@utkustnr
Last active May 13, 2025 22:42
Show Gist options
  • Select an option

  • Save utkustnr/8bd6cd7a48846d34c959424558be4ae1 to your computer and use it in GitHub Desktop.

Select an option

Save utkustnr/8bd6cd7a48846d34c959424558be4ae1 to your computer and use it in GitHub Desktop.
Generic Kernel Installer Script for Samsung
#!/sbin/sh
# Shell Script EDIFY Replacement: Recovery Flashable Zip
# osm0sis @ XDAdevelopers
# salvogiangri @ XDAdevelopers
# Frax3r @ XDAdevelopers
OUTFD=/proc/self/fd/$2;
ZIPFILE="$3";
TMPDIR="/cache/lux";
package_extract_dir() {
local entry outfile;
for entry in $(unzip -l "$ZIPFILE" 2>/dev/null | tail -n+4 | grep -v '/$' | grep -o " $1.*$" | cut -c2-); do
outfile="$(echo "$entry" | sed "s|${1}|${2}|")";
mkdir -p "$(dirname "$outfile")";
unzip -o "$ZIPFILE" "$entry" -p > "$outfile";
done;
}
ui_print() {
while [ "$1" ]; do
echo -e "ui_print $1
ui_print" >> $OUTFD;
shift;
done;
}
set_metadata() {
local file i;
file="$1";
shift;
while [ "$2" ]; do
case $1 in
uid) chown $2 "$file";;
gid) chown :$2 "$file";;
mode) chmod $2 "$file";;
selabel)
for i in /system/bin/toybox /system/toolbox /system/bin/toolbox; do
(LD_LIBRARY_PATH=/system/lib64 $i chcon -h $2 "$file" || LD_LIBRARY_PATH=/system/lib64 $i chcon $2 "$file") 2>/dev/null;
done || chcon -h $2 "$file" || chcon $2 "$file";
;;
*) ;;
esac;
shift 2;
done;
}
set_metadata_recursive() {
local dir i;
dir="$1";
shift;
while [ "$2" ]; do
case $1 in
uid) chown -R $2 "$dir";;
gid) chown -R :$2 "$dir";;
dmode) find "$dir" -type d -exec chmod $2 {} +;;
fmode) find "$dir" -type f -exec chmod $2 {} +;;
selabel)
for i in /system/bin/toybox /system/toolbox /system/bin/toolbox; do
(find "$dir" -exec LD_LIBRARY_PATH=/system/lib64 $i chcon -h $2 {} + || find "$dir" -exec LD_LIBRARY_PATH=/system/lib64 $i chcon $2 {} +) 2>/dev/null;
done || find "$dir" -exec chcon -h $2 '{}' + || find "$dir" -exec chcon $2 '{}' +;
;;
*) ;;
esac;
shift 2;
done;
}
is_mounted() { mount | grep -qE "$1"; }
write_raw_image() { dd if="$1" of="$2"; }
set_progress() { echo "set_progress $1" >> $OUTFD; }
ui_print " ";
ui_print "********************************************";
ui_print " Generic Kernel Installer ";
ui_print " by Frax3r ";
ui_print " ";
ui_print " Presenting LUX & RIO... ";
ui_print "********************************************";
ui_print " ";
set_progress 0
if ! getprop ro.boot.bootloader | grep -qE "A736|A528|M526"; then
ui_print "- Device is not an A73, A52s or M52, aborting...";
exit 1;
fi
ui_print "- Extracting images";
mount -o rw,remount -t auto "/cache";
mkdir -p $TMPDIR;
package_extract_dir "images" "$TMPDIR/";
set_progress 10;
ui_print "- Flashing boot.img...";
write_raw_image "$TMPDIR/boot.img" "/dev/block/bootdevice/by-name/boot";
set_progress 20;
ui_print "- Flashing dtbo.img...";
write_raw_image "$TMPDIR/dtbo.img" "/dev/block/bootdevice/by-name/dtbo";
set_progress 30;
ui_print "- Flashing vendor_boot.img...";
write_raw_image "$TMPDIR/vendor_boot.img" "/dev/block/bootdevice/by-name/vendor_boot";
set_progress 40;
ui_print "- Mounting /vendor...";
if is_mounted vendor; then umount /vendor; fi
mount -o rw /dev/block/mapper/vendor /vendor;
set_progress 50;
ui_print "- Checking if modules can be extracted...";
if ! is_mounted vendor || is_mounted 'vendor.*(erofs|f2fs)'; then
ui_print "- Read-Only filesystem detected, skipping...";
set_progress 80;
else
ui_print "- Read-Write filesystem detected, proceeding...";
set_progress 60;
[ -f /vendor/bin/install-recovery.sh ] && rm -f "/vendor/bin/install-recovery.sh";
[ -f /vendor/etc/init/vendor_flash_recovery.rc ] && rm -f "/vendor/etc/init/vendor_flash_recovery.rc";
[ -f /vendor/recovery-from-boot.p ] && rm -f "/vendor/recovery-from-boot.p";
[ -f /vendor/bin/vendor_modprobe.sh ] && rm -f "/vendor/bin/vendor_modprobe.sh";
rm -rf /vendor/lib/modules/*;
ui_print "- Extracting...";
package_extract_dir "vendor" "/vendor";
set_metadata "/vendor/bin/vendor_modprobe.sh" uid "0" gid "2000" mode "0755" selabel "u:object_r:vendor_modinstall-sh_exec:s0";
for file in /vendor/lib/modules/*; do
set_metadata $file uid "0" gid "0" mode "0644" selabel "u:object_r:vendor_file:s0";
done;
set_progress 80;
fi
ui_print "- Cleaning up...";
rm -rf "$TMPDIR";
umount /vendor;
set_progress 100;
ui_print " ";
ui_print "********************************************";
ui_print " Flashing completed. ";
ui_print " Make sure to check the UN1CA project. ";
ui_print " Special Thanks to Salvogiangri ";
ui_print " And Simon1511 ";
ui_print "********************************************";
ui_print " ";
#! /vendor/bin/sh
#=============================================================================
# Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
#=============================================================================
MODULES_PATH="/vendor/lib/modules/"
MODPROBE="/vendor/bin/modprobe"
MODULES=`${MODPROBE} -d ${MODULES_PATH} -l`
# Iterate over module list and modprobe them in background.
for MODULE in ${MODULES}; do
${MODPROBE} -a -b -d ${MODULES_PATH} ${MODULE} &
done
# Wait until all the modprobes are finished
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment