-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·144 lines (125 loc) · 3.25 KB
/
entrypoint.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
#!/bin/bash
set -ef
GROUP=
group() {
endgroup
echo "::group:: $1"
GROUP=1
}
endgroup() {
if [ -n "$GROUP" ]; then
echo "::endgroup::"
fi
GROUP=
}
trap 'endgroup' ERR
group "bash setup.sh"
# snapshot containers don't ship with the ImageBuilder to save bandwidth
# run setup.sh to download and extract the ImageBuilder
[ ! -f setup.sh ] || bash setup.sh
endgroup
# rules
eval "$(grep CONFIG_TARGET_BOARD .config)"
eval "$(grep CONFIG_TARGET_SUBTARGET .config)"
[ -z "$(grep CONFIG_USE_APK .config)" ] || export USE_APK=y
export BOARD=$CONFIG_TARGET_BOARD
export SUBTARGET=$CONFIG_TARGET_SUBTARGET
export TOPDIR=$(pwd)
export OUTPUT_DIR=$TOPDIR/bin
export BIN_DIR=$OUTPUT_DIR/targets/$BOARD/$SUBTARGET
export SCRIPT_DIR=$TOPDIR/scripts
export OPKG_KEYS=$TOPDIR/keys
export BUILD_KEY=$TOPDIR/key-build
export BUILD_KEY_APK_SEC=$TOPDIR/keys/local-private-key.pem
export BUILD_KEY_APK_PUB=$TOPDIR/keys/local-public-key.pem
export STAGING_DIR_HOST=$TOPDIR/staging_dir/host
PATHBK="$PATH"
export PATH="$STAGING_DIR_HOST/bin:$PATH"
for d in bin; do
mkdir -p /artifacts/$d 2>/dev/null
ln -s /artifacts/$d $d
done
if [ -n "$KEY_BUILD" ]; then
if [ -z "$USE_APK" ]; then
echo "$KEY_BUILD" > $BUILD_KEY
else
echo "$KEY_BUILD" > $BUILD_KEY_APK_SEC
openssl ec -in $BUILD_KEY_APK_SEC -pubout > $BUILD_KEY_APK_PUB
ADD_LOCAL_KEY="1"
fi
SIGN="1"
fi
if [ -n "$KEY_BUILD_PUB" ]; then
if [ -z "$USE_APK" ]; then
echo "$KEY_BUILD_PUB" > $BUILD_KEY.pub
$SCRIPT_DIR/opkg-key add $BUILD_KEY.pub
fi
ADD_LOCAL_KEY="1"
fi
if [ -n "$KEY_VERIFY" ]; then
for _key in $KEY_VERIFY; do
base64 -d <<< "$_key" > /tmp/_key
if [ -z "$USE_APK" ]; then
$SCRIPT_DIR/opkg-key add /tmp/_key
else
cp -f /tmp/_key $OPKG_KEYS/$(md5sum /tmp/_key | awk '{print $1}').pem
fi
done
fi
group "ls -R $OPKG_KEYS"
ls -R $OPKG_KEYS
endgroup
if [ -n "$USE_APK" ]; then
n=$(sed -n '$=' repositories)
if [ -n "$NO_DEFAULT_REPOS" ]; then
sed -i 's|^http|# http|g' repositories
fi
if [ -z "$NO_LOCAL_REPOS" ]; then
sed -i "${n}a\\file:///repo/packages.adb" repositories
fi
for EXTRA_REPO in $EXTRA_REPOS; do
sed -i "${n}a\\$EXTRA_REPO" repositories
done
# in future
#if [ -n "$NO_SIGNATURE_CHECK" ]; then
# sed -i 's|^option check_signature|## option check_signature|' repositories
#fi
group "repositories"
cat repositories
endgroup
else # use opkg
regexp='src imagebuilder file:packages'
if [ -n "$NO_DEFAULT_REPOS" ]; then
sed -i 's|^src/gz|## src/gz|g' repositories.conf
fi
if [ -z "$NO_LOCAL_REPOS" ]; then
sed -i "/$regexp/i\\src custom file:///repo/" repositories.conf
fi
for EXTRA_REPO in $EXTRA_REPOS; do
sed -i "/$regexp/i\\$(tr '|' ' ' <<< "$EXTRA_REPO")" repositories.conf
done
if [ -n "$NO_SIGNATURE_CHECK" ]; then
sed -i 's|^option check_signature|## option check_signature|' repositories.conf
fi
group "repositories.conf"
cat repositories.conf
endgroup
fi
if [ -n "$ROOTFS_SIZE" ]; then
sed -i "s|\(\bCONFIG_TARGET_ROOTFS_PARTSIZE\)=.*|\1=$ROOTFS_SIZE|" .config
fi
RET=0
export PATH="$PATHBK"
make image \
PROFILE="$PROFILE" \
DISABLED_SERVICES="$DISABLED_SERVICES" \
ADD_LOCAL_KEY="$ADD_LOCAL_KEY" \
PACKAGES="$PACKAGES" || RET=$?
if [ "$SIGN" = '1' ];then
pushd $BIN_DIR
if [ -z "$USE_APK" ]; then
$STAGING_DIR_HOST/bin/usign -S -m sha256sums -s $BUILD_KEY # in future
fi
popd
fi
exit "$RET"