[HD2 Android NAND Development] HypoTurtle:
Annotated code (part 2) ...

mkdirs() {
[COLOR="red"]### Directories made ###
[/COLOR]busybox printf "%b\n" "creating directories"
mkdir -p /NativeSD 2> /dev/null
mkdir -p /DirectSD 2> /dev/null
mkdir -p /boot_dir 2> /dev/null
mkdir -p /boot 2> /dev/null
mkdir -p /system 2> /dev/null
mkdir -p /data 2> /dev/null
mkdir -p /cache 2> /dev/null
mkdir -p /sdcard/NativeSD/"${2}"_"${1}" 2> /dev/null
}
mountpart() {
[COLOR="red"]### Mounting partitions and files ###
[/COLOR]busybox printf "%s\n" "mounting files"
sdmounted=` mount | grep "${sdpart} on /sdcard" `
sdfile=` ls -la | grep "sdcard" `
if [ -z "${sdmounted:-$sdfile}" ]; then
mount -t auto ${sdpart} /sdcard
fi
if [ ${mountedalready:-nope} = "nope" ]; then
mount --bind /sdcard/NativeSD /boot_dir
mount --bind /sdcard/NativeSD/${2}_${1} /boot
mountedalready=yes
fi
if echo ${1} | grep -q porta; then
if [ ${loopdevready:-not} = "yes" ]; then
echo "loops ready to mount: ${loopdevready}"
mount ${firstpart} /system
mount ${secondpart} /data
mount ${thirdpart} /cache
printf "#!/sbin/sh\nlosetup -d ${firstpart}\nlosetup -d ${secondpart}\nlosetup -d ${thirdpart}\n" > /tmp/umountloop.sh
fi
else
if [ -b "${firstpart}" ]; then
mount -t auto ${firstpart} /NativeSD
if [ ${1} = "NativeSD" -o ${1} = "DataOnExt" ]; then
mkdir -p /NativeSD/${2}/data 2> /dev/null
mount --bind /NativeSD/${3}/data /data
fi
if [ ${install_type} -gt '2' ]; then
mkdir -p /NativeSD/${2}/system 2> /dev/null
mount --bind /NativeSD/${2}/system /system
fi
fi
if [ -b "${secondpart}" ]; then
mount -t auto ${secondpart} /DirectSD
if [ ${1} = "DirectSD" ]; then
mkdir -p /DirectSD/${3}/data > /dev/null
mount --bind /DirectSD/${3}/data /data
fi
fi
fi
}
bootorig() {
busybox printf "%b\n" "saving original boot.img to boot-orig folder"
mkdir /boot_dir/boot-orig/
#chmod 0777 /tmp/dump_image
cd /tmp
./dump_image boot /boot/boot-orig/boot.img
cd /
}
systeminstall() {
[COLOR="red"]### ROM zip being read though and items extracted as required ###
[/COLOR]#cp /tmp/inc.lst inc.lst > /dev/null
#cp /tmp/exc.lst exc.lst > /dev/null
local romzip=` ls /sdcard/${2}*.zip | head -n1 `
printf "Reading ${romzip}\n"
cd /
# rm -rf /system/*
if [ ${alreadyran:-no} = "no" ]; then
printf "ROM zip is found at ... ${romzip}\nDuplicating so the original remains untouched\nThis may take a while ...\n"
cp -rf ${romzip} /sdcard/${2}_${1}.zip
alreadran=y
if echo ${type} | grep -q porta; then
echo "creating system, data and cache blocks on /sdcard first"
romsize=$((` /tmp/7za l /sdcard/${2}_${1}.zip | busybox tail -1 | busybox awk '{print $(NF-5)}' `/4096))
fls=` cat /sdcard/porta.txt | busybox cut -d " " -f "1" `
if [ ${5} = "y" ]; then
umount /system
losetup -d /dev/block/loop1
rm -rf /sdcard/NativeSD/${2}_${1}/system.${fls:-ext4}
fi
mntstuff "$@"
mt1=` blkid /sdcard/NativeSD/${2}_${1}/system.${fls:-ext4} | cut -d '"' -f '4' `
mt2=` blkid /sdcard/NativeSD/${2}_${1}/data.${fls:-ext4} | cut -d '"' -f '4' `
fi
fi
chmod 0777 /tmp/7za
local systemlocat=` mount | grep /system | busybox cut -d ' ' -f '1' `
local datalocat=` mount | grep /data | busybox cut -d ' ' -f '1' `
printf "system mounted at ... ${systemlocat}\ndata mounted at ... ${datalocat}\n"
if [ -n "$systemlocat" ]; then
echo META-INF/*aroma* > exc.lst
printf "initrd.gz\nzImage\nboot.img\n" > inc.lst
bootstuff=done
###### Including haret stuff ###
if [ ${bootloader} = "haret" ]; then
printf "haret.exe\nclrcad.exe\n" >> inc.lst
fi
/tmp/7za x /sdcard/${2}_${1}.zip META-INF '-xr@exc.lst' -o/tmp2 -y > /dev/null
/tmp/7za x /sdcard/${2}_${1}.zip '-ir@inc.lst' -o/inc -y > /dev/null
if [ ${5} = "y" ]; then
echo "installing system"
/tmp/7za x /sdcard/${2}_${1}.zip data -o/ -y > /dev/null
/tmp/7za x /sdcard/${2}_${1}.zip system -o/ -y > /dev/null
fi
local ubi=` find /tmp2 -name update-binary-installer -print0 `
local ub=` find /tmp2 -name update-binary -print0 `
local ups=` find /tmp2 -name updater-script -print0 `
echo "UBI location is ${ubi:-$ub} UPS is ${ups}"
cp /${ubi:-$ub} /tmp2/META-INF/com/google/android/update-binary
printf "package_extract_file(\"multi\", \"/tmp/multi.sh\");\nset_perm(0, 0, 0777, \"/tmp/multi.sh\");\nrun_program(\"/tmp/multi.sh\", \"m\", \"${1}\", \"${2}\", \"${3}\");\n" > /tmp2/META-INF/com/google/android/updater-script2
if [ ${5} = "y" ]; then
cat /$ups | busybox sed -e '/^symlink/,/);/!d' >> /tmp2/META-INF/com/google/android/updater-script2
else
printf "package_extract_dir(\"system\", \"/system\");\npackage_extract_dir(\"data\", \"/data\");\n" >> /tmp2/META-INF/com/google/android/updater-script2
cat /$ups | busybox sed -e '/^symlink/,/);/!d' >> /tmp2/META-INF/com/google/android/updater-script2
fi
cat /$ups | busybox sed -e '/^set_perm/,/);/!d' >> /tmp2/META-INF/com/google/android/updater-script2
cat /$ups | busybox sed -e '/^setmetadata/,/);/!d' >> /tmp2/META-INF/com/google/android/updater-script2
echo "modifying updater-script"
printf "unmount (\"/NativeSD\");\nunmount (\"/DirectSD\");\nunmount (\"/DirectData\");\nunmount (\"/system\");\nunmount (\"/data\");\nunmount (\"/boot\");\nunmount (\"/boot_dir\");\n" >> /tmp2/META-INF/com/google/android/updater-script2
if echo ${1} | grep -q porta; then
cp /tmp/umountloop.sh /tmp2/umountloop.sh
printf "package_extract_file(\"umountloop.sh\", \"/tmp/umountloop.sh\");\nset_perm(0, 0, 0777, \"/tmp/multi.sh\");\nrun_program(\"/tmp/umountloop.sh\");\n" >> /tmp2/META-INF/com/google/android/updater-script2
fi
cp /tmp2/META-INF/com/google/android/updater-script2 /tmp2/META-INF/com/google/android/updater-script
rm /tmp2/META-INF/com/google/android/updater-script2; rm /tmp2/META-INF/com/google/android/updater-script~
dd if=$0 of=/tmp2/multi
/tmp/7za u /sdcard/${2}_${1}.zip /tmp2/* > /dev/null
else
if [ ${alreadyran:-no} != yes ]; then
alreadyran=yes
systeminstall "$@"
else
echo "system isn't mounted"
fi
fi
}
bootingred() {
[COLOR="red"]### Locating the initrd.gz and zImage that need to be modified/looked at ###
[/COLOR]busybox printf "%s\n" "obtaining an initrd.gz and zImage to work with"
local installsystem=` find /sdcard -name *.zip | grep ${2} `
if [ -n "${installsystem}" -a ${bootstuff:-notdone} = "notdone" ]; then
local romzip=` ls /sdcard/${2}*.zip | busybox head -n1 `
cp -rf ${romzip} /sdcard/${2}_${1}.zip
chmod 0777 /tmp/7za
printf "initrd.gz\nzImage\nboot.img\n" > inc.lst
/tmp/7za x /sdcard/${2}_${1}.zip '-ir@inc.lst' -o/inc -y
rm -rf /sdcard/${2}_${1}.zip
bootstuff=done
bootingred "$@"
###### Copying zImage and initrd.gz from /boot_dir when one wasn't in the zip
else
if [ ! -e "/tmp/boot.img" ]; then
nandinitrd=` find /inc -name initrd.gz -print0 | busybox xargs -0 ls -s | busybox sort -nr | busybox awk '{print $(NF)}' | busybox tail -n 1 `
zImagelocat=` find /inc -name zImage `
if [ -n "${zImagelocat}" ]; then
printf "%b\n" "zImage is at ... ${zImagelocat}"
cp ${zImagelocat} /tmp/zImage
fi
if [ -n "${nandinitrd}" ]; then
printf "%b\n" "nand ramdisk is at ... ${nandinitrd}"
cp ${nandinitrd} /tmp/initrd.gz
fi
else
chmod 0777 /tmp/unmkbootimg
cp /ramds/boot.img /tmp/boot.img
mkdir -p /tmp/boot 2> /dev/null
cd /tmp
./unmkbootimg /tmp/boot.img /tmp/boot
cd /
cp /tmp/boot/boot.img-ramdisk.gz /tmp/initrd.gz
cp /tmp/boot/boot.img-zImage /tmp/zImage
fi
fi
if [ ${runonce:-once} = "once" ]; then
if [ -f "/sdcard/zImage" ]; then
cp /sdcard/zImage /tmp/zImage
cp /sdcard/modules/* /system/lib/modules/ 2> /dev/null
fi
if [ -f "/sdcard/initrd.gz" ]; then
cp /sdcard/initrd.gz /tmp/initrd.gz
fi
local runonce=twice
if [ -f "/sdcard/useit/boot.img" ]; then
cp /sdcard/useit/boot.img /tmp/boot.img
bootstuff=done
bootingred "$@"
fi
fi
if [ ! -f "/tmp/initrd.gz" ]; then
echo "no ramdisk found to modify - Exitting"
busybox printf "%b\n" "Please flash ${2}_${1}.zip in recovery"
exit 0
fi
}
usecurrentboot() {
[COLOR="red"]### This is here to for example add DataOnExt to a cLK boot.img flashed in boot partition ###
[/COLOR]chmod 0777 /tmp/dump_image
cd /tmp
./dump_image boot /tmp/boot.img
./unpackbootimg /tmp/boot.img /tmp > /tmp/bootimg.txt
cd /
cp /tmp/boot.img-ramdisk.gz /tmp/initrd.gz
cp /tmp/boot.img-zImage /tmp/zImage
}
mkmountfsloop() {
### making the script that mounts the looped system (not currently working) ###
if [ ${type} = "porta-o" ]; then
printf "#!/bin/busybox sh\nwhile [ ! -b ${sdpart} ]; do\n/bin/busybox sleep 5\ndone\n/bin/busybox sleep 2\n/bin/e2fsck -p /sdcard/${ROM_NAME}_${type}/system.${fls:-ext4} > e2fsck.log\n/bin/e2fsck -p /sdcard/${ROM_NAME}_${type}/data.${fls:-ext4} >> e2fsck.log\n/bin/e2fsck -p /sdcard/${ROM_NAME}_${type}/cache.${fls:-ext4} >> e2fsck.log\nlosetup ${firstpart} /sdcard/${ROM_NAME}_${type}/system.${fls:-ext4}\nlosetup ${secondpart} /sdcard/${ROM_NAME}_${type}/data.${fls:-ext4}\nlosetup ${thirdpart} /sdcard/${ROM_NAME}_${type}/cache.${fls:-ext4}\n/bin/busybox mkdir /system\n/bin/busybox mkdir /data\n/bin/busybox mkdir /cache\n/bin/busybox mount -t auto -o rw,noatime,nodiratime,sync ${firstpart} /system\n/bin/busybox mount -t auto -o rw,noatime,nodiratime,sync ${secondpart} /data\n/bin/busybox mount -t auto ${thirdpart} /cache\n" > /tmp/mountfs-"${1}".sh
printf "#by KAI 25.11.2011 always dual mount\necho /dev/block/mmcblk0 > /sys/devices/platform/usb_mass_storage/lun0/file\n# move init files to /system\ninit_files=\"init.rc init.htcleo.rc bootcomplete.htcleo.rc shutdown.htcleo.rc default.prop ueventd.rc\"\nfor init_file in \$init_files; do\nif [ -f /\$init_file ]; then\ncp -a /\$init_file /system/\$init_file\nfi\nif [ -f /system/\$init_file ]; then\n[ -f /\$init_file ] && rm -f /\$init_file\nln -s /system/\$init_file /\$init_file\nfi\ndone\n#cleanup - delete /bin to free ram\n/bin/busybox rm -rf /bin\n" >> /tmp/mountfs-"${1}".sh
fi
}
mkmountfs() {
[COLOR="red"]### Making the mountfs.sh for the various install types ###
[/COLOR]busybox printf "%b\n" "creating mountfs.sh"
if [ ${4} -gt '1' ]; then
printf "#!/bin/busybox sh\nwhile [ ! -b ${firstpart} ]; do\n/bin/busybox sleep 5\ndone\n/bin/busybox sleep 2\n" > /tmp/mountfs-"${1}".sh
if [ ${1} = DirectSD ]; then
echo "Modifying for ${type}"
printf "while [ ! -b ${secondpart} ]; do\n/bin/busybox sleep 5\ndone\n/bin/busybox sleep 2\n" >> /tmp/mountfs-"${1}".sh
fi
[COLOR="red"]### This looks for the partition type (defaulting to ext4) ###
[/COLOR] mt1=` blkid ${firstpart} | cut -d '"' -f '4' `
mt2="${mt1}"
if [ ${mt1:-f2fs} = ext4 ]; then
printf "# check the first ext4 fs\n/bin/e2fsck -p ${firstpart} > /e2fsck.log\n" >> /tmp/mountfs-"${1}".sh
else
printf "# check the first f2fs fs\n/bin/fsck.f2fs -p ${firstpart} > /fsckf2fs.log\n" >> /tmp/mountfs-"${1}".sh
fi
if [ ${1} = DirectSD ]; then
if [ -b ${secondpart} ]; then
mt2=` blkid ${secondpart} | busybox cut -d '"' -f '4' `
else
echo "No 2nd ext partition present, format one and run script again"
fi
if [ ${mt2:-f2fs} = ext4 ]; then
printf "# check the second ext4 fs\n/bin/e2fsck -p ${secondpart} > /e2fsck2.log\n" >> /tmp/mountfs-"${1}".sh
else
printf "# check the second f2fs fs\n/bin/fsck.f2fs -p ${secondpart} > /fsckf2fs2.log\n" >> /tmp/mountfs-"${1}".sh
fi
fi
printf "/bin/busybox mkdir -p /NativeSD\n/bin/busybox mount -t ${mt1:-f2fs} -o rw,noatime,nodiratime,barrier=0 ${firstpart} /NativeSD\n# mount the data dir\n" >> /tmp/mountfs-"${1}".sh
if [ ${1} = DataOnExt ]; then
echo "Modifying for ${1}"
printf "/bin/busybox mount --bind /NativeSD/${2}/data /data\n" >> /tmp/mountfs-"${1}".sh
fi
if [ ${4} -gt '2' ]; then
printf "/bin/busybox mount --bind /NativeSD/${2}/system /system\n" >> /tmp/mountfs-"${1}".sh
if [ ${1} = NativeSD ]; then
echo "Modifying for ${1}"
printf "/bin/busybox mount --bind /NativeSD/${3}/data /data\n" >> /tmp/mountfs-"${1}".sh
else
printf "/bin/busybox mkdir -p /DirectData\n/bin/busybox mount -t ${mt2:-f2fs} -o rw,noatime,nodiratime,nosuid,nodev,discard ${secondpart} /DirectData\n/bin/busybox mount --bind /DirectData/${3}/data /data\n" >> /tmp/mountfs-"${1}".sh
fi
fi
printf "%b\n" "##/system/bin/logcat -d -f /sdcard/logcat.log *:V\n# cleanup deleting /bin to free ram\n## /bin/busybox rm -rf /bin\n" >> /tmp/mountfs-"${1}".sh
fi
}
mkinitrd() {
[COLOR="red"]### Modifying the initrd.gz for the chosen install type (adding the mountfs.sh made above) ###
[/COLOR]busybox printf "%b\n" "modifying ramdisk"
###### Setting up working directory
#cp /tmp/initrd.gz /tmp/initrd_"${2}".gz
mkdir -p /tmp/work
cd /tmp/work
cp /tmp/initrd.gz /tmp/initrd_o.gz
[COLOR="red"]### Unzipping nand kernel ###
[/COLOR]gzip -d -c ../initrd.gz | busybox cpio -i -d
if [ ! -d bin ]; then
mkdir bin
fi
cp /tmp/busybox /tmp/work/bin/busybox
cp /tmp/e2fsck /tmp/work/bin/e2fsck
cp /tmp/mountfs-${1}.sh /tmp/work/mountfs-${1}.sh

if [ ${mt1:-f2fs} = f2fs -o ${mt2:-f2fs} = f2fs ]; then
busybox printf "%b\n" "copying fsck for f2fs"
cp /tmp/mkfs.f2fs /tmp/work/bin/mkfs.f2fs ; cp /tmp/mkfs.f2fs /system/bin/mkfs.f2fs
cp /tmp/fsck.f2fs /tmp/work/bin/fsck.f2fs ; cp /tmp/fsck.f2fs /system/bin/fsck.f2fs
chmod 0777 /tmp/work/bin/mkfs.f2fs; chmod 0777 /system/bin/mkfs.f2fs
chmod 0777 /tmp/work/bin/fsck.f2fs; chmod 0777 /system/bin/fsck.f2fs
fi
chmod 0777 /tmp/work/mountfs-${1}.sh
chmod 0777 /tmp/work/bin/busybox
chmod 0777 /tmp/work/bin/e2fsck

[COLOR="red"]### Modifying ramdisk to not use yaffs, and use sd partitions instead. ###
[/COLOR]if [ "${4}" -gt '2' ]; then
busybox sed -i '/mtd@misc/s/^/#/' /tmp/work/ueventd.*.rc
busybox sed -i '/mount yaffs2/s/^/#/
s/# #/# /g' /tmp/work/*.rc
fi
[COLOR="red"]### Checking for anything other than nand is to be installed ###
[/COLOR]if [ "${4}" -gt '1' ]; then
busybox sed -i "/on fs/ a exec /mountfs-${1}.sh" /tmp/work/*.rc
chmod 0750 /tmp/work/init*.rc
chmod 0644 /tmp/work/ueventd.*.rc
fi
[COLOR="red"]### Building new ramdisk ###
[/COLOR]find . | busybox cpio -o -H newc | gzip -9 > /tmp/initrd-done.gz
}
mkinitrdduo() {
[COLOR="red"]### This is an untested attempt at the modifying of ramdisk for devices with combined boot/recovery.imgs ###
[/COLOR]mkdir -p /tmp/work/ing
mkdir -p /tmp/work/ramd
cd /tmp
./unpackbootimg /tmp/boot.img /tmp/work/
cd /tmp/work/ing
## Setting up working directory
cp /tmp/boot.img-ramdisk.gz /tmp/work/initrd.gz
## Unzipping nand kernel
gzip -d -c ../initrd.gz | busybox cpio -i -d
chmod 777 sbin
chmod 777 sbin/ramdisk.cpio
cp /tmp/work/ing/sbin/ramdisk.cpio /tmp/work/ramd
cd /tmp/work/ramd
busybox cpio -i -d < ramdisk.cpio
rm ramdisk.cpio
mkdir bin
cp /tmp/busybox bin/busybox
cp /tmp/e2fsck bin/e2fsck
cp /tmp/mountfs.sh /tmp/work/ramd/
chmod 0777 mountfs.sh
chmod 0777 bin/busybox
chmod 0777 bin/e2fsck
## Modifying ramdisk to not use fstab, and use mountfs.sh instead.
busybox sed -i '/mount_all/s/^/#/' init*.rc
busybox sed -i "s/rOm/$ROM_NAME/g" mountfs-${type}.sh
busybox sed -i '/on fs/ a exec /mountfs.sh' init*.rc
chmod 0750 init*.rc
find .| busybox cpio -o -H newc > newramdisk.cpio
cp /tmp/ramd/newramdisk.cpio /tmp/work/ing/sbin/ramdisk.cpio
chmod 750 /tmp/work/ing/sbin/ramdisk.cpio
chmod 750 /tmp/work/ing/sbin
cd /tmp/work/ing
# Building new ramdisk
find .| cpio -o -H newc | gzip -9 > ../boot.img-ramd.gz
cd /
}
initrdcp() {
[COLOR="red"]### Copying the ramdisk and checking if it needs the 6MB 00 file ###
[/COLOR]busybox printf "%b\n" "copying ramdisk"
###### Checking bootloader
if [ ${bootloader} != cLK ]; then
###### Checking zImage type
if [ -f /tmp/zImage ]; then
`hexdump /tmp/zImage | grep '1f 8b 08'` > /tmp/zI.txt
if grep -q 00003f80 "/tmp/zI.txt"; then
dd if=/dev/zero of=/tmp/6MB bs=1M count=6
fi
fi
cat /tmp/initrd-done.gz >> /tmp/6MB; cp /tmp/6MB /tmp/initrd.gz
else
cp /tmp/initrd-done.gz /tmp/initrd.gz
fi
cp /tmp/initrd.gz /boot/initrd.gz; cp /tmp/zImage /boot/zImage; cp /tmp/initrd.gz /boot_dir/initrd.gz; cp /tmp/zImage /boot_dir/zImage
}
bootflash() {
### Flashing boot for cLK users - base is taken from when boot.img is unmade (defaulted to 0x11800000) - default may need to be changed for other devices (can this be automated).
busybox printf "%b\n" "flashing boot"
chmod 0755 /tmp/mkbootimg
base=` cat /tmp/boot.img-base `
base=${base:-0x11800000}
cd /tmp
./mkbootimg --base "${base}" --cmdline "`cat /tmp/boot.img-cmdline`" --kernel /boot/zImage --ramdisk /boot/initrd.gz -o /tmp/boot.img
cd /
cp /tmp/boot.img /boot_dir/boot.img
[COLOR="red"]### CHecking what partition chould be flashed for cLK ###
[/COLOR]if [ ${install_type} -gt '2' ] && [ -b /sboot ]; then
boot=sboot
else
boot=boot
fi
chmod 0777 /tmp/flash_image
cd /tmp
./flash_image "${boot}" /tmp/boot.img
cd /
}
revertinitrd() {
[COLOR="red"]### the original unaltered ramdisk left in the tmp folder ###
[/COLOR]busybox printf "%b\n" "reverting ramdisk in /tmp"
cp /tmp/initrd_o.gz /tmp/initrd.gz
}
showresult() {
[COLOR="red"]### Result output to user ###
[/COLOR]busybox printf "Ramdisk successfully modified for ${ROM_NAME} running as ${type}\non ${mt1:-f2fs} with data on ${mt2:-f2fs}\nThe install folder is ${2}_${1}\n"
if [ -f /tmp/zI.txt ]; then
if grep -q 00003f80 /tmp/zI.txt; then
busybox printf "%b\n" "Kernel is a 3.0.x kernel"
else
busybox printf "%b\n" "Kernel is a 2.x kernel"
fi
fi
if [ -f /sdcard/${2}_${1}.zip ]; then
busybox printf "%b\n" "Please flash ${2}_${1}.zip in recovery"
fi
}
exiterr() {
echo "command failed" ; exit 1;
}
runn() {
bootloadercheck || exiterr
mntstuff "$@"
if [ "${bootloader}" = cLK ]; then
bootorig || exiterr
fi
[COLOR="red"]### ROM zip containing defined rom name looked for ###
[/COLOR]installsystem=` find /sdcard -name *.zip | grep ${2}`
if [ -n "${installsystem}" ]; then
systeminstall "$@" || exiterr
fi
if [ "$bootloader" = "haret" ]; then
[COLOR="red"]### not sure on this ###
[/COLOR]haretstuff < clrcad.exe haret.exe || exiterr
fi
[COLOR="red"]### Checking if the ROM zip detected is an actual ROM and not an update zip ###
[/COLOR]initmdck=` /tmp/7za -l /sdcard/${2}*.zip | grep vold.fstab `
if [ ! -f /tmp/initrd.gz -a -n ${initmdck} ]; then
bootingred "$@" || exiterr
fi
if [ -n ${initmdck} ]; then
mkmountcheck "$@"
mkinitrd "$@" || exiterr
initrdcp || exiterr
if [ ${bootloader} = cLK ]; then
bootflash
fi
fi
# revertinitrd || exiterr
showresult "$@" || exiterr
umountstuff "$@"
}
mkmountcheck() {
[COLOR="red"]### Looking for a mountfs file in /tmp - will take precedence over one made by the function above ###
[/COLOR]if [ ! -f /tmp/mountfs-"${1}".sh ]; then
echo "making mountfs.sh for $type"
if echo ${1} | grep -q porta; then
mkmountfsloop "$@" || exiterr
else
mkmountfs "$@" || exiterr
fi
fi
}
mntstuff() {
[COLOR="red"]### Folders mounted - for use with update zips ###
[/COLOR]mkdirs $@
if echo ${1} | grep -q "porta"; then
looppartnames $@
mkloopdev $@
else
partnames $@
fi
if [ ${1} != "NAND" ]; then
mountpart $@
else
mount /data
fi
if [ ${4} -lt "3" ]; then
mount /system
fi
}
modifyramdisk() {
[COLOR="red"]### modify ramdisk function calling the relevant functions from above ###
### desktop check run as script can be run on Linux (Ubuntu) ###[/COLOR]
if grep -q Ubuntu /proc/version; then
bootloader
else
bootloadercheck
fi
mntstuff $@
bootingred $@
mkmountcheck $@
mkinitrd $@
initrdcp $@
}
flashbootpart() {
bootingred $@
bootflash $@
}
remtxt() {
[COLOR="red"]### Test function - trying to create a function that can remove a given segment from the ramdisk ###
[/COLOR]rmfile=` cat /tmp/removerc.txt | busybox awk '{print $(NF)}' `
startrm=` cat /tmp/removerc.txt | busybox awk '{print $(NF-1)}' `
endrm=` cat /tmp/removerc.txt | busybox awk '{print $(NF-2)}' `
grep -lrIZ $p $currdir/$rmfile | busybox xargs -0 busybox sed --in-place "/$startrm/,/$endrm/d"
}
haretstuff() {
[COLOR="red"]### test stuff to make sure the haret elements are there if needed - startup.txt made if not present ###
[/COLOR]for i in $@; do zz=` find /inc -iname "$i" `; sdsd=` find /tmp -iname "$i" `
hrtstff=${zz:-$sdsd}
if [ -n ${hrtstff} ]; then
cp ${hrtstff} /boot_dir
fi
done
printf "set mtype 2524\nset ramaddr 0x11800000\nset ramsize 0x1e400000\nset initrd_offset 0x00a00000\nset KERNEL zImage\nset initrd initrd.gz\nset cmdline \"rel_path=NativeSD bootloader=haret\"\nboot\n" > /boot_dir/startup.txt
bootloader=MAGLDR
}
redir() {
[COLOR="red"]### test redirect to make debugging and appearance better ###
[/COLOR]if [ $# -gt 0 ]; then
nil="> /dev/null"; err="2> /dev/null"; logg=">> /tmp/` echo ${0} | busybox cut -d \".\" -f \"1\" `run.log"
eval ${1}
fi
}
installsystem() {
mntstuff "$@"
systeminstall "$@"
}
umountstuff() {
[COLOR="red"]### Unmounting elements ###
[/COLOR]if [ ${alreadyranums:-no} = "no" ]; then
umount /data
umount /system
umount /cache
if echo ${@} | grep -q "porta"; then
looppartnames
losetup -d ${firstpart}
losetup -d ${secondpart}
losetup -d ${thirdpart}
fi
else
if [ ${systemunzip} != "y" ]; then
umount /boot
umount /boot_dir
umount /NativeSD
umount /DirectSD
umount /DirectData
umount /system
umount /data
umount /cache
if echo ${type} | grep -q "porta"; then
losetup -d ${firstpart}
losetup -d ${secondpart}
losetup -d ${thirdpart}
fi
fi
fi
alreadyranums=yes
}
desktopcheck() {
[COLOR="red"]### this is the desktop check and make the relevant files and symlinks for Ubuntu so that it can be tested easily ###
[/COLOR]if [ ${alreadyrandc:-no} = "no" ]; then
alreadyrandc=yes
if grep -q Ubuntu /proc/version; then
ln -s ${currdir}/sdcard /
ln -s ${currdir}/tmp /
else
mkdir /tmp
fi
else
if grep -q Ubuntu /proc/version; then
rm -rf /tmp/work/*
rm -rf /sdcard
else
rm /tmp
fi
fi
}
currdir=$(pwd)
cd /
desktopcheck
cleanup "$@"
chmod 0777 /sdcard/bins/*
[COLOR="Red"]### The whole /sdcard/bins folder is dumped into /tmp - this adds the needed binaries and the various overwriting files that take precedence over the defaults in the script (mountfs-${type}.sh for example) ###[/COLOR]
cp /sdcard/bins/* /tmp
umountstuff "$@"
testing "$@"
desktopcheck
exit 0

If needed I'll try and further annotate.

For the (untested) update mechanic (I'll have to check the above code to see if it's there), a copy of the above script is including in the ramdisk, (possibly with the 7za binary) and if a given folder or zip is found (containing the ROM name) then the mounting part of the script is run followed by the systeminstall function (which is dump of system folder to /system and data folder to /data - similar to how the Portadroid updates were done).