#!/bin/bash # # common.sh: common functions for simplepkg # feedback: rhatto at riseup.net # # common.sh is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or any later version. # # common.sh is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place - Suite 330, Boston, MA 02111-1307, USA # BASE_CONF="/etc/simplepkg" CONF="$BASE_CONF/simplepkg.conf" JAIL_LIST="$BASE_CONF/jailist" SIMPLARET="simplaret" # ----------------------------------------------- # pkgtool functions # ----------------------------------------------- function package_name { # get the package name # in some places (like in /var/log/packages), the package name is appended with # an -upgrade information that should be striped basename $1 .tgz | sed -e 's/-upgraded-[0-9]*-[0-9]*-[0-9]*,[0-9]*:[0-9]*:[0-9]*$//' \ -e 's/-[^-]*-[^-]*-[^-]*$//' } # ----------------------------------------------- # package info functions # ----------------------------------------------- function package_version { # get VERSION from a package name local file pack version file="`basename $1`" pack="`package_name $1`" echo $file | sed -e "s/^$pack-//" | cut -d "-" -f 1 } function package_arch { # get ARCH from a package name local file pack arch basename $1 | sed -e 's/.*\-\(.*\)\-.*.tgz$/\1/' -e 's/_slamd64$//g' -e 's/_sflack$//g' } function package_build { # get BUILD from a package name local file pack build basename $1 | sed -e 's/.*\-.*\-\(.*\).tgz$/\1/' } # ----------------------------------------------- # package administrative functions # ----------------------------------------------- function install_packages { local check installed unable_to_install root # check if is time to clean the local repository if [ "$SIMPLARET_CLEAN" == "1" ]; then ARCH=$ARCH VERSION=$VERSION $SIMPLARET --purge elif [ ! -z "$SIMPLARET_PURGE_WEEKS" ] && [ "$SIMPLARET_PURGE_WEEKS" != "0" ]; then ARCH=$ARCH VERSION=$VERSION $SIMPLARET --purge -w $SIMPLARET_PURGE_WEEKS fi root="$JAIL_ROOT/$server" mkdir -p $root/var/log/packages # now tries to install each package listed in the template for pack in `cat $TEMPLATE | grep -v -e "^#" | cut -d : -f 1 | awk '{ print $1 }'`; do # try to install the package ROOT=/$root ARCH=$ARCH VERSION=$VERSION $SIMPLARET --install $pack --skip-checks # check if the package was installed pack="`echo $pack | sed -e 's/\+/\\\+/'`" installed=`eval "ls /$root/var/log/packages/ | egrep -E '^$pack-[^-]+-[^-]+-[^-]+$'"` check=$? if [ ! -z "$installed" ] && [ "$check" == "0" ]; then # the package is installed if [ ! -z "$SIMPLARET_DELETE_DURING" ] && [ "$SIMPLARET_DELETE_DURING" != "0" ]; then SILENT=1 ARCH=$ARCH VERSION=$VERSION $SIMPLARET --purge fi else unable_to_install="$unable_to_install\n\t`echo $pack | sed -e 's/\\\+/\+/'`" fi done # purge packages, if needed if [ "$SIMPLARET_DELETE_DOWN" == "1" ]; then ARCH=$ARCH VERSION=$VERSION $SIMPLARET --purge fi if [ ! -z "$unable_to_install" ]; then echo "mkjail was unable to install the following packages on $root:" echo -e "$unable_to_install" fi } function remove_packages { for pack in `cat $TEMPLATE | grep -v -e "^#" | cut -d : -f 1`; do ROOT=/$JAIL_ROOT/$server removepkg $pack done } # ----------------------------------------------- # config file functions # ----------------------------------------------- function eval_parameter { # usage: eval $1 parameter from $CONF # return the evaluated parameter if available or $2 $3 ... $n if grep -qe "^$1=" $CONF; then grep -e "^$1=" $CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | sed -e 's/ *#.*$//' else shift echo $* fi } function set_constants { # Set common constants # on/off on=1 off=0 # yes/no yes=1 no=0 } function eval_boolean_parameter { # get a boolean parameter from the configuration local value # get the value value="`eval_parameter $1 $2`" convert_boolean $value } function convert_boolean { # force case insensitiveness local value="`echo $1 | tr '[:upper:]' '[:lower:]'`" # convert it to wheter 0 or 1 if [ "$value" == "yes" ] || [ "$value" == "1" ] || [ "$value" == "on" ]; then echo 1 else echo 0 fi } function eval_config { # simplepkg config file evaluation # usage: eval_config [-u] if [ -f "$CONF" ]; then DEFAULT_ARCH="`eval_parameter DEFAULT_ARCH $(default_arch)`" DEFAULT_VERSION="`eval_parameter DEFAULT_VERSION $(default_version)`" STORAGE="`eval_parameter STORAGE /var/simplaret/packages`" JAIL_ROOT="`eval_parameter JAIL_ROOT /vservers`" PATCHES_DIR="`eval_parameter PATCHES_DIR /var/simplaret/patches`" ROOT_PRIORITY="`eval_parameter ROOT_PRIORITY patches slackware extra testing pasture`" REPOS_PRIORITY="`eval_parameter REPOS_PRIORITY patches slackware extra testing pasture`" SIMPLARET_PURGE_WEEKS="`eval_parameter SIMPLARET_PURGE_WEEKS 0`" FTP_TOOL="`eval_parameter FTP_TOOL curl`" HTTP_TOOL="`eval_parameter HTTP_TOOL curl`" CONNECT_TIMEOUT="`eval_parameter CONNECT_TIMEOUT 0`" TEMPLATE_FOLDER="`eval_parameter TEMPLATE_BASE /etc/simplepkg/templates`" TEMPLATE_STORAGE_STYLE="`eval_parameter TEMPLATE_STORAGE_STYLE own-folder`" SIMPLARET_CLEAN="`eval_boolean_parameter SIMPLARET_CLEAN 1`" SIMPLARET_DELETE_DOWN="`eval_boolean_parameter SIMPLARET_DELETE_DOWN 1`" SIMPLARET_UPDATE="`eval_boolean_parameter SIMPLARET_UPDATE 0`" SIMPLARET_DELETE_DURING="`eval_boolean_parameter SIMPLARET_DELETE_DURING 0`" SIMPLARET_PURGE_PATCHES="`eval_boolean_parameter SIMPLARET_PURGE_PATCHES 1`" SIMPLARET_DOWNLOAD_FROM_NEXT_REPO="`eval_boolean_parameter SIMPLARET_DOWNLOAD_FROM_NEXT_REPO 1`" PASSIVE_FTP="`eval_boolean_parameter PASSIVE_FTP 0`" WARNING="`eval_boolean_parameter WARNING 0`" SIGNATURE_CHECKING="`eval_boolean_parameter SIGNATURE_CHECKING 0`" DEPENDENCY_CHECKING="`eval_boolean_parameter DEPENDENCY_CHECKING 1`" TEMPLATES_UNDER_SVN="`eval_boolean_parameter TEMPLATES_UNDER_SVN 0`" ADD_TO_JAIL_LIST="`eval_boolean_parameter ADD_TO_JAIL_LIST 1`" # Enabling this option (i.e, setting to "1" or "yes"), simplaret will # donwload even # already applied patches, a good option when you plan # to keep local copies of all needed patches for your system DOWNLOAD_EVEN_APPLIED_PATCHES="`eval_boolean_parameter DOWNLOAD_EVEN_APPLIED_PATCHES 0`" # Enabling this option, jail-upgrade will look at your # standard repositories for new packages; if it find a package # with different version of your current installed package and # also this package isnt in the packages folder, then the new # package is apllied; if in doubt, just say no or leave blank. CONSIDER_ALL_PACKAGES_AS_PATCHES="`eval_boolean_parameter CONSIDER_ALL_PACKAGES_AS_PATCHES 0`" # Enabling this option (i.e, setting to "1" or "yes"), simplaret will # store patches it finds on ROOT repositories on # # $PATCHES_DIR/$ARCH/$VERSION/root-$repository_name. # # By default this option is turned off because it breaks the standard # way to store packages and can cause some confusion, but its an useful # feature if you like to see all patches apart from common packages and/or # stored in the same tree. STORE_ROOT_PATCHES_ON_PATCHES_DIR="`eval_boolean_parameter STORE_ROOT_PATCHES_ON_PATCHES_DIR 0`" # now we place "patches" on the top of ROOT_PRIORITY ROOT_PRIORITY="patches `echo $ROOT_PRIORITY | sed -e 's/patches//'`" else echo $1 error: config file $CONFIG not found exit 1 fi if [ ! -d "$STORAGE" ]; then mkdir -p $STORAGE fi if [ ! -d "$PATCHES_DIR" ]; then mkdir -p $PATCHES_DIR fi if [ -z "$ARCH" ]; then ARCH="$DEFAULT_ARCH" fi if [ -z "$VERSION" ]; then VERSION="$DEFAULT_VERSION" fi if [ "$FTP_TOOL" != "wget" ] && [ "$FTP_TOOL" != "curl" ] && [ "$FTP_TOOL" != "ncftpget" ]; then echo "$1 configuration error: invalid value $FTP_TOOL for config parameter FTP_TOOL" echo "$1 assuming value \"curl\" for variable FTP_TOOL" FTP_TOOL="curl" fi if [ "$HTTP_TOOL" != "wget" ] && [ "$HTTP_TOOL" != "curl" ]; then echo "$1 configuration error: invalid value $HTTP_TOOL for config parameter HTTP_TOOL" echo "$1 assuming value \"curl\" for variable HTTP_TOOL" HTTP_TOOL="curl" fi if which $SIMPLARET &> /dev/null; then if [ "$SIMPLARET_UPDATE" == "1" ]; then if [ "$2" == "-u" ]; then ARCH=$ARCH VERSION=$VERSION $SIMPLARET --update fi fi else echo "$SIMPLARET not found, please install it before run $0" fi if [ "$TEMPLATE_STORAGE_STYLE" != "simplepkg-folder" ] && \ [ "$TEMPLATE_STORAGE_STYLE" != "templates-folder" ] && \ [ "$TEMPLATE_STORAGE_STYLE" != "own-folder" ]; then TEMPLATE_STORAGE_STYLE="own-folder" fi if [ ! -z "$ROOT" ]; then JAIL_ROOT="$ROOT" fi } # ----------------------------------------------- # arch and version functions # ----------------------------------------------- function default_version { # get version from /etc/slackware-version if [ -f "$1/etc/slackware-version" ]; then cat $1/etc/slackware-version | awk '{ print $2 }' | sed -e 's/.0$//' elif [ -f "$1/etc/slamd64-version" ]; then cat $1/etc/slamd64-version | awk '{ print $2 }' | sed -e 's/.0$//' elif [ -f "$1/etc/bluewhite64-version" ]; then cat $1/etc/bluewhite64-version | awk '{ print $2 }' | sed -e 's/.0$//' elif [ -f "$1/etc/sflack-version" ]; then cat $1/etc/sflack-version | awk '{ print $2 }' | sed -e 's/.0$//' else aaa_base="`basename $(ls $1/var/log/packages/aaa_base-[0-9]* 2> /dev/null)`" echo `package_version $aaa_base` fi } function default_arch { # get arch from /etc/slackware-version local arch if [ -f "$1/etc/slackware-version" ]; then arch="`cat $1/etc/slackware-version | awk '{ print $3 }' | sed -e 's/(//' -e 's/)//'`" if [ -z "$arch" ]; then arch="i386" fi elif [ -f "$1/etc/slamd64-version" ] || [ -f "$1/etc/bluewhite64-version" ] || [ -f "$1/etc/sflack-version" ]; then arch="x86_64" else aaa_base="`basename $(ls $1/var/log/packages/aaa_base-[0-9]* 2> /dev/null)`" echo `package_arch $aaa_base` fi if [ -z "$arch" ]; then echo `uname -m` else echo $arch fi } # ----------------------------------------------- # template functions # ----------------------------------------------- function search_default_template { if [ -e "$BASE_CONF/default.template" ]; then TEMPLATE_BASE="$BASE_CONF/default" echo $BASENAME using default template elif [ -e "$TEMPLATE_FOLDER/default.template" ]; then TEMPLATE_BASE="$TEMPLATE_FOLDER/default" echo $BASENAME: using default template elif [ -e "$TEMPLATE_FOLDER/default/default.template" ]; then TEMPLATE_BASE="$TEMPLATE_FOLDER/default/default" echo $BASENAME: using default template elif [ -e "$BASE_CONF/defaults/templates/default/default.template" ]; then TEMPLATE_BASE="$BASE_CONF/defaults/templates/default" echo $BASENAME using default template else echo $BASENAME: error: default template not found echo $BASENAME: please create a template using templatepkg return 1 fi } function search_template { # determine the template to be used # usage: search-template [--new | --update] # # templates can be stored either on # # - $BASE_CONF/template_name.template # - $TEMPLATE_FOLDER/template_name.template # - $TEMPLATE_FOLDER/template_name/template_name.template # # also, there's a folder for "oficial" simplepkg templates, # $BASE_CONF/defaults/templates/ and you can override any template # in the default folder by placing a template with the same name # in the template storage folders # if [ -f "$BASE_CONF/$1.template" ]; then TEMPLATE_BASE="$BASE_CONF/$1" elif [ -f "$TEMPLATE_FOLDER/$1.template" ]; then TEMPLATE_BASE="$TEMPLATE_FOLDER/$1" elif [ -f "$TEMPLATE_FOLDER/$1/$1.template" ]; then TEMPLATE_BASE="$TEMPLATE_FOLDER/$1/$1" elif [ -f "$BASE_CONF/defaults/templates/$1/$1.template" ] && \ [ "$2" != "--update" ]; then TEMPLATE_BASE="$BASE_CONF/defaults/templates/$1/$1" else if [ "$2" == "--new" ]; then # we need to return the path for a new template if [ "$TEMPLATE_STORAGE_STYLE" == "simplepkg-folder" ]; then TEMPLATE_BASE="$BASE_CONF/$1" elif [ "$TEMPLATE_STORAGE_STYLE" == "templates-folder" ]; then TEMPLATE_BASE="$TEMPLATE_FOLDER/$1" else TEMPLATE_BASE="$TEMPLATE_FOLDER/$1/$1" fi elif [ "$2" == "--update" ]; then return 1 else echo $BASENAME: template $1 not found search_default_template fi fi } # ----------------------------------------------- # unix permission functions # ----------------------------------------------- function numeric_perm { # get the numeric permission of a file # usage: numeric_perm # just a bit of forbidden secrets if [ -a "$1" ]; then ls -lnd $1 | awk '{ print $1 }' | \ sed -e 's/^.//' -e 's/r/4/g' -e 's/w/2/g' -e 's/x/1/g' \ -e 's/-/0/g' -e 's/\(.\)\(.\)\(.\)/\1+\2+\3/g' | \ fold -w5 | bc -l | xargs | sed -e 's/ //g' fi } function get_owner { # get the numeric owner for a file # usage: get_owner if [ -a "$1" ]; then ls -lnd $1 | awk '{ print $3 }' fi } function get_group { # get the numeric group for a file # usage: get_group if [ -a "$1" ]; then ls -lnd $1 | awk '{ print $4 }' fi } # ----------------------------------------------- # subversion functions # ----------------------------------------------- function use_svn { # check if svn usage is enabled if [ "$TEMPLATES_UNDER_SVN" == "1" ] && \ [ "$TEMPLATE_STORAGE_STYLE" == "own-folder" ]; then return 0 else return 1 fi } function svn_check { # check if a file is under svn # usage: svn_check local cwd folder cwd="`pwd`" folder="`dirname $1`" if [ -d "$folder/.svn" ]; then cd $folder if [ "`svn status $1 | awk '{ print $1 }'`" == "?" ]; then return 1 else return 0 fi cd $cwd else return 1 fi } # ----------------------------------------------- # update jail functions # ----------------------------------------------- function update_template_files { # update template files from svn # usage: update_template_files if use_svn && [ -d "$TEMPLATE_BASE.d/.svn" ]; then echo Checking out last template revision from svn... cd `dirname $TEMPLATE_BASE` svn update fi } function update_jail_packages { # update jail packages according the template # usage: update_jail_packages # check if installed packages are listed in the template for pack in `ls -1 $1/var/log/packages/`; do pack=`package_name $pack` if ! `grep -v -e "^#" $TEMPLATE_BASE.template | cut -d : -f 1 | awk '{ print $1 }' | grep -q -e "^$pack\$"`; then ROOT=$1 removepkg $pack fi done # check if each package from the template is installed grep -v -e "^#" $TEMPLATE_BASE.template | cut -d : -f 1 | awk '{ print $1 }' | while read pack; do # check if the package is installed pack="`echo $pack | sed -e 's/\+/\\\+/'`" installed=`eval "ls /$1/var/log/packages/ | egrep -E '^$pack-[^-]+-[^-]+-[^-]+$'"` check=$? if [ -z "$installed" ] || [ "$check" != "0" ]; then # the package isn't installed ROOT=$1 simplaret install $pack fi done } function copy_template_files { # copy template files into jail # usage: copy_template_files if [ -d "$1" ]; then if [ -d "$TEMPLATE_BASE.d" ]; then echo "Copying template files to $1..." if use_svn && [ -d "$TEMPLATE_BASE.d/.svn" ]; then rsync -av --exclude=.svn $TEMPLATE_BASE.d/ $1/ else rsync -av $TEMPLATE_BASE.d/ $1/ fi fi fi } function set_jail_perms { # set template file permissions under a jail # usage: set_jail_perms if [ -s "$TEMPLATE_BASE.perms" ]; then echo Setting jail $1 permissions... cat $TEMPLATE_BASE.perms | while read entry; do file="`echo $entry | cut -d ";" -f 1`" if [ -e "$TEMPLATE_BASE.d/$file" ] && [ -a "$1/$file" ]; then owner="`echo $entry | cut -d ";" -f 2`" group="`echo $entry | cut -d ";" -f 3`" perms="`echo $entry | cut -d ";" -f 4`" chmod $perms $1/$file chown $owner:$group $1/$file fi done fi } # ----------------------------------------------- # repository build functions # ----------------------------------------------- function svn_add_meta { find . -name '*meta' -exec svn add {} 2> /dev/null \; } function gen_filelist { # generate FILELIST.TXT # usage: gen_filelist find . -type f -name '*.tgz' -follow -print | sort | tr '\n' '\0' | \ xargs -0r ls -ldL --time-style=long-iso > FILELIST.TXT echo "Created new FILELIST.TXT" } function gen_patches_filelist { # generate FILE_LIST # usage: gen_patches_filelist if [ ! -z "$1" ] && [ -d "$1" ]; then cwd="`pwd`" cd $1 find . -type f -name '*.tgz' -follow -print | sort | tr '\n' '\0' | \ xargs -0r ls -ldL --time-style=long-iso > FILE_LIST cd $cwd if [ "$1" == "." ]; then echo "Created new FILE_LIST" else echo "Created new $1/FILE_LIST" fi fi } function gen_packages_txt { # generate PACKAGES.TXT # usage: gen_packages_txt if [ ! -z "$1" ] && [ -d "$1" ]; then cwd="`pwd`" cd $1 echo '' > PACKAGES.TXT find . -type f -name '*.meta' -exec cat {} \; >> PACKAGES.TXT cat PACKAGES.TXT | gzip -9 -c - > PACKAGES.TXT.gz cd $cwd if [ "$1" == "." ]; then echo "Created new PACKAGES.TXT and PACKAGES.TXT.gz" else echo "Created new $1/PACKAGES.TXT and $1/PACKAGES.TXT.gz" fi fi } function gen_md5_checksums { # generate CHECKSUMS.md5 # usage: gen_md5_checksums if [ -d "$1" ]; then cwd="`pwd`" cd $1 echo '' > CHECKSUMS.md5 find . -type f -name '*.tgz' -exec md5sum {} \; >> CHECKSUMS.md5 cat CHECKSUMS.md5 | gzip -9 -c - > CHECKSUMS.md5.gz cd $cwd if [ "$1" == "." ]; then echo "Created new CHECKSUMS.md5 and CHECKSUMS.md5.gz" else echo "Created new $1/CHECKSUMS.md5 and $1/CHECKSUMS.md5.gz" fi fi } function gen_meta { # generate metafiles # usage: gen_meta if [ ! -f $1 ]; then echo "File not found: $1" exit 1; else echo "Processing $1" fi if [ "`echo $1|grep -E '(.*{1,})\-(.*[\.\-].*[\.\-].*).tgz[ ]{0,}$'`" == "" ]; then return; fi NAME=$(echo $1 | sed -re "s/(.*\/)(.*.tgz)$/\2/") LOCATION=$(echo $1 | sed -re "s/(.*)\/(.*.tgz)$/\1/") SIZE=$( expr `gunzip -l $1 | tail -n 1 | awk '{print $1}'` / 1024 ) USIZE=$( expr `gunzip -l $1 | tail -n 1 | awk '{print $2}'` / 1024 ) REQUIRED=$(tar xzfO $1 install/slack-required 2>/dev/null | xargs -r -iZ echo -n "Z," | sed -e "s/,$//") CONFLICTS=$(tar xzfO $1 install/slack-conflicts 2>/dev/null | xargs -r -iZ echo -n "Z," | sed -e "s/,$//") SUGGESTS=$(tar xzfO $1 install/slack-suggests 2>/dev/null | xargs -r ) METAFILE=${NAME%tgz}meta echo "PACKAGE NAME: $NAME" > $LOCATION/$METAFILE if [ -n "$DL_URL" ]; then echo "PACKAGE MIRROR: $DL_URL" >> $LOCATION/$METAFILE fi echo "PACKAGE LOCATION: $LOCATION" >> $LOCATION/$METAFILE echo "PACKAGE SIZE (compressed): $SIZE K" >> $LOCATION/$METAFILE echo "PACKAGE SIZE (uncompressed): $USIZE K" >> $LOCATION/$METAFILE echo "PACKAGE REQUIRED: $REQUIRED" >> $LOCATION/$METAFILE echo "PACKAGE CONFLICTS: $CONFLICTS" >> $LOCATION/$METAFILE echo "PACKAGE SUGGESTS: $SUGGESTS" >> $LOCATION/$METAFILE echo "PACKAGE DESCRIPTION:" >> $LOCATION/$METAFILE tar xzfO $1 install/slack-desc | grep -E '\w+\:' | grep -v '^#' >> $LOCATION/$METAFILE echo "" >> $LOCATION/$METAFILE } # ----------------------------------------------- # 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 ERROR_NOT_NUMBER=101 # argument is not a number ERROR_PAR_NUMBER=102 # incorrect number of parameters ERROR_COMMON_NOT_FOUND=103 # common.sh 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 ERROR_MKBUILD_SVN=504 # Mkpatch error codes ERROR_MKPATCH=600 } 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!" ;; $ERROR_NOT_NUMBER) eecho $error "$BASENAME: $2 need a number argument" ;; $ERROR_PAR_NUMBER) eecho $error "$BASENAME: incorrect number of parameters" ;; #$ERROR_COMMON_NOT_FOUND) # eecho $error "$BASENAME: file $COMMON_SH not found. Check your $BASENAME installation" ;; # # 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\"." ;; $ERROR_MKPATCH) eecho $error "$BASENAME: Mkpatch error. Check .mkbuild file." ;; $ERROR_MKBUILD_VCS) eecho $error "$BASENAME: VCS or empty URL. Disable this sections in .mkbuild file:\n - download_source;\n - md5sum_download_and_check_0;\n - md5sum_download_and_check_1;\n - gpg_signature_check\n - untar_source" ;; # # Others errors *) eecho $error "$BASENAME: unknown error or user interrupt" ;; esac is_number $1 && exit $1 || 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 # ----------------------------------------------- function slash { # remove additional slashes echo $* | sed -e 's/\/\+/\//g' } function color_select { # Select color mode: gray, color or none (*) # commun - Communication # messag - Commum messages # error - Error messages # normal - turn off color case "$1" in 'gray') # colors normal="\033[m" dark_gray="\033[30;1m" gray="\033[37m" white="\033[37;1m" red=$dark_gray blue=$dark_gray green=$gray yellow=$gray # Actions commun=$white messag=$white error=$dark_gray alert=$gray ;; 'color') # colors normal="\033[m" dark_gray="\033[30;1m" gray="\033[37m" white="\033[37;1m" red="\033[31;1m" blue="\033[34;1m" green="\033[32;1m" yellow="\033[33;1m" # Actions commun=$green messag=$blue error=$red alert=$yellow ;; *) commun="" messag="" error="" alert="" ;; esac } function eecho { # echoes a message # usage: eecho # message-type can be: commun, messag, error, normal echo -e "${1}${2}${normal}" } 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 }