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