--- /dev/null
+#! /bin/bash
+
+SCRIPT_PATH=$(readlink -f $(dirname $0))
+
+[ -n "$DEPLOY_DIR" ] || DEPLOY_DIR="/opt/usr/dev"
+[ -n "$OUT_DIR" ] || OUT_DIR=$(readlink -f "$SCRIPT_PATH/../out.mobile.arm")
+[ -n "$DEPLOY_STRIPPED_LIBS" ] || DEPLOY_STRIPPED_LIBS=1
+[ -n "$TIZEN_SDK_PATH" ] || TIZEN_SDK_PATH="$HOME/tizen-sdk"
+
+# Globals.
+out_dir=$OUT_DIR
+out_subdir=""
+deploy_subdir=""
+arm_strip=""
+
+usage() {
+ cat << EOF
+Usage: $0 debug|release [-o outdir] [lib|ewk]
+
+ default outdir: out.mobile.arm
+
+ENVIRONMENT
+ DEPLOY_DIR
+ default: /opt/usr/dev
+ OUT_DIR
+ default: out.mobile.arm
+ DEPLOY_STRIPPED_LIBS
+ default: 1
+ TIZEN_SDK_PATH
+ default: ~/tizen-sdk
+
+EOF
+}
+
+dieTrap() {
+ echo "ERROR at $0:$1"
+ usage
+ exit 1
+}
+
+trap 'die $0 $LINENO' ERR SIGINT SIGTERM SIGQUIT
+
+fastpush() {
+ src=$1
+ dst=$2
+ size=$(ls -1s --block-size=1 $src | cut -f 1 -d ' ')
+ trashold="524288" # 512K
+ # Avoid setup overhead for small files.
+ if [ "$size" -le "$trashold" ]; then
+ sdb push $src $dst
+ else
+ $SCRIPT_PATH/tizensync.sh push $src $dst
+ # Print a report that is somewhat consistent with sdb push.
+ echo "fast-pushed $src"
+ fi
+}
+
+_setupDevice() {
+ # Do a quick heuristic check that it was already installed via package.
+ # We don't handle everything so the package has to be installed once.
+ lsout=$(sdb shell "ls /usr/lib/chromium-efl/icudtl.dat 2>/dev/null")
+ if [ -z "$lsout" ]; then
+ >&2 echo "It seems like you have never installed chromium-efl via package."
+ >&2 echo "Sorry but it won't work, exiting..."
+ exit 1
+ fi
+
+ sdb start-server
+ sdb root on
+ sdb shell << EOF
+mkdir -p "$DEPLOY_DIR/lib/release"
+mkdir -p "$DEPLOY_DIR/lib/debug"
+[ -f /var/run/sshd.pid ] || /usr/sbin/sshd
+exit
+EOF
+ sdb push "$SCRIPT_PATH/device_envsetup.sh" $DEPLOY_DIR
+}
+
+setupDevice() {
+ _setupDevice > /dev/null
+}
+
+get_arm_strip() {
+ if [ -n "$CROSS_COMPILE" -a -x "${CROSS_COMPILE}strip" ]; then
+ echo "${CROSS_COMPILE}strip"
+ return 0
+ fi
+
+ # Try to use the one from tizen sdk.
+ for _dummy in $(seq 1 1); do # dummy loop for bailing on error to print message.
+ # Glob (*) to handle different versions.
+ pushd $TIZEN_SDK_PATH/tools/arm-linux-gnueabi-gcc*/bin > /dev/null || break
+ path="$(pwd)/arm-linux-gnueabi-strip"
+ [ -x "$path" ] || break
+ popd > /dev/null || break
+ return 0
+ done
+
+ >&2 echo "Cannot find usable strip binary. Hint: try setting TIZEN_SDK_PATH to your installation."
+ return 1
+}
+
+deploylib() {
+ lib=$1
+ target_dir=$2
+ [ -f "$lib" ]
+ stripped="$1.0"
+ if [ "$DEPLOY_STRIPPED_LIBS" != "1" ]; then
+ stripped=$lib
+ elif [ ! -e "$stripped" -o "$stripped" -ot "$lib" ]; then
+ echo "stripping $lib to $stripped..."
+ $arm_strip -s $lib -o $stripped
+ fi
+
+ fastpush $stripped $target_dir/$(basename $lib)
+}
+
+deploychromiumlib() {
+ lib="$out_subdir/lib/libchromium-efl.so"
+ echo "deploying $lib..."
+ deploylib $lib $deploy_subdir
+
+ web_proc=$out_subdir/efl_webprocess
+ echo "deploying $web_proc..."
+ fastpush $web_proc $deploy_subdir
+}
+
+deployewk() {
+ lib="$out_subdir/lib/libchromium-ewk.so"
+ echo "deploying $lib..."
+ deploylib $lib $deploy_subdir
+
+ webview_app="$out_subdir/efl_webview_app"
+ if [ -f "$webview_app" ]; then
+ echo "deploying $webview_app..."
+ fastpush "$webview_app" $DEPLOY_DIR
+ fi
+ minibrowser="$out_subdir/mini_browser"
+ if [ -f "$minibrowser" ]; then
+ echo "deploying $minibrowser..."
+ fastpush "$minibrowser" $DEPLOY_DIR
+ fi
+}
+
+# Off we go...
+
+if echo "$@" | grep -Eqw "\-h|\-\-help"; then
+ usage
+ exit 0
+fi
+
+buildtype=$1
+[ "$buildtype" == "release" -o "$buildtype" == "debug" ]
+shift
+
+deploy_part="all"
+
+while [ "$#" -gt "0" ]; do
+ if [ "$1" == "-o" ]; then
+ out_dir=$2
+ shift
+ else
+ [ -z "$deploy_part" ]
+ deploy_part=$1
+ fi
+ shift
+done
+
+[ -d "$out_dir" ]
+[ "$deploy_part" == "all" -o "$deploy_part" == "lib" -o "$deploy_part" == "ewk" ]
+
+if [ "$buildtype" == "release" ]; then
+ deploy_subdir="$DEPLOY_DIR/lib/release"
+ out_subdir="${out_dir}/Release"
+elif [ "$buildtype" == "debug" ]; then
+ deploy_subdir="$DEPLOY_DIR/lib/debug"
+ out_subdir="${out_dir}/Debug"
+fi
+
+[ -d "$out_subdir" ]
+
+if [ "$DEPLOY_STRIPPED_LIBS" == "1" ]; then
+ arm_strip="$(get_arm_strip)"
+fi
+
+setupDevice
+
+case "$deploy_part" in
+ lib)
+ deploychromiumlib
+ ;;
+ ewk)
+ deployewk
+ ;;
+ all)
+ deploychromiumlib && deployewk
+ ;;
+esac
+
+echo ""
+echo "SUCCESS!"
+echo "Build has been deployed to device."
+echo "Source in device_envsetup.sh in $DEPLOY_DIR before starting application."
+++ /dev/null
-# NOTE: $0 doesn't work for sourced scripts.
-__SCRIPT_PATH=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
-
-unset DEPLOY_DIR
-unset OUT_DIR
-unset DEPLOY_STRIPPED_LIBS
-unset TIZEN_SDK_TOOLCHAIN_PATH
-[ -n "$DEPLOY_DIR" ] || DEPLOY_DIR="/opt/usr/dev"
-[ -n "$OUT_DIR" ] || OUT_DIR=$(readlink -f "$__SCRIPT_PATH/../out.mobile.arm")
-[ -n "$DEPLOY_STRIPPED_LIBS" ] || DEPLOY_STRIPPED_LIBS=1
-[ -n "$TIZEN_SDK_TOOLCHAIN_PATH" ] || TIZEN_SDK_TOOLCHAIN_PATH="$HOME/tizen-sdk/tools/arm-linux-gnueabi-gcc-4.5/bin"
-
-fastpush() {
- $__SCRIPT_PATH/tizensync.sh push $1 $2
-}
-
-setupdevice() {
- __setupdevice >/dev/null
-}
-
-deploylib() {
- lib=$1
- target_dir=$2
- stripped="$1.0"
- if [ "$DEPLOY_STRIPPED_LIBS" != "1" ]; then
- stripped=$lib
- elif [ ! -e "$stripped" -o "$stripped" -ot "$lib" ]; then
- STRIP="$TIZEN_SDK_TOOLCHAIN_PATH/arm-linux-gnueabi-strip"
- $STRIP -s $lib -o $stripped
- fi
- fastpush $stripped $target_dir/$(basename $lib)
-}
-
-# Usage: deploy* debug|release [outdir]
-# outdir is out.mobile.arm by default.
-# sdb root should be on.
-
-deploychromiumlib() {
- __setup_enter
- __setOutDir $1 $2 || return 1
- LIB="$__out_dir/lib/libchromium-efl.so"
- deploylib $LIB $__deploy_dir
- __setup_exit
-}
-
-deploywebproc() {
- __setup_enter
- __setOutDir $1 $2 || return 1
- web_proc_path=$__out_dir/efl_webprocess
- fastpush $web_proc_path $__deploy_dir
- __setup_exit
-}
-
-deploychromium() {
- __setup_enter
- deploychromiumlib $1 $2 && deploywebproc $1 $2
- __setup_exit
-}
-
-deployewklib() {
- __setup_enter
- __setOutDir $1 $2 || return 1
- LIB="$__out_dir/lib/libchromium-ewk.so"
- deploylib $LIB $__deploy_dir
- __setup_exit
-}
-
-deployapps() {
- __setup_enter
- __setOutDir $1 $2 || return 1
- [ -f "$__out_dir/efl_webview_app" -o -f "$__out_dir/mini_browser" ] || (>&2 echo "no app binaries exist"; return 1)
- [ -f "$__out_dir/efl_webview_app" ] && sdb push "$__out_dir/efl_webview_app" $DEPLOY_DIR
- [ -f "$__out_dir/mini_browser" ] && sdb push "$__out_dir/mini_browser" $DEPLOY_DIR
- __setup_exit
-}
-
-deployewk() {
- __setup_enter
- deployewklib $1 $2 && deployapps $1 $2
- __setup_exit
-}
-
-deployall() {
- __setup_enter
- deploychromium $1 $2 && deployewk $1 $2
- __setup_exit
-}
-
-
-# Internal
-
-__deploy_dir=""
-__out_dir=""
-
-__setOutDir() {
- if [ "$1" == "release" ]; then
- __deploy_dir="$DEPLOY_DIR/lib/release"
- if [ -z "$2" ]; then
- __out_dir="$OUT_DIR/Release"
- else
- __out_dir=$(readlink -f $2)/Release
- fi
- elif [ "$1" == "debug" ]; then
- __deploy_dir="$DEPLOY_DIR/lib/debug"
- if [ -z "$2" ]; then
- __out_dir="$OUT_DIR/Release"
- else
- __out_dir=$(readlink -f $2)/Release
- fi
- else
- >&2 echo "Wrong config. Options: debug or release."
- return 1
- fi
-}
-
-__setupdevice() {
- sdb shell << EOF
-su
-cd "$DEPLOY_DIR"
-mkdir -p lib/release &>/dev/null
-mkdir -p lib/debug &>/dev/null
-[ -f /var/run/sshd.pid ] || /usr/sbin/sshd
-exit
-exit
-EOF
-
- sdb push "$__SCRIPT_PATH/device_envsetup.sh" $DEPLOY_DIR
-}
-
-__setup_enter_counter="0"
-
-__setup_enter() {
- if [ "$__setup_enter_counter" == "0" ]; then
- setupdevice
- fi
- let __setup_enter_counter=__setup_enter_counter+1
-}
-
-__setup_exit() {
- let __setup_enter_counter=__setup_enter_counter-1
-}
# Uses rsync which means faster reupload of libraries after recompilation as only the diff has to be uploaded.
usage() {
- echo "ERROR at $(caller)"
-
cat << EOF
usage: $0 (push|pull) src dst
-Preconditions:
- * sdb root should be on
- * /root/.ssh/authorized_keys should contain your public key
EOF
- exit
}
-[ "$#" == "3" ] || usage
+die() {
+ echo "ERROR at $1:$2"
+ usage
+ exit 1
+}
+
+trap 'die $0 $LINENO' ERR SIGINT SIGTERM SIGQUIT
+
+if echo "$@" | grep -Eqw "\-h|\-\-help"; then
+ usage
+ exit 0
+fi
+
+[ "$#" == "3" ]
src=$2
dst=$3
if [ "$1" == "push" ]; then
src=$(readlink -f $src)
- [ -f $src ] || usage
+ [ -f $src ]
elif [ "$1" == "pull" ]; then
# NOTE: dirname "" is .
- [ -d $(dirname "$dst") ] || usage
+ [ -d $(dirname "$dst") ]
else
- usage
+ false
fi
SCRIPT_PATH=$(readlink -f "$(dirname $0)")
USER=root
sdb start-server
+sdb root on >/dev/null
+sdb shell "change-booting-mode.sh --update" >/dev/null
-# Start sshd on device if not running
+# Start sshd on device if not running.
function startSSHD() {
sdb shell << EOF
-su
if [ ! -f "/var/run/sshd.pid" ]; then
- mkdir -m 700 /var/run/sshd &>/dev/null
- /usr/sbin/sshd
+ mkdir -m 700 /var/run/sshd &>/dev/null
+ /usr/sbin/sshd
fi
exit
-exit
EOF
}
startSSHD >/dev/null
-# Copy bundled rsync if not there yet.
-lscmd="ls /usr/local/bin/rsync 2>/dev/null"
-output=$(sdb shell "$lscmd")
-if [ -z "$output" ]; then
- PREBUILD_PATH=$(readlink -f $SCRIPT_PATH/../build/prebuild)
- sdb push "$PREBUILD_PATH/rsync" /usr/local/bin
+fileExistsOnDevice() {
+ lsout=$(sdb shell "ls $1 2>/dev/null")
+ ([ -n "$lsout" ] && echo 1) || echo 0
+}
+
+if [ "$(fileExistsOnDevice /root/.ssh/authorized_keys)" -eq 0 ]; then
+ echo "setting up /root/.ssh/authorized_keys"
+ sdb shell "mkdir /root/.ssh" &>/dev/null
+ sdb push "$HOME/.ssh/id_rsa.pub" "/root/.ssh/authorized_keys"
+fi
+if [ "$(fileExistsOnDevice /usr/local/bin/rsync)" -eq 0 ]; then
+ echo "installing rsync on device"
+ PREBUILD_PATH=$(readlink -f $SCRIPT_PATH/../build/prebuild)
+ sdb push "$PREBUILD_PATH/rsync" /usr/local/bin
fi
-# It looks like it's ok to do the forward multiple times.
-sdb forward tcp:$PORT tcp:22
-[ "$?" == "0" ] || (>&2 echo "error sdb port forward failed"; usage)
+# It's ok to do the forwarding multiple times.
+sdb forward tcp:$PORT tcp:22 || (\
+ >&2 echo "ERROR: sdb port forward failed"; \
+ >&2 echo "Hint: if you have /root/.ssh/authorized_keys file on your device make sure it contains your public key."; \
+ false)
do_rsync() {
- rsync -axzH -e "ssh -oStrictHostKeyChecking=no -p $PORT" $1 $2
+ rsync -axzH -e "ssh -oStrictHostKeyChecking=no -p $PORT" $1 $2
}
if [ "$1" == "push" ]; then