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