#!/bin/bash # # createpkg: package builder using http://slack.sarava.org/slackbuilds scripts # feedback: rhatto at riseup.net | gpl # rudsonalves at yahoo.com.br # # createpkg 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. # # createpkg 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 # # /etc/simplepkg/slackbuildrc parameters: # # SLACKBUILDS_DIR="/folder/to/place/slackbuilds", defaults to /var/slackbuilds # SVN="svn://repository", defaults do svn://slack.sarava.org/slackbuilds # SYNC="yes|no", whether to always update the repository # #--------------------------------------------------- # Createpkg functions #--------------------------------------------------- CREATEPKG_VERSION="1.1.15" function usage { # Help message echo -e "${red}NAME${normal} createpkg - create Slackware packages from SlackBuilds in Sarava repository ${red}SYNOPSIS createpkg${normal} [${green}OPTIONS${normal}] [${green}program${normal}] ${red}DESCRIPTION${normal} [${green}program${normal}] name to build/search Input ${green}OPTIONS${normal}: ${red}-i${normal}, ${red}--install${normal} ${green}${normal} create the package ${green}${normal} and install ${red}-a${normal}, ${red}--all${normal} create all packages and install ${red}-np${normal}, ${red}--no-deps${normal} does not solve dependences ${red}-d${normal}, ${red}--debug${normal} ${green}${normal} enable SlackBuild debug (sh -x ...) ${red}-s${normal}, ${red}--search${normal} ${green}S search for a ${green}${normal} ${red}-f${normal}, ${red}--info${normal} ${green}${normal} show description and dependences of the program ${red}-l${normal}, ${red}--list${normal} list all the SlackBuilds ${red}--sync${normal} synchronize SlackBuilds repository ${red}-h${normal}, ${red}--help${normal} show this help ${red}EXAMPLES${normal} ${red}createpkg -i scilab${normal} build and install scilab package ${red}createpkg -s at*${normal} search for all at* SlackBuilds scripts (at-spi, atk, ...) ${red}createpkg --info pyrex${normal} show pyrex description and dependences ${red}AUTHOR${normal} Written by ${blue}Rudson R. Alves${normal} ${red}AVAILABILITY${normal} by svn: ${yellow}svn checkout svn://slack.sarava.org/simplepkg${normal} this mkbuild is found in branches/0.6/ ${red}REPORTING BUGS${normal} Report bugs to <${blue}rudsonalves[at]rra.etc.br${normal}> ${red}COPYRIGHT${normal} Copyright © 2006 Free Software Foundation, Inc. This is free software. You may redistribute copies of it under the terms of the GNU General Public License <${yellow}http://www.gnu.org/licenses/gpl.html${normal}>. There is NO WARRANTY, to the extent permitted by law." | more } function build_all_slackbuild { # Build all SlackBuilds in repository createpkg --sync cd $SLACKBUILDS_DIR LIST=`find . -name *.SlackBuild | sed 's/.*\/\(.*\)\.SlackBuild$/\1/' | sort | uniq` for i in $LIST; do [ ! lspkg $i >/dev/null ] && createpkg -i $i done } function check_config { # check the configuration TMP=${TMP:=/tmp}; if [ ! -z "$REPOS" ]; then MAKEPKG_REPOS="$REPOS" else REPOS=$MAKEPKG_REPOS fi # Create $TMP and $REPOS if need [ ! -e $TMP ] && mkdir -p $TMP [ ! -e $MAKEPKG_REPOS ] && mkdir -p $MAKEPKG_REPOS # SLACKBUILDS_DIR=${SLACKBUILDS_DIR:=/var/slackbuilds} # SYNC=${SYNC:=$no} SYNC=`convert_boolean $SYNC` BASEDIR="`dirname $SLACKBUILDS_DIR`" } function solve_dep { # Solve dependency [ $# -ne 3 ] && handle_error $ERROR_PAR_NUMBER local PACK="$1" local COND="$2" local VER="$3" # Check package in local system PACK="`echo $PACK | sed -e 's/\+/\\\+/'`" INSTALLED=`eval "ls /var/log/packages/ | egrep -E '^$PACK-[^-]+-[^-]+-[^-]+$'"` CHECK=$? # TODO: Make check version procedures if [ -z "$INSTALLED" ]; then if [ $CHECK -ne 0 ]; then # Check package in SlackBuilds tree eecho $messag "$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 -eq $ERROR_CREATEPKG_SLACKBUILD_NOTFOUND ]; then # Try to use simplaret ARCH=$CREATE_ARCH simplaret --update ARCH=$CREATE_ARCH simplaret --install $PACK [ $? -ne 0 ] && handle_error $ERROR_CREATEPKG_SLACKBUILD_NOTFOUND $PACK elif [ $EXIT_CODE -ne 0 ]; then handle_error $EXIT_CODE $PACK fi fi fi } function find_slackbuild { # Find SlackBuild script in the repository [ $# -ne 1 ] && handle_error $ERROR_PAR_NUMBER OUTPUT=`find $SLACKBUILDS_DIR -iname $1.SlackBuild` [ "$OUTPUT" != "" ] && EXIT_CODE=0 || EXIT_CODE=1 echo $OUTPUT } function info_builds { # Show packages info if [ "$PKG_PATH" != "" ]; then for i in $PKG_PATH; do PACKAGE=`basename $i .SlackBuild` NAME_UP=`echo $PACKAGE | tr [a-z] [A-Z]` eecho $commun "$NAME_UP: " PKG_DIR=`dirname $i` if [ -e $PKG_DIR/slack-desc ]; then eval "cat $PKG_DIR/slack-desc | grep '^$PACKAGE:' | cut -f2- -d:" eecho $normal else eval "cat $i | grep '^$PACKAGE:' | cut -f2- -d:" eecho $normal fi if [ -e $PKG_DIR/slack-required ]; then eecho $commun "slack-required" cat $PKG_DIR/slack-required | sed 's/^/ /' fi done fi } function list_builds { # List all available SlackBuilds cd $SLACKBUILDS_DIR echo "Sarava SlackBuilds list" # level 1 for i in *; do if [ -d $i ]; then echo -e " $i: " ( cd $i # level 2 for j in *; do if [ -d $j ]; then eecho $commun " $j" ( cd $j BUILD="`ls *.SlackBuild 2>/dev/null`" if [ "$BUILD" != "" ]; then # level 3 for k in $BUILD; do eecho $messag " $k" done else BUILD="" fi for k in *; do if [ -d $k ]; then eecho $messag " $k.SlackBuild" fi done ) fi done ) fi done } function load_parameters { # Load Createpkg parameters MAKEPKG_REPOS="`eval_parameter MAKEPKG_REPOS /var/simplaret/repos`" SOURCE_DIR="`eval_parameter SOURCE_DIR /var/simplaret/sources`" SLACKBUILDS_DIR="`eval_parameter SLACKBUILDS_DIR /var/simplaret/slackbuilds`" SLACKBUILDS_SVN="`eval_parameter SLACKBUILDS_SVN svn://slack.sarava.org/slackbuilds`" COLOR_MODE="`eval_parameter COLOR_MODE none`" CREATE_ARCH="`eval_parameter CREATE_ARCH $(default_arch)`" CREATE_CLEANUP="`eval_parameter CREATE_CLEANUP yes`" REMOVE_OLD_PACKAGE="`eval_boolean_parameter REMOVE_OLD_PACKAGE $off`" MOVE_BIN_PACKAGE="`eval_boolean_parameter MOVE_BIN_PACKAGE $off`" } #--------------------------------------------------- # Starting createpkg #--------------------------------------------------- # Common functions COMMON="/usr/libexec/simplepkg/common.sh" SIMPLEPKG_CONF="/etc/simplepkg/simplepkg.conf" BASENAME="`basename $0`" EXIT_CODE=0 if [ -f "$COMMON" ]; then source $COMMON else echo "error: file $COMMON found, check your $BASENAME installation" mk_exit 0 fi set_constants # Load simplepkg.conf variables load_parameters # Loading error codes error_codes # 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_MODE # This is used to show how many children process we have if [ -z "$CREATEPKG_CHILD" ]; then CREATEPKG_CHILD=1 else let CREATEPKG_CHILD++ fi BASENAME="`basename $0`[$CREATEPKG_CHILD]" check_config check_repo $SLACKBUILDS_DIR $SLACKBUILDS_SVN INSTALL=$off NO_DEPS=$off DEBUG=$off case $1 in '--all'|'-a') # build all SlackBuilds in repository build_all_slackbuild exit $EXIT_CODE ;; '--search'|'-s') [ $# -ne 2 ] && usage # two parameters is required LIST=`find_slackbuild $2` for i in $LIST; do echo $i | sed 's/.*\/\([^\/]\+\)\.[Ss]lack[Bb]uild$/ \1/' done exit $EXIT_CODE ;; '--info'|'-f') [ $# -ne 2 ] && usage # two parameters is required PKG_PATH=`find_slackbuild $2` info_builds exit $EXIT_CODE ;; '--install'|'-i') [ $# -ne 2 ] && usage # two parameters is required PACKAGE="$2" INSTALL=$on ;; '--no-deps'|'-nd') [ $# -ne 2 ] && usage # two parameters is required NO_DEPS=$on PACKAGE="$2" ;; '--debug'|'-d') [ $# -ne 2 ] && usage # two parameters is required PACKAGE="$2" DEBUG=$on ;; '--sync') sync_repo $SLACKBUILDS_DIR $SLACKBUILDS_SVN exit $EXIT_CODE ;; '--help'|'-h'|'') usage exit $EXIT_CODE ;; '--list'|'-l') list_builds exit $EXIT_CODE ;; *) if [ "${1:0:1}" != "-" ]; then PACKAGE="$1" else usage fi ;; esac # Synchronize repository [ $SYNC -eq $yes ] && sync_repo $SLACKBUILDS_DIR $SLACKBUILDS_SVN # Get SlackBuild script BUILD_SCRIPT="`find_slackbuild $PACKAGE`" # Check SlackBuild script found if [ -z "$BUILD_SCRIPT" ]; then handle_error $ERROR_CREATEPKG_SLACKBUILD_NOTFOUND $PACKAGE fi # Select one SlackBuild if [ "`echo $BUILD_SCRIPT | wc -w`" -gt 1 ]; then AUX="$PS3" PS3="Choice: " LIST=`echo $BUILD_SCRIPT | sed 's/ /\n/g' | sed -r 's/.*\/(.*)\.SlackBuild$/\1/'`" EXIT" select PACKAGE in `echo $LIST`; do break done if [ "$PACKAGE" = "EXIT" ]; then eecho $error "error: None package select" exit 1 fi # Select only one SlackBuild in BUILD_SCRIPT BUILD_SCRIPT=`echo $BUILD_SCRIPT | sed 's/ /\n/g' | grep "/$PACKAGE.SlackBuild"` PS3="$AUX" else PACKAGE=`basename $BUILD_SCRIPT .SlackBuild` fi # Get dirname and script name from slackbuild SCRIPT_BASE="`dirname $BUILD_SCRIPT`" SCRIPT_NAME="`basename $BUILD_SCRIPT`" eecho $messag "$BASENAME: found script $PACKAGE.SlackBuild, now checking for dependencies" # Sets the package's slack-required if [ -f "$SCRIPT_BASE/$PACKAGE.slack-required" ]; then SLACK_REQUIRED="$SCRIPT_BASE/$PACKAGE.slack-required" elif [ -f "$SCRIPT_BASE/slack-required" ]; then SLACK_REQUIRED="$SCRIPT_BASE/slack-required" fi if [ ! -z "$SLACK_REQUIRED" -a $NO_DEPS -ne $on ]; then # This routine checks for dependencies in package's slack-required ( grep '^[^#]' $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" fi true done ) [ $? -ne 0 ] && handle_error $error $ERROR_CREATEPKG_DEPENDENCY eecho $messag "$BASENAME: done checking for $PACKAGE dependencies" else eecho $messag "$BASENAME: no unmet dependencies for $PACKAGE" fi eecho $messag "$BASENAME: processing $SCRIPT_NAME" # Change to script base directory cd $SCRIPT_BASE # Run SlackBuild script [ $DEBUG -eq $off ] && SHELL_FLAG="+x" || SHELL_FLAG="-x" ( LANG=en_US \ SRC_DIR=${SRC_DIR:=$SOURCE_DIR} \ SRC=${SRC_DIR:=$SOURCE_DIR} \ ARCH=${ARCH:=$CREATE_ARCH} \ COLOR=${COLOR:=$COLOR_MODE} \ REPOS=${REPOS:=$MAKEPKG_REPOS} \ CLEANUP=${CLEANUP:=$CREATE_CLEANUP} \ INTERACT=no sh $SHELL_FLAG ./$SCRIPT_NAME ) # Check if package was built handle_error $? $PACKAGE # Get package name PKG_NAME="`ls -1 -c $MAKEPKG_REPOS/$PACKAGE-*-*-*.tgz | head -n 1 | xargs basename`" # Select repository directory [ $MOVE_BIN_PACKAGE -eq $on ] && NEW_REPOS=$MAKEPKG_REPOS/$( echo ${SCRIPT_BASE#$SLACKBUILDS_DIR/} ) || NEW_REPOS=$MAKEPKG_REPOS # Create repository directory # TODO: subversion integration [ ! -e $NEW_REPOS ] && mkdir -p $NEW_REPOS 2>/dev/null # Remove old packages from repository tree # TODO: subversion integration [ $REMOVE_OLD_PACKAGE -eq $on ] && rm $NEW_REPOS/$PACKAGE-*-*-*.tgz 2>/dev/null # Move package and slack-required to SlackBuilds-like tree # TODO: subversion integration [ $MOVE_BIN_PACKAGE -eq $on ] && mv $MAKEPKG_REPOS/$PKG_NAME $NEW_REPOS/ [ ! -z "$SLACK_REQUIRED" ] && cp $SLACK_REQUIRED $NEW_REPOS/$PACKAGE.slack-required # Install package if [ "$INSTALL" -eq $on ]; then # as we dont have the full package file name, we'll # use the newer file name that matches our wildcard: upgradepkg --install-new $NEW_REPOS/$PKG_NAME fi # TODO: subversion integration # generate or update all metadata # svn commit # Update repository FILELIST.TXT, ... ( cd $MAKEPKG_REPOS gen_filelist ) exit $EXIT_CODE