[PATCH 2/2] commitpkg: introduce abort function to be used on errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



---
 commitpkg |   42 +++++++++++++-----------------------------
 1 files changed, 13 insertions(+), 29 deletions(-)

diff --git a/commitpkg b/commitpkg
index 5abc088..ba98490 100755
--- a/commitpkg
+++ b/commitpkg
@@ -1,11 +1,15 @@
 #!/bin/bash
 
+abort() {
+    echo ${1:-"Cancelled"}
+    exit 1
+}
+
 # Source makepkg.conf; fail if it is not found
 if [ -r "/etc/makepkg.conf" ]; then
     source "/etc/makepkg.conf"
 else
-    echo "/etc/makepkg.conf not found!"
-    exit 1
+    abort "/etc/makepkg.conf not found!"
 fi
 
 # Source user-specific makepkg.conf overrides
@@ -16,8 +20,7 @@ fi
 cmd=$(basename $0)
 
 if [ ! -f PKGBUILD ]; then
-    echo "No PKGBUILD file"
-    exit 1
+    abort "No PKGBUILD file"
 fi
 
 source PKGBUILD
@@ -39,8 +42,7 @@ elif [ "$cmd" == "community-testingpkg" ]; then
     server="aur.archlinux.org"
 else
     if [ $# -eq 0 ]; then
-        echo "usage: commitpkg <reponame> [-l limit] [commit message]"
-        exit 1
+        abort "usage: commitpkg <reponame> [-l limit] [commit message]"
     fi
     repo="$1"
     shift
@@ -70,46 +72,28 @@ for CARCH in ${arch[@]}; do
         uploadto="staging/${repo}/$(basename ${pkgfile})"
         # don't re-upload the same package (useful for -any sub packages)
         if [ "$(md5sum "${pkgfile}" | cut -d' ' -f1)" != "$(ssh ${server} md5sum "${uploadto}" | cut -d' ' -f1)" ]; then
-            scp ${scpopts} "${pkgfile}" "${server}:${uploadto}"
+            scp ${scpopts} "${pkgfile}" "${server}:${uploadto}" || abort
         fi
         if [ "$(md5sum "${pkgfile}" | cut -d' ' -f1)" != "$(ssh ${server} md5sum "${uploadto}" | cut -d' ' -f1)" ]; then
-            echo "File got corrupted during upload, cancelled."
-            exit 1
+            abort "File got corrupted during upload, cancelled."
         else
             echo "File integrity okay."
         fi
-
-        if [ $? -ne 0 ]; then
-            echo "Cancelled"
-            exit 1
-        fi
         echo "===> Uploaded $pkgfile"
     done
 
     if [ "$1" != "" ]; then
         svn commit -m "upgpkg: $pkgbase $pkgver-$pkgrel
-    $1" > /dev/null 
-        if [ $? -ne 0 ]; then
-            echo "Cancelled"
-            exit 1
-        fi
+    $1" > /dev/null || abort
         echo "===> Commited with message:
   upgpkg: $pkgbase $pkgver-$pkgrel
       $1"
     else
-        svn commit
-        if [ $? -ne 0 ]; then
-            echo "Cancelled"
-            exit 1
-        fi
+        svn commit || abort
         echo "===> Commited"
     fi
 
-    archrelease $repo-$CARCH
-    if [ $? -ne 0 ]; then
-        echo "Cancelled"
-        exit 1
-    fi
+    archrelease $repo-$CARCH || abort
     echo "===> Tagged for $repo-$CARCH"
 done
 
-- 
1.6.4.4



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux