[SCRIPT] Helium server PC download - separation - Miscellaneous Android Development

This is simple linux script I've made to separate all apps from one big zip file made by Helium sever -> PC download. Helium wiki says to don't try to do anything with this file, but I didn't want to restore all that stuff that I've backuped before bootloader unlock on my nexus 4. I'm sure it can be writed better, but it's working
Just place script file and unziped backup folder (must be named "backup") in one directory. After execution of the script everything should be ready to copying to carbon folder on your sd card/internal memory and restoring like after normal backup.
Tested on Ubuntu 14.04.
I'm not responsible for data loss or any other problem. Use at your own risk.
Constructive criticism welcome.
Code:
#!/bin/bash
DIRECTORY='./backup'
if [ -f $DIRECTORY/backup.json ]; then
cp $DIRECTORY/backup.json $DIRECTORY/temp.json
sed -e "s/{\"packages\"://g" $DIRECTORY/temp.json > $DIRECTORY/temp2.json
tr '[]' ' ' < $DIRECTORY/temp2.json | tee $DIRECTORY/temp.json
tr '}' '\n' < $DIRECTORY/temp.json | tee $DIRECTORY/temp2.json
sed -e "s/,{/{/g" $DIRECTORY/temp2.json > $DIRECTORY/temp.json
sed -e 's/^[ \t]*//' $DIRECTORY/temp.json > $DIRECTORY/temp2.json
sed '/^$/d' $DIRECTORY/temp2.json > $DIRECTORY/temp.json
sed 's/\([^|]\)$/\1}/' $DIRECTORY/temp.json > $DIRECTORY/temp_last.json
fi;
count=`ls -1 $DIRECTORY/*.ab 2>/dev/null | wc -l`
if [ $count != 0 ]; then
for i in $DIRECTORY/*.ab ; do
AB=$(basename $i)
mkdir -p $DIRECTORY/${AB%.*}
mv -i $DIRECTORY/$AB $DIRECTORY/${AB%.*}/
if [ -f $DIRECTORY/${AB%.*}.png ]; then
mv -i $DIRECTORY/${AB%.*}.png $DIRECTORY/${AB%.*}/._${AB%.*}.png
fi;
if [ ! -f $DIRECTORY/${AB%.*}/${AB%.*}.json ];then
touch $DIRECTORY/${AB%.*}/${AB%.*}.json
fi;
while read p; do
if [[ "$p" =~ "${AB%.*}" ]]; then
echo "$p" > $DIRECTORY/${AB%.*}/${AB%.*}.json
fi;
done <$DIRECTORY/temp_last.json
done;
fi;
rm $DIRECTORY/temp.json
rm $DIRECTORY/temp2.json
rm $DIRECTORY/temp_last.json
exit;

Related

[For DEV][Build.prop Tweak's]All tweaks

Tweaks Increase download/upload/3G speeds
Code:
ro.ril.hsxpa=2
ro.ril.gprsclass=10
ro.ril.hep=1
ro.ril.enable.dtm=0
ro.ril.hsdpa.category=8 (or 10,12,14) Still looking for more of these though.
ro.ril.enable.a53=1
ro.ril.enable.3g.prefix=1
ro.ril.htcmaskw1.bitmask=4294967295
ro.ril.htcmaskw1=14449
ro.ril.hsupa.category=6
net.tcp.buffersize.default=4096,87380,256960,4096,16384,256960
net.tcp.buffersize.wifi=4096,87380,256960,4096,16384,256960
net.tcp.buffersize.umts=4096,87380,256960,4096,16384,256960
net.tcp.buffersize.gprs=4096,87380,256960,4096,16384,256960
net.tcp.buffersize.edge=4096,87380,256960,4096,16384,256960
Power Save Tweak
Code:
Allows the phone to sleep better
ro.ril.disable.power.collapse=0
Saves power when phone is sleep
pm.sleep_mode=1
Allows your wifi to scan less, saving more battery
wifi.supplicant_scan_interval=150 or 180 (your choice)
Helps Scrolling Responsiveness
windowsmgr.max_events_per_sec=150
Increase overal touch responsivenss
debug.performance.tuning=1
video.accelerate.hw=1
MEDIA TWEAKS
Code:
Makes streaming videos stream faster
media.stagefright.enable-player=true
media.stagefright.enable-meta=true
media.stagefright.enable-scan=true
media.stagefright.enable-http=true
media.stagefright.enable-record=false
Increases quality of photo and videos
ro.media.dec.jpeg.memcap=8000000
ro.media.enc.hprof.vid.bps=8000000
Raises quality of JPEG images
ro.media.enc.jpeg.quality=90 or 100 (your choice)
BOOT TWEAKS
Code:
Gives your phone no boot animation
debug.sf.nobootanimation=1
SYSTEM TWEAKS
Code:
Forces your home launcher into memory
ro.HOME_APP_ADJ=1
Change the Dalvik VM heap size
dalvik.vm.heapsize=64m #or 48mb
To disable usb debugging popup
persist.adb.notify=0
To stop the phone from waking up when pressing the volume key
ro.config.hwfeature_wakeupkey=0
To make the phone ring faster when dialing out
ro.telephony.call_ring.delay=800
Disable black screen issue after call
ro.lge.proximity.delay=25
mot.proximity.delay=25
dalvik.vm.startheapsize = 4м
Screen ppi or font density
[B]ro.sf.lcd_density=240
Other Tweaks
Code:
mot.proximity.delay=150
debug.sf.hw=1 #Render UI with GPU
ro.kernel.android.checkjni=0
persist.sys.purgeable_assets=1
download link ? does it work in miui ?
anna0811 said:
download link ? does it work in miui ?
Click to expand...
Click to collapse
You add it to build.prop on your own.
Cheers
Sent from my GT-i9003 powered by MIUI
anna0811 said:
download link ? does it work in miui ?
Click to expand...
Click to collapse
read it it is for dev only
I am using must of them so no need to change it.Thanks Frank for collecting.
tarunagg said:
read it it is for dev only
Click to expand...
Click to collapse
i know it is for devs but i want to try it if there is a download link
btw can you tell me how to flash it
anna0811 said:
i know it is for devs but i want to try it if there is a download link
btw can you tell me how to flash it
Click to expand...
Click to collapse
all hail the king of troll
it has to be changed manually.not a flashable file.
anna0811 said:
i know it is for devs but i want to try it if there is a download link
btw can you tell me how to flash it
Click to expand...
Click to collapse
If you don't know how to apply them just install a rom that surely has some of them
Nice list.
I think ro.ril.disable.power.collapse should read
Code:
ro.ril.disable.power.collapse=0
because you want the power collapse to happen to save energy. Also, all commands should be lower case. Therefore it should be
Code:
debug.performance.tuning=1
video.accelerate.hw=1
with 'd' and 'v' instead of 'D' and 'V' at the beginning.
Further, I use
Code:
dalvik.vm.startheapsize=4m
which in my experience reduces RAM usage by approx. 15 MB on startup.
XDA_Bam said:
Nice list.
I think ro.ril.disable.power.collapse should read
Code:
ro.ril.disable.power.collapse=0
because you want the power collapse to happen to save energy. Also, all commands should be lower case. Therefore it should be
Code:
debug.performance.tuning=1
video.accelerate.hw=1
with 'd' and 'v' instead of 'D' and 'V' at the beginning.
Further, I use
Code:
dalvik.vm.startheapsize=4m
which in my experience reduces RAM usage by approx. 15 MB on startup.
Click to expand...
Click to collapse
Thanks man, i add this later
Nice one frank,ButI think Mediastatefright breaks HD Video
PhosgenMod init.d + build.prop
PhosgenCharger
Code:
echo "0,3,5,7,14,15" > /sys/module/lowmemorykiller/parameters/adj; # OOM Grouping
echo "1536,2048,4096,10240,12800,15360"> /sys/module/lowmemorykiller/parameters/minfree;
PhosgenCore
Code:
if [ -e /sys/devices/virtual/bdi/179:0/read_ahead_kb ]
then
/system/xbin/echo "4096" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;
fi;
if [ -e /sys/devices/virtual/bdi/179:8/read_ahead_kb ]
then
/system/xbin/echo "4096" > /sys/devices/virtual/bdi/179:8/read_ahead_kb;
fi;
if [ -e /sys/devices/virtual/bdi/default/read_ahead_kb ]
then
/system/xbin/echo "4096" > /sys/devices/virtual/bdi/default/read_ahead_kb;
fi;
if [ -e /sys/module/lowmemorykiller/parameters/adj ]; then
echo "0,1,2,4,6,15" > /sys/module/lowmemorykiller/parameters/adj
fi
if [ -e /sys/module/lowmemorykiller/parameters/minfree ]; then
echo "2560,4096,5632,10240,11776,14848" > /sys/module/lowmemorykiller/parameters/minfree
fi
if [ -e /proc/sys/vm/swappiness ]; then
echo "20" > /proc/sys/vm/swappiness
fi
if [ -e /proc/sys/vm/vfs_cache_pressure ]; then
echo "70" > /proc/sys/vm/vfs_cache_pressure
fi
if [ -e /proc/sys/vm/dirty_expire_centisecs ]; then
echo "3000" > /proc/sys/vm/dirty_expire_centisecs
fi
if [ -e /proc/sys/vm/dirty_writeback_centisecs ]; then
echo "450" > /proc/sys/vm/dirty_writeback_centisecs
fi
if [ -e /proc/sys/vm/dirty_ratio ]; then
echo "10" > /proc/sys/vm/dirty_ratio
fi
if [ -e /proc/sys/vm/dirty_background_ratio ]; then
echo "2" > /proc/sys/vm/dirty_background_ratio
fi
LOG_FILE=/data/zipalign.log;
ZIPALIGNDB=/data/zipalign.db;
if [ -e $LOG_FILE ]; then
rm $LOG_FILE;
fi;
if [ ! -f $ZIPALIGNDB ]; then
touch $ZIPALIGNDB;
fi;
echo "Starting FV Automatic ZipAlign $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
for DIR in /system/app /data/app; do
cd $DIR;
for APK in *.apk; do
if [ $APK -ot $ZIPALIGNDB ] && [ $(grep "$DIR/$APK" $ZIPALIGNDB|wc -l) -gt 0 ]; then
echo "Already checked: $DIR/$APK" | tee -a $LOG_FILE;
else
ZIPCHECK=`/system/xbin/zipalign -c -v 4 $APK | grep FAILED | wc -l`;
if [ $ZIPCHECK == "1" ]; then
echo "Now aligning: $DIR/$APK" | tee -a $LOG_FILE;
/system/xbin/zipalign -v -f 4 $APK /data/local/$APK;
busybox mount -o rw,remount /system;
cp -f -p /data/local/$APK $APK;
grep "$DIR/$APK" $ZIPALIGNDB > /dev/null || echo $DIR/$APK >> $ZIPALIGNDB;
else
echo "Already aligned: $DIR/$APK" | tee -a $LOG_FILE;
grep "$DIR/$APK" $ZIPALIGNDB > /dev/null || echo $DIR/$APK >> $ZIPALIGNDB;
fi;
fi;
done;
done;
busybox mount -o ro,remount /system;
touch $ZIPALIGNDB;
echo "Automatic ZipAlign finished at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
MODULES="ipv6"
for i in $MODULES;
do
modprobe $i;
done
sysctl -p /etc/sysctl.conf;
LOOP=`ls -d /sys/block/loop*`;
blk0=`ls -d /sys/block/mmcblk0`;
blk1=`ls -d /sys/block/mmcblk1`;
MMC=`ls -d /sys/block/mmc*`;
for j in $blk0 $blk1; do
echo "0" > $j/queue/rotational;
echo "4096" > $j/queue/read_ahead_kb;
done;
for k in $(busybox mount | grep relatime | cut -d " " -f3) ; do
sync;
busybox mount -o remount,noatime $k;
done;
for i in /sys/block/*/queue/scheduler ; do
echo "noop" > $i;
done;
for a in $blk0 $blk1 $MMC ; do
echo "512" > $a/queue/nr_requests;
done;
for k in $(busybox mount | grep relatime | cut -d " " -f3) ; do
sync
busybox mount -o remount,noatime $k
done
STL=`ls -d /sys/block/stl*`;
BML=`ls -d /sys/block/bml*`;
MMC=`ls -d /sys/block/mmc*`;
ZRM=`ls -d /sys/block/zram*`;
MTD=`ls -d /sys/block/mtd*`;
for i in $STL $BML $MMC $TFSR; do
echo 0 > $i/queue/rotational
echo 1 > $i/queue/iosched/low_latency
echo 1 > $i/queue/iosched/back_seek_penalty
echo 1000000000 > $i/queue/iosched/back_seek_max
echo 3 > $i/queue/iosched/slice_idle
echo 16 > $i/queue/iosched/quantum
echo 1 > $i/queue/iosched/fifo_batch
echo sio > $i/queue/scheduler
done
if [ -n ${up_threshold} ];
then echo ${up_threshold} > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
fi
if [ -n ${sampling_rate} ];
then echo ${sampling_rate} > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate
fi
if [ -e /sys/module/lowmemorykiller/parameters/adj ]; then
echo "0,1,2,4,7,15" > /sys/module/lowmemorykiller/parameters/adj
fi
if [ -e /sys/module/lowmemorykiller/parameters/minfree ]; then
echo "2560,4096,6144,12288,14336,18432" > /sys/module/lowmemorykiller/parameters/minfree
fi
if [ -e /sys/devices/virtual/bdi/179:0/read_ahead_kb ]; then
echo "3072" > /sys/devices/virtual/bdi/179:0/read_ahead_kb
fi
echo "deadline" > /sys/block/mmcblk0/queue/scheduler
echo "0" > /sys/block/mmcblk0/queue/rotational
echo "2048" > /sys/block/mmcblk0/queue/nr_requests
echo ${READ_AHEAD_KB} > /sys/block/mmcblk0/queue/read_ahead_kb
echo "deadline" > /sys/block/mmcblk1/queue/scheduler
echo "0" > /sys/block/mmcblk1/queue/rotational
echo "2048" > /sys/block/mmcblk1/queue/nr_requests
echo ${READ_AHEAD_KB} > /sys/block/mmcblk1/queue/read_ahead_kb
for i in \ `find /data -iname "*.db"` do \ sqlite3
$i 'VACUUM;'
done
echo "6144 87380 524288" > /proc/sys/net/ipv4/tcp_wmem
echo "6144 87380 524288" > /proc/sys/net/ipv4/tcp_rmem
setprop ro.telephony.call_ring.delay 0
setprop ring.delay 0
setprop windowsmgr.support_rotation_270 true
setprop ro.HOME_APP_ADJ 1
setprop ro.HOME_APP_MEM 2048
echo "500" > /proc/sys/vm/dirty_expire_centisecs
echo "1000" > /proc/sys/vm/dirty_writeback_centisecs
echo "0" > /proc/sys/net/ipv4/tcp_timestamps;
echo "1" > /proc/sys/net/ipv4/tcp_tw_reuse;
echo "1" > /proc/sys/net/ipv4/tcp_sack;
echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle;
echo "1" > /proc/sys/net/ipv4/tcp_window_scaling;
echo "5" > /proc/sys/net/ipv4/tcp_keepalive_probes;
echo "30" > /proc/sys/net/ipv4/tcp_keepalive_intvl;
echo "30" > /proc/sys/net/ipv4/tcp_fin_timeout;
echo "404480" > /proc/sys/net/core/wmem_max;
echo "404480" > /proc/sys/net/core/rmem_max;
echo "256960" > /proc/sys/net/core/rmem_default;
echo "256960" > /proc/sys/net/core/wmem_default;
echo "4096,16384,404480" > /proc/sys/net/ipv4/tcp_wmem;
echo "4096,87380,404480" > /proc/sys/net/ipv4/tcp_rmem;
PhosgenKNZO
Code:
b="busybox"; _e () { echo "$1" > "$2"; };
_m () { $b mount -o $mop -t $fs $1 $2 > /dev/nul 2>&1; };
_t1 () { tune2fs -o $1 $2; }; _t2 () { tune2fs -O $1 $2; };
_mt () { mount -o rw -t tmpfs tmpfs /data/data/$1; };
qa="com.aurorasoftworks.quadrant.ui.standard";
qs="com.aurorasoftworks.quadrant.ui.advanced";
_e "Smartassv2" /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor;
for i in /sys/block/*/queue/scheduler; do sync; echo "sio" > /$i; done;
sd="/sys/devices/virtual/bdi";
_e "1024" $sd/179:0/read_ahead_kb; _e "1024" $sd/default/read_ahead_kb;
if [ -e "$sd/179:16/read_ahead_kb" ]; then _e "1024" $sd/179:16/read_ahead_kb; else _e "1024" $sd/179:17/read_ahead_kb; fi;
PhosgenLoopy
Code:
###### Loopy Smoothness Tweak for PhosgenMod (Experimental) #######
sleep 3
renice 18 `pidof kswapd0` # please give credit and thanks to loopy for this line if it works
##### Set nice levels for smoothness loop BEGIN #####
### Let's loop this in the background for a bit
for i in {1..20}
do
sleep 5
### Phone dialer app ###
renice -20 `pidof com.android.phone`
### Launcher apps ###
renice -20 `pidof com.sec.android.app.twlauncher` # TouchWiz Launcher
renice -20 `pidof org.adwfreak.launcher` # ADW Launcher Ex
renice -20 `pidof org.zeam.core` # Zeam launcher
### System apps ###
renice -19 `pidof com.android.mms` # Text message app
renice -19 `pidof com.swype.android.inputmethod` # Swype keyboard
renice -15 `pidof com.sec.android.app.controlpanel` # Task manager
renice -15 `pidof com.android.systemui` # Status bar
renice -9 `pidof com.android.settings` # Settings menu
renice -9 `pidof com.android.browser` # Browser app
renice -9 `pidof com.android.vending` # Market app
renice -20 `pidof com.sec.android.app.camera` # Camera app
renice -6 `pidof com.sec.android.app.fm` # FM Radio app
renice -6 `pidof com.google.android.youtube` # YouTube app
renice -6 `pidof com.google.android.apps.maps` # Maps
renice -3 `pidof android.process.acore`
renice -3 `pidof android.process.media`
### Memory management kernel thread ###
renice 19 `pidof kswapd0` # please give credit and thanks to loopy for this line if it works
done
PhosgenTouch
Code:
echo 7035 > /sys/class/touch/switch/set_touchscreen;
echo 8002 > /sys/class/touch/switch/set_touchscreen;
echo 11000 > /sys/class/touch/switch/set_touchscreen;
echo 13060 > /sys/class/touch/switch/set_touchscreen;
echo 14005 > /sys/class/touch/switch/set_touchscreen;
PhosgenTune
Code:
if [ -e /sys/class/misc/gpu_clock_control/gpu_control ]; then
echo "100 200 267" > /sys/class/misc/gpu_clock_control/gpu_control;
echo "85% 45% 85% 70%" > /sys/class/misc/gpu_clock_control/gpu_control;
#echo "800000 850000 950000" > /sys/devices/virtual/misc/gpu_voltage_control/gpu_control;
fi;
if [ -e /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table ]; then
#echo "1400 1300 1175 1075 975 850 825 825 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
fi;
for i in \
`busybox find /data -iname "*.db"`;
do \
/system/xbin/sqlite3 $i 'VACUUM;';
/system/xbin/sqlite3 $i 'REINDEX;';
done;
if [ -d "/dbdata" ]; then
for i in \
`busybox find /dbdata -iname "*.db"`;
do \
/system/xbin/sqlite3 $i 'VACUUM;';
/system/xbin/sqlite3 $i 'REINDEX;';
done;
fi;
if [ -d "/datadata" ]; then
for i in \
`busybox find /datadata -iname "*.db"`;
do \
/system/xbin/sqlite3 $i 'VACUUM;';
/system/xbin/sqlite3 $i 'REINDEX;';
done;
fi;
for i in \
`busybox find /sdcard -iname "*.db"`;
do \
/system/xbin/sqlite3 $i 'VACUUM;';
/system/xbin/sqlite3 $i 'REINDEX;';
done;
if [ "`grep 'quadrant.*true' $p`" ]; then
echo "`date` Enabling Quadrant hack..." >>$LOG
dd="/data/data"
qs="com.aurorasoftworks.quadrant.ui.standard"
qa="com.aurorasoftworks.quadrant.ui.advanced"
if [ -d "$dd/$qs" ]; then mount -t tmpfs tmpfs $dd/$qs; renice -20 `pidof $qs`; fi
if [ -d "$dd/$qa" ]; then mount -t tmpfs tmpfs $dd/$qa; renice -20 `pidof $qa`; fi
mount |grep quadrant >>$LOG
fi
if [ -e /sys/devices/system/cpu/cpufreq/smartass/awake_ideal_freq ]; then
echo "800000" > /sys/devices/system/cpu/cpufreq/smartass/awake_ideal_freq;
if [ "`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq`" -eq 200000 ]; then
echo "200000" > /sys/devices/system/cpu/cpufreq/smartass/sleep_ideal_freq;
else
echo "100000" > /sys/devices/system/cpu/cpufreq/smartass/sleep_ideal_freq;
fi;
echo "800000" > /sys/devices/system/cpu/cpufreq/smartass/sleep_wakeup_freq;
echo "85" > /sys/devices/system/cpu/cpufreq/smartass/max_cpu_load;
echo "75" > /sys/devices/system/cpu/cpufreq/smartass/min_cpu_load;
echo "200000" > /sys/devices/system/cpu/cpufreq/smartass/ramp_down_step;
echo "0" > /sys/devices/system/cpu/cpufreq/smartass/ramp_up_step;
fi;
XDA_Bam said:
Nice list.
I think ro.ril.disable.power.collapse should read
Code:
ro.ril.disable.power.collapse=0
because you want the power collapse to happen to save energy. Also, all commands should be lower case. Therefore it should be
Code:
debug.performance.tuning=1
video.accelerate.hw=1
with 'd' and 'v' instead of 'D' and 'V' at the beginning.
Further, I use
Code:
dalvik.vm.startheapsize=4m
which in my experience reduces RAM usage by approx. 15 MB on startup.
Click to expand...
Click to collapse
ro.ril.disable.power.collapse should be 1 to disable the power collapse
For collection of scripts and tweaks look here
send from gt-i9003 using android keyboard
sirilpta said:
For collection of scripts and tweaks look here
send from gt-i9003 using android keyboard
Click to expand...
Click to collapse
..Thanks!
TheFrankenstain said:
..Thanks!
Click to expand...
Click to collapse
in that link it is written
Code:
ro.ril.disable.power.collapse=0
The sense says it should be=1, so what do we use?
Another thing, we can't use all the build.prop lines of that link is this right?
Originally Posted by TheFrankenstain
..Thanks!
Click to expand...
Click to collapse
in that link it is written
ro.ril.disable.power.collapse=0
The sense says it should be=1, so what do we use?
Another thing, we can't use all the build.prop lines of that link is this right?
Click to expand...
Click to collapse
Just use the tweaks currently in the OP. I believe thefrankenstein will only state the tweaks that work.
Cheers
Sent from my GT-i9003 powered by MIUI
Nice work!
I'd changed the media builds yesterday, however, now i can't playing youtube's videos because when i press play button the Mobile become frigde and i only can to turn off pressing long the power button.
Can you give me thr factory status? I didn't a back up file :s
Thx!!
Enviado desde mi GT-I9003 usando Tapatalk
txitxo0 said:
Nice work!
I'd changed the media builds yesterday, however, now i can't playing youtube's videos because when i press play button the Mobile become frigde and i only can to turn off pressing long the power button.
Can you give me thr factory status? I didn't a back up file :s
Thx!!
Enviado desde mi GT-I9003 usando Tapatalk
Click to expand...
Click to collapse
When you edit build.prop, the phone automatically saves a build.prop.bak in the same location, just under your build.prop. Just rename it to build.prop and delete the bad one.
luiseteyo said:
When you edit build.prop, the phone automatically saves a build.prop.bak in the same location, just under your build.prop. Just rename it to build.prop and delete the bad one.
Click to expand...
Click to collapse
Thx a lot luiseteyo! I fell weird writing on english with you jaja
Enviado desde mi GT-I9003 usando Tapatalk

[script][tool] stuff.sh

Code:
# Custom settings for session behaviour
# values for all settings should either be 1 or 0.
# Check Busybox Applet Generator 2.4.
run_Busybox_Applet_Generator=1
# Check Superuser.
run_Superuser=
# Use /dev/urandom for print_RANDOM_BYTE.
use_urand=1
# invert print_RANDOM_BYTE.
invert_rand=1
until [[ "$1" != --verbose ]] && [[ "$1" != --supass ]] && [[ "$1" != --bbpass ]] && [[ "$1" != --urand ]] && [[ "$1" != --invrand ]] && [[ "$1" != --renice ]]; do
if [[ "$1" == --verbose ]]; then
set -x
elif [[ "$1" == --supass ]] && [[ "$run_Superuser" != 0 ]]; then
readonly run_Superuser=0
elif [[ "$1" == --bbpass ]] && [[ "$run_Busybox_Applet_Generator" != 0 ]]; then
readonly run_Busybox_Applet_Generator=0
elif [[ "$1" == --urand ]] && [[ "$use_urand" != 1 ]]; then
readonly use_urand=1
elif [[ "$1" == --invrand ]] && [[ "$invert_rand" != 1 ]]; then
readonly invert_rand=1
elif [[ "$1" == --renice ]]; then
if [[ ! "$(echo $2 | tr [0-9] ' ' | sed 's/^-//' | sed 's/ //g')" ]]; then
if [[ "$2" -le 19 ]] && [[ "$2" -ge -20 ]]; then
renice $2 $$ 1>/dev/null
else
echo "parameter input out-of-range!"
exit 1
fi
else
echo "invalid parameter input!"
exit 1
fi
shift
fi
shift
done
readonly version="0.0.2"
readonly BASE_NAME=$(basename $0)
readonly NO_EXTENSION=$(echo $BASE_NAME | sed 's/\..*//')
readonly backup_PATH=$PATH
readonly set_PATH=$(dirname $0 | sed 's/^\.//')
readonly set_PATH2=$(pwd)
if [[ "$set_PATH" ]]; then
if [[ "$(ls / | grep $(echo $set_PATH | tr -s / \\n | head -n2 | tr -s \\n / | sed 's/\/$//' | sed 's/^\///'))" ]] ; then
export PATH=$set_PATH:$PATH
else
export PATH=$set_PATH2:$PATH
fi
else
export PATH=$set_PATH2:$PATH
fi
reg_name=$(which $BASE_NAME 2>/dev/null) # somewhat seems to be incompatible with 1.22.1-stericson.
if [[ ! "$reg_name" ]]; then
echo "you are not running this program in proper location. this may cause trouble for codes that use this function: DIR_NAME"
readonly DIR_NAME="NULL" #'NULL' will go out instead of an actual directory name
else
readonly DIR_NAME=$(dirname $reg_name | sed 's/^\.//')
fi
export PATH=$backup_PATH # revert back to default
readonly FULL_NAME=$(echo $DIR_NAME/$BASE_NAME)
print_PARTIAL_DIR_NAME(){
echo $(echo $DIR_NAME | tr -s / \\n | head -n$(($1+1)) | tr -s \\n / | sed 's/\/$//')
}
readonly ROOT_DIR=$(print_PARTIAL_DIR_NAME 1)
print_RANDOM_BYTE(){
if [[ "$use_urand" != 1 ]]; then
rand=$(($(od -An -N2 -i /dev/random)%32767))
else
rand=$(($(od -An -N2 -i /dev/urandom)%32767))
fi
if [[ "$invert_rand" == 1 ]]; then
if [[ "$rand" -lt 0 ]]; then
rand=$(($((rand*-1))-1))
fi
fi
echo $rand #output
}
debug_shell(){
echo "welcome to the debug_shell program! type in: 'help' for more information."
echo -e -n "\e[1;32mdebug-\e[1;33m$version\e[0m"
if [[ "$su_check" == 0 ]]; then
echo -n '# '
else
echo -n '$ '
fi
while eval read i; do
case $i in
randtest)
while true; do echo -n $(print_RANDOM_BYTE); done
;;
help)
echo -e "this debug shell is \e[1;31mONLY\e[0m used for testing conditions inside this program!
it is not a complete shell as you CANNOT use any regex with it.
such includes:
-functions
-variables
-built-in sh or bash commands
instead, you can use these commands built-in to this program:
-print_PARTIAL_DIR_NAME
-print_RANDOM_BYTE
-Busybox_Applet_Generator
-Superuser
-any other functions built-in to this program...
you can use set command to view all the functions and variables built-in to this program.
you can also use these built-in commands in debug_shell:
-randtest (tests if print_RANDOM_BYTE is functioning properly)
-help (brings out this message)
debug_shell \e[1;33mv$version\e[0m
Copyright (C) 2013-2015 [email protected]"
;;
return*)
exit
;;
*)
$i
;;
esac
echo -e -n "\e[1;32mdebug-\e[1;33m$version\e[0m"
if [[ "$su_check" == 0 ]]; then
echo -n '# '
else
echo -n '$ '
fi
done
}
install(){
local loc # prevent breaks
n=0
for i in $(echo $PATH | sed 's/:/ /g'); do
n=$(($n+1))
export slot$n=$i
done
if [[ "$1" == -i ]]; then
for i in $(seq -s ' $slot' 0 $n | sed 's/^0//'); do
eval echo $i
done
else
echo $n hits.
for i in $(seq -s ' $slot' 0 $n | sed 's/^0//'); do
v=$(eval echo $i)
echo -n "would you like to install it in $v? (y/n) "
while true; do
read f
case $f in
y* | Y*)
loc=$v
break
;;
n* | N*)
break
;;
q* | Q*)
return 0
;;
*)
random=$(print_RANDOM_BYTE)
random=$((random%4+1))
if [[ "$random" -eq 1 ]]; then
echo -n 'what? '
elif [[ "$random" -eq 2 ]]; then
echo -n 'i dont understand. '
elif [[ "$random" -eq 3 ]]; then
echo -n 'come on mate, you could do better than that! '
elif [[ "$random" -eq 4 ]]; then
echo -n 'if i were you, i would choose the chicken. '
fi
;;
esac
done
if [[ "$loc" ]]; then
break
fi
done
if [[ ! "$loc" ]]; then
echo couldnt install, sorry. :p
return 1
fi
echo 'please wait...'
loc_DIR_NAME=$(echo $loc | tr -s / \\n | head -n2 | tr -s \\n / | sed 's/\/$//')
mountstat=$(grep $loc_DIR_NAME /proc/mounts | head -n1)
if [[ "$mountstat" ]]; then
if [[ "$(echo $mountstat | grep ro)" ]]; then
ro=1
echo -n -e '\rmounting...'
mount -o remount,rw $loc_DIR_NAME
fi
if [[ "$(echo $mountstat | grep rw)" ]]; then
echo -n -e '\rcopying files...'
cp $0 $loc/$NO_EXTENSION
if [[ "$?" == 1 ]]; then
return 1
fi
chmod 755 $loc/$NO_EXTENSION
if [[ "$ro" == 1 ]]; then
mount -o remount,ro $loc_DIR_NAME
fi
else
error=1
fi
else
error=1 # exception error
fi
if [[ "$error" == 1 ]]; then
echo -e "internal error! please use '--verbose' and try again. \e[1;31m\"error code 1\"\e[0m"
return 1
else
echo
long_line 2
echo install complete!
echo type $NO_EXTENSION to run the program!
fi
fi
}
long_line(){
for i in $(seq 1 $(tput cols 2>/dev/null)); do
if [[ "$1" -le 1 ]]; then
echo -n '-'
else
echo -n '='
fi
done
if [[ "$i" == 1 ]]; then
echo -n -e '\r'
if [[ "$1" -le 1 ]]; then # 80 columns
echo -n '--------------------------------------------------------------------------------'
else
echo -n '================================================================================'
fi
fi
echo
}
# chklnk.sh
#
# Copyright (C) 2013-2015 [email protected]
#
# Everyone is permitted to copy and distribute verbatim copies
# of this code, but changing it is not allowed.
#
# Changelogs:
# alpha version
# 0.0.1 - first release
# 0.0.2 - permission error support added.
# - revamped return command.
# - some codes borrowed from avcore.sh
# - skeleton.sh
set +e #error proof
# Busybox Applet Generator 2.4
# You can type in any commands you would want it to check.
# It will start by checking from cmd1, and its limit is up to cmd224.
cmd1=dirname
cmd2=basename
cmd3=ls
cmd4=grep
cmd5=head
cmd6=awk
cmd7=cat
cmd8=pgrep
cmd9=ps
cmd= # It notifies the generator how many cmds are available for check. Leave it as blank.
silent_mode=1 # enabling this will hide errors.
# This feature might not be compatible with some other multi-call binaries.
# if similar applets are found and Busybox do not have them, it will still continue but leave out some error messages regarding compatibility issues.
Busybox_Applet_Generator(){
local n i busyboxloc busyboxenv fail
if [[ ! "$(busybox)" ]]; then #allow non-Busybox users to continue.
if [[ "$silent_mode" != 1 ]]; then
echo "Busybox does not exist! Busybox is required for best compatibility!"
fi
if [[ "$cmd" ]]; then
if [[ "$cmd" -lt 0 ]]; then
cmd=0
fi
else
cmd=224
fi
for i in $(seq -s ' $cmd' 0 $cmd | sed 's/^0//'); do
v=$(eval echo $i)
if [[ "$v" ]]; then
if [[ ! "$(which $v)" ]]; then
if [[ "$silent_mode" != 1 ]]; then
echo "required applet: '$v' does not exist!"
fi
fail=1 #fail later
fi
else
break #reduce cycle
fi
done
else
busyboxloc=$(dirname $(which busybox))
n=0
for i in $(echo $PATH | sed 's/:/ /g'); do
n=$(($n+1))
export slot$n=$i
if [[ "$i" == "$busyboxloc" ]]; then
busyboxenv=slot$n
fi
done
if [[ "$busyboxenv" != slot1 ]]; then
export PATH=$(echo -n $busyboxloc
for i in $(seq -s ' $slot' 0 $n | sed 's/^0//'); do
v=$(eval echo $i)
if [[ "$v" != "$busyboxloc" ]]; then
echo -n ":$v"
fi
done)
fi
if [[ "$cmd" ]]; then
if [[ "$cmd" -lt 0 ]]; then
cmd=0
fi
else
cmd=224
fi
for i in $(seq -s ' $cmd' 0 $cmd | sed 's/^0//'); do
v=$(eval echo $i)
if [[ "$v" ]]; then
if [[ ! "$(busybox | grep "\<$v\>")" ]]; then
if [[ "$silent_mode" != 1 ]]; then
echo -n "required applet: '$v' not embedded in Busybox!"
fi
if [[ ! "$(which $v)" ]]; then
if [[ "$silent_mode" != 1 ]]; then
echo "...and also does not exist!"
fi
fail=1 #fail later
else
if [[ "$silent_mode" != 1 ]]; then
echo
fi
fi
fi
if [[ ! -e "$busyboxloc"/"$v" ]]; then
alias $i="busybox $i"
fi
else
break #reduce cycle
fi
done
fi 2>/dev/null
if [[ "$fail" == 1 ]]; then #the fail manager!
echo -e "process terminated. \e[1;31m\"error code 1\"\e[0m"
return 1
fi
}
# Check Superuser.
su_check= # root availability
Superuser(){
su_check=0
if [[ "$(grep -i "^Uid:" /proc/$$/status | awk '{print $2}')" != 0 ]]; then
su_check=1
echo "Permission denied, are you root?"
return 1
fi
}
# Session behaviour
Roll_Down(){
local return
if [[ "$run_Busybox_Applet_Generator" == 1 ]]; then
Busybox_Applet_Generator
return=$?
if [[ "$return" -ne 0 ]]; then
exit $return
fi
fi
if [[ "$run_Superuser" == 1 ]]; then
Superuser
return=$?
if [[ "$return" -ne 0 ]]; then
exit $return
fi
fi
}
Roll_Down
# Main script
case $1 in
-h | --help)
echo "$BASE_NAME v$version
Copyright (C) 2013-2015 [email protected]
Usage: $BASE_NAME [LOCATION] -h
"
shift
exit 0
;;
*)
if [[ ! "$1" ]]; then
exit 0
fi
;;
esac
file=$1
dir=$(dirname $file)
base=$(basename $file)
if [ ! -e "$file" ] && [ ! -d "$file" ]; then
echo "$file: not found"
exit 127
fi
count=0
for i in $(ls -l $dir | grep $base | head -1); do
count=$((count+1))
if [ "$i" == "->" ]; then
found=y
break
fi
done 2>/dev/null
return=$?
if [ "$return" != 0 ]; then
echo "$file: operation not permitted"
exit $return
fi
if [ ! "$found" ] || [ "$file" == "/" ]; then
echo "$file: is not a symlink"
exit 1
fi
#link=$((count-1))
orig=$((count+1))
linked_file=$(ls -l $dir | grep $base | head -1 | awk '{print $'"$orig"'}')
echo "$linked_file"
exit 0 #EOF
Code:
# Custom settings for session behaviour
# values for all settings should either be 1 or 0.
# Check Busybox Applet Generator 2.4.
run_Busybox_Applet_Generator=1
# Check Superuser.
run_Superuser=1
# Use /dev/urandom for print_RANDOM_BYTE.
use_urand=1
# invert print_RANDOM_BYTE.
invert_rand=1
until [[ "$1" != --verbose ]] && [[ "$1" != --supass ]] && [[ "$1" != --bbpass ]] && [[ "$1" != --urand ]] && [[ "$1" != --invrand ]] && [[ "$1" != --renice ]]; do
if [[ "$1" == --verbose ]]; then
set -x
elif [[ "$1" == --supass ]] && [[ "$run_Superuser" != 0 ]]; then
readonly run_Superuser=0
elif [[ "$1" == --bbpass ]] && [[ "$run_Busybox_Applet_Generator" != 0 ]]; then
readonly run_Busybox_Applet_Generator=0
elif [[ "$1" == --urand ]] && [[ "$use_urand" != 1 ]]; then
readonly use_urand=1
elif [[ "$1" == --invrand ]] && [[ "$invert_rand" != 1 ]]; then
readonly invert_rand=1
elif [[ "$1" == --renice ]]; then
if [[ ! "$(echo $2 | tr [0-9] ' ' | sed 's/^-//' | sed 's/ //g')" ]]; then
if [[ "$2" -le 19 ]] && [[ "$2" -ge -20 ]]; then
renice $2 $$ 1>/dev/null
else
echo "parameter input out-of-range!"
exit 1
fi
else
echo "invalid parameter input!"
exit 1
fi
shift
fi
shift
done
readonly version="0.1"
readonly BASE_NAME=$(basename $0)
readonly NO_EXTENSION=$(echo $BASE_NAME | sed 's/\..*//')
readonly backup_PATH=$PATH
readonly set_PATH=$(dirname $0 | sed 's/^\.//')
readonly set_PATH2=$(pwd)
if [[ "$set_PATH" ]]; then
if [[ "$(ls / | grep $(echo $set_PATH | tr -s / \\n | head -n2 | tr -s \\n / | sed 's/\/$//' | sed 's/^\///'))" ]] ; then
export PATH=$set_PATH:$PATH
else
export PATH=$set_PATH2:$PATH
fi
else
export PATH=$set_PATH2:$PATH
fi
reg_name=$(which $BASE_NAME 2>/dev/null) # somewhat seems to be incompatible with 1.22.1-stericson.
if [[ ! "$reg_name" ]]; then
echo "you are not running this program in proper location. this may cause trouble for codes that use this function: DIR_NAME"
readonly DIR_NAME="NULL" #'NULL' will go out instead of an actual directory name
else
readonly DIR_NAME=$(dirname $reg_name | sed 's/^\.//')
fi
export PATH=$backup_PATH # revert back to default
readonly FULL_NAME=$(echo $DIR_NAME/$BASE_NAME)
print_PARTIAL_DIR_NAME(){
echo $(echo $DIR_NAME | tr -s / \\n | head -n$(($1+1)) | tr -s \\n / | sed 's/\/$//')
}
readonly ROOT_DIR=$(print_PARTIAL_DIR_NAME 1)
print_RANDOM_BYTE(){
if [[ "$use_urand" != 1 ]]; then
rand=$(($(od -An -N2 -i /dev/random)%32767))
else
rand=$(($(od -An -N2 -i /dev/urandom)%32767))
fi
if [[ "$invert_rand" == 1 ]]; then
if [[ "$rand" -lt 0 ]]; then
rand=$(($((rand*-1))-1))
fi
fi
echo $rand #output
}
debug_shell(){
echo "welcome to the debug_shell program! type in: 'help' for more information."
echo -e -n "\e[1;32mdebug-\e[1;33m$version\e[0m"
if [[ "$su_check" == 0 ]]; then
echo -n '# '
else
echo -n '$ '
fi
while eval read i; do
case $i in
randtest)
while true; do echo -n $(print_RANDOM_BYTE); done
;;
help)
echo -e "this debug shell is \e[1;31mONLY\e[0m used for testing conditions inside this program!
it is not a complete shell as you CANNOT use any regex with it.
such includes:
-functions
-variables
-built-in sh or bash commands
instead, you can use these commands built-in to this program:
-print_PARTIAL_DIR_NAME
-print_RANDOM_BYTE
-Busybox_Applet_Generator
-Superuser
-any other functions built-in to this program...
you can use set command to view all the functions and variables built-in to this program.
you can also use these built-in commands in debug_shell:
-randtest (tests if print_RANDOM_BYTE is functioning properly)
-help (brings out this message)
debug_shell \e[1;33mv$version\e[0m
Copyright (C) 2013-2015 [email protected]"
;;
return*)
exit
;;
*)
$i
;;
esac
echo -e -n "\e[1;32mdebug-\e[1;33m$version\e[0m"
if [[ "$su_check" == 0 ]]; then
echo -n '# '
else
echo -n '$ '
fi
done
}
install(){
local loc # prevent breaks
n=0
for i in $(echo $PATH | sed 's/:/ /g'); do
n=$(($n+1))
export slot$n=$i
done
if [[ "$1" == -i ]]; then
for i in $(seq -s ' $slot' 0 $n | sed 's/^0//'); do
eval echo $i
done
else
echo $n hits.
for i in $(seq -s ' $slot' 0 $n | sed 's/^0//'); do
v=$(eval echo $i)
echo -n "would you like to install it in $v? (y/n) "
while true; do
read f
case $f in
y* | Y*)
loc=$v
break
;;
n* | N*)
break
;;
q* | Q*)
return 0
;;
*)
random=$(print_RANDOM_BYTE)
random=$((random%4+1))
if [[ "$random" -eq 1 ]]; then
echo -n 'what? '
elif [[ "$random" -eq 2 ]]; then
echo -n 'i dont understand. '
elif [[ "$random" -eq 3 ]]; then
echo -n 'come on mate, you could do better than that! '
elif [[ "$random" -eq 4 ]]; then
echo -n 'if i were you, i would choose the chicken. '
fi
;;
esac
done
if [[ "$loc" ]]; then
break
fi
done
if [[ ! "$loc" ]]; then
echo couldnt install, sorry. :p
return 1
fi
echo 'please wait...'
loc_DIR_NAME=$(echo $loc | tr -s / \\n | head -n2 | tr -s \\n / | sed 's/\/$//')
mountstat=$(grep $loc_DIR_NAME /proc/mounts | head -n1)
if [[ "$mountstat" ]]; then
if [[ "$(echo $mountstat | grep ro)" ]]; then
ro=1
echo -n -e '\rmounting...'
mount -o remount,rw $loc_DIR_NAME
fi
if [[ "$(echo $mountstat | grep rw)" ]]; then
echo -n -e '\rcopying files...'
cp $0 $loc/$NO_EXTENSION
if [[ "$?" == 1 ]]; then
return 1
fi
chmod 755 $loc/$NO_EXTENSION
if [[ "$ro" == 1 ]]; then
mount -o remount,ro $loc_DIR_NAME
fi
else
error=1
fi
else
error=1 # exception error
fi
if [[ "$error" == 1 ]]; then
echo -e "internal error! please use '--verbose' and try again. \e[1;31m\"error code 1\"\e[0m"
return 1
else
echo
long_line 2
echo install complete!
echo type $NO_EXTENSION to run the program!
fi
fi
}
long_line(){
for i in $(seq 1 $(tput cols 2>/dev/null)); do
if [[ "$1" -le 1 ]]; then
echo -n '-'
else
echo -n '='
fi
done
if [[ "$i" == 1 ]]; then
echo -n -e '\r'
if [[ "$1" -le 1 ]]; then # 80 columns
echo -n '--------------------------------------------------------------------------------'
else
echo -n '================================================================================'
fi
fi
echo
}
# skeleton.sh
#
# Copyright (C) 2013-2015 [email protected]
#
# Everyone is permitted to copy and distribute verbatim copies
# of this code, but changing it is not allowed.
#
# Changelogs:
set +e #error proof
# Busybox Applet Generator 2.4
# You can type in any commands you would want it to check.
# It will start by checking from cmd1, and its limit is up to cmd224.
cmd1=dirname
cmd2=basename
cmd3=ls
cmd4=grep
cmd5=head
cmd6=awk
cmd7=cat
cmd8=pgrep
cmd9=ps
cmd10=chrt
cmd11=cp
cmd= # It notifies the generator how many cmds are available for check. Leave it as blank.
silent_mode= # enabling this will hide errors.
# This feature might not be compatible with some other multi-call binaries.
# if similar applets are found and Busybox do not have them, it will still continue but leave out some error messages regarding compatibility issues.
Busybox_Applet_Generator(){
local n i busyboxloc busyboxenv fail
if [[ ! "$(busybox)" ]]; then #allow non-Busybox users to continue.
if [[ "$silent_mode" != 1 ]]; then
echo "Busybox does not exist! Busybox is required for best compatibility!"
fi
if [[ "$cmd" ]]; then
if [[ "$cmd" -lt 0 ]]; then
cmd=0
fi
else
cmd=224
fi
for i in $(seq -s ' $cmd' 0 $cmd | sed 's/^0//'); do
v=$(eval echo $i)
if [[ "$v" ]]; then
if [[ ! "$(which $v)" ]]; then
if [[ "$silent_mode" != 1 ]]; then
echo "required applet: '$v' does not exist!"
fi
fail=1 #fail later
fi
else
break #reduce cycle
fi
done
else
busyboxloc=$(dirname $(which busybox))
n=0
for i in $(echo $PATH | sed 's/:/ /g'); do
n=$(($n+1))
export slot$n=$i
if [[ "$i" == "$busyboxloc" ]]; then
busyboxenv=slot$n
fi
done
if [[ "$busyboxenv" != slot1 ]]; then
export PATH=$(echo -n $busyboxloc
for i in $(seq -s ' $slot' 0 $n | sed 's/^0//'); do
v=$(eval echo $i)
if [[ "$v" != "$busyboxloc" ]]; then
echo -n ":$v"
fi
done)
fi
if [[ "$cmd" ]]; then
if [[ "$cmd" -lt 0 ]]; then
cmd=0
fi
else
cmd=224
fi
for i in $(seq -s ' $cmd' 0 $cmd | sed 's/^0//'); do
v=$(eval echo $i)
if [[ "$v" ]]; then
if [[ ! "$(busybox | grep "\<$v\>")" ]]; then
if [[ "$silent_mode" != 1 ]]; then
echo -n "required applet: '$v' not embedded in Busybox!"
fi
if [[ ! "$(which $v)" ]]; then
if [[ "$silent_mode" != 1 ]]; then
echo "...and also does not exist!"
fi
fail=1 #fail later
else
if [[ "$silent_mode" != 1 ]]; then
echo
fi
fi
fi
if [[ ! -e "$busyboxloc"/"$v" ]]; then
alias $i="busybox $i"
fi
else
break #reduce cycle
fi
done
fi 2>/dev/null
if [[ "$fail" == 1 ]]; then #the fail manager!
echo -e "process terminated. \e[1;31m\"error code 1\"\e[0m"
return 1
fi
}
# Check Superuser.
su_check= # root availability
Superuser(){
su_check=0
if [[ "$(grep -i "^Uid:" /proc/$$/status | awk '{print $2}')" != 0 ]]; then
su_check=1
echo "Permission denied, are you root?"
return 1
fi
}
# Session behaviour
Roll_Down(){
local return
if [[ "$run_Busybox_Applet_Generator" == 1 ]]; then
Busybox_Applet_Generator
return=$?
if [[ "$return" -ne 0 ]]; then
exit $return
fi
fi
if [[ "$run_Superuser" == 1 ]]; then
Superuser
return=$?
if [[ "$return" -ne 0 ]]; then
exit $return
fi
fi
}
Roll_Down
process=$1
suddencharge=$2
sleep=$3
task(){
stat=$(cat /proc/$1/task/$2/stat)
rm=${stat#*)}
last_prio=$(echo $rm | cut -d' ' -f17)
proctime=$(echo $rm | cut -d' ' -f12)
while true
do
if [[ ! $(cat /proc/$1/task/$2/stat) ]]; then
exit
fi
prev_proctime=$proctime
stat=$(cat /proc/$1/task/$2/stat)
rm=${stat#*)}
proctime=$(echo $rm | cut -d' ' -f12)
buffer=$(echo $proctime $prev_proctime $4 | awk '{printf "%d\n", ($1-$2)/$3}')
#buffer=$(echo $proctime $prev_proctime $4 | awk '{print ($1-$2)/$3}' | cut -d'.' -f1)
if [[ $buffer -gt $3 ]]; then
renice $5 $2
else
renice $last_prio $2
fi
sleep $4
done | tee 2>&1 /data/log/skeleton.log
}
fork(){
until [[ $(pgrep $1) ]]
do
sleep 1
done
pid=$(pgrep $1)
if [[ $(ls /proc/$pid/task) ]]; then
for i in $(ls /proc/$pid/task)
do
task $pid $i $2 $3 $4 &
done
fi 2>/dev/null
}
#fork $process $suddencharge $sleep $nice
test_task(){
stat=$(cat /proc/$1/task/$2/stat)
rm=${stat#*)}
last_prio=$(echo $rm | cut -d' ' -f17)
proctime=$(echo $rm | cut -d' ' -f12)
while true
do
if [[ ! $(cat /proc/$1/task/$2/stat) ]]; then
exit
fi
prev_proctime=$proctime
stat=$(cat /proc/$1/task/$2/stat)
rm=${stat#*)}
proctime=$(echo $rm | cut -d' ' -f12)
buffer=$(echo $proctime $prev_proctime $4 | awk '{printf "%d\n", ($1-$2)/$3}')
#buffer=$(echo $proctime $prev_proctime $4 | awk '{print ($1-$2)/$3}' | cut -d'.' -f1)
if [[ $buffer -gt $3 ]]; then
renice $5 $2
else
renice $last_prio $2
fi
sleep $4
done | tee 2>&1 /data/log/skeleton.log
}
#exit
#todo: limit threads that illegaly use -20.
#top
testdebug(){
process=$1
sleep=$2
if [[ ! $sleep ]]; then
sleep=5
fi
while true
do
gprocess=$(pgrep $process)
if [[ "$gprocess" ]]; then
for i in $(ls /proc/$gprocess/task); do
echo -e "\e[1;31m$(cat /proc/$gprocess/task/$i/comm)\e[0m -> \e[1;32m$(cat /proc/$gprocess/task/$i/wchan)\e[0m"
stat=$(cat /proc/$gprocess/task/$i/stat)
rm=${stat#*)}
nicelevel=$(echo $rm | cut -d' ' -f17)
echo "nicelevel:$nicelevel"
echo -e $(cat /proc/$gprocess/task/$i/stat)
if [[ "$3" == 1 ]]; then
if [[ $(grep -i 'congestion\|0\|linux' /proc/$gprocess/task/$i/wchan) ]] && [[ $(cat /proc/$gprocess/comm) == $(cat /proc/$gprocess/task/$i/comm) ]]; then
pid=$i
renice -20 $i
else
if [[ $pid != $i ]] && [[ $nicelevel -le -16 ]]; then
#if [[ $(grep -i 'audio' /proc/$gprocess/task/$i/comm) ]]; then
renice 19 $i
#else
#renice 0 $i
#fi
fi
fi
fi
echo
done
else
echo waiting...
fi
sleep $sleep
echo
echo
echo
long_line 2
done | tee 2>&1 /data/log/****.txt
}
test(){
process=$1
sleep=$2
if [[ ! $sleep ]]; then
sleep=5
fi
echo waiting...
until [[ $(pgrep $process) ]]; do sleep 1; done
while true; do
gprocess=$(pgrep $process)
if [[ "$gprocess" ]]; then
clear
echo pid $gprocess is being monitored.
for i in $(ls /proc/$gprocess/task); do
stat=$(cat /proc/$gprocess/task/$i/stat)
rm=${stat#*)}
nicelevel=$(echo $rm | cut -d' ' -f17)
echo $i $nicelevel $(cat /proc/$gprocess/task/$i/wchan)
if [[ $(grep -i 'congestion\|0\|linux' /proc/$gprocess/task/$i/wchan) ]] && [[ $(cat /proc/$gprocess/comm) == $(cat /proc/$gprocess/task/$i/comm) ]] && [[ $gprocess != $i ]]; then
pid=$i
if [[ $3 != 1 ]]; then
renice -20 $i
else
chrt -f -p 1 $i
fi
else
if [[ $pid != $i ]] && [[ $nicelevel -le -16 ]]; then
#if [[ $(grep -i 'audio' /proc/$gprocess/task/$i/comm) ]]; then
renice 19 $i
#else
#renice 0 $i
#fi
fi
fi
done
else
echo process ended.
break
fi
sleep $sleep
done
}
#test range!
#echo $version #show version number
#echo $BASE_NAME
#echo $DIR_NAME
#echo $FULL_NAME
#print_PARTIAL_DIR_NAME 1 #print home directory(will work only when DIR_NAME works)
#print_RANDOM_BYTE #print random number upto 32767
echo thread priority manager beta v0.1
echo only tested in applications that use congestion_wait sched!
long_line 1
if [[ ! "$(echo $(install -i) | grep $DIR_NAME | sed 's/ //g')" ]]; then
echo "type 'install' to begin installation!"
else
echo 'test [app name] [interval] [rt_sched]'
echo '-useful for processes that use congestion_wait scheduler'
echo 'fork [app name] [throttle] [interval(float)] [niceness]'
echo '-useful for preventing processes that randomly spark their thread priority to max'
fi
debug_shell
exit 0 #EOF
Code:
# Custom settings for session behaviour
# values for all settings should either be 1 or 0.
# Check Busybox Applet Generator 2.4.
run_Busybox_Applet_Generator=1
# Check Superuser.
run_Superuser=
# Use /dev/urandom for print_RANDOM_BYTE.
use_urand=1
# invert print_RANDOM_BYTE.
invert_rand=1
until [[ "$1" != --verbose ]] && [[ "$1" != --supass ]] && [[ "$1" != --bbpass ]] && [[ "$1" != --urand ]] && [[ "$1" != --invrand ]] && [[ "$1" != --renice ]]; do
if [[ "$1" == --verbose ]]; then
set -x
elif [[ "$1" == --supass ]] && [[ "$run_Superuser" != 0 ]]; then
readonly run_Superuser=0
elif [[ "$1" == --bbpass ]] && [[ "$run_Busybox_Applet_Generator" != 0 ]]; then
readonly run_Busybox_Applet_Generator=0
elif [[ "$1" == --urand ]] && [[ "$use_urand" != 1 ]]; then
readonly use_urand=1
elif [[ "$1" == --invrand ]] && [[ "$invert_rand" != 1 ]]; then
readonly invert_rand=1
elif [[ "$1" == --renice ]]; then
if [[ ! "$(echo $2 | tr [0-9] ' ' | sed 's/^-//' | sed 's/ //g')" ]]; then
if [[ "$2" -le 19 ]] && [[ "$2" -ge -20 ]]; then
renice $2 $$ 1>/dev/null
else
echo "parameter input out-of-range!"
exit 1
fi
else
echo "invalid parameter input!"
exit 1
fi
shift
fi
shift
done
readonly version="0.2"
readonly BASE_NAME=$(basename $0)
readonly NO_EXTENSION=$(echo $BASE_NAME | sed 's/\..*//')
readonly backup_PATH=$PATH
readonly set_PATH=$(dirname $0 | sed 's/^\.//')
readonly set_PATH2=$(pwd)
if [[ "$set_PATH" ]]; then
if [[ "$(ls / | grep $(echo $set_PATH | tr -s / \\n | head -n2 | tr -s \\n / | sed 's/\/$//' | sed 's/^\///'))" ]] ; then
export PATH=$set_PATH:$PATH
else
export PATH=$set_PATH2:$PATH
fi
else
export PATH=$set_PATH2:$PATH
fi
reg_name=$(which $BASE_NAME 2>/dev/null) # somewhat seems to be incompatible with 1.22.1-stericson.
if [[ ! "$reg_name" ]]; then
echo "you are not running this program in proper location. this may cause trouble for codes that use this function: DIR_NAME"
readonly DIR_NAME="NULL" #'NULL' will go out instead of an actual directory name
else
readonly DIR_NAME=$(dirname $reg_name | sed 's/^\.//')
fi
export PATH=$backup_PATH # revert back to default
readonly FULL_NAME=$(echo $DIR_NAME/$BASE_NAME)
print_PARTIAL_DIR_NAME(){
echo $(echo $DIR_NAME | tr -s / \\n | head -n$(($1+1)) | tr -s \\n / | sed 's/\/$//')
}
readonly ROOT_DIR=$(print_PARTIAL_DIR_NAME 1)
print_RANDOM_BYTE(){
if [[ "$use_urand" != 1 ]]; then
rand=$(($(od -An -N2 -i /dev/random)%32767))
else
rand=$(($(od -An -N2 -i /dev/urandom)%32767))
fi
if [[ "$invert_rand" == 1 ]]; then
if [[ "$rand" -lt 0 ]]; then
rand=$(($((rand*-1))-1))
fi
fi
echo $rand #output
}
debug_shell(){
echo "welcome to the debug_shell program! type in: 'help' for more information."
echo -e -n "\e[1;32mdebug-\e[1;33m$version\e[0m"
if [[ "$su_check" == 0 ]]; then
echo -n '# '
else
echo -n '$ '
fi
while eval read i; do
case $i in
randtest)
while true; do echo -n $(print_RANDOM_BYTE); done
;;
help)
echo -e "this debug shell is \e[1;31mONLY\e[0m used for testing conditions inside this program!
it is not a complete shell as you CANNOT use any regex with it.
such includes:
-functions
-variables
-built-in sh or bash commands
instead, you can use these commands built-in to this program:
-print_PARTIAL_DIR_NAME
-print_RANDOM_BYTE
-Busybox_Applet_Generator
-Superuser
-any other functions built-in to this program...
you can use set command to view all the functions and variables built-in to this program.
you can also use these built-in commands in debug_shell:
-randtest (tests if print_RANDOM_BYTE is functioning properly)
-help (brings out this message)
debug_shell \e[1;33mv$version\e[0m
Copyright (C) 2013-2015 [email protected]"
;;
return*)
exit
;;
*)
$i
;;
esac
echo -e -n "\e[1;32mdebug-\e[1;33m$version\e[0m"
if [[ "$su_check" == 0 ]]; then
echo -n '# '
else
echo -n '$ '
fi
done
}
install(){
local loc # prevent breaks
n=0
for i in $(echo $PATH | sed 's/:/ /g'); do
n=$(($n+1))
export slot$n=$i
done
if [[ "$1" == -i ]]; then
for i in $(seq -s ' $slot' 0 $n | sed 's/^0//'); do
eval echo $i
done
else
echo $n hits.
for i in $(seq -s ' $slot' 0 $n | sed 's/^0//'); do
v=$(eval echo $i)
echo -n "would you like to install it in $v? (y/n) "
while true; do
read f
case $f in
y* | Y*)
loc=$v
break
;;
n* | N*)
break
;;
q* | Q*)
return 0
;;
*)
random=$(print_RANDOM_BYTE)
random=$((random%4+1))
if [[ "$random" -eq 1 ]]; then
echo -n 'what? '
elif [[ "$random" -eq 2 ]]; then
echo -n 'i dont understand. '
elif [[ "$random" -eq 3 ]]; then
echo -n 'come on mate, you could do better than that! '
elif [[ "$random" -eq 4 ]]; then
echo -n 'if i were you, i would choose the chicken. '
fi
;;
esac
done
if [[ "$loc" ]]; then
break
fi
done
if [[ ! "$loc" ]]; then
echo couldnt install, sorry. :p
return 1
fi
echo 'please wait...'
loc_DIR_NAME=$(echo $loc | tr -s / \\n | head -n2 | tr -s \\n / | sed 's/\/$//')
mountstat=$(grep $loc_DIR_NAME /proc/mounts | head -n1)
if [[ "$mountstat" ]]; then
if [[ "$(echo $mountstat | grep ro)" ]]; then
ro=1
echo -n -e '\rmounting...'
mount -o remount,rw $loc_DIR_NAME
fi
if [[ "$(echo $mountstat | grep rw)" ]]; then
echo -n -e '\rcopying files...'
cp $0 $loc/$NO_EXTENSION
if [[ "$?" == 1 ]]; then
return 1
fi
chmod 755 $loc/$NO_EXTENSION
if [[ "$ro" == 1 ]]; then
mount -o remount,ro $loc_DIR_NAME
fi
else
error=1
fi
else
error=1 # exception error
fi
if [[ "$error" == 1 ]]; then
echo -e "internal error! please use '--verbose' and try again. \e[1;31m\"error code 1\"\e[0m"
return 1
else
echo
long_line 2
echo install complete!
echo type $NO_EXTENSION to run the program!
fi
fi
}
long_line(){
for i in $(seq 1 $(tput cols 2>/dev/null)); do
if [[ "$1" -le 1 ]]; then
echo -n '-'
else
echo -n '='
fi
done
if [[ "$i" == 1 ]]; then
echo -n -e '\r'
if [[ "$1" -le 1 ]]; then # 80 columns
echo -n '--------------------------------------------------------------------------------'
else
echo -n '================================================================================'
fi
fi
echo
}
# cpuramcheck.sh
#
# Copyright (C) 2013-2015 [email protected]
#
# Everyone is permitted to copy and distribute verbatim copies
# of this code, but changing it is not allowed.
#
# Changelogs:
set +e #error proof
# Busybox Applet Generator 2.4
# You can type in any commands you would want it to check.
# It will start by checking from cmd1, and its limit is up to cmd224.
cmd1=ls
cmd= # It notifies the generator how many cmds are available for check. Leave it as blank.
silent_mode= # enabling this will hide errors.
# This feature might not be compatible with some other multi-call binaries.
# if similar applets are found and Busybox do not have them, it will still continue but leave out some error messages regarding compatibility issues.
Busybox_Applet_Generator(){
local n i busyboxloc busyboxenv fail
if [[ ! "$(busybox)" ]]; then #allow non-Busybox users to continue.
if [[ "$silent_mode" != 1 ]]; then
echo "Busybox does not exist! Busybox is required for best compatibility!"
fi
if [[ "$cmd" ]]; then
if [[ "$cmd" -lt 0 ]]; then
cmd=0
fi
else
cmd=224
fi
for i in $(seq -s ' $cmd' 0 $cmd | sed 's/^0//'); do
v=$(eval echo $i)
if [[ "$v" ]]; then
if [[ ! "$(which $v)" ]]; then
if [[ "$silent_mode" != 1 ]]; then
echo "required applet: '$v' does not exist!"
fi
fail=1 #fail later
fi
else
break #reduce cycle
fi
done
else
busyboxloc=$(dirname $(which busybox))
n=0
for i in $(echo $PATH | sed 's/:/ /g'); do
n=$(($n+1))
export slot$n=$i
if [[ "$i" == "$busyboxloc" ]]; then
busyboxenv=slot$n
fi
done
if [[ "$busyboxenv" != slot1 ]]; then
export PATH=$(echo -n $busyboxloc
for i in $(seq -s ' $slot' 0 $n | sed 's/^0//'); do
v=$(eval echo $i)
if [[ "$v" != "$busyboxloc" ]]; then
echo -n ":$v"
fi
done)
fi
if [[ "$cmd" ]]; then
if [[ "$cmd" -lt 0 ]]; then
cmd=0
fi
else
cmd=224
fi
for i in $(seq -s ' $cmd' 0 $cmd | sed 's/^0//'); do
v=$(eval echo $i)
if [[ "$v" ]]; then
if [[ ! "$(busybox | grep "\<$v\>")" ]]; then
if [[ "$silent_mode" != 1 ]]; then
echo -n "required applet: '$v' not embedded in Busybox!"
fi
if [[ ! "$(which $v)" ]]; then
if [[ "$silent_mode" != 1 ]]; then
echo "...and also does not exist!"
fi
fail=1 #fail later
else
if [[ "$silent_mode" != 1 ]]; then
echo
fi
fi
fi
if [[ ! -e "$busyboxloc"/"$v" ]]; then
alias $i="busybox $i"
fi
else
break #reduce cycle
fi
done
fi 2>/dev/null
if [[ "$fail" == 1 ]]; then #the fail manager!
echo -e "process terminated. \e[1;31m\"error code 1\"\e[0m"
return 1
fi
}
# Check Superuser.
su_check= # root availability
Superuser(){
su_check=0
if [[ "$(grep -i "^Uid:" /proc/$$/status | awk '{print $2}')" != 0 ]]; then
su_check=1
echo "Permission denied, are you root?"
return 1
fi
}
# Session behaviour
Roll_Down(){
local return
if [[ "$run_Busybox_Applet_Generator" == 1 ]]; then
Busybox_Applet_Generator
return=$?
if [[ "$return" -ne 0 ]]; then
exit $return
fi
fi
if [[ "$run_Superuser" == 1 ]]; then
Superuser
return=$?
if [[ "$return" -ne 0 ]]; then
exit $return
fi
fi
}
Roll_Down
# Main script
case $1 in
-h | --help)
echo "$BASE_NAME v$version
Copyright (C) 2013-2015 [email protected]
Usage: $BASE_NAME [interval] [bar_length] -h -i -d
"
shift
exit 0
;;
-i)
proto=1
shift
;;
-d | --debug)
debug_shell
shift
;;
esac
if [[ "$proto" == 1 ]]; then
IFS=','
for i in $(grep cpu /proc/stat | tr '\n' ','); do
eval prev_$(echo $i | cut -d' ' -f1)_total=$(IFS=' '; x=0; for j in $(echo $i | cut -d' ' -f2-); do x=$((x+j)); done; echo $x)
eval prev_$(echo $i | cut -d' ' -f1)_idle=$(echo $i | cut -d' ' -f2- | cut -d' ' -f4)
done
unset IFS
while true; do
memfree=$(cat /proc/meminfo | grep -i memfree | awk '{print $2}')
cached=$(cat /proc/meminfo | grep -i cached | awk '{print $2}')
memtotal=$(cat /proc/meminfo | grep -i memtotal | awk '{print $2}')
memused=$(echo $memtotal $cached $memfree | awk '{print $1-$2-$3}')
usedmb=$(($memused/1024))
usedGB=$(echo $usedmb | awk '{printf "%.2f", $1/1024}')
if [[ "$usedmb" -ge 1000 ]]; then
iused="$usedGB"GB
else
iused="$usedmb"MB
fi
totalmb=$(($memtotal/1024))
totalGB=$(echo $totalmb | awk '{printf "%.2f", $1/1024}')
if [[ "$totalmb" -ge 1000 ]]; then
itotal="$totalGB"GB
else
itotal="$totalmb"MB
fi
if [[ "$2" ]]; then
count=$2
else
count=25
fi
ibar=$(echo $usedmb $totalmb $count | awk '{printf "%d", $1/$2*$3}')
isheep=$(for x in $(seq 1 $count); do
if [[ "$x" -le "$ibar" ]]; then
echo -n -e '|'
else
echo -n -e 'o'
fi
done)
echo -n -e "\e[3;m\rtotal " #invert color
IFS=','
for i in $(grep cpu /proc/stat | tr '\n' ','); do
total=$(IFS=' '; x=0; for j in $(echo $i | cut -d' ' -f2-); do x=$((x+j)); done; echo $x)
idle=$(echo $i | cut -d' ' -f2- | cut -d' ' -f4)
eval diff_$(echo $i | cut -d' ' -f1)_total=$(($total-$(eval echo \$prev_$(echo $i | cut -d' ' -f1)_total)))
eval diff_$(echo $i | cut -d' ' -f1)_idle=$(($idle-$(eval echo \$prev_$(echo $i | cut -d' ' -f1)_idle)))
eval prev_$(echo $i | cut -d' ' -f1)_total=$total
eval prev_$(echo $i | cut -d' ' -f1)_idle=$idle
usage=$(($((1000*$(($(eval echo \$diff_$(echo $i | cut -d' ' -f1)_total)-$(eval echo \$diff_$(echo $i | cut -d' ' -f1)_idle)))/$(eval echo \$diff_$(echo $i | cut -d' ' -f1)_total)+5))/10))
if [[ "$usage" -lt 10 ]]; then
echo -n -e "$(echo $i | cut -d' ' -f1) usage: $usage%"
elif [[ "$usage" -lt 100 ]]; then
echo -n -e "$(echo $i | cut -d' ' -f1) usage: $usage%"
else
echo -n -e "$(echo $i | cut -d' ' -f1) usage:$usage%"
fi
echo -n -e " "
done
unset IFS
if [[ "$usedmb" -ge 1000 ]]; then
echo -n -e "RAM usage: $iused/$itotal"
else
if [[ "$usedmb" -lt 10 ]]; then
echo -n -e "RAM usage: $iused/$itotal"
elif [[ "$usedmb" -lt 100 ]]; then
echo -n -e "RAM usage: $iused/$itotal"
elif [[ "$usedmb" -lt 1000 ]]; then
echo -n -e "RAM usage: $iused/$itotal"
fi
fi
echo -n -e " "
echo -n -e $isheep
echo -n -e "\e[0m"
if [[ "$1" ]]; then
sleep $1
else
sleep 1
fi
done
else
prev_total=0
prev_idle=0
while true; do
cpu=$(cat /proc/stat | head -n1 | sed 's/cpu //')
idle=$(echo $cpu | awk '{print $4}')
total=$(echo $cpu | awk '{print $1+$2+$3+$4+$5+$6+$7+$8}')
diff_idle=$(($idle-$prev_idle))
diff_total=$(($total-$prev_total))
usage=$(($((1000*$(($diff_total-$diff_idle))/$diff_total+5))/10))
memfree=$(cat /proc/meminfo | grep -i memfree | awk '{print $2}')
cached=$(cat /proc/meminfo | grep -i cached | awk '{print $2}')
memtotal=$(cat /proc/meminfo | grep -i memtotal | awk '{print $2}')
memused=$(echo $memtotal $cached $memfree | awk '{print $1-$2-$3}')
usedmb=$(($memused/1024))
usedGB=$(echo $usedmb | awk '{printf "%.2f", $1/1024}')
if [[ "$usedmb" -ge 1000 ]]; then
iused="$usedGB"GB
else
iused="$usedmb"MB
fi
totalmb=$(($memtotal/1024))
totalGB=$(echo $totalmb | awk '{printf "%.2f", $1/1024}')
if [[ "$totalmb" -ge 1000 ]]; then
itotal="$totalGB"GB
else
itotal="$totalmb"MB
fi
if [[ "$2" ]]; then
count=$2
else
count=25
fi
ibar=$(echo $usedmb $totalmb $count | awk '{printf "%d", $1/$2*$3}')
isheep=$(for x in $(seq 1 $count); do
if [[ "$x" -le "$ibar" ]]; then
echo -n -e '|'
else
echo -n -e 'o'
fi
done)
echo -n -e "\e[3;m\r" #invert color
if [[ "$usage" -lt 10 ]]; then
echo -n -e "CPU usage: $usage%"
elif [[ "$usage" -lt 100 ]]; then
echo -n -e "CPU usage: $usage%"
else
echo -n -e "CPU usage:$usage%"
fi
echo -n -e " "
if [[ "$usedmb" -ge 1000 ]]; then
echo -n -e "RAM usage: $iused/$itotal"
else
if [[ "$usedmb" -lt 10 ]]; then
echo -n -e "RAM usage: $iused/$itotal"
elif [[ "$usedmb" -lt 100 ]]; then
echo -n -e "RAM usage: $iused/$itotal"
elif [[ "$usedmb" -lt 1000 ]]; then
echo -n -e "RAM usage: $iused/$itotal"
fi
fi
echo -n -e " "
echo -n -e $isheep
echo -n -e "\e[0m"
prev_total=$total
prev_idle=$idle
if [[ "$1" ]]; then
sleep $1
else
sleep 1
fi
done
fi
exit 0 #EOF
Here, take my thanks (for RTMixManager) hahahah
bump
bump

