]> gitweb.fluxo.info Git - simplepkg.git/commitdiff
createpkg: instala pacotes da árvore oficial do slackware, durante a resolução de...
authorrudson <rudson@04377dda-e619-0410-9926-eae83683ac58>
Thu, 4 Jan 2007 01:21:51 +0000 (01:21 +0000)
committerrudson <rudson@04377dda-e619-0410-9926-eae83683ac58>
Thu, 4 Jan 2007 01:21:51 +0000 (01:21 +0000)
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@78 04377dda-e619-0410-9926-eae83683ac58

simplepkg.SlackBuild
src/createpkg

index 0d3a2c88626d30fc4efb49c17f4d25f8934177fa..fb790d639b6bbe3ecf70f4c384fe101456ec418e 100755 (executable)
@@ -52,6 +52,7 @@ chmod +x $PACK_DIR/etc/$PACKAGE/vserver.s/*.sh
 chmod +x $PACK_DIR/etc/$PACKAGE/vserver-legacy.s/*.sh
 cp conf/simplepkg.conf.new $PACK_DIR/etc/$PACKAGE
 cp conf/repos.conf.new $PACK_DIR/etc/$PACKAGE
+cp conf/createpkg.conf.new $PACK_DIR/etc/$PACKAGE
 cd $PACK_DIR/usr/sbin && ln -s jail-upgrade vserver-upgrade
 cd -
 
@@ -60,3 +61,7 @@ chown -R root.root *
 
 makepkg -c y -l y ../simplepkg-$VERSION-$ARCH-$BUILD.tgz
 cd ..
+
+if [ "$CLEANUP" != "no" ]; then
+    rm -rf $PACK_DIR
+fi
index 1523933d33fab5451ff6b23a1deddceea2764f1a..8c4e7de205d9ad76bc3994a3de837d8808082d5e 100644 (file)
 #
 # - optionally show a dependency tree before create the package
 # - in function solve_dep: resolve program versions
-#
+# - mkdir source directory - error... (please check!)
 
 #---------------------------------------------------
 #               Createpkg functions
 #---------------------------------------------------
+
+function error_codes {
+
+    # Slackbuilds error codes
+    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
+
+    # Createpkg error codes
+    ERROR_INSTPKG=200    # installpkg error
+    ERROR_DEPEN=201      # dependency error
+
+}
+
 function handle_error {
 
     # This function deals with internal createpkg errors
@@ -42,14 +65,12 @@ function handle_error {
     # 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_PATCH=40;     ERROR_VCS=41;       ERROR_MKDIR=42
     #
     # 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
+    [ "$1" == "0" ] && return
 
     # Exit codes
     case $1 in
@@ -57,18 +78,21 @@ function handle_error {
         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" ;;
+        $ERROR_WGET)    echo -e "$CL_ERROR $BASENAME: error downloading source/package for $2 $CL_OFF" ;;
+        $ERROR_MAKE)    echo -e "$CL_ERROR $BASENAME: error compiling $2 source code $CL_OFF" ;;
+        $ERROR_INSTALL) echo -e "$CL_ERROR $BASENAME: error installing $2 $CL_OFF" ;;
+        $ERROR_MD5)     echo -e "$CL_ERROR $BASENAME: error on source code integrity check for $2 $CL_OFF" ;;
+        $ERROR_CONF)    echo -e "$CL_ERROR $BASENAME: error configuring the source code for $2 $CL_OFF" ;;
+        $ERROR_HELP)    exit 0 ;; # its supposed to never happen here :P
+        $ERROR_TAR)     echo -e "$CL_ERROR $BASENAME: error decompressing source code for $2 $CL_OFF" ;;
+        $ERROR_MKPKG)   echo -e "$CL_ERROR $BASENAME: error creating package $2 $CL_OFF" ;;
+        $ERROR_GPG)     echo -e "$CL_ERROR $BASENAME: error verifying GPG signature the source code for $2 $CL_OFF" ;;
+        $ERROR_PATCH)   echo -e "$CL_ERROR $BASENAME: error patching the source code for $2 $CL_OFF" ;;
+        $ERROR_VCS)     echo -e "$CL_ERROR $BASENAME: error downloading $2 source from version control system $CL_OFF" ;;
+        $ERROR_MKDIR)   echo -e "$CL_ERROR $BASENAME: make directory $2 error, aborting $CL_OFF" ;;
+        $ERROR_INSTPKG) echo -e "$CL_ERROR $BASENAME: install package $2 error, aborting $CL_OFF" ;;
+        $ERROR_DEPEN)   echo -e "$CL_ERROR $BASENAME: dependency solve error, aborting $CL_OFF" ;;
+        *) echo -e "$CL_ERROR $BASENAME: unknown error or user interrupt $CL_OFF" ;;
     esac
 
     exit $1
@@ -89,21 +113,25 @@ function build_repo {
 function usage {
 
     # Help mensage
-    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 --info package-name $CL_OFF"
-    echo -e "$CL_COMMU        createpkg --list $CL_OFF"
+    echo -e "$CL_COMMU Usage: createpkg [--install/-i] package-name $CL_OFF"
+    echo -e "$CL_COMMU        createpkg --no-deps/-np package-name $CL_OFF"
+    echo -e "$CL_COMMU        createpkg --search/-s package-name $CL_OFF"
+    echo -e "$CL_COMMU        createpkg --info/-f package-name $CL_OFF"
+    echo -e "$CL_COMMU        createpkg --list/-l $CL_OFF"
     echo -e "$CL_COMMU        createpkg --sync $CL_OFF"
-    echo -e "$CL_COMMU        createpkg --help $CL_OFF"
+    echo -e "$CL_COMMU        createpkg --help/-h $CL_OFF"
 
 }
 
 function check_config {
 
     # check the configuration
-    TMP=${TMP:=/tmp}
-    REPOS=${REPOS:=$TMP}
+    TMP=${TMP:=/tmp};
+    REPOS=${REPOS:=$TMP};
+    # Create $TMP and $REPOS if need
+    [ ! -e $TPM ] && mkdir $TMP
+    [ ! -e $REPOS ] && mkdir $REPOS
+    #
     SLACKBUILDS=${SLACKBUILDS:=/var/slackbuilds}
     SVN=${SVN:=svn://slack.sarava.org/slackbuilds}
     SYNC=${SYNC:=no}
@@ -112,64 +140,71 @@ function check_config {
 }
 
 function solve_dep {
-
     # Solve dependency
-    pack="$1"
-    cond="$2"
-    ver="$3"
+    local PACK="$1"
+    local COND="$2"
+    local VER="$3"
+
+    # Check package in local system
+    local INSTALLED=`eval "ls /var/log/packages/ | egrep '^$PACK-[^-]+-[^-]+-[^-]+$'"`
+
+    # TODO: Make check version procedures
+    if [ -z $INSTALLED ]; then
+        createpkg_simplaret --slack_install $PACK # Install package from official Slackware tree
+        if [ $? -ne 0 ]; then
+            # Check package in SlackBuilds tree
+            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="$?"
+            [ "$EXIT_CODE" != "0" ] && handle_error $EXIT_CODE
+        fi
+    fi
 
-    #if [ "$cond" != "e" ] && [ "$cond" != "l" ] && [ "$cond" != "ge" ] && [ "$cond" != "le" ] && [ ! -z "$cond" ]; then
-    #if [ ! -z "$cond" ]; then
-        # slack-required has a wrong logical sentence, so we ignore it
-        check_version="no"
-    #fi
+}
 
-    #found="0"
+function createpkg_simplaret {
+    local SLACK_MIRROR="http://slackware.cs.utah.edu/pub/slackware/slackware-$DEFAULT_VERSION"
 
-    #
-    candidate=`eval "ls /var/log/packages/ | egrep '^$pack-[^-]+-[^-]+-[^-]+$'"`
-    [ "$candidate" = "" ] && found=1 || found=0 # 0 to notfound
-    #
-    #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
-
-    # Notes:
-    # Make one list of slackware packages
-    # cat /slackware-mirror/FILELIST.TXT | grep 'tgz$' | awk '{print $8}' | sed -r 's,.*/(.*)-.*-.*-.*\..*$,\1,' | sort
-    # with version
-    # cat /slackware-mirror/FILELIST.TXT | grep 'tgz$' | awk '{print $8}' | sed -r 's,.*/(.*-.*)-.*-.*\..*$,\1,' | sort
-
-    # TODO: Change this...
-    if [ $found -eq 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
+    # Slackware FILELIST. ( put after 'source COMMON' command )
+    SLACK_FILELIST="$STORAGE/$DEFAULT_ARCH/$DEFAULT_VERSION/FILELIST.TXT"
+
+    # Verify parameters number
+    [ $# -lt 1 ] && exit 32
 
+
+    case $1 in
+        '--slack_install')
+            # Install package from Slackware mirror
+            # Check package in Slackware tree
+            local CANDIDATE=`eval "cat $SLACK_FILELIST | egrep '\/$2-[^-]+-[^-]+-[^-]\.tgz$'" | awk '{print $8}' | sort -r | head -n1`
+            [ -z $CANDIDATE ] && return 31
+            #
+            local PACK=$CANDIDATE
+            local PKG_NAME=`basename $PACK`
+            local REPOS_DIR=$REPOS/slackware-$DEFAULT_VERSION/${PACK#./}
+
+            # Make repository directory
+            if [ ! -e $REPOS_DIR ]; then
+                mkdir -p $REPOS_DIR || handle_error $ERROR_MKDIR $REPOS_DIR
+            fi
+
+            # Download package from slackware mirror
+            wget $SLACK_MIRROR/$PACK --directory-prefix=$REPOS_DIR/ || handle_error $ERROR_WGET $PACK
+
+            # Install slackware package
+            installpkg $REPOS_DIR/$PKG_NAME || handle_error $ERROR_INSTPKG $PKG_NAME
+        ;;
+        *)
+            echo "None..."
+        ;;
+    esac
 }
 
 function check_repo {
 
     # Verify if repository exist
-    if [ ! -d "$SLACKBUILDS" ]; then
-        build_repo
-    fi
+    [ ! -d "$SLACKBUILDS" ] && build_repo
 
 }
 
