setup-all-dchroots: move all main code to after function declarations
[mirror/dsa-puppet.git] / modules / schroot / files / setup-all-dchroots
index 552385c..1031b5e 100755 (executable)
 DPKGARCH=$(dpkg --print-architecture)
 UNAMEARCH=$(uname -m)
 
-if [ "${1:-}" = "buildd" ]; then
-    MODE=buildd
-    if ! [ -d /srv/buildd/ ]; then
-        echo >&2 "Error: /srv/buildd does not exist or is not a directory."
-        exit 1
-    fi
-else
-    MODE=porterbox
-fi
-
 get_suites() {
     case "$1" in
-      armhf|s390x)
-        echo "sid stretch jessie wheezy"
-        ;;
-      ia64|s390)
-        echo "wheezy"
-        ;;
-      sparc)
-        echo "sid wheezy"
-        ;;
-      arm64|ppc64el)
-        echo "sid stretch jessie"
-        ;;
-      amd64|i386)
-        echo "sid stretch jessie wheezy squeeze"
-        ;;
-      kfreebsd-*)
-        echo "sid         jessie wheezy"
+      amd64|i386|armel|armhf)
+        echo "sid buster stretch jessie"
         ;;
       *)
-        echo "sid stretch jessie wheezy"
+        echo "sid buster stretch"
         ;;
     esac
 }
 
+do_one() {
+    local a="$1"; shift
+    local s="$1"; shift
+
+    case "$MODE" in
+        buildd)
+            mkdir -p /srv/buildd/unpack
+            if ! $SILENT setup-dchroot $extraargs -f -a "$a" $extra -D -d '/srv/buildd/unpack' -K "$s"
+            then
+                return 1
+            fi
+            ;;
+        porterbox)
+            if ! $SILENT setup-dchroot $extraargs -f -a "$a" $extra "$s"
+            then
+                return 1
+            fi
+            ;;
+        *)
+            echo >&2 "Invalid mode $MODE"
+            exit 1
+    esac
+    return 0
+}
+
+usage()
+{
+cat << EOF
+usage: $0 [<options>] [buildd]
+
+OPTIONS:
+    -c         write config only
+    -h         this help
+EOF
+}
+
+extraargs=""
+while getopts "cu" OPTION
+do
+    case $OPTION in
+        c)
+            extraargs="$extraargs -c"
+            ;;
+        h)
+            usage
+            exit 0
+            ;;
+        *)
+            usage >&2
+            exit 1
+            ;;
+    esac
+done
+shift $(($OPTIND - 1))
+
+if [ "$#" -gt 1 ]; then
+    usage >&2
+    exit 1
+elif [ "$#" = 1 ]; then
+    if [ "${1:-}" = "buildd" ]; then
+        MODE=buildd
+        if ! [ -d /srv/buildd/ ]; then
+            echo >&2 "Error: /srv/buildd does not exist or is not a directory."
+            exit 1
+        fi
+    else
+        usage >&2
+        exit 1
+    fi
+else
+    MODE=porterbox
+fi
+
+if [ -t 0 ] ; then
+    SILENT=""
+else
+    SILENT="chronic"
+fi
+
+
+extra=""
+
 archs="$DPKGARCH"
 case "$DPKGARCH" in
     amd64)
@@ -86,38 +143,16 @@ case "$DPKGARCH" in
             archs="$archs armhf"
         fi
         ;;
-    s390|s390x)
-        archs="s390 s390x"
+    mips64el)
+        archs="$archs mipsel"
+        ;;
+    mipsel)
+        archs="$archs mips64el"
         ;;
 esac
 
 err=0
 
-do_one() {
-    local a="$1"; shift
-    local s="$1"; shift
-
-    case "$MODE" in
-        buildd)
-            mkdir -p /srv/buildd/unpack
-            if ! chronic setup-dchroot -f -a "$a" -D -d '/srv/buildd/unpack' -K "$s"
-            then
-                return 1
-            fi
-            ;;
-        porterbox)
-            if ! chronic setup-dchroot -f -a "$a" "$s"
-            then
-                return 1
-            fi
-            ;;
-        *)
-            echo >&2 "Invalid mode $MODE"
-            exit 1
-    esac
-    return 0
-}
-
 for a in $archs; do
     for s in `get_suites "$a"`; do
         if ! do_one "$a" "$s"; then