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)..
Related
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
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
I have two of these devices sitting around and I was wondering how people were repurposing them. I just picked up a Raspberry Pi with the intention of setting up a home automation system. Isn't the Eris also an ARMv6 processor? Could they be used as smart WiIP video security cameras? Is there a Linux distro somewhere? Anyone have any experience?
Greetings! There's a thread here you might be interested in. http://forum.xda-developers.com/showthread.php?t=823564&highlight=linux
roirraW "edor" ehT said:
Greetings! There's a thread here you might be interested in. http://forum.xda-developers.com/showthread.php?t=823564&highlight=linux
Click to expand...
Click to collapse
http://www.4shared.com/zip/uiPl7NhN/ubuntu.html Link to Ubuntu.img
to mount you can use this:
linuxboot.sh
#option if you wish to load a different file than the rc_enter just replace the rc_enter.sh with the script file you want to run
# i.e init.sh below this script I will post the initl.ls if you wan to replace the rc_enter.sh
Code:
#!/system/bin/sh
(
# If $BINDS does not exist, then done of the others are set iether.
if [ -z "$BINDS" ]; then
export DIST="debian squeeze"
export FILESYSTEM=/sdcard/ubuntu.img
export MOUNTPOINT=/sdcard/linux
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
export USER=root
export LOGNAME=root
export UID=0
export SHELL=bash
export FS=ext3
export busybox="/data/data/com.galoula.LinuxInstall/bin/busybox"
export BINDS="1"
unset TMPDIR
fi
createLinuxBoot() {
if $busybox [ -d "$FILESYSTEM" ]
then
echo "I: Directory chroot !"
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT/proc")" ]; then
# If the loop device is already mounted, we do nothing.
echo "W: $DIST is already mounted. Entering chroot..."
else
echo "I: Mounting device for $DIST..."
# Bind some Android dirs to the linux filesystem
if $busybox [ $BINDS -eq 1 ]
then
# Create mtab
echo > "${MOUNTPOINT}/etc/mtab"
$busybox cat /proc/mounts > "${MOUNTPOINT}/etc/mtab"
# for i in `$busybox cat /proc/mounts | $busybox cut -d " " -f 2`
for i in $( $busybox cat /proc/mounts | $busybox awk '{print $2}' )
do
$busybox mkdir -p "${MOUNTPOINT}/$i" 2> /dev/null
$busybox mount -o bind "${i}" "${MOUNTPOINT}/${i}" 2> /dev/null
#echo "${i}" >> "${MOUNTPOINT}/etc/mtab"
done
fi
fi
else
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
# If the loop device is already mounted, we do nothing.
echo "W: $DIST is already mounted. Entering chroot..."
else
echo "I: Mounting device for $DIST..."
if $busybox [ ! -d $MOUNTPOINT ]; then
# Create the mount point if it does not already exist
$busybox mkdir -p $MOUNTPOINT 2> /dev/null
if $busybox [ ! -d $MOUNTPOINT ]; then
echo "F: It was not possible to create the missing mount location ($MOUNTPOINT)"
return 0
fi
fi
if $busybox [ -f "$FILESYSTEM" ]
then
# Android places loop devices in /dev/block/ instead of root /dev/
# If there are none in /dev/ we create links between /dev/loopX and /dev/block/loopX so that losetup will work as it should.
if $busybox [ ! -e /dev/block/loop0 ]; then
i=0
while [ $i -le 8 ]
do
$busybox mknod /dev/block/loop$i b 7 $i
let i=1+$i
done
fi
# Locate the current loop device file
if $busybox [ ! -z "$($busybox losetup | $busybox grep "$FILESYSTEM")" ]; then
# If the filesystem file is already attached to an loop device, we get the path to the device file.
loblk=$($busybox losetup | $busybox grep "$FILESYSTEM" | $busybox cut -d ":" -f 1)
else
# If the filesystem file is not yet attached, we attach it.
loblk=$($busybox losetup -f)
$busybox losetup $loblk $FILESYSTEM 2> /dev/null
# Make sure that the device was successfully attached to a loop device file
if $busybox [ -z "$($busybox losetup | $busybox grep "$FILESYSTEM")" ]; then
echo "F: It was not possible to attach the device to a loop device file"
return 0
fi
fi
fi
if $busybox [ -b "$FILESYSTEM" ]
then
loblk=$FILESYSTEM
fi
# Mount the filesystem
$busybox mount -t $FS $loblk $MOUNTPOINT 2> /dev/null
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
# Bind some Android dirs to the linux filesystem
if $busybox [ $BINDS -eq 1 ]
then
# Create mtab
echo > "${MOUNTPOINT}/etc/mtab"
$busybox cat /proc/mounts > "${MOUNTPOINT}/etc/mtab"
# for i in `$busybox cat /proc/mounts | $busybox cut -d " " -f 2`
for i in $( $busybox cat /proc/mounts | $busybox awk '{print $2}' )
do
# /sdcard/Mon mount/Linux
$busybox mkdir -p "${MOUNTPOINT}/$i" 2> /dev/null
$busybox mount -o bind "${i}" "${MOUNTPOINT}/${i}" 2> /dev/null
#echo "${i}" >> "${MOUNTPOINT}/etc/mtab"
done
fi
#for i in $BINDS
#do
# # Bind the dirs if they are not already binded
# if $busybox [ -z "$($busybox mount | $busybox grep "$MOUNTPOINT/$i ")" ]; then
# # Create any missing dirs in the mountpoint
# if $busybox [ ! -d $MOUNTPOINT/$i ]; then
# $busybox mkdir -p $MOUNTPOINT/$i
# fi
# $busybox mount -o bind $i $MOUNTPOINT$i
# fi
#done
else
echo "F: It was not possible to mount $DIST at the specified location ($MOUNTPOINT)"
return 0
fi
fi
fi
# FIX the "stdin: is not a tty" error in direct hadware case.
if $busybox [ -z "$($busybox mount | $busybox grep "$MOUNTPOINT/dev/pts ")" ]; then
$busybox mount -t devpts devpts $MOUNTPOINT/dev/pts
fi
# For the network.
#sysctl -w net.ipv4.ip_forward=1
echo 1 > /proc/sys/net/ipv4/ip_forward
# Cleanup tmp folder.
$busybox rm -rf $MOUNTPOINT/tmp/*
if $busybox [ -f $MOUNTPOINT/etc/init.android/rc_mount.sh ]; then
# Execute the mount init file, if it exists
echo "I: Executing /etc/init.android/rc_mount.sh"
$busybox chroot $MOUNTPOINT /etc/init.android/rc_mount.sh
fi
echo "I: Entering chroot..."
return 1
}
removeLinuxBoot() {
if $busybox [ -d "$FILESYSTEM" ]
then
echo "I: Directory chroot !"
# Unmount pts
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT/dev/pts ")" ]; then
$busybox umount $MOUNTPOINT/dev/pts 2> /dev/null
fi
for i in $BINDS
do
# Unmount all binding dirs
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT/$i ")" ]; then
$busybox umount $MOUNTPOINT/$i
fi
done
for i in `$busybox cat /proc/mounts | $busybox tac | $busybox grep -v "$MOUNTPOINT " | $busybox grep "$MOUNTPOINT" | $busybox cut -d " " -f 2`;do umount $i 2> /dev/null;done
else
if $busybox [ -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
# If linux is not mounted, then do nothing.
echo "W: $DIST is already unmounted"
else
echo "I: Unmounting $DIST..."
if $busybox [ -f $MOUNTPOINT/etc/init.android/rc_unmount.sh ]; then
echo "I: Executing /etc/init.android/rc_unmount.sh"
# Execute the unmount init script, if it exist.
$busybox chroot $MOUNTPOINT /etc/init.android/rc_unmount.sh
fi
sync
# Make sure that we have an loop device file to use
if $busybox [ -f "$FILESYSTEM" ]
then
if $busybox [ ! -z "$($busybox losetup | $busybox grep "$FILESYSTEM")" ]; then
# Get the loop device file
loblk=$($busybox losetup | $busybox grep "$FILESYSTEM" | $busybox cut -d ":" -f 1)
else
echo "E: Could not locate the loop device file. $DIST was not unmounted successfully"
fi
fi
if $busybox [ -b "$FILESYSTEM" ]
then
loblk=$FILESYSTEM
fi
# Unmount pts
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT/dev/pts ")" ]; then
$busybox umount $MOUNTPOINT/dev/pts
fi
for i in `$busybox cat /proc/mounts | $busybox tac | $busybox grep -v "$MOUNTPOINT " | $busybox grep "$MOUNTPOINT" | $busybox cut -d " " -f 2`;do umount $i 2> /dev/null;done
for i in $BINDS
do
# Unmount all binding dirs
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT/$i ")" ]; then
$busybox umount $MOUNTPOINT/$i
fi
done
sync && sleep 1
# Unmount the device
$busybox umount $MOUNTPOINT 2> /dev/null && sleep 1
# If the device could not be unmounted
if $busybox [ ! -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
echo "E: $DIST could not be unmounted. Trying to kill attached processes..."
# Try to kill all processes holding the device
for i in `$busybox grep "$MOUNTPOINT" /proc/*/maps 2> /dev/null | $busybox cut -d":" -f 1 | $busybox sort | $busybox uniq | $busybox cut -d "/" -f 3`; do kill $i 2> /dev/null; echo; done
fuser -k -9 $MOUNTPOINT
for i in `$busybox grep "$MOUNTPOINT" /proc/*/maps 2> /dev/null | $busybox cut -d":" -f 1 | $busybox sort | $busybox uniq | $busybox cut -d "/" -f 3`; do kill -9 $i 2> /dev/null; echo; done
# Use umount with the -l option to take care of the rest
$busybox umount -l $MOUNTPOINT 2> /dev/null && sleep 1
fi
# Make sure the device has been successfully unmounted
if $busybox [ -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
if $busybox [ -f "$FILESYSTEM" ]
then
# Try to detach the device from the loop device file
$busybox losetup -d $loblk 2> /dev/null
# Make sure that the device was successfully detached
if $busybox [ -z "$($busybox losetup | $busybox grep "$FILESYSTEM")" ]; then
echo "I: $DIST has been successfully unmounted"
else
echo "E: $DIST has been unmounted, but could not detach the loop device"
fi
fi
if $busybox [ -b "$FILESYSTEM" ]
then
if $busybox [ -z "$($busybox mount | $busybox grep "$MOUNTPOINT ")" ]; then
echo "I: $DIST has been successfully unmounted"
else
echo "E: $DIST has been unmounted, but could not detach the loop device"
fi
fi
else
echo "E: $DIST could not be unmounted successfully"
fi
fi
fi
}
if $busybox [ "$1" = "unmount" ]; then
removeLinuxBoot
else
createLinuxBoot
if $busybox [ $? -eq 1 ]; then
if $busybox [ -f $MOUNTPOINT/etc/init.android/rc_enter.sh ]; then
echo "I: Executing /etc/init.android/rc_enter.sh"
$busybox chroot $MOUNTPOINT /etc/init.android/rc_enter.sh
else
echo "I: To run command when enterring Linux create executable file at /etc/init.android/rc_enter.sh"
fi
$busybox chroot $MOUNTPOINT /bin/bash -i
if $busybox [ -f $MOUNTPOINT/etc/init.android/rc_leave.sh ]; then
echo "I: Executing /etc/init.android/rc_leave.sh ..."
$busybox chroot $MOUNTPOINT /etc/init.android/rc_leave.sh
else
echo "I: To run command when leaving Linux create executable file at /etc/init.android/rc_leave.sh"
fi
echo "Q: Do you want to unmount the $DIST environment, or leave it as is ? Y will kill all process as required; any other key will leave services running."
read REPLY
if $busybox [ "y$REPLY" = "yy" ] || $busybox [ "y$REPLY" = "yY" ]; then
removeLinuxBoot
fi
fi
fi
)
or you can mount it with this linuxboot.sh:
Code:
# Check Permissions
if [ $(whoami) != root ]; then
echo "This script must be run as root."
exit
fi
# Script Variables
NAME=ubuntu
PATH=$(dirname $0)
# Enviroment Variables
export BIN=/system/bin
export HOME=/root
export MOUNT=/data/local/mnt/$NAME
export PATH=$BIN:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
export TERM=linux
export USER=root
# Change Directory
cd $PATH
# Create Mount Point
mkdir -p $MOUNT
# Remount System Read/Write
mount -o remount,rw /system
# Check Loop Block Device
if [ ! -b /dev/block/loop_$NAME ]; then
# Create Loop Block Device
mknod /dev/block/loop_$NAME b 7 255
fi
# Setup Loop Block Device
losetup /dev/block/loop_$NAME $NAME.img
# Mount Loop Block Device To Mount Point
mount -t ext3 /dev/block/loop_$NAME $MOUNT
# Add Mount Points
mount -o bind /dev $MOUNT/dev
mount -o bind /dev/pts $MOUNT/dev/pts
mount -o bind /dev/shm $MOUNT/dev/shm
mount -o bind /sdcard $MOUNT/media
mount -t proc none $MOUNT/proc
mount -t sysfs none $MOUNT/sys
# Set Options
echo "127.0.0.1 localhost" > $MOUNT/etc/hosts
echo "nameserver 8.8.4.4" > $MOUNT/etc/resolv.conf
echo "nameserver 8.8.8.8" >> $MOUNT/etc/resolv.conf
rm -rf $MOUNT/lost+found
sysctl -w net.ipv4.ip_forward=1 > /dev/null
sysctl -w net.ipv6.conf.all.forwarding=1 > /dev/null
# Enter Linux
chroot $MOUNT /bin/bash -c "source /etc/profile; bash"
# Remove Mount Points
umount $MOUNT/sys
umount $MOUNT/proc
umount $MOUNT/media
umount $MOUNT/dev/shm
umount $MOUNT/dev/pts
umount $MOUNT/dev
# Clean Up
umount $MOUNT
losetup -d /dev/block/loop_$NAME
rm /dev/block/loop_$NAME
rmdir $MOUNT
this is not the init.sh.
the init.sh is iniside the ubuntu.img so to boot using the init.sh you can edit the rc_enter.sh to start init.sh like so:
./init.sh
you can also start a service like so:
service hostname start
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?
Hi,
for catching events I found:
http://forum.xda-developers.com/showthread.php?t=2233865
Now I want to build a shell were I can look for devices and then catch them and bind them to a action...
It's my first time I tried to write a shell script...
The script works if I don't have any devices witch sends continuously there daters:
Code:
#!/system/bin/sh
[...]
device1="/dev/input/event4"
device2="/dev/input/event0"
while :; do
getevent -q -t -c 2 | grep -e "$device1" -e "$device2" | while IFS=' ' read -r ev_t_brckt ev_time ev_path ev_type ev_code ev_value _; do #-r _ a; do
Mapping "${ev_path/:}" "$ev_code" "$ev_value" "$device1" "$device2"
done
Result="$?"
if [[ "$Result" == "11" ]] then
input keyevent 85 #KEYCODE_MEDIA_PLAY_PAUSE
fi
done
..mapping looks like:
Code:
Mapping() { # "${ev_path/:}" "$ev_code" "$ev_value" "$deviceX1" "$deviceX2" (...)
if [[ "$1" == "$4" && "$2" == "0139" && "$3" == "00000001" ]] then
return 11 #Play/Pause
fi
# (…) and so on
}
is there any way to write
Code:
getevent -q -t -c 2 | grep -e "$device1" -e "$device2" | while IFS=' ' read -r ev_t_brckt ev_time ev_path ev_type ev_code ev_value _; do #-r _ a; do
to
Code:
getevent -q -t | grep -e "$device1" -e "$device2" | while IFS=' ' read -r ev_t_brckt ev_time ev_path ev_type ev_code ev_value _; do #-r _ a; do
Mapping "${ev_path/:}" "$ev_code" "$ev_value" "$device1" "$device2"
if [ -n "$?" ]; then
>>>> exit / break /what ever
fi
done
I tried it with “exit”, “break” and “return” (and “kill $PID”) but getevent didn't want to exit :'(
any ideas?
(pleas be clement with my grammar.. it's not my native language )
kind regards, Veit