[Ubuntu][How to][4/11/12 Creating a Kernel Build Script - Android

This thread is meant for kernel devs or people who wants to begin building kernels for their first time.
There is a bit of a learning curve to this though, you need to known Linux functions and have android environment setup
This is a UBUNTU script saved as a shell script for any version of UBUNTU
Start off script with executable script definitions
Code:
#!/bin/bash
This next part is important and ultimately optional however it makes coding the script crazy easier
I call these definitions (likely not what they are technically but, it's my interpretation) to enable shortcoding commands which makes the script look cleaner
These can be named whatever you want btw
Kerneldir - is the directory where your kernel files are kept and this is the main place where you build your kernel
Packagedir - is your work environment, this is where your boot.img will be copied to, extra files, updater-script to be later packaged into a zip folder
INITRAMFS_SOURCE - is where the ramdisk should be placed in folder form [Click Here for how to split ramdisk and zimage from boot.img]
Meta - where the updater script is kept so it can be packaged for my kernel to be able to flashed
ARCH - Must stay as this definition as it is needed for compile to become successful
CROSS_COMPILE - Toolchain command, make sure your kernel supports linaro 4.6 and later. Or default to CM's 4.4.3 toolchain. Must stay as this definition as it is needed for compile to become successful
Code:
export KERNELDIR=/home/ayysir/android/kernel/ASDK
export INITRAMFS_DEST=$KERNELDIR/kernel/usr/initramfs
export PACKAGEDIR=/home/ayysir/android/kernel/asdk_out
export INITRAMFS_SOURCE=/home/ayysir/android/kernel
export Meta=/home/ayysir/android/kernel/Ayysir/META-INF
export Drivers=/home/ayysir/android/kernel/Ayysir/Drivers
export App=/home/ayysir/android/kernel/Ayysir/app
export exfat=/home/ayysir/android/kernel/Ayysir/exfat_modules
export ARCH=arm
export CROSS_COMPILE=/home/ayysir/android/kernel/toolchains/android-toolchain-4.7/bin/arm-eabi-
This part are mostly setup commands to clean out workspace deleting previous compile remnants. This is where definitions we made above comes in handy.
The echo commands are like description commands, used for many situations but for our purpose, it tells the user what is currently happening in the script
Assuming you have knowledge about kernel deving so I don't have to hold your hand in describing things
Below commands vary depending on dev as they have their own defconfig setup for their specific device replace my asdk_defconfig with
this is is for configuring what to include the compile build
UPDATE:
OPTIONAL:
Code:
# Colorize and add text parameters
red=$(tput setaf 1) # red
grn=$(tput setaf 2) # green
cya=$(tput setaf 6) # cyan
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldgrn=${txtbld}$(tput setaf 2) # green
bldblu=${txtbld}$(tput setaf 4) # blue
bldcya=${txtbld}$(tput setaf 6) # cyan
txtrst=$(tput sgr0) # Reset
Above Codes Colorize and add text parameters.. it makes it look cleaner and more concise on what is happening in the terminal
The "echo -e" command tells terminal to apply the following text.
"${bldcya}" refers back to colorize table, making it bold (bld) and making text color cyan (cya)
"${txtrst}" closes the statement and resets the color back to terminal default. So the color parameters do not spill over into the next lines
Click to expand...
Click to collapse
the echo "" adds a space in between lines, just so it looks clean and does not jumble things
so here are some example on how to implement this: [Below]
Code:
echo -e "${bldcya} Making Kernel ${txtrst}"
make asdk_defconfig
echo""
echo -e "${bldcya} Clean Environment ${txtrst}"
make menuconfig
Code:
echo "Remove old Package Files"
rm -rf $PACKAGEDIR/*
echo "Setup Package Directory"
mkdir -p $PACKAGEDIR/system/lib/modules
echo "Setup App Directory"
mkdir -p $PACKAGEDIR/data/app
echo "Remove old zImage"
rm $PACKAGEDIR/zImage
echo "Remove old ramdisk"
rm $INITRAMFS_SOURCE/ramdisk.img.gz
echo "Clean Environment"
cd $KERNELDIR
make clean
echo "Make the kernel"
make asdk_defconfig
echo "Clean Environment"
make menuconfig
Before we get to this important section you need two files put into your /bin folder, mkbootfs and mkbootimg Click Here to download these files.
Then you need to cp these files to bin folder [put the files in home folder]
Code:
sudo cp ~/mkbootfs /bin
sudo cp ~/mkbootimg /bin
cd /bin
sudo chmod +x mkbootfs
sudo chmod +x mkbootimg
Now we are ready for next section
Make -j[num] command tells system how much things can be compiled at once, it's dependent on your system (number of processors] so i cay default to -j4
You also notice the script coding wrapped around the make command, this is what I setup to create compile log for compile session just incase you need to go back to review errors or debug some things
Code:
script -q ~/Compile.log -c "
make -j12 "
Below command searches for modules in zimage file and copies the modules files to workplace modules folder for packaging
Code:
cp -a $(find . -name *.ko -print |grep -v initramfs) $PACKAGEDIR/system/lib/modules/
Like I stated before you should of have already split the boot.img file and extracted ramdisk to a ramdisk folder. Below command uses mkbootfs to compress that folder into a .gz formatted file.
Below part is a bit tricky, because it is dependent on device to device basis.
first the code below moves ramdisk to workfolder
Then it cd's to the package folder and uses mkbootimg command to combine zimage and ramdisk together to make a boot.img
What is tricky is the command mkbootimg uses to determine space for the boot.img to be compiled in
The best way to determine the page size, base, & ramdiskaddr is either use the previous tools that you used to split a already compile boot.img commands and it spits out a file info run down or use DSIXDA ANDROID KITCHEN and using it's advanced options to determine boot.img info. Again I am not going to hold your hand on this one since you should research before trying this build script.
Note: many boot.img's use cmdline option in creation
Code:
echo "Make boot.img"
cp $INITRAMFS_SOURCE/ramdisk.img.gz $PACKAGEDIR
cd $PACKAGEDIR
mkbootimg --cmdline 'console = null androidboot.hardware=qcom user_debug=31 zcache' --kernel $PACKAGEDIR/zImage --ramdisk $PACKAGEDIR/ramdisk.img.gz --base 0x80200000 --pagesize 2048 --ramdiskaddr 0x81500000 --output $PACKAGEDIR/boot.img
Code:
echo "Packaging Ramdisk"
cd $INITRAMFS_SOURCE/
mkbootfs ./ASDK-ramdisk | gzip > ramdisk.img.gz
Code:
echo "Compiling"
script -q ~/Compile.log -c "
make -j12 "
echo "Copy modules to Package"
cp -a $(find . -name *.ko -print |grep -v initramfs) $PACKAGEDIR/system/lib/modules/
cp $Drivers/* $PACKAGEDIR/system/lib/
echo "Copy zImage to Package"
cp $KERNELDIR/arch/arm/boot/zImage $PACKAGEDIR/zImage
echo "Packaging Ramdisk"
cd $INITRAMFS_SOURCE/
mkbootfs ./ASDK-ramdisk | gzip > ramdisk.img.gz
echo "Make boot.img"
cp $INITRAMFS_SOURCE/ramdisk.img.gz $PACKAGEDIR
cd $PACKAGEDIR
mkbootimg --cmdline 'console = null androidboot.hardware=qcom user_debug=31 zcache' --kernel $PACKAGEDIR/zImage --ramdisk $PACKAGEDIR/ramdisk.img.gz --base 0x80200000 --pagesize 2048 --ramdiskaddr 0x81500000 --output $PACKAGEDIR/boot.img
This is where you add files you want packaged into your zip folder
*Remember add new definitions every time you add a new directory to the mix and have them cp all the files to workfolder
Code:
export curdate=`date "+%m-%d-%Y"`
This sets definition to zip to auto-generate dates to date your builds so it takes the work out of renaming the zip file [Your welcome lol]
Code:
zip -r ../ASDK-AOSP-4.2-$curdate.zip
set a name to your build and add $curdate.zip to enable auto dating zip
Code:
echo "Import of META-INF"
cp -R $Meta $PACKAGEDIR
echo "Import Voltage Control"
cp $App/* $PACKAGEDIR/data/app
echo "Importing Exfat fix"
cp $exfat/* $PACKAGEDIR/system/lib/modules
export curdate=`date "+%m-%d-%Y"`
cp ~/Compile.log ~/android/Compile-$curdate.log
rm ~/Compile.log
cd $PACKAGEDIR
rm ramdisk.img.gz
rm zImage
rm ../ASDK-AOSP-4.2*.zip\
rm -R .fr-7q5stU
zip -r ../ASDK-AOSP-4.2-$curdate.zip .
read -p "Press ENTER to Exit"
UPDATE:
Not to confuse anyone, Below is based off my new build script I use. PLEASE DO NOT COPY WORD FOR WORD, CODE BY CODE JUST USE IT AS REFERENCE. IF YOUR NOT SMART ENOUGH TO GET WHAT I AM DOING THEN DONT TRY BUILDING KERNELS LOL
Code:
if [ -e $KERNELDIR/arch/arm/boot/zImage ]; then
echo -e "${bldred} Copy modules to Package ${txtrst}"
cp -a $(find . -name *.ko -print |grep -v initramfs) $PACKAGEDIR/system/lib/modules/
echo ""
echo -e "${bldred} Copy zImage to Package ${txtrst}"
cp $KERNELDIR/arch/arm/boot/zImage $PACKAGEDIR/zImage
echo ""
echo -e "${bldred} Ramdisk Readying.. ${txtrst}"
cp $KERNELDIR/mkbootfs $INITRAMFS_SOURCE
cd $INITRAMFS_SOURCE/
./mkbootfs ASDK-krait | gzip > ramdisk.krait.gz
rm mkbootfs
echo ""
echo -e "${bldred} Making Boot.img.. ${txtrst}"
cp $KERNELDIR/mkbootimg $PACKAGEDIR
cp $INITRAMFS_SOURCE/ramdisk.krait.gz $PACKAGEDIR
cd $PACKAGEDIR
./mkbootimg --cmdline 'console = null androidboot.hardware=qcom user_debug=31 zcache' --kernel $PACKAGEDIR/zImage --ramdisk $PACKAGEDIR/ramdisk.krait.gz --base 0x80200000 --pagesize 2048 --ramdiskaddr 0x81500000 --output $PACKAGEDIR/boot.img
rm mkbootimg
echo ""
export curdate=`date "+%m-%d-%Y"`
cp ~/Compile.log ~/android/compile_logs/Success-Krait-$curdate.log
rm ~/Compile.log
cd $PACKAGEDIR
rm ramdisk.krait.gz
rm zImage
rm ../../ASDK-AOSP-3.4.x-*.zip
rm ../ramdisk.krait.gz
rm ../zImage
zip -r ../ASDK-AOSP-3.4.x-$curdate-EXP.zip .
mv ../ASDK-AOSP-3.4.x-$curdate-EXP.zip ~/android/kernel
echo "ASDK HOT OFF THE PRESS"
else
echo "KERNEL DID NOT BUILD! no zImage exist"
export curdate=`date "+%m-%d-%Y"`
cp ~/Compile.log ~/android/compile_logs/Failed-Krait-$curdate.log
fi;
exit 0
Now before you get mind blown Let me explain the update above:
"if [ -e $KERNELDIR/arch/arm/boot/zImage ]; then" is known as the "if, then" commands. Most used in C and scripting it tells system to look for a certain file or directory first, "if" present "then" it will proceed to following commands after it.
so if the zimage does exist then, the code after the statement will go on and end up making the zip folder.
"else" commands tells terminal, well if that file in the if statement does not exist then use following commands instead. In this case if $KERNELDIR/arch/arm/boot/zImage does not exist then else do this:
Code:
else
echo "KERNEL DID NOT BUILD! no zImage exist"
export curdate=`date "+%m-%d-%Y"`
cp ~/Compile.log ~/android/compile_logs/Failed-Krait-$curdate.log
This else statement makes a fail log to where you keep your build logs. This allows you to see where in the build did you received an error which caused the zimage to not be produced. Also it wont make a zip folder so no useless zips with no boot.img in there
Click to expand...
Click to collapse
chmod +x your script [make sure you save it as blahblah.sh] and boom your done
CLICK HERE TO SEE MY FULL SCRIPT THAT I USE FOR MY GS3 KERNEL BUILDS [NEEDS REVISING THOUGH]
IF YOU HAVE ANY QUESTIONS LEAVE IT IN THE COMMENTS OR PM ME
IF YOU LIKED MY HOW-TO AND WOULD LIKE TO DONATE TO HELP ME DEV FOR MORE DEVICES [APPRECIATED BUT DONATION NOT REQUIRED] CLICK HERE

Reserved

hm

Another Example for Fun
Well this thread looked like it needed a comment or at least some positive feedback so here it goes.
Thanks so much @ayysir for making this tutorial!!!! I've been using scripts to do lots of things for me for about a year now and it all started when I read this thread. (for some reason the though of bash scripts never really crossed my mind before then)
Here is an example of how creative I've got since the beginning of this. My script now includes some colored logos just for fun as well as final build time, uploading to goo.im, and signing of the final zip. (The logos might not show up right on here but they look great in terminal)
Code:
#!/bin/bash
#Cl3Kener's Hammerhead Script
# Colorize and add text parameters (originally grabbed from Ayysir)
red=$(tput setaf 1) # red
grn=$(tput setaf 2) # green
cya=$(tput setaf 6) # cyan
pnk=$(tput bold ; tput setaf 5) # pink
yel=$(tput bold ; tput setaf 3) # yellow
pur=$(tput setaf 5) # purple
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldgrn=${txtbld}$(tput setaf 2) # green
bldyel=${txtbld}$(tput bold ; tput setaf 3) # yellow
bldblu=${txtbld}$(tput setaf 4) # blue
bldpur=${txtbld}$(tput setaf 5) # purple
bldpnk=${txtbld}$(tput bold ; tput setaf 5) # pink
bldcya=${txtbld}$(tput setaf 6) # cyan
txtrst=$(tput sgr0) # Reset
#Place you defconfig name here:
DEFCONFIG=uber_hammerhead_defconfig
# Change these exports as needed:
export INITRAMFS_DEST=~/android/kernel/usr/initramfs
export PACKAGEDIR=~/android/kernel/OUT
export KERNEL_SOURCE=~/android/kernel
export Meta=~/android/kernel/Cl3Kener/META-INF
export Etc=~/android/kernel/Cl3Kener/etc
export Scripts=~/android/kernel/Cl3Kener/kernel
export Bin=~/android/kernel/Cl3Kener/bin
export Lib=~/android/kernel/Cl3Kener/lib
export GPU=~/android/kernel/Cl3Kener/kcontrol_gpu_msm
export sign=~/android/kernel/Cl3Kener/signapk_files
export ARCH=arm
export CROSS_COMPILE=~/android/kernel/TOOLCHAINS/arm-eabi-4.7/bin/arm-eabi-
# Place your goo.im password here instead of XXXXXX so you don't have to input password (or you can use ssh key if you have one):
export SSHPASS=XXXXXXX
# Start Time
res1=$(date +%s.%N)
# Logo (just for fun)
echo "${bldpur} ${txtrst}"
echo "${bldpur} ________________________________________ ${txtrst}"
echo "${bldpur}| |${txtrst}"
echo "${bldpur}| _| _| _|_|_| _|_|_|_| _|_|_| |${txtrst}"
echo "${bldpur}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldpur}| _| _| _|_|_| _|_|_| _|_|_| |${txtrst}"
echo "${bldpur}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldpur}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldpur}| _|_| _|_|_| _|_|_|_| _| _| |${txtrst}"
echo "${bldpur}|________________________________________|${txtrst}"
echo "${bldpur} ${txtrst}"
echo "${bldcya}Remove Old Package Files ${txtrst}"
rm -rf $PACKAGEDIR/*
echo " "
echo "${bldgrn}Setup Init.d Directory ${txtrst}"
mkdir -p $PACKAGEDIR/system/etc
echo " "
echo "${bldyel}Setup Scripts Directory ${txtrst}"
mkdir -p $PACKAGEDIR/modules
echo " "
echo "${bldblu}Remove old zImage ${txtrst}"
rm $KERNEL_SOURCE/arch/arm/boot/zImage
rm $KERNEL_SOURCE/arch/arm/boot/zImage-dtb
echo " "
echo -e "${bldred}Removing annoying gedit backup files ${txtrst}"
cd ~/android/kernel
find ./ -name '*~' | xargs rm
echo " "
echo "${bldgrn}Clean Environment ${txtrst}"
cd $KERNEL_SOURCE
make $DEFCONFIG
rm $KERNEL_SOURCE/.version
rm $KERNEL_SOURCE/.config.old
rm $KERNEL_SOURCE/.config
make clean
echo " "
echo "${bldpnk}Kernel Menu ${txtrst}"
make menuconfig
echo " "
echo "${bldcya}Compiling.... ${txtrst}"
script -q ~/Compile.log -c "
make -j7"
echo " "
if [ -e $KERNEL_SOURCE/arch/arm/boot/zImage-dtb ]; then
# I used Showp1984 msm_mpdecision hotplug and so I use his KControl Module.
echo "${bldyel}Making GPU Module ${txtrst}"
cd $GPU
make clean
make -j7
echo " "
cd $KERNEL_SOURCE
echo "${bldgrn}Copy Modules to OUT ${txtrst}"
cp -a $(find . -name *.ko -print |grep -v initramfs) $PACKAGEDIR/modules/
echo "${bldblu}Import Scripts ${txtrst}"
cp -R $Scripts $PACKAGEDIR
echo "${bldcya}Copy bin to OUT ${txtrst}"
cp -R $Bin $PACKAGEDIR/system/bin
echo "${bldred}Copy zImage to OUT ${txtrst}"
cp $KERNEL_SOURCE/arch/arm/boot/zImage-dtb $PACKAGEDIR/kernel/zImage
echo "${bldgrn}Import of META-INF ${txtrst}"
cp -R $Meta $PACKAGEDIR
echo "${bldcya}Import Init.d Tweaks ${txtrst}"
cp -R $Etc/init.d $PACKAGEDIR/system/etc
echo "${bldred}Import Dalvik/Bionic Optimized Libs ${txtrst}"
cp -R $Lib $PACKAGEDIR/system
export curdate=`date "+%m-%d-%Y"`
cp ~/Compile.log ~/android/Logs/Completed-Uber-hammerhead-$curdate.log
rm ~/Compile.log
cd $PACKAGEDIR
rm ../UBER-Hammerhead*.zip\
rm -R .fr-7q5stU
zip -r ../UBER-Hammerhead-Nightly.zip .
echo " "
echo "${bldblu}Signing Zip ${txtrst}"
cd $KERNEL_SOURCE
cp $sign/signapk.jar $KERNEL_SOURCE
cp $sign/testkey.pk8 $KERNEL_SOURCE
cp $sign/testkey.x509.pem $KERNEL_SOURCE
java -jar ~/android/kernel/signapk.jar testkey.x509.pem testkey.pk8 UBER-Hammerhead-Nightly.zip UBER-Hammerhead-Linaro-4.8.3-$curdate.zip
rm UBER-Hammerhead-Nightly.zip
rm signapk.jar
rm testkey.pk8
rm testkey.x509.pem
echo "${bldgrn} ${txtrst}"
echo "${bldgrn} ${txtrst}"
echo "${bldgrn} ________________________________________ ${txtrst}"
echo "${bldgrn}| |${txtrst}"
echo "${bldgrn}| _| _| _|_|_| _|_|_|_| _|_|_| |${txtrst}"
echo "${bldgrn}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldgrn}| _| _| _|_|_| _|_|_| _|_|_| |${txtrst}"
echo "${bldgrn}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldgrn}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldgrn}| _|_| _|_|_| _|_|_|_| _| _| |${txtrst}"
echo "${bldgrn}|________________________________________|${txtrst}"
echo "${bldgrn} ${txtrst}"
echo "${bldgrn} ${txtrst}"
echo "${bldgrn}Kernel has completed successfully!!! ${txtrst}"
echo " "
echo " "
echo "${bldgrn}Uploading .... ${txtrst}"
echo " "
sshpass -e scp -P 2222 ~/android/kernel/UBER-Hammerhead-Linaro-4.8.3-$curdate.zip [email protected]:/home/Cl3Kener/public_html/HAMMERHEAD/KERNELS/UBER/EXP-LINARO/UBER-Hammerhead-Linaro-4.8.3-$curdate.zip
# Show Elapsed Time
res2=$(date +%s.%N)
echo "${bldgrn}Total elapsed time of ALL BUILDS AND UPLOADS: ${txtrst}${grn}$(echo "($res2 - $res1) / 60"|bc ) minutes ($(echo "$res2 - $res1"|bc ) seconds) ${txtrst}"
else
export curdate=`date "+%m-%d-%Y"`
cp ~/Compile.log ~/android/Logs/Failed-Uber-hammerhead-$curdate.log
rm ~/Compile.log
echo "${bldred} ${txtrst}"
echo "${bldred} ${txtrst}"
echo "${bldred} ________________________________________ ${txtrst}"
echo "${bldred}| |${txtrst}"
echo "${bldred}| _| _| _|_|_| _|_|_|_| _|_|_| |${txtrst}"
echo "${bldred}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldred}| _| _| _|_|_| _|_|_| _|_|_| |${txtrst}"
echo "${bldred}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldred}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldred}| _|_| _|_|_| _|_|_|_| _| _| |${txtrst}"
echo "${bldred}|________________________________________|${txtrst}"
echo "${bldred} ${txtrst}"
echo "${bldred} ${txtrst}"
echo "${bldred}KERNEL IMAGE DID NOT BUILD PROPERLY! Check Compile log! ${txtrst}"
echo " "
# Show Elapsed Time
res2=$(date +%s.%N)
echo "${bldred}Total elapsed time of ALL BUILDS AND UPLOADS: ${txtrst}${red}$(echo "($res2 - $res1) / 60"|bc ) minutes ($(echo "$res2 - $res1"|bc ) seconds) ${txtrst}"
fi;
echo " "
read -p "Press ENTER to Exit"
Hope this helps some of you get creative!
If you want to see a finished product so you can figure out how everything came together see here: http://goo.im/devs/Cl3Kener/HAMMERHEAD/KERNELS/UBER
Cheers!
Cl3Kener

Awesome guide. probbaly not seen much because of its placement but his is helpful!

This is very helpful. Thanks!
Tapatalk-kal küldve az én Nexus 5-el

I have kali linux,i am using for two years
can i use it for this?

Related

need help to translate MIUI V4 (ICS)

Hi,
i tried to translate a MIUI for Galaxy Nexus rom into french (can also be an other language)
i wrote an unix script to automate the process.
What i do is quite simple:
i get a specific MIUI V4 version for my device and the same translated version for the nexus S (because the nexus S has a french version)
i decompile each apk from the french rom, an put the french files into to decompile galaxy nexus directories
i recompile each apk
and i copy the compiled resources into the origin galaxy nexus apks
and i build the new ROM
but i get a bootloop any ideas ?
here is my script
if there are any part of this script that isn't clear, i could try to explain them.
of course this script could also be used on other device or other translation with some changes.
Thanks in advance .
Code:
#!/bin/bash
# MIUI-FRENCH TRANSLATE SCRIPT FOR GNEX V1.0 By Alain57
BASE_DIR=$PWD
FRENCH_DIR=$BASE_DIR/french_rom
ORIGINAL_DIR=$BASE_DIR/original_rom
OUTPUT_ROM_DIR=$BASE_DIR/output_rom
OUT_DIR=$BASE_DIR/out
WORK_DIR=$BASE_DIR/workdir
ORIGIN_APK_DIR=$WORK_DIR/origin
TRANSLATION_DIR=$WORK_DIR/translation
DECODED_APK_DIR=$WORK_DIR/decoded
LOG_FILE=$BASE_DIR/log.txt
TEMP_DIR=$BASE_DIR/temp
# clean the log file and create the missing directories if they don't exist (for exemple on first run)
function cleanLog(){
rm -fr $LOG_FILE
ARRAY_DIR=( $FRENCH_DIR $ORIGINAL_DIR $OUTPUT_ROM_DIR $OUT_DIR $WORK_DIR $ORIGIN_APK_DIR $TRANSLATION_DIR $DECODED_APK_DIR $TEMP_DIR )
echo "creating missing directoriesi if needed"
for DIR in ${ARRAY_DIR[@]}; do
if [ ! -d $DIR ]; then
mkdir $DIR
fi
done
}
# configure apktool to use framework-res and framework-miui-res
function setFramework(){
cd $FRENCH_DIR
echo "<- apktool if system/framework/framework-res.apk ->" >> $LOG_FILE
apktool if framework-res.apk >> $LOG_FILE 2>&1
echo "<- apktool if system/framework/framework-miui-res.apk ->" >> $LOG_FILE
apktool if framework-miui-res.apk >> $LOG_FILE 2>&1
}
#decompile all apk file from the english Gnex miui rom
function decompileOriginFiles(){
cd $ORIGINAL_DIR
COUNT_ORIGINAL_ZIP=`ls . | grep '.zip' | wc -l`
if [ "$COUNT_ORIGINAL_ZIP" -eq "1" ]; then
mv *.zip en.zip
echo "unzip the original rom"
unzip -q -o en.zip
echo "copy the apks to the origin dir"
cp -a system/framework/*.apk $ORIGIN_APK_DIR
cp -a system/app/*apk $ORIGIN_APK_DIR
cd $ORIGIN_APK_DIR
for F in *.apk; do
echo "decompiling origianl file $F ..." | tee -a $LOG_FILE
apktool d $F $DECODED_APK_DIR/${F%.apk} >> $LOG_FILE 2>&1
done
else
echo "there need to be ONE zip file in the original directory"
exit
fi
}
# decompile all apk files from the french Nexus S ROM
function decompileTranslatedFiles(){
cd $FRENCH_DIR
COUNT_FRENCH_ZIP=`ls . | grep '.zip' | wc -l`
if [ "$COUNT_FRENCH_ZIP" -eq "1" ]; then
mv *.zip fr.zip
echo "unzip the french rom"
unzip -q -o fr.zip
setFramework
echo "copy the apks to the working dir"
cp -a system/framework/*.apk $WORK_DIR
cp -a system/app/*.apk $WORK_DIR
cd $WORK_DIR
for F in *.apk; do
echo "decompiling french file $F ..." | tee -a $LOG_FILE
apktool d $F $TRANSLATION_DIR/${F%.apk} >> $LOG_FILE 2>&1
done
else
echo "there neeed to be ONE zip file in the french directory"
exit
fi
}
# Delete the given directory, because it is not needed
function deleteDirectoryWithoutTranslation(){
echo " ---> directory useless, removed"
cd $TRANSLATION_APK_DIR
rm -fr $1
}
# delete all useless data from the french apks
function cleanTranslatedFiles(){
cd $TRANSLATION_DIR
for d in *; do
echo "cleaning the directory $d"
cd $TRANSLATION_DIR/$d
if [ -d "res" ]; then
ls . | grep -v res | xargs -o rm -fr
cd "res"
CONTAINS_FRENCH_TRANSLATION=`ls .| grep '\-fr' | wc -l`
if [ "$CONTAINS_FRENCH_TRANSLATION" -eq "0" ]; then
deleteDirectoryWithoutTranslation $d
else
echo "---> transltation here, clean it"
ls . | grep -v '\-fr\|\./\|\.\./' | xargs -o rm -fr
fi
else
echo "no res directory"
deleteDirectoryWithoutTranslation $d
fi
if [ ! -f $ORIGIN_APK_DIR/$d.apk ];then
echo "directory not in original rom $d"
deleteDirectoryWithoutTranslation $d
fi
done
}
# merge the decoded translation in the decoded english files
function mergeTranslations(){
cd $DECODED_APK_DIR
mv $TRANSLATION_DIR/* .
cd $WORK_DIR
rm -f *.apk
}
# compile new apks including french files
function compileApk(){
cd $ORIGIN_APK_DIR
for f in *.apk; do
echo "compiling $f"
echo "apktool b $DECODED_APK_DIR/${f%.apk} $WORK_DIR/$f"
apktool b $DECODED_APK_DIR/${f%.apk} $WORK_DIR/$f >> $LOG_FILE 2>&1
done
}
# delete apk in work directory and put the original apks there
function deleteWorkFileAndCopyOriginalApk(){
cd $WORK_DIR
rm -f *.apk
cp -a $ORIGIN_APK_DIR/*.apk .
}
# put the compiled modified files in the original apk files
function finalMerge(){
cd $DECODED_APK_DIR
for F in *.apk; do
echo "doing final build $F"
cd $TEMP_DIR
rm -fr *
unzip -q $DECODED_DIR/$F
ls . | grep -v 'res\|classes.dex\|resources.arsc\|\./\|\.\./' | xargs -o rm -fr
if [ -d res ]; then
cd res
ls . | grep -v '\-fr\|\./\|\.\./' | xargs -o rm -fr
HAS_FR=`ls . | grep '\-fr' | wc -l`
if [ "$HAS_FR" -eq "0" ]; then
cd ..
rm -fr res
else
cd ..
fi
fi
zip -r $WORK_DIR/$F *
done
}
#replace the english apk files with the new french apk files, change the build.prop value and create an unsigned zip that can be flashed
function createRom(){
cd $OUTPUT_ROM_DIR
mv $ORIGINAL_DIR/system $ORIGINAL_DIR/boot.img $ORIGINAL_DIR/META-INF .
mv $WORK_DIR/*.apk system/app
mv system/app/framework*.apk system/framework
mv system/build.prop build.prop
sed 's/=en/=fr/g' build.prop > build1.prop
rm -f build.prop
sed 's/=US/=FR/g' build1.prop > system/build.prop
rm -f build1.prop
zip -r $BASE_DIR/new_rom.zip *
}
cleanLog
decompileTranslatedFiles
decompileOriginFiles
cleanTranslatedFiles
mergeTranslations
compileApk
deleteWorkFileAndCopyOriginalApk
finalMerge
createRom
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums & Read the Forum Rules
Moving to Q&A

[Q] How to flash boot.img in shell? (from phone's sdcard)

some kernel app can download and flash boot.img, restarts, how can I do that in terminal? (without the need of adb or Recovery... save hell lots of time)
I'm afraid thats impossible.
kurotsugi said:
I'm afraid thats impossible.
Click to expand...
Click to collapse
so this are dark magic?
Code:
#!/sbin/bb/busybox ash
# lkflash - flash latest leanKernel
#
# author - [email protected]
#
BB="/sbin/bb/busybox"
STABLE="http://imoseyon.host4droid.com/latest"
EXP180="http://imoseyon.host4droid.com/exp/latest180"
EXP230="http://imoseyon.host4droid.com/exp/latest230"
CUR=`$BB uname -a | $BB awk -F'-' '{ print \$3 }'`
while [ 1 ]; do
echo
echo "leanKernel flasher"
echo "------------------"
echo "1) latest stable (recommended)"
echo "2) latest experimental 180mhz-1.65ghz (notrim)"
echo "3) latest experimental 230mhz-1.65ghz (notrim)"
echo "4) check/display versions"
echo "9) latest stable franco (warning: no md5 check)"
echo
echo "FLASH AT YOUR OWN RISK. I'm not responsible for my mistakes or yours. ;)"
echo
echo -n "Please enter a number between 1 and 4 (or press enter to exit): "
read option
case $option in
1)
$BB wget -q -O /sdcard/lk $STABLE
echo; echo -n "Downloading stable "
break
;;
2)
$BB wget -q -O /sdcard/lk $EXP180
echo; echo -n "Downloading experimental 180mhz (notrim) "
break
;;
3)
$BB wget -q -O /sdcard/lk $EXP230
echo; echo -n "Downloading experimental 230mhz (notrim) "
break
;;
4)
echo "Please wait..."
vstable=`$BB wget -q -O - $STABLE | $BB awk '{ print \$3 }'`
v180=`$BB wget -q -O - $EXP180 | $BB awk '{ print \$3 }'`
v230=`$BB wget -q -O - $EXP230 | $BB awk '{ print \$3 }'`
echo; echo ">>> Current version: $CUR, Latest stable: $vstable, Exp: $v180 $v230"
sleep 2
;;
9)
$BB wget -q -O /sdcard/fboot.img http://minooch.com/franciscofranco/Galaxy%20Nexus/nightlies/appfiles/boot.img
$BB dd if=/sdcard/fboot.img of=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot 2> /dev/null
echo "Latest Franco Kernel flashed. Reboot when you're ready."
exit
;;
*)
echo "BYE"
exit
;;
esac
done
[ ! -s "/sdcard/lk" ] && exit
MD5=`$BB awk '{ print \$2 }' /sdcard/lk`
VER=`$BB awk '{ print \$3 }' /sdcard/lk`
if [ "$CUR" == "$VER" ]; then
echo
echo "Aborted. You're already running $CUR."
exit
fi
echo "v$VER. Please wait..."
$BB wget -q -O /sdcard/lkboot.img `$BB awk '{ print \$1 }' /sdcard/lk`
[ ! -s "/sdcard/lkboot.img" ] && exit
SUM=`$BB md5sum /sdcard/lkboot.img | $BB awk '{ print \$1 }'`
echo
if [ "$MD5" == "$SUM" ]; then
echo "Download finished. Checksum verified. Flashing kernel to boot partition..."
$BB dd if=/sdcard/lkboot.img of=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot 2> /dev/null
echo; echo "leanKernel $VER flashed! Reboot when you're ready to run new kernel."
else
echo "md5sum check failed - please try again."
fi

[Q] Need help for executing a script

HI, I'm trying to extract initramfs from zImage by following this excellent thread:
http://forum.xda-developers.com/showthread.php?t=901152
I have followed carefully all the steps but i am getting the following error while executing the extraction script :
# sh repack-zImage.sh -u
repack-zImage.sh: 99: Syntax error: "(" unexpected
How can i resolve this please.
here is the sript :
Code:
#!/bin/bash
version="Version 6, by mizch <[email protected]>
Time-stamp: <2011-05-03 20:14:30 hcz>
Please refer to the thread on http://www.xda-developers.com for
questions and remarks about this program."
# Copyright (C) 2011 by Heike C. Zimmerer <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License. For
# details see <http://www.gnu.org/licenses/>.
### Preparation:
# You should have received cpio_set0 along with this program.
# Copy it into /usr/local/bin.
#
# The program will run without this (and emit an info message about
# using the normal cpio). However, the compession result of the
# initramfs will be smaller and consistent if you use it.
### What the program does:
usage(){
echo "\
Usage: $pname [-v] -u|-p|-z [<file name, default: zImage>]
Function: [Un]Pack a zImage (for modification, mainly of the initramfs)
Opts:
-u unpack an Image
-p pack an image from a directory structure created by
a previous unpack
-z create <file name>.tar from <file name> (simple tar, nothing fancy)
--version print version info
--help print this help
Play with the following three options to get best compression results:
-s use standard cpio (default: uses cpio_set0 if available)
-g use gen_init_cpio instead of cpio/cpio_set0 (ignores -s)
-r don't reorder initramfs according to the original layout
Debugging:
-v verbose (show commands and results as they are executed)
-x script debug (set -x)
Options to help nail down which modified part causes booting to fail.
Lower numbers override higher numbered options:
-1 Use original piggy.gz+piggy_trailer
-2 Use original piggy.gz
-3 Use original piggy
-4 Use original initramfs(_gz)+part3
-5 Use original initramfs_cpio"
exit $1
}
### Graphical display of the unpack process:
#
# Each of the indented items on the same level is derived from the
# single item one level higher.
#
# zImage
# (split)
# +---- decompression_code
# +---- piggy.gz+piggy_trailer
# (split)
# +---- piggy.gz
# | (gunzip)
# | +---- piggy
# | ===== either (compressed initramfs) ====
# | |
# | (split via gunzip limits)
# | +---- kernel.img
# | +---- initramfs_gz+part3
# | (split)
# | +---- initramfs.cpio.gz
# | | (gunzip)
# | | +---- initramfs.cpio
# | | (cpio -i)
# | | +---- initramfs/
# | +---- padding3
# | +---- part3
# | ===== or (uncompressed initramfs) =====
# | |
# | (split at "0707")
# | +---- kernel.img
# | +---- initramfs+part3
# | (split after "TRAILER!!!")
# | +---- initramfs.cpio
# | | (cpio -i)
# | | +---- initramfs/
# | +---- padding3
# | +---- part3
# +---- padding_piggy
# +---- piggy_trailer
#
#
pname="${0##*/}"
args=("[email protected]")
cur_dir="$(pwd)"
# file names:
decompression_code="decompression_code"
piggy_gz_piggy_trailer="piggy.gz+piggy_trailer"
piggy="piggy"
piggy_gz="piggy.gz"
padding_piggy="padding_piggy"
piggy_trailer="piggy_trailer"
ramfs_gz_part3="initramfs.cpio+part3"
ramfs_cpio_gz="initramfs.cpio.gz"
padding3="padding3"
part3="part3"
kernel_img="kernel.img"
ramfs_cpio="initramfs.cpio"
ramfs_dir="initramfs"
sizes="sizes"
ramfs_part3="ramfs+part3"
ramfs_list="initramfs_list"
cpio_t="cpio-t"
cpio="cpio_set0"
# We dup2 stderr to 3 so an error path is always available (even
# during commands where stderr is redirected to /dev/null). If option
# -v is set, we dup2 sterr to 9 also so commands (and some of their
# results if redirected to &9) are printed also.
exec 9>/dev/null # kill diagnostic ouput (will be >&2 if -v)
exec 3>&2 # an always open error channel
#
########### Start of functions
#
# Emit an error message and abort
fatal(){
# Syntax: fatal <string ...>
# Output error message, then abort
echo >&3
echo >&3 "$pname: $*"
kill $$
exit 1
}
# Execute a command, displaying the command if -v:
cmd(){
# Syntax: cmd <command> <args...>
# Execute <command>, echo command line if -v
echo >&9 "$*"
"[email protected]"
}
# Execute a required command, displaying the command if -v, abort on
# error:
rqd(){
# Syntax: cmd <command> <args...>
# Execute <command>, echo commandline if -v, abort on error
cmd "[email protected]" || fatal "$* failed."
}
relpath(){
# Syntax: relpath <absolute_path>
# Function: print a path below $cur_dir as relative path on stdout
if [ "${1#$cur_dir}" != "$1" ]; then
echo -n ".${1#$cur_dir}"
else # not below cur_dir
echo -n "$1"
fi
}
findByteSequence(){
# Syntax: findByteSequence <fname> [<string, default: gzip header>]
# Returns: position (offset) on stdout, empty string if nothing found
file="$1"
local opt
if [ "$2" = "lzma" ]; then
srch=$'\x5d....\xff\xff\xff\xff\xff'
opt=
else
srch="${2:-$'\x1f\x8b\x08'}" # Default: search for gzip header
opt="-F"
fi
pos=$(LC_ALL=C grep $opt -a --byte-offset -m 1 --only-matching -e "$srch" -- "$file")
echo ${pos%%:*}
}
getFileSize(){
# Syntax: getFileSize <file>
# Returns size of the file on stdout.
# Aborts if file doesn't exist.
rqd stat -c %s "$1"
}
recordPackingFileSize()(
# Syntax: recordPackingFileSize <file-var> ...
#
# dump out a file size from the packing directory for debugging.
# Note that the whole function is running in a subshell, so we can
# cd here.
rqd cd "$packing"
for file in "[email protected]"; do
eval local fnam=\$$file
local size=$(getFileSize "$fnam")
printf 'size_%s=%d # %#x\n' $file $size $size
done >> "$sizes"
)
recordFileSize(){
# Syntax: recordFileSize <file-var> ...
# Dump a file size from the current directory into $sizes for
# later sourcing as a shell script.
for file in "[email protected]"; do
eval local fnam=\$$file
local size=$(getFileSize "$fnam")
printf 'size_%s=%d # %#x\n' $file $size $size
done >> "$sizes"
}
recordVars(){
# Syntax dumpVar <var-name>
# Dumps var into file $sizes for later sourcing as a shell script
for var in "[email protected]"; do
eval printf '"%s=\"%s\"\n"' $var \$$var \$$var
done >> "$sizes"
}
checkNUL(){
# Syntax: checkNUL file offset
# Returns true (0) if byte there is 0x0.
[ "$(rqd 2>/dev/null dd if="$1" skip=$2 bs=1 count=1)" = $'\0' ]
}
# We can tell from the magic number where the start of a gzipped
# section is. We cannot tell its exact end. We could only know the
# end if we could get at the kernel's zeropage variables - which we
# can't since their position varies between versions and
# architectures. The following function separates the gzipped part
# from trailing bytes (which can be possibly garbage, but who knows?)
# via successive aproximation.
gunzipWithTrailer(){
# Syntax gunzipWithTrailer <file> <gzip name, sans .gz> <padding> <trailer>
#
# <file>: the input file
# <gzip name, sans .gz>, <padding>, <trailer>:
# The output files. For the gzipped part, both the
# compressed and the uncompressed output is generated, so we have
# 4 output files.
local file="$1"
local gz_result="$2.gz"
local result="$2"
local padding="$3"
local trailer="$4"
local tmpfile="/tmp/gunzipWithTrailer.$$.gz"
local original_size=$(getFileSize "$file")
local d=$(( (original_size+1) / 2))
local direction fini at_min=0
local results_at_min=()
local size=$d
local at_min=0
echo "Separating gzipped part from trailer in '$(relpath "$file")'"
echo -n "Trying size: $size"
while :; do
rqd dd if="$file" of="$tmpfile" bs=$size count=1 2>/dev/null
cmd gunzip >/dev/null 2>&1 -c "$tmpfile"
res=$?
if [ "$d" -eq 1 ]; then
: $((at_min++))
results_at_min[$size]=1
[ "$at_min" -gt 3 ] && break
fi
d=$(((d+1)/2))
case $res in
# 1: too small
1) size=$((size+d)); direction="↑";;
# 2: trailing garbage
2) size=$((size-d)); direction="↓";;
# OK
0) break;;
*) fatal "gunzip returned $res while checking '$(relpath "$file")'";;
esac
echo -n " $size"
done
if [ "$at_min" -gt 3 ]; then
echo -e "\ngunzip result is oscillating between 'too small' and 'too large' at size: ${!results_at_min[*]}"
echo -n "Trying lower nearby values: "
fini=
for ((d=1; d < 30; d++)); do
: $((size--))
echo -n " $size"
rqd dd if="$file" of="$tmpfile" bs=$size count=1 2>/dev/null
if cmd gunzip >/dev/null 2>&1 -c "$tmpfile"; then
echo -n " - OK"
fini=1
break
fi
done
[ -z "$fini" ] && fatal 'oscillating gunzip result, giving up.'
fi
# We've found the end of the gzipped part. This is not the real
# end since gzip allows for some trailing padding to be appended
# before it barfs. First, go back until we find a non-null
# character:
echo -ne "\npadding check (may take some time): "
real_end=$((size-1))
while checkNUL "$file" $real_end; do
: $((real_end--))
done
# Second, try if gunzip still succeeds. If not, add trailing
# null(s) until it succeeds:
while :; do
rqd dd if="$file" of="$tmpfile" bs=$real_end count=1 2>/dev/null
gunzip >/dev/null 2>&1 -c "$tmpfile"
case $? in
# 1: too small
1) : $((real_end++));;
*) break;;
esac
done
real_next_start=$size
# Now, skip NULs forward until we reach a non-null byte. This is
# considered as being the start of the next part.
while checkNUL "$file" $real_next_start; do
: $((real_next_start++))
done
echo $((real_next_start - real_end))
echo
rm "$tmpfile"
# Using the numbers we got so far, create the output files which
# reflect the parts we've found so far:
rqd dd 2>&9 if="$file" of="$gz_result" bs=$real_end count=1
rqd dd 2>&9 if="$file" of="$padding" skip=$real_end bs=1 count=$((real_next_start - real_end))
rqd dd 2>&9 if="$file" of="$trailer" bs=$real_next_start skip=1
rqd gunzip -c "$gz_result" > "$result"
}
# See the comment for gunzipWithTrailer (above) for what this function
# does:
unlzmaWithTrailer(){
# Syntax unlzmaWithTrailer <file> <gzip name, sans .gz> <padding> <trailer>
#
# <file>: the input file
# <gzip name, sans .gz>, <padding>, <trailer>:
# The output files. For the lzma'd part, both the
# compressed and the uncompressed output is generated, so we have
# 4 output files.
local file="$1"
local gz_result="$2.gz"
local result="$2"
local padding="$3"
local trailer="$4"
local tmpfile="/tmp/unlzmaWithTrailer.$$.gz"
local original_size=$(getFileSize "$file")
local d=$(( (original_size+1) / 2))
local direction fini at_min=0
local results_at_min=()
local size=$d
local at_min=
echo "Separating lzma'd part from trailer in '$(relpath "$file")'"
echo -n "Trying size: $size"
while :; do
rqd dd if="$file" of="$tmpfile" bs=$size count=1 2>/dev/null
cmd unlzma >/dev/null 2>&1 -S '' -c "$tmpfile"
res=$?
if [ "$d" -eq 1 ] && [ "$res" -eq 1 ]; then
at_min=yes # we're 1 below the result
fi
d=$(((d+1)/2))
case $res in
# 1: too small
1) size=$((size+d)); direction="↑";;
# 0: too large (or OK if d==1)
0) if [ "$at_min" ]; then
break
fi
size=$((size-d)); direction="↓";;
*) fatal "unlzma returned $res while checking '$(relpath "$file")'";;
esac
echo -n " $size"
done
# Now, skip NULs forward until we reach a non-null byte. This is
# considered as being the start of the next part.
echo
echo -n "Detecting padding: "
real_end="$size"
real_next_start="$size"
while checkNUL "$file" $real_next_start; do
: $((real_next_start++))
done
echo $((real_next_start - real_end))
echo
rm "$tmpfile"
# Using the numbers we got so far, create the output files which
# reflect the parts we've found so far:
rqd dd 2>&9 if="$file" of="$gz_result" bs=$real_end count=1
rqd dd 2>&9 if="$file" of="$padding" skip=$real_end bs=1 count=$((real_next_start - real_end))
rqd dd 2>&9 if="$file" of="$trailer" bs=$real_next_start skip=1
rqd unlzma -c -S '' "$gz_result" > "$result"
}
padTo(){
# Syntax: padTo <file> <size>
# Pads <file> to <size> with trailung 0x0s
# Does nothing if file matches size.
# Aborts if <file> too large for the operation.
local size=$(getFileSize "$1")
local tmp="/tmp/$pname.$$.zeroes"
if [ "$size" -eq "$2" ]; then
echo "$(relpath "$1"): size matches ($size)"
elif [ "$size" -gt "$2" ]; then
fatal "Size of '$(relpath "$1")' too large ($size > $2) (+$((size - $2)))"
else
echo "Padding '$(relpath "$1")' to $2 bytes (+$(($2 - size)))"
rqd dd 2>&9 if=/dev/zero of="$tmp" count=1 bs=$(($2 - size))
rqd cat "$tmp" >> "$1"
rqd rm -f "$tmp"
fi
}
padToMod(){
# Syntax: padTo <modulo> <file>
# Pads <file> until (size mod <modulo>) == 0.
local modulo=$1
local file="$2"
local size=$(getFileSize "$file")
local rest=$((size % modulo))
if [ "$rest" -ne 0 ]; then
padTo "$file" $((size + modulo - rest))
fi
}
buildZImageTar(){
# Syntax: buildZImageTar <path>
# Generates tarred file from <path> into the same directory.
# The file in the archive doesn't contain the path.
# Also copies the result to /home/Shared if it detects
# that it is running at home.
local dir="${1%/*}"/
[ "$dir" = "$1/" ] && dir="$(pwd)/"
(
cd "$dir"
rqd tar cf zImage.tar zImage
)
echo "Generated file: '$(relpath "${dir}$zImage.tar")'"
if [ "$HOSTNAME:$USER" = "Xelzbrot:hcz" ]; then
cp "${dir}zImage.tar" /home/Shared
echo "also copied to '/home/Shared'."
fi
}
reorderInitramfsList(){
# This is some black magic to get about the same compression
# result as the original initramfs.cpio. We reorder the files in
# our initramfs (which is to be created) so that they appear in
# the same order as in the original initramfs.
#
# Syntax: reorderInitramfsList <initramfs_list_file> <reordering_template_file>
#
# Reorders <initramfs_list_file> so that enries are in the order
# given by <reordering_template_file> (which comes from cpio -t).
# Files in <initramfs_list_file> but not in
# <reordering_template_file> are moved in sorted order to the end.
# Comments and empty lines are discarded. The result is written
# to <initramfs_list_file>.
#echo >&2 "Reordering initramfs list"
initramfs_list_file="$1"
reordering_template_file="$2"
declare -A ramfs_entries # make it an associative array
while read line; do
set -- $line
[ $# -eq 0 ] && continue # skip empty lines
[[ "$1" = \#* ]] && continue # skip comments
ramfs_entries["$2"]="$line" # else remember line, indexed by path
done < "$initramfs_list_file"
echo "# reordered ramfs entries" > "$initramfs_list_file"
# now spit the lines out in the order given by the reordering_template_file:
while read path; do
echo "${ramfs_entries["$path"]}"
unset ramfs_entries["$path"] # remove written lines from the array
done < "$reordering_template_file" >> "$initramfs_list_file"
# if there are any files left, append them in sorted order so directories
# come first:
for line in "${ramfs_entries[@]}"; do
echo "$line"
done \
| sort >> "$initramfs_list_file"
}
pack(){
if ! find >/dev/null 2>&1 "$unpacked" "$unpacked/$ramfs" "$unpacked/$sizes" -maxdepth 0; then
fatal "\
This does not look like a directory where a
previous unpack has been done."
fi
# create packing direcory
rqd mkdir -p "$packing"
sizes="$packing/sizes"
echo "# Packing sizes" > "$sizes"
# cd to unpacking directory (original and modified parts)
rqd cd "$unpacked"
# read in file size at the time of unpicking
rqd source sizes
if [ "$opt_1" ]; then
rqd cp "$piggy_gz_piggy_trailer" "$packing"
else
if [ "$opt_2" ]; then
rqd cp "$piggy_gz" "$packing"
else
if [ "$opt_3" ]; then
rqd cp "$piggy" "$packing"
compress_list=("$packing/$piggy") # compress it as a single file
else
if [ "$opt_4" ]; then
rqd cp "$ramfs_gz_part3" "$packing"
else
if [ "$opt_5" ]; then
rqd cp "$ramfs_cpio" "$packing"
else
echo "Generating initramfs"
if ! which >/dev/null "$cpio"; then
if [ -n "$compressed" ]; then
echo "Info: '$cpio' not found, using normal cpio."
echo " This only means that your compressed initramfs will be slightly larger"
echo " and its size will differ from invocation to invocation."
fi
cpio="cpio"
fi
for ftime in "" "-a" "-m"; do
find "$ramfs_dir" -exec touch $ftime -d @0 {} \;
done
rqd gen_initramfs_list.sh -u squash -g squash "$ramfs_dir" > "$packing/$ramfs_list"
cp "$packing/$ramfs_list" "$packing/$ramfs_list.orig"
if [ -z "$opt_r" ]; then
# reorder so files are arranged as in original initramfs:
reorderInitramfsList "$packing/$ramfs_list" "$cpio_t"
else
# sort so directories come before their content:
sort < "$cpio_t" > "$packing/$cpio_t.sorted"
reorderInitramfsList "$packing/$ramfs_list" "packing/$cpio_t.sorted"
fi
if [ -z "$opt_g" ]; then
# No -g: Use our own cpio routine
(
rqd cd "$ramfs_dir"
# extract the file names from our
# (possibly reordered) initramfs list
# and pass them to cpio:
while read line; do
set -- $line
[ $# -eq 0 ] && continue # skip empty lines
[[ "$1" = \#* ]] && continue # skip comments
echo "${2#/}"
done < "$packing/$ramfs_list" \
| rqd "$cpio" -H newc -R root:root -o > "$packing/$ramfs_cpio"
)
else
# -g set: use gen_init_cpio (from kernel tree)
rqd gen_init_cpio "$packing/$ramfs_list" > "$packing/$ramfs_cpio"
fi
recordPackingFileSize ramfs_cpio
fi # opt_5
if [ "$compressed" = "gz" ]; then
echo "Creating gzip compressed initramfs"
rqd gzip -8 < "$packing/$ramfs_cpio" > "$packing/$ramfs_cpio_gz"
padTo "$packing/$ramfs_cpio_gz" "$((size_ramfs_cpio_gz + size_padding3))"
rqd cat "$packing/$ramfs_cpio_gz" "$part3" > "$packing/$ramfs_gz_part3"
recordPackingFileSize ramfs_cpio_gz ramfs_gz_part3
elif [ "$compressed" = "lzma" ]; then
echo "Creating lzma compressed initramfs"
rqd lzma -9 < "$packing/$ramfs_cpio" > "$packing/$ramfs_cpio_gz"
padTo "$packing/$ramfs_cpio_gz" "$((size_ramfs_cpio_gz + size_padding3))"
rqd cat "$packing/$ramfs_cpio_gz" "$part3" > "$packing/$ramfs_gz_part3"
recordPackingFileSize ramfs_cpio_gz ramfs_gz_part3
else
echo "initramfs is not compressed"
fi
fi # opt_4
echo "Assembling piggy"
if [ -n "$compressed" ]; then
rqd cat "$kernel_img" "$packing/$ramfs_gz_part3" > "$packing/$piggy"
compress_list=("$packing/$piggy") # compress it as a single file
else
#touch "$packing/$padding3"
#padTo "$packing/$padding3" "$size_padding3"
padTo "$packing/$ramfs_cpio" $((size_ramfs_cpio + size_padding3))
# compress parts seperately (yields better compression results):
cat "$kernel_img" "$packing/$ramfs_cpio" "$part3" > "$packing/$piggy"
recordPackingFileSize "piggy"
compress_list=("$packing/$piggy")
fi
fi # opt_3
echo "Creating piggy.gz"
target_size=$((size_piggy_gz + size_padding_piggy))
# At first, use gzip -9 for compressing since it delivers
# better results with zImages most of the time:
rqd gzip -n -9 -c "${compress_list[@]}" > "$packing/$piggy_gz"
size1=$(getFileSize "$packing/$piggy_gz")
if [ "$size1" -gt "$target_size" ]; then
# too large. Try if we can get better results with
# gzip -8. If not, barf and abort:
rqd gzip -8 -n -c "${compress_list[@]}" > "$packing/$piggy_gz"
size2=$(getFileSize "$packing/$piggy_gz")
if [ "$size2" -gt "$target_size" ]; then
fatal "\
piggy.gz too large (gzip -9: +$((size1-target_size)), gzip -8: +$((size2-target_size)))
You might want to try a different combination of the -g, -r and -s options."
fi
fi
padTo "$packing/$piggy_gz" "$((size_piggy_gz + size_padding_piggy))"
recordPackingFileSize "piggy_gz"
fi # opt_2
echo "Assembling $zImage"
rqd cat "$packing/$piggy_gz" "$piggy_trailer" > "$packing/$piggy_gz_piggy_trailer"
fi # opt_1
rqd cat "$decompression_code" "$packing/$piggy_gz_piggy_trailer" \
> "$packing/$zImage"
echo "Successfully created '$(relpath "$packing/$zImage")'"
recordPackingFileSize zImage
buildZImageTar "$packing/$zImage"
}
unpack()(
[ -d "$unpacked" ] && echo "\
Warning: there is aready an unpacking directory. If you have files added on
your own there, the repacking result may not reflect the result of the
current unpacking process."
rqd mkdir -p "$unpacked"
rqd cd "$unpacked"
sizes="$unpacked/sizes"
echo "# Unpacking sizes" > "$sizes"
piggy_start=$(findByteSequence "$cur_dir/$zImage")
if [ -z "$piggy_start" ]; then
fatal "Can't find a gzip header in file '$zImage'"
fi
rqd dd 2>&9 if="$cur_dir/$zImage" bs="$piggy_start" count=1 of="$decompression_code"
rqd dd 2>&9 if="$cur_dir/$zImage" bs="$piggy_start" skip=1 of="$piggy_gz_piggy_trailer"
recordFileSize decompression_code piggy_gz_piggy_trailer
gunzipWithTrailer "$piggy_gz_piggy_trailer" \
"$piggy" "$padding_piggy" "$piggy_trailer"
recordFileSize "piggy" "piggy_gz" "padding_piggy" "piggy_trailer"
ramfs_gz_start=$( findByteSequence "$piggy" lzma)
if [ -n "$ramfs_gz_start" ]; then
echo "Found lzma compressed ramdisk."
compressed=lzma
else
ramfs_gz_start=$( findByteSequence "$piggy")
if [ -n "$ramfs_gz_start" ]; then
echo "Found gzip compressed ramdisk."
compressed=gz
fi
fi
if [ "$compressed" ]; then
rqd dd 2>&9 if="$piggy" of="$kernel_img" bs="$ramfs_gz_start" count=1
rqd dd 2>&9 if="$piggy" of="$ramfs_gz_part3" bs="$ramfs_gz_start" skip=1
if [ "$compressed" = "gz" ]; then
rqd gunzipWithTrailer "$ramfs_gz_part3" "$ramfs_cpio" "$padding3" "$part3"
else
rqd unlzmaWithTrailer "$ramfs_gz_part3" "$ramfs_cpio" "$padding3" "$part3"
fi
recordFileSize "kernel_img" "ramfs_cpio_gz" "padding3" "ramfs_gz_part3" "ramfs_cpio" "part3"
recordVars compressed
else
echo "Found uncompressed ramdisk."
compressed=""
initrd_start=$(findByteSequence "$piggy" "0707")
[ -z "$initrd_start" ] && fatal "Cannot find cpio header"
rqd dd 2>&9 if="$piggy" of="$kernel_img" bs="$initrd_start" count=1
rqd dd 2>&9 if="$piggy" of="$ramfs_part3" bs="$initrd_start" skip=1
initrd_end=$(findByteSequence "$ramfs_part3" "TRAILER!!!")
[ -z "$initrd_end" ] && fatal "Cannot find cpio trailer"
initrd_end=$((initrd_end + 10)) # skip trailer length
initrd_end=$(( (initrd_end | 0x1ff) + 1)) # round up to block size (512)
rqd dd 2>&9 if="$ramfs_part3" of="$ramfs_cpio" bs="$initrd_end" count=1
real_next_start=$initrd_end
echo -n "Detecting padding (may take some time): "
while checkNUL "$ramfs_part3" $real_next_start; do
: $((real_next_start++))
done
padding3_len=$((real_next_start - initrd_end))
echo $padding3_len
rqd dd 2>&9 if="$ramfs_part3" of="$padding3" skip="$initrd_end" count="$padding3_len" bs=1
rqd dd 2>&9 if="$ramfs_part3" of="$part3" bs="$real_next_start" skip=1
recordFileSize "kernel_img" "padding3" "ramfs_part3" "ramfs_cpio" "part3"
recordVars compressed
fi
echo "Unpacking initramfs"
rqd cpio -t < "$ramfs_cpio" > "$cpio_t"
rqd mkdir -p "$ramfs_dir"
(
rqd cd "$ramfs_dir"
rqd cpio -i -m --no-absolute-filenames -d -u < "../$ramfs_cpio"
)
echo
echo "Success."
echo "The unpacked files and the initramfs directory are in '$(relpath "$unpacked")'."
)
#### start of main program
while getopts xv12345sgrpuhtz-: argv; do
case $argv in
p|u|z|1|2|3|4|5|t|r|g) eval opt_$argv=1;;
v) exec 9>&2; opt_v=1;;
s) cpio="cpio";;
x) set -x;;
-) if [ "$OPTARG" = "version" ]; then
echo "$pname $version"
exit 0
else
usage
fi;;
h|-) usage;;
*) fatal "Illegal option";;
esac
done
shift $((OPTIND-1))
zImage="${1:-zImage}"
unpacked="$cur_dir/${zImage}_unpacked"
packing="$cur_dir/${zImage}_packing"
shift
if [ -n "$*" ]; then
fatal "Excess arguments: '$*'"
fi
if [ -n "$opt_z" ]; then
buildZImageTar "$zImage"
fi
if [ -n "$opt_u" ]; then
[ -f "$zImage" ] || fatal "file '$zImage': not found"
unpack
fi
if [ -n "$opt_p" ]; then
pack
fi
#if [ -n "$opt_t" ]; then # for testing
# reorderInitramfsList "$packing/$ramfs_list" "$unpacked/$cpio_t"
#fi
if [ -z "$opt_p$opt_u$opt_z$opt_t" ]; then
echo >&2 "$pname: Need at least one of -u, -p, or -z."
echo >&2 "$pname: Type '$pname --help' for usage info."
exit 1
fi
exit
Solved. (by using bash instead of sh)..

