All pastes #2101685 Raw Edit

Miscellany

public text v1 · immutable
#2101685 ·published 2012-01-09 20:26 UTC
rendered paste body
fail() {
	/bin/echo "Failed"
		clear
		/bin/echo "$1"
		exec /bin/sh
}



/bin/echo "Recovery loaded."



if [ "$CARD_PATH" = "" ];then
	CARD_PATH="andboot"
fi;
if [ -d /sdcard/$CARD_PATH ] ; then
	card=/sdcard/$CARD_PATH
else
	card=/sdcard
fi

[ -d /tmp ] || mkdir /tmp
mount $card/tmp /tmp 
[ $? -eq 0 ] || fail "Failed to mount TMP directory. Cannot continue"
mount -t auto -o noatime,nodiratime,rw /dev/block/mmcblk0p2 /system
[ $? -eq 0 ] || fail "Failed to mount SYSTEM partition. Cannot continue"
mount -t auto -o noatime,nodiratime,rw /dev/block/mmcblk0p3 /data
[ $? -eq 0 ] || fail "Failed to mount DATA partition. Cannot continue"
mount -t auto -o noatime,nodiratime,rw /dev/block/mmcblk0p4 /cache
[ $? -eq 0 ] || fail "Failed to mount DATA partition. Cannot continue."

read -s -n3 -p "Press Volume Down SHORTLY to go in CWM Recovery" -t5 keypress
if [ "$keypress" = "[2" ] ; then
		if [ ! -d /cache/recovery ] ; then
			mkdir /cache/recovery
		fi
		mkdir $card/recoveryinstalled
		if cat /proc/cpuinfo | grep -q Kovsky ; then
			echo -n "XPERIA detected"
			mount --bind /sbin/recoveryx /sbin/recovery
		fi
		exec /recovery/init.recovery

else
	if [ -d $card/AndroidApps ] ; then
        echo Copying Applications
        if [ ! -d /data/app ] ; then
                mkdir -m 0771 /data/app
		chown -R 1000:1000 /data/app
        fi
	(cd $card/AndroidApps; for i in *; do if [ ! -f "/data/app/$i" -o "$i" -nt "/data/app/$i" ]; then \
		cp "$i" /data/app; fi done)
fi

cp -ar /init.etc/* /system/etc

LCDDENSITY=`/bin/grep -o "lcd.density=.*" /proc/cmdline | /bin/sed -e "s/.*lcd.density=//g" -e "s/ .*//g"`

if [ "$LCDDENSITY" != "" ] ; then
	DENS2=`grep lcd_density /system/etc/default.prop | sed -e 's/.*=//'`
	if [ "$LCDDENSITY" != "$DENS2" ]; then
		echo Setting ro.sf.lcd_density=$LCDDENSITY
		if [ -z "$DENS2" ]; then
			echo "ro.sf.lcd_density=$LCDDENSITY" >> /system/etc/default.prop
		else
			sed -i /lcd_density/s/=.*/=$LCDDENSITY/ /system/etc/default.prop
		fi
	fi
fi

mount /sdcard/cache /tmp

KAISER=0
DIAMOND=0
WIFI_TI=0
WIFI_BCM=0
XPERIA=0
WVGA=0
HW=`cat /proc/cpuinfo | grep Hardware`
case "$HW" in
    *Kaiser*)
	echo "KAISER detected"
	HW=KAISER
	KAISER=1
	WIFI_TI=1
	;;
    *Polaris*)
	echo "POLARIS detected"
	HW=POLARIS
	KAISER=1
	WIFI_TI=1
	;;
    *Diamond*)
	echo "DIAMOND detected"
	HW=DIAMOND
	DIAMOND=1
	WIFI_TI=1
	;;
    *Raphael*)
	echo "RAPHAEL detected"
	HW=RAPHAEL
	DIAMOND=1
	WIFI_TI=1
	;;
    *blackstone*)
	echo "BLACKSTONE detected"
	HW=BLACKSTONE
	DIAMOND=1
	WIFI_TI=1
	WVGA=1
	;;
    *Topaz*)
	echo "TOPAZ detected"
	HW=TOPAZ
	DIAMOND=1
	WIFI_TI=1
	WVGA=1
	KBD=topa
	;;
    *Kovsky*)
	echo "XPERIA detected"
	HW=KOVSKY
	XPERIA=1
	WIFI_TI=1
	WVGA=1
	;;
    *Rhodium*)
	echo "RHODIUM detected"
	HW=RHODIUM
	DIAMOND=1
	WIFI_BCM=1
	WVGA=1
	;;
    *)
	echo "VOGUE detected"
	HW=VOGUE
	;;
