]> gitweb.fluxo.info Git - simplepkg.git/commitdiff
createpkg: pequenas alterações
authorrudson <rudson@04377dda-e619-0410-9926-eae83683ac58>
Sat, 18 Nov 2006 13:13:18 +0000 (13:13 +0000)
committerrudson <rudson@04377dda-e619-0410-9926-eae83683ac58>
Sat, 18 Nov 2006 13:13:18 +0000 (13:13 +0000)
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@33 04377dda-e619-0410-9926-eae83683ac58

simplepkg.SlackBuild
src/createpkg

index bb087f65ee89921bd89c4da758be3d601c904cba..0d3a2c88626d30fc4efb49c17f4d25f8934177fa 100755 (executable)
@@ -5,7 +5,7 @@
 
 PACKAGE="simplepkg"
 PACK_DIR="package-$PACKAGE"
-BUILD="1rha"
+BUILD=${BUILD:=1rha}
 VERSION="0.4.9"
 ARCH="noarch"
 LIBEXEC="/usr/libexec/$PACKAGE"
index 75a7f7f988006ae691b63ac8777bbb2d922b4c44..6adf502ac000f3694c581c404449f59290403f17 100644 (file)
 # - in function solve_dep: resolve program versions
 #
 
-COMMON="/usr/libexec/simplepkg/common.sh"
-if [ -f ~/.slackbuildrc ]; then
-  SLACKBUILDRC=~/.slackbuildrc
-else
-  SLACKBUILDRC=/etc/slackbuildrc
-fi
-
-# first load simplepkg helper functions
-if [ -f "$COMMON" ]; then
-  source $COMMON
-else
-  echo "error: file $COMMON found, check your $BASENAME installation"
-  exit 1
-fi
-
+#---------------------------------------------------
+#               Createpkg functions
+#---------------------------------------------------
 function handle_error {
 
-  # this function deals with internal createpkg errors
-  # and also with non-zero exit codes from slackbuilds
-
-  # 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
-  #
-  # thanks to rudsonalves at yahoo.com.br for this spec.
-
-  # we don't want to process when exit status = 0
-  if [ "$1" == "0" ]; then
-    return
-  fi
-
-  # exit codes
-  case $1 in
-    2) usage ;;
-    3) echo $BASENAME: could not update the repository $2 ;;
-    4) echo $BASENAME: could not create folder $2 ;;
-    5) echo $BASENAME: script not found for $2 ;;
-   31) echo $BASENAME: error downloading source for $2 ;;
-   32) echo $BASENAME: error compiling $2 source code ;;
-   33) echo $BASENAME: error installing $2 ;;
-   34) echo $BASENAME: error on source code integrity check for $2 ;;
-   35) echo $BASENAME: error configuring the source code for $2 ;;
-   36) exit 0 ;; # its supposed to never happen here :P
-   37) echo $BASENAME: error decompressing source code for $2 ;;
-   38) echo $BASENAME: error creating package $2 ;;
-   39) echo $BASENAME: error verifying GPG signature the source code for $2 ;;
-   40) echo $BASENAME: error patching the source code for $2 ;;
-   41) echo $BASENAME: error downloading $2 source from version control system ;; 
-    *) echo $BASENAME: unknown error or user interrupt
-  esac
-
-  exit $1
+    # this function deals with internal createpkg errors
+    # and also with non-zero exit codes from slackbuilds
+
+    # 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
+    #
+    # thanks to rudsonalves at yahoo.com.br for this spec.
+
+    # we don't want to process when exit status = 0
+    if [ "$1" == "0" ]; then
+        return
+    fi
+
+    # exit codes
+    case $1 in
+        2) usage ;;
+        3) echo -e "$CL_ALERT $BASENAME: could not update the repository $2 $CL_OFF" ;;
+        4) echo -e "$CL_ALERT $BASENAME: could not create folder $2 $CL_OFF" ;;
+        5) echo -e "$CL_ALERT $BASENAME: script not found for $2 $CL_OFF" ;;
+        31) echo -e "$CL_ERROR $BASENAME: error downloading source for $2 $CL_OFF" ;;
+        32) echo -e "$CL_ERROR $BASENAME: error compiling $2 source code $CL_OFF" ;;
+        33) echo -e "$CL_ERROR $BASENAME: error installing $2 $CL_OFF" ;;
+        34) echo -e "$CL_ERROR $BASENAME: error on source code integrity check for $2 $CL_OFF" ;;
+        35) echo -e "$CL_ERROR $BASENAME: error configuring the source code for $2 $CL_OFF" ;;
+        36) exit 0 ;; # its supposed to never happen here :P
+        37) echo -e "$CL_ERROR $BASENAME: error decompressing source code for $2 $CL_OFF" ;;
+        38) echo -e "$CL_ERROR $BASENAME: error creating package $2 $CL_OFF" ;;
+        39) echo -e "$CL_ERROR $BASENAME: error verifying GPG signature the source code for $2 $CL_OFF" ;;
+        40) echo -e "$CL_ERROR $BASENAME: error patching the source code for $2 $CL_OFF" ;;
+        41) echo -e "$CL_ERROR $BASENAME: error downloading $2 source from version control system $CL_OFF" ;;
+        *) echo -e "$CL_ERROR $BASENAME: unknown error or user interrupt $CL_OFF"
+    esac
+
+    exit $1
 
 }
 
 function build_repo {
 
-  # checkout a new slackbuild working copy 
+    # checkout a new slackbuild working copy
 
-  BASEDIR="`dirname $SLACKBUILDS`"
-  mkdir -p $BASEDIR || handle_error 4 $BASEDIR
-  cd $BASEDIR
-  svn checkout $SVN
-  cd $SLACKBUILDS
+    BASEDIR="`dirname $SLACKBUILDS`"
+    mkdir -p $BASEDIR || handle_error 4 $BASEDIR
+    cd $BASEDIR
+    svn checkout $SVN
+    cd $SLACKBUILDS
 
 }
 
 function usage {
 
-  echo "usage: createpkg [--install] package-name"
-  echo "       createpkg --no-deps package-name"
-  echo "       createpkg --search package-name"
-  echo "       createpkg --sync"
+    echo -e "$CL_COMMU usage: createpkg [--install] package-name $CL_OFF"
+    echo -e "$CL_COMMU        createpkg --no-deps package-name $CL_OFF"
+    echo -e "$CL_COMMU       createpkg --search package-name $CL_OFF"
+    echo -e "$CL_COMMU       createpkg --sync $CL_OFF"
 
 }
 
 function check_config {
 
-  # check the configuration
+    # check the configuration
 
-  # TODO: eval also ~/.slackbuildrc
-  if [ -f "$SLACKBUILDRC" ]; then
-    source $SLACKBUILDRC
-  fi
+    # TODO: eval also ~/.slackbuildrc
+    #if [ -f "$SLACKBUILDRC" ]; then
+    #  source $SLACKBUILDRC
+    #fi
 
-  TMP=${TMP:=/tmp}
-  REPOS=${REPOS:=$TMP}
-  SLACKBUILDS=${SLACKBUILDS:=/var/slackbuilds}
-  SVN=${SVN:=svn://slack.sarava.org/slackbuilds}
-  SYNC=${SYNC:=no}
-  BASEDIR="`dirname $SLACKBUILDS`"
+    TMP=${TMP:=/tmp}
+    REPOS=${REPOS:=$TMP}
+    SLACKBUILDS=${SLACKBUILDS:=/var/slackbuilds}
+    SVN=${SVN:=svn://slack.sarava.org/slackbuilds}
+    SYNC=${SYNC:=no}
+    BASEDIR="`dirname $SLACKBUILDS`"
 
 }
 
 function solve_dep {
 
-  pack="$1"
-  cond="$2"
-  ver="$3"
-
-  if [ "$cond" != "equal" ] && [ "$cond" != "less" ] && [ "$cond" != "equalorgreater" ] && [ "$cond" != "lessequal" ] && [ ! -z "$cond" ]; then
-    # slack-required has a wrong logical sentence, so we ignore it
-    check_version="no"
-  fi
-
-  for candidate in `ls /var/log/packages/$pack* 2> /dev/null`; do
-    candidate="`package_name $candidate`"
-    if [ "$pack" == "$candidate" ]; then
-      if [ "$check_version" != "no" ]; then
-        # TODO: check if the pack has the correct version
-        true
-      fi
-      found="1"
-      break
+    pack="$1"
+    cond="$2"
+    ver="$3"
+
+    if [ "$cond" != "equal" ] && [ "$cond" != "less" ] && [ "$cond" != "equalorgreater" ] && [ "$cond" != "lessequal" ] && [ ! -z "$cond" ]; then
+        # slack-required has a wrong logical sentence, so we ignore it
+        check_version="no"
     fi
-  done
-
-  if [ "$found" != "1" ]; then
-    echo $BASENAME: processing $PACKAGE dependency $pack
-    SYNC=no CREATEPKG_CHILD=$CREATEPKG_CHILD createpkg --install $pack
-    # check if the package was built and installed
-    exit_code="$?"
-    if [ "$exit_code" != "0" ]; then
-      echo $BASENAME: received an error when processing $pack, aborting
-      exit $exit_code
+
+    for candidate in `ls /var/log/packages/$pack* 2> /dev/null`; do
+        candidate="`package_name $candidate`"
+        if [ "$pack" == "$candidate" ]; then
+            if [ "$check_version" != "no" ]; then
+                # TODO: check if the pack has the correct version
+                true
+            fi
+            found="1"
+            break
+        fi
+    done
+
+    if [ "$found" != "1" ]; then
+        echo -e "$CL_MENSG $BASENAME: processing $PACKAGE dependency $pack $CL_OFF"
+        SYNC=no CREATEPKG_CHILD=$CREATEPKG_CHILD createpkg --install $pack
+        # check if the package was built and installed
+        exit_code="$?"
+        if [ "$exit_code" != "0" ]; then
+            echo -e "$CL_ALERT $BASENAME: received an error when processing $pack, aborting $CL_OFF"
+            exit $exit_code
+        fi
+    else
+        found="0"
     fi
-  else
-    found="0"
-  fi
 
 }
 
 function check_repo {
 
-  if [ ! -d "$SLACKBUILDS" ]; then
-    build_repo
-  fi
+    if [ ! -d "$SLACKBUILDS" ]; then
+        build_repo
+    fi
 
 }
 
 function sync_repo {
 
-  cd $SLACKBUILDS
-  svn update || build_repo
+    cd $SLACKBUILDS
+    svn update || build_repo
 
 }
 
 function find_script {
 
-  find $SLACKBUILDS | grep -v .svn | grep -e "/$1.SlackBuild$"
+    #find $SLACKBUILDS | grep -v .svn | grep -e "/$1.SlackBuild$"
+    find $SLACKBUILDS -name $1.SlackBuild
 
 }
 
-# this is used to show how many children process we have
+#---------------------------------------------------
+#                 Starting createpkg
+#---------------------------------------------------
+# Common functions
+COMMON="/usr/libexec/simplepkg/common.sh"
+if [ -f ~/.slackbuildrc ]; then
+    source ~/.slackbuildrc
+else
+    source /etc/slackbuildrc 2>/dev/null
+fi
+
+# Select color mode: gray, color or none (*)
+# CL_COMMU - Communication
+# CL_MENSG - Commum messages
+# CL_ERROR - Error messages
+# CL_OFF   - turn off color
+case "$COLOR" in
+    'gray')
+        CL_COMMU="\033[37;1m"
+        CL_MENSG="\033[37;1m"
+        CL_ERROR="\033[30;1m"
+        CL_ALERT="\033[37m"
+        CL_OFF="\033[m"
+    ;;
+    'color')
+        CL_COMMU="\033[34;1m" # green
+        CL_MENSG="\033[32;1m" # blue
+        CL_ERROR="\033[31;1m" # red
+        CL_ALERT="\033[33;1m" # yellow
+        CL_OFF="\033[m"       # normal
+    ;;
+    *)
+        CL_COMMU=""
+        CL_MENSG=""
+        CL_ERROR=""
+        CL_ALERT=""
+        CL_OFF=""
+    ;;
+esac
+
+# First load simplepkg helper functions
+if [ -f "$COMMON" ]; then
+    source $COMMON
+else
+    echo -e "$CL_ERROR error: file $COMMON found, check your $BASENAME installation $CL_OFF"
+    exit 1
+fi
+
+# This is used to show how many children process we have
 if [ -z "$CREATEPKG_CHILD" ]; then
-  CREATEPKG_CHILD="1"
+    CREATEPKG_CHILD="1"
 else
-  CREATEPKG_CHILD="`echo $CREATEPKG_CHILD + 1 | bc -l`"
+    CREATEPKG_CHILD="`echo $CREATEPKG_CHILD + 1 | bc -l`"
 fi
 
 BASENAME="`basename $0`[$CREATEPKG_CHILD]"
@@ -200,65 +237,65 @@ check_config
 check_repo
 
 if [ -z "$1" ]; then
-  handle_error 2
-elif [ "$#" == "2" ]; then
-  if [ "$1" == "--search" ]; then
-    find_script $2
-    exit
-  elif [ "$1" == "--install" ]; then
-    PACKAGE="$2"
-    INSTALL="1"
-  elif [ "$1" == "--no-deps" ]; then
-    NO_DEPS="1"
-    PACKAGE="$2"
-  else
     handle_error 2
-  fi
+elif [ "$#" == "2" ]; then
+    if [ "$1" == "--search" ]; then
+        find_script $2
+        exit
+    elif [ "$1" == "--install" ]; then
+        PACKAGE="$2"
+        INSTALL="1"
+    elif [ "$1" == "--no-deps" ]; then
+        NO_DEPS="1"
+        PACKAGE="$2"
+    else
+        handle_error 2
+    fi
 elif [ "$1" == "--sync" ]; then