[SCRIPTS][INIT.D] KangBang Kernel [DEVELOPMENT]

KangBang Kernel Scripts Development
This thread is dedicated to the development of bash scripts to control several aspects of KangBang Kernel.
The scripts below, are there for that. most of the work have been done already (but more additions to be made), but be are with problems on the logs files... the output indicates that the scripts are giving errors...
these are scripts so far​
S91voltctrl​
Spoiler
Code:
#!/system/bin/sh
##############################################################
## CPU/GPU Voltage and Frequency Control script by infected_ #
##############################################################
LOG_FILE=/data/log/cpu_gpu_control.log
rm -Rf $LOG_FILE
exec &> $LOG_FILE
# ************************************
# CPU Clock Control
# ************************************
echo "Starting Voltage and Frequency Control $( date +"%m-%d-%Y %H:%M:%S" )"
echo "Sleeping for 20 seconds to workaround oc not setting properly on stock derivatve roms..."
sleep 20
echo "Ok lets start working"
echo "Set MIN Scaling Frequency"
echo "200000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo ""
echo "---------------"
echo "Set MAX Scaling Frequency"
echo "1000000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo ""
echo "---------------"
# ************************************
# CPU Governor and I/O Scheduler
# ************************************
echo "Set Scheduler for stl, bml and mmc"
for i in `ls /sys/block/stl*` /sys/block/bml* /sys/block/mmcblk* /sys/block/mtdblock* ; do
echo "zen" > $i/queue/scheduler;
echo "$i/queue/scheduler";
done;
echo "---------------";
echo "Set governor"
echo "zzmoove" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo ""
echo "---------------"
#
echo "Set zzmove extra options"
# *************************************
# "zzmove" cpu governor extra settings
# *************************************
echo "85" > /sys/devices/system/cpu/cpufreq/zzmoove/up_threshold;
echo "85" > /sys/devices/system/cpu/cpufreq/zzmoove/up_threshold_hotplug1;
echo "80" > /sys/devices/system/cpu/cpufreq/zzmoove/down_threshold;
echo "75" > /sys/devices/system/cpu/cpufreq/zzmoove/down_threshold_hotplug1;
echo "85" > /sys/devices/system/cpu/cpufreq/zzmoove/down_threshold_sleep;
echo "5" > /sys/devices/system/cpu/cpufreq/zzmoove/freq_step;
echo "1" > /sys/devices/system/cpu/cpufreq/zzmoove/hotplug_sleep;
echo "4" > /sys/devices/system/cpu/cpufreq/zzmoove/sampling_down_factor;
echo "100000" > /sys/devices/system/cpu/cpufreq/zzmoove/sampling_rate;
echo "500000" > /sys/devices/system/cpu/cpufreq/zzmoove/freq_limit_sleep;
echo "75" > /sys/devices/system/cpu/cpufreq/zzmoove/smooth_up;
echo "95" > /sys/devices/system/cpu/cpufreq/zzmoove/up_threshold_sleep;
# ************************************
# CPU Voltage Control
# ************************************
echo "Set UV" | tee -a $LOG_FILE;
echo "1275 1250 1200 1175 1150 1100 1050 1000 950 900 875 925 850 850 825 825 800 775" > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table #change voltages according to your device !!!
echo ""
echo "---------------"
# ************************************
# Screen Off CPU Policy
# ************************************
# Disable second CPU core when screen is off (default 0=second core enabled)
echo "Disable second CPU core when screen is off"
echo "1" /sys/devices/system/cpu/cpufreq/zzmoove/hotplug_sleep;
echo ""
echo "---------------"
# ************************************
# GPU Clock, Voltages & Thresholds
# ************************************
# Set GPU clocks (Valid values are: 100 160 200 267)
echo "Set GPU frequencies"
echo "100 160 267" > /sys/class/misc/gpu_clock_control/gpu_control;
echo ""
echo "---------------"
# Set GPU Up and Down thresholds
echo "Set GPU thresholds"
echo "80% 50% 85% 60%" > /sys/class/misc/gpu_clock_control/gpu_control;
echo ""
echo "---------------"
# Set GPU voltages (Changes possible at +/-50mV ie at 50000 steps)
echo "Set GPU UV"
echo "850000 900000 950000" > /sys/class/misc/gpu_voltage_control/gpu_control;
echo ""
echo "---------------"
#
echo "Voltage and Frequency Control finished at $( date +"%m-%d-%Y %H:%M:%S" )"
S92zipalign (credits goes to darky for original)​
Spoiler
Code:
#!/system/bin/sh
##############################################################
## Automatic ZipAlign script by infected_ #
##############################################################
su
LOG_FILE=/data/log/zipalign.log
rm -Rf $LOG_FILE
exec &> $LOG_FILE
#
if [ -n $zipalign ] && [ $zipalign = "true" ];
then
busybox mount -o remount,rw /;
busybox mount -o remount,rw -t auto /system;
busybox mount -o remount,rw -t auto /data;
fi;
busybox mount -t tmpfs -o size=70m none /mnt/tmp;
echo "Starting Automatic ZipAlign " `date`
echo "Starting Automatic ZipAlign $( date +"%m-%d-%Y %H:%M:%S" )"
for apk in /data/app/*.apk ; do
zipalign -c 4 $apk;
ZIPCHECK=$?;
if [ $ZIPCHECK -eq 1 ]; then
echo ZipAligning $(basename $apk)
zipalign -f 4 $apk /cache/$(basename $apk);
if [ -e /cache/$(basename $apk) ]; then
cp -f -p /cache/$(basename $apk) $apk
rm /cache/$(basename $apk);
else
echo ZipAligning $(basename $apk) Failed
fi;
else
echo ZipAlign already completed on $apk
fi;
done;
for apk in /system/app/*.apk ; do
zipalign -c 4 $apk;
ZIPCHECK=$?;
if [ $ZIPCHECK -eq 1 ]; then
echo ZipAligning $(basename $apk)
zipalign -f 4 $apk /cache/$(basename $apk);
if [ -e /cache/$(basename $apk) ]; then
cp -f -p /cache/$(basename $apk) $apk
rm /cache/$(basename $apk);
else
echo ZipAligning $(basename $apk) Failed
fi;
else
echo ZipAlign already completed on $apk
fi;
done;
for apk in /system/framework/*.apk ; do
zipalign -c 4 $apk;
ZIPCHECK=$?;
if [ $ZIPCHECK -eq 1 ]; then
echo ZipAligning $(basename $apk)
zipalign -f 4 $apk /cache/$(basename $apk);
if [ -e /cache/$(basename $apk) ]; then
cp -f -p /cache/$(basename $apk) $apk
rm /cache/$(basename $apk);
else
echo ZipAligning $(basename $apk) Failed
fi;
else
echo ZipAlign already completed on $apk
fi;
done;
echo "Automatic ZipAlign finished at $( date +"%m-%d-%Y %H:%M:%S" )"
S93sqlite​
Spoiler
Code:
#!/system/bin/sh
##############################################################
## SQLite database VACUUM and REINDEX script by infected_ #
##############################################################
LOG_FILE=/data/log/sqlite.log
rm -Rf $LOG_FILE
exec &> $LOG_FILE
# echo "";
echo "*********************************************";
echo "Optimizing and defragging your database files (*.db)";
echo "Ignore the 'database disk image is malformed' error";
echo "Ignore the 'no such collation sequence' error";
echo "*********************************************";
echo "";
#
#
echo "SQLite database VACUUM and REINDEX started at $( date +"%m-%d-%Y %H:%M:%S" )"
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;
echo "SQLite database VACUUM and REINDEX finished at $( date +"%m-%d-%Y %H:%M:%S" )"
S94tweaks​
Code:
#!/system/bin/sh
##############################################################
## Miscellaneous Tweaks script by infected_ #
##############################################################
#
LOG_FILE=/data/log/tweaks.log
rm -Rf $LOG_FILE
exec &> $LOG_FILE
#
echo "Applying Tweaks $( date +"%m-%d-%Y %H:%M:%S" )"
#
# ***************************************
# Turn logging off
# ***************************************
#
echo "Turning off logging"
su
mount -o remount,rw /
rm -rf /dev/log
echo "0" > /sys/module/ump/parameters/ump_debug_level
echo "0" > /sys/module/mali/parameters/mali_debug_level
echo "0" > /sys/module/kernel/parameters/initcall_debug
echo "0" > /sys//module/lowmemorykiller/parameters/debug_level
echo "0" > /sys/module/earlysuspend/parameters/debug_mask
echo "0" > /sys/module/alarm/parameters/debug_mask
echo "0" > /sys/module/alarm_dev/parameters/debug_mask
echo "0" > /sys/module/binder/parameters/debug_mask
echo "0" > /sys/module/xt_qtaguid/parameters/debug_mask
echo ""
echo "---------------"
# ************************************************
# VM Tweaks
# ************************************************
echo "Enabling VM Tweaks"
sysctl -w vm.swappiness=0
sysctl -w vm.vfs_cache_pressure=10
sysctl -w vm.dirty_background_ratio=45
sysctl -w vm.dirty_ratio=50
sysctl -w vm.dirty_writeback_centisecs=2000
sysctl -w vm.dirty_expire_centisecs=1000
sysctl -w vm.min_free_kbytes=4096
sysctl -w kernel.sched_min_granularity_ns=200000 > /dev/null
sysctl -w kernel.sched_latency_ns=400000 > /dev/null
sysctl -w kernel.sched_wakeup_granularity_ns=100000 > /dev/null
echo ""
echo "---------------"
# ********************************************************
# Enable JIT Packet Filter Compiler (needs kernel support)
# ********************************************************
echo "Enabling JIT Packet Filter Compiler"
echo "1" > /proc/sys/net/core/bpf_jit_enable
echo ""
echo "---------------"
# ********************************************************
# microSD card speed tweak
# ********************************************************
echo "Enabling microSD card speed tweak"
echo "4096" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;
echo ""
echo "---------------"
# ********************************************************
# Flags blocks as non-rotational and increases cache size
# ********************************************************
echo "Flagging blocks as non-rotational and increasig cache size"
LOOP=`ls -d /sys/block/loop*`;
RAM=`ls -d /sys/block/ram*`;
MMC=`ls -d /sys/block/mmc*`;
for j in $LOOP $RAM
do
echo "0" > $j/queue/rotational;
echo "4096" > $j/queue/read_ahead_kb;
done
echo ""
echo "---------------"
# ********************************************************
# Battery tweaks
# ********************************************************
echo "Enabling battery tweaks"
echo "500" > /proc/sys/vm/dirty_expire_centisecs
echo "1000" > /proc/sys/vm/dirty_writeback_centisecs
echo ""
echo "---------------"
# ********************************************************
# EXT4 tweaks
# ********************************************************
echo "Enabling EXT4 tweaks"
# a) remove journals
echo "Removing journals"
tune2fs -f -o journal_data_writeback /dev/block/mmcblk0p9
tune2fs -f -O ^has_journal /dev/block/mmcblk0p9
tune2fs -f -o journal_data_writeback /dev/block/mmcblk0p7
tune2fs -f -O ^has_journal /dev/block/mmcblk0p7
tune2fs -f -o journal_data_writeback /dev/block/mmcblk0p10
tune2fs -f -O ^has_journal /dev/block/mmcblk0p10
echo ""
echo "---------------"
# b) better mount options
echo "Applying better mount options"
busybox mount -o remount,noatime,noauto_da_alloc,nodiratime,barrier=0,nobh /system
busybox mount -o remount,noatime,noauto_da_alloc,nosuid,nodev,nodiratime,barrier=0,nobh /data
busybox mount -o remount,noatime,noauto_da_alloc,nosuid,nodev,nodiratime,barrier=0,nobh /cache
echo ""
echo "---------------"
#
echo "Tweaks applying finished at $( date +"%m-%d-%Y %H:%M:%S" )"
S95bln​
Spoiler
Code:
#!/system/bin/sh
#######################################
# ************************************
# BLN and leds timeout
# ************************************
#
LOG_FILE=/data/log/bln.log
rm -Rf $LOG_FILE
exec &> $LOG_FILE
#
# ***************************************
# Enable Button Light Notification (BLN)
# ***************************************
#
echo "Enabling BLN $( date +"%m-%d-%Y %H:%M:%S" )"
echo 1 > /sys/class/misc/backlightnotification/enabled
echo ""
echo "---------------"
#
echo "Enabling BLN finished at $( date +"%m-%d-%Y %H:%M:%S" )"
# **************************************
# Enable Button Light Timeout
# **************************************
#
echo "Enabling leds timeout $( date +"%m-%d-%Y %H:%M:%S" )"
echo 3 > /sys/class/misc/notification/bl_timeout
echo ""
echo "---------------"
#
echo "Enabling leds timeout finished at $( date +"%m-%d-%Y %H:%M:%S" )"
#
# **************************************
# leds voltage setting
# **************************************
echo "setting leds voltage $( date +"%m-%d-%Y %H:%M:%S" )"
#
echo "---------------"
echo 2500 > /sys/devices/virtual/sec/sec_touchkey/touchkey_brightness
echo ""
echo "setting leds voltage finished at $( date +"%m-%d-%Y %H:%M:%S" )"
S91 is partially working, it sets the correct governor, speed, voltage and i/o scheduler, but gives other errors...
S92 no sure. zipalign binary seems to be doing its job, but strange output on log...
S93 seem to be working, sometimes it gives an error about *db being locked" or "permission denied" ...
S94 not working. lots of errors on log...
S95 is working properly.
Click to expand...
Click to collapse
We appreciate ALL the help we can't get from the XDA community..
This is a fantastic kernel compilded and mantained by @sakindia123, but there aren't lots of options to control it, besides the init.d scripts...
So please, if you have suggestions, corrections and additions to be made, please do so ! ​
reserved ..
Thank you for the topic. As i'm very new to kernel scripting would you mind explain what exacly each script is designed for?
Thank you in advance
Envoyé depuis mon GT-I9100 avec Tapatalk
@infected_
Nice idea mate!
A small tip/request: can you put the scripts inside spoilers?
Could be much easier to search for what we need
Reserved...
Thanks mate:beer::beer::beer:
Inviato dal mio GT-I9100 con Tapatalk 2
ive attached the scripts that i use in my roms to be placed in the init.d folder. the zipalign file needs to go in the system\bin folder and sqlite3 goes in the system\xbin folder
dead0 said:
ive attached the scripts that i use in my roms to be placed in the init.d folder. the zipalign file needs to go in the system\bin folder and sqlite3 goes in the system\xbin folder
Click to expand...
Click to collapse
many thank for your contribution !!
just a quick (and maybe silly question) .. normally on all zipalign scripts the binary goes to pah /system/xbin .. is it the same thing, or in the future i may have problems, using same some scripts that use zipalign or something for ex..?
infected_ said:
many thank for your contribution !!
just a quick (and maybe silly question) .. normally on all zipalign scripts the binary goes to pah /system/xbin .. is it the same thing, or in the future i may have problems, using same some scripts that use zipalign or something for ex..?
Click to expand...
Click to collapse
ive had no problem with the zipalign binary being in the system\bin folder. the log shows everything completes successfully without any errors. i dont think it matters too much tho
Just we wondering if there is a script for turning off the menu and back button lights after 3 seconds or so and for then to turn on when you touch the screen.
I set it using the settings in advanced/display but they are either always on or always off?
Thanks for any help :thumbup:
Sent From My Galaxy S2
Running SentinelROM 4.75
Powered By KangBang Kernel v1.3
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Nos_20 said:
Just we wondering if there is a script for turning off the menu and back button lights after 3 seconds or so and for then to turn on when you touch the screen.
I set it using the settings in advanced/display but they are either always on or always off?
Thanks for any help :thumbup:
Sent From My Galaxy S2
Running SentinelROM 4.75
Powered By KangBang Kernel v1.3
Click to expand...
Click to collapse
S95bln ..
Enviado do meu GT-I9100
infected_ said:
S95bln ..
Enviado do meu GT-I9100
Click to expand...
Click to collapse
I copied the script into notepad++, I save as an .xml? Like S95bln.xml?
Then copy the script to system/etc/init.d and reboot and voila???
Thanks for helping! I really do not understand all this scripting !
Nos_20 said:
I copied the script into notepad++, I save as an .xml? Like S95bln.xml?
Then copy the script to system/etc/init.d and reboot and voila???
Thanks for helping! I really do not understand all this scripting !
Click to expand...
Click to collapse
You dont need to change anything on the script. Just place it on init.d folder and set permissions to 0755. NO extension to the file!
Enviado do meu GT-I9100
infected_ said:
You dont need to change anything on the script. Just place it on init.d folder and set permissions to 0755. NO extension to the file!
Enviado do meu GT-I9100
Click to expand...
Click to collapse
OK thanks.
Is this looking correct?
Sent From My Galaxy S2
Running SentinelROM 4.75
Powered By KangBang Kernel v1.3
Nos_20 said:
OK thanks.
Is this looking correct?
Sent From My Galaxy S2
Running SentinelROM 4.75
Powered By KangBang Kernel v1.3
Click to expand...
Click to collapse
Yes.
Restart your phone and check the log in /data/log
axpira said:
Yes.
Restart your phone and check the log in /data/log
Click to expand...
Click to collapse
The directory of /data/log is empty?
Does this mean the script has not run? Any idea how I get it going as the behaviour of the leds is still the same!
Nos_20 said:
The directory of /data/log is empty?
Does this mean the script has not run? Any idea how I get it going as the behaviour of the leds is still the same!
Click to expand...
Click to collapse
If don't have this file: /data/log/bln.log , then the script not run.
Do you restart your phone?
axpira said:
If don't have this file: /data/log/bln.log , then the script not run.
Do you restart your phone?
Click to expand...
Click to collapse
Yes I just restarted my phone and checked the directory, empty!
What should I do to get it working?
Edit. Got the script to run at boot, but it still doesn't work.
Here is the log from /data/log
Enabling BLN 06-28-2013 13:56:30
/system/etc/init.d/S95Bln[16]: can't create /sys/class/misc/backlightnotification/enabled
: No such file or directory
---------------
Enabling BLN finished at 06-28-2013 13:56:30
Enabling leds timeout 06-28-2013 13:56:30
/system/etc/init.d/S95Bln[26]: can't create /sys/class/misc/notification/bl_timeout
: No such file or directory
---------------
Enabling leds timeout finished at 06-28-2013 13:56:30
setting leds voltage 06-28-2013 13:56:30
---------------
/system/etc/init.d/S95Bln[38]: can't create /sys/devices/virtual/sec/sec_touchkey/touchkey_brightness
: No such file or directory
setting leds voltage finished at 06-28-2013 13:56:30
Edit
I was looking at the directory /sys/class/misc/backlightnotification/enabled.
On my Rom - SentinelROM it looks like this directory is symlinked to /sys/devices/virtual/misc/backlightnotification
Just wondering if this would impact on the script and why it says "No such file or directory" as the error??
Sent From My Galaxy S2
Running SentinelROM 4.75
Powered By KangBang Kernel v1.3
the original (base) zip algin script is from darky one of my co devs please give credits
pxrave said:
the original (base) zip algin script is from darky one of my co devs please give credits
Click to expand...
Click to collapse
Done
Could you ask to him to give a jump to this thread, and have a look to see whats causing all the errors in log file?
Thanks!
Thanks a lot for this thread
Posté via Vanilla Rootbox

A script to get a random file

Dear developers,
I have an issue in my script switching from Android 9 to 10 (devices from a Umidigi s3 Pro to a Umidigi F2)
I have installed Bosybox App on the first and Busybox Magisk module on the latter
Now the script does not work because the command
list=(`busybox find "$dirs" -type f -name *.$ext`)
returns an empty array
This is the complete script:
Bash:
#!/system/bin/sh
echo
if test "$1" = ""; then
echo "Randomfile script by Uranya <[email protected]> v1.4 01.01.2021"
echo "Usage:"
echo "sh randomfile.sh <sourcedir> <extension> <destdir>"
exit 1
fi
dirs=$1
ext=$2
dird=$3'/'
dest=$dird'random'
delim1=""
delim2=""
last='last.txt'
# create filename's array
IFS=$'\n'
# here we have the ISSUE
list=(`busybox find "$dirs" -type f -name *.$ext`)
# count number of files
num=${#list[@]}
# initialize random generator
RANDOM=$$
# generate random number in range 1-NUM
let "ran=(${RANDOM} % ${num})+ 1"
echo Random from $num files is $ran
sour=${list[ran]}
sourn=${sour#$dirs}
sourn=${sourn:1:${#sourn}}
date=$(date +"%Y.%m.%d %H:%M")
day=$(date +"%d")
hour=$(date +"%H")
minute=$(date +"%M")
message='---------------------------------------\n'$date' - '$num' >>> '$ran'\n'$delim1$sourn$delim2
if ([ "$day" = "01" ] && [[ "$minute" < "29" ]]) || [ ! -f $dird$last ]; then
echo >$dird$last $message
else
sed -i '1i'$message $dird$last
fi
echo $delim1$sourn$delim2
# rename the old file
cp $dest.$ext $dest'_back.'$ext
# copy the file
cat "$sour" >$dest.$ext
echo File copied as $delim1$dest.$ext$delim2
Can you please help me why this happens, and how to fix it?
Thank you very much for your attention!
Uranya said:
[...]
Click to expand...
Click to collapse
Having done some tests I have found this:
opening a root privileged terminal and executing
---
echo `find /storage/7BC3-1805/Music/MP3/Abba -type f -name *.mp3`
---
it returns two strings containing the names of files inside that folder, but putting it in my script continues to return an empty array, so the issue is not in the access to the folder, but in the syntax, I guess
try putting that *.$ext into quotes...
Dear friends, CXZa, after a couple of hours debugging the script, finally, I have found the mistake!
The line to be used is:
list=( `find "$dirs" -type f -name "*.$ext"` )
it is a very subtle difference: the space after and before the parenthesis!
(even the word busybox is useless)
Oddly in the Busybox app (I have had on my S3 Pro) the spaces are not mandatory, whilst in the Busybox Magisk module those spaces ARE mandatory!
I'm using that script for almost 8 years to have an every day different music for my wake up.
I'm using Tasker to call it just before my alarm get off, so the same file contains every day, a different song.
I have done a change also in the array index that did not began by 0...
So, here it is the right script:
Bash:
#!/system/bin/sh
echo
if test "$1" = ""; then
echo "Randomfile script by Uranya <@uranya7x> v1.5 26.03.2021"
echo "Usage:"
echo "sh randomfile.sh <sourcedir> <extension> <destdir>"
exit 1
fi
dirs=$1
ext=$2
dird=$3'/'
dest=$dird'random'
delim1=""
delim2=""
last='last.txt'
# create filename's array
IFS=$'\n'
list=( `find "$dirs" -type f -name "*.$ext"` )
# count number of files
num=${#list[@]}
# generate random number in range 1-NUM
let "ran=(${RANDOM} % ${num})+ 1"
echo Random from $num files is $ran
sour=${list[$ran-1]}
sourn=${sour#$dirs}
sourn=${sourn:1:${#sourn}}
date=$(date +"%Y.%m.%d %H:%M")
day=$(date +"%d")
hour=$(date +"%H")
minute=$(date +"%M")
message='---------------------------------------\n'$date' - '$num' >>> '$ran'\n'$delim1$sourn$delim2
if ([ "$day" = "01" ] && [[ "$minute" < "29" ]]) || [ ! -f $dird$last ]; then
echo >$dird$last $message
else
sed -i '1i'$message $dird$last
fi
echo $delim1$sourn$delim2
# rename the old file
cp $dest.$ext $dest'_back.'$ext
# copy the file
cat "$sour" >$dest.$ext
echo File copied as $delim1$dest.$ext
I hope it will be useful to someone else that loves to be waked up by music...
Peace everywhere!

Categories

Resources