-
Notifications
You must be signed in to change notification settings - Fork 83
/
publish.sh
executable file
·205 lines (171 loc) · 4.47 KB
/
publish.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
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
198
199
200
201
202
203
204
205
#!/bin/bash
set -euxo pipefail
: "${AGENT_WORKDIR:=/tmp}"
: "${GPG_KEYNAME:?Require valid gpg keyname}"
: "${DEB:?Require Debian package}"
: "${DEBDIR:? Require where to put binary files}"
: "${DEB_WEBDIR:? Require where to put repository index and other web contents}"
: "${DEB_URL:? Require Debian repository Url}"
# $$ Contains current pid
D="$AGENT_WORKDIR/$$"
# Convert string to array to correctly escape cli parameter
SSH_OPTS=($SSH_OPTS)
bin="$(dirname "$0")"
function clean() {
rm -rf "$D"
}
# Generate and publish site content
function generateSite() {
cp -R "$bin/contents/." "$D/contents"
gpg --export -a --output "$D/contents/${ORGANIZATION}.key" "${GPG_KEYNAME}"
echo "$(gpg --import-options show-only --import $D/contents/${ORGANIZATION}.key)" >"$D/contents/${ORGANIZATION}.key.info"
"$BASE/bin/indexGenerator.py" \
--distribution debian \
--gpg-key-info-file "${D}/contents/${ORGANIZATION}.key.info" \
--targetDir "$D/html"
"$BASE/bin/branding.py" "$D"
# build package index
# see http://wiki.debian.org/SecureApt for more details
cp "${DEB}" "$D/binary/"
pushd "$D"
apt-ftparchive packages binary >binary/Packages
apt-ftparchive contents binary >binary/Contents
popd
# Remote ftparchive-merge
# https://github.com/kohsuke/apt-ftparchive-merge
pushd $D/binary
mvn -V org.kohsuke:apt-ftparchive-merge:1.6:merge -Durl="$DEB_URL/binary/" -Dout=../merged
popd
# Local ftparchive-merge
cat $D/merged/Packages >$D/binary/Packages
gzip -9c "$D/merged/Packages" >"$D/binary/Packages.gz"
bzip2 -c "$D/merged/Packages" >"$D/binary/Packages.bz2"
lzma -c "$D/merged/Packages" >"$D/binary/Packages.lzma"
gzip -9c "$D/merged/Contents" >"$D/binary/Contents.gz"
apt-ftparchive -c "$bin/release.conf" release "$D/binary" >"$D/binary/Release"
}
function init() {
mkdir -p "$D/binary" "$D/contents" "$D/html"
# where to put binary files
mkdir -p "$DEBDIR" # where to put binary files
# where to put repository index and other web contents
mkdir -p "$DEB_WEBDIR"
## On remote serve
# shellcheck disable=SC2029
ssh "${SSH_OPTS[@]}" "$PKGSERVER" mkdir -p "$DEBDIR/"
}
function skipIfAlreadyPublished() {
if ssh "${SSH_OPTS[@]}" "$PKGSERVER" test -e "${DEBDIR}/$(basename "$DEB")"; then
echo "File already published, nothing else todo"
return 0
fi
return 1
}
# Upload Debian Package
function uploadPackage() {
rsync \
--verbose \
--recursive \
--compress \
--ignore-existing \
--progress \
"$DEB" "$DEBDIR/"
rsync \
--archive \
--verbose \
--compress \
--ignore-existing \
--progress \
-e "ssh ${SSH_OPTS[*]}" \
"${DEB}" "$PKGSERVER:${DEBDIR// /\\ }"
}
function uploadPackageSite() {
cp \
"$D"/binary/Packages* \
"$D"/binary/Release \
"$D"/binary/Release.gpg \
"$D"/binary/Contents* \
"$D"/contents/binary
rsync \
--verbose \
--recursive \
--compress \
--progress \
"$D/contents/" "$DEB_WEBDIR/"
rsync \
--archive \
--compress \
--progress \
--verbose \
-e "ssh ${SSH_OPTS[*]}" \
"$D/contents/" "$PKGSERVER:${DEB_WEBDIR// /\\ }/"
}
function uploadHtmlSite() {
# Html file need to be located in the binary directory
rsync \
--include "HEADER.html" \
--include "FOOTER.html" \
--exclude "*" \
--compress \
--recursive \
--progress \
--verbose \
"$D/html/" "$DEBDIR/"
rsync \
--archive \
--compress \
--include "index.html" \
--exclude "*" \
--progress \
--verbose \
-e "ssh ${SSH_OPTS[*]}" \
"$D/html/" "$PKGSERVER:${DEB_WEBDIR// /\\ }/"
rsync \
--archive \
--compress \
--include "HEADER.html" \
--include "FOOTER.html" \
--exclude "*" \
--progress \
--verbose \
-e "ssh ${SSH_OPTS[*]}" \
"$D/html/" "$PKGSERVER:${DEBDIR// /\\ }/"
}
function show() {
echo "Parameters:"
echo "DEB: $DEB"
echo "DEBDIR: $DEBDIR"
echo "DEB_WEBDIR: $DEB_WEBDIR"
echo "SSH_OPTS: ${SSH_OPTS[*]}"
echo "PKGSERVER: $PKGSERVER"
echo "GPG_KEYNAME: $GPG_KEYNAME"
echo "---"
}
function signSite() {
# sign the release file
if [ -f "$D/binary/Release.gpg" ]; then
rm "$D/binary/Release.gpg"
fi
gpg \
--batch \
--pinentry-mode loopback \
--digest-algo=sha256 \
-u "$GPG_KEYNAME" \
--passphrase-file "$GPG_PASSPHRASE_FILE" \
-abs \
-o "$D/binary/Release.gpg" \
"$D/binary/Release"
}
show
## Disabling this function allow us to recreate and sign the repository.
# the debian package won't be overrided as we use the parameter '--ignore-existing'
#skipIfAlreadyPublished
init
generateSite
signSite
if ! skipIfAlreadyPublished; then
uploadPackage
uploadPackageSite
fi
uploadHtmlSite
clean