From 77de7b1cc11ceb7532f264b303b3b1470d5958f9 Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Sun, 9 Apr 2017 18:02:02 +0200 Subject: [PATCH 01/11] new: unmounting firmware and others more early --- fishing/FIsH.porting | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fishing/FIsH.porting b/fishing/FIsH.porting index 5a55546..3149362 100644 --- a/fishing/FIsH.porting +++ b/fishing/FIsH.porting @@ -144,6 +144,9 @@ F_KEYPRESS(){ # The ORDER is IMPORTANT! # (means u have to umount all submounts first before u can unmount the main one) MOUNTS="/acct \ + /firmware \ + /cust \ + /sns \ /mnt/secure \ /mnt/asec \ /mnt/obb \ @@ -158,12 +161,9 @@ MOUNTS="/acct \ /storage/emulated \ /data/media \ /data \ - /persist \ - /firmware \ - /sns \ /persist-lg \ - /mpt \ - /cust" + /persist \ + /mpt" # device specific mount points - OS special # - Porting instructions - From dede0c1d5aa60e00f6e1c6029c50ac537d5f646d Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Sun, 9 Apr 2017 18:02:47 +0200 Subject: [PATCH 02/11] fix: speedup umount-kill! --- fishing/FIsH.me | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/fishing/FIsH.me b/fishing/FIsH.me index 505cc2c..f3c3460 100644 --- a/fishing/FIsH.me +++ b/fishing/FIsH.me @@ -129,16 +129,11 @@ F_UMOUNT(){ if [ $pid -eq $PID ]||[ $pid -eq 1 ];then ECHOL "skipped to kill excluded pid $pid" else - if [ ! -z $pid ];then - #ECHOL kill disabled - echo "Trying to kill" - $PS -T -o pid,comm,args | $GREP " $pid ">> $LOGFILE - $KILL -9 $pid >> $LOGFILE 2>&1 - else - ECHOL "Empty pid skipped..!" - fi + [ ! -z $pid ];then $KILL -9 $pid & >> $LOGFILE 2>&1 fi done + # give it a short time to breath because we kill what we can in parallel + $SLEEP 2 EXECL ${UMOUNT} $i || EXECL ${UMOUNT} -f $i || EXECL ${UMOUNT} -l $i else ECHOL "Skipped requested unmount because it does not exist ($i)" From 74623b9227a020d5b67c1aba83053d64165a2acf Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Sun, 9 Apr 2017 18:03:52 +0200 Subject: [PATCH 03/11] fix: speedup sbin/bin-kill! new: remount system-rw earlier --- fishing/FIsH | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fishing/FIsH b/fishing/FIsH index 6924a9f..a818944 100755 --- a/fishing/FIsH +++ b/fishing/FIsH @@ -134,8 +134,12 @@ if [ -f ${BTMGRPATH}/${RAMDISK} ];then MODEL2=$(getprop ro.build.product) ECHOL "Model found: $MODEL / $MODEL2 ($VERSION)" + # remount rootfs to rw. + ECHOL "### remount rootfs to rw..." + EXECL ${MOUNT} -o remount,rw rootfs / + # Stop init services. - F_STOPSVCS 1 + F_STOPSVCS 2 # umount partitions, stripping the ramdisk to bare metal ECHOL " ### Unmounting partitions but before: here all current mounts" @@ -147,21 +151,21 @@ if [ -f ${BTMGRPATH}/${RAMDISK} ];then $MOUNT >> /$LOGFILE # Stop init services again to catch those not stopped on the first try - F_STOPSVCS 1 + #F_STOPSVCS 1 # Kill remaining processes under /system/bin ECHOL "### Kill /system/bin and /system/xbin processes (ps based)..." ${PS} | e${GREP} '(/system/bin|/system/xbin)' >> $LOGFILE for RUNNINGPRC in $(${PS} | e${GREP} '(/system/bin|/system/xbin)' | ${GREP} -v grep | ${GREP} -v $0 | ${AWK} '{print $1}' ) do - EXECL ${KILL} -9 ${RUNNINGPRC} + EXECL ${KILL} -9 ${RUNNINGPRC} & done ECHOL "### Kill /system/bin and /system/xbin processes (lsof based)..." $LSOF | e${GREP} '(/system/bin|/system/xbin)' >> $LOGFILE for RUNNINGPRC in $(${LSOF} | e${GREP} '(/system/bin|/system/xbin)' | ${GREP} -v grep | ${GREP} -v $0 | ${AWK} '{print $1}' ) do - EXECL ${KILL} -9 ${RUNNINGPRC} + EXECL ${KILL} -9 ${RUNNINGPRC} & done # Kill remaining processes under /sbin @@ -169,13 +173,9 @@ if [ -f ${BTMGRPATH}/${RAMDISK} ];then $PS -T -o pid,comm,args | ${GREP} /sbin >> $LOGFILE for RUNNINGPRC in $(${PS} | ${GREP} /sbin | ${GREP} -v grep | $AWK '{print $1}' ) do - EXECL ${KILL} -9 ${RUNNINGPRC} + EXECL ${KILL} -9 ${RUNNINGPRC} & done - # remount rootfs to rw. - ECHOL "### remount rootfs to rw..." - EXECL ${MOUNT} -o remount,rw rootfs / - # Install exfat module to support exfat file system ECHOL "### Install exfat module..." LIBP=/system/lib/modules From de29028b21b49e2f7af2c312b9c6932f1332ef61 Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Mon, 10 Apr 2017 10:27:54 +0200 Subject: [PATCH 04/11] new options & bug fixes new: adding a --clean option fix: /res/fish which was introduced after v1 will be deleted now as well new: moved remount, selinux->permissive and cleaning to functions fix: remount readonly after installation has finished --- install.sh | 113 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 30 deletions(-) diff --git a/install.sh b/install.sh index f66ea85..e8d215e 100755 --- a/install.sh +++ b/install.sh @@ -55,6 +55,64 @@ MINSU="279" ############################################################################################## +# error handling +F_ERR(){ + ERR=${1/*=/} + [ -z "$ERR" ]&& echo "ERROR IN ERROR HANDLING! $1 was cut down to: $ERR" && exit + + if [ "$ERR" -ne 0 ];then + echo "--> ERROR!! ABORTED WITH ERROR $ERR! Check the above output!" + exit 3 + else + echo "-> command ended successfully ($1)" + fi +} + +# clean up any previous installation +F_CLEAN(){ + echo "############# cleaning" + FISHTRASH="/data/local/tmpfish/ /system/su.d/FIsH /system/su.d/callmeFIsH /system/fish/ /res/fish/" + F_REMOUNT rw "/system" + F_REMOUNT rw "/" + for trash in $FISHTRASH;do + echo "processing: >$trash<" + RET=0 + RET=$(adb shell "su -c test -e $trash || echo err=1" | cut -d "=" -f 2 |tr -d '\r') + if [ "$RET" != "1" ];then + echo "--> exists. will be deleted now." + RET=$(adb shell "su -c rm -rf $trash || echo err=1" |tr -d '\r') + [ ! -z "$RET" ] && echo "WARNING: cleaning ended with $RET !!" + fi + done +} + +#remount RW a partition +F_REMOUNT(){ + WHAT="$1" + PARTITION="$2" + [ "$WHAT" != "ro" -a "$WHAT" != "rw" ] && echo "ERROR: wrong or missing remount argument!!" && exit 3 + + PEXIST=$(adb shell "su -c test -d $PARTITION || echo err=1") + if [ ! -z "$PEXIST" ];then + echo "WARNING: $PARTITION IS MISSING OR NOT MOUNTED.." + else + echo "... remounting $PARTITION in $WHAT mode" + adb shell "su -c mount -oremount,${WHAT} $PARTITION || echo err=1 " + adb shell "su -c mount |grep ' $PARTITION '" + # no valid return code from busybox. + fi +} + +# set selinux to permissive +F_SELPERM(){ + echo "############# temporary disable SELinux" + RET=$(adb shell 'su -c setenforce 0; echo err=$?' | grep err=|tr -d '\r') + F_ERR $RET + SEL="$(adb shell getenforce|tr -d '\r')" + echo "SELinux mode: $SEL" + [ "$SEL" != "Permissive" ]&& echo 'ABORTED!!! YOU CAN NOT GET PERMISSIVE SELINUX MODE!' && exit +} + # we do not want to distribute busybox to avoid licensing issues so u need to download it: echo -e "\n############# Checking for busybox" [ ! -f fishing/busybox ] && echo "...downloading busybox" && wget "$BUSYBOXURI" -O fishing/busybox && chmod 755 fishing/busybox @@ -65,21 +123,27 @@ adb start-server echo -e "Waiting for your device... (you may have to switch to PTP mode on some devices!!)" adb wait-for-device +# save current selinux state +CURSELINUX=$(adb shell getenforce |tr -d '\r') + +# clean and exit +if [ "$1" == "--clean" ];then + # disable selinux + F_SELPERM + # clean as requested + F_CLEAN + echo "############# restoring SELinux mode to $CURSELINUX" + RET=$(adb shell "su -c setenforce $CURSELINUX; echo err=$?" | grep err= |tr -d '\r') + F_ERR $RET + + echo -e "\nFinished cleaning and as you choose to clean only I will exit now.\n" + exit +fi + # precheck min requirement adb: adb version [ $? -ne 0 ]&& echo "ADB is not installed?! Use FWUL (https://tinyurl.com/FWULatXDA) you FOOL! :)" && exit -F_ERR(){ - ERR=${1/*=/} - [ -z "$ERR" ]&& echo "ERROR IN ERROR HANDLING! $1 was cut down to: $ERR" && exit - - if [ "$ERR" -ne 0 ];then - echo "--> ERROR!! ABORTED WITH ERROR $ERR! Check the above output!" - exit 3 - else - echo "-> command ended successfully ($1)" - fi -} echo "############# checking Android version" AVER=$(adb shell getprop ro.build.version.sdk| tr -d '\r') @@ -111,13 +175,8 @@ else exit 3 fi -echo "############# temporary disable SELinux" -CURSELINUX=$(adb shell getenforce |tr -d '\r') -RET=$(adb shell 'su -c setenforce 0; echo err=$?' | grep err=|tr -d '\r') -F_ERR $RET -SEL="$(adb shell getenforce|tr -d '\r')" -echo "SELinux mode: $SEL" -[ "$SEL" != "Permissive" ]&& echo 'ABORTED!!! YOU CAN NOT GET PERMISSIVE SELINUX MODE!' && exit +# temporary disable SELinux +F_SELPERM # check if we run in testing mode and exit if [ "$1" == "--check" ];then @@ -127,18 +186,9 @@ if [ "$1" == "--check" ];then exit fi -echo "############# remount /system" -RET=$(adb shell "su -c 'mount -oremount,rw /system; echo err=$?'" | grep err=|tr -d '\r') # bullshit.. mount do not return a valid errorcode! -#F_ERR $RET -echo "############# cleaning" -RET=$(adb shell 'su -c rm -Rf /data/local/tmpfish/; echo err=$?' | grep err= |tr -d '\r') -F_ERR $RET -RET=$(adb shell 'su -c rm -f /system/su.d/FIsH; echo err=$?' | grep err= |tr -d '\r') -F_ERR $RET -RET=$(adb shell 'su -c rm -f /system/su.d/callmeFIsH; echo err=$?' | grep err= |tr -d '\r') -F_ERR $RET -RET=$(adb shell 'su -c rm -Rf /system/fish; echo err=$?' | grep err= |tr -d '\r') -F_ERR $RET +# clean up first +F_CLEAN + echo "############# creating temporary directory" RET=$(adb shell 'su -c mkdir /data/local/tmpfish; echo err=$?' | grep err=|tr -d '\r') F_ERR $RET @@ -157,6 +207,9 @@ RET=$(adb shell 'su -c mount -oremount,ro /system; echo err=$?' | grep err=|tr - echo "############# restoring SELinux mode to $CURSELINUX" RET=$(adb shell "su -c setenforce $CURSELINUX; echo err=$?" | grep err= |tr -d '\r') F_ERR $RET +echo "############# remounting system partitions to read-only again" +F_REMOUNT ro "/system" +F_REMOUNT ro "/" echo "ALL DONE! Reboot and enjoy the FIsH." echo echo -e "Get support on IRC:\n" From 7c0a02664ddf1ac606bfe7a0aa9d426e9dc068ee Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Mon, 10 Apr 2017 10:49:51 +0200 Subject: [PATCH 05/11] fix: use busybox sh from /res to start FIsH new: log to dmesg in early state --- fishing/callmeFIsH | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fishing/callmeFIsH b/fishing/callmeFIsH index 6e9eeab..1889916 100644 --- a/fishing/callmeFIsH +++ b/fishing/callmeFIsH @@ -23,8 +23,8 @@ FISHME=/system/fish/FIsH.me FISHPORT=/system/fish/FIsH.porting -[ ! -f $FISHME ] && echo "ERROR missing FIsH.me" && exit 3 -[ ! -f $FISHPORT ] && echo "ERROR missing FIsH.porting" && exit 3 +[ ! -f $FISHME ] && echo "$0 - ERROR missing FIsH.me" >> /dev/kmsg && exit 3 +[ ! -f $FISHPORT ] && echo "$0 - ERROR missing FIsH.porting" >> /dev/kmsg && exit 3 source $FISHME source $FISHPORT @@ -67,7 +67,7 @@ if [ -x /res/fish/busybox ];then CMD_SETUP ECHOL "### calling the FIsH and exit" - /res/fish/FIsH & + $BUSYBOX sh /res/fish/FIsH & else ECHOL "### calling the FIsH not possible because busybox install fail" EXECL $MOUNT -oremount,ro / From 98d2d03f3cc5fe66dbc8ddf2f01af7d65aec4452 Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Mon, 10 Apr 2017 10:50:18 +0200 Subject: [PATCH 06/11] fix: code error avoids killing services --- fishing/FIsH.me | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fishing/FIsH.me b/fishing/FIsH.me index f3c3460..c350534 100644 --- a/fishing/FIsH.me +++ b/fishing/FIsH.me @@ -129,7 +129,7 @@ F_UMOUNT(){ if [ $pid -eq $PID ]||[ $pid -eq 1 ];then ECHOL "skipped to kill excluded pid $pid" else - [ ! -z $pid ];then $KILL -9 $pid & >> $LOGFILE 2>&1 + [ ! -z $pid ] && $KILL -9 $pid & >> $LOGFILE 2>&1 fi done # give it a short time to breath because we kill what we can in parallel From b248fbc9a9c18b5659e0a6a7bed98770282a0d77 Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Mon, 10 Apr 2017 10:50:42 +0200 Subject: [PATCH 07/11] fix: protect ramdisk path --- fishing/FIsH | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fishing/FIsH b/fishing/FIsH index a818944..ec7faad 100755 --- a/fishing/FIsH +++ b/fishing/FIsH @@ -113,7 +113,7 @@ fi # Boot FIsH food if it exists (AND key pressed or flag set) EXECL cd / -if [ -f ${BTMGRPATH}/${RAMDISK} ];then +if [ -f "${BTMGRPATH}/${RAMDISK}" ];then ECHOL "### ${RAMDISK} exists..." ECHOL "Your FIsHFOOD is: $($CAT ${BTMGRPATH}/fishfood.release)" >> $LOGFILE From c77a2fac161ef75956bd4409fbf358ccec82bc3b Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Mon, 10 Apr 2017 11:53:56 +0200 Subject: [PATCH 08/11] fix: no wait time when boot flag is set --- fishing/FIsH | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fishing/FIsH b/fishing/FIsH index ec7faad..a0df5bd 100755 --- a/fishing/FIsH +++ b/fishing/FIsH @@ -80,7 +80,13 @@ echo "0" > ${WAIT_LED} # Turn on WAIT-led -> NOW the user should press the key combo - until he feels the vibrate and red led! echo "255" > ${WAIT_LED} -$SLEEP $KEYWAIT + +# check FIsH flag +if [ -f /cache/recovery/boot ];then + FISH_FLAG=true +else + $SLEEP $KEYWAIT +fi # for debugging.. $DMESG > ${LOGPATH}/dmesg.log @@ -91,9 +97,6 @@ echo '200' > $VIBRATE $PS -T -o pid,comm,args > ${LOGPATH}/ps.log ${CHMOD} 660 ${LOGPATH}/ps.log -# check FIsH flag -[ -f /cache/recovery/boot ] && FISH_FLAG=true - # see if we want to start FIsH or not if [ "$FISH_FLAG" == "true" ];then ECHOL "### Enforcing FIsH boot mode by $FISH_FLAG..." From 344010d989b1826b23910209f3f47c973897008d Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Mon, 10 Apr 2017 11:54:42 +0200 Subject: [PATCH 09/11] fix: speedup killing/unmounting --- fishing/FIsH.me | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fishing/FIsH.me b/fishing/FIsH.me index c350534..64f55c8 100644 --- a/fishing/FIsH.me +++ b/fishing/FIsH.me @@ -102,7 +102,7 @@ F_STOPSVCS(){ # try to stop a service it up to 3 times (we cannot get a valid service error state so this way..) while [ $CNT -lt 1 ];do if [ ! -z "$SVCNAME" ];then - EXECL stop ${SVCNAME} + EXECL stop ${SVCNAME} & CNT=$((CNT +1)) ECHOL "increased counter for $SVCNAME to $CNT" else @@ -121,7 +121,7 @@ F_UMOUNT(){ if [ -z "$MOUNTS" ];then ECHOL "ERROR: MISSING MOUNTS ARG FOR F_UMOUNT!!" else - # umount given list + # kill unmount list for i in $MOUNTS;do if [ -e "$i" ];then ECHOL "### killing all processes accessing $i (if any can be found by fuser)" @@ -132,8 +132,16 @@ F_UMOUNT(){ [ ! -z $pid ] && $KILL -9 $pid & >> $LOGFILE 2>&1 fi done - # give it a short time to breath because we kill what we can in parallel - $SLEEP 2 + else + ECHOL "Skipped killing processes for $i because mountpoint does not exists" + fi + done + # give it a short time to breath because we kill what we can in parallel + $SLEEP 1 + # umount given list + for i in $MOUNTS;do + if [ -e "$i" ];then + ECHOL "### unmounting $i" EXECL ${UMOUNT} $i || EXECL ${UMOUNT} -f $i || EXECL ${UMOUNT} -l $i else ECHOL "Skipped requested unmount because it does not exist ($i)" From 5bd77047ed97bf6fd82a10852ac620eb6d4eebe8 Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Mon, 10 Apr 2017 12:15:05 +0200 Subject: [PATCH 10/11] fix: cosmetics --- fishing/FIsH | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fishing/FIsH b/fishing/FIsH index a0df5bd..9587dc1 100755 --- a/fishing/FIsH +++ b/fishing/FIsH @@ -256,6 +256,10 @@ if [ -f "${BTMGRPATH}/${RAMDISK}" ];then cd /res && EXECL ${CPIO} -i -u "$FOODBIN" < $TMPFISHDIR/${RAMDISK/.gz} EXECL $MV /res/$FOODBIN /init cd / + + echo -e "\n\n ***** directory before exec init ***** \n" >> $LOGFILE + ${LS} -la >> $LOGFILE + # TODO: validations of the above?! to avoid extraction errors etc.. @@ -265,10 +269,10 @@ if [ -f "${BTMGRPATH}/${RAMDISK}" ];then echo -e "\n\n ***** process before exec init ***** \n" >> $LOGFILE $PS -T -o pid,comm,args >> $LOGFILE - echo -e "\n\n ***** lsof before extracting ramdisk ***** \n" >> $LOGFILE + echo -e "\n\n ***** lsof before exec init ***** \n" >> $LOGFILE ${LSOF} >> $LOGFILE - echo -e "\n\n ***** inotifies before extracting ramdisk ***** \n" >> $LOGFILE + echo -e "\n\n ***** inotifies before exec init ***** \n" >> $LOGFILE $PS $($FIND /proc/*/fd/* -type l -lname 'anon_inode:inotify' -print 2> /dev/null | $SED -e 's/^\/proc\/\([0-9]*\)\/.*/\1/') >> $LOGFILE # umount all special mounts From fee3c3e3e9dd9a1693bbc9595ff74eca7cf13a7f Mon Sep 17 00:00:00 2001 From: steadfasterX Date: Mon, 10 Apr 2017 12:15:38 +0200 Subject: [PATCH 11/11] fix: amount was not respected for stopping services --- fishing/FIsH.me | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fishing/FIsH.me b/fishing/FIsH.me index 64f55c8..bbd9584 100644 --- a/fishing/FIsH.me +++ b/fishing/FIsH.me @@ -100,7 +100,7 @@ F_STOPSVCS(){ CNT=0 SVCNAME=$(${EXPR} ${SVCRUNNING} : '\[init\.svc\.\(.*\)\]:.*') # try to stop a service it up to 3 times (we cannot get a valid service error state so this way..) - while [ $CNT -lt 1 ];do + while [ $CNT -lt $AMOUNT ];do if [ ! -z "$SVCNAME" ];then EXECL stop ${SVCNAME} & CNT=$((CNT +1))