c6efbb17e85e7072e0bd019861dd0eaef61b0092
[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 buster stretch jessie"
35         ;;
36       *)
37         echo "sid buster stretch"
38         ;;
39     esac
40 }
41
42 do_one() {
43     local a="$1"; shift
44     local s="$1"; shift
45
46     case "$MODE" in
47         buildd)
48             mkdir -p /srv/buildd/unpack
49             if ! $SILENT setup-dchroot $EXTRAARGS -f -a "$a" -D -d '/srv/buildd/unpack' -K "$s"
50             then
51                 return 1
52             fi
53             ;;
54         porterbox)
55             if ! $SILENT setup-dchroot $EXTRAARGS -f -a "$a" "$s"
56             then
57                 return 1
58             fi
59             ;;
60         *)
61             echo >&2 "Invalid mode $MODE"
62             exit 1
63     esac
64     return 0
65 }
66
67 usage()
68 {
69 cat << EOF
70 usage: $0 [<options>] [buildd]
71
72 OPTIONS:
73     -a <ARCH>  limit to ARCH
74     -c         write config only
75     -h         this help
76     -s <SUITE> limit to SUITE
77 EOF
78 }
79
80 ##########
81 # "main"
82 ##########
83
84
85 # parse options
86 ##########
87 EXTRAARGS=""
88 limitarch=""
89 limitsuite=""
90 while getopts "cha:s:" OPTION
91 do
92     case $OPTION in
93         a)
94             limitarch="$OPTARG"
95             ;;
96         c)
97             EXTRAARGS="$EXTRAARGS -c"
98             ;;
99         h)
100             usage
101             exit 0
102             ;;
103         s)
104             limitsuite="$OPTARG"
105             ;;
106         *)
107             usage >&2
108             exit 1
109             ;;
110     esac
111 done
112 shift $(($OPTIND - 1))
113
114 # parse arguments
115 ##########
116 if [ "$#" -gt 1 ]; then
117     usage >&2
118     exit 1
119 elif [ "$#" = 1 ]; then
120     if [ "${1:-}" = "buildd" ]; then
121         MODE=buildd
122         if ! [ -d /srv/buildd/ ]; then
123             echo >&2 "Error: /srv/buildd does not exist or is not a directory."
124             exit 1
125         fi
126     else
127         usage >&2
128         exit 1
129     fi
130 else
131     MODE=porterbox
132 fi
133
134 # figure out whether to be verbose or not
135 ##########
136 if [ -t 0 ] ; then
137     SILENT=""
138 else
139     SILENT="chronic"
140 fi
141
142 # get list of archs based on dpkg architecture
143 ##########
144 DPKGARCH=$(dpkg --print-architecture)
145 archs="$DPKGARCH"
146 case "$DPKGARCH" in
147     amd64)
148         archs="$archs i386"
149         ;;
150     arm64)
151         archs="$archs armhf armel"
152         ;;
153     armhf)
154         if [ "$(uname -m)" = "aarch64" ] ; then
155             archs="$archs arm64"
156         fi
157         archs="$archs armel"
158         ;;
159     armel)
160         if [ "$(uname -m)" = "armv7l" ] && grep -w vfpv3 -q /proc/cpuinfo ; then
161             archs="$archs armhf"
162         fi
163         ;;
164     mips64el)
165         archs="$archs mipsel"
166         ;;
167     mipsel)
168         archs="$archs mips64el"
169         ;;
170 esac
171
172 err=0
173
174 for a in $archs; do
175     [ "$limitarch" != "" ] && [ "$limitarch" != "$a" ] && continue
176     for s in `get_suites "$a"`; do
177         [ "$limitsuite" != "" ] && [ "$limitsuite" != "$s" ] && continue
178         if ! do_one "$a" "$s"; then
179             err=1
180             echo >&2
181             echo >&2 "Error: setting up $s:$a dchroot failed."
182             echo >&2
183             echo >&2
184         fi
185     done
186 done
187
188 exit $err