58d0eca44c505188b69880027a2153838b536c67
[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 DPKGARCH=$(dpkg --print-architecture)
32 UNAMEARCH=$(uname -m)
33
34 get_suites() {
35     case "$1" in
36       amd64|i386|armel|armhf)
37         echo "sid buster stretch jessie"
38         ;;
39       *)
40         echo "sid 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     -c         write config only
77     -h         this help
78 EOF
79 }
80
81 ##########
82 # "main"
83 ##########
84
85
86 # parse options
87 ##########
88 EXTRAARGS=""
89 while getopts "cu" OPTION
90 do
91     case $OPTION in
92         c)
93             EXTRAARGS="$EXTRAARGS -c"
94             ;;
95         h)
96             usage
97             exit 0
98             ;;
99         *)
100             usage >&2
101             exit 1
102             ;;
103     esac
104 done
105 shift $(($OPTIND - 1))
106
107 # parse arguments
108 ##########
109 if [ "$#" -gt 1 ]; then
110     usage >&2
111     exit 1
112 elif [ "$#" = 1 ]; then
113     if [ "${1:-}" = "buildd" ]; then
114         MODE=buildd
115         if ! [ -d /srv/buildd/ ]; then
116             echo >&2 "Error: /srv/buildd does not exist or is not a directory."
117             exit 1
118         fi
119     else
120         usage >&2
121         exit 1
122     fi
123 else
124     MODE=porterbox
125 fi
126
127 # figure out whether to be verbose or not
128 ##########
129 if [ -t 0 ] ; then
130     SILENT=""
131 else
132     SILENT="chronic"
133 fi
134
135
136 # get list of archs based on DPKGARCH
137 ##########
138 archs="$DPKGARCH"
139 case "$DPKGARCH" in
140     amd64)
141         archs="$archs i386"
142         ;;
143     arm64)
144         archs="$archs armhf armel"
145         ;;
146     armhf)
147         if [ "$(uname -m)" = "aarch64" ] ; then
148             archs="$archs arm64"
149         fi
150         archs="$archs armel"
151         ;;
152     armel)
153         if [ "$(uname -m)" = "armv7l" ] && grep -w vfpv3 -q /proc/cpuinfo ; then
154             archs="$archs armhf"
155         fi
156         ;;
157     mips64el)
158         archs="$archs mipsel"
159         ;;
160     mipsel)
161         archs="$archs mips64el"
162         ;;
163 esac
164
165 err=0
166
167 for a in $archs; do
168     for s in `get_suites "$a"`; do
169         if ! do_one "$a" "$s"; then
170             err=1
171             echo >&2
172             echo >&2 "Error: setting up $s:$a dchroot failed."
173             echo >&2
174             echo >&2
175         fi
176     done
177 done
178
179 exit $err