-
Notifications
You must be signed in to change notification settings - Fork 2
/
publish-debs
executable file
·199 lines (176 loc) · 7.07 KB
/
publish-debs
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
#!/bin/bash
# Usage: publish-debs deb-directory area version repo
usage() {
echo "Usage: $(basename $0) input area version repo"
echo
echo input example: /nobackup/tim/externals/9.1
echo area examples: public private security test
echo version examples: 8.8.2, 8.9.1
echo repo examples: snapshot, daily, alpha, rc, beta, update, release
}
confirm=1
if [ $# -ge 1 -a "$1" = "-y" ]; then
confirm=0
shift
fi
if [ $# -ne 4 ]; then
usage
exit 1
fi
input=$1
area=$2
version=$3
repo=$4
if [ ! -d $1 ]; then
echo ERROR: no directory: $1
usage
exit 1
fi
echo "Input: ${input} Area: ${area}, Version: ${version}, Repo: ${repo}"
if [ $confirm -eq 1 ]; then
read -p "Continue? [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
else
echo
fi
. $(dirname $0)/common.sh
aptly="/nobackup/tim/bin/aptly -config=$(dirname $0)/aptly${suffix}.conf"
# Update Debian/Ubuntu repositories
drop_deb_publish () {
distro=$1
code_name=$2
if ${aptly} publish show $code_name $distro/$deb_repo_name > /dev/null 2>&1; then
echo "======= Dropping publish ${deb_repo_name} $distro $code_name ======="
${aptly} publish drop $code_name $distro/$deb_repo_name
fi
}
drop_deb_repo () {
distro=$1
code_name=$2
if ${aptly} repo show $deb_repo_name-$code_name > /dev/null 2>&1; then
echo "======= Dropping repo ${deb_repo_name} $distro $code_name ======="
${aptly} repo drop $deb_repo_name-$code_name
fi
}
update_deb_repo_and_publish () {
platform_name=$1
distro=$2
code_name=$3
arch=$4
aptly_arch="${aptly} -architectures=${arch}"
if ! ${aptly_arch} repo show $deb_repo_name-$code_name > /dev/null 2>&1; then
echo "======= Creating repo ${deb_repo_name} $distro $code_name ======="
${aptly_arch} repo create -distribution=$code_name $deb_repo_name-$code_name
fi
echo "======= Adding packages to repo ${deb_repo_name} $distro $code_name ======="
${aptly_arch} repo add $deb_repo_name-$code_name ${input}/${platform_name}
# Be sure to add the necessary externals
if [ -d /nobackup/tim/externals/${repo_version}/${platform_name} ]; then
echo "======= Adding external packages to repo ${deb_repo_name} $distro $code_name ======="
${aptly_arch} repo add $deb_repo_name-$code_name /nobackup/tim/externals/${repo_version}/${platform_name}
else
echo "WARNING: No externals to add to repository"
fi
if ${aptly_arch} publish show $code_name $distro/$deb_repo_name > /dev/null 2>&1; then
echo "======= Updating publish ${deb_repo_name} $distro $code_name ======="
${aptly_arch} publish update -gpg-key=$key $code_name $distro/$deb_repo_name
else
echo "======= Publishing repo ${deb_repo_name} $distro $code_name ======="
${aptly_arch} publish repo -gpg-key=$key $deb_repo_name-$code_name $distro/$deb_repo_name
fi
}
echo ======= Updating ${repository} =======
pushd $input
# Be sure amd64 packages take precendence
dirs=$(echo x86_64_* ppc64le_*)
popd
deb_repo_name=${repo_version}
if [ $repo != 'release' ]; then
deb_repo_name=${deb_repo_name}-${repo}
fi
# Always drop the publish
# Because you cannot add new CPU architectures to existing publishes
for dir in $dirs; do
if [ $dir = 'x86_64_Debian9' ]; then
drop_deb_publish "debian" "stretch"
elif [ $dir = 'x86_64_Debian10' ]; then
drop_deb_publish "debian" "buster"
elif [ $dir = 'x86_64_Debian11' ]; then
drop_deb_publish "debian" "bullseye"
elif [ $dir = 'x86_64_Debian12' ]; then
drop_deb_publish "debian" "bookworm"
elif [ $dir = 'x86_64_Ubuntu18' ]; then
drop_deb_publish "ubuntu" "bionic"
elif [ $dir = 'x86_64_Ubuntu20' ]; then
drop_deb_publish "ubuntu" "focal"
elif [ $dir = 'ppc64le_Ubuntu20' ]; then
drop_deb_publish "ubuntu" "focal"
elif [ $dir = 'x86_64_Ubuntu22' ]; then
drop_deb_publish "ubuntu" "jammy"
elif [ $dir = 'x86_64_Ubuntu24' ]; then
drop_deb_publish "ubuntu" "noble"
fi
done
# Drop old repos for snapshot and rc builds
# Because the souce tarball changes with a fixed version number
if [ $repo != 'release' ]; then
for dir in $dirs; do
if [ $dir = 'x86_64_Debian9' ]; then
drop_deb_repo "debian" "stretch"
elif [ $dir = 'x86_64_Debian10' ]; then
drop_deb_repo "debian" "buster"
elif [ $dir = 'x86_64_Debian11' ]; then
drop_deb_repo "debian" "bullseye"
elif [ $dir = 'x86_64_Debian12' ]; then
drop_deb_repo "debian" "bookworm"
elif [ $dir = 'x86_64_Ubuntu18' ]; then
drop_deb_repo "ubuntu" "bionic"
elif [ $dir = 'x86_64_Ubuntu20' ]; then
drop_deb_repo "ubuntu" "focal"
elif [ $dir = 'ppc64le_Ubuntu20' ]; then
drop_deb_repo "ubuntu" "focal"
elif [ $dir = 'x86_64_Ubuntu22' ]; then
drop_deb_repo "ubuntu" "jammy"
elif [ $dir = 'x86_64_Ubuntu24' ]; then
drop_deb_repo "ubuntu" "noble"
fi
done
${aptly} db cleanup
fi
# Publish new packages
for dir in $dirs; do
if [ $dir = 'x86_64_Debian9' ]; then
update_deb_repo_and_publish "x86_64_Debian9" "debian" "stretch" "amd64,source"
elif [ $dir = 'x86_64_Debian10' ]; then
update_deb_repo_and_publish "x86_64_Debian10" "debian" "buster" "amd64,source"
elif [ $dir = 'x86_64_Debian11' ]; then
update_deb_repo_and_publish "x86_64_Debian11" "debian" "bullseye" "amd64,source"
elif [ $dir = 'x86_64_Debian12' ]; then
update_deb_repo_and_publish "x86_64_Debian12" "debian" "bookworm" "amd64,source"
elif [ $dir = 'x86_64_Ubuntu18' ]; then
update_deb_repo_and_publish "x86_64_Ubuntu18" "ubuntu" "bionic" "amd64,source"
elif [ $dir = 'x86_64_Ubuntu20' ]; then
update_deb_repo_and_publish "x86_64_Ubuntu20" "ubuntu" "focal" "amd64,ppc64el,source"
elif [ $dir = 'ppc64le_Ubuntu20' ]; then
update_deb_repo_and_publish "ppc64le_Ubuntu20" "ubuntu" "focal" "amd64,ppc64el,source"
elif [ $dir = 'x86_64_Ubuntu22' ]; then
update_deb_repo_and_publish "x86_64_Ubuntu22" "ubuntu" "jammy" "amd64,source"
elif [ $dir = 'x86_64_Ubuntu24' ]; then
update_deb_repo_and_publish "x86_64_Ubuntu24" "ubuntu" "noble" "amd64,source"
fi
done
# Rsync up to the web server
for distro in 'debian' 'ubuntu'; do
echo "======= Updating ${repository}/${distro}/${deb_repo_name} ======="
mkdir -p ${repository}/${distro}/${deb_repo_name}
# Put the new files in the pool
rsync -rlotv /nobackup/tim/aptly${suffix}/public/${distro}/${deb_repo_name}/pool ${repository}/${distro}/${deb_repo_name}/
# Update the dists to point to the new files
rsync -rlotv /nobackup/tim/aptly${suffix}/public/${distro}/${deb_repo_name}/dists ${repository}/${distro}/${deb_repo_name}/
# Delete any old files
rsync -rlotv --delete /nobackup/tim/aptly${suffix}/public/${distro}/${deb_repo_name}/* ${repository}/${distro}/${deb_repo_name}/
done