diff options
Diffstat (limited to 'trunk/lib')
-rw-r--r-- | trunk/lib/common.sh | 162 |
1 files changed, 161 insertions, 1 deletions
diff --git a/trunk/lib/common.sh b/trunk/lib/common.sh index 91f715f..ef5d62a 100644 --- a/trunk/lib/common.sh +++ b/trunk/lib/common.sh @@ -690,6 +690,156 @@ function gen_meta { } # ----------------------------------------------- +# Error functions +# ----------------------------------------------- +function error_codes { + + # Slackbuilds error codes ** not change ** + ERROR_WGET=31 # wget error + ERROR_MAKE=32 # make source error + ERROR_INSTALL=33 # make install error + ERROR_MD5=34 # md5sum error + ERROR_CONF=35 # ./configure error + ERROR_HELP=36 # dasable + ERROR_TAR=37 # tar error + ERROR_MKPKG=38 # makepkg error + ERROR_GPG=39 # gpg check error + ERROR_PATCH=40 # patch error + ERROR_VCS=41 # cvs error + ERROR_MKDIR=42 # make directory error + # Slackbuilds error codes ** not change ** + + # Commum error codes + ERROR_FILE_NOTFOUND=100 # file not found + + # Createpkg error codes + ERROR_CREATEPKG_INSTALLPKG=200 # installpkg error + ERROR_CREATEPKG_DEPENDENCY=201 # dependency error + ERROR_CREATEPKG_SLACKBUILD_NOTFOUND=202 # Script or package not found + + # Mkbuild error codes + ERROR_MKBUILD_FILE_NOT_FOUND=500 + ERROR_MKBUILD_CONSTRUCTION=501 + ERROR_MKBUILD_PROGRAM=502 + ERROR_MKBUILD_INPUT_PAR=503 + +} + +function handle_error { + + # This function deals with internal createpkg errors + # and also with non-zero exit codes from slackbuilds + # Input: $1 - error code + # Output: Error mensage + # + # check slackbuild exit status are: + # + # ERROR_WGET=31; ERROR_MAKE=32; ERROR_INSTALL=33 + # ERROR_MD5=34; ERROR_CONF=35; ERROR_HELP=36 + # ERROR_TAR=37; ERROR_MKPKG=38 ERROR_GPG=39 + # ERROR_PATCH=40; ERROR_VCS=41; ERROR_MKDIR=42 + # + + # we don't want to process when exit status = 0 + [ "$1" == "0" ] && return + + # Exit codes + case $1 in + # + # Slackbuilds errors + $ERROR_WGET) + eecho $error "$BASENAME: error downloading source/package for $2" ;; + $ERROR_MAKE) + eecho $error "$BASENAME: error compiling $2 source code" ;; + $ERROR_INSTALL) + eecho $error "$BASENAME: error installing $2" ;; + $ERROR_MD5) + eecho $error "$BASENAME: error on source code integrity check for $2" ;; + $ERROR_CONF) + eecho $error "$BASENAME: error configuring the source code for $2" ;; + $ERROR_HELP) + exit 0 ;; # its supposed to never happen here :P + $ERROR_TAR) + eecho $error "$BASENAME: error decompressing source code for $2" ;; + $ERROR_MKPKG) + eecho $error "$BASENAME: error creating package $2" ;; + $ERROR_GPG) + eecho $error "$BASENAME: error verifying GPG signature the source code for $2" ;; + $ERROR_PATCH) + eecho $error "$BASENAME: error patching the source code for $2" ;; + $ERROR_VCS) + eecho $error "$BASENAME: error downloading $2 source from version control system" ;; + $ERROR_MKDIR) + eecho $error "$BASENAME: make directory $2 error, aborting" ;; + # + # General errors + $ERROR_FILE_NOTFOUND) + eecho $error "$BASENAME: file $2 not found!" ;; + # + # Createpkg errors + $ERROR_CREATEPKG_INSTALLPKG) + eecho $error "$BASENAME: install package $2 error, aborting" ;; + $ERROR_CREATEPKG_DEPENDENCY) + eecho $error "$BASENAME: dependency solve error, aborting" ;; + $ERROR_CREATEPKG_SLACKBUILD_NOTFOUND) + eecho $error "$BASENAME: SlackBuild or package not found" ;; + # + # Mkbuild errors + $ERROR_MKBUILD_CONSTRUCTION) + eecho $error "$BASENAME: Construction error in $2 variable." ;; + $ERROR_MKBUILD_PROGRAM) + eecho $error "$BASENAME: Program logical error." ;; + $ERROR_MKBUILD_INPUT_PAR) + eecho $error "$BASENAME: Input parameter $2 error. See \"mkbuild --help\"." ;; + # + # Others errors + *) + eecho $error "$BASENAME: unknown error or user interrupt" ;; + esac + + exit $1 + +} + +# ----------------------------------------------- +# svn functions +# ----------------------------------------------- +function build_repo { + + # Checkout a new slackbuild working copy + # input: $1 - svn directory name + # $2 - svn address + [ $# -ne 2 ] && exit 5 + SVN_BASEDIR="`dirname $1`" + mkdir -p $SVN_BASEDIR || exit 4 + cd $SVN_BASEDIR + svn checkout $2 + cd $1 + +} + +function check_repo { + + # Verify if repository exist + # input: $1 - svn directory name + # $2 - svn address + [ $# -ne 2 ] && exit 5 + [ ! -d "$1" ] && build_repo $1 $2 + +} + +function sync_repo { + + # Synchronize repository + # input: $1 - svn directory name + # $2 - svn address + [ $# -ne 2 ] && exit 5 + cd $1 + svn update || build_repo $1 $2 + +} + +# ----------------------------------------------- # misc functions # ----------------------------------------------- @@ -733,7 +883,6 @@ function color_select { } - function eecho { # echoes a message @@ -744,3 +893,14 @@ function eecho { } +function is_number { + + # Check if $1 is a number + local -i int + if [ $# -eq 0 ]; then + return 1 + else + (let int=$1) 2>/dev/null + return $? # Exit status of the let thread + fi +} |