esac

RCSCRIPT=""
RCCONFIG=""

echo "Checking for build type..."
if [ -f /system/hero.build ] ; then
	echo "Hero build detected"
	RCSCRIPT="hero"
	RCCONFIG="hero"
	ln /data/app_s /system/app

elif [ -f /system/eclairhero.build ] ; then
	echo "HERO 2.1 BUILD DETECTED -- ECLAIR"
	RCSCRIPT="eclairhero"
	RCCONFIG="eclairhero"
	mount --bind /lib/eclair/hw /system/lib/hw

elif [ -f /system/eclair.build ] ; then
	echo "Eclair build detected"
	RCSCRIPT="eclair"
	RCCONFIG="eclair"
	mount --bind /lib/eclair/hw /system/lib/hw

elif [ -f /system/froyo.build ] ; then
	echo "Froyo build detected"
	RCSCRIPT="froyo"
	RCCONFIG="froyo"
	mount --bind /lib/froyo/hw /system/lib/hw

elif [ -f /system/gingerbread.build ] ; then
	echo "Gingerbread build detected"
	RCSCRIPT="gingerbread"
	RCCONFIG="gingerbread"

elif [ -f /system/tattoo.build ] ; then
	echo "Tattoo build detected"
	RCSCRIPT="tattoo"
	RCCONFIG="tattoo"

elif [ -f /system/donut.build ] ; then
	echo "Donut build detected"
	RCSCRIPT="donut"
	RCCONFIG="donut"
	mount --bind /lib/donut/hw /system/lib/hw

elif [ -d /system/lib/donut ] ; then
	echo "Donut build detected"
	RCSCRIPT="donut"
	RCCONFIG="donut"

elif [ -f /system/xrom.build ] ; then
	echo "xROM build detected"
	RCSCRIPT="xrom"
	RCCONFIG="xrom"

elif [ -f /system/rogers.build ] ; then
	echo "Rogers build detected"
	RCSCRIPT="rogers"
	RCCONFIG="rogers"

elif [ -f /system/cyanogen.build ] ; then
	echo "cyanogen experimental detected.....eating donuts"
	RCSCRIPT="cyanogen"
	RCCONFIG="cyanogen"

elif [ -f /system/custom.build ] ; then
	echo "Custom init.rc detected"
	cp /system/sysinit.rc /init.cfg/init.sysinit.rc
	RCCONFIG="hero"
	RCSCRIPT="sysinit"
	
else
	echo "Unknown Android build. Assuming Ion variant"
	RCSCRIPT="ion"
	RCCONFIG="ion"

	# for the fake sensors library
	mount /lib/hw /system/lib/hw -o loop
	chmod 666 /dev/input/event0

	if [ $DIAMOND -eq 1 ] ; then
		RCCONFIG="ion.diamond"
	fi
fi

if [ $KAISER -eq 1 ] ; then
	RCSCRIPT="$RCSCRIPT.kaiser"
fi

if [ "$LCDDENSITY" != "" ] ; then
	DENS2=`grep lcd_density /system/etc/default.prop | sed -e 's/.*=//'`
	if [ "$LCDDENSITY" != "$DENS2" ]; then
		echo Setting ro.sf.lcd_density=$LCDDENSITY
		if [ -z "$DENS2" ]; then
			echo "ro.sf.lcd_density=$LCDDENSITY" >> /system/etc/default.prop
		else
			sed -i /lcd_density/s/=.*/=$LCDDENSITY/ /system/etc/default.prop
		fi
	fi
