[HD2 Android Q&A, Help & Troubleshooting and Genera] HypoTurtle:
I see what you mean about updater script (there is an error there but not the one you think), all those run_programs will fail to run (no mounting occurs from the updater script) as none of the mount.sh's are extracted to /tmp.

Just incase someone else can see the error before I see it.

The code is:

echo "package_extract_dir(\"system\", \"/system\");
package_extract_dir(\"data\", \"/data\");" > /META-INF/com/google/android/updater-script
cat /$ups | sed -e '/^symlink/,/);/!d' >> /META-INF/com/google/android/updater-script
cat /$ups | sed -e '/^set_perm/,/);/!d' >> /META-INF/com/google/android/updater-script
###cat /$ups | sed -e '/^set_perm_recursive/,/);/!d' >> /META-INF/com/google/android/updater-script
cat /$ups | sed -e '/^setmetadata/,/);/!d' >> /META-INF/com/google/android/updater-script
echo "modifying updater-script"
echo "unmount (\"/NativeSD\");
unmount (\"/DirectSD\");
unmount (\"/system\");
unmount (\"/data\");
unmount (\"/boot\");
unmount (\"/boot_dir\");

" >> /META-INF/com/google/android/updater-script

What the above should do is create a updater-script with:

package_extract_dir("system", "/system");

package_extract_dir("data", "/data");

followed by the lines from the original updater script from:

symlink( to the next occurance of );

with the same occuring for setperm(, set_perm_recursive(, and setmetadata(

and then ended with the unmounts.

The current result is the updater-script posted by RobbieP, seems one of the );'s isn't picked up.

The run_program and ui_print lines shouldn't be there.

Nearest I can get it down to is ...

package_extract_dir("system", "/system");
package_extract_dir("data", "/data");
symlink("../xbin/su", "/system/bin/su");
symlink("Roboto-Bold.ttf", "/system/fonts/DroidSans-Bold.ttf");
symlink("Roboto-Regular.ttf", "/system/fonts/DroidSans.ttf");
symlink("busybox", "/system/xbin/[", "/system/xbin/[[",
"/system/xbin/adjtimex", "/system/xbin/arp", "/system/xbin/ash",
"/system/xbin/awk", "/system/xbin/base64", "/system/xbin/basename",
"/system/xbin/bbconfig", "/system/xbin/blkid", "/system/xbin/blockdev",
"/system/xbin/brctl", "/system/xbin/bunzip2", "/system/xbin/bzcat",
"/system/xbin/bzip2", "/system/xbin/cal", "/system/xbin/cat",
"/system/xbin/catv", "/system/xbin/chattr", "/system/xbin/chgrp",
"/system/xbin/chmod", "/system/xbin/chown", "/system/xbin/chroot",
"/system/xbin/clear", "/system/xbin/cmp", "/system/xbin/comm",
"/system/xbin/cp", "/system/xbin/cpio", "/system/xbin/crond",
"/system/xbin/crontab", "/system/xbin/cut", "/system/xbin/date",
"/system/xbin/dc", "/system/xbin/dd", "/system/xbin/depmod",
"/system/xbin/devmem", "/system/xbin/df", "/system/xbin/diff",
"/system/xbin/dirname", "/system/xbin/dmesg", "/system/xbin/dnsd",
"/system/xbin/dos2unix", "/system/xbin/du", "/system/xbin/echo",
"/system/xbin/ed", "/system/xbin/egrep", "/system/xbin/env",
"/system/xbin/expand", "/system/xbin/expr", "/system/xbin/false",
"/system/xbin/fbsplash", "/system/xbin/fdisk", "/system/xbin/fgrep",
"/system/xbin/find", "/system/xbin/flash_lock",
"/system/xbin/flash_unlock", "/system/xbin/flashcp",
"/system/xbin/flock", "/system/xbin/fold", "/system/xbin/free",
"/system/xbin/freeramdisk", "/system/xbin/fstrim", "/system/xbin/fsync",
"/system/xbin/ftpget", "/system/xbin/ftpput", "/system/xbin/fuser",
"/system/xbin/getopt", "/system/xbin/grep", "/system/xbin/groups",
"/system/xbin/gunzip", "/system/xbin/gzip", "/system/xbin/halt",
"/system/xbin/head", "/system/xbin/hexdump", "/system/xbin/id",
"/system/xbin/ifconfig", "/system/xbin/inetd", "/system/xbin/insmod",
"/system/xbin/install", "/system/xbin/ionice", "/system/xbin/iostat",
"/system/xbin/ip", "/system/xbin/kill", "/system/xbin/killall",
"/system/xbin/killall5", "/system/xbin/less", "/system/xbin/ln",
"/system/xbin/losetup", "/system/xbin/ls", "/system/xbin/lsattr",
"/system/xbin/lsmod", "/system/xbin/lsusb", "/system/xbin/lzcat",
"/system/xbin/lzma", "/system/xbin/lzop", "/system/xbin/lzopcat",
"/system/xbin/man", "/system/xbin/md5sum", "/system/xbin/mesg",
"/system/xbin/mkdir", "/system/xbin/mke2fs", "/system/xbin/mkfifo",
"/system/xbin/mkfs.ext2", "/system/xbin/mkfs.vfat",
"/system/xbin/mknod", "/system/xbin/mkswap", "/system/xbin/mktemp",
"/system/xbin/modinfo", "/system/xbin/modprobe", "/system/xbin/more",
"/system/xbin/mount", "/system/xbin/mountpoint", "/system/xbin/mpstat",
"/system/xbin/mv", "/system/xbin/nanddump", "/system/xbin/nandwrite",
"/system/xbin/nbd-client", "/system/xbin/netstat", "/system/xbin/nice",
"/system/xbin/nohup", "/system/xbin/nslookup", "/system/xbin/ntpd",
"/system/xbin/od", "/system/xbin/patch", "/system/xbin/pgrep",
"/system/xbin/pidof", "/system/xbin/ping", "/system/xbin/pipe_progress",
"/system/xbin/pkill", "/system/xbin/pmap", "/system/xbin/poweroff",
"/system/xbin/printenv", "/system/xbin/printf", "/system/xbin/ps",
"/system/xbin/pstree", "/system/xbin/pwd", "/system/xbin/pwdx",
"/system/xbin/rdev", "/system/xbin/readlink", "/system/xbin/realpath",
"/system/xbin/renice", "/system/xbin/reset", "/system/xbin/resize",
"/system/xbin/rev", "/system/xbin/rm", "/system/xbin/rmdir",
"/system/xbin/rmmod", "/system/xbin/route", "/system/xbin/run-parts",
"/system/xbin/rx", "/system/xbin/sed", "/system/xbin/seq",
"/system/xbin/setconsole", "/system/xbin/setserial",
"/system/xbin/setsid", "/system/xbin/sh", "/system/xbin/sha1sum",
"/system/xbin/sha256sum", "/system/xbin/sha3sum",
"/system/xbin/sha512sum", "/system/xbin/sleep", "/system/xbin/sort",
"/system/xbin/split", "/system/xbin/stat", "/system/xbin/strings",
"/system/xbin/stty", "/system/xbin/sum", "/system/xbin/swapoff",
"/system/xbin/swapon", "/system/xbin/sync", "/system/xbin/sysctl",
"/system/xbin/tac", "/system/xbin/tail", "/system/xbin/tar",
"/system/xbin/taskset", "/system/xbin/tee", "/system/xbin/telnet",
"/system/xbin/telnetd", "/system/xbin/test", "/system/xbin/tftp",
"/system/xbin/tftpd", "/system/xbin/time", "/system/xbin/timeout",
"/system/xbin/top", "/system/xbin/touch", "/system/xbin/tr",
"/system/xbin/traceroute", "/system/xbin/true", "/system/xbin/ttysize",
"/system/xbin/tune2fs", "/system/xbin/umount", "/system/xbin/uname",
"/system/xbin/uncompress", "/system/xbin/unexpand", "/system/xbin/uniq",
"/system/xbin/unix2dos", "/system/xbin/unlzma", "/system/xbin/unlzop",
"/system/xbin/unxz", "/system/xbin/unzip", "/system/xbin/uptime",
"/system/xbin/usleep", "/system/xbin/uudecode", "/system/xbin/uuencode",
"/system/xbin/vi", "/system/xbin/watch", "/system/xbin/wc",
"/system/xbin/wget", "/system/xbin/which", "/system/xbin/whoami",
"/system/xbin/xargs", "/system/xbin/xz", "/system/xbin/xzcat",
"/system/xbin/yes",
"/system/xbin/zcat");
symlink("libGLESv2.so", "/system/lib/libGLESv3.so");
symlink("mksh", "/system/bin/sh");
symlink("toolbox", "/system/bin/cat", "/system/bin/chcon",
"/system/bin/chmod", "/system/bin/chown", "/system/bin/clear",
"/system/bin/cmp", "/system/bin/cp", "/system/bin/date",
"/system/bin/dd", "/system/bin/df", "/system/bin/dmesg",
"/system/bin/du", "/system/bin/getenforce", "/system/bin/getevent",
"/system/bin/getprop", "/system/bin/getsebool", "/system/bin/grep",
"/system/bin/hd", "/system/bin/id", "/system/bin/ifconfig",
"/system/bin/iftop", "/system/bin/insmod", "/system/bin/ioctl",
"/system/bin/ionice", "/system/bin/kill", "/system/bin/ln",
"/system/bin/load_policy", "/system/bin/log", "/system/bin/ls",
"/system/bin/lsmod", "/system/bin/lsof", "/system/bin/md5",
"/system/bin/mkdir", "/system/bin/mkswap", "/system/bin/mount",
"/system/bin/mv", "/system/bin/nandread", "/system/bin/netstat",
"/system/bin/newfs_msdos", "/system/bin/notify", "/system/bin/printenv",
"/system/bin/ps", "/system/bin/r", "/system/bin/readlink",
"/system/bin/renice", "/system/bin/restorecon", "/system/bin/rm",
"/system/bin/rmdir", "/system/bin/rmmod", "/system/bin/route",
"/system/bin/runcon", "/system/bin/schedtop", "/system/bin/sendevent",
"/system/bin/setconsole", "/system/bin/setenforce",
"/system/bin/setprop", "/system/bin/setsebool", "/system/bin/sleep",
"/system/bin/smd", "/system/bin/start", "/system/bin/stop",
"/system/bin/swapoff", "/system/bin/swapon", "/system/bin/sync",
"/system/bin/top", "/system/bin/touch", "/system/bin/umount",
"/system/bin/uptime", "/system/bin/vmstat", "/system/bin/watchprops",
"/system/bin/wipe");
symlink("/system/vendor/firmware/fw_bcm4329.bin", "/system/etc/firmware/fw_bcm4329.bin");
symlink("/system/vendor/firmware/fw_bcm4329_apsta.bin", "/system/etc/firmware/fw_bcm4329_apsta.bin");
set_perm(0, 0, 0777, "/tmp/installswap.sh");
run_program("/tmp/installswap.sh");
set_perm(0, 0, 0777, "/tmp/check_data_apps.sh");
run_program("/tmp/check_data_apps.sh");
set_perm_recursive(0, 0, 0755, 0644, "/system");
set_perm_recursive(0, 0, 0755, 0755, "/system/addon.d");
set_perm_recursive(0, 2000, 0755, 0755, "/system/bin");
set_perm(0, 3003, 02750, "/system/bin/netcfg");
set_perm(0, 0, 0755, "/system/bin/ping");
set_perm(0, 2000, 0750, "/system/bin/run-as");
set_perm(1014, 2000, 0550, "/system/etc/dhcpcd/dhcpcd-run-hooks");
set_perm_recursive(0, 2000, 0755, 0755, "/system/etc/init.d");
set_perm(0, 0, 0755, "/system/etc/init.d");
set_perm_recursive(0, 2000, 0755, 0644, "/system/vendor");
set_perm(0, 0, 0644, "/system/vendor/etc/audio_effects.conf");
set_perm_recursive(0, 0, 0755, 0644, "/system/vendor/firmware");
set_perm(0, 2000, 0755, "/system/vendor/firmware");
set_perm(0, 0, 0644, "/system/vendor/lib/libbt-vendor.so");
set_perm_recursive(0, 2000, 0755, 0755, "/system/xbin");
set_perm(0, 0, 06755, "/system/xbin/librank");
set_perm(0, 0, 06755, "/system/xbin/procmem");
set_perm(0, 0, 06755, "/system/xbin/procrank");
set_perm(0, 0, 06755, "/system/xbin/su");
symlink("/system/vendor/firmware/fw_bcm4329.bin", "/system/etc/firmware/fw_bcm4329.bin");
set_perm_recursive(0, 1001, 0755, 0775, "/system/etc/ppp");
set_perm(0, 0, 04755, "/system/bin/pppd");
set_perm(0, 3003, 02750, "/system/bin/netcfg");
set_perm(0, 3004, 02755, "/system/bin/ping");
set_perm(0, 2000, 06750, "/system/bin/run-as");
set_perm(1002, 1002, 0440, "/system/etc/dbus.conf");
set_perm(1014, 2000, 0550, "/system/etc/dhcpcd/dhcpcd-run-hooks");
set_perm_recursive(0, 2000, 0755, 0644, "/system/vendor");
set_perm(0, 2000, 0755, "/system/vendor/lib");
set_perm_recursive(1000, 1000, 0771, 0644, "/data/app");
unmount ("/NativeSD");
unmount ("/DirectSD");
unmount ("/system");
unmount ("/data");
unmount ("/boot");
unmount ("/boot_dir");

still a couple run_programs there.

Full code here:

#!/sbin/sh
set -u
testing() {
printf "%s\n" "TESTING MODE"
types="NAND DataOnExt NativeSD DirectSD "
typecheck=` echo "$types" | grep "$1 " `
if [ -z "${typecheck}" ]; then
echo "$1 is not a valid type - choices are $types"
exit 0
fi
if [ -z "$2" ]; then
printf "%s\n" "no type or ROM name specified"
printf "%s\n" "usage sh multiboot.sh [type] [ROM_NAME]"
printf "%s\n" "type can be ${types}, ROM_NAME to be taken from ROM_NAMEqweasd1234.zip"
exit 0
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=` 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
}
partnames() {
sdpart=/dev/block/mmcblk0p1
firstpart=/dev/block/mmcblk0p2
secondpart=/dev/block/mmcblk0p3
printf "%s\n" "setting partitions with ${firstpart} format"
}
looppartnames() {
sdpart=/dev/block/platform/msm_sdcc.1/by-name/userdata/media/0
#sdpart=/sdcard
firstpart=/dev/block/loop1
secondpart=/dev/block/loop2
thirdpart=/dev/block/loop3
systemblock=/dev/block/mtd4
printf "%s\n" "setting partitions with ${firstpart} format"
}
mkloopdev() {
dd if=/dev/zero of=${sdpart}/${ROM_NAME}/system.ext4 bs=4096 count=128000
dd if=/dev/zero of=${sdpart}/${ROM_NAME}/data.ext4 bs=4096 count=256000
dd if=/dev/zero of=${sdpart}/${ROM_NAME}/cache.ext4 bs=4096 count=32000
losetup ${firstpart} ${sdpart}/${ROM_NAME}/system.ext4
losetup ${secondpart} ${sdpart}/${ROM_NAME}/data.ext4
losetup ${thirdpart} ${sdpart}/${ROM_NAME}/cache.ext4
UU=` blkid ${systemblock} | cut -d '"' -f '2' `
mke2fs -T ext4 -O has_journal,ext_attr,resize_inode,filetype,extent, sparse_super,large_file,uninit_bg -U ${UU} -I 256 ${firstpart}
mke2fs -T ext4 -O has_journal,ext_attr,resize_inode,filetype,extent, sparse_super,large_file,uninit_bg -U ${UU} -I 256 ${secondpart}
mke2fs -T ext4 -O has_journal,ext_attr,resize_inode,filetype,extent, sparse_super,large_file,uninit_bg -U ${UU} -I 256 ${thirdpart}
tune2fs -o journal_data_writeback ${secondpart}
tune2fs -o journal_data_writeback ${thirdpart}
losetup -d ${firstpart}
losetup -d ${secondpart}
losetup -d ${thirdpart}
}
getpropfile() {
mkdir /tmp/sdcard > /dev/null
mount ${sdpart} /tmp/sdcard
if [ -f "/tmp/sdcard/installtype.prop" ]; then
if [ -z "`cut -d ' ' -f '3' /tmp/sdcard/installtype.prop`" ]; then
type=` cat /tmp/sdcard/installtype.prop | awk '{print $(NF)}' | sed 's/\(\[\|\]\)//g' `
ROM_NAME=` cat /tmp/sdcard/installtype.prop | awk '{print $(NF-1)}' | sed 's/\(\[\|\]\)//g' `
data_NAME=${ROM_NAME}
else
data_NAME=` cat /tmp/sdcard/installtype.prop | awk '{print $(NF)}' | sed 's/\(\[\|\]\)//g' `
type=` cat /tmp/sdcard/installtype.prop | awk '{print $(NF-1)}' | sed 's/\(\[\|\]\)//g' `
ROM_NAME=` cat /tmp/sdcard/installtype.prop | awk '{print $(NF-2)}' | sed 's/\(\[\|\]\)//g' `
fi
else
printf "%s\n" "no installtype.prop on sdcard - exitting"
exit 0
fi
umount /tmp/sdcard
}
bootloadercheck() {
printf "%s\n" "checking bootloader"
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() {
printf "%s\n" "creating directories"
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() {
printf "%s\n" "mounting files"
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() {
printf "%s\n" "saving original boot.img to boot-orig folder"
mkdir /boot_dir/boot-orig/
#chmod 0777 /sbin/dump_image
/sbin/dump_image boot /boot/boot-orig/boot.img
}
systeminstall() {
printf "%s\n" "installing system"
cd /
# rm -rf /system/*
local systemlocat=` mount | grep /system | cut -d ' ' -f '1' `
local datalocat=` mount | grep /data | cut -d ' ' -f '1' `
echo "system mounted at ${systemlocat}"
echo "data mounted at ${datalocat}"
if [ -n "$systemlocat" ]; then
local romzip="/sdcard/${2}*.zip"
echo ROM zip found is at ... ${romzip}
if [ ! -d /sdcard/tempy ]; then
mkdir /sdcard/tempy
fi
cp ${romzip} /sdcard/tempy/test.zip
chmod 0777 /sbin/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
clrcad.exe
startup.txt" >> inc.lst
fi
/sbin/7za x /sdcard/tempy/test.zip META-INF -oMEI '-xr@exc.lst' -y
/sbin/7za x /sdcard/tempy/test.zip '-ir@inc.lst' -oramds -y
if [ ${5} = "y" ]; then
/sbin/7za x /sdcard/tempy/test.zip data -y
/sbin/7za x /sdcard/tempy/test.zip system -y
fi
local ubi=` find MEI -name update-binary-installer -print0 `
local ub=` find MEI -name update-binary -print0 `
local ups=` find MEI -name updater-script -print0 `
echo "UBI location is ${ubi:-$ub} UPS is ${ups}"
mkdir -p /META-INF/com/google/android
cp /${ubi:-$ub} /META-INF/com/google/android/update-binary
##echo "package_extract_file(\"multi.sh\", \"/tmp/multi.sh\");
##set_perm(0, 0, 0777, \"/tmp/multi.sh\");
##run_program(\"/tmp/multi.sh\", \"dothis\" \"${type}\" \"${ROM_NAME}\" \"${data_NAME}\" \"m\" );" > /META-INF/com/google/android/updater-script
echo "package_extract_dir(\"system\", \"/system\");
package_extract_dir(\"data\", \"/data\");" > /META-INF/com/google/android/updater-script
cat /$ups | sed -e '/^symlink/,/);/!d' >> /META-INF/com/google/android/updater-script
cat /$ups | sed -e '/^set_perm/,/);/!d' >> /META-INF/com/google/android/updater-script
cat /$ups | sed -e '/^setmetadata(/,/);/!d' >> /META-INF/com/google/android/updater-script
echo "modifying updater-script"
echo "unmount (\"/NativeSD\");
unmount (\"/DirectSD\");
unmount (\"/system\");
unmount (\"/data\");
unmount (\"/boot\");
unmount (\"/boot_dir\");

" >> /META-INF/com/google/android/updater-script
/sbin/7za u /sdcard/tempy/test.zip META-INF/
#dd if=$0 of=multi.sh
#/sbin/7za a /sdcard/tempy/test.zip multi.sh
else
cat "system not mounted"
fi
}
bootingred() {
printf "%s\n" "obtaining an initrd.gz and zImage to work with"
###### Copying zImage and initrd.gz from /boot_dir when one wasn't in the zip
if [ ! -e "ramds/boot.img" ]; then
local nandinitrd=` find ramds -name initrd.gz -print0 | xargs -0 ls -s | sort -nr | awk '{print $(NF)}' | tail -n 1 `
local zImagelocat=` find ramds -name zImage `
echo "nand ramdisk is at $nandinitrd"
echo "zImage is at $zImagelocat"
cp /${zImagelocat} /tmp/
cp /${nandinitrd} /tmp/initrd.gz
else
chmod 0777 /sbin/unmkbootimg
cp /ramds/boot.img /tmp/boot.img
mkdir -p /tmp/boot 2> /dev/null
cd /sbin
./unmkbootimg /tmp/boot.img /tmp/boot | tee /tmp/bootimg.txt
cp /tmp/boot/boot.img-ramdisk.gz /tmp/initrd.gz
cp /tmp/boot/boot.img-zImage /tmp/zImage
fi
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
}
usecurrentboot() {
#chmod 0777 /sbin/dump_image
/sbin/dump_image boot /tmp/boot.img
/sbin/unpackbootimg /tmp/boot.img /tmp > /tmp/bootimg.txt
cp /tmp/boot.img-ramdisk.gz /tmp/initrd.gz
cp /tmp/boot.img-zImage /tmp/zImage
}
mkmountfs() {
printf "%s\n" "creating mountfs.sh"
if [ "${4}" -gt '1' ]; then
echo "#!/bin/busybox sh
while [ ! -b ${firstpart} ]; do
/bin/busybox sleep 5
done
/bin/busybox sleep 2" > /tmp/mountfs-"${1}".sh
if [ ${1} = DirectSD ]; then
echo "Modifying for ${type}"
echo "while [ ! -b ${secondpart} ]; do
/bin/busybox sleep 5
done
/bin/busybox sleep 2" >> /tmp/mountfs-"${1}".sh
fi
mt1=` blkid ${firstpart} | cut -d '"' -f '4' `
mt2="${mt1}"
if [ ${mt1:-f2fs} = ext4 ]; then
echo "# check the ext4 fs
/bin/e2fsck -p ${firstpart} > /e2fsck.log" >> /tmp/mountfs-"${1}".sh
else
echo "# check the f2fs fs
/bin/fsck.f2fs -p ${firstpart} > /fsckf2fs.log" >> /tmp/mountfs-"${1}".sh
fi
if [ ${1} = DirectSD ]; then
if [ -b ${secondpart} ]; then
mt2=` blkid ${secondpart} | cut -d '"' -f '4' `
else
echo "No 2nd ext partition present, format one and run script again"
fi
if [ ${mt2:-f2fs} = ext4 ]; then
echo "# check the ext4 fs
/bin/e2fsck -p ${secondpart} > /e2fsck2.log" >> /tmp/mountfs-"${1}".sh
else
echo "# check the f2fs fs
/bin/fsck.f2fs -p ${secondpart} > /fsckf2fs2.log" >> /tmp/mountfs-"${1}".sh
fi
fi
echo "/bin/busybox mkdir -p /NativeSD
/bin/busybox mount -t ${mt1:-f2fs} -o ro,noatime,nodiratime,barrier=0 ${firstpart} /NativeSD
# mount the system data app dir" >> /tmp/mountfs-"${1}".sh
if [ ${1} = DataOnExt ]; then
echo "Modifying for ${1}"
echo "/bin/busybox mount --bind /NativeSD/${2}/data /data" >> /tmp/mountfs-"${1}".sh
fi
if [ ${4} -gt '2' ]; then
echo "/bin/busybox mount --bind /NativeSD/${2}/system /system" >> /tmp/mountfs-"${1}".sh
if [ ${1} = NativeSD ]; then
echo "Modifying for ${1}"
echo "/bin/busybox mount --bind /NativeSD/${3}/data /data" >> /tmp/mountfs-"${1}".sh
else
echo "/bin/busybox mkdir -p /DirectData
/bin/busybox mount -t ${mt2:-f2fs} -o noatime,nodiratime,nosuid,nodev,discard ${secondpart} /DirectData
/bin/busybox mount --bind /DirectData/${3}/data /data" >> /tmp/mountfs-"${1}".sh
fi
fi
echo "# cleanup
# delete /bin to free ram
### /bin/busybox rm -rf /bin" >> /tmp/mountfs-"${1}".sh
fi
}
mkinitrd() {
printf "%s\n" "modifying ramdisk"
###### Setting up working directory
cp /tmp/initrd.gz /tmp/initrd-${2}.gz
mkdir -p /tmp/work
cd /tmp/work

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

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

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