-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_medkit
executable file
·197 lines (183 loc) · 5.42 KB
/
generate_medkit
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
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# Turris medkit generator script
# (C) 2018-2020 CZ.NIC, z.s.p.o.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
src_dir="$(dirname "$(readlink -f "$0")")"
. "$src_dir/helpers/common.sh"
. "$src_dir/helpers/generate_common.sh"
. "$src_dir/defaults.sh"
export BOARD=
export BRANCH="$PUBLISH_BRANCH"
export UPDATER_BRANCH=
export L10N=cs,de
export LISTS=
export UPDATER_SCRIPT=
export OVERLAY=
export SIGN_KEY=
export OUTPUT=
export TESTKEY=
export TURRIS_BUILD_DIR="$src_dir"
## Parse arguments ##
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
echo "This script generates Turris medkit using updater-ng."
echo "Usage: $0 [OPTION].. [OUTPUT]"
echo
echo "Generated medkit is written to file at path OUTPUT. If no OUTPUT"
echo "is specified then the default format for used board is used."
echo "Warning: This script generates a lot of stuff to current working"
echo "directory. It is suggested to use some empty one not your home."
echo "Options:"
echo " --target, -t BOARD"
echo " Set given board as target for generated medkit. In default"
echo " if this options is not specified omnia is used. Allowed"
echo " values are: turris1x, omnia, mox"
echo " --branch, -b BRANCH"
echo " Set given branch as source for packages used to generate "
echo " this medkit. If this option is not set then 'hbl' is used."
echo " Note that this does not sets that branch to updater-ng"
echo " configuration. You have to use --updater-branch for that."
echo " --updater-branch BRANCH"
echo " Set target branch inside medkit for updater-ng."
# TODO maybe add version specification for future out of build use.
echo " --localization, -l LOCALIZATION,.."
echo " After this argument a list of language codes to be added to"
echo " medkit should be specified. Language codes should be"
echo " separated by comma. In default cs,de is used."
echo " --lists, -p PKGLIST,.."
echo " What lists should be added to medkit. In default no"
echo " additional lists will be added. Multiple lists can be"
echo " specified by separating them by commas."
echo " --updater-script FILE"
echo " Run file as updater's script. It is executed after primary"
echo " entry script of this tool."
echo " --overlay PATH"
echo " This allows you to overwrite or add some files to medkit."
echo " PATH is expected to be directory and whole content is copied"
echo " to newly generated root. This is handy if you want to change"
echo " some default settings for example."
echo " --sign KEY"
echo " Sign medkit with given KEY and usign utility"
echo " --help, -h"
echo " Print this text and exit."
exit 0
;;
--target|-t)
shift
BOARD="$1"
;;
--branch|-b)
shift
BRANCH="$1"
;;
--updater-branch)
shift
UPDATER_BRANCH="$1"
TESTKEY=y
;;
--localization|-l)
shift
L10N="$1"
;;
--lists|-p)
shift
LISTS="$1"
;;
--updater-script)
shift
UPDATER_SCRIPT="$1"
;;
--overlay)
shift
OVERLAY="$1"
;;
--sign)
shift
SIGN_KEY="$1"
;;
*)
if [ -z "$OUTPUT" ]; then
OUTPUT="$1"
else
echo "Unknown option: $1" >&2
exit 1
fi
;;
esac
shift
done
[ -n "$BOARD" ] || die "You have to specify target Turris router."
[ -n "$OUTPUT" ] || {
case "$BOARD" in
mox)
OUTPUT=mox-medkit.tar.gz
;;
omnia)
OUTPUT=omnia-medkit.tar.gz
;;
turris1x)
OUTPUT=turris-medkit.tar.gz
;;
esac
}
OUTPUT="$(readlink -f "$OUTPUT")"
updater_ng_repodetect "$BRANCH" "$BOARD"
get_usign
get_updater_ng
export PATH="$PATH:$(dirname "$USIGN")"
## Generate root ##
exec fakeroot -- /bin/bash -s <<EOF
set -e
mkdir -p root
## Create base filesystem for updater
ln -sf tmp root/var
# Create lock required by updater
mkdir -p root/tmp/lock
# Create opkg status file and info file
mkdir -p root/usr/lib/opkg/info
touch root/usr/lib/opkg/status
## Run updater it self
"\$PKGUPDATE" \
-R "$(pwd)"/root --out-of-root --batch \
"file://\$TURRIS_BUILD_DIR/helpers/medkit-updater-ng.lua"
## Generate /etc/config/updater
m4args=()
[ -z "\$UPDATER_BRANCH" ] || m4args+=("-D_BRANCH_='\$UPDATER_BRANCH'")
[ -z "\$LISTS" ] || m4args+=("-D_LISTS_='\$LISTS'")
[ -z "\$L10N" ] || m4args+=("-D_LANGS_=\$L10N")
m4 "\${m4args[@]}" "\$TURRIS_BUILD_DIR/helpers/medkit-updater-ng-config.m4" > root/etc/config/updater
## Overlay user's files
if [ -n "\$OVERLAY" ]; then
cp -a "\$OVERLAY/." root/
fi
## Root cleanups
rm -f root/var/lock/opkg.lock
rm -f root/usr/share/updater/flags
rm -rf root/usr/share/updater/unpacked
rm -rf root/var/opkg-collided
## Tar root
(
cd root
# Create archive
tar -czf "\$OUTPUT" .
)
md5sum "\$OUTPUT" | sed 's| /.*/| |' > "\$OUTPUT.md5"
sha256sum "\$OUTPUT" | sed 's| /.*/| |' > "\$OUTPUT.sha256"
[ -z "\$SIGN_KEY" ] || "\$USIGN" -S -m "\$OUTPUT" -s "\$SIGN_KEY"
## Cleanup
rm -rf root
EOF