43424902665b37b49fd1260cba2e77e833f54ddc
[mirror/dsa-puppet.git] / modules / schroot / files / schroot-setup.d / 99builddsourceslist
1 #!/bin/bash
2
3 ##
4 ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
5 ## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
6 ##
7
8 # vim:set et ts=4 sw=4:
9 # Copyright © 2010 Marc Brockschmidt <he@debian.org>
10 # Copyright © 2010 Andreas Barth <aba@not.so.argh.org>
11 # Copyright © 2010 Philipp Kern <pkern@debian.org>
12 #
13 # buildd is free software: you can redistribute it and/or modify it
14 # under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 2 of the License, or
16 # (at your option) any later version.
17 #
18 # buildd is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 # General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program.  If not, see
25 # <http://www.gnu.org/licenses/>.
26 #
27 #####################################################################
28
29 set -e
30 shopt -s extglob
31
32 [ "$CHROOT_PROFILE" = "buildd" ] || exit 0
33
34 . "$SETUP_DATA_DIR/common-data"
35 . "$SETUP_DATA_DIR/common-functions"
36 . "$SETUP_DATA_DIR/common-config"
37
38 # The test below tries to determine if a source chroot is being used.
39 # The apt configuration is generated only for non-source chroots.
40 #
41 # It originally tested CHROOT_SESSION_PURGE, but while it works for
42 # LVM based chroots, it doesn't for tar based chroots which always
43 # needed to be purged.
44 #
45 # Future versions of schroot will implement CHROOT_SESSION_SOURCE for
46 # a more robust way to check for source chroots.
47 #
48 # See bug#718127 for more details.
49 if ! echo "$CHROOT_DESCRIPTION" | grep -q '(source chroot)' ; then
50     CHROOT_ALIAS="${CHROOT_ALIAS/#experimental-/sid-experimental-}"
51     case $CHROOT_ALIAS in
52         +([^-])-kfreebsd-+([^-])-kfreebsd-*-sbuild*)
53         SUITE_BASE=$(echo $CHROOT_ALIAS | cut -f1-2 -d-)
54         SUITE_VARIANT=$(echo $CHROOT_ALIAS | cut -f3 -d-)
55         ;;
56         +([^-])-kfreebsd-kfreebsd-*-sbuild*)
57         SUITE_BASE=$(echo $CHROOT_ALIAS | cut -f1-2 -d-)
58         if [ ${SUITE_BASE} != "sid" ]; then
59             SUITE_VARIANT="proposed-updates"
60         fi
61         ;;
62         +([^-])-+([^-])-@(kfreebsd|hurd)-*-sbuild*)
63         SUITE_BASE=$(echo $CHROOT_ALIAS | cut -f1 -d-)
64         SUITE_VARIANT=$(echo $CHROOT_ALIAS | cut -f2 -d-)
65         ;;
66         *-*-*-*-sbuild*)
67         SUITE_BASE=$(echo $CHROOT_ALIAS | cut -f1 -d-)
68         SUITE_VARIANT=$(echo $CHROOT_ALIAS | cut -f2,3 -d-)
69         ;;
70         +([^-])-@(kfreebsd|hurd)-*-sbuild*)
71         SUITE_BASE=$(echo $CHROOT_ALIAS | cut -f1 -d-)
72         if [ ${SUITE_BASE} != "sid" ]; then
73             SUITE_VARIANT="proposed-updates"
74         fi
75         ;;
76         *-*-*-sbuild*)
77         SUITE_BASE=$(echo $CHROOT_ALIAS | cut -f1 -d-)
78         SUITE_VARIANT=$(echo $CHROOT_ALIAS | cut -f2 -d-)
79         ;;
80         *-*-sbuild*)
81         SUITE_BASE=$(echo $CHROOT_ALIAS | cut -f1 -d-)
82         if [ ${SUITE_BASE} != "sid" ]; then
83             SUITE_VARIANT="proposed-updates"
84         fi
85         ;;
86     esac
87 fi
88
89 VERBOSE=""
90 if [ "$AUTH_VERBOSITY" = "verbose" ]; then
91       VERBOSE="--verbose"
92 fi
93
94 if [ -f /etc/schroot/dsa/default-mirror ]; then
95     debian_mirror=$(cat /etc/schroot/dsa/default-mirror)
96 elif [ -f /etc/schroot/conf.buildd ]; then
97     . /etc/schroot/conf.buildd
98 fi
99
100 function domirror() {
101     for SUITE in ${SUITES:-SUITE}; do
102         echo deb $1     | sed -e "s,COMPONENT,${COMPONENT},"     -e "s,SUITE,${SUITE}," >> $2
103         echo deb-src $1 | sed -e "s,COMPONENT,${COMPONENT_SRC}," -e "s,SUITE,${SUITE}," >> $2
104     done
105 }
106
107 if [ "$1" = "setup-start" ] || [ "$1" = "setup-recover" ]; then
108     if [ -n "${SUITE_BASE}" ] && ( [ -f /etc/schroot/conf.buildd ] || [ -f /etc/schroot/dsa/default-mirror ] ); then
109         APT_LIST="${CHROOT_PATH}/etc/apt/sources.buildd.list"
110         APT_CONF="${CHROOT_PATH}/etc/apt/apt.conf.d/99buildd.conf"
111         APT_KEYS=""
112         rm -f "${APT_LIST}" "${APT_CONF}"
113
114         COMPONENT="main contrib"
115         COMPONENT_SRC="main contrib non-free"
116
117         if [ "${SUITE_VARIANT}" = 'proposed-updates' ]; then
118             SUITES="${SUITE_BASE} ${SUITE_BASE}-proposed-updates"
119             [ -n "${debian_mirror}" ] && domirror "${debian_mirror} SUITE COMPONENT" ${APT_LIST}
120             domirror "http://ftp.debian.org/debian SUITE COMPONENT" ${APT_LIST}
121             if [ "${debian_incoming}" != 'no' ]; then
122                 SUITES="${SUITE_BASE}-proposed-updates"
123                 domirror "http://incoming.debian.org/debian-buildd buildd-SUITE COMPONENT" ${APT_LIST}
124             fi
125
126         elif [ "${SUITE_VARIANT}" = 'lts' ]; then
127             SUITES="${SUITE_BASE} ${SUITE_BASE}-lts"
128             [ -n "${debian_mirror}" ] && domirror "${debian_mirror} SUITE COMPONENT" ${APT_LIST}
129             domirror "http://ftp.debian.org/debian SUITE COMPONENT" ${APT_LIST}
130             if [ "${debian_incoming}" != 'no' ]; then
131                 SUITES="${SUITE_BASE}-lts"
132                 domirror "http://incoming.debian.org/debian-buildd buildd-SUITE COMPONENT" ${APT_LIST}
133             fi
134
135         elif [ "${SUITE_VARIANT}" = 'security' ]; then
136             SUITES="${SUITE_BASE}"
137             [ -n "${debian_mirror}" ] && domirror "${debian_mirror} ${SUITE_BASE} COMPONENT" ${APT_LIST}
138             domirror "http://ftp.debian.org/debian ${SUITE_BASE} COMPONENT" ${APT_LIST}
139             [ -n "${security_mirror}" ] && domirror "${security_mirror} ${SUITE_BASE}/updates COMPONENT" ${APT_LIST}
140             domirror "https://security-master.debian.org/debian-security ${SUITE_BASE}/updates COMPONENT" ${APT_LIST}
141             domirror "https://security-master.debian.org/debian-security-buildd buildd-${SUITE_BASE}/updates COMPONENT" ${APT_LIST}
142
143             # Temporarily add stretch-proposed-updates for stretch-security chroots as requested
144             # by the security team to handle Thunderbird and Firefox ESR 60.x releases. This should
145             # be removed with the release of the 9.5 point release.
146             if [ ${SUITE_BASE} = "stretch" ] ; then
147                 SUITES="${SUITE_BASE}-proposed-updates"
148                 [ -n "${debian_mirror}" ] && domirror "${debian_mirror} SUITE COMPONENT" ${APT_LIST}
149                 domirror "http://ftp.debian.org/debian SUITE COMPONENT" ${APT_LIST}
150             fi
151
152         elif [ "${SUITE_VARIANT%%-sloppy}" = 'backports' ]; then
153             SUITES="${SUITE_BASE}"
154             [ -n "${debian_mirror}" ] && domirror "${debian_mirror} SUITE COMPONENT" ${APT_LIST}
155             domirror "http://ftp.debian.org/debian SUITE COMPONENT" ${APT_LIST}
156             SUITES="${SUITE_BASE}"
157             [ -n "${debian_mirror}" ] && domirror "${debian_mirror} SUITE-backports COMPONENT" ${APT_LIST}
158             domirror "http://ftp.debian.org/debian SUITE-backports COMPONENT" ${APT_LIST}
159             if [ "${debian_incoming}" != 'no' ]; then
160                 domirror "http://incoming.debian.org/debian-buildd buildd-SUITE-backports COMPONENT" ${APT_LIST}
161             fi
162             if [ "$(echo ${SUITE_VARIANT} | cut -d - -f 2)" = "sloppy" ]; then
163                 [ -n "${debian_mirror}" ] && domirror "${debian_mirror} SUITE-backports-sloppy COMPONENT" ${APT_LIST}
164                 domirror "http://ftp.debian.org/debian SUITE-backports-sloppy COMPONENT" ${APT_LIST}
165                 if [ "${debian_incoming}" != 'no' ]; then
166                     domirror "http://incoming.debian.org/debian-buildd buildd-SUITE-backports-sloppy COMPONENT" ${APT_LIST}
167                 fi
168             fi
169
170         elif [ "${SUITE_BASE}" = 'sid' ]; then
171             SUITES="unstable"
172             if [ "${SUITE_VARIANT}" = "experimental" ]; then
173                 SUITES="unstable experimental"
174             fi
175             [ -n "${debian_mirror}" ] && domirror "${debian_mirror} SUITE COMPONENT" ${APT_LIST}
176             domirror "http://ftp.debian.org/debian SUITE COMPONENT" ${APT_LIST}
177             if [ "${debian_incoming}" != 'no' ]; then
178                 domirror "http://incoming.debian.org/debian-buildd buildd-SUITE COMPONENT" ${APT_LIST}
179             fi
180
181         else
182             echo "ERROR: cannot adjust sources.list: ${SUITE_BASE}/${SUITE_VARIANT} unknown - exiting"
183             exit 1
184
185         fi
186         echo 'Acquire::PDiffs "false";' >> ${APT_CONF}
187         echo 'APT::Install-Recommends 0;' >> ${APT_CONF}
188         echo 'Dir::Etc::SourceList "sources.buildd.list";' >> ${APT_CONF}
189         echo 'Acquire::Languages "none";' >> ${APT_CONF}
190
191         if [ -n "${APT_KEYS}" ]; then
192             for KEY in ${APT_KEYS}; do
193                 if [ -f /usr/share/buildd/${KEY}.asc ]; then
194                     chroot ${CHROOT_PATH} apt-key add - < /usr/share/buildd/${KEY}.asc >&2
195                 else
196                     echo W: should add apt key ${KEY} but not found >&2
197                 fi
198             done
199         fi
200     else
201     if [ -n "$SUITE_VARIANT" ]; then
202         SOURCES_FILE_NAME="${SUITE_BASE}-${SUITE_VARIANT}.sources"
203         SOURCES_FILE_PATH="/etc/schroot/buildd.d/${SOURCES_FILE_NAME}"
204                 APT_LIST_AUTO="${CHROOT_PATH}/etc/apt/sources.list.d/auto.list"
205
206         if [ -f "$SOURCES_FILE_PATH" ]; then
207                 cp $VERBOSE ${SOURCES_FILE_PATH} "${CHROOT_PATH}/etc/apt/sources.list.d/${SOURCES_FILE_NAME}.list"
208                 elif [ ${SUITE_VARIANT} = 'security' ]; then
209                         : > ${APT_LIST_AUTO}
210                     if [ -n "${security_mirror}" ]; then
211                         echo deb ${security_mirror} ${SUITE_BASE}/updates main contrib >> ${APT_LIST_AUTO}
212                         echo deb-src ${security_mirror} ${SUITE_BASE}/updates main contrib >> ${APT_LIST_AUTO}
213                     fi
214                     echo deb https://security-master.debian.org/debian-security ${SUITE_BASE}/updates main contrib >> ${APT_LIST_AUTO}
215                     echo deb-src https://security-master.debian.org/debian-security ${SUITE_BASE}/updates main contrib >> ${APT_LIST_AUTO}
216                     echo deb https://security-master.debian.org/debian-security-buildd buildd-${SUITE_BASE}/updates main contrib >> ${APT_LIST_AUTO}
217                     echo deb-src https://security-master.debian.org/debian-security-buildd buildd-${SUITE_BASE}/updates main contrib >> ${APT_LIST_AUTO}
218                 elif [ ${SUITE_VARIANT%%-sloppy} = 'backports' ]; then
219                         : > ${APT_LIST_AUTO}
220                     if [ -n "${debian_mirror}" ]; then
221                         echo deb ${debian_mirror} ${SUITE_BASE}-backports main contrib >> ${APT_LIST_AUTO}
222                         echo deb-src ${debian_mirror} ${SUITE_BASE}-backports main contrib non-free >> ${APT_LIST_AUTO}
223                     fi
224                     echo deb http://ftp.debian.org/debian ${SUITE_BASE}-backports main contrib >> ${APT_LIST_AUTO}
225                     echo deb-src http://ftp.debian.org/debian ${SUITE_BASE}-backports main contrib non-free >> ${APT_LIST_AUTO}
226                     echo deb http://incoming.debian.org/debian-buildd buildd-${SUITE_BASE}-backports main contrib  >> ${APT_LIST_AUTO}
227                     echo deb-src http://incoming.debian.org/debian-buildd buildd-${SUITE_BASE}-backports main contrib non-free >> ${APT_LIST_AUTO}
228                     if [ "$(echo ${SUITE_VARIANT} | cut -d - -f 2)" = "sloppy" ]; then
229                         if [ -n "${debian_mirror}" ]; then
230                             echo deb ${debian_mirror} ${SUITE_BASE}-backports-sloppy main contrib >> ${APT_LIST_AUTO}
231                             echo deb-src ${debian_mirror} ${SUITE_BASE}-backports-sloppy main contrib non-free >> ${APT_LIST_AUTO}
232                         fi
233                         echo deb http://ftp.debian.org/debian ${SUITE_BASE}-backports-sloppy main contrib >> ${APT_LIST_AUTO}
234                         echo deb-src http://ftp.debian.org/debian ${SUITE_BASE}-backports-sloppy main contrib non-free >> ${APT_LIST_AUTO}
235                         echo deb http://incoming.debian.org/debian-buildd buildd-${SUITE_BASE}-backports-sloppy main contrib  >> ${APT_LIST_AUTO}
236                         echo deb-src http://incoming.debian.org/debian-buildd buildd-${SUITE_BASE}-backports-sloppy main contrib non-free >> ${APT_LIST_AUTO}
237                     fi
238                 elif [ ${SUITE_VARIANT} = 'experimental' ]; then
239                     : > ${APT_LIST_AUTO}
240                     if [ -n "${debian_mirror}" ]; then
241                         echo deb ${debian_mirror} experimental main contrib >> ${APT_LIST_AUTO}
242                         echo deb-src ${debian_mirror} experimental main contrib non-free >> ${APT_LIST_AUTO}
243                     fi
244                     echo deb     http://ftp.debian.org/debian experimental main contrib >> ${APT_LIST_AUTO}
245                     echo deb-src http://ftp.debian.org/debian experimental main contrib non-free >> ${APT_LIST_AUTO}
246                     echo deb     http://incoming.debian.org/debian-buildd buildd-experimental main contrib >> ${APT_LIST_AUTO}
247                     echo deb-src http://incoming.debian.org/debian-buildd buildd-experimental main contrib non-free >> ${APT_LIST_AUTO}
248         fi
249     fi
250     fi
251 elif [ "$1" = "setup-stop" ]; then
252     if [ -n "${SUITE_BASE}" ] && ( [ -f /etc/schroot/conf.buildd ] || [ -f /etc/schroot/dsa/default-mirror ] ); then
253         APT_LIST="${CHROOT_PATH}/etc/apt/sources.buildd.list"
254         APT_CONF="${CHROOT_PATH}/etc/apt/apt.conf.d/99buildd.conf"
255         rm -f "${APT_LIST}" "${APT_CONF}"
256     else
257     if [ -n "$SUITE_VARIANT" ]; then
258         SOURCES_FILE_NAME="${SUITE_BASE}-${SUITE_VARIANT}.sources"
259         SOURCES_FILE_PATH="/etc/schroot/buildd.d/${SOURCES_FILE_NAME}"
260
261         if [ -f "$SOURCES_FILE_PATH" ]; then
262                 rm -f $VERBOSE "${CHROOT_PATH}/etc/apt/sources.list.d/${SOURCES_FILE_NAME}.list"
263                 elif [ ${SUITE_VARIANT} = 'security' ] || [ ${SUITE_VARIANT} = 'backports' ] || [ ${SUITE_VARIANT} = 'experimental' ] ; then
264                 rm -f $VERBOSE "${CHROOT_PATH}/etc/apt/sources.list.d/auto.list"
265         fi
266     fi
267     fi
268 fi