[HD2 Android Q&A, Help & Troubleshooting and Genera] HypoTurtle:
#!/sbin/sh
set -u
testing() {
busybox printf "%s\n" "TESTING MODE" > ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
sdpart=/dev/block/mmcblk0p1
types="NAND DataOnExt NativeSD DirectSD porta "
optslist desc
if [ $# -gt 0 ]; then
typecheck=` echo "$types" | grep "$1 " `
if [ -z "${typecheck}" ]; then
echo "$1 is not a valid type - choices are $types" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
echo "checking if $1 is a command" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
optioncheck=` echo "$options" | grep "$1 " `
if [ -z ${optioncheck} ]; then
busybox printf "%b\n" "${1} is not a valid option - choices are:"
for i in ${options}
do
opts="$i"
echo "$opts to $(eval echo \$$opts)"
done
cp ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log /sdcard/${0}run.log
exit 0
else
typecheck=` echo "$types" | grep "$2 " `
if [ -n "${typecheck}" ] || [ -n "${optioncheck}" ]; then
type=${2}; ROM_NAME=${3}; data_NAME=${4:-$ROM_NAME}; install_type=` busybox expr index "Axvrp" "${type}" `; systemunzip=${5:-n}
if [ ${type} = "porta" ]; then
systemunzip=y
fi
printf "TYPE is $type\nRomName is $ROM_NAME\nDataName is $data_NAME\ninstall no is $install_type\nsystem install is $systemunzip" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
optslist functs
eval \$${1} ${type:-NativeSD} ${ROM_NAME} ${data_NAME:-$ROM_NAME} ${install_type:-3} ${systemunzip}
fi
fi
else
type=${1}; ROM_NAME=${2}; data_NAME=${3:-$ROM_NAME}; install_type=` busybox expr index "Axvrp" "${type}" `; systemunzip=${4:-n}
runn ${type:-NativeSD} ${ROM_NAME} ${data_NAME:-$ROM_NAME} ${install_type:-3} ${systemunzip}
fi
else
printf "no commands sent to script\nchecking /sdcard/installtype.prop" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
getpropfile
cp ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log /sdcard/${0}run.log
exit 0
fi
}
optslist() {
options="m ins mr fb "
if [ $1 = "desc" ]; then
m="mount partitions"; ins="install system"; mr="modify the ramdisk"; fb="andthis"; runn="runn"
else
m="mntstuff"; ins="installsystem"; mr="modifyramdisk"; fb="andthis"; runn="runn"
fi
}
#terminalvars() {
#m="mntstuff"; is="orthis"; mr="maybethis"; fb="andthis"; runn="runn";
#for i in $@;
#do
#	eval \$$i ${type:-NativeSD} ${ROM_NAME} ${data_NAME:-$ROM_NAME} ${install_type:-3} ${systemunzip:-n}
#	if [ $? = "127" ]; then
#	##eval \$$i ${type:-NativeSD} ${ROM_NAME} ${data_NAME:-$ROM_NAME} ${install_type:-3}
#	TMP="VAR${t:-1}"
#	printf "%s\n" ${TMP}=$i
#	eval "${TMP}=$i"
#	t=$((t+1))
#	type=$VAR1
#	ROM_NAME=$VAR2
#	data_NAME=$VAR3
#	install_type=` busybox expr index "Axvr" "${type}" `
#	printf "%s\n" install type is $type
#	printf "%s\n" ROM_NAME is $ROM_NAME
#	printf "%s\n" data_NAME is $data_NAME
#	printf "%s\n" install no. is $install_type
#	fi
#done
#}
#optionscheck() {
#### Options ###
#terminalvars $@
#options="m is mr fb $ROM_NAME $type ${data_NAME:-$ROM_NAME} $install_type "
#m="mount partitions"; is="install system"; mr="modify ramdisk"; fb="flash boot partition"; runn="run all"
#for i in $@
#do
#	optioncheck=` echo "$options " | grep "$i " `
#	if [ -z "${optioncheck}" ]; then
#	printf "%s\n" "$i is not a valid option - choices are:"
#	for t in $options
#	do
#	printf "%s" "$t to "
#	eval echo \$${t}
#	#echo -n "$t to "
#	#eval echo \$${t}
#	done
#	exit 0
#	fi
#done
#}
cleanup() {
echo "cleaning"
rm -rf zI.txt bootimg.txt updater-script test.zip META-INF MEI ramds umountloop.sh
}
partnames() {
firstpart=/dev/block/mmcblk0p2
secondpart=/dev/block/mmcblk0p3
busybox printf "%b\n" "setting partitions with ` echo ${firstpart} | busybox cut -d "/" -f "4" ` format" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
}
looppartnames() {
firstpart=/dev/block/loop1
secondpart=/dev/block/loop2
thirdpart=/dev/block/loop3
busybox printf "%b\n" "setting partitions with ` echo ${firstpart} | busybox cut -d "/" -f "4" ` format" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
}
mkloopdev() {
echo "" >> /sdcard/porta.txt
fls=` cat /sdcard/porta.txt | busybox cut -d " " -f "1" `
dd if=/dev/zero of=/sdcard/${ROM_NAME}/system.${fls:-ext4} bs=4096 count=${romsize}
dd if=/dev/zero of=/sdcard/${ROM_NAME}/data.${fls:-ext4} bs=4096 count=256000
dd if=/dev/zero of=/sdcard/${ROM_NAME}/cache.${fls:-ext4} bs=4096 count=32000
losetup ${firstpart} /sdcard/${ROM_NAME}/system.${fls:-ext4}
losetup ${secondpart} /sdcard/${ROM_NAME}/data.${fls:-ext4}
losetup ${thirdpart} /sdcard/${ROM_NAME}/cache.${fls:-ext4}
busybox mke2fs -T ${fls:-ext4} -O has_journal,ext_attr,resize_inode,filetype,extent,sparse_super,large_file,uninit_bg -I 256 ${firstpart}
busybox mke2fs -T ${fls:-ext4} -O has_journal,ext_attr,resize_inode,filetype,extent,sparse_super,large_file,uninit_bg -I 256 ${secondpart}
busybox mke2fs -T ${fls:-ext4} -O has_journal,ext_attr,resize_inode,filetype,extent,sparse_super,large_file,uninit_bg -I 256 ${thirdpart}
tune2fs -o journal_data_writeback ${secondpart}
tune2fs -o journal_data_writeback ${thirdpart}
}
mountloop() {
mount ${firstpart} /system
mount ${secondpart} /data
mount ${thirdpart} /cache
mount ${sdpart} /NativeSD
printf "#!/sbin/sh\nlosetup -d ${firstpart}\nlosetup -d ${secondpart}\nlosetup -d ${thirdpart}\n" > ${currdir}/tmp/umountloop.sh
}
getpropfile() {
mkdir -p ${currdir}/tmp/sdcard > /dev/null
mount ${sdpart} ${currdir}/tmp/sdcard
if [ -f "${currdir}/tmp/sdcard/installtype.prop" ]; then
busybox printf "%b\n" "installtype.prop found on sdcard" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
if [ -z "`busybox cut -d ' ' -f '3' ${currdir}/tmp/sdcard/installtype.prop`" ]; then
type=` cat ${currdir}/tmp/sdcard/installtype.prop | busybox awk '{print $(NF)}' | busybox sed 's/\(\[\|\]\)//g' `
ROM_NAME=` cat ${currdir}/tmp/sdcard/installtype.prop | busybox awk '{print $(NF-1)}' | busybox sed 's/\(\[\|\]\)//g' `
else
data_NAME=` cat ${currdir}/tmp/sdcard/installtype.prop | busybox awk '{print $(NF)}' | busybox sed 's/\(\[\|\]\)//g' `
type=` cat ${currdir}/tmp/sdcard/installtype.prop | busybox awk '{print $(NF-1)}' | busybox sed 's/\(\[\|\]\)//g' `
ROM_NAME=` cat ${currdir}/tmp/sdcard/installtype.prop | busybox awk '{print $(NF-2)}' | busybox sed 's/\(\[\|\]\)//g' `
fi
else
busybox printf "%b\n" "no installtype.prop on sdcard - exitting\nno type or ROM name specified\nusage sh hytmb.sh {options} [type] [ROM_NAME]\ntype can be ${types}\nROM_NAME to be taken from ROM_NAMEqweasd1234.zip" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
for i in ${options}
do
opts="$i"
echo "$opts to $(eval echo \$$opts)"
done
cp ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log /sdcard/${0}run.log
exit 0
fi
testing ${type} ${ROM_NAME} ${data_NAME:-$ROM_NAME}
umount ${currdir}/tmp/sdcard
}
bootloadercheck() {
busybox printf "%b\n" "checking bootloader" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
bootloader=MAGLDR
output=`grep -i "clk" /proc/cmdline`
if [ -n "${output}" ]; then
bootloader=cLK
fi
output=`grep -i "haret" /proc/cmdline`
if [ -n "${output}" ]; then
bootloader=haret
fi
####For testing
#bootloader=haret
}
bootloader() {
bootloader=cLK
}
mkdirs() {
busybox printf "%b\n" "creating directories" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
mkdir -p /NativeSD > /dev/null
mkdir -p /DirectSD > /dev/null
mkdir -p /boot_dir > /dev/null
mkdir -p /boot > /dev/null
mkdir -p /system > /dev/null
mkdir -p /data > /dev/null
mkdir -p /sdcard/NativeSD/"${2}" > /dev/null
mkdir -p /sdcard/NativeSD/"${2}"_"${1}" > /dev/null
}
mountpart() {
busybox printf "%s\n" "mounting files" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
if [ -b "${firstpart}" ]; then
mount -t auto ${firstpart} /NativeSD
if [ ${1} = "NativeSD" ] || [ ${1} = "DataOnExt" ]; then
mkdir -p /NativeSD/${2}/data > /dev/null
mount --bind /NativeSD/${3}/data /data
fi
if [ ${install_type} -gt '2' ]; then
mkdir -p /NativeSD/${2}/system > /dev/null
mount --bind /NativeSD/${2}/system /system
fi
fi
sdmounted=` mount | grep "${sdpart} on /sdcard" `
if [ -z "${sdmounted}" ]; then
mount -t auto ${sdpart} /sdcard
fi
mount --bind /sdcard/NativeSD /boot_dir
mount --bind /sdcard/NativeSD/${2}_${1} /boot
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
}
bootorig() {
busybox printf "%b\n" "saving original boot.img to boot-orig folder" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
mkdir /boot_dir/boot-orig/
#chmod 0777 ${currdir}/tmp/dump_image
cd ${currdir}/tmp
./dump_image boot /boot/boot-orig/boot.img
cd ${currdir}
}
systeminstall() {
#cp ${currdir}/tmp/inc.lst inc.lst > /dev/null
#cp ${currdir}/tmp/exc.lst exc.lst > /dev/null
busybox printf "%b\n" "installing system" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
cd ${currdir}
# rm -rf /system/*
local systemlocat=` mount | grep /system | busybox cut -d ' ' -f '1' `
local datalocat=` mount | grep /data | busybox cut -d ' ' -f '1' `
echo "system mounted at ... ${systemlocat}
data mounted at ... ${datalocat}" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
if [ -n "$systemlocat" ]; then
local romzip=` ls /sdcard/${2}*.zip | busybox head -n1 `
echo ROM zip found is at ... ${romzip} >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
cp -rf ${romzip} /sdcard/${2}_${1}.zip
chmod 0777 ${currdir}/tmp/7za
echo META-INF/*aroma* > exc.lst
echo "initrd.gz
zImage
boot.img" > inc.lst
###### Including haret stuff ###
if [ ${bootloader} = "haret" ]; then
echo "haret.exe\nclrcad.exe" >> inc.lst
fi
${currdir}/tmp/7za x /sdcard/${2}_${1}.zip META-INF -oMEI '-xr@exc.lst' -y > /dev/null
${currdir}/tmp/7za x /sdcard/${2}_${1}.zip '-ir@inc.lst' -oramds -y > /dev/null
if [ ${5} = "y" ]; then
echo "installing system" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
if [ ${type} = "porta" ]; then
echo "creating system, data and cache blocks on /sdcard first"
romsize=$((` ${currdir}/tmp/7za -l /sdcard/${2}_${1}.zip | busybox tail -1 | busybox awk '{print $(NF-5)}' `/4096))
fi
${currdir}/tmp/7za x /sdcard/${2}_${1}.zip data -y >> ${currdir}/tmp/${0}run.log
${currdir}/tmp/7za x /sdcard/${2}_${1}.zip system -y >> ${currdir}/tmp/${0}run.log
fi
local ubi=` busybox find MEI -name update-binary-installer -print0 `
local ub=` busybox find MEI -name update-binary -print0 `
local ups=` busybox find MEI -name updater-script -print0 `
echo "UBI location is ${ubi:-$ub} UPS is ${ups}" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
mkdir -p /META-INF/com/google/android
cp /${ubi:-$ub} /META-INF/com/google/android/update-binary
printf "package_extract_file(\"multi.sh\", \"${currdir}/tmp/multi.sh\");\nset_perm(0, 0, 0777, \"${currdir}/tmp/multi.sh\");\nrun_program(\"${currdir}/tmp/multi.sh\", \"m\" \"${type}\" \"${ROM_NAME}\" \"${data_NAME}\")" > /META-INF/com/google/android/updater-script
if [ ${5} = "y" ]; then
cat /$ups | busybox sed -e '/^symlink/,/);/!d' > /META-INF/com/google/android/updater-script
else
echo "package_extract_dir(\"system\", \"/system\");\npackage_extract_dir(\"data\", \"/data\");" > /META-INF/com/google/android/updater-script
cat /$ups | busybox sed -e '/^symlink/,/);/!d' >> /META-INF/com/google/android/updater-script
fi
cat /$ups | busybox sed -e '/^set_perm/,/);/!d' >> /META-INF/com/google/android/updater-script
cat /$ups | busybox sed -e '/^setmetadata/,/);/!d' >> /META-INF/com/google/android/updater-script
echo "modifying updater-script"
printf "unmount (\"/NativeSD\");\nunmount (\"/DirectSD\");\nunmount (\"/system\");\nunmount (\"/data\");\nunmount (\"/boot\");\nunmount (\"/boot_dir\");\n" >> /META-INF/com/google/android/updater-script
if [ ${type} = "porta" ]; then
printf "run_program("${currdir}/tmp/umountloop.sh");\n" >> /META-INF/com/google/android/updater-script
fi
${currdir}/tmp/7za u /sdcard/${2}_${1}.zip META-INF/
dd if=$0 of=multi.sh
${currdir}/tmp/7za a /sdcard/${2}_${1}.zip multi.sh
else
echo "system isn't mounted" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
fi
}
bootingred() {
busybox printf "%s\n" "obtaining an initrd.gz and zImage to work with" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
###### Copying zImage and initrd.gz from /boot_dir when one wasn't in the zip
if [ ! -e "ramds/boot.img" ]; then
local nandinitrd=` busybox find ramds -name initrd.gz -print0 | busybox xargs -0 ls -s | busybox sort -nr | busybox awk '{print $(NF)}' | busybox tail -n 1 `
local zImagelocat=` busybox find ramds -name zImage `
echo "nand ramdisk is at ... $nandinitrd
zImage is at ... $zImagelocat" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
if [ -n ${zImagelocat} ]; then
cp /${zImagelocat} ${currdir}/tmp/
fi
if [ -n ${nandinitrd} ]; then
cp /${nandinitrd} ${currdir}/tmp/initrd.gz
fi
else
chmod 0777 ${currdir}/tmp/unmkbootimg
cp /ramds/boot.img ${currdir}/tmp/boot.img
mkdir -p ${currdir}/tmp/boot 2> /dev/null
cd ${currdir}/tmp
./unmkbootimg ${currdir}/tmp/boot.img ${currdir}/tmp/boot
cd ${currdir}
cp ${currdir}/tmp/boot/boot.img-ramdisk.gz ${currdir}/tmp/initrd.gz
cp ${currdir}/tmp/boot/boot.img-zImage ${currdir}/tmp/zImage
fi
if [ -f "/sdcard/zImage" ]; then
cp /sdcard/zImage ${currdir}/tmp/zImage
cp /sdcard/modules/* /system/lib/modules/ 2> /dev/null
fi
if [ -f "/sdcard/initrd.gz" ]; then
cp /sdcard/initrd.gz ${currdir}/tmp/initrd.gz
fi
}
usecurrentboot() {
chmod 0777 ${currdir}/tmp/dump_image
cd ${currdir}/tmp
./dump_image boot ${currdir}/tmp/boot.img
./unpackbootimg ${currdir}/tmp/boot.img ${currdir}/tmp > ${currdir}/tmp/bootimg.txt
cd ${currdir}
cp ${currdir}/tmp/boot.img-ramdisk.gz ${currdir}/tmp/initrd.gz
cp ${currdir}/tmp/boot.img-zImage ${currdir}/tmp/zImage
}
mkmountfsloop() {
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}/system.${fls:-ext4} > e2fsck.log\n/bin/e2fsck -p /sdcard/${ROM_NAME}/data.${fls:-ext4} >> e2fsck.log\n/bin/e2fsck -p /sdcard/${ROM_NAME}/cache.${fls:-ext4} >> e2fsck.log\nlosetup ${firstpart} /sdcard/${ROM_NAME}/system.${fls:-ext4}\nlosetup ${secondpart} /sdcard/${ROM_NAME}/data.${fls:-ext4}\nlosetup ${thirdpart} /sdcard/${ROM_NAME}/cache.${fls:-ext4}\n/bin/busybox mkdir /system\n/bin/busybox mkdir /data\n/bin/busybox mkdir /cache\n/bin/busybox mount ${firstpart} /system\n/bin/busybox mount ${secondpart} /data\n/bin/busybox mount ${thirdpart} /cache\n" > ${currdir}/tmp/mountfs-"${1}".sh
if [ ${fls:-ext4} = "ext4" ]; then
printf "tune2fs -O dir_index,has_journal,uninit_bg ${firstpart}\n tune2fs -O dir_index,has_journal,uninit_bg ${secondpart}\n tune2fs -O dir_index,has_journal,uninit_bg ${thirdpart}" >> ${currdir}/tmp/mountfs-"${1}".sh
else
printf "tune2fs -o journal_data_writeback ${secondpart}\ntune2fs -o journal_data_writeback ${thirdpart}" >> ${currdir}/tmp/mountfs-"${1}".sh
fi
printf "# cleanup - delete /bin to free ram\n/bin/busybox rm -rf /bin\n" >> ${currdir}/tmp/mountfs-"${1}".sh
}
mkmountfs() {
busybox printf "%b\n" "creating mountfs.sh" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
if [ "${4}" -gt '1' ]; then
printf "#!/bin/busybox sh\nwhile [ ! -b ${firstpart} ]; do\n/bin/busybox sleep 5\ndone\n/bin/busybox sleep 2" > ${currdir}/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" >> ${currdir}/tmp/mountfs-"${1}".sh
fi
mt1=` busybox blkid ${firstpart} | busybox cut -d '"' -f '4' `
mt2="${mt1}"
if [ ${mt1:-f2fs} = ext4 ]; then
printf "# check the ext4 fs\n/bin/e2fsck -p ${firstpart} > /e2fsck.log" >> ${currdir}/tmp/mountfs-"${1}".sh
else
printf "# check the f2fs fs\n/bin/fsck.f2fs -p ${firstpart} > /fsckf2fs.log" >> ${currdir}/tmp/mountfs-"${1}".sh
fi
if [ ${1} = DirectSD ]; then
if [ -b ${secondpart} ]; then
mt2=` busybox 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 ext4 fs\n/bin/e2fsck -p ${secondpart} > /e2fsck2.log" >> ${currdir}/tmp/mountfs-"${1}".sh
else
printf "# check the f2fs fs\n/bin/fsck.f2fs -p ${secondpart} > /fsckf2fs2.log" >> ${currdir}/tmp/mountfs-"${1}".sh
fi
fi
printf "/bin/busybox mkdir -p /NativeSD\n/bin/busybox mount -t ${mt1:-f2fs} -o noatime,nodiratime,barrier=0 ${firstpart} /NativeSD\n# mount the data dir" >> ${currdir}/tmp/mountfs-"${1}".sh
if [ ${1} = DataOnExt ]; then
echo "Modifying for ${1}"
echo "/bin/busybox mount --bind /NativeSD/${2}/data /data" >> ${currdir}/tmp/mountfs-"${1}".sh
fi
if [ ${4} -gt '2' ]; then
echo "/bin/busybox mount --bind /NativeSD/${2}/system /system" >> ${currdir}/tmp/mountfs-"${1}".sh
if [ ${1} = NativeSD ]; then
echo "Modifying for ${1}"
echo "/bin/busybox mount --bind /NativeSD/${3}/data /data" >> ${currdir}/tmp/mountfs-"${1}".sh
else
printf "/bin/busybox mkdir -p /DirectData\n/bin/busybox mount -t ${mt2:-f2fs} -o noatime,nodiratime,nosuid,nodev,discard ${secondpart} /DirectData\n/bin/busybox mount --bind /DirectData/${3}/data /data" >> ${currdir}/tmp/mountfs-"${1}".sh
fi
fi
echo "##/system/bin/logcat -d -f /sdcard/logcat.log *:V
# cleanup deleting /bin to free ram
## /bin/busybox rm -rf /bin\n" >> ${currdir}/tmp/mountfs-"${1}".sh
fi
}
mkinitrd() {
busybox printf "%b\n" "modifying ramdisk" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
###### Setting up working directory
cp ${currdir}/tmp/initrd.gz ${currdir}/tmp/initrd-${2}.gz
mkdir -p ${currdir}/tmp/work
cd ${currdir}/tmp/work

###### Unzipping nand kernel
gzip -d -c ../initrd-${2}.gz | busybox cpio -i -d
if [ ! -d bin ]; then
mkdir bin
fi
cp ${currdir}/tmp/busybox ${currdir}/tmp/work/bin/busybox
cp ${currdir}/tmp/e2fsck ${currdir}/tmp/work/bin/e2fsck
cp ${currdir}/tmp/mountfs-${1}.sh ${currdir}/tmp/work/mountfs-${1}.sh

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

###### Modifying ramdisk to not use yaffs, and use sd partitions instead.
if [ "${4}" -gt '2' ]; then
busybox sed -i '/mtd@misc/s/^/#/' ${currdir}/tmp/work/ueventd.*.rc
busybox sed -i '/mount yaffs2/s/^/#/
s/# #/# /g' ${currdir}/tmp/work/*.rc
fi
###### Checking for anything other than nand is to be installed
if [ "${4}" -gt '1' ]; then
busybox sed -i "/on fs/ a exec /mountfs-${1}.sh" ${currdir}/tmp/work/*.rc
chmod 0750 ${currdir}/tmp/work/init*.rc
chmod 0644 ${currdir}/tmp/work/ueventd.*.rc
fi
###### Building new ramdisk
busybox find . | busybox cpio -o -H newc | gzip -9 > ${currdir}/tmp/initrd-done.gz
}
mkinitrdduo() {
mkdir -p ${currdir}/tmp/work/ing
mkdir -p ${currdir}/tmp/work/ramd
cd ${currdir}/tmp
./unpackbootimg ${currdir}/tmp/boot.img ${currdir}/tmp/work/
cd ${currdir}/tmp/work/ing
## Setting up working directory
cp ${currdir}/tmp/boot.img-ramdisk.gz ${currdir}/tmp/work/initrd.gz
## Unzipping nand kernel
gzip -d -c ../initrd.gz | busybox cpio -i -d
chmod 777 ${currdir}sbin
chmod 777 ${currdir}sbin/ramdisk.cpio
cp ${currdir}/tmp/work/ing/sbin/ramdisk.cpio ${currdir}/tmp/work/ramd
cd ${currdir}/tmp/work/ramd
busybox cpio -i -d < ramdisk.cpio
rm ramdisk.cpio
mkdir bin
cp ${currdir}/tmp/busybox bin/busybox
cp ${currdir}/tmp/e2fsck bin/e2fsck
cp ${currdir}/tmp/mountfs.sh ${currdir}/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
busybox find .| busybox cpio -o -H newc > newramdisk.cpio
cp ${currdir}/tmp/ramd/newramdisk.cpio ${currdir}/tmp/work/ing/sbin/ramdisk.cpio
chmod 750 ${currdir}/tmp/work/ing/sbin/ramdisk.cpio
chmod 750 ${currdir}/tmp/work/ing/sbin
cd ${currdir}/tmp/work/ing
# Building new ramdisk
busybox find .| busybox cpio -o -H newc | gzip -9 > ../boot.img-ramd.gz
}
initrdcp() {
busybox printf "%b\n" "copying ramdisk" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
###### Checking bootloader
cd ${currdir}/tmp
if [ ${bootloader} != cLK ]; then
###### Checking zImage type
if [ -f zImage ]; then
hexdump -C zImage | grep '1f 8b 08' > zI.txt
if grep -q 00003f80 "zI.txt"; then dd if=/dev/zero of=${currdir}/tmp/6MB bs=1M count=6
fi
fi
cat ${currdir}/tmp/initrd-done.gz >> 6MB; cp 6MB ${currdir}/tmp/initrd.gz
else
cp ${currdir}/tmp/initrd-done.gz ${currdir}/tmp/initrd.gz
fi
cp ${currdir}/tmp/initrd.gz /boot/initrd.gz; cp ${currdir}/tmp/zImage /boot/zImage; cp ${currdir}/tmp/initrd.gz /boot_dir/initrd.gz; cp ${currdir}/tmp/zImage /boot_dir/zImage
cd ${currdir}
}
bootflash() {
busybox printf "%b\n" "flashing boot" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
chmod 0755 ${currdir}/tmp/mkbootimg
base=` cat ${currdir}/tmp/boot.img-base `
base=${base:-0x11800000}
cd ${currdir}/tmp
./mkbootimg --base "${base}" --cmdline "`cat ${currdir}/tmp/boot.img-cmdline`" --kernel /boot/zImage --ramdisk /boot/initrd.gz -o ${currdir}/tmp/boot.img
cd ${currdir}
cp ${currdir}/tmp/boot.img /sdcard/NativeSD/"${2}"_"${1}"/
if [ ${install_type} -gt '2' ] && [ -b /sboot ]; then
boot=sboot
else
boot=boot
fi
chmod 0777 ${currdir}/tmp/flash_image
cd ${currdir}/tmp
./flash_image "${boot}" ${currdir}/tmp/boot.img
cd ${currdir}
}
revertinitrd() {
busybox printf "%b\n" "reverting ramdisk in ${currdir}/tmp" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
cp ${currdir}/tmp/initrd-"${ROM_NAME}".gz ${currdir}/tmp/initrd.gz
}
showresult() {
busybox printf "%b\n" "Ramdisk successfully modified for ${ROM_NAME} running as ${type}
on ${mt1:-f2fs} with data on ${mt2:-f2fs}
The install folder is ${2}_${1}" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
if [ -f ${currdir}/tmp/zI.txt ]; then
if grep -q 00003f80 ${currdir}/tmp/zI.txt; then
busybox printf "%b\n" "Kernel ubusybox sed is a 3.0.x kernel" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
else
busybox printf "%b\n" "Kernel ubusybox sed is a 2.x kernel" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
fi
fi
if [ -f /sdcard/${2}_${1}.zip ]; then
busybox printf "%b\n" "Please flash ${2}_${1}.zip in recovery" >> ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log
fi
cat ${currdir}/tmp/mountfs-${1}.sh >> ${currdir}/tmp/${0}run.log
}
exiterr() {
echo "command failed"; exit 1;
}
runn() {
cleanup "$@" || exiterr
if [ ${1} = "porta" ]; then
looppartnames || exiterr
else
partnames || exiterr
fi
bootloadercheck || exiterr
mkdirs "$@" || exiterr
if [ ${1} = "porta" ]; then
mkloopdev
mountloop
else
if [ "${1}" != 'NAND' ]; then
mountpart "$@" || exiterr
fi
fi
if [ "${bootloader}" = cLK ]; then
bootorig || exiterr
fi
installsystem=` busybox find /sdcard -name *.zip | grep ${2}`
if [ -n "${installsystem}" ]; then
systeminstall "$@" || exiterr
fi
if [ "$bootloader" = "haret" ]; then
###not sure on this ###
haretstuff < clrcad.exe haret.exe || exiterr
fi
if [ ! -f ${currdir}/tmp/initrd.gz ]; then
bootingred "$@" || exiterr
fi
if [ ! -f ${currdir}/tmp/mountfs-"${1}".sh ]; then
echo "making mountfs.sh for $type"
if [ ${type} = "porta" ]; then
mkmountfsloop "$@" || exiterr
else
mkmountfs "$@" || exiterr
fi
fi
mkinitrd "$@" || exiterr
initrdcp || exiterr
if [ ${bootloader} = cLK ]; then
bootflash
fi
# revertinitrd || exiterr
showresult "$@" || exiterr
}
#vb() {
#local q=""
#local e="> /dev/null"
#local r="2> /dev/null"
#local l="2> /sdcard/univlog.txt"
#local b="2&> /sdcard/univlog.txt"
#export verb=`eval \$${1} `
#}
mntstuff() {
##getpropfile $@
mkdirs $@
if [ ${type} != "porta" ]; then
partnames $@
mountpart $@
else
looppartnames $@
mountloop
fi
}
modifyramdisk() {
mntstuff $@
install_type=` busybox expr index "Axvrp" "${type}" `
bootingred $@
mkmountfs $@
mkinitrd $@
initrdcp $@
}
flashbootpart() {
bootingred $@
bootflash $@
}
findit() {
busybox find $1 -name $2
}
remtxt() {
rmfile=` cat ${currdir}/tmp/removerc.txt | busybox awk '{print $(NF)}' `
startrm=` cat ${currdir}/tmp/removerc.txt | busybox awk '{print $(NF-1)}' `
endrm=` cat ${currdir}/tmp/removerc.txt | busybox awk '{print $(NF-2)}' `
grep -lrIZ $p $currdir/$rmfile | busybox xargs -0 busybox sed --in-place "/$startrm/,/$endrm/d"
}
haretstuff() {
for i in $@; do zz=`findit ramds $i`; sdsd=`findit tmp $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
}
installsystem() {
systemunzip="y"
systeminstall ${type} ${ROM_NAME} ${data_NAME:-$ROM_NAME} ${install_type} ${systemunzip:-n}
}
currdir=$(pwd)
currdir=""
mkdir ${currdir}/tmp
cp /sdcard/bins/* ${currdir}/tmp 2> /dev/null
testing "$@" || exiterr
cp ${currdir}/tmp/`echo ${0} | busybox cut -d "." -f "1"`run.log /sdcard/${0}run.log
exit 0

Wasn't executing the right mounts, system wasn't mounted thus it didn't bother looking for it. I've removed the output splits (tee), so that it''s all just redirected to the log (you won't/shouldn't see any echo output on screen).

I'll have a look at those attachments when I get a chance.

Edit. I've found/remembered how Portadroid/SuperRam etc. runs, would like to see if my way runs first. They have there script run earlier than mine, if it works where I have it I could slide in a modified version of there script (with credits to OP), it's much more comprehensive that mine.