fi
if [ $XPERIA -eq 1 ] ; then
	ROT=`grep hwrotation /system/etc/default.prop | sed -e 's/.*=//'`
	if [ "$ROT" != 180 ]; then
		echo Setting ro.sf.hwrotation=180
		if [ -z "$ROT" ]; then
			echo "ro.sf.hwrotation=180" >> /system/etc/default.prop
		else
			sed -i /hwrotation/s/=.*/=180/ /system/etc/default.prop
		fi
	fi
fi

echo "using $card/conf/$RCCONFIG.user.conf"

INITRC=`ls -l /init.rc | grep "$RCSCRIPT"`
if [ -z "$INITRC" ]; then
	echo "using /init.$RCSCRIPT.rc as init.rc"
	rm -f /init.rc
	ln -s "/init.cfg/init.$RCSCRIPT.rc" /init.rc
fi

#Assume this rootfs.img will be used only on "good" devices
#Meaning raph/diam/blac/

# echo /dev/block/mmcblk0p2 > /sys/devices/platform/usb_mass_storage/lun0/file
ifconfig usb0 192.168.20.1 up
busybox telnetd -b 192.168.20.1 -l /bin/sh
#chmod 4755 /bin/su
#mkdir -m 0777 /smodem
mknod /dev/urandom c 1 9
if [ -d /data/dropbear/ ] ; then
	echo "Starting SSH"
	mknod /dev/random c 1 8
	/bin/dropbear -r /data/dropbear/dropbear_rsa_host_key -s
fi

