#!/system/bin/sh # v1.4.0 2010-09-06 Firerat, broke script down # split the 20userinit check up to do two tests instead of one ## Version="Version 1.4.1 BETA2" printmsg () { ml=`echo -e $1|wc -L` hf="" for i in `seq $ml`;do hf="${hf}=" done echo -e $1|busybox awk -v hf=$hf 'BEGIN{print hf};END{print hf};{print $0};' ###########^^^^^^^ keep that, makes testing on pc easy return } remountrw () { MOUNT_CMD="busybox mount" if [ "$1" = "ro" ]; then mode=ro else mode=rw fi if [ -e "/system/csys" ]; then mps="/system /system/csys" else mps="/system" fi for mp in $mps ;do if [ "`grep \ $mp\ /proc/mounts|grep -q $mode;echo $?`" != "0" ]; then $MOUNT_CMD -o $mode,remount ${mp} if [ "$?" != "0" ]; then echo "Mounting ${mp} Failed" exitcode="1" fi fi done if [ "$exitcode" = "1" ]; then printmsg "mounting $mode failed, which is a bit of a pain\ncan't think why it would fail\nanyway, not much point trying to contiune" exit 1 fi return } FindSPL () { #Block4=`df |grep block4|sed -e s~\ \ \ ~\ ~g -e s~\ \ ~\ ~g -e s~\ \ ~\ ~g|cut -d " " -f2|head -n1` Block4=`df |grep block4|awk '$0 { print $2 }'|head -n1` if [ `expr $Block4 \/ 1024` -lt "67" ]; then SPL=DangerSPL elif [ `expr $Block4 \/ 1024` -gt "67" ]; then # cheap check for MPH ( MTD Partition Hack, i.e. kernel cmd line for partition map # as cache ends up as a bind mount it will return a false +ve for MT3G if [ "`getprop ro.hardware`" = "trout" ]; then SPL=DangerSPL else SPL=MT3G fi else SPL=NoneDangerSPL fi # removing this message, it just creates noobfusion #printmsg "$SPL detected" return } recoverycheck () { if [ "`ls /sbin|grep -q recovery;echo $?`" = "0" ]; then mount -a > /dev/null recoverymode=y else recoverymode=n rootcheck fi return } rootcheck () { if [ "`busybox id -u`" != "0" ]; then printmsg -e "root is required to run this script\ntype\nsu\nand then run again" exit 1 fi return } initcheck () { instinit () { if [ ! -e $initd ]; then install -d $initd fi if [ -e $initd ] && [ ! -d $initd ]; then rm $initd install -d $initd fi return } PatchUserinit () { # patch userinit script to use /data/local/userinit.d # I was going to make a fake sd-ext mount, but nah, no risk of any a2sd weirdness with this for userinit in `ls /system/etc/init.d/*userinit*`;do if [ "`grep -q userinit $userinit;echo $?`" = "0" ]; then # check not already patched if [ "`grep -q data/local/userinit.sh $userinit;echo $?`" != "0" ]; then remountrw cat >> $userinit << "EOF" # Firerat patching userinit to use /data/local/ # target being setups with no ext partition e.g. mt3g if [ -e /data/local/userinit.sh ]; then log -p i -t userinit "Executing /data/local/userinit.sh" logwrapper /system/bin/sh /data/local/userinit.sh setprop cm.userinit.active 1 fi EOF fi if [ "`grep -q data/local/userinit.d $userinit;echo $?`" != "0" ]; then remountrw cat >> $userinit << "EOF" if [ -d /data/local/userinit.d ]; then logwrapper busybox run-parts /data/local/userinit.d setprop cm.userinit.active 1 fi EOF busybox chmod 700 $userinit printmsg "$userinit patched to check in /data/local/\nchanges will take effect on next boot" fi fi done return } undoinitopts () { for i in lwp swap DCbind2Cache DCbind2SD rba ddb;do ${i}_="0" done printmsg "Options that require run-parts disabled.." return } # if [ "`grep -q system /proc/mounts;echo $?`" = "1" ]; then mount /system fi if [ ! -d /system/etc/init.d ]; then printmsg "It appears that this 'ROM' does not use 'run-parts'\nwhich is required for some of these scripts to work\nTherefore I will only install none 'run-parts'" undoinitopts fi if [ "`grep -q sd-ext /proc/mounts ;echo $?`" = "0" ]; then initd=/sd-ext/userinit.d instinit elif [ "`grep -q system/sd /proc/mounts ;echo $?`" = "0" ]; then initd=/system/sd/userinit.d instinit else PatchUserinit initd=/data/local/userinit.d instinit fi return } ## end common functions ## begin scripts FroYoApps2sdext () { #!/system/bin/sh # 2010-07-13 Firerat - symlink apps from /data/app/ to sd-ext/app/ # optionally leave apps on /data/app/ # optionally move froyo fat apps to sd-ext # 2010-08-06 ==> 2010-08-12 , disbaled lots, and added better Apps2sdext + ApkManager.sh script # 2010-08-17 Firerat, Mister Opinion's fix # 2010-08-17 Firerat, switched from symlink to bind mount # 2010-09-02 Firerat, added a system free check + option to move rom manager if full # 2010-09-08 Firerat, make compatible with RA Recovery # 2010-10-22 Firerat, check for sd-ext mount and force install of 05mountsd if not mounted # 2010-10-22 Firerat, separate out a2sdext binds and /data/data bind # 2010-10-22 Firerat, bind /data/system as well as /data/data # 2010-10-22 Firerat, fix up the dupefixer ( was doing two 'runs' due to being writen for symlinks and not bind mounts ) # 2010-10-28 Firerat, many thanks to Kali- for custom restore feature http://goo.gl/hvS9 # 2010-11-3 Firerat, modified 05mountsd to support incedible ( or devices with mmcblk1 as well as mmcblk0 ) # 2010-11-3 Firerat, moved dupecleaner into ApkManager.sh # 2010-11-3 Firerat, added a little check to the 05mountsd restore, with msg # 2010-11-3 Firerat, removed checkcfg function, not used a config for ages # 2010-11-3 Firerat, use alias instead of creating symlinks in recovery # start FroYo apps2sdext Functions recoverycheck () { #if [ "`ls /sbin|grep -q recovery;echo $?`" = "0" ]; if [ -e "/sbin/recovery" ]; then mount -a > /dev/null recoverymode=y # fix for missing busybox links on RA for i in `busybox |sed -n '/defined/,$p'|sed -e s/,//g|grep -v Currently`;do #ln -s busybox /sbin/$i alias $i="busybox $i" done else recoverymode=n fi return } fsdextmnt () { if [ "`grep -q sd-ext /proc/mounts;echo $?`" = "0" ]; then printmsg "/system/etc/init.d/05mountsd alreadys exists and appears to work" mountsd=ok return fi if [ -e "/system/etc/init.d/05mountsd" ]; then mountsd=failed else # assume the 05mountsd we install will work mountsd=ok fi # install sd-ext mount script cat > /dev/05mountsd << "EOF" #!/system/bin/sh # # mount ext[234] partition from sd card BB="logwrapper busybox"; if [ "$SD_EXT_DIRECTORY" = "" ]; then SD_EXT_DIRECTORY=/sd-ext; fi; # find first linux partition on SD card(s) for mmcblk in 0 1;do MMC=/dev/block/mmcblk${mmcblk} # wait for the device to settle COUNT=6; until [ -b "$MMC" ] || [ $COUNT -lt 1 ]; do sleep 1; COUNT=$((COUNT-1)); done; # if no mmcblkx try to fudge it frfudge=y if [ ! -b "$MMC" -a "$frfudge" = "y" ]; then # IConrad01's fix for CM6 # http://forum.cyanogenmod.com/topic/2636-froyo-a2sdext/page__view__findpost__p__26124 base_minor=$(expr 8 \* $mmcblk) mknod ${MMC} b 179 $base_minor chmod 600 ${MMC} for minor in 1 2 3;do if [ ! -b "${MMC}p${minor}" ]; then mknod ${MMC}p${minor} b 179 $(expr $base_minor \+ $minor) chmod 600 ${MMC}p${minor} fi done fi if [ -b "$MMC" ]; then FDISK="busybox fdisk" PARTITION=`$FDISK -l $MMC | awk '/^\// && $5 == 83 {print $1;exit;}'` if [ -b "$PARTITION" ]; then log -p i -t mountsd "$PARTITION = linux partition" break fi fi done if [ "$PARTITION" = "" ]; then log -p i -t mountsd "valid linux partition not found" exit fi log -p i -t mountsd "Checking filesystems.."; # fsck the sdcard filesystem first if [ -x `which e2fsck` ]; then e2fsck -y $PARTITION;e2fsck_exitcode=$? else echo "executable e2fsck not found, assuming no filesystem errors" e2fsck_exitcode=0 fi # set property with exit code in case an error occurs setprop cm.e2fsck.errors $e2fsck_exitcode; if [ "$e2fsck_exitcode" -lt 2 ]; then # mount and set perms $BB mount -o noatime,nodiratime -t auto $PARTITION $SD_EXT_DIRECTORY; if [ "$?" = 0 ]; then $BB chown 1000:1000 $SD_EXT_DIRECTORY; $BB chmod 771 $SD_EXT_DIRECTORY; log -p i -t mountsd "$SD_EXT_DIRECTORY successfully mounted"; else log -p e -t mountsd "Unable to mount filesystem for $SD_EXT_DIRECTORY!"; fi else log -p e -t mountsd "Unable to repair filesystem, disabling apps2sd"; fi EOF if [ "`grep -q sd-ext /proc/mounts;echo $?`" != "0" ]; then sh /dev/05mountsd if [ "`grep -q sd-ext /proc/mounts;echo $?`" != "0" ]; then printmsg "/sd-ext mount failed, exiting" if [ "`getprop cm.e2fsck.errors`" = "1" ]; then printmg "It looks like e2fsck repaired errors and a reboot is required\nplease reboot and try again" exit else # dump some stuff ls -l /dev/block/mmcblk* for mmcblk in mmcblk0 mmcblk1;do if [ -b "/dev/block/${mmcblk}" ]; then busybox fdisk -l /dev/block/${mmcblk} fi done printmsg "above are some details of your system\nif don't see a line like\n/dev/block/mmcblk0p2 229680 245301 499872 83 Linux\nare you sure your sdcard is partitioned?\nIf you do see something like that line\nit might be that it is just not formated\nyou could try formating it with this command\nmke2fs /dev/block/mmcblk0p2\nreplace mmcblk0p2 with the one in your output\nWARNING THAT WILL DESTORY THE DATA on that partition" exit fi fi fi mount -o rw,remount /system install -m 700 -D /dev/05mountsd /system/etc/init.d/05mountsd if [ "$?" = "0" ]; then printmsg "mount sd-ext installed" else printmsg "mount sd-ext script failed to install\nProbably ran out of space\nchecking..." systemfree fi mount -o ro,remount /system return } systemfree () { # check free space on system df |grep -E "system$|^Filesystem" ls -l /dev/05mountsd sysfree=`df |awk '/system$/ {print $4}'` scriptsize=`ls -l /dev/05mountsd|awk ' { print $5 }'` # going to need at least 7k for ApkManager scriptsize=`expr $scriptsize + 8000` if [ "$sysfree" -lt "$scriptsize" ]; then printmsg "looks like you have no room on system" if [ -e /system/app/RomManager.apk ]; then echo "would you like me to move RomManager.apk to data (y/n)?" mvromman else printmsg "can't see an easy target, please make space\non system and run again" exit fi fi return } mvromman () { if [ "$recoverymode" = "n" ]; then read a else a=y fi if [ "$a" = "y" ]; then if [ "$recoverymode" = "y" ]; then mv /system/app/RomManager.apk /data/app/ else pm install -rf /system/app/RomManager.apk # pm always gives 0 exit rm /system/app/RomManager.apk printmsg "RomManager.apk moved" fsdextmnt return fi elif [ "$a" = "n" ]; then printmsg "ok, can't do anything yet\nmanually make space and run again" exit else echo "please enter y or n" mvromman fi return } movefroyocfg () { if [ "`mount|grep -c \"/mnt/asec/\"`" != "0" ]; then printmsg "move FroYo FAT installed apps to /sd-ext? (y/n)\nit can be a little slow, so if your in a rush\nthen answer n, you can always run the script again later" read a if [ "$a" = "n" ]; then printmsg "FroYo FAT 2 sd-ext will be skipped" froyo2sdext=n elif [ "$a" = "y" ]; then printmsg "FroYo fat apps will be moved to sd-ext" froyo2sdext=y else printmsg "please enter y or n" movefroyocfg fi fi return } a2sdbind () { initd=/sd-ext/userinit.d cat > /dev/10data2sdext-binds << "EOF" #!/system/bin/sh # a2sd bind mounts # remove FroYo a2sdext hack if official a2sd is live [ Firerat ] if [ -e "/sd-ext/userinit.d/10data2sdext-binds" -a -e "/system/etc/init.d/10apps2sd" ]; then # delete the script which sets up bind mounts + script that re-creates /system/bin/ApkManager.sh ( this will make strange symlinks links ) rm /sd-ext/userinit.d/10data2sdext-binds /sd-ext/userinit.d/55ApkManager 2> /dev/null # move the 'keep on internal' apps to their proper place for apkdir in app app-private;do mv /data/${apkdir}_i/* /data/${apkdir}/ 2> /dev/null done # remove the symlinks it the 'keep on internal' apps find /sd-ext/app /sd-ext/app-private -type l -exec rm {} \; if [ -e "/data/system/packages.xml" ]; then for apk in `ls /sd-ext/app/*apk /sd-ext/app-private/*apk`;do # update packages.xml with apk's location sed s~/data/`basename $apk`~/sd-ext/`basename $apk`~ -i /data/system/packages.xml # clear dalvik-cache ( will probably get generated on /sd-ext ) rm /data/dalvik-cache/*`basename $apk`*.dex 2> /dev/null done fi exit fi # end of AutoSelfDestruct SD_EXT_DIRECTORY=`egrep "/sd-ext|/system/sd" /proc/mounts|awk '{ print $2 }'` if [ "$SD_EXT_DIRECTORY" = "" ]; then SD_EXT_DIRECTORY=/sd-ext fi if [ "`egrep -q $SD_EXT_DIRECTORY /proc/mounts;echo $?`" != "0" ]; then echo "$SD_EXT_DIRECTORY not mounted.. skipping a2sd" exit fi for dir in app app-private;do if [ "`egrep -q \"/data/${dir}\" /proc/mounts;echo $?`" != "0" ]; then if [ ! -e "${SD_EXT_DIRECTORY}/${dir}" ]; then install -m 771 -o 1000 -g 1000 -d ${SD_EXT_DIRECTORY}/${dir} fi if [ -L "/data/${dir}" ]; then rm /data/${dir} install -m 771 -o 1000 -g 1000 -d /data/${dir} fi if [ "${dir}" = "app" -o "${dir}" = "app-private" ]; then for app in `find /data/${dir} -type f -iname "*.apk" -o -iname "*.zip"`;do mv ${app} ${SD_EXT_DIRECTORY}/${dir}/ done fi mount -o bind ${SD_EXT_DIRECTORY}/${dir}/ /data/${dir} fi done EOF install -m 700 -o 0 -g 0 -D /dev/10data2sdext-binds ${initd}/10data2sdext-binds rm /dev/10data2sdext-binds sh ${initd}/10data2sdext-binds if [ "`grep -q \"/data/data\" /proc/mounts;echo $?`" != "0" ]; then if [ ! -e /sd-ext/data ]; then install -m 771 -o 1000 -g 1000 -d /sd-ext/data fi sdextdatasize=`du -cs /sd-ext/data|awk '/total/ {print $1}'` sdextdatasize4human=`echo $sdextdatasize|awk '{printf "%.1f" "%c",$1/1024,"M"}'` datadatasize=`du -cs /data/data|awk '/total/ {print $1}'` dataAvailable=`df |awk '/\ \/data$/ {print $4}'` datadata4human=`echo $datadatasize|awk '{printf "%.1f" "%c",$1/1024,"M"}'` dataAvailable4human=`echo $dataAvailable|awk '{printf "%.1f" "%c",$1/1024,"M"}'` postdatabindfree=`echo $datadatasize $dataAvailable|awk '{printf "%.1f" "%c",($1+$2)/1024,"M"}'` if [ "$sdextdatasize" -gt "$datadatasize" -a "$recoverymode" != "y" ]; then newestdir="`ls /sd-ext/data/ -lt|head -n 1|awk '{print $6" "$7" "$8" "$9" "$10}'`" oldestdir="`ls /sd-ext/data/ -lt|tail -n 1|awk '{print $6" "$7" "$8" "$9" "$10}'`" printmsg "You currently have $sdextdatasize4human in /sd-ext/data\nThe newest dir is $newestdir\nThe oldest dir is $oldestdir\ndo you want to use /sd-ext/data?(y/n)" datadatabindcfg if [ "$datadatabind" = "y" ]; then cat > /data/firstboot.sh << "EOF" rm -r /data/data/* rm -r /data/system/* EOF fi else printmsg "do you want to put /data/data on /sd-ext(y/n)?\nIt will free up $datadata4human from data\n/data currently has $dataAvailable4human free\nthis option would give you approx $postdatabindfree free\n( /data/data can grow to 30M or more )" datadatabindcfg fi else datadatabinds fi if [ "$recoverymode" = "y" -a "`du -cs /data/data|awk '/total/ {print $1}'`" -lt "3000" ]; then datadatabinds fi return } datadatabindcfg () { read a if [ "$a" = "y" ]; then datadatabind=y datadatabinds elif [ "$a" = "n" ]; then datadatabind=n else printmsg "Please answer y or n" datadatabindcfg fi return } datadatabinds () { cat > /dev/11datadata-binds << "EOF" #!/system/bin/sh if [ "$1" = "off" ]; then FreeData=`df|awk '$6 == "/data" {print $4}'` SizeOnSdext=`du -cs /sd-ext/data /sd-ext/system|awk '$2 == "total" {print $1}'` if [ "$FreeData" -gt "$SizeOnSdext" ]; then cat > /data/firstboot.sh << "ddboff" echo "Uninstalling /data/data binds" sh /system/etc/init.d/05mountsd for i in data system;do cp -a /sd-ext/${i}/* /data/${i}/ rm -r /sd-ext/${i} done rm /sd-ext/userinit.d/11datadata-binds ddboff echo "reboot for changes to take effect" exit else echo "You do not have enough space available on /data" echo "Free space on data = `echo $FreeData|awk '{printf "%.2f" "%c",$1/1024,"M"}'`" echo "size on /sd-ext = `echo $SizeOnSdext|awk '{printf "%.2f" "%c",$1/1024,"M"}'`" echo "" echo "exiting without changes" exit fi fi SD_EXT_DIRECTORY=`egrep "/sd-ext|/system/sd" /proc/mounts|awk '{ print $2 }'` if [ "$SD_EXT_DIRECTORY" = "" ]; then SD_EXT_DIRECTORY=/sd-ext fi if [ "`egrep -q $SD_EXT_DIRECTORY /proc/mounts;echo $?`" != "0" ]; then echo "$SD_EXT_DIRECTORY not mounted.. skipping data/data binds" exit fi for dir in data system;do if [ ! -e ${SD_EXT_DIRECTORY}/${dir} ]; then install -m 771 -o 1000 -g 1000 -d ${SD_EXT_DIRECTORY}/${dir} fi if [ "`egrep -q \"/data/${dir}\" /proc/mounts;echo $?`" != "0" ]; then if [ ! -e /data/${dir} ]; then install -m 771 -o 1000 -g 1000 -d /data/${dir} fi du_datadata=`du /data/${dir}|awk '/\/data\/'${dir}'$/ {print $1}'` du_sdextdata=`du ${SD_EXT_DIRECTORY}/${dir}|awk '/\'${SD_EXT_DIRECTORY}'\/'${dir}'$/ {print $1}'` if [ "$du_datadata" -gt "5" -a "$du_sdextdata" -lt "5" ]; then cp -a /data/${dir}/* ${SD_EXT_DIRECTORY}/${dir}/ rm -r /data/${dir}/* fi mount -o bind ${SD_EXT_DIRECTORY}/${dir}/ /data/${dir} fi done EOF install -m 700 -o 0 -g 0 -D /dev/11datadata-binds ${initd}/11datadata-binds sh ${initd}/11datadata-binds return } ApkManager () { cat > /dev/ApkManager.sh << "EOAPKMANAGER" #!/system/bin/sh if [ ! -e /system/bin/ApkManager.sh -o "$1" = "force" ]; then busybox mount -o rw,remount /system cat > /dev/ApkManager.sh << "EOF" #!/system/bin/sh # ApkManager.sh v0.5 me=$0 applist=/dev/appslist.txt printmsg () { ml=`echo -e $1|wc -L` hf="" for i in `seq $ml`;do hf="${hf}=" done echo -e $1|busybox awk -v hf=$hf 'BEGIN{print hf};END{print hf};{print $0};' ###########^^^^^^^ keep that, makes testing on pc easy return } recoverycheck () { if [ "`ls /sbin|grep -q recovery;echo $?`" = "0" ]; then mount -a > /dev/null recoverymode=y else recoverymode=n rootcheck fi return } rootcheck () { if [ "`busybox id -u`" != "0" ]; then echo -e "root is required to run this script\ntype\nsu\nand then run again" exit 1 fi return } internallinks () { # make sure we have dir and links for internel apps for dir in app_i app-private_i;do if [ ! -e /data/${dir} ]; then install -m 771 -o 1000 -g 1000 -d /data/${dir} fi for apk in `find /data/${dir} -type f`;do ln -sf $apk `dirname $apk|sed -e s/data/sd-ext/ -e s/_i//`/`basename $apk` done done return } dupecleaner () { for i in `find /sd-ext/app/ /sd-ext/app-private /data/app-private_i /data/app_i -name "*apk" -type f`;do apk=`basename $i` echo "checking ${i}..." if [ "`grep -q $apk /data/system/packages.xml;echo $?`" = "1" ]; then echo -e "$apk is not listed in packages.xml\nremoving .." rm $i else echo "OK.." fi done return } movefroyocfg () { if [ "`mount|grep -c \"/mnt/asec/\"`" != "0" ]; then printmsg "move FroYo FAT installed apps to /sd-ext? (y/n)\nit can be a little slow, so if your in a rush\nthen answer n, you can always run the script again later" read a if [ "$a" = "n" ]; then printmsg "FroYo FAT 2 sd-ext will be skipped" froyo2sdext=n elif [ "$a" = "y" ]; then printmsg "FroYo fat apps will be moved to sd-ext" froyo2sdext=y else printmsg "please enter y or n" movefroyocfg fi fi return } fat2ext () { for apk in `find /mnt/asec/ -type d|grep -v asec/\$`;do echo "moving `basename ${apk}.apk`" if [ -e /mnt/secure/asec/smdl2tmp1.asec ]; then rm /mnt/secure/asec/smdl2tmp1.asec fi time pm install -f -r ${apk}/pkg.apk done return } menu () { if [ "$recoverymode" = "y" ]; then return fi find /data/app_i /data/app-private_i /sd-ext/app /sd-ext/app-private -type f -name "*apk" -exec ls -lh {} \; \ |awk 'sub(/\/sd-ext/,"sdext /sd-ext") sub(/\/data/,"Data /data") ( ++c ) {print "["c"] \t"$9"\t"$5"\t"$10};' > $applist apkcount=`sed -n '$=' $applist` if [ "$apkcount" = "" ]; then printmsg "no apps to manage yet" return fi #awk 'sub(/\/.+ap.+\//,"") sub(/-.\.apk/,"")' $applist #show the silly froyo number thing #awk 'sub(/\/.+ap.+\//,"") sub(/\.apk/,"")' $applist # better formating awk '{sub(/\/.+ap.+\//,"") sub(/\.apk/,"")};{printf "%5s %-5s %8s %s",$1,$2,$3,$4"\n"}' $applist dataAvailable=`df |awk '/\ \/data$/ {print $4}'` sdextAvailable=`df |awk '/\/sd-ext$/ {print $4}'` dataAvailable4human=`echo $dataAvailable|awk '{printf "%7.1f" "%c",$1/1024,"M"}'` sdextAvailable4human=`echo $sdextAvailable|awk '{printf "%7.1f" "%c",$1/1024,"M"}'` printmsg "Available space on\n/data = $dataAvailable4human\t/sd-ext = $sdextAvailable4human" printmsg "List the app numbers you wish to move\neg:10 12 45\nor use 'keyword'\ne.g. swype twit\n0 to exit" #Toggle BetterToggle return } BetterToggle () { #START BetterToggle functions BToggle () { # for app in $toggle;do for app in $@;do test=`echo $app|awk '{if ( int($1) == 0 ) ( $1 = $1 ) else ( $1 = "\\\["$1"\\\]")} {print}'` apps2move=$(awk '/'$test'/ {print $4 };' $applist) if [ "`echo $apps2move |wc -w`" -gt "1" ]; then # awk '/'$test'/ {print $0 };' $applist awk '{sub(/\/.+ap.+\//,"") sub(/\.apk/,"")};/'$test'/ {printf "%5s %-5s %8s %s",$1,$2,$3,$4"\n"}' $applist echo "More than one app in \"$app\" filter" echo "do you want to toggle all of them (y/n)" ConfirmFilter elif [ "`echo $apps2move |wc -w`" = "0" ]; then echo "no apps found in \"$app\" filter" fi move="$(echo $move `awk '/'$test'/ {print $4 };' $applist`)" done return } ConfirmFilter () { read a if [ "$a" = "y" ] then echo "ok, will toggle them all" return elif [ "$a" = "n" ] then RedefineFilter else echo "please Answer y or n" ConfirmFilter fi return } RedefineFilter () { toggle=`echo toggle|sed s/$app//` echo "please enter numbers or new filter" read minitoggle toggle=`echo $toggle $minitoggle` BToggle `echo $minitoggle` return } # END BetterToggle functions move="" if [ "$#" = "0" ]; then read toggle if [ "$toggle" = "0" ]; then return fi BToggle `echo $toggle` else BToggle `echo $toggle` fi toData="" toSdext="" for app in $toggle;do test=`echo $app|awk '{if ( int($1) == 0 ) ( $1 = $1 ) else ( $1 = "\\\["$1"\\\]")} {print}'` toSdext="${toSdext} `awk '/'$test'/ {print $4}' $applist|grep -v \/data\/`" toData="${toData} `awk '/'$test'/ {print $4}' $applist|grep -v \/sd-ext\/`" intcount=`echo $toData|sed s/\ /"\n"/g|grep sd-ext|sed -n '$='` done moveapps menu return } moveapps () { for i in toSdext toData;do eval files=\$${i} if [ "`echo $files|grep -q apk;echo $?`" != "0" ]; then eval ${i}Size=0 else eval ${i}Size=`du -c $files|awk '/total/ {print $1}'` fi done # thanks to Mister Opinion # http://forum.cyanogenmod.com/user/34339-mister-opinion/ # for point bug out http://forum.cyanogenmod.com/topic/2636-froyo-apps2sdext-2010-08-12-new-v12-include-apkmanager/page__view__findpost__p__40320 dataAvailable=`df |awk '/\ \/data$/ {print $4}'` sdextAvailable=`df |awk '/\/sd-ext$/ {print $4}'` datapostmove=`expr $dataAvailable - \( $toDataSize - $toSdextSize \)` sdextpostmove=`expr $sdextAvailable - \( $toSdextSize - $toDataSize \)` if [ "$datapostmove" -lt "10240" ]; then printmsg "It looks like free space on data is going to fall below 10mb\nare you sure you want to continue? (y/n)" read a if [ "$a" = "y" ]; then printmsg "OK, continuing" else printmsg "will skip moving apps to internal" movetointernal=n fi fi if [ "$sdextpostmove" -lt "0" ]; then printmsg "not going to have enough space on sd-ext\nskipping" movetosdext=n fi #make sure we don't have duplicates for app in $move;do move="$app `echo $move|sed s~$app~~g`" done for app in $move;do app=`basename $app` location=`awk '/'$app'/ {print $2}' $applist` apk=`awk '/'$app'/ {print $4}' $applist` if [ "$location" = "Data" ]; then if [ "$movetosdext" != "n" ]; then echo "moving ${apk}..." find `dirname $apk|sed -e s/data/sd-ext/ -e s/_i//` -type l -name "`basename $apk`" -exec rm {} \; mv $apk `dirname $apk|sed -e s/data/sd-ext/ -e s/_i//`/ if [ "$?" != "0" ]; then echo "moving $apk failed.. relinking." ln -s $apk `dirname $apk|sed -e s/data/sd-ext/ -e s/_i//`/`basename $apk` fi fi elif [ "$location" = "sdext" ]; then if [ "$movetointernal" != "n" ]; then echo "moving ${apk}..." mv $apk `dirname $apk|sed s/sd-ext/data/`_i/ if [ "$?" != "0" ]; then echo "moving $apk failed... not preformining link" else ln -sf `echo $apk|sed -e 's/sd-ext/data/' -e 's~/~_i/~3'` `dirname $apk`/ fi fi else return fi done return } if [ "`echo $@ |egrep -q \"dupefix|fixdupe|fd|df\";echo $?`" = "0" ]; then dupecleaner exit fi recoverycheck if [ "$recoverymode" = "n" ]; then movefroyocfg if [ "$froyo2sdext" = "y" ]; then fat2ext fi else printmsg "FroYoFat2sdext is not available in recovery" fi internallinks menu if [ -e "$applist" ]; then rm $applist fi printmsg "use `basename $me` if to manage apps" EOF install -g 0 -o 0 -m 755 /dev/ApkManager.sh /system/bin/ApkManager.sh ln -sf /system/bin/ApkManager.sh /system/bin/apkmanager.sh busybox mount -o ro,remount /system echo "ApkManager installed" fi EOAPKMANAGER install -m 700 -g 0 -o 0 -D /dev/ApkManager.sh /sd-ext/userinit.d/55ApkManager rm /dev/ApkManager.sh sh /sd-ext/userinit.d/55ApkManager force sh /system/bin/ApkManager.sh return } printmsg () { ml=`echo -e $1|wc -L` hf="" for i in `seq $ml`;do hf="${hf}=" done echo -e $1|busybox awk -v hf=$hf 'BEGIN{print hf};END{print hf};{print $0};' return } # end FroYo apps2sdext Functions version="1.36" printmsg "a2sd for FroYo version $version" if [ "`echo $@ |egrep -q \"dupefix|fixdupe|fd|-fd\";echo $?`" = "0" ]; then printmsg "The duplicate fixer has been moved into ApkManager.sh\nuse:\nsu\napkmanager.sh -fd\nto \'fix\' duplicates" exit fi recoverycheck fsdextmnt a2sdbind ApkManager printmsg "FroYo apps2sdext complete..\nyou may need to reboot to see apps\nwhich were already on /sd-ext" if [ "$datadatabind" = "y" ]; then printmsg "bind mounting /data/data with /sd-ext/data\nchanges will take effect on next boot" elif [ "$datadatabind" = "n" ]; then printmsg "skipping data/data bind mount\nIf you are running low on space then\njust rerun this script to see how much its grown.." fi if [ "$mountsd" = "failed" ]; then custbak=/system/etc/custom_backup_list.txt if [ ! -e "$custbak" -o "`grep -q \"etc/init.d/05mountsd\" $custbak;echo $?`" != "0" ]; then remountrw echo "etc/init.d/05mountsd" >> $custbak else printmsg "It looks like you already have 05mountsd backup/restore on\nbut .. it seems it failed as /sd-ext was not mounted on boot\nNot sure of what I can do right now.. Firerat 2010-11-03\nif /sd-ext keeps failing to mount on boot .. make some noise! ;)" fi fi return } DCbind2Cache () { if [ "$SPL" = "Danger" ]; then printmsg -e "Nah.. DangerSPL only has 30mb /cache\nBind mounting from it would mess stuff up\nSkipping" return fi remountrw find /sd-ext/userinit.d /data/local/ /etc/init.d -name 10bind-dc -exec rm {} \; if [ "$rev" = "1" ]; then printmsg "10bind-dc removed" return fi cat > /dev/10bind-dc << "EOF" #!/system/bin/sh if [ "`mount |grep -q dalvik-cache;echo $?`" = "1" ]; then if [ -e /cache/dalvik-cache ] && [ ! -d /cache/dalvik-cache ]; then rm /cache/dalvik-cache fi if [ ! -d /cache/dalvik-cache ]; then install -m 771 -o 1000 -g 1000 -d /cache/dalvik-cache fi rm /data/dalvik-cache/* busybox mount -o bind /cache/dalvik-cache /data/dalvik-cache fi EOF install -m 700 -D /dev/10bind-dc ${initd}/10bind-dc printmsg "${initd}/10bind-dc installed" return } DCbind2SD () { remountrw find /sd-ext/userinit.d /data/local/ /etc/init.d -name 10bind-dc -exec rm {} \; if [ "$rev" = "1" ]; then printmsg "10bind-dc removed" return fi cat > /dev/10bind-dc << "EOF" #!/system/bin/sh if [ "`mount |grep -q dalvik-cache;echo $?`" = "1" ]; then if [ "`egrep -q "sd-ext|/system/sd" /proc/mounts;echo $?`" = "0" ]; then SD_EXT_DIRECTORY=`egrep "sd-ext|/system/sd" /proc/mounts|awk '{ print $2 }'` else echo "sdext not mounted.. nothing to bind with.. exiting" exit fi if [ -e $SD_EXT_DIRECTORY/dalvik-cache ] && [ ! -d $SD_EXT_DIRECTORY/dalvik-cache ]; then rm $SD_EXT_DIRECTORY/dalvik-cache fi if [ ! -d $SD_EXT_DIRECTORY/dalvik-cache ]; then install -m 771 -o 1000 -g 1000 -d $SD_EXT_DIRECTORY/dalvik-cache fi rm /data/dalvik-cache/* busybox mount -o bind $SD_EXT_DIRECTORY/dalvik-cache /data/dalvik-cache else exit 0 fi EOF install -m 700 -D /dev/10bind-dc ${initd}/10bind-dc printmsg "${initd}/10bind-dc installed\nchanges will take effect on next boot" return } fb () { # Edit trout.prop to get sync option in Facebook 1.2.x # Credits : SilverSurfR and Skri11a prop=/system/build.trout.prop if [ `grep -q "Facebook 1.2.x Sync" $prop;echo $?` != "0" ]; then remountrw sed \ -e '/ro.product.name=kila/ i #ro.product.name=kila' \ -e '/ro.product.name=kila/ i #Facebook 1.2.x Sync on G1 Credits : SilverSurfR and Skri11a' \ -e '/ro.product.device=dream/ i #ro.product.device=dream' \ -e '/ro.product.device=dream/ i #Facebook 1.2.x Sync on G1 Credits : SilverSurfR and Skri11a' \ -e 's/ro.product.name=kila/ro.product.name=opal/' \ -e 's/ro.product.device=dream/ro.product.device=sapphire/' \ -i $prop printmsg "$prop Patched for Facebook 1.2.x sync\nchanges will take effect on next boot\nenable sync in Facebook app settings" else printmsg "$prop appears to have already been patched" fi return } fixp () { # new patch, universal i.e. cm5 cm6 or any ( will find mountpoint ) remountrw for i in `find /system -iname "fix_permiss*"`;do if [ "`grep -q fix $i;echo $?`" = "0" ]; then if [ "`grep -q SD_EXT_DIRECTORY $i;echo $?`" != "0" ]; then sed -e '/VERSION\=\"/ a # sdext mount point\nSD_EXT_DIRECTORY=\`egrep \"sd-ext\|\/system\/sd\" \/proc\/mounts\|awk \"{ print $2 }\"\`\nif \[ \"\$SD_EXT_DIRECTORY\" \= \"\" \]\;\nthen\n\tSD_EXT_DIRECTORY=\/sd-ext\nfi' -e s~/system/sd~\$SD_EXT_DIRECTORY~g $i -i printmsg "$i Patched.." else printmsg "$i is already Patched.." fi fi done return } legacysd () { if [ ! -d /system/sd ]; then remountrw install -d /system/sd printmsg "legacy /system/sd mount point created\nrecovery images will now support sd ext backup" else printmsg "/system/sd already exists" fi return } lwp () { if [ "$rev" = "1" ]; then remountrw for i in hw3d.xml 15GPU_perms;do find /sd-ext/userinit.d /data/local/ /etc/ -name $i -exec rm {} \; echo "$i removed" done return fi #if [ ! -e ${initd}/15GPU_perms ]; #then cat > ${initd}/15GPU_perms << "EOF" #!/system/bin/sh # restrictive Perms for GPU - Firerat 2010-05-05 # NB, see also /system/etc/permissions/hw3d.xml if [ -e /dev/msm_hw3dc ]; then chmod 660 /dev/msm_hw3d* #dumb down gpu permisions chown root.graphics /dev/msm_hw3d* fi # NB, this is a bit ugly packages=/data/system/packages.xml app=com.rovio.angrybirds if [ `grep -q ${app}s ${packages};echo $?` = "0" ]; then appUID=`awk -F\" '/'${app}'/ {print $12}' ${packages}` chown ${appUID} /dev/msm_hw3d* fi EOF chmod 700 ${initd}/15GPU_perms printmsg "${initd}/15GPU_perms installed\nchanges will take effect on next boot" if [ ! -e /system/etc/permissions/hw3d.xml ]; then remountrw cat > /system/etc/permissions/hw3d.xml << "EOF" EOF chmod 644 /system/etc/permissions/hw3d.xml printmsg "hw3d.xml installed\nchanges will take effect on next boot" else printmsg "hw3d.xml is already installed" fi cat >> ${initd}/15GPU_perms << "EOF" if [ ! -e /system/etc/permissions/hw3d.xml ]; then mount -o rw,remount /system cat > /system/etc/permissions/hw3d.xml << "EOhw3d" EOF cat /system/etc/permissions/hw3d.xml >> ${initd}/15GPU_perms cat >> ${initd}/15GPU_perms << "EOF" EOhw3d chmod 644 /system/etc/permissions/hw3d.xml mount -o ro,remount /system fi EOF return } remount () { # remount installer - Firerat 2010-05-04 remountrw cat > /system/bin/remount << "EOF" #!/system/bin/sh # make system files rw/ro - Firerat 2010-04-13 # symlink options - Firerat 2010-05-01 # sectioned into functions, was bored - Firerat 2010-05-04 Version=0.4.2 MOUNT_CMD="busybox mount" GetMPs () { if [ -e "/system/csys" ]; then mps="/system /system/csys" else mps="/system" fi return } GetMode () { if [ `basename $0` = "rwsystem" -o "$opt" = "rw" ]; then mode=rw elif [ `basename $0` = "rosystem" -o "$opt" = "ro" ]; then mode=ro else echo -e "remount system - usage:\n\nMount system readwrite\n remount rw\nor\n rwsystem\n\nMount system readonly\n remount ro\nor\n rosystem\n\ncurrent system mount status" DisplayMP exit 0 fi return } DisplayMP () { for mp in $mps ;do echo "`$MOUNT_CMD|grep \ ${mp}\ `" done return } Remount () { for mp in $mps ;do $MOUNT_CMD -o $mode,remount ${mp} if [ "$?" != "0" ]; then echo "Mounting ${mp} Failed" exitcode="1" fi done DisplayMP return } Exit () { if [ "${exitcode}" != "0" ]; then exit 1 else exit 0 fi } testroot () { if [ `busybox id -u` != "0" ]; then echo -e "root is required to run this script\ntype\nsu\nand run again" exit 1; fi return } opt=$1 testroot GetMPs GetMode Remount Exit EOF chmod 755 /system/bin/remount for i in rw ro;do if [ -e /system/bin/${i}system ]; then rm /system/bin/${i}system fi ln -s remount /system/bin/${i}system done printmsg "remount rwsystem and rosystem scripts installed" return } sdextmnt () { if [ "`grep -q sd-ext /proc/mounts;echo $?`" = "0" -a -e "/system/etc/init.d/05mountsd" ]; then printmsg "/sd-ext is already mounted, so skipping install\nif you want/need to force the install\n use the force sd-ext mount option ( fsdext )" return fi # install sd-ext mount script ( from cm5 ) cat > /dev/05mountsd << "EOF" #!/system/bin/sh # # mount ext[234] partition from sd card BB="logwrapper busybox"; if [ ! -d /sd-ext ]; then $BB mount -o rw,remount / install -m 774 -o 1000 -g 1000 -d /sd-ext $BB mount -o ro,remount / fi if [ "$SD_EXT_DIRECTORY" = "" ]; then SD_EXT_DIRECTORY=/sd-ext; fi; # find first linux partition on SD card for mmcblk in 0 1;do MMC=/dev/block/mmcblk${mmcblk} # wait for the device to settle COUNT=6; until [ -b "$MMC" ] || [ $COUNT -lt 1 ]; do sleep 1; COUNT=$((COUNT-1)); done; # if no mmcblkx try to fudge it frfudge=y if [ ! -b "$MMC" -a "$frfudge" = "y" ]; then base_minor=$(expr 8 \* $mmcblk) mknod ${MMC} b 179 $base_minor chmod 600 ${MMC} for minor in 1 2 3;do if [ ! -b "${MMC}p${minor}" ]; then mknod ${MMC}p${minor} b 179 $(expr $base_minor \+ $minor) chmod 600 ${MMC}p${minor} fi done fi if [ -b "$MMC" ]; then FDISK="busybox fdisk" PARTITION=`$FDISK -l $MMC | awk '/^\// && $5 == 83 {print $1;exit;}'` if [ -b "$PARTITION" ]; then log -p i -t mountsd "$PARTITION = linux partition" break fi fi done if [ "$PARTITION" = "" ]; then log -p i -t mountsd "Valid linux partition not found" exit fi log -p i -t mountsd "Checking filesystems.."; # fsck the sdcard filesystem first if [ -x `which e2fsck` ]; then e2fsck -y $PARTITION;e2fsck_exitcode=$? else echo "executable e2fsck not found, assuming no filesystem errors" e2fsck_exitcode=0 fi # set property with exit code in case an error occurs setprop cm.e2fsck.errors $e2fsck_exitcode; if [ "$e2fsck_exitcode" -lt 2 ]; then # mount and set perms $BB mount -o noatime,nodiratime -t auto $PARTITION $SD_EXT_DIRECTORY; if [ "$?" = 0 ]; then $BB chown 1000:1000 $SD_EXT_DIRECTORY; $BB chmod 771 $SD_EXT_DIRECTORY; log -p i -t mountsd "$SD_EXT_DIRECTORY successfully mounted"; else log -p e -t mountsd "Unable to mount filesystem for $SD_EXT_DIRECTORY!"; fi else log -p e -t mountsd "Unable to repair filesystem, disabling apps2sd"; fi EOF if [ "`grep -q sd-ext /proc/mounts;echo $?`" != "0" ]; then sh /dev/05mountsd if ! awk -vDIR="$SD_EXT_DIRECTORY" '$2 == DIR { exit 1; }' /proc/mounts ; then # create directories if necessary. for i in app app-private dalvik-cache; do if [ ! -d $SD_EXT_DIRECTORY/$i ] then install -o 1000 -g 1000 -m 771 -d $SD_EXT_DIRECTORY/$i log -p i -t a2sd "$SD_EXT_DIRECTORY/$i created" fi done fi fi mount -o rw,remount /system install -m 700 -D /dev/05mountsd /system/etc/init.d/05mountsd printmsg "mount sd-ext installed" custbak=/system/etc/custom_backup_list.txt if [ ! -e "$custbak" -o "`grep -q \"etc/init.d/05mountsd\" $custbak;echo $?`" != "0" ]; then mountrw echo "etc/init.d/05mountsd" >> $custbak else printmsg "It looks like you already have 05mountsd backup/restore on\nbut .. it seems it failed as /sd-ext was not mounted on boot\nNot sure of what I can do right now.. Firerat 2010-11-03\nif /sd-ext keeps failing to mount on boot .. make some noise! ;)" fi return } shabang () { remountrw for droidscript in am pm bmgr ime input monkey svc ;do droidscript=/system/bin/${droidscript} if [ "`grep -q '#!/system/bin/sh' ${droidscript};echo $?`" = "0" ]; then echo "${droidscript} already has a shabang" else sed '\/Script\ to\ start/ i #!\/system\/bin\/sh' -i ${droidscript} echo "${droidscript} patched with shabang" fi done return } swap () { swappy_install () { remountrw if [ "$recoverymode" = "y" ]; then a=20 useswapdefaults=y else useswapdefaults=n fi cat > /dev/swappy << "EOF" #!/system/bin/sh swappy () { echo `awk '{ print "current swappiness="$1 }' /proc/sys/vm/swappiness` echo "what swappiness would you like?" echo "enter a number between 1 and 100" read a if [ "`expr $a + 1;echo $?`" = "2" ]; then echo "Number beween 1 and 100 required" swappy if [ "$a" -lt "0" -o "$a" -gt "100" ]; then echo "Number beween 1 and 100 required" swappy fi if [ "`dirname $swapscript`" = "/system/etc/init.d" ]; then mount -o rw,remount /system fi fi sed -e s/^SWAPPINESS=../SWAPPINESS=$a/ -e s/^SWAPPINESS=.../SWAPPINESS=$a/ $swapscript -i echo $a > /proc/sys/vm/swappiness echo `awk '{ print "swappiness="$1 }' /proc/sys/vm/swappiness` return } getsdext () { SD_EXT_DIRECTORY=`egrep "/sd-ext|/system/sd" /proc/mounts|awk '{ print $2 }'` return } mkswapfile () { if [ "$SD_EXT_DIRECTORY" = "" ]; then return fi swappartsize=`fdisk -l /dev/block/mmcblk0|awk '/swap$/ {print int($4/1024)}'` if [ -e "${SD_EXT_DIRECTORY}/swapfile.swp" ]; then swapfilesize=`du -h ${SD_EXT_DIRECTORY}/swapfile.swp` else swapfilesize=0 fi if [ "$swapfilesize" != "0" ]; then echo "current swapfile = $swapfilesize" echo "would you like to change this? (y/n)" elif [ "$swappartsize" != "" ]; then echo "current swap partition = $swappartsize" echo "would you like to install a swapfile instead? (y/n)" else echo "you currently have no swapfile or swap partition" echo "would you like to create a swapfile? (y/n)" fi read a if [ "$a" = "y" ]; then maxswapfile=`busybox df -h |awk '$6 == "'$SD_EXT_DIRECTORY'"{ gsub(/M/,""); printf "%d",$4*.7}'` echo maxswapfile $maxswapfile swapfilesize=`echo $swapfilesize|awk 'gsub(/M/,""){printf "%d",$1}'` if [ "$swapfilesize" = "" ]; then swapfilesize=0 fi echo swapfilesize $swapfilesize maxswapfile=`expr $maxswapfile + $swapfilesize` echo maxswapfile $maxswapfile echo "what size would you like?" echo "max is ${maxswapfile}M which is approx 70% of the space available on your sd-ext" echo "but don't make it too big!!" getswapfilesize elif [ "$a" = "n" ]; then echo "Well, you know what to do if you want to ;)" return else echo "please Answer (y/n)" mkswapfile fi return } getswapfilesize () { read size echo size $size if [ "$size" -gt "0" -a "$size" -lt "`expr $maxswapfile + 1`" ]; then swapstop createswapfile startswap else echo "please enter a number between 1 and $maxswapfile" getswapfilesize fi return } swapstop () { for Swap in `awk '!/Filename/ {print $1}' /proc/swaps`;do echo "turning current swap off" swapoff $Swap & swaptotal=1 while [ "$swaptotal" != "0" ];do swaptab=`free|awk '/Swap/ {printf $2" "$3}'` echo $swaptab|awk '{printf "\rswap used "$2" "}' swaptotal=`echo $swaptab|awk '{print $1}'` done echo "" done return } createswapfile () { echo "creating ${SD_EXT_DIRECTORY}/swapfile.swp..." echo "busybox dd if=/dev/zero of=${SD_EXT_DIRECTORY}/swapfile.swp bs=1024k count=$size" busybox dd if=/dev/zero of=${SD_EXT_DIRECTORY}/swapfile.swp bs=1024k count=$size & sizebytes=`expr 1048576 \* $size` LSswapfile="0" lenght=`echo $sizebytes|awk '(l=length($1)) {print l}'` while [ "$sizebytes" -gt "$LSswapfile" ];do LSswapfile=`ls -l ${SD_EXT_DIRECTORY}/swapfile.swp|awk '{print $5}'` echo|awk '{printf "% 8s %s %s","\r"'$LSswapfile'/1024,"/",'$sizebytes'/1024}' done echo "" mkswap ${SD_EXT_DIRECTORY}/swapfile.swp return } startswap () { $swapscript return } opt=$1 me=$0 getsdext swapscript=`find ${SD_EXT_DIRECTORY}/userinit.d /data/local/ /system/etc/init.d -name 25Swap` # hoping we don't have any more that just the one if [ "$opt" = "off" ]; then swapstop chmod 000 $swapscript echo "swap on boot turned off" echo "$me on to turn back on" exit fi if [ "$opt" = "on" ]; then chmod 700 $swapscript startswap fi swappy mkswapfile echo "swappy complete" echo "use" echo "$me off # to turn swap off" echo "$me on # to turn swap on" EOF install -o 0 -g 0 -m 700 /dev/swappy /system/bin/swappy cat >> ${initd}/25Swap << "EOF" if [ ! -e /system/bin/swappy ]; then mount -o rw,remount /system cat > /dev/swappy << "EOswappy" EOF cat /system/bin/swappy >> ${initd}/25Swap cat >> ${initd}/25Swap << "EOF" EOswappy install -o 0 -g 0 -m 700 /dev/swappy /system/bin/swappy rm /dev/swappy mount -o ro,remount /system fi EOF printmsg "swappy utility installed\njust run swappy if you want to change your swappiness" if [ "$useswapdefaults" = "n" ]; then sh /system/bin/swappy fi return } # make sure we don't have dupes floating around remountrw find /sd-ext/userinit.d /data/local/ /etc/init.d -name 25Swap -exec rm {} \; if [ "$rev" = "1" ]; then echo "25Swap removed" return fi if [ ! -e ${initd}/25Swap ]; then cat > ${initd}/25Swap << "EOF" #!/system/bin/sh # Autoswap - Firerat 2010-05-05 # thought about doing the partition check as per cm5 05mountsd # but then I remembered that I couldn't do that with other busyboxes # which is why I used a 'suck and see' in the past # 2010-08-12 Firerat, added swapfile support FindSwap () { SWAPPINESS=20 MMC=/dev/block/mmcblk0 if [ ! -b "$MMC" ]; then mknod ${MMC} b 179 0 chmod 600 ${MMC} for i in 1 2 3;do mknod ${MMC}p${i} b 179 $i chmod 600 ${MMC}p${i} done fi if [ "`sed -n '$=' /proc/swaps`" -gt "1" ]; then echo "Swap appears to be already setup, skipping checks" return else if [ "`egrep -q "sd-ext|/system/sd" /proc/mounts;echo $?`" = "0" ]; then SD_EXT_DIRECTORY=`egrep "/sd-ext|/system/sd" /proc/mounts|awk '{ print $2 }'` fi if [ -e ${SD_EXT_DIRECTORY}/swapfile.swp ]; then SWAPFILE=${SD_EXT_DIRECTORY}/swapfile.swp else SWAPFILE="" fi for isitswap in $SWAPFILE `ls /dev/block/mmcblk0p*` ; do swapon $isitswap 2>/dev/null if [ "$?" = "0" ]; then echo "$isitswap is swap" echo $SWAPPINESS > /proc/sys/vm/swappiness break else echo "$isitswap is not swap" fi done fi return } FindSwap EOF chmod 700 ${initd}/25Swap printmsg "${initd}/25Swap installed" else printmsg "${initd}/25Swap already installed" fi swappy_install return } data_data_bind () { if [ "$rev" = "1" ]; then if [ -e "/sd-ext/userinit.d/11datadata-binds" ]; then printmsg "Please use\nsh /sd-ext/userinit.d/11datadata-binds off\nto uninstall ddb" return else printmsg "ddb does not appear to be installed" retun fi fi cat > /dev/11datadata-binds << "EOF" #!/system/bin/sh if [ "$1" = "off" ]; then FreeData=`df|awk '$6 == "/data" {print $4}'` SizeOnSdext=`du -cs /sd-ext/data /sd-ext/system|awk '$2 == "total" {print $1}'` if [ "$FreeData" -gt "$SizeOnSdext" ]; then cat > /data/firstboot.sh << "ddboff" echo "Uninstalling /data/data binds" sh /system/etc/init.d/05mountsd for i in data system;do cp -a /sd-ext/${i}/* /data/${i}/ rm -r /sd-ext/${i} done rm /sd-ext/userinit.d/11datadata-binds ddboff echo "reboot for changes to take effect" exit else echo "You do not have enough space available on /data" echo "Free space on data = `echo $FreeData|awk '{printf "%.2f" "%c",$1/1024,"M"}'`" echo "size on /sd-ext = `echo $SizeOnSdext|awk '{printf "%.2f" "%c",$1/1024,"M"}'`" echo "" echo "exiting without changes" exit fi fi SD_EXT_DIRECTORY=`egrep "/sd-ext|/system/sd" /proc/mounts|awk '{ print $2 }'` if [ "$SD_EXT_DIRECTORY" = "" ]; then SD_EXT_DIRECTORY=/sd-ext fi if [ "`egrep -q $SD_EXT_DIRECTORY /proc/mounts;echo $?`" != "0" ]; then echo "$SD_EXT_DIRECTORY not mounted.. skipping data/data binds" exit fi for dir in data system;do if [ ! -e ${SD_EXT_DIRECTORY}/${dir} ]; then install -m 771 -o 1000 -g 1000 -d ${SD_EXT_DIRECTORY}/${dir} fi if [ "`egrep -q \"/data/${dir}\" /proc/mounts;echo $?`" != "0" ]; then if [ ! -e /data/${dir} ]; then install -m 771 -o 1000 -g 1000 -d /data/${dir} fi du_datadata=`du /data/${dir}|awk '/\/data\/'${dir}'$/ {print $1}'` du_sdextdata=`du ${SD_EXT_DIRECTORY}/${dir}|awk '/\'${SD_EXT_DIRECTORY}'\/'${dir}'$/ {print $1}'` if [ "$du_datadata" -gt "5" -a "$du_sdextdata" -lt "5" ]; then cp -a /data/${dir}/* ${SD_EXT_DIRECTORY}/${dir}/ rm -r /data/${dir}/* fi mount -o bind ${SD_EXT_DIRECTORY}/${dir}/ /data/${dir} fi done EOF install -m 700 -o 0 -g 0 -D /dev/11datadata-binds ${initd}/11datadata-binds sh ${initd}/11datadata-binds return } rba () { if [ "$rev" = "1" -a -e "/sd-ext/userinit.d/99randomBA" ]; then rm /sd-ext/userinit.d/99randomBA printmsg "random bootanimations script removed" return fi # just for fun, random bootanimation if [ "`grep -q sd-ext /proc/mounts;echo $?`" != "0" ]; then echo "/sd-ext is not mounted" echo "you will need somewhere to put bootanimations!" install -d /data/local/bootanimations printmsg "created /data/local/bootanimations\nput your collection in there" fi cat > /dev/99randomBA << "EOF" #!/system/xbin/bash # had to be bash, sh didn't have $RANDOM bootanimDir=/sd-ext/bootanimations if [ ! -e "$bootanimDir" -a -e "/data/local/bootanimations" ]; then bootanimDir=/data/local/bootanimations else echo "bootanimations directory not found" echo "exiting.." exit fi if [ -e /system/media/bootanimation.zip ]; then bootaminations="/system/media/bootanimation.zip" fi bootaminations="$bootaminations `find $bootanimDir -name \"*.zip\"`" No_bootaminations=`echo $bootaminations|awk '{ total = total + NF }; END {print total}'` if [ "$No_bootaminations" = "0" ]; then exit fi randomBA=`echo $[ ( $RANDOM % $No_bootaminations ) +1 ]` bootanimation=`echo $bootaminations|awk '{print $'$randomBA'}'` ln -sf $bootanimation /data/local/bootanimation.zip echo "random bootanimation = $bootanimation" EOF install -m 700 -D /dev/99randomBA /sd-ext/userinit.d/99randomBA if [ ! -d /sd-ext/bootanimations ]; then install -m 666 -d /sd-ext/bootanimations fi return } AIOMenu () { TheAIOMenu0="##################################################################" TheAIOMenu01="# All In One Patcher AIOMenu $Version" TheAIOMenu02="##################################################################" TheAIOMenu1="1: :X:a2sd:FroYo Apps 2 sdext" TheAIOMenu2="2: :X:sdext:sd-ext mount for CM6" TheAIOMenu3="3: :X:lwp:Live Wallpaper (work around) \*" TheAIOMenu4="4: :X:lsd:Leagacy /system/sd mount point" TheAIOMenu5="5: :X:swap:swap " TheAIOMenu6="6: :X:shabang:shabang" TheAIOMenu7="7: :X:remount:system remount script" TheAIOMenu8="8: :X:fb:Facebook 1.2.x sync for G1/Dream/Trout" TheAIOMenu9="9: :X:fixp:fix_permissions patch ( for CM5.0.x )" TheAIOMenu10="10: :X:dc2x:dalvik-cache bind mount " TheAIOMenu11="11: :X:ddb:/data/(data,system) bind mount " TheAIOMenu12="12: :X:rba:random bootanimations" TheAIOMenu13="13: :X:fsdext:force sd-ext mount script" TheAIOMenu03="------------------------------------------------------------------" TheAIOMenu04="Enter the Number ( separate multiple with space )" TheAIOMenu05="Enter 0 to install sellected" TheAIOMenu06="Enter 99 to uninstall sellected ( only \* supported )" MenuItems=13 displaymenu return } option () { read a if [ "$a" = "0" -o "$a" = "99" ]; then c=1 while [ "$c" != "`expr $MenuItems + 1`" ];do eval temp=\$TheAIOMenu${c} flags="$flags `echo $temp|awk -F: '$2 == "X" {print $4}'`" c=`expr $c + 1` done if [ "$a" = "99" ]; then flags="$flags rev" echo $flags echo $flags echo $flags echo $flags fi return fi for i in $a;do eval temp=\$TheAIOMenu${i} eval TheAIOMenu${i}=\"`echo $temp|awk -F: '{t = $2;$2 = $3;$3 = t;print $1":"$2":"$3":"$4i":"$5}'`\" done displaymenu return } displaymenu () { reset echo $TheAIOMenu0 echo $TheAIOMenu01 echo $TheAIOMenu02 c=1 while [ "$c" != "`expr $MenuItems + 1`" ];do eval temp=\$TheAIOMenu${c} echo $temp |awk -F: '{ print "["$1"]\t["$2"] ("$4")\t"$5 }' c=`expr $c + 1` done echo $TheAIOMenu03 echo $TheAIOMenu04 echo $TheAIOMenu05 # undo is broken #echo $TheAIOMenu06 option return } # end Scripts options="lwp swap shabang remount fb fixp lsd fsdext sdext a2sd ddb rba" opt="all" flags=$@ for i in dc2x $options;do opt=`echo ${opt}\|$i` done if [ "`echo $flags|grep -q rev;echo $?`" = "0" ]; then rev="1" else rev="0" fi if [ "`echo $flags|egrep -q \"$opt\";echo $?`" != "0" ]; then AIOMenu # echo "Firerat script installer $Version" # echo "Options:" # echo "a2sd apps2sdext ( for FroYo ) #NEW#" # echo "sdext sdext mount for cm6" # echo "lwp LWP fix *" # echo "lsd create legacy sd mount point" # echo "swap Auto setup swap *" # echo "shabang Patch Android scripts to work with ash" # echo "remount install remount scripts" # echo "fb Patch for Facebook 1.2.x sync on G1" # echo "fixp Patch fix_permissions with new sd mount point" # echo "dc2x DangerSPL : dalvik-cache will be bound with sd-ext *" # echo " NoneDangerSPL : dalvik-cache will be bound with cache *" # echo " MT3G : does nothing" # echo "ddb data/data binds *" # echo "" # echo "all All of the above" # echo "* run-parts required ( autodetected )" # echo "--------------------------------------" # echo "rev