Note that exim contains tracker-specific configuration
[mirror/dsa-puppet.git] / modules / schroot / files / setup-all-dchroots
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 # Copyright (c) 2013 Peter Palfrader
9 #
10 # Permission is hereby granted, free of charge, to any person
11 # obtaining a copy of this software and associated documentation
12 # files (the "Software"), to deal in the Software without
13 # restriction, including without limitation the rights to use,
14 # copy, modify, merge, publish, distribute, sublicense, and/or sell
15 # copies of the Software, and to permit persons to whom the
16 # Software is furnished to do so, subject to the following
17 # conditions:
18 #
19 # The above copyright notice and this permission notice shall be
20 # included in all copies or substantial portions of the Software.
21 #
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 # OTHER DEALINGS IN THE SOFTWARE.
30
31 get_suites() {
32     case "$1" in
33       amd64|i386|armel|armhf)
34         echo "sid bullseye buster stretch jessie"
35         ;;
36       mips)
37         echo "buster stretch"
38         ;;
39       *)
40         echo "sid bullseye buster stretch"
41         ;;
42     esac
43 }
44
45 do_one() {
46     local a="$1"; shift
47     local s="$1"; shift
48
49     case "$MODE" in
50         buildd)
51             mkdir -p /srv/buildd/unpack
52             if ! $SILENT setup-dchroot $EXTRAARGS -f -a "$a" -D -d '/srv/buildd/unpack' -K "$s"
53             then
54                 return 1
55             fi
56             ;;
57         porterbox)
58             if ! $SILENT setup-dchroot $EXTRAARGS -f -a "$a" "$s"
59             then
60                 return 1
61             fi
62             ;;
63         *)
64             echo >&2 "Invalid mode $MODE"
65             exit 1
66     esac
67     return 0
68 }
69
70 usage()
71 {
72 cat << EOF
73 usage: $0 [<options>] [buildd]
74
75 OPTIONS:
76     -a <ARCH>  limit to ARCH
77     -c         write config only
78     -h         this help
79     -s <SUITE> limit to SUITE
80 EOF
81 }
82
83 ##########
84 # "main"
85 ##########
86
87
88 # parse options
89 ##########
90 EXTRAARGS=""
91 limitarch=""
92 limitsuite=""
93 while getopts "cha:s:" OPTION
94 do
95     case $OPTION in
96         a)
97             limitarch="$OPTARG"
98             ;;
99         c)
100             EXTRAARGS="$EXTRAARGS -c"
101             ;;
102         h)
103             usage
104             exit 0
105             ;;
106         s)
107             limitsuite="$OPTARG"
108             ;;
109         *)
110             usage >&2
111             exit 1
112             ;;
113     esac
114 done
115 shift $(($OPTIND - 1))
116
117 # parse arguments
118 ##########
119 if [ "$#" -gt 1 ]; then
120     usage >&2
121     exit 1
122 elif [ "$#" = 1 ]; then
123     if [ "${1:-}" = "buildd" ]; then
124         MODE=buildd
125         if ! [ -d /srv/buildd/ ]; then
126             echo >&2 "Error: /srv/buildd does not exist or is not a directory."
127             exit 1
128         fi
129     else
130         usage >&2
131         exit 1
132     fi
133 else
134     MODE=porterbox
135 fi
136
137 # figure out whether to be verbose or not
138 ##########
139 if [ -t 0 ] ; then
140     SILENT=""
141 else
142     SILENT="chronic"
143 fi
144
145 # get list of archs based on dpkg architecture
146 ##########
147 DPKGARCH=$(dpkg --print-architecture)
148 archs="$DPKGARCH"
149 case "$DPKGARCH" in
150     amd64)
151         archs="$archs i386"
152         ;;
153     arm64)
154         archs="$archs armhf armel"
155         ;;
156     armhf)
157         if [ "$(uname -m)" = "aarch64" ] ; then
158             archs="$archs arm64"
159         fi
160         archs="$archs armel"
161         ;;
162     armel)
163         if [ "$(uname -m)" = "armv7l" ] && grep -w vfpv3 -q /proc/cpuinfo ; then
164             archs="$archs armhf"
165         fi
166         ;;
167     mips64el)
168         archs="$archs mipsel"
169         ;;
170     mipsel)
171         archs="$archs mips64el"
172         ;;
173 esac
174
175 err=0
176
177 for a in $archs; do
178     [ "$limitarch" != "" ] && [ "$limitarch" != "$a" ] && continue
179     for s in `get_suites "$a"`; do
180         [ "$limitsuite" != "" ] && [ "$limitsuite" != "$s" ] && continue
181         if ! do_one "$a" "$s"; then
182             err=1
183             echo >&2
184             echo >&2 "Error: setting up $s:$a dchroot failed."
185             echo >&2
186             echo >&2
187         fi
188     done
189 done
190
191 exit $err