-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
run.sh
executable file
·153 lines (125 loc) · 3.17 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
# -*- coding: utf-8 -*-
#{
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/ .
#}
set -e
set -x
env_()
{
project="generic-sensors-webthings"
org="rzr"
branch="master"
url_suffix="#{branch}"
# user="rzr" # Update here if forking
# org="TizenTeam"
# branch="sandbox/${user}/${branch}"
# url_suffix="#{branch}"
url_suffix="" # TODO: For older docker
url="https://github.com/${org}/${project}.git${url_suffix}"
run_url="https://raw.githubusercontent.com/${org}/${project}/${branch}/run.sh"
release="0.0.0"
src=false
if [ -d '.git' ] && which git > /dev/null 2>&1 ; then
src=true
branch=$(git rev-parse --abbrev-ref HEAD) ||:
release=$(git describe --tags || echo "$release")
fi
SELF="$0"
[ "$SELF" != "$SHELL" ] || SELF="${PWD}/run.sh"
[ "$SELF" != "/bin/bash" ] || SELF="${DASH_SOURCE}"
[ "$SELF" != "/bin/bash" ] || SELF="${BASH_SOURCE}"
self_basename=$(basename -- "${SELF}")
}
usage_()
{
cat<<EOF
Usage:
$0
or
curl -sL "${run_url}" | bash -
EOF
}
die_()
{
errno=$?
echo "error: [$errno] $@"
exit $errno
}
setup_debian_()
{
which git || sudo apt-get install git
which docker || sudo apt-get install docker.io
sudo apt-get install qemu qemu-user-static binfmt-support
sudo update-binfmts --enable qemu-arm
}
setup_()
{
docker version && return $? ||:
if [ -r /etc/debian_version ] ; then
setup_debian_
else
cat<<EOF
warning: OS not supported
Please ask for support at:
${url}
EOF
cat /etc/os-release ||:
fi
docker version && return $? ||:
docker --version || die_ "please install docker"
groups | grep docker \
|| sudo addgroup ${USER} docker \
|| die_ "${USER} must be in docker group"
su -l $USER -c "docker version" \
&& { su -l $USER -c "$SHELL $SELF $@" ; exit $?; } \
|| die_ "unexpected error"
}
prep_()
{
echo "Prepare: "
cat /etc/os-release
docker version || setup_
}
build_()
{
version="latest"
outdir="${PWD}/tmp/out"
container="${project}"
branch_name=$(echo "${branch}" | sed -e 's|/|.|g')
dir="/usr/local/src/${project}/"
image="${user}/${project}/${branch}"
tag="$image:${version}"
tag="${org}/${project}:${branch_name}"
tag="${org}/${project}:${branch_name}.${release}"
tag=$(echo "${tag}" | tr [A-Z] [a-z])
container="${project}"
container=$(echo "${container}" | sed -e 's|/|-|g')
if $src && [ "run.sh" = "${self_basename}" ] ; then
docker build -t "${tag}" .
else
docker build -t "${tag}" "${url}"
fi
docker rm "${container}" > /dev/null 2>&1 ||:
docker create --name "${container}" "${tag}" /bin/true
rm -rf "${outdir}"
mkdir -p "${outdir}"
docker cp "${container}:${dir}" "${outdir}"
echo "Check Ouput files in:"
ls "${outdir}/"*
find "${outdir}" -iname "*.tgz"
}
test_()
{
curl -sL "${run_url}" | bash -
}
main_()
{
env_ "$@"
usage_ "$@"
prep_ "$@"
build_ "$@"
}
main_ "$@"