Add extract feature to update-binary

This commit is contained in:
topjohnwu 2018-05-13 14:26:28 +08:00
parent c3c78428c4
commit 9b445d89a1

View File

@ -1,31 +1,40 @@
# EX_ARM, EX_X86, BB_ARM, and BB_X86 should be generated in build.py # EX_ARM, EX_X86, BB_ARM, and BB_X86 should be generated in build.py
dirname_wrap() { getdir() {
case "$1" in case "$1" in
*/*) dir=${1%/*}; [ -z $dir ] && echo "/" || echo $dir ;; */*) dir=${1%/*}; [ -z $dir ] && echo "/" || echo $dir ;;
*) echo "." ;; *) echo "." ;;
esac esac
} }
[ "$1" = "indep" ] && INDEP=true || INDEP=false extract_bb() {
$INDEP && TMPDIR="`dirname_wrap "${BASH_SOURCE:-$0}"`" || TMPDIR=/dev/tmp EXBIN=$BBDIR/b64xz; BBBIN=$BBDIR/busybox
INSTALLER=$TMPDIR/install; BBDIR=$TMPDIR/bin touch $EXBIN; touch $BBBIN; chmod 755 $EXBIN $BBBIN
EXBIN=$BBDIR/b64xz; BBBIN=$BBDIR/busybox echo -ne $EX_ARM > $EXBIN
$INDEP || rm -rf $TMPDIR 2>/dev/null; if $EXBIN --test 2>/dev/null; then
mkdir -p $BBDIR 2>/dev/null echo $BB_ARM | $EXBIN > $BBBIN
touch $EXBIN; touch $BBBIN; chmod 755 $EXBIN $BBBIN else
echo -ne $EX_ARM > $EXBIN echo -ne $EX_X86 > $EXBIN
if $EXBIN --test 2>/dev/null; then echo $BB_X86 | $EXBIN > $BBBIN
echo $BB_ARM | $EXBIN > $BBBIN fi
else rm $EXBIN
echo -ne $EX_X86 > $EXBIN }
echo $BB_X86 | $EXBIN > $BBBIN setup_bb() {
fi BBDIR=$TMPDIR/bin; mkdir -p $BBDIR 2>/dev/null
$BBBIN --install -s $TMPDIR/bin extract_bb
export PATH=$BBDIR:$PATH $BBBIN --install -s $BBDIR
if $INDEP; then export PATH=$BBDIR:$PATH
shift }
exec sh "$@" case "$1" in
else "extract")
mkdir -p $INSTALLER [ -z "$2" ] && BBDIR=. || BBDIR="$2"
unzip -o "$3" -d $INSTALLER extract_bb
exec sh $INSTALLER/META-INF/com/google/android/updater-script $@ ;;
fi "indep")
TMPDIR="`getdir "${BASH_SOURCE:-$0}"`"; setup_bb
shift; exec sh "$@"
;;
*)
TMPDIR=/dev/tmp; rm -rf $TMPDIR 2>/dev/null; setup_bb
INSTALLER=$TMPDIR/install; mkdir -p $INSTALLER; unzip -o "$3" -d $INSTALLER
exec sh $INSTALLER/META-INF/com/google/android/updater-script $@
;;
esac