chiark / gitweb /
bin/mdw-build: Abolish (direct) use of `mdw-conf'.
[profile] / bin / mdw-build
index 650f0c1360b5a2ea6755f1e0ebe3c40ef93dbfba..572aa755b1e9dc254710f6c2534c3a30402c9129 100755 (executable)
@@ -58,8 +58,10 @@ set -e
 
 unset checkout checkoutrev
 unset setup setupcmd
+unset sign signkey
+unset upload uploadpath
 unset dput dputtarget
-unset build distcheck debian upload clean vpath native
+unset build distcheck debian clean vpath native
 for i in \
   "/etc/mdw-build.conf" \
   "${XDG_CONFIG_HOME-$HOME/.config}/mdw-build.conf" \
@@ -67,15 +69,22 @@ for i in \
 do
   if [ -f "$i" ]; then . "$i"; fi
 done
+default_depends () {
+  var=$1 want=$2
+  eval "p=\${$var+t} q=\${$want+t}"
+  case $p,$q in t,*) ;; *,t) eval "$var=yes" ;; *) eval "$var=no" ;; esac
+}
 : ${checkout=yes} ${checkoutrev=HEAD}
 : ${build=test}
 : ${setup=yes} ${setupcmd=mdw-setup}
 : ${distcheck=yes}
 : ${debian=yes}
-: ${upload=yes}
 : ${clean=yes}
 : ${vpath=yes}
 : ${native=yes}
+default_depends sign signkey
+default_depends upload uploadpath
+default_depends dput dputtarget
 : ${DEB_BUILD_OPTIONS=parallel=4}; export DEB_BUILD_OPTIONS
 
 ###--------------------------------------------------------------------------
@@ -94,9 +103,11 @@ Build options:
   [no]setup[=RUNE]
   [no]distcheck
   [no]debian
-  [no]upload
+  [no]upload[=SERVER:PATH]
+  [no]dput[=TARGET]
   [no]clean
   [no]vpath
+  [no]sign[=KEYID]
   [no]native
 EOF
 }
@@ -113,6 +124,14 @@ done
 shift $((OPTIND - 1))
 
 ## Parse the build options.
+maybe_set () {
+  var=$1 want=$2
+  eval "p=\${$want+t}\${$want-nil}"
+  case $p in
+    t) eval $var=yes ;;
+    nil) echo >&2 "$prog: $want not set"; exit 1 ;;
+  esac
+}
 for opt; do
   case "$opt" in
     checkout)  checkout=yes checkoutrev=HEAD ;;
@@ -121,12 +140,18 @@ for opt; do
     norelease) build=test ;;
     setup)     setup=yes setupcmd=mdw-setup ;;
     setup=*)   setup=yes setupcmd=${opt#*=} ;;
-
-    distcheck | debian | upload | clean | vpath | native)
+    upload)    maybe_set upload uploadpath ;;
+    upload=*)  upload=yes uploadpath=${opt#*=} ;;
+    sign)      maybe_set sign signkey ;;
+    sign=*)    sign=yes signkey=${opt#*=} ;;
+    dput)      maybe_set dput dputtarget ;;
+    dput=*)    dput=yes dputtarget=${opt#*=} ;;
+
+    distcheck | debian | clean | vpath | native)
       eval "$opt=yes"
       ;;
     nocheckout | nosetup | nodistcheck | nodebian | \
-    noupload | noclean | novpath | nonative)
+    noupload | nodput | noclean | novpath | nonative | nosign)
       eval "${opt#no}=no"
       ;;
     *)
@@ -349,10 +374,9 @@ case $native in
 esac
 
 run mv $buildpath/$distdir.tar.gz .
-case $build in
-  release)
-    run gpg -u$(mdw-conf releasekey) -ab -o$distdir.tar.gz.gpg \
-      $distdir.tar.gz
+case $build,$sign in
+  release,yes)
+    run gpg -u$signkey -ab -o$distdir.tar.gz.gpg $distdir.tar.gz
     ;;
 esac
 
@@ -376,24 +400,21 @@ EOF
        mv debian/changelog.new debian/changelog
        ;;
     esac
-    run dpkg-buildpackage -k$(mdw-conf releasekey)
+    case $build,$sign in
+      release,yes) run dpkg-buildpackage -k$signkey ;;
+      no,*) run dpkg-buildpackage -us -uc ;;
+    esac
     ;;
 esac
 
 ## Maybe upload Debian packages.
 cd $releasepath
 case "$upload,$build" in
-  yes,test)
-    info "Test build: not uploading."
-    ;;
-  yes,release)
-    run rsync $distdir.tar.gz $distdir.tar.gz.gpg \
-      $(mdw-conf upload-target ftp.distorted.org.uk:~ftp/pub/mdw/)
-    case "$debian" in
-      yes)
-       run dput -f $(mdw-conf dput-target distorted) *.changes
-       ;;
-    esac
+  yes,test) info "Test build: not uploading." ;;
+  yes,release) run rsync $distdir.tar.gz $distdir.tar.gz.gpg $uploadpath ;;
+esac
+case "$debian,$upload,$dput,$build" in
+  yes,yes,yes,release) run dput -f $dputtarget *.changes ;;
 esac
 
 ## Tidy up.