@@ -178,10 +213,11 @@ function sync_repo {
     # Synchronize repository
     cd $SLACKBUILDS
     svn update || build_repo
+    simplaret --update
 
 }
 
-function find_script {
+function find_slackbuild {
 
     # Find SlackBuild script in the repository
     find $SLACKBUILDS -name $1.SlackBuild
@@ -205,6 +241,11 @@ function info_builds {
                 eval "cat $i | grep '^$PACKAGE:' | cut -f2- -d:"
                 echo -e "$CL_OFF"
             fi
+
+            if [ -e $PKG_DIR/slack-required ]; then
+                echo -e "$CL_COMMU slack-required $CL_OFF"
+                cat $PKG_DIR/slack-required | sed 's/^/ /'
+            fi
         done
     fi
 
@@ -213,7 +254,6 @@ function info_builds {
 function list_builds {
 
     # List all available SlackBuilds
-    # find $SLACKBUILDS -name *.SlackBuild | sed -r 's,.*/(.*)\.SlackBuild$,\1,' | sort
     cd $SLACKBUILDS
     echo "Sarava SlackBuilds list"
     # level 1
@@ -250,63 +290,68 @@ function list_builds {
     done
 }
 
-#---------------------------------------------------
-#                 Starting createpkg
-#---------------------------------------------------
-# Common functions
-COMMON="/usr/libexec/simplepkg/common.sh"
-
-# TODO: SLACKBUILDRC is need?
-if [ -f ~/.slackbuildrc ]; then
-    SLACKBUILDRC=~/.slackbuildrc
-else
-    SLACKBUILDRC=/etc/slackbuildrc
-fi
-
-source $SLACKBUILDRC 2>/dev/null
-
-# 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
+function color_select {
+    # Select color mode: gray, color or none (*)
+    # CL_COMMU - Communication
+    # CL_MENSG - Commum messages
+    # CL_ERROR - Error messages
+    # CL_OFF   - turn off color
+    case "$1" 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
+        ;;
+    esac
+}
+
+#---------------------------------------------------
+#                 Starting createpkg
+#---------------------------------------------------
+# Common functions
+COMMON="/usr/libexec/simplepkg/common.sh"
+SIMPLEPKG_CONF="/etc/simplepkg/simplepkg.conf"
+
+# Loading error codes
+error_codes
 
 # 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"
+source $COMMON && source $SIMPLEPKG_CONF
+if [ $? -ne 0 ]; then
+    echo -e "$CL_ERROR error: file $COMMON not found, check your $BASENAME installation $CL_OFF"
     exit 1
 fi
 
+# Load slackbuildrc definitions
+if [ -f ~/.slackbuildrc ]; then
+    source ~/.slackbuildrc
+else
+    source /etc/slackbuildrc 2>/dev/null
+fi
+
+# Select color mode: gray, color or none (*)
+color_select $COLOR
+
 # This is used to show how many children process we have
 if [ -z "$CREATEPKG_CHILD" ]; then
     CREATEPKG_CHILD="1"
 else
-    #CREATEPKG_CHILD="`echo $CREATEPKG_CHILD + 1 | bc -l`"
     let CREATEPKG_CHILD++
 fi
 
@@ -318,12 +363,12 @@ check_repo
 case $1 in
     '--search'|'-s')
         [ $# -ne 2 ] && handle_error 2   # two parameters is required
-        find_script $2
+        find_slackbuild $2
         exit
     ;;
     '--info'|'-f')
         [ $# -ne 2 ] && handle_error 2   # two parameters is required
-        PKG_PATH=`find_script $2`
+        PKG_PATH=`find_slackbuild $2`
         info_builds
         exit
     ;;
@@ -339,15 +384,15 @@ case $1 in
     ;;
     '--sync')
         sync_repo
-        exit
+        exit 0
     ;;
     '--help'|'-h'|'')
         usage
-        exit
+        exit 0
     ;;
     '--list'|'-l')
         list_builds
-        exit
+        exit 0
     ;;
     *)
         if [ "${1:0:1}" != "-" ]; then
@@ -359,12 +404,10 @@ case $1 in
 esac
 
 # Synchronize repository
-if [ "$SYNC" == "yes" ]; then
-    sync_repo
-fi
+[ "$SYNC" == "yes" ] && sync_repo
 
 # Get SlackBuild script
-BUILD_SCRIPT="`find_script $PACKAGE`"
+BUILD_SCRIPT="`find_slackbuild $PACKAGE`"
 
 # Select one SlackBuild
 if [ "`echo $BUILD_SCRIPT | wc -w`" -gt 1 ]; then
@@ -386,9 +429,7 @@ else
 fi
 
 # Check SlackBuild script found
-if [ -z "$BUILD_SCRIPT" ]; then
-    handle_error 5 $PACKAGE
-fi
+[ -z "$BUILD_SCRIPT" ] && handle_error 5 $PACKAGE
 
 # Get dirname and script name from slackbuild
 SCRIPT_BASE="`dirname $BUILD_SCRIPT`"
@@ -397,22 +438,27 @@ echo -e "$CL_MENSG $BASENAME: found script $PACKAGE.SlackBuild, now checking for
 
 # Sets the package's slack-required
 if [ -f "$SCRIPT_BASE/$PACKAGE.slack-required" ]; then
-    SLACK_REQ="$SCRIPT_BASE/$PACKAGE.slack-required"
+    SLACK_REQUIRED="$SCRIPT_BASE/$PACKAGE.slack-required"
 elif [ -f "$SCRIPT_BASE/slack-required" ]; then
-    SLACK_REQ="$SCRIPT_BASE/slack-required"
+    SLACK_REQUIRED="$SCRIPT_BASE/slack-required"
 fi
 
-if [ ! -z "$SLACK_REQ" -a "$NO_DEPS" != "1" ]; then
+if [ ! -z "$SLACK_REQUIRED" -a "$NO_DEPS" != "1" ]; then
     # this routine checks for dependencies in package's slack-required
-    while read dep; do
+    ( cat $SLACK_REQUIRED | while read dep; do
         if [ ! -z "$dep" ]; then
-            program="`echo $dep | awk '{ print $1 }'`"
-            condition="`echo $dep | awk '{ print $2 }' | tr [=\>\<] [egl]`"
-            version="`echo $dep | awk '{ print $3 }' | tr -dc '[:digit:]'`"
-            solve_dep $program $condition $version
+            PROGRAM="`echo $dep | awk '{ print $1 }'`"
+            CONDITION="`echo $dep | awk '{ print $2 }' | tr [=\>\<] [egl]`"
+            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"
+        true
+    done )
+    if [ $? -ne 0 ]; then
+        echo -e "$CL_MENSG $BASENAME: dependency solve error $CL_OFF"
+        exit 1
+    fi
+    echo -e "$CL_MENSG $BASENAME: done checking for $PACKAGE dependencies $CL_OFF"
 else
     echo -e "$CL_MENSG $BASENAME: no unmet dependencies for $PACKAGE $CL_OFF"
 fi