setup-all-dchroots: get rid of obsolete variable "$extra" that is always the empty...
[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 extraargs=""
82 while getopts "cu" OPTION
83 do
84     case $OPTION in
85         c)
86             extraargs="$extraargs -c"
87             ;;
88         h)
89             usage
90             exit 0
91             ;;
92         *)
93             usage >&2
94             exit 1
95             ;;
96     esac
97 done
98 shift $(($OPTIND - 1))
99
100 if [ "$#" -gt 1 ]; then
101     usage >&2
102     exit 1
103 elif [ "$#" = 1 ]; then
104     if [ "${1:-}" = "buildd" ]; then
105         MODE=buildd
106         if ! [ -d /srv/buildd/ ]; then
107             echo >&2 "Error: /srv/buildd does not exist or is not a directory."
108             exit 1
109         fi
110     else
111         usage >&2
112         exit 1
113     fi
114 else
115     MODE=porterbox
116 fi
117
118 if [ -t 0 ] ; then
119     SILENT=""
120 else
121     SILENT="chronic"
122 fi
123
124
125 archs="$DPKGARCH"
126 case "$DPKGARCH" in
127     amd64)
128         archs="$archs i386"
129         ;;
130     arm64)
131         archs="$archs armhf armel"
132         ;;
133     armhf)
134         if [ "$(uname -m)" = "aarch64" ] ; then
135             archs="$archs arm64"
136         fi
137         archs="$archs armel"
138         ;;
139     armel)
140         if [ "$(uname -m)" = "armv7l" ] && grep -w vfpv3 -q /proc/cpuinfo ; then
141             archs="$archs armhf"
142         fi
143         ;;
144     mips64el)
145         archs="$archs mipsel"
146         ;;
147     mipsel)
148         archs="$archs mips64el"
149         ;;
150 esac
151
152 err=0
153
154 for a in $archs; do
155     for s in `get_suites "$a"`; do
156         if ! do_one "$a" "$s"; then
157             err=1
158             echo >&2
159             echo >&2 "Error: setting up $s:$a dchroot failed."
160             echo >&2
161             echo >&2
162         fi
163     done
164 done
165
166 exit $err