Skip to content
This repository has been archived by the owner on Dec 28, 2018. It is now read-only.

Commit

Permalink
Merge commit 'fee3c3e3e9dd9a1693bbc9595ff74eca7cf13a7f'
Browse files Browse the repository at this point in the history
  • Loading branch information
steadfasterX committed Apr 11, 2017
2 parents 5670295 + fee3c3e commit ef57c27
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 65 deletions.
39 changes: 23 additions & 16 deletions fishing/FIsH
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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..."
Expand All @@ -113,7 +116,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
Expand All @@ -134,8 +137,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"
Expand All @@ -147,35 +154,31 @@ 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
ECHOL "### Kill /sbin processes..."
$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
Expand Down Expand Up @@ -253,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..

Expand All @@ -262,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
Expand Down
25 changes: 14 additions & 11 deletions fishing/FIsH.me
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ 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}
EXECL stop ${SVCNAME} &
CNT=$((CNT +1))
ECHOL "increased counter for $SVCNAME to $CNT"
else
Expand All @@ -121,24 +121,27 @@ 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)"
for pid in $($FUSER -m $i);do
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 ] && $KILL -9 $pid & >> $LOGFILE 2>&1
fi
done
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)"
Expand Down
10 changes: 5 additions & 5 deletions fishing/FIsH.porting
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 -
Expand Down
6 changes: 3 additions & 3 deletions fishing/callmeFIsH
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 /
Expand Down
113 changes: 83 additions & 30 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit ef57c27

Please sign in to comment.