From 9b445d89a15d9196a7b331e053317d8dd4510242 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 13 May 2018 14:26:28 +0800 Subject: [PATCH] Add extract feature to update-binary --- scripts/update_binary.sh | 59 +++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/scripts/update_binary.sh b/scripts/update_binary.sh index d9af09c46..01448099f 100644 --- a/scripts/update_binary.sh +++ b/scripts/update_binary.sh @@ -1,31 +1,40 @@ # EX_ARM, EX_X86, BB_ARM, and BB_X86 should be generated in build.py -dirname_wrap() { +getdir() { case "$1" in */*) dir=${1%/*}; [ -z $dir ] && echo "/" || echo $dir ;; *) echo "." ;; esac } -[ "$1" = "indep" ] && INDEP=true || INDEP=false -$INDEP && TMPDIR="`dirname_wrap "${BASH_SOURCE:-$0}"`" || TMPDIR=/dev/tmp -INSTALLER=$TMPDIR/install; BBDIR=$TMPDIR/bin -EXBIN=$BBDIR/b64xz; BBBIN=$BBDIR/busybox -$INDEP || rm -rf $TMPDIR 2>/dev/null; -mkdir -p $BBDIR 2>/dev/null -touch $EXBIN; touch $BBBIN; chmod 755 $EXBIN $BBBIN -echo -ne $EX_ARM > $EXBIN -if $EXBIN --test 2>/dev/null; then - echo $BB_ARM | $EXBIN > $BBBIN -else - echo -ne $EX_X86 > $EXBIN - echo $BB_X86 | $EXBIN > $BBBIN -fi -$BBBIN --install -s $TMPDIR/bin -export PATH=$BBDIR:$PATH -if $INDEP; then - shift - exec sh "$@" -else - mkdir -p $INSTALLER - unzip -o "$3" -d $INSTALLER - exec sh $INSTALLER/META-INF/com/google/android/updater-script $@ -fi +extract_bb() { + EXBIN=$BBDIR/b64xz; BBBIN=$BBDIR/busybox + touch $EXBIN; touch $BBBIN; chmod 755 $EXBIN $BBBIN + echo -ne $EX_ARM > $EXBIN + if $EXBIN --test 2>/dev/null; then + echo $BB_ARM | $EXBIN > $BBBIN + else + echo -ne $EX_X86 > $EXBIN + echo $BB_X86 | $EXBIN > $BBBIN + fi + rm $EXBIN +} +setup_bb() { + BBDIR=$TMPDIR/bin; mkdir -p $BBDIR 2>/dev/null + extract_bb + $BBBIN --install -s $BBDIR + export PATH=$BBDIR:$PATH +} +case "$1" in + "extract") + [ -z "$2" ] && BBDIR=. || BBDIR="$2" + extract_bb + ;; + "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