-  sync_repo 
-  exit
+    sync_repo
+    exit
 elif [ "${1:0:1}" != "-" ]; then
-  PACKAGE="$1"
+    PACKAGE="$1"
 else
-  handle_error 2
+    handle_error 2
 fi
 
 if [ "$SYNC" == "yes" ]; then
-  sync_repo
+    sync_repo
 fi
 
 BUILD_SCRIPT="`find_script $PACKAGE`"
 
 if [ -z "$BUILD_SCRIPT" ]; then
-  handle_error 5 $PACKAGE
+    handle_error 5 $PACKAGE
 fi
 
 SCRIPT_BASE="`dirname $BUILD_SCRIPT`"
-echo $BASENAME: found script $PACKAGE.SlackBuild, now checking for dependencies
+echo -e "$CL_MENSG $BASENAME: found script $PACKAGE.SlackBuild, now checking for dependencies $CL_OFF"
 
 # sets the package's slack-required
 if [ -f "$SCRIPT_BASE/$PACKAGE.slack-required" ]; then
-  SLACK_REQ="$SCRIPT_BASE/$PACKAGE.slack-required"
+    SLACK_REQ="$SCRIPT_BASE/$PACKAGE.slack-required"
 elif [ -f "$SCRIPT_BASE/slack-required" ]; then