if [ "$WIFI_TI" = "1" ] || [ "$WIFI_BCM" = "1" ];then
	if [ -e "$card/modules-$(uname -r).tar.gz" ] && ! `strings /lib/modules/mac80211.ko 2>/dev/null | grep -q "vermagic=$(uname -r)"`; then
		echo "Installing $card/modules-$(uname -r).tar.gz"
		tar xzf $card/modules-$(uname -r).tar.gz -C /lib/modules
		ln -s /lib/modules /lib/modules/`uname -r`
	else
		echo "Modules already unpacked for this kernel version -- skipping installation of $card/modules-$(uname -r).tar.gz"
	fi

	if [ -f /system/etc/wifi/wlan.ko ]; then
	cp -R /system/etc/wifi/* /lib/modules/
	rm /system/etc/wifi/wlan.ko
	depmod
	fi

	if [ "`grep -c ^wifi /system/etc/default.prop`" != "2" ]; then
		echo "wifi.interface = wlan0" >> /system/etc/default.prop
		echo "wifi.supplicant_scan_interval = 45" >> /system/etc/default.prop
	fi
fi

if [ -f /system/eclair.build ]
then
	mount --bind /lib/eclair/libhardware_legacy.so /system/lib/libhardware_legacy.so
fi

if [ "$WIFI_BCM" = "1" ] ;then
	# fyi: firmware is loaded from /data/etc/wifi/bcm432x/bcm4325-rtecdc.bin, nvram from /data/wifi-nvram.txt

	# extract nvram (todo: clean this up/integrate with TI calibration)
	if [ ! -e /data/wifi-nvram.txt ]; then
		insmod /lib/modules/mtdchar.ko
		mknod /dev/mtd0ro c 90 1
		for SKIP in 5744 4736;do
			mkdir /lib/modules/$(uname -r)

			dd if=/dev/mtd0ro of=/tmp/tempcal bs=8192 count=1 skip=$SKIP
			rmdir /lib/modules/$(uname -r)
			dd if=/tmp/tempcal of=/data/wifi-nvram.txt bs=1 count=466
			rm /tmp/tempcal
		
			if grep nocrc= /data/wifi-nvram.txt 2>&1 > /dev/null;then 
				break
			fi;
		done
		rm /dev/mtd0ro
		rmmod mtdchar
		if [ "$SKIP" = "5744" ];then
			echo "CDMA Rhodium detected"
		fi;
		if [ "$SKIP" = "4736" ];then
			echo "GSM Rhodium detected"
		fi;

	fi
fi

for i in local.prop eri.xml serialno; do
	if [ -f "$card/$i" ]; then
		if [ ! -f /data/$i -o "$card/$i" -nt /data/$i ]; then
			cp "$card/$i" /data/$i
		fi
	fi
done

if [ -f "$card/conf/$RCCONFIG.user.conf" ]; then
	/bin/userinit.sh -c "$card/conf/$RCCONFIG.user.conf"
else
	echo "No user config files ($RCCONFIG) found on sdcard"
fi

mount -tdebugfs none /dbgfs
#Activate baclight control
echo 3 > /sys/class/htc_hw/test
#Smooth scroll
echo 40 >/sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
#Activate full charging
echo 2 > /dbgfs/htc_battery/charger_state

[ -z $KBD ] && KBD=`sed 's/.*physkeyboard=\([0-9a-z_]*\).*/\1/' /proc/cmdline`
cp /init.etc/keymaps/default/*.kl /system/usr/keylayout/
cp /init.etc/keymaps/default/*.kcm* /system/usr/keychars/
if [ -d "/init.etc/keymaps/$KBD" ]
then
	cp /init.etc/keymaps/"$KBD"/*.kl /system/usr/keylayout/
	cp /init.etc/keymaps/"$KBD"/*.kcm* /system/usr/keychars/
fi

mount -o remount,ro /system

for i in /sys/class/input/input* ; do
        if [ "`cat $i/name`" = "tssc-manager" ] ; then
                touchscreendir=$i
                echo "Touchscreen device directory is $i"
        fi
done

if [ -f $card/ts-calibration ] ; then
        echo "Using Saved Touchscreen Calibration"
	echo 128,128,1903,128,128,1907,1903,1907,1024,1024 > $touchscreendir/calibration_screen
        cat $card/ts-calibration > $touchscreendir/calibration_points
else
        mkdir /dev/graphics
        mknod /dev/graphics/fb0 c 29 0
        clear
        echo; echo; echo; echo; echo; echo; echo; echo "Calibrating Touchscreen:"
        echo "Click the Five Targets in order -- Top Left, Top Right, Middle, Bottom Left, Bottom Right"
	echo "(Tap lightly. The screen is quite sensitive.)"
        tssc-calibrate
        echo 0,0,0,0,0,0,0,0,0,0 | cmp -s $touchscreendir/calibration_points # determine if calibration is still null -- means failed calibration
        if [ $? -eq 0 ] ; then
                echo "Touchscreen Calibration Failed"
        else
                echo "Touchscreen Calibration Successful; Saving..."
                cat $touchscreendir/calibration_points > $card/ts-calibration
        fi
fi

mkdir /dev/msm_camera
mknod /dev/msm_camera/control0 c 250 0
mknod /dev/msm_camera/config0 c 250 1
mknod /dev/msm_camera/frame0 c 250 2

# Generate a "serial number" for the Android system to identify the device.
# Put it in /data so it survives reboots. Won't survive a factory reset, though.
[ -f "/data/serialno" ] || echo -e `cat /dev/urandom | tr -dc 'A-Z0-9' | fold -w 12 | head -n 1` >/data/serialno

SERIALNO=$(cat /data/serialno)
cp /proc/cmdline /tmp/cmdline
sed -i -e "s:$: androidboot.serialno=${SERIALNO}:" /tmp/cmdline
mount --bind /tmp/cmdline /proc/cmdline

# Transition sequence for FRX06->FRX07 (eth0/tiwlan0 renamed)
if [ -f "/data/misc/wifi/wpa_supplicant.conf" ]
then
	sed -i -e 's:=\(tiwlan0\|eth0\):=wlan0:' /data/misc/wifi/wpa_supplicant.conf
	chown 1000:1010 /data/misc/wifi/wpa_supplicant.conf
fi

# Bind-mount /sdcard/.android_secure to /mnt/secure/asec for native Apps2SD
[ -d /sdcard/.android_secure ] || mkdir /sdcard/.android_secure
mount --bind /sdcard/.android_secure /mnt/secure/asec
fi
exec /init.android