forked from LibreELEC/LibreELEC.tv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_docker_package
executable file
·184 lines (157 loc) · 4.08 KB
/
create_docker_package
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/sh
FIRST_LABEL=30002
LABEL_DEVICE="D"
LABEL_ENV="E_"
LABEL_PORT="P_"
LABEL_VOLUME="V"
STRING_DEVICE="-d "
STRING_ENV="-e "
STRING_PORT="-p "
STRING_VOLUME="-v "
add_default() {
defaults="${defaults} <setting id=\"${1}\" value=\"${2}\" />\n"
}
add_device() {
add_label
default="${1%:*}"
docker="${1#*:}"
id="${LABEL_DEVICE}${docker//\//_}"
add_default "${id}" "${default}"
add_option "--device=\"\$${id}\""
add_setting "<setting label=\"${label}\" type=\"folder\" id=\"${id}\" default=\"${default}\" />"
add_string "${STRING_DEVICE}${docker}"
}
add_env() {
add_label
default="${1#*=}"
docker="${1%%=*}"
id="${LABEL_ENV}${docker}"
add_default "${id}" "${default}"
add_option "-e ${docker}=\"${id}\""
add_setting "<setting label=\"${label}\" type=\"text\" id=\"${id}\" default=\"${default}\" />"
add_string "${STRING_ENV}${docker}"
}
add_label() {
if [ -z ${label} ]; then
label=${FIRST_LABEL}
else
label=$((label+1))
fi
}
add_option() {
if [ ! -z "${options}" ]; then
options="${options} "'\\\n'
fi
options="${options} ${1}"
}
add_port() {
add_label
default="${1%:*}"
docker="${1#*:}"
port="${docker%/*}"
id="${LABEL_PORT}${port}"
add_default "${id}" "${default}"
add_option "-p \"\$${id}\":${docker}"
add_setting "<setting label=\"${label}\" type=\"number\" id=\"${id}\" default=\"${default}\" />"
add_string "${STRING_PORT}${port}"
}
add_setting() {
settings="${settings} ${1}\n"
}
add_string() {
strings="${strings}\nmsgctxt \"${label}\"\nmsgid \"${1}\"\nmsgstr \"\"\n"
}
add_volume() {
add_label
default="${1%:*}"
docker="${1#*:}"
id="${LABEL_VOLUME}${docker//\//_}"
add_default "${id}" "${default}"
add_option "-v \"\$${id}\":${docker}"
add_setting "<setting label=\"${label}\" type=\"folder\" id=\"${id}\" default=\"${default}\" />"
add_string "${STRING_VOLUME}${docker}"
}
case "${ARCH}" in
arm)
projects="imx6 RPi RPi2"
;;
x86_64)
projects="Generic"
;;
*)
echo "Unkown project"
exit 1
;;
esac
while [[ $# -gt 0 ]]; do
option="${1}"
shift
case "${option}" in
--device=*)
add_device "${option#--device=}"
;;
--name=*)
;;
--port=*)
add_port "${option#--port=}"
;;
--volume=*)
add_volume "${option#--volume=}"
;;
-e)
add_env "${1}"
shift
;;
-p)
add_port "${1}"
shift
;;
-v)
add_volume "${1}"
shift
;;
-*)
add_option "${option}"
;;
*/*)
add_option "${option}"
image="${option%:*}"
version="${option#*:}"
if [ "${version}" = "${option}" ]; then
version="latest"
fi
if [ ! -z "$*" ]; then
add_option "$*"
fi
break
;;
*)
add_option "${option}"
;;
esac
done
if [ -z "${image}" ]; then
echo "Failed to parse image"
exit 1
fi
name="${image//\//.}"
dir="packages/addons/docker/${name}"
if [ -d "${dir}" ]; then
echo "Package already exists"
exit 1
fi
cp -R config/docker "${dir}"
sed -e "s|@NAME@|${name}|g" \
-e "s|@VERSION@|${version}|g" \
-e "s|@ARCH@|${arch}|g" \
-e "s|@IMAGE@|${image}|g" \
-e "s|@PROJECTS@|${projects}|g" \
-i "${dir}/package.mk"
defaults="$(echo -en "${defaults}" | sort)"
echo -en "<settings>\n${defaults}\n</settings>" > "${dir}/source/settings-default.xml"
echo -en "${options}" >> "${dir}/source/bin/docker"
sed -e "s|@SETTINGS@|${settings}|g" \
-i "${dir}/source/resources/settings.xml"
echo -en "${strings}" >> "${dir}/source/resources/language/English/strings.po"
mv "${dir}/source/bin/docker" "${dir}/source/bin/docker.${name}"
mv "${dir}/source/system.d/docker.service" "${dir}/source/system.d/docker.${name}.service"