[SCRIPT/ZIP][v1.3] Init.d enabler @ stock kernel / ALL DEVICES / NO BUSYBOX needed

I present you universal script to enable Init.d in ALL ANDROID DEVICES (I hope...) while running the stock kernel. NO BUSYBOX needed! It is packed in easy to use ZIP flashable
EDIT: This script will NOT work with Magisk! However, notice that using Magisk you do not need init.d support at all (you can put your scripts in /magisk/.core/post-fs-data.d OR /magisk/.core/service.d, depending on your needs).
Requirements:
- a rooted Android device (SuperSU)
- ANY tool to flash a ZIP (custom recovery or FlashFire app)
Installation:
1. Custom recovery - open file using "Install Zip" option and confirm "Yes - install..."
2. FlashFire - open file using "Flash ZIP or OTA" option (default mount options). Tap "FLASH"
How to check:
Just check if /data/initd_test.log file exists (optionally you can check its content)
Changelog:
v1.3:
★ This version automatically detects privileges of launched sh script used to trigger init.d and if these are not sufficient to remount /system rw - all commands are automatically expanded to "/su/bin/su -c [command]" or "/system/xbin/su -c [command]" (depending on SuperSU install mode)
★ Fixed problem with "exit 0" at the end of used sh script resulting that simply added new lines never worked. This version automatically detects such case and moves "exit 0" at the end of modified file
★ SELinux context autodetection - starting from v1.3 modified file has always exact same context as original file
★ BusyBox will not be used anymore, even if exists (checking the presence removed)
v1.2:
★ Starting from this version installer performs more secure and only 100% reversible actions. Original *.sh file is never touched (just renamed to *.bak to keep its original attributes, including context). Installer will try to set to modified file as many attributes taken from original file as possible (instead of forcing "known values").
★ Added initd_remover.zip. Use it if you want to remove Init.d support (enabled by script from this thread!) and restore 100% original system files
v1.1:
★ Avoids potential WiFi problems in case of Samsung S6 (and probably other Samsung's Exynos based devices running Android 6.0.1) - see post #3
v1.0:
★ Initial version
Enabler [sh script]:
Code:
#!/sbin/sh
# Init.d enabler by ALEXNDR (_alexndr @ XDA)
OUTFD=/proc/self/fd/$2
ui_print() {
echo -n -e "ui_print $1\n" >> $OUTFD
echo -n -e "ui_print\n" >> $OUTFD
}
set_perm() {
chown $1.$2 $4
chown $1:$2 $4
chmod $3 $4
if [ -z "$5" ] ; then
chcon u:object_r:system_file:s0 $4
else
chcon u:object_r:$5:s0 $4
fi
}
resolve_link() {
if [ -z "$1" ] || [ ! -e $1 ] ; then return 1 ; fi
local VAR=$1
while [ -h "$VAR" ] ; do
VAR=$(readlink $VAR)
done
echo $VAR
}
is_mounted() {
if [ -z "$2" ] ; then
cat /proc/mounts | grep $1 >/dev/null
else
cat /proc/mounts | grep $1 | grep "$2," >/dev/null
fi
return $?
}
ui_print " "
ui_print "=========================================="
ui_print "Init.d enabler by ALEXNDR (_alexndr @ XDA)"
ui_print "=========================================="
ui_print " "
SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/app$")) ||
SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/system$"))
if (! is_mounted /system) ; then mount -o rw /system ; fi
if (! is_mounted /system rw) ; then mount -o rw,remount /system ; fi
if (! is_mounted /system rw) ; then mount -t ext4 -o rw $SYSTEM /system ; fi
if (! is_mounted /system rw) ; then mount -t f2fs -o rw $SYSTEM /system ; fi
if (! is_mounted /system rw) ; then
ui_print "Failed! Can't mount /system rw, aborting!"
ui_print " "
exit 1
fi
SYSLIB=/system/lib
cat /system/build.prop | grep "ro.product.cpu.abilist=" | grep "64" >/dev/null && SYSLIB=/system/lib64
cat /system/build.prop | grep "ro.product.cpu.abi=" | grep "64" >/dev/null && SYSLIB=/system/lib64
# These files are prefered to trigger init.d scripts (in following order, if exists):
# /system/etc/init.*.post_boot.sh
# /system/etc/*.post_boot.sh
# /system/etc/init.*.boot.sh
# /system/etc/*.boot.sh
#
# /system/bin/debuggerd is used if there is no suitable *.sh file in /system/etc
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.boot\.sh$") ||
BOOTFILE=/system/bin/debuggerd
BOOTCON=$(ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
if [ -z "$BOOTCON" ] ; then
BOOTCON=$(LD_LIBRARY_PATH=$SYSLIB /system/bin/toolbox ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
fi
if [ -z "$BOOTCON" ] ; then
BOOTCON=$(LD_LIBRARY_PATH=$SYSLIB /system/bin/toybox ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
fi
if [ -z "$BOOTCON" ] ; then
BOOTCON=system_file
fi
cat $BOOTFILE | grep "^exit 0" >/dev/null && EXIT=true || EXIT=false
if [ -z "$(cat $BOOTFILE | grep "Init\.d")" ] ; then
if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
if [ ! -f /system/bin/debuggerd_real ] ; then
mv -f $BOOTFILE /system/bin/debuggerd_real
echo "#!/system/bin/sh" > $BOOTFILE
else
sed -i '/debuggerd_real/d' $BOOTFILE
fi
else
mv -f $BOOTFILE "$BOOTFILE.bak"
cp -pf "$BOOTFILE.bak" $BOOTFILE
if ($EXIT) ; then sed -i '/^exit 0/d' $BOOTFILE ; fi
echo "" >> $BOOTFILE
fi
echo "# Init.d support" >> $BOOTFILE
echo 'SU="$(ls /su/bin/su 2>/dev/null || ls /system/xbin/su) -c"' >> $BOOTFILE
echo 'mount -o rw,remount /system && SU="" || eval "$SU mount -o rw,remount /system"' >> $BOOTFILE
echo 'eval "$SU chmod 777 /system/etc/init.d"' >> $BOOTFILE
echo 'eval "$SU chmod 777 /system/etc/init.d/*"' >> $BOOTFILE
echo 'eval "$SU mount -o ro,remount /system"' >> $BOOTFILE
echo 'ls /system/etc/init.d/* 2>/dev/null | while read xfile ; do eval "$SU /system/bin/sh $xfile" ; done' >> $BOOTFILE
if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
echo '/system/bin/debuggerd_real [email protected]' >> $BOOTFILE
set_perm 0 2000 755 $BOOTFILE $BOOTCON
else
if ($EXIT) ; then echo "exit 0" >> $BOOTFILE ; fi
chcon u:object_r:$BOOTCON:s0 $BOOTFILE
fi
mkdir -p /system/etc/init.d
echo "#!/system/bin/sh" > /system/etc/init.d/00test
echo "# Init.d test" >> /system/etc/init.d/00test
echo 'echo "Init.d is working !!!" > /data/initd_test.log' >> /system/etc/init.d/00test
echo 'echo "excecuted on $(date +"%d-%m-%Y %r")" >> /data/initd_test.log' >> /system/etc/init.d/00test
echo "#!/system/bin/sh" > /system/etc/init.d/99SuperSUDaemon
echo "/system/xbin/daemonsu --auto-daemon &" >> /system/etc/init.d/99SuperSUDaemon
set_perm 0 0 777 /system/etc/init.d
set_perm 0 0 777 "/system/etc/init.d/*"
ui_print "Init.d has been successfully enabled"
ui_print "using following file run at boot:"
ui_print " "
ui_print "$BOOTFILE"
ui_print " "
ui_print "Check result in /data/initd_test.log file"
ui_print " "
else
ui_print "Init.d is enabled already, aborting!"
ui_print " " # exit is not necessary
fi
umount /system
exit 0
Remover [sh script]:
Code:
#!/sbin/sh
# Init.d remover by ALEXNDR (_alexndr @ XDA)
OUTFD=/proc/self/fd/$2
ui_print() {
echo -n -e "ui_print $1\n" >> $OUTFD
echo -n -e "ui_print\n" >> $OUTFD
}
resolve_link() {
if [ -z "$1" ] || [ ! -e $1 ] ; then return 1 ; fi
local VAR=$1
while [ -h "$VAR" ] ; do
VAR=$(readlink $VAR)
done
echo $VAR
}
is_mounted() {
if [ -z "$2" ] ; then
cat /proc/mounts | grep $1 >/dev/null
else
cat /proc/mounts | grep $1 | grep "$2," >/dev/null
fi
return $?
}
ui_print " "
ui_print "=========================================="
ui_print "Init.d remover by ALEXNDR (_alexndr @ XDA)"
ui_print "=========================================="
ui_print " "
SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/app$")) ||
SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/system$"))
if (! is_mounted /system) ; then mount -o rw /system ; fi
if (! is_mounted /system rw) ; then mount -o rw,remount /system ; fi
if (! is_mounted /system rw) ; then mount -t ext4 -o rw $SYSTEM /system ; fi
if (! is_mounted /system rw) ; then mount -t f2fs -o rw $SYSTEM /system ; fi
if (! is_mounted /system rw) ; then
ui_print "Failed! Can't mount /system rw, aborting!"
ui_print " "
exit 1
fi
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.boot\.sh$") ||
BOOTFILE=/system/bin/debuggerd
if [ ! -z "$(cat $BOOTFILE | grep "Init\.d")" ] ; then
if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
if [ -f /system/bin/debuggerd_real ] ; then
rm -f $BOOTFILE
mv -f /system/bin/debuggerd_real $BOOTFILE
else
ui_print "Failed! Missing debuggerd_real file!"
exit 1
fi
elif [ -f "$BOOTFILE.bak" ] ; then
rm -f $BOOTFILE
mv -f "$BOOTFILE.bak" $BOOTFILE
else
ui_print "Failed! Missing *.sh.bak file!"
exit 1
fi
rm -Rf /system/etc/init.d
ui_print "Init.d has been successfully removed :)"
else
ui_print "Init.d by ALEXNDR has not been detected!"
fi
ui_print " "
umount /system
exit 0
NOTE:
If it does not work for your device - please post here a feedback! I will try to find a reason and tune my script
Credits: @Chainfire, @JustArchi
Hit Thanks button if you like my work. If you really appreciate my work - feel free to buy me a beer
Great Work..
Thanks
@_alexndr mate today i tried ur init.d enabled but on my s6 mm 6.0.1 its bricked my wifi as after flashing ur script i can't get wifi connected any fix for MM ?? Thanks
thereassaad said:
@_alexndr mate today i tried ur init.d enabled but on my s6 mm 6.0.1 its bricked my wifi as after flashing ur script i can't get wifi connected any fix for MM ?? Thanks
Click to expand...
Click to collapse
In my case work good no problem with WiFi connection on S5 MM 6.0.1
Regards
thereassaad said:
@_alexndr mate today i tried ur init.d enabled but on my s6 mm 6.0.1 its bricked my wifi as after flashing ur script i can't get wifi connected any fix for MM ?? Thanks
Click to expand...
Click to collapse
Strange as my installer in case of G920F should only add to /system/etc/init.sec.boot.sh following lines:
Code:
# Init.d support
mount -o rw,remount /system
chmod 777 /system/etc/init.d
chmod 777 /system/etc/init.d/*
mount -o ro,remount /system
busybox run-parts /system/etc/init.d
or following if busybox has not been installed:
Code:
# Init.d support
mount -o rw,remount /system
chmod 777 /system/etc/init.d
chmod 777 /system/etc/init.d/*
mount -o ro,remount /system
ls /system/etc/init.d/* 2>/dev/null | while read xfile ; do $xfile ; done
Original file should be renamed to /system/etc/init.sec.boot.sh.bak, so you can just delete modified init.sec.boot.sh and then rename init.sec.boot.sh.bak -> init.sec.boot.sh to revert changes (+ delete /system/etc/init.d folder but it's just a cosmetic)
...but before you do it - it would be great if you help in further development and try if following command put in terminal emulator or adb shell will help:
Code:
su
mount -o rw,remount /system
chmod 550 /system/etc/init.sec.boot.sh
chown 0:2000 /system/etc/init.sec.boot.sh
chcon u:object_r:sec-sh_exec:s0 /system/etc/init.sec.boot.sh
mount -o ro,remount /system
...then reboot device
EDIT:
Anyway - #1 has been updated as I found potential permissions / SELinux context mismatch in case of Samsung's Exynos based devices running Android 6.0.1. NOTE: It will not fix broken installation already done - you need to revert changes first (as I mentioned above - by deleting init.sec.boot.sh and renaming init.sec.boot.sh.bak -> init.sec.boot.sh) and then re-flash v1.1
Another update
Changelog:
v1.2:
★ Starting from this version installer performs more secure and only 100% reversible actions. Original *.sh file is never touched (just renamed to *.bak to keep its original attributes, including context). Installer will try to set to modified file as many attributes taken from original file as possible (instead of forcing "known values").
★ Added initd_remover.zip. Use it if you want to remove Init.d support (enabled by script from this thread!) and restore 100% original system files
@_alexndr , definitely mate will give a shot , later , thanks for ur work xD ,
good work bro will test more with new update
Good work ?
Sent from my A66A using XDA-Developers mobile app
Another update
Changelog:
v1.3:
★ This version automatically detects privileges of launched sh script used to trigger init.d and if these are not sufficient to remount /system rw - all commands are automatically expanded to "/su/bin/su -c [command]" or "/system/xbin/su -c [command]" (depending on SuperSU install mode)
★ Fixed problem with "exit 0" at the end of used sh script resulting that simply added new lines never worked. This version automatically detects such case and moves "exit 0" at the end of modified file
★ SELinux context autodetection - starting from v1.3 modified file has always exact same context as original file
★ BusyBox will not be used anymore, even if exists (checking the presence removed)
First of all really thank you for this script which works very well...except if included in the installation script.
The initd.sh is this
I use this command in the updater-script:
ui_print("@ Add init.d support");
package_extract_file("tools/initd.sh", "/tmp/initd.sh");
set_perm(0, 0, 0777, "/tmp/initd.sh");
run_program("/tmp/initd.sh");
delete("/tmp/initd.sh");
ui_print("--> Init.d Installed");
But not working. Got this error in recovery log
run_program: execv failed: No such file or directory
run_program: child exited with status 1
Any advice or a proper .sh script please ?
Thanks very much.
WILMANS2M said:
First of all really thank you for this script which works very well...except if included in the installation script.
The initd.sh is this
I use this command in the updater-script:
ui_print("@ Add init.d support");
package_extract_file("tools/initd.sh", "/tmp/initd.sh");
set_perm(0, 0, 0777, "/tmp/initd.sh");
run_program("/tmp/initd.sh");
delete("/tmp/initd.sh");
ui_print("--> Init.d Installed");
But not working. Got this error in recovery log
run_program: execv failed: No such file or directory
run_program: child exited with status 1
Any advice or a proper .sh script please ?
Thanks very much.
Click to expand...
Click to collapse
My script (as it is in post #1) is designed to be standalone installer. If you want to enable init.d by a sh script called from the updater-script - please try as follow:
Code:
#!/sbin/sh
# Init.d enabler by ALEXNDR (_alexndr @ XDA)
set_perm() {
chown $1.$2 $4
chown $1:$2 $4
chmod $3 $4
if [ -z "$5" ] ; then
chcon u:object_r:system_file:s0 $4
else
chcon u:object_r:$5:s0 $4
fi
}
# These files are prefered to trigger init.d scripts (in following order, if exists):
# /system/etc/init.*.post_boot.sh
# /system/etc/*.post_boot.sh
# /system/etc/init.*.boot.sh
# /system/etc/*.boot.sh
#
# /system/bin/debuggerd is used if there is no suitable *.sh file in /system/etc
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.boot\.sh$") ||
BOOTFILE=/system/bin/debuggerd
BOOTCON=$(ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
if [ -z "$BOOTCON" ] ; then
BOOTCON=system_file
fi
cat $BOOTFILE | grep "^exit 0" >/dev/null && EXIT=true || EXIT=false
if [ -z "$(cat $BOOTFILE | grep "[Ii]nit\.d")" ] ; then
if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
if [ ! -f /system/bin/debuggerd_real ] ; then
mv -f $BOOTFILE /system/bin/debuggerd_real
echo "#!/system/bin/sh" > $BOOTFILE
else
sed -i '/debuggerd_real/d' $BOOTFILE
fi
else
mv -f $BOOTFILE "$BOOTFILE.bak"
cp -pf "$BOOTFILE.bak" $BOOTFILE
if ($EXIT) ; then sed -i '/^exit 0/d' $BOOTFILE ; fi
echo "" >> $BOOTFILE
fi
echo "# Init.d support" >> $BOOTFILE
echo 'SU="$(ls /su/bin/su 2>/dev/null || ls /system/xbin/su) -c"' >> $BOOTFILE
echo 'mount -o rw,remount /system && SU="" || eval "$SU mount -o rw,remount /system"' >> $BOOTFILE
echo 'eval "$SU chmod 777 /system/etc/init.d"' >> $BOOTFILE
echo 'eval "$SU chmod 777 /system/etc/init.d/*"' >> $BOOTFILE
echo 'eval "$SU mount -o ro,remount /system"' >> $BOOTFILE
echo 'ls /system/etc/init.d/* 2>/dev/null | while read xfile ; do eval "$SU /system/bin/sh $xfile" ; done' >> $BOOTFILE
if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
echo '/system/bin/debuggerd_real [email protected]' >> $BOOTFILE
set_perm 0 2000 755 $BOOTFILE $BOOTCON
else
if ($EXIT) ; then echo "exit 0" >> $BOOTFILE ; fi
chcon u:object_r:$BOOTCON:s0 $BOOTFILE
fi
mkdir -p /system/etc/init.d
echo "#!/system/bin/sh" > /system/etc/init.d/00test
echo "# Init.d test" >> /system/etc/init.d/00test
echo 'echo "Init.d is working !!!" > /data/initd_test.log' >> /system/etc/init.d/00test
echo 'echo "excecuted on $(date +"%d-%m-%Y %r")" >> /data/initd_test.log' >> /system/etc/init.d/00test
echo "#!/system/bin/sh" > /system/etc/init.d/99SuperSUDaemon
echo "/system/xbin/daemonsu --auto-daemon &" >> /system/etc/init.d/99SuperSUDaemon
set_perm 0 0 777 /system/etc/init.d
set_perm 0 0 777 "/system/etc/init.d/*"
fi
exit 0
Thanks for the answer. Will try it asap and give you feedback.
Envoyé de mon GT-I9505 en utilisant Tapatalk
hello @_alexndr
So tried again with the sh modified script, but same thing. Same error and no initd installed unfortunately
If you have any other advice, i really thank you in advance.
i tried something different. I keep your original zip file, and put it in tools/initd folder in my custom rom
Then i added this in the updater script:
ui_print("@ Add init.d support");
package_extract_dir("tools/initd", "/tmp/initd");
run_program("/sbin/busybox", "unzip", "/tmp/initd/initd.any.stock.1.3.zip", "META-INF/com/google/android/*", "-d", "/tmp/initd");
run_program("/sbin/busybox", "sh", "/tmp/initd/META-INF/com/google/android/update-binary", "dummy", "1", "/tmp/initd/initd.any.stock.1.3.zip");
ui_print("--> Init.d Installed");
IT WORKS with this
Thanks
great job
You sir are an animal. This script is intelligently designed
Deleted
Hey, Firstly thanks for all your work!
I've not tried this yet but I'm working on stock based ROM nd I want to enable to init.d support in it.
I've used the SuperR's Kitchen to enable the init.d support in the kernel nd I could find the script in the kernel too. Not sure if it'll work or not as I haven't tested in yet. So I hope you can tell me if I need to enable this way too or not,
Thanks.
@_alexndr
Thanks a lot
Confirmed Working on Samsung Galaxy S5 G900H
OS: Stock Deodexed Marshmallow 6.0.1 with GreenApple Kernal

[UPDATE]MOD][TOOL] oNandroid: a contribution to help make it work in newer devices

Credits to: ameer1234567890
Official Thread:Online Nandroid Backup / Nandroid Backup without re-booting
I wanted to use Ameer's script/app on my new Galaxy S7 but it was not recognized.
I was able to make it work myself by generating the correct patch file using this script:
Code:
mount -o rw,remount /system
echo "dev: size erasesize name" > /system/partlayout4nandroid
cd `find /dev -name by-name`
for d in * ; do
lc=`echo $d | tr [A-Z] [a-z]`
dev=`readlink $d | awk -F/ '{print $NF}'`
hex=$(printf "%07x\n" `dd if=$d of=/dev/null bs=1m 2>&1 | grep bytes | awk '{print $1/1024}'`)
echo "$dev: $hex 0000000 \"$lc\"" >> /system/partlayout4nandroid
done;
mount -o ro,remount /system
I had also to change this line :
Code:
if $bb [ "`$bb cat /system/partlayout4nandroid | $bb egrep "(mtd|mmc|bml|nand|act)"`" != "" ]; then
to
Code:
if $bb [ "`$bb cat /system/partlayout4nandroid | $bb egrep "([B]sda|[/B]mtd|mmc|bml|nand|act)"`" != "" ]; then
Cheers

Can somebody help me with this shell script?

Basically what I want to do is convert this into batch script for windows and by using Linux Binaries from Sourceforge create a script that basically does the same thing except it doesnt have to be pushed into my Phone's system it works directly in windows using ADB commands!
The script in question looks like this
Spoiler: THIS Script
Bash:
#adb shell mkdir /data/media/0/PartitionImages
#adb push .\backupPartitions.sh /data/media/0/PartitionImages/backupPartitions.sh
#adb shell chmod 0755 /data/media/0/PartitionImages/backupPartitions.sh
#adb shell /data/media/0/PartitionImages/backupPartitions.sh
#adb pull /data/media/0/PartitionImages .\PartitionImages
max_blocks=102400
names=""
compress=0
while getopts "h?bzn:" opt; do
case "$opt" in
h|\?)
echo "Usage $0 [-z] [-b MaxBlocks] [-n partition1 ] [-n partition2 ]"
echo " options:"
echo "-z optional to tar.gz the output folder default=false"
echo "-b 102400 optional maximum number of blocks of the partition - 0 will dump all partitions default=$max_blocks"
echo "-n partitionName... optional - one or more partitions to dump"
exit 0
;;
z) compress=1
;;
b) max_blocks=$OPTARG
;;
n) names+=" $OPTARG"
;;
esac
done
script=$(readlink -f "$0")
script_path=$(dirname "$script")
serial=$(cat /sys/class/android_usb/f_accessory/device/iSerial)
serial_date=$serial/$(date +"%Y_%m_%d_%H_%M_%S")
output_path=$script_path/$serial_date
echo "********************************"
echo "Backup partitions TO $output_path"
echo "********************************"
mkdir -p $output_path
part_dir=$(find /dev/block/platform -name by-name)
partitions=$(ls -la $part_dir | awk '{if ( $10 == "->") print $9 ">" $11 }')
getprop > $output_path/build.prop
echo "Id Name Size MD5" > $output_path/partitions.txt
for f in $partitions
do
part_id=$(echo $f | sed 's/^[^>]*>\/dev\/block\///')
part_name=$(echo $f | sed 's/>.*//')
size=$(cat /proc/partitions | awk -v p=$part_id '{if ( $4 == p ) print $3}')
checksum="0"
skip=0
if [ $max_blocks -gt 0 -a $size -gt $max_blocks ]
then
skip=1
echo "Skipping $part_name Id $part_id due to size"
else
if [ "$names" -ne "" ]
then
if echo $names | grep -w $part_name > /dev/null; then
skip=0
else
skip=1
echo "Skipping $part_name Id $part_id"
fi
fi
fi
if [ "$skip" -eq "0" ]
then
echo "Processing $part_name Id $part_id Size $size";
dd if=/dev/block/$part_id of=$output_path/$part_name.img
checksum=$(md5sum -b $output_path/$part_name.img | sed 's/ .*//')
fi
echo "$part_id $part_name $size $checksum" >> $output_path/partitions.txt
done
if [ "$compress" -eq "1" ]
then
cd $script_path
tar cz $serial_date > $output_path.tar.gz
rm -rf $output_path
fi
its from an old Xda Dev thread original post and author
givitago​​
I tried by guidelines from an "Appendix N. Converting DOS Batch Files to Shell Scripts" from another site to turn the shell script variables into batch script ones but since I got no experience with either of them my attempt turned into an amalgamation of the two's code in one..
Spoiler: it turned Into THIS
Code:
::adb shell mkdir /data/media/0/PartitionImages
::adb push .\backupPartitions.sh /data/media/0/PartitionImages/backupPartitions.sh
::adb shell chmod 0755 /data/media/0/PartitionImages/backupPartitions.sh
::adb shell /data/media/0/PartitionImages/backupPartitions.sh
::adb pull /data/media/0/PartitionImages .\PartitionImages
%max_blocks==102400
%names==""
%compress==0
while getopts "h?bzn:" opt; do
case "$opt" in
h|\?)
echo "Usage $0 [-z] [-b MaxBlocks] [-n partition1 ] [-n partition2 ]"
echo " options:"
echo "-z optional to tar.gz the output folder default=false"
echo "-b 102400 optional maximum number of blocks of the partition - 0 will dump all partitions default=$max_blocks"
echo "-n partitionName... optional - one or more partitions to dump"
exit 0
;;
z) compress=1
;;
b) max_blocks=$OPTARG
;;
n) names+=" $OPTARG"
;;
esac
done
%script%==%(echo %CD% "%0")
%script_path%==(dirname "%script")
%serial%==%(adb shell cat /sys/class/android_usb/f_accessory/device/iSerial)
%serial_date%==%serial% /%(date +"%Y_%m_%d_%H_%M_%S")
%output_path%==%script_path%/%serial_date%
echo "********************************"
echo "Backup partitions TO $output_path"
echo "********************************"
mkdir -p %output_path%
%part_dir%==%(adb shell find /dev/block/platform -name by-name)
%partitions%==%(ls -la %part_dir% | awk '{if ( %10 == "->") print %9 ">" %11 }')
adb shell getprop > %output_path%/build.prop
echo "Id Name Size MD5" > %output_path%/partitions.txt
for %%i in %partitions do
%part_id=%(echo %f | sed 's/^[^>]*>\/dev\/block\///')
%part_name=%(echo %f | sed 's/>.*//')
%size=%(adb shell cat /proc/partitions | awk -v p==%part_id% '{if ( %4 == p ) print %3}')
checksum="0"
skip==0
if [ %max_blocks -gt 0 -a %size -gt %max_blocks ]
then
skip=1
echo "Skipping %part_name% Id %part_id% due to size"
else
if [ "%names" -ne "" ]
then
if echo %names | grep -w %part_name% > /dev/null; then
skip==0
else
skip==1
echo "Skipping %part_name% Id %part_id%"
fi
fi
fi
if [ "$skip" -eq "0" ]
then
echo "Processing %part_name% Id %part_id% Size %size";
'adb shell pull' /dev/block/%part_id% %output_path%/%part_name%.img
checksum==%(md5sum -b %output_path%/%part_name%.img | sed 's/ .*//')
fi
echo "%part_id% %part_name% %size %checksum" >> %output_path%/partitions.txt
done
if [ "%compress" -eq "1" ]
then
cd %script_path%
tar cz %serial_date% > %output_path%.tar.gz
rm -rf %output_path%
fi
additionally I have pretty much all linux commands's binaries on the same folder as the .bat script so as long as the syntax is correct and nothing finniky going on it should work technically but since I got no experience I can't do this on my own...
You may use the DOS script used here
[TOOL][ADB][WIN]Android Partitions Backupper / Cloner
Hi all, wrote a Windows CMD script that backups / clones partitions of an Android device via ADB because I wasn't content with any 3rd-party APK what claims to do this job. The backups /clones are stored on Windows computer as...
forum.xda-developers.com
as a template.
jwoegerbauer said:
You may use the DOS script used here
[TOOL][ADB][WIN]Android Partitions Backupper / Cloner
Hi all, wrote a Windows CMD script that backups / clones partitions of an Android device via ADB because I wasn't content with any 3rd-party APK what claims to do this job. The backups /clones are stored on Windows computer as...
forum.xda-developers.com
as a template.
Click to expand...
Click to collapse
I have tried that script itself and it failed at "DM-Verity" and SELinux enforcement also for some reason no logs at all in temp folder

Categories

Resources