From 61e30d9d6b5dbfb3887d3e4cee93e096ab0c05c3 Mon Sep 17 00:00:00 2001 From: rhatto Date: Mon, 26 Jan 2009 20:42:12 +0000 Subject: attempting to fix #31 git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@777 04377dda-e619-0410-9926-eae83683ac58 --- trunk/src/createpkg | 520 ++++++++++++++++++++++++++++------------------------ trunk/src/mkbuild | 7 +- 2 files changed, 286 insertions(+), 241 deletions(-) diff --git a/trunk/src/createpkg b/trunk/src/createpkg index 31b7fc6..0e55e2c 100644 --- a/trunk/src/createpkg +++ b/trunk/src/createpkg @@ -94,7 +94,7 @@ ${red}COPYRIGHT${normal} to the extent permitted by law." } -function build_all_slackbuild { +function build_all_slackbuilds { # Build all SlackBuilds in repository createpkg --sync @@ -104,6 +104,7 @@ function build_all_slackbuild { for i in $LIST; do [ ! lspkg $i >/dev/null ] && createpkg -i $i done + } function check_config { @@ -510,6 +511,273 @@ function sign_package { } +function create_package { + + # Synchronize repository + [ $SYNC -eq $yes ] && sync_repo $SLACKBUILDS_DIR $SLACKBUILDS_SVN + + # Update keyring + update_keyring $SLACKBUILDS_DIR/GPG-KEY + + # 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: no package selected" + return 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 + + # Use fakeroot if needed and available + if [ "`whoami`" != "root" ]; then + FAKEROOT="`which fakeroot`" + if [ "$?" == "0" ]; then + eecho $messag "$BASENAME: running SlackBuild with fakeroot." + FAKEROOT="$FAKEROOT --" + else + eecho $messag "$BASENAME: WARNING: not running as root and no fakeroot found." + eecho $messag "$BASENAME: WARNING: your build might not be successful." + FAKEROOT="" + fi + else + FAKEROOT="" + fi + + # Run SlackBuild script + [ $DEBUG -eq $off ] && SHELL_FLAG="+x" || SHELL_FLAG="-x" + ( + LANG=en_US \ + TMP=$TMP \ + SRC_DIR=${SRC_DIR:=$SOURCE_DIR} \ + SRC=${SRC_DIR:=$SOURCE_DIR} \ + ARCH=${ARCH:=$CREATEPKG_ARCH} \ + COLOR=${COLOR:=$COLOR_MODE} \ + REPOS=${REPOS:=$PACKAGES_DIR} \ + CLEANUP=${CLEANUP:=$CREATEPKG_CLEANUP} \ + INTERACT=no $FAKEROOT sh $SHELL_FLAG ./$SCRIPT_NAME + ) + + # Check if package was built + handle_error $? $PACKAGE + + # Fix source folder user + if [ ! -z "$SOURCE_DIR_USER" ]; then + chown -R $SOURCE_DIR_USER $SOURCE_DIR + fi + + # Fix source folder group + if [ ! -z "$SOURCE_DIR_GROUP" ]; then + chgrp -R $SOURCE_DIR_GROUP $SOURCE_DIR + fi + + # Get package name, arch, version and build number + PKG_NAME="`ls -1 -c $PACKAGES_DIR/$PACKAGE-*-*-*.tgz | head -n 1 | xargs basename`" + PACKAGE_NAME="`package_name $PKG_NAME`" + PACKAGE_VERSION="`package_version $PKG_NAME`" + PACKAGE_ARCH="`package_arch $PKG_NAME`" + PACKAGE_BUILD="`package_build $PKG_NAME`" + + # Update package author + if [ ! -z "$CREATEPKG_AUTHOR" ]; then + AUTHOR="`echo $PACKAGE_BUILD | sed -e 's/^[0-9]*//'`" + if [ "$AUTHOR" != "$CREATEPKG_AUTHOR" ]; then + echo "Changing package build author..." + BUILD_NUMBER="`echo $PACKAGE_BUILD | sed -e "s/$AUTHOR$//"`" + NEW_BUILD="$BUILD_NUMBER""$CREATEPKG_AUTHOR" + mv $PACKAGES_DIR/$PKG_NAME $PACKAGES_DIR/$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_ARCH-$NEW_BUILD.tgz + PKG_NAME="$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_ARCH-$NEW_BUILD.tgz" + PACKAGE_BUILD="$NEW_BUILD" + AUTHOR="$CREATEPKG_AUTHOR" + echo "New package name is $PKG_NAME." + fi + fi + + # Sign package + if [ $SIGN_PACKAGES -eq $on ]; then + + echo "Signing package..." + + get_sign_user + + if [ ! -z "$SIGN_PACKAGES_USER" ] && [ "`whoami`" != "$SIGN_PACKAGES_USER" ]; then + tmp_sign_folder="`mktemp -d $TMP/createpkg_sign.XXXXXX`" + chown $SIGN_PACKAGES_USER $tmp_sign_folder + su $SIGN_PACKAGES_USER -c "gpg $GPG_AGENT_OPTION --armor -sb -u $SIGN_KEYID -o $tmp_sign_folder/$PKG_NAME.asc $PACKAGES_DIR/$PKG_NAME" + cp $tmp_sign_folder/$PKG_NAME.asc $PACKAGES_DIR/$PKG_NAME.asc + rm -rf $tmp_sign_folder + else + gpg $GPG_AGENT_OPTION --armor -sb -u $SIGN_KEYID $PACKAGES_DIR/$PKG_NAME + fi + + fi + + # Select repository directory + if [ $MOVE_BIN_PACKAGE -eq $on ]; then + SUBFOLDER="$( echo ${SCRIPT_BASE#$SLACKBUILDS_DIR/} )" + NEW_REPOS=$PACKAGES_DIR/$SUBFOLDER + else + SUBFOLDER="." + NEW_REPOS=$PACKAGES_DIR + fi + + # Update information from remote repository + repository_update $PACKAGES_DIR + + # Create the repository folders + create_repo_folder $PACKAGES_DIR + + # Remove old packages from repository tree + remove_old_package_data $PACKAGES_DIR + + # Move package to SlackBuilds-like tree + if [ $MOVE_BIN_PACKAGE -eq $on ]; then + + mv $PACKAGES_DIR/$PKG_NAME $NEW_REPOS/ + if [ -e "$PACKAGES_DIR/$PKG_NAME.asc" ]; then + mv $PACKAGES_DIR/$PKG_NAME.asc $NEW_REPOS/ + fi + + if [ -d "$NEW_REPOS/.svn" ]; then + ( + cd $NEW_REPOS + chown_svn $PACKAGES_DIR && chgrp_svn $PACKAGES_DIR + svn_add $PKG_NAME + svn_add $PKG_NAME.asc + ) + fi + + # Move package's slack-required to binary repository + if [ $MOVE_SLACK_REQUIRED -eq $on ]; then + if [ ! -z "$SLACK_REQUIRED" ]; then + svn_copy $SLACK_REQUIRED $NEW_REPOS/$PACKAGE.slack-required + fi + fi + + fi + + # Update repository metadata + update_metadata $PACKAGES_DIR + + # General cleanup + echo Cleaning up the repository... + svn_remove_empty_folders $PACKAGES_DIR + + # Update noarch repository + if [ $PACKAGES_REPOS_NOARCH -eq $on ] && [ "`package_arch $PKG_NAME`" == "noarch" ]; then + repository_update $NOARCH_DIR + echo Copying package to noarch repository... + create_repo_folder $NOARCH_DIR + remove_old_package_data $NOARCH_DIR + svn_copy $NEW_REPOS/$PKG_NAME $NOARCH_DIR/$SUBFOLDER/ + svn_copy $NEW_REPOS/`basename $PKG_NAME .tgz`.meta $NOARCH_DIR/$SUBFOLDER/ + svn_copy $NEW_REPOS/`basename $PKG_NAME`.asc $NOARCH_DIR/$SUBFOLDER/ + svn_copy $NEW_REPOS/$PACKAGE.slack-required $NOARCH_DIR/$SUBFOLDER/ + update_metadata $NOARCH_DIR + svn_remove_empty_folders $NOARCH_DIR + fi + + # Install package + if [ "$INSTALL" -eq $on ]; then + upgradepkg --install-new $NEW_REPOS/$PKG_NAME + fi + + echo "Package saved at $NEW_REPOS/$PKG_NAME" + + if [ $PACKAGES_REPOS_NOARCH -eq $on ] && [ "`package_arch $PKG_NAME`" == "noarch" ]; then + echo "Aditional copy saved at $NOARCH_DIR/$SUBFOLDER/$PKG_NAME" + fi + + return $EXIT_CODE + +} + +function build_queue { + + # createpkg's build queue + # usage: build_queue ... + + local unable_to_install built=0 total=0 + + if [ -z "$1" ]; then + return + fi + + for PACKAGE in $*; do + create_package + if [ "$?" != "0" ]; then + unable_to_install="$unable_to_install\n\t`echo $PACKAGE | sed -e 's/\\\+/\+/'`" + let total++ + else + let built++ + fi + done + + if [ ! -z "$unable_to_install" ]; then + eecho $messag "$BASENAME: done building $built of $total existing SlackBuilds." + eecho $messag "$BASENAME: unable to create the following packages:" + echo -e "$unable_to_install" + fi + +} + #--------------------------------------------------- # Starting createpkg #--------------------------------------------------- @@ -563,7 +831,7 @@ DEBUG=$off case $1 in '--all'|'-a') # build all SlackBuilds in repository - build_all_slackbuild + build_all_slackbuilds exit $EXIT_CODE ;; '--search'|'-s') @@ -585,18 +853,24 @@ case $1 in ;; '--install'|'-i') [ $# -ne 2 ] && usage # two parameters is required - PACKAGE="$2" + shift + PACKAGE="$1" INSTALL=$on + build_queue $* ;; '--no-deps'|'-nd') [ $# -ne 2 ] && usage # two parameters is required + shift NO_DEPS=$on - PACKAGE="$2" + PACKAGE="$1" + build_queue $* ;; '--debug'|'-d') [ $# -ne 2 ] && usage # two parameters is required - PACKAGE="$2" + shift + PACKAGE="$1" DEBUG=$on + build_queue $* ;; '--sync') sync_repo $SLACKBUILDS_DIR $SLACKBUILDS_SVN @@ -647,243 +921,9 @@ case $1 in ;; *) if [ "${1:0:1}" != "-" ]; then - PACKAGE="$1" + build_queue $* else usage fi ;; esac - -# Synchronize repository -[ $SYNC -eq $yes ] && sync_repo $SLACKBUILDS_DIR $SLACKBUILDS_SVN - -# Update keyring -update_keyring $SLACKBUILDS_DIR/GPG-KEY - -# 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 - -# Use fakeroot if needed and available -if [ "`whoami`" != "root" ]; then - FAKEROOT="`which fakeroot`" - if [ "$?" == "0" ]; then - eecho $messag "$BASENAME: running SlackBuild with fakeroot." - FAKEROOT="$FAKEROOT --" - else - eecho $messag "$BASENAME: WARNING: not running as root and no fakeroot found." - eecho $messag "$BASENAME: WARNING: your build might not be successful." - FAKEROOT="" - fi -else - FAKEROOT="" -fi - -# Run SlackBuild script -[ $DEBUG -eq $off ] && SHELL_FLAG="+x" || SHELL_FLAG="-x" -( - LANG=en_US \ - TMP=$TMP \ - SRC_DIR=${SRC_DIR:=$SOURCE_DIR} \ - SRC=${SRC_DIR:=$SOURCE_DIR} \ - ARCH=${ARCH:=$CREATEPKG_ARCH} \ - COLOR=${COLOR:=$COLOR_MODE} \ - REPOS=${REPOS:=$PACKAGES_DIR} \ - CLEANUP=${CLEANUP:=$CREATEPKG_CLEANUP} \ - INTERACT=no $FAKEROOT sh $SHELL_FLAG ./$SCRIPT_NAME -) - -# Check if package was built -handle_error $? $PACKAGE - -# Fix source folder user -if [ ! -z "$SOURCE_DIR_USER" ]; then - chown -R $SOURCE_DIR_USER $SOURCE_DIR -fi - -# Fix source folder group -if [ ! -z "$SOURCE_DIR_GROUP" ]; then - chgrp -R $SOURCE_DIR_GROUP $SOURCE_DIR -fi - -# Get package name, arch, version and build number -PKG_NAME="`ls -1 -c $PACKAGES_DIR/$PACKAGE-*-*-*.tgz | head -n 1 | xargs basename`" -PACKAGE_NAME="`package_name $PKG_NAME`" -PACKAGE_VERSION="`package_version $PKG_NAME`" -PACKAGE_ARCH="`package_arch $PKG_NAME`" -PACKAGE_BUILD="`package_build $PKG_NAME`" - -# Update package author -if [ ! -z "$CREATEPKG_AUTHOR" ]; then - AUTHOR="`echo $PACKAGE_BUILD | sed -e 's/^[0-9]*//'`" - if [ "$AUTHOR" != "$CREATEPKG_AUTHOR" ]; then - echo "Changing package build author..." - BUILD_NUMBER="`echo $PACKAGE_BUILD | sed -e "s/$AUTHOR$//"`" - NEW_BUILD="$BUILD_NUMBER""$CREATEPKG_AUTHOR" - mv $PACKAGES_DIR/$PKG_NAME $PACKAGES_DIR/$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_ARCH-$NEW_BUILD.tgz - PKG_NAME="$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_ARCH-$NEW_BUILD.tgz" - PACKAGE_BUILD="$NEW_BUILD" - AUTHOR="$CREATEPKG_AUTHOR" - echo "New package name is $PKG_NAME." - fi -fi - -# Sign package -if [ $SIGN_PACKAGES -eq $on ]; then - - echo "Signing package..." - - get_sign_user - - if [ ! -z "$SIGN_PACKAGES_USER" ] && [ "`whoami`" != "$SIGN_PACKAGES_USER" ]; then - tmp_sign_folder="`mktemp -d $TMP/createpkg_sign.XXXXXX`" - chown $SIGN_PACKAGES_USER $tmp_sign_folder - su $SIGN_PACKAGES_USER -c "gpg $GPG_AGENT_OPTION --armor -sb -u $SIGN_KEYID -o $tmp_sign_folder/$PKG_NAME.asc $PACKAGES_DIR/$PKG_NAME" - cp $tmp_sign_folder/$PKG_NAME.asc $PACKAGES_DIR/$PKG_NAME.asc - rm -rf $tmp_sign_folder - else - gpg $GPG_AGENT_OPTION --armor -sb -u $SIGN_KEYID $PACKAGES_DIR/$PKG_NAME - fi - -fi - -# Select repository directory -if [ $MOVE_BIN_PACKAGE -eq $on ]; then - SUBFOLDER="$( echo ${SCRIPT_BASE#$SLACKBUILDS_DIR/} )" - NEW_REPOS=$PACKAGES_DIR/$SUBFOLDER -else - SUBFOLDER="." - NEW_REPOS=$PACKAGES_DIR -fi - -# Update information from remote repository -repository_update $PACKAGES_DIR - -# Create the repository folders -create_repo_folder $PACKAGES_DIR - -# Remove old packages from repository tree -remove_old_package_data $PACKAGES_DIR - -# Move package to SlackBuilds-like tree -if [ $MOVE_BIN_PACKAGE -eq $on ]; then - - mv $PACKAGES_DIR/$PKG_NAME $NEW_REPOS/ - if [ -e "$PACKAGES_DIR/$PKG_NAME.asc" ]; then - mv $PACKAGES_DIR/$PKG_NAME.asc $NEW_REPOS/ - fi - - if [ -d "$NEW_REPOS/.svn" ]; then - ( - cd $NEW_REPOS - chown_svn $PACKAGES_DIR && chgrp_svn $PACKAGES_DIR - svn_add $PKG_NAME - svn_add $PKG_NAME.asc - ) - fi - - # Move package's slack-required to binary repository - if [ $MOVE_SLACK_REQUIRED -eq $on ]; then - if [ ! -z "$SLACK_REQUIRED" ]; then - svn_copy $SLACK_REQUIRED $NEW_REPOS/$PACKAGE.slack-required - fi - fi - -fi - -# Update repository metadata -update_metadata $PACKAGES_DIR - -# General cleanup -echo Cleaning up the repository... -svn_remove_empty_folders $PACKAGES_DIR - -# Update noarch repository -if [ $PACKAGES_REPOS_NOARCH -eq $on ] && [ "`package_arch $PKG_NAME`" == "noarch" ]; then - repository_update $NOARCH_DIR - echo Copying package to noarch repository... - create_repo_folder $NOARCH_DIR - remove_old_package_data $NOARCH_DIR - svn_copy $NEW_REPOS/$PKG_NAME $NOARCH_DIR/$SUBFOLDER/ - svn_copy $NEW_REPOS/`basename $PKG_NAME .tgz`.meta $NOARCH_DIR/$SUBFOLDER/ - svn_copy $NEW_REPOS/`basename $PKG_NAME`.asc $NOARCH_DIR/$SUBFOLDER/ - svn_copy $NEW_REPOS/$PACKAGE.slack-required $NOARCH_DIR/$SUBFOLDER/ - update_metadata $NOARCH_DIR - svn_remove_empty_folders $NOARCH_DIR -fi - -# Install package -if [ "$INSTALL" -eq $on ]; then - upgradepkg --install-new $NEW_REPOS/$PKG_NAME -fi - -echo "Package saved at $NEW_REPOS/$PKG_NAME" - -if [ $PACKAGES_REPOS_NOARCH -eq $on ] && [ "`package_arch $PKG_NAME`" == "noarch" ]; then - echo "Aditional copy saved at $NOARCH_DIR/$SUBFOLDER/$PKG_NAME" -fi - -exit $EXIT_CODE diff --git a/trunk/src/mkbuild b/trunk/src/mkbuild index 1098aa8..45c99fe 100755 --- a/trunk/src/mkbuild +++ b/trunk/src/mkbuild @@ -126,7 +126,7 @@ ${red}COPYRIGHT${normal} 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 + to the extent permitted by law." } function set_parameters { @@ -332,6 +332,11 @@ function set_parameters { shift done + if [ "${MKBUILD_NAME:0:1}" == "-" ]; then + echo "Invalid mkbuild name $MKBUILD_NAME" + exit 1 + fi + if [ ! -e "$MKBUILD_NAME" ] && [ "$ACTION" != "search" ] && [ "$ACTION" != "status" ]; then search="`search_mkbuild`" -- cgit v1.2.3