-  SLACK_REQ="$SCRIPT_BASE/slack-required"
+    SLACK_REQ="$SCRIPT_BASE/slack-required"
 fi
 
 if [ ! -z "$SLACK_REQ" ] && [ "$NO_DEPS" != "1" ]; then
-  # this routine checks for dependencies in package's slack-required
-  while read dep; do
-    if [ ! -z "$dep" ]; then
-      program="`echo $dep | awk '{ print $1 }'`"
-      condition="`echo $dep | awk '{ print $2 }' | sed -e 's/>=/equalorgreater/' -e 's/=</equalorless/' -e 's/</less/' -e 's/>/greater/' -e 's/=/equal/'`"
-      version="`echo $dep | awk '{ print $3 }' | tr -dc '[:digit:]'`"
-      solve_dep $program $condition $version
-    fi
-  done < <( cat $SLACK_REQ )
-  echo $BASNEMAE: done checking for $PACKAGE dependencies
+    # this routine checks for dependencies in package's slack-required
+    while read dep; do
+        if [ ! -z "$dep" ]; then
+            program="`echo $dep | awk '{ print $1 }'`"
+            condition="`echo $dep | awk '{ print $2 }' | sed -e 's/>=/equalorgreater/' -e 's/=</equalorless/' -e 's/</less/' -e 's/>/greater/' -e 's/=/equal/'`"
+            version="`echo $dep | awk '{ print $3 }' | tr -dc '[:digit:]'`"
+            solve_dep $program $condition $version
+        fi
+    done < <( cat $SLACK_REQ )
+    echo -e "$CL_MENSG $BASNEMAE: done checking for $PACKAGE dependencies $CL_OFF"
 else
-  echo $BASENAME: no unmet dependencies for $PACKAGE
+    echo -e "$CL_MENSG $BASENAME: no unmet dependencies for $PACKAGE $CL_OFF"
 fi
 
-echo $BASENAME: processing `basename $BUILD_SCRIPT`
+echo -e "$CL_MENSG $BASENAME: processing `basename $BUILD_SCRIPT` $CL_OFF"
 
 # built package
 cd $SCRIPT_BASE
@@ -268,9 +305,9 @@ INTERACT=no ./`basename $BUILD_SCRIPT`
 handle_error $? $PACKAGE
 
 if [ "$INSTALL" == "1" ]; then
-  # as we dont have the full package file name, we'll
-  # use the newer file name that matches our wildcard:
-  PACKAGE="`ls -1 -c $REPOS/$PACKAGE-*-*-*tgz | head -n 1`"
-  upgradepkg --install-new $PACKAGE
+    # as we dont have the full package file name, we'll
+    # use the newer file name that matches our wildcard:
+    PACKAGE="`ls -1 -c $REPOS/$PACKAGE-*-*-*tgz | head -n 1`"
+    upgradepkg --install-new $PACKAGE
 fi