#!/bin/sh fail () { echo "$@" >&2; exit 1; } necho () { echo "$@" | tr -d \\012; } needroot () { [ x$ID = x0 -o x"$TE" != x ] && return [ x$NEEDROOTLOOP != x ] && return; NEEDROOTLOOP=1; export NEEDROOTLOOP necho "Command $cmd requires root access. " d=${ROOTUSER:-root} necho "Please enter your root id [$d]: " read r rest : ${r:=$d} # Can not use $@ inside su ... -c "...", therefore ... x=`for i in "$@"; do echo $i | sed "s/'/'\\\\\''/g; s/.*/ '&'/"; done \ | tr -d '\012'; echo` # ... tested with some Linux, OpenBSD and Solaris /bin/sh:s unset POSIXLY_CORRECT # This with next line is the most portable option(?) exec su ${r:-root} -c "exec sh $0 $cmd $x" # exec su ${r:-root} "exec sh $0 $cmd $x" exit 0 } pre () { test x"$1" = x && fail Usage: $0 imagefile test -x flasher || fail No flasher binary in current directory test -f "$1" || fail $1: No such file needroot "$@" echo echo Switch off power from 770 and plug USB cable in '(then press enter)'. read line echo Press home button down, keep it down while powering 770 on... echo } cmd_fiasco () ## flash fiasco (full fs?) { pre "$@" echo ... And wait until upload complete and 700 has rebooted. ./flasher -F "$1" -f -R } cmd_kernel () ## flash kernel { pre "$@" ./flasher -f -k "$1" sleep 1 echo ... now you can unplug usb cable from your 770. } [ x"$1" = x ] && { echo #echo Usage: $0 '[-n] [args]' echo Usage: $0 ' [args]' echo echo $0 commands available: echo sed -n '/^cmd_[a-z]/ { s/^cmd_/ /; s/[ ]()[ ]//; s/#/ /g; p; }' $0 # echo # echo 'with option -n the operation is simulated (semi-accurately).' echo exit 0 } cmd=$1; shift cc= for i in `sed -n 's/^cmd_\([a-z_]*\) (.*/\1/p' $0` do case $i in $cmd*) cp=$cc; cc="$i $cc";; esac done [ x"$cc" = x ] && { echo $0: $cmd -- command not found.; exit 1; } [ x"$cp" != x ] && { echo $0: $cmd -- ambiquous command: matches $cc; exit 1; } cmd=$cc cmd_$cc "$@" exit 0