-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·109 lines (91 loc) · 3.1 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
#
# Copyright © 2020 Dmitry Yudin. All rights reserved.
# Licensed under the Apache License, Version 2.0
#
set -eu
dirScript=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
DIR_RUN_LOCAL=$dirScript
#
# Runnig ARM32 build on ARM64 host machine: https://askubuntu.com/questions/1090351/can-i-run-an-arm32-bit-app-on-an-arm64bit-platform-which-is-running-ubuntu-16-04
# dpkg --add-architecture armhf
# apt-get update
# apt-get install libc6:armhf libstdc++6:armhf
# cd /lib && ln -s arm-linux-gnueabihf/ld-2.23.so ld-linux.so.3
#
usage()
{
local targets=$("$dirScript/build.sh" --target list)
cat <<-EOT
Run application on a remote machine.
Usage:
$(basename $0) --app test --target <name> [opt]
$(basename $0) --app test index
Options:
-h|--help Print help
-t|--target <name> Remote target
-a|--app <name> Test to run
--local <path> 'run.local' file directory (default: <cmake-it>)
-- End of options list, pass the rest to test app
$targets
Target credentials are read from the local shell script 'run-ut.local'.
Usign SSH for Linux targets and ADB for Android.
EOT
}
entrypoint()
{
local target= app=
[[ $# == 0 ]] && usage && return 1
while [[ $# -gt 0 ]]; do
local nargs=2 end_of_options=
case $1 in
-h|--help) usage && return;;
-a|--app) app=$2;;
-t|--target) target=$2;;
--local) DIR_RUN_LOCAL=$2;;
[0-9]|[0-9][0-9]|[0-9][0-9][0-9]|a|aa|b|bb)
target=$("$dirScript/build.sh" $1 --demangle)
nargs=1
;;
--) end_of_options=1; nargs=1;;
*) error_exit "unrecognized option '$1'";;
esac
shift $nargs
[[ -n $end_of_options ]] && break
done
[[ -z "$target" ]] && error_exit "'--target' option not set"
[[ -z "$app" ]] && error_exit "no application selected selected"
[[ "$target" == list ]] && "$dirScript/build.sh" --target list && return
local prms_file=$DIR_RUN_LOCAL/run.local
if [[ -f "$prms_file" ]]; then
. "$prms_file"
else
error_exit "'$prms_file' not found"
fi
local remote=host
case $target in arm*) remote=ssh;; esac
case $target in *-ndk) remote=adb;; esac
# Do not build here since we do not know 'build.local' file location
# "$dirScript/build.sh" --target $target --app "$app"
local dirBin=$("$dirScript/build.sh" --target $target --app $app --print)
echo "[$remote] $dirBin/$app"
if [[ "$remote" == host ]]; then
"$dirBin/$app" "$@"
else
. "$dirScript/remote_target.sh"
TARGET_setTarget $remote "$prms_file"
TARGET_getExecDir; remoteDirBin=$REPLY;
TARGET_exec "mkdir -p '$remoteDirBin'"
TARGET_push "$dirBin/$app" "$remoteDirBin/$app"
TARGET_exec "
chmod +x '$remoteDirBin/$app'
'$remoteDirBin/$app' "$@"
"
fi
}
error_exit()
{
echo "error: $*" >&2
exit 1
}
entrypoint "$@"