Debian Codegraph @

scripts/jdg-generate-reprepro-codename

raw
1 #!/bin/bash
2
3 if [ -z ${JENKINS_DEBIAN_GLUE_QUIET:-} ]; then
4 set -x
5 fi
6 set -e
7
8 bailout() {
9 [ -n "${1:-}" ] && EXIT="${1}" || EXIT=0
10 [ -n "${2:-}" ] && echo "$2" >&2
11 rm -f /var/lock/jdg-generate-reprepro-codename."$(id -un)"
12 exit $EXIT
13 }
14
15 # backwards compatibility, see PR#94
16 if [ -z "${REPOSITORY:-}" ] ; then
17 repository_is_missing_in_env=true
18 else
19 repository_is_missing_in_env=false
20 fi
21
22 if [ -r /etc/jenkins/debian_glue ] ; then
23 echo "*** Sourcing /etc/jenkins/debian_glue ***"
24 . /etc/jenkins/debian_glue
25 fi
26
27 # backwards compatibility, see PR#94
28 if [ -n "${REPOSITORY:-}" ] && $repository_is_missing_in_env ; then
29 echo "*** WARNING: 'REPOSITORY' set in /etc/jenkins/debian_glue but should be DEFAULT_REPOSITORY ***"
30 echo "*** WARNING: Setting DEFAULT_REPOSITORY to $REPOSITORY for backwards compatibility ***"
31 echo "*** WARNING: Please replace REPOSITORY=... in /etc/jenkins/debian_glue with DEFAULT_REPOSITORY=... ***"
32 DEFAULT_REPOSITORY="${REPOSITORY}"
33 fi
34
35 if [ "${BUILD_ONLY:-}" = "true" ] ; then
36 echo "BUILD_ONLY is set to true, ignoring request to generate local repository."
37 exit 0
38 fi
39
40 ARCHITECTURES="${ARCHITECTURES:-amd64 i386 source}"
41 COMPONENTS="${COMPONENTS:-main}"
42 UDEB_COMPONENTS="${UDEB_COMPONENTS:-main}"
43
44 usage() {
45 echo "Usage: $0" \
46 "[ --architectures <architectures> ]" \
47 "[ --components <components> ]" \
48 "[ --udeb-components <udeb components> ]" \
49 "[ --origin <origin> ]" \
50 "[ --suite <suite> ]" \
51 "[ --label <label> ]" \
52 "[ --version <version> ]" \
53 "<codename>"
54 }
55
56
57 while [ "$#" -gt 1 ]; do
58 case "$1" in
59 --architectures)
60 ARCHITECTURES="$2"
61 shift 2
62 ;;
63 --components)
64 COMPONENTS="$2"
65 shift 2
66 ;;
67 --udeb-components)
68 UDEB_COMPONENTS="$2"
69 shift 2
70 ;;
71 --origin)
72 ORIGIN="$2"
73 shift 2
74 ;;
75 --suite)
76 SUITE="$2"
77 shift 2
78 ;;
79 --label)
80 LABEL="$2"
81 shift 2
82 ;;
83 --version)
84 VERSION="$2"
85 shift 2
86 ;;
87 --)
88 shift; break
89 ;;
90 *)
91 echo "Usage error." >&2
92 usage >&2
93 exit 1
94 ;;
95 esac
96 done
97
98 if [ "$#" -lt 1 ] ; then
99 usage >&2
100 exit 1
101 fi
102
103 # repository/codename that should be added
104 REPOS="$1"
105
106 JENKINS_DEBIAN_GLUE_VERSION=$(dpkg --list jenkins-debian-glue 2>/dev/null | awk '/^ii/ {print $3}')
107 if [ -n "${JENKINS_DEBIAN_GLUE_VERSION:-}" ] ; then
108 echo "*** Running jenkins-debian-glue version $JENKINS_DEBIAN_GLUE_VERSION ***"
109 fi
110
111 if [ -z "${DEFAULT_REPOSITORY:-}" ] ; then
112 echo "*** Repository variable DEFAULT_REPOSITORY is unset, using default [$DEFAULT_REPOSITORY] ***"
113 DEFAULT_REPOSITORY='/srv/repository'
114 fi
115
116 # REPOSITORY can overwrite DEFAULT_REPOSITORY, so define only if unset
117 if [ -z "${REPOSITORY:-}" ] ; then
118 REPOSITORY="${DEFAULT_REPOSITORY}"
119 echo "*** Repository variable REPOSITORY is unset, using default [$REPOSITORY] ***"
120 fi
121
122 if ! mkdir -p "${REPOSITORY}"/conf ; then
123 echo "Error creating ${REPOSITORY}/conf (forgot to create ${REPOSITORY} and chown jenkins?)" >&2
124 exit 1
125 fi
126
127 if ! chown $(id -un) "${REPOSITORY}"/conf ; then
128 echo "*** Warning: failed to adjust permissions of ${REPOSITORY}/conf ***"
129 echo "*** This might be caused by a remote FS like sshfs, so not failing the build. ***"
130 echo "*** Please fix the underlying problem if you depend on according permissions. ***"
131 fi
132 touch "${REPOSITORY}"/conf/distributions
133
134 # support setting key id
135 if [ -z "${KEY_ID:-}" ] ; then
136 echo "*** WARNING: No KEY_ID found, can not sign repository. ***"
137 echo "*** Generate a key executing 'gpg --gen-key' as user root"
138 echo "*** and then adjust /etc/jenkins/debian_glue."
139 fi
140
141 # lock access to file to avoid duplicate entries when two jdg-generate-reprepro-codename
142 # runs happen at the very same time
143 (
144 flock --timeout 5 9 || bailout 1 "Error: could not lock file ${REPOSITORY}/conf/distributions, giving up."
145
146 if grep -q "^\(Codename\|Suite\): ${REPOS}$" "${REPOSITORY}"/conf/distributions ; then
147 echo "Codename/repository $REPOS exists already, ignoring request to add again."
148 exit 0
149 fi
150
151 cat >> "${REPOSITORY}"/conf/distributions << EOF
152
153 Codename: ${REPOS}
154 Architectures: ${ARCHITECTURES}
155 Components: ${COMPONENTS}
156 EOF
157
158 if [ -n "${SUITE:-}" ]; then
159 printf "Suite: ${SUITE}\n" >> "${REPOSITORY}"/conf/distributions
160 fi
161
162 if [ -n "${LABEL:-}" ]; then
163 printf "Label: ${LABEL}\n" >> "${REPOSITORY}"/conf/distributions
164 fi
165
166 if [ -n "${VERSION:-}" ]; then
167 printf "Version: ${VERSION}\n" >> "${REPOSITORY}"/conf/distributions
168 fi
169
170 if [ -n "${ORIGIN:-}" ]; then
171 printf "Origin: ${ORIGIN}\n" >> "${REPOSITORY}"/conf/distributions
172 fi
173
174 if [ -n "${UDEB_COMPONENTS:-}" ]; then
175 printf "UDebComponents: ${UDEB_COMPONENTS}\n" >> "${REPOSITORY}"/conf/distributions
176 fi
177
178 printf "Tracking: minimal\n" >> "${REPOSITORY}"/conf/distributions
179
180 if [ -n "${KEY_ID:-}" ] ; then
181 echo "*** Signing repository with Key ID $KEY_ID ***"
182 printf "SignWith: ${KEY_ID}\n" >> "${REPOSITORY}"/conf/distributions
183 fi
184
185 echo "Added $REPOS as new codename/repos to the reprepro configuration."
186
187 ) 9>/var/lock/jdg-generate-reprepro-codename."$(id -un)" || bailout 1 "Error while generating reprepro codename/repos."
188
189 rm -f /var/lock/jdg-generate-reprepro-codename."$(id -un)"
190
191 # vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=2