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