aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-10-07 19:32:06 -0300
committerSilvio Rhatto <rhatto@riseup.net>2017-10-07 19:32:06 -0300
commit0d6bcb2b7d08e3a41481372c1ae0d11868d88b1b (patch)
treed4429ce3a62e9cb5d095ad567b5f821d99a7b9f5 /src
parent5bfb15bdbedbc7273a283d611c84ed1cf401011b (diff)
downloadsimplepkg-0d6bcb2b7d08e3a41481372c1ae0d11868d88b1b.tar.gz
simplepkg-0d6bcb2b7d08e3a41481372c1ae0d11868d88b1b.tar.bz2
New repo layout with git migration
Diffstat (limited to 'src')
-rw-r--r--src/createpkg1096
-rwxr-xr-xsrc/jail-commit175
-rwxr-xr-xsrc/jail-update62
-rwxr-xr-xsrc/lspkg148
-rwxr-xr-xsrc/mkbuild1904
-rwxr-xr-xsrc/mkjail115
-rw-r--r--src/mkpatch145
-rwxr-xr-xsrc/mkpatch.new145
-rwxr-xr-xsrc/rebuildpkg86
-rwxr-xr-xsrc/simplaret1194
-rwxr-xr-xsrc/simpletrack66
-rwxr-xr-xsrc/templatepkg987
12 files changed, 6123 insertions, 0 deletions
diff --git a/src/createpkg b/src/createpkg
new file mode 100644
index 0000000..10daf0b
--- /dev/null
+++ b/src/createpkg
@@ -0,0 +1,1096 @@
+#!/bin/bash
+#
+# createpkg: package builder using http://slack.sarava.org/slackbuilds scripts
+# feedback: rhatto at riseup.net / 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
+#
+# Version $Rev$ - $Author$
+#
+
+#---------------------------------------------------
+# Createpkg functions
+#---------------------------------------------------
+
+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}program1${normal} ... ${green}programN${normal}]
+
+${red}DESCRIPTION${normal}
+ [${green}program${normal}] name to build/search (some options support more than one program)
+
+ Input ${green}OPTIONS${normal}:
+ ${red}-i${normal}, ${red}--install${normal} ${green}<program1>${normal}
+ create the package ${green}<program>${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}<program>${normal}
+ enable SlackBuild debug (sh -x ...)
+ ${red}-s${normal}, ${red}--search${normal} ${green}<program${normal}>
+ search for a ${green}<program>${normal}
+ ${red}-f${normal}, ${red}--info${normal} ${green}<program>${normal}
+ show description and dependences of the program
+ ${red}-l${normal}, ${red}--list${normal}
+ list all the SlackBuilds
+ ${red}--list-packages ${green}[repository]${normal}
+ list all packages in binary repositories
+ ${red}--sign${green}<package_name>${normal}
+ sign a binary package
+ ${red}--remove${green}<package_name>${normal}
+ remove a binary package
+ ${red}--sync${normal}
+ synchronize SlackBuilds repository
+ ${red}--update${normal}
+ synchronize packages repository
+ ${red}--commit${normal} ${green}["message"]${normal}
+ commit changes to binary packages' repository
+ ${red}--status${normal}
+ check binary packages' svn repository status
+ ${red}--import${normal}
+ import packages into a svn repository
+ ${red}--checkout${normal}
+ checkout binary packages from a svn repository
+ ${red}--update-keyring${normal}
+ update GPG-KEY from binary repositories
+ ${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
+ $SYNC=yes {red}createpkg -i scilab${normal}
+ sync repository first, then build and install scilab package
+
+${red}AUTHOR${normal}
+ Written by ${blue}Rudson R. Alves${normal} and ${blue}Silvio Rhatto${normal}
+
+${red}AVAILABILITY${normal}
+ by svn: ${yellow}svn checkout http://slack.sarava.org/simplepkg${normal}
+
+${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."
+}
+
+function build_all_slackbuilds {
+
+ # 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
+ PACKAGES_DIR="$REPOS"
+ else
+ REPOS=$PACKAGES_DIR
+ fi
+
+ # Nested folders, if configured
+ if [ ! -z "$PACKAGES_REPOS_STYLE" ]; then
+ PACKAGES_REPOS_STYLE=$(echo $PACKAGES_REPOS_STYLE | sed -e "s/none//g" -e "s/distro/`default_distro`/g" \
+ -e "s/arch/`default_arch`/g" -e "s/version/`default_version`/g")
+ PACKAGES_DIR="$PACKAGES_DIR/$PACKAGES_REPOS_STYLE"
+ REPOS="$REPOS/$PACKAGES_REPOS_STYLE"
+ fi
+
+ # Create $TMP and $REPOS if need
+ [ ! -e $TMP ] && mkdir -p $TMP
+ [ ! -e $PACKAGES_DIR ] && create_repo_folder $PACKAGES_DIR
+ #
+ SLACKBUILDS_DIR=${SLACKBUILDS_DIR:=/var/simplepkg/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="`check_installed $PACK`"
+ CHECK=$?
+
+ # TODO: check dependency versions
+ 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=$CREATEPKG_ARCH simplaret --update
+ ARCH=$CREATEPKG_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]`
+ ID_VERSION=`grep '^SRC_VERSION' $i | cut -f2- -d":" | cut -f2 -d= | cut -f1 -d}`
+ eecho $commun "$NAME_UP: "
+ eecho Version: "$ID_VERSION"
+ eecho
+
+ 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_slackbuilds {
+
+ # list all available slackbuilds
+ # usage: list_slackbuilds
+
+ list_builds $SLACKBUILDS_DIR SlackBuild
+
+}
+
+function load_parameters {
+
+ # Load Createpkg parameters
+ PACKAGES_DIR="`eval_parameter PACKAGES_DIR /var/simplepkg/repos`"
+ PACKAGES_SVN="`eval_parameter PACKAGES_SVN http://slack.sarava.org/packages`"
+ PACKAGES_REPOS_STYLE="`eval_parameter PACKAGES_REPOS_STYLE none`"
+ NOARCH_DIR="`eval_parameter PACKAGES_DIR /var/simplepkg/repos`/noarch"
+ SOURCE_DIR="`eval_parameter SOURCE_DIR /var/simplepkg/sources`"
+ SLACKBUILDS_DIR="`eval_parameter SLACKBUILDS_DIR /var/simplepkg/slackbuilds`"
+ SLACKBUILDS_SVN="`eval_parameter SLACKBUILDS_SVN http://slack.sarava.org/slackbuilds`"
+ SVN_USER="`eval_parameter PACKAGES_SVN_USER`"
+ SVN_GROUP="`eval_parameter PACKAGES_SVN_GROUP`"
+ SOURCE_DIR_USER="`eval_parameter SOURCE_DIR_USER`"
+ SOURCE_DIR_GROUP="`eval_parameter SOURCE_DIR_GROUP`"
+
+ COLOR_MODE="`eval_parameter COLOR_MODE none`"
+ CREATEPKG_ARCH="`eval_parameter CREATEPKG_ARCH $(default_arch)`"
+ CREATEPKG_CLEANUP="`eval_parameter CREATEPKG_CLEANUP yes`"
+ CREATEPKG_AUTHOR="`eval_parameter CREATEPKG_AUTHOR`"
+
+ TMP="`eval_parameter TMP /tmp`"
+ TMP_USER="`eval_parameter TMP_USER`"
+ TMP_GROUP="`eval_parameter TMP_GROUP`"
+
+ SIGN_PACKAGES="`eval_boolean_parameter SIGN_PACKAGES $off`"
+ SIGN_PACKAGES_USER="`eval_parameter SIGN_PACKAGES_USER`"
+ SIGN_PACKAGES_KEYID="`eval_parameter SIGN_PACKAGES_KEYID`"
+ SIGN_PACKAGES_WITH_GPG_AGENT="`eval_boolean_parameter SIGN_PACKAGES_WITH_GPG_AGENT $off`"
+
+ if [ ! -z "$SIGN_PACKAGES_KEYID" ]; then
+ SIGN_PACKAGES_KEYID="`echo $SIGN_PACKAGES_KEYID | tr '[:lower:]' '[:upper:]'`"
+ fi
+
+ if [ "$SIGN_PACKAGES_WITH_GPG_AGENT" -eq $on ]; then
+ GPG_AGENT_OPTION="--use-agent"
+ else
+ GPG_AGENT_OPTION=""
+ fi
+
+ # For use at common.sh functions
+ SIGN="$SIGN_PACKAGES"
+ SIGN_KEYID="$SIGN_PACKAGES_KEYID"
+ SIGN_USER="$SIGN_PACKAGES_USER"
+
+ REMOVE_OLD_PACKAGE="`eval_boolean_parameter REMOVE_OLD_PACKAGE $off`"
+ MOVE_BIN_PACKAGE="`eval_boolean_parameter MOVE_BIN_PACKAGE $off`"
+ MOVE_SLACK_REQUIRED="`eval_boolean_parameter MOVE_SLACK_REQUIRED $off`"
+ PACKAGES_REPOS_NOARCH="`eval_boolean_parameter PACKAGES_REPOS_NOARCH $on`"
+ FORCE_MANIFEST_CHECK="`eval_boolean_parameter FORCE_MANIFEST_CHECK $off`"
+ FORCE_MANIFEST_CHECK_SIGNATURE="`eval_boolean_parameter FORCE_MANIFEST_CHECK_SIGNATURE $off`"
+
+}
+
+function repository_checkout {
+
+ # checkout a binary repository
+ # usage: repository_checkout [repository-adress]
+
+ local svn oldfolder
+
+ if [ -d "$PACKAGES_DIR" ]; then
+ oldfolder="$(mktemp -d $(echo $PACKAGES_DIR | sed -e 's/\/*$//g').XXXXXX)"
+ echo "Backing up old $folder at $oldfolder..."
+ mv $PACKAGES_DIR $oldfolder
+ fi
+
+ if [ -z "$1" ]; then
+ svn="$1"
+ else
+ svn="$PACKAGES_SVN"
+ fi
+
+ if valid_svn_repo $svn; then
+ svn checkout $svn $PACKAGES_DIR
+ chown_svn $PACKAGES_DIR && chgrp_svn $PACKAGES_DIR
+ if [ "$svn" != "$PACKAGES_SVN" ]; then
+ echo "Using svn repository different from the one pointed at $CONF."
+ fi
+ else
+ echo "Invalid repository $repository, aborting."
+ EXIT_CODE="1"
+ fi
+
+}
+
+function repository_update {
+
+ if [ ! -z "$1" ] && svn_folder $1; then
+ echo "Fetching changes from svn repository for $1..."
+ cwd="`pwd`"
+ chown_svn $1 && chgrp_svn $1
+ cd $1 && su_svn update
+ cd $cwd
+ fi
+
+}
+
+function repository_status {
+
+ local cwd
+
+ if svn_folder $PACKAGES_DIR; then
+ echo "Status of $PACKAGES_DIR."
+ cwd="`pwd`"
+ cd $PACKAGES_DIR && su_svn status
+ cd $cwd
+ fi
+
+ if svn_folder $NOARCH_DIR; then
+ cwd="`pwd`"
+ echo "Status of $NOARCH_DIR."
+ cd $NOARCH_DIR && su_svn status
+ cd $cwd
+ fi
+
+ exit 0
+
+}
+
+function binary_repository_import {
+
+ # import packages into a subversion repository
+ # usage: binary_repository_import [repository]
+
+ local repository="$1" folder
+
+ if [ -z "$repository" ]; then
+ repository="file:////var/svn/packages"
+ fi
+
+ # eval again so it doesn't include repository style information
+ folder="`eval_parameter PACKAGES_DIR /var/simplepkg/repos`"
+
+ repository_import $folder $repository
+
+}
+
+function create_repo_folder {
+
+ # Create repository directory
+ # usage: create_repo_folder <repository_folder>
+
+ local folder="$1" basedir
+
+ if [ ! -d "$folder" ]; then
+ echo "Creating packages folder $folder..."
+ basedir="`dirname $folder`"
+ if svn_folder $basedir && ! svn_check $folder; then
+ (
+ cd $basedir
+ chown_svn $basedir && chgrp_svn $basedir
+ svn_mkdir `basename $folder`/$SUBFOLDER
+ )
+ else
+ mkdir -p $folder/$SUBFOLDER
+ fi
+ elif [ ! -e $folder/$SUBFOLDER ]; then
+ if svn_folder $folder && ! svn_check $folder/$SUBFOLDER; then
+ (
+ cd $folder
+ chown_svn $folder && chgrp_svn $folder
+ svn_mkdir $SUBFOLDER
+ )
+ else
+ mkdir -p $folder/$SUBFOLDER
+ fi
+ fi
+
+}
+
+function remove_old_package_data {
+
+ # Remove old packages from repository tree
+ # usage: remove_old_package_data <repository_folder>
+
+ if [ ! -d "$1" ]; then
+ return 1
+ fi
+
+ local makepkg_repos="$1"
+
+ # Remove old PACKAGEs from repository tree
+ if [ $REMOVE_OLD_PACKAGE -eq $on ]; then
+
+ # first remove entries from CHECKSUMS.md5
+ if [ -f "$makepkg_repos/CHECKSUMS.md5" ]; then
+ sed -i "/$PACKAGE-.*-.*-.*.*$/d" $makepkg_repos/CHECKSUMS.md5
+ fi
+
+ # then remove entries from patches/CHECKSUMS.md5
+ if [ -f "$makepkg_repos/patches/CHECKSUMS.md5" ]; then
+ sed -i "/$PACKAGE-.*-.*-.*.*$/d" $makepkg_repos/patches/CHECKSUMS.md5
+ fi
+
+ # Using subversion
+ if svn_folder $makepkg_repos; then
+
+ (
+
+ cd $makepkg_repos
+
+ # Using -mindepth 2 so it doesn't delete the new PACKAGE
+ for file in `find . -mindepth 2 -name "$PACKAGE-*-*-*.*"`; do
+ candidate="`echo $file | sed -e 's/\.meta$/\.tgz/'`" # otherwise PACKAGE info functions can fail
+ candidate="`echo $candidate | sed -e 's/\.asc$//'`" # otherwise PACKAGE info functions can fail
+ # Just delete packages with different arch, version, build number or folder
+ if [ "`package_name $candidate`" == "$PACKAGE" ]; then
+ if [ "`package_version $candidate`" != "$PACKAGE_VERSION" ] || \
+ [ "`package_arch $candidate`" != "$PACKAGE_ARCH" ] || \
+ [ "`package_build $candidate`" != "$PACKAGE_BUILD" ] || \
+ [ "`package_ext $candidate`" != "$PACKAGE_EXT" ] || \
+ [ "`dirname $candidate | sed -e 's/^\.\///'`" != "`dirname $SUBFOLDER/$PKG_NAME | sed -e 's/^\.\///'`" ]; then
+ svn_del $file
+ fi
+ fi
+ done
+
+ for file in `find $makepkg_repos -name "$PACKAGE.slack-required"`; do
+ if [ $MOVE_SLACK_REQUIRED -eq $off ]; then
+ svn_del $file
+ elif [ ! -z "$SLACK_REQUIRED" ] && [ "$makepkg_repos/$SUBFOLDER/$PACKAGE.slack-required" != "$file" ]; then
+ svn_del $file
+ fi
+ done
+
+ )
+
+ else
+ # Using -mindepth 2 so it doesn't delete the new package
+ eval find $makepkg_repos -mindepth 2 $(pkg_ext_find $PACKAGE-*-*-*) -exec rm {} 2>/dev/null \;
+ find $makepkg_repos -mindepth 2 -name "$PACKAGE-*-*-*.meta" -exec rm {} 2>/dev/null \;
+ find $makepkg_repos -mindepth 2 -name "$PACKAGE-*-*-*.*.asc" -exec rm {} 2>/dev/null \;
+ find $makepkg_repos -name "$PACKAGE.slack-required" -exec rm {} 2>/dev/null \;
+ fi
+ fi
+
+}
+
+function update_metadata {
+
+ # Update repository metadata
+ # usage: update_metadata <repository_folder>
+
+ if [ ! -d "$1" ]; then
+ return 1
+ fi
+
+ local makepkg_repos="$1"
+
+ (
+
+ cd $makepkg_repos
+
+ get_sign_user
+ repo_gpg_key $makepkg_repos
+ gen_meta $SUBFOLDER/$PKG_NAME
+ gen_filelist
+ update_md5_checksum $makepkg_repos $SUBFOLDER/$PKG_NAME
+
+ # update md5 file from patches/ folder if needed
+ if [ -d "patches/" ]; then
+
+ found_patch="no"
+
+ for file in `eval find patches/ $(pkg_ext_find $PACKAGE-*-*-*)`; do
+ found_patch="yes"
+ update_md5_checksum $makepkg_repos/patches patches/$SUBFOLDER/$PKG_NAME
+ done
+
+ if [ "$found_patch" == "yes" ]; then
+ gen_patches_filelist patches
+ fi
+ fi
+
+ )
+
+}
+
+function list_packages {
+
+ # list packages in repositories
+ # usage: list_packages [repository_list]
+
+ local repository repositories="$*"
+
+ if [ -z "$repositories" ]; then
+ repositories="$PACKAGES_DIR $NOARCH_DIR"
+ fi
+
+ for repository in $repositories; do
+ echo "Packages from $repository..."
+ eval find $repository $(pkg_ext_find)
+ done
+
+}
+
+function remove_package {
+
+ # delete a package from repositories
+ # usage: remove_packages <package> [repository_list]
+
+ local package="$1" repository repositories="$2"
+
+ if [ -z "$package" ]; then
+ return 1
+ fi
+
+ if [ -z "$repositories" ]; then
+ repositories="$PACKAGES_DIR $NOARCH_DIR"
+ fi
+
+ for repository in $repositories; do
+
+ (
+
+ cd $repository
+
+ for file in `eval find . $(pkg_ext_find $package-*-*-*) -o -name "$package-*-*-*.meta" -o -name "$package-*-*-*.*.asc"`; do
+ svn_del $file
+ if [ -e "CHECKSUMS.md5" ] && echo $file | grep -q -E -e "$(pkg_ext_grep)$"; then
+ # remove md5 information
+ sed -i "/ \.*\/*$(regexp_slash $file)$/d" CHECKSUMS.md5
+ cat CHECKSUMS.md5 | gzip -9 -c - > CHECKSUMS.md5.gz
+ fi
+ done
+
+ for file in `find $repository -name "$package.slack-required"`; do
+ svn_del $file
+ done
+
+ )
+
+ update_metadata $repository
+ done
+
+}
+
+function sign_package {
+
+ # sign a package from repositories
+ # usage: sign_package <package> [repository_list]
+
+ local package="$1" repository repositories="$2"
+
+ if [ -z "$package" ]; then
+ return 1
+ fi
+
+ if [ -z "$repositories" ]; then
+ repositories="$PACKAGES_DIR $NOARCH_DIR"
+ fi
+
+ for repository in $repositories; do
+
+ (
+
+ cd $repository
+
+ for file in `eval find . $(pkg_ext_find $package-*-*-*)`; do
+
+ 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/`basename $file`.asc $repository/$file"
+ cp $tmp_sign_folder/`basename $file`.asc $repository/$file.asc
+ rm -rf $tmp_sign_folder
+ else
+ tmp_sign_folder="`mktemp -d $TMP/createpkg_sign.XXXXXX`"
+ gpg $GPG_AGENT_OPTION --armor -sb -u $SIGN_KEYID -o $tmp_sign_folder/`basename $file`.asc $repository/$file
+ cp $tmp_sign_folder/`basename $file`.asc $repository/$file.asc
+ rm -rf $tmp_sign_folder
+ fi
+
+ done
+
+ )
+
+ update_metadata $repository
+ done
+
+}
+
+function create_package {
+
+ # Synchronize repository
+ [ $SYNC -eq $yes ] && sync_svn_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
+
+ # Manifest checking
+ if [ $FORCE_MANIFEST_CHECK -eq $on ] || [ $FORCE_MANIFEST_CHECK_SIGNATURE -eq $on ]; then
+ if [ ! -e "`dirname $SCRIPT_NAME`/Manifest" ]; then
+ eecho $messag "$BASENAME: ERROR: no Manifest file for $PACKAGE."
+ return 1
+ fi
+ fi
+
+ # Manifest signature checking
+ if [ $FORCE_MANIFEST_CHECK_SIGNATURE -eq $on ]; then
+ if grep -q -- "-----BEGIN PGP SIGNED MESSAGE-----" `dirname $SCRIPT_NAME`/Manifest; then
+ gpg --verify `dirname $SCRIPT_NAME`/Manifest &> /dev/null
+ if [ "$?" != "0" ]; then
+ eecho $messag "$BASENAME: ERROR: invalid signature for $PACKAGES's Manifest file."
+ return 1
+ fi
+ else
+ eecho $messag "$BASENAME: ERROR: no signed Manifest file for $PACKAGE."
+ return 1
+ fi
+ 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} \
+ SLACKBUILD_PATH="/" \
+ 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-*-*-*.* | grep -E -e "$(pkg_ext_grep)$" | 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`"
+ PACKAGE_EXT="`package_ext $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.$PACKAGE_EXT
+ PKG_NAME="$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_ARCH-$NEW_BUILD.$PACKAGE_EXT"
+ 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
+ tmp_sign_folder="`mktemp -d $TMP/createpkg_sign.XXXXXX`"
+ 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
+ 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 svn_folder $NEW_REPOS; 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/`strip_pkg_ext $PKG_NAME`.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 <package1> ... <packageN>
+
+ local unable_to_install last_status built=0 total=0
+
+ if [ -z "$1" ]; then
+ return
+ fi
+
+ for PACKAGE in $*; do
+ create_package
+ last_status="$?"
+ let total++
+ if [ "$last_status" != "0" ]; then
+ unable_to_install="$unable_to_install\n\t`echo $PACKAGE | sed -e 's/\\\+/\+/'`"
+ else
+ let built++
+ fi
+ done
+
+ if [ ! -z "$unable_to_install" ] && [[ $total > 1 ]]; then
+ eecho $messag "$BASENAME: done building $built of $total requested SlackBuilds."
+ eecho $messag "$BASENAME: unable to create the following packages:"
+ echo -e "$unable_to_install"
+ fi
+
+ # Fix possible $TMP removal
+ mkdir -p $TMP
+
+ # Fix $TMP user
+ if [ ! -z "$TMP_USER" ]; then
+ chown $TMP_USER $TMP
+ fi
+
+ # Fix $TMP group
+ if [ ! -z "$TMP_GROUP" ]; then
+ chgrp $TMP_GROUP $TMP
+ fi
+
+ # Exit with last build package exit status
+ exit $last_status
+
+}
+
+#---------------------------------------------------
+# 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"
+ 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_svn_repo $SLACKBUILDS_DIR $SLACKBUILDS_SVN
+
+INSTALL=$off
+NO_DEPS=$off
+DEBUG=$off
+
+case $1 in
+ '--all'|'-a')
+ # build all SlackBuilds in repository
+ build_all_slackbuilds
+ exit $EXIT_CODE
+ ;;
+ '--search'|'-s')
+ if [ $# -ne 2 ]; then
+ list_slackbuilds
+ else
+ LIST=`find_slackbuild $2`
+ if [ -z $LIST ]; then
+ EXIT_CODE=1
+ else
+ for i in $LIST; do
+ echo $i #| sed 's/.*\/\([^\/]\+\)\.[Ss]lack[Bb]uild$/ \1/'
+ done
+ fi
+ fi
+ 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
+ shift
+ PACKAGE="$1"
+ INSTALL=$on
+ build_queue $*
+ ;;
+ '--no-deps'|'-nd')
+ [ $# -ne 2 ] && usage # two parameters is required
+ shift
+ NO_DEPS=$on
+ PACKAGE="$1"
+ build_queue $*
+ ;;
+ '--debug'|'-d')
+ [ $# -ne 2 ] && usage # two parameters is required
+ shift
+ PACKAGE="$1"
+ DEBUG=$on
+ build_queue $*
+ ;;
+ '--sync')
+ sync_svn_repo $SLACKBUILDS_DIR $SLACKBUILDS_SVN
+ exit $EXIT_CODE
+ ;;
+ '--help'|'-h'|'')
+ usage
+ exit $EXIT_CODE
+ ;;
+ '--list'|'-l')
+ list_slackbuilds
+ exit $EXIT_CODE
+ ;;
+ '--update')
+ repository_update $PACKAGES_DIR
+ repository_update $NOARCH_DIR
+ exit $EXIT_CODE
+ ;;
+ '--commit')
+ shift
+ commit_changes $PACKAGES_DIR "`basename $PACKAGES_DIR:`" $*
+ if [ $PACKAGES_REPOS_NOARCH -eq $on ]; then
+ commit_changes $NOARCH_DIR "noarch:" $*
+ fi
+ exit $EXIT_CODE
+ ;;
+ '--status')
+ repository_status
+ exit $EXIT_CODE
+ ;;
+ '--import')
+ shift
+ binary_repository_import $*
+ exit $EXIT_CODE
+ ;;
+ '--checkout')
+ shift
+ repository_checkout $*
+ exit $EXIT_CODE
+ ;;
+ '--update-keyring')
+ get_sign_user
+ repo_gpg_key $PACKAGES_DIR --update
+ if [ $PACKAGES_REPOS_NOARCH -eq $on ]; then
+ repo_gpg_key $NOARCH_DIR --update
+ fi
+ exit $EXIT_CODE
+ ;;
+ '--list-packages')
+ shift
+ list_packages $*
+ exit $EXIT_CODE
+ ;;
+ '--sign')
+ shift
+ sign_package $*
+ exit $EXIT_CODE
+ ;;
+ '--remove')
+ shift
+ remove_package $*
+ exit $EXIT_CODE
+ ;;
+ *)
+ if [ "${1:0:1}" != "-" ]; then
+ build_queue $*
+ else
+ usage
+ fi
+ ;;
+esac
diff --git a/src/jail-commit b/src/jail-commit
new file mode 100755
index 0000000..60e0a36
--- /dev/null
+++ b/src/jail-commit
@@ -0,0 +1,175 @@
+#!/bin/bash
+#
+# jail-commit: update config files from a jail to a template
+# feedback: rhatto@riseup.net | gpl
+#
+# Jail-commit 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.
+#
+# Jail-commit 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
+#
+
+COMMON="/usr/libexec/simplepkg/common.sh"
+BASENAME="`basename $0`"
+
+if [ -f "$COMMON" ]; then
+ source $COMMON
+ eval_config $BASENAME
+else
+ echo "error: file $COMMON found, check your $BASENAME installation"
+ exit 1
+fi
+
+function usage {
+
+ echo $BASENAME: commit a jail configuration into a template
+ echo "usage: \"$BASENAME [<jail-path> [template]]\""
+ echo " \"$BASENAME --all\" to commit all templates"
+ echo " \"$BASENAME --help\" for help"
+
+}
+
+function template_merge {
+
+ # copy differences between the jail
+ # and the template in the template folder
+
+ # usage: template_merge <jail-path>
+
+ if [ -z "$1" ] || [ ! -d "`template_files`" ]; then
+ return 1
+ fi
+
+ echo "" > `template_perms`.tmp
+ cd `template_files`
+
+ for file in `find | grep -v -e "/.svn$" | grep -v -e "/.svn/" | grep -v -e "^\.$"`; do
+
+ if [[ -e "$file" && -e "$1/$file" ]]; then
+
+ if [ ! -d "$file" ] && [ ! -h "$file" ]; then
+ if ! diff -u $file $1/$file; then
+ echo Updating $file
+ cp -af $1/$file $file
+ fi
+ elif [ -h "$file" ]; then
+ if [ "`readlink $file`" != "`readlink $1/$file`" ]; then
+ rm -f $file
+ ln -s `readlink $1/$file` $file
+ fi
+ fi
+
+ perms="`numeric_perm $1/$file`"
+ owner="`get_owner $1/$file`"
+ group="`get_group $1/$file`"
+
+ # secure the file
+ chown root.root `template_files`/$file
+ chmod $perms `template_files`/$file
+
+ echo "$file;$owner;$group;$perms" >> `template_perms`.tmp
+
+ else
+ if [ ! -e "$1/$file" ]; then
+ echo $BASENAME: warning: missing file `slash $1/$file`
+ fi
+ fi
+
+ done
+
+ cat `template_perms`.tmp | sed '/^$/d' > `template_perms`
+ rm -f `template_perms`.tmp
+
+ if templates_under_svn && ! svn_check `template_perms`; then
+ svn add `template_perms`
+ fi
+
+}
+
+function template_svn_commit {
+
+ # issue a svn_commit from a template folder
+ # usage: template_svn_commit <template-folder>
+
+ if templates_under_svn && svn_folder $1; then
+ cd $1
+ echo First checking out from the repository...
+ svn update
+ echo Commiting changes to the repository...
+ svn commit -m "changes for `date`"
+ if [ "$?" != "0" ]; then
+ echo $BASENAME: commit error
+ fi
+ fi
+
+}
+
+function do_commit {
+
+ # commit jail changes to a repository
+ # usage: do_commit <jailpath> [template]
+
+ local jailpath template
+
+ jailpath="$1"
+ jail="`basename $jailpath`"
+
+ if [ ! -z "$2" ]; then
+ template="$2"
+ else
+ template="$jail"
+ fi
+
+ search_template $template --update
+ if [ "$?" == "0" ] && ! echo "$TEMPLATE_UPDATE_LIST" | grep -q " `basename $TEMPLATE_BASE` "; then
+ TEMPLATE_UPDATE_LIST=" $TEMPLATE_UPDATE_LIST `basename $TEMPLATE_BASE` " # the spaces are important
+ if [ "$jailpath" == "/" ]; then
+ echo Updating main installation...
+ else
+ echo Updating $jailpath...
+ fi
+ if [ -d "`template_files`" ] || [ -a "`template_packages`" ]; then
+ SILENT=yes templatepkg -u $template $jailpath
+ template_merge $jailpath
+ fi
+ else
+ if [ -z "$SILENT" ]; then
+ echo $BASENAME: template $template not found
+ fi
+ return 1
+ fi
+
+}
+
+TEMPLATE_UPDATE_LIST=""
+
+if [ "$1" == "--help" ]; then
+ usage
+elif [ "$1" == "--all" ]; then
+ template_svn_commit $BASE_CONF/templates
+elif echo $1 | grep -q -e "^--"; then
+ usage
+elif [ ! -z "$1" ]; then
+ do_commit $1 $2
+ if [ "$?" == "0" ]; then
+ template_svn_commit `dirname $TEMPLATE_BASE`
+ fi
+else
+ SILENT="yes"
+ if [ -e $JAIL_LIST ]; then
+ for jailpath in `cat $JAIL_LIST`; do
+ do_commit $jailpath
+ done
+ fi
+ # main jail
+ do_commit / main
+ template_svn_commit $BASE_CONF/templates
+fi
+
diff --git a/src/jail-update b/src/jail-update
new file mode 100755
index 0000000..ce2d165
--- /dev/null
+++ b/src/jail-update
@@ -0,0 +1,62 @@
+#!/bin/bash
+#
+# jail-update: update config files from a jail to a template
+# feedback: rhatto@riseup.net | gpl
+#
+# Jail-update 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.
+#
+# Jail-update 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
+#
+
+COMMON="/usr/libexec/simplepkg/common.sh"
+BASENAME="`basename $0`"
+
+if [ -f "$COMMON" ]; then
+ source $COMMON
+ eval_config $BASENAME
+else
+ echo "error: file $COMMON found, check your $BASENAME installation"
+ exit 1
+fi
+
+function usage {
+
+ echo "$BASENAME: update a jail configuration from a template"
+ echo "usage: $BASENAME <jail-path> [template]"
+
+}
+
+if [ -z "$1" ] || [ "$1" == "--help" ] || echo $1 | grep -q -e "^--"; then
+ usage
+ exit 1
+fi
+
+if [ -z "$2" ]; then
+ template_name="`basename $1`"
+else
+ template_name="$2"
+fi
+
+search_template $template_name --update
+
+if [ "$?" != "0" ]; then
+ echo $BASENAME: template $template_name not found
+ exit 1
+elif [ ! -d "$1" ]; then
+ echo $BASENAME: jail $1 not found
+ exit 1
+fi
+
+update_template_files
+update_jail_packages $1
+copy_template_files $1
+set_jail_perms $1
+
diff --git a/src/lspkg b/src/lspkg
new file mode 100755
index 0000000..c5e4ec8
--- /dev/null
+++ b/src/lspkg
@@ -0,0 +1,148 @@
+#!/bin/bash
+#
+# lspkg v0.4: view installed and contents of slackware packages
+#
+# feedback: rhatto at riseup.net | gpl
+#
+# Lspkg 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.
+#
+# Lspkg 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
+#
+
+COMMON="/usr/libexec/simplepkg/common.sh"
+PKG_LIST_DIR="var/log/packages"
+
+if [ -f "$COMMON" ]; then
+ source $COMMON
+else
+ echo "error: file $COMMON not found, check your `basename $0` installation"
+ exit 1
+fi
+
+function head_line {
+ echo "usage: [ROOT=/otherroot] `basename $0` [option expression]"
+}
+
+function usage {
+ head_line
+ echo "
+options are:
+
+ -v, --view <package_name>
+ view installed package contents
+ -p, --print <package_name>
+ print the contents of a package file
+ -r, --remove <package_name>
+ remove matching packages
+ -s, --search <file_name>
+ search a file under installed packages
+ -d, --description <package_name>
+ show matching packages' descriptions
+"
+}
+
+# -----------------------------------------------------
+# lspkg
+# -----------------------------------------------------
+
+if [ $# -eq 2 ]; then
+ pack=$2
+elif [ $# -eq 1 ]; then
+ pack=$1
+else
+ pack=""
+fi
+
+if [ ! -z "$pack" ]; then
+ if echo $pack | grep -q "*"; then
+ LIST_PKGS="`ls -1 /$ROOT/$PKG_LIST_DIR/$pack 2> /dev/null`"
+ else
+ pack="`echo $pack | sed -e 's/\+/\\\+/'`"
+ LIST_PKGS=`eval "ls -1 /$ROOT/$PKG_LIST_DIR/ 2> /dev/null | grep -E '^$pack-[^-]+-[^-]+-[^-]+$'"`
+ fi
+else
+ LIST_PKGS="`ls /$ROOT/$PKG_LIST_DIR/ 2> /dev/null`"
+fi
+
+LIST_PKGS="`slash $LIST_PKGS`"
+
+case $1 in
+ "-h"|"--help")
+ usage
+ ;;
+ "-v"|"--view")
+ if [ ! -z "$2" ]; then
+ if [ ! -z "$LIST_PKGS" ]; then
+ for file in $LIST_PKGS; do
+ less /$PKG_LIST_DIR/$file
+ done
+ else
+ if [ ! -z "$ROOT" ]; then
+ echo "$2: package not found on /$ROOT/$PKG_LIST_DIR"
+ exit 1
+ else
+ echo "$2: package not found on /$PKG_LIST_DIR"
+ exit 1
+ fi
+ fi
+ else
+ head_line
+ exit 1
+ fi
+ ;;
+ "-p"|"--print")
+ if [ -f "$2" ]; then
+ tar ztvf $2
+ else
+ echo $2: file not found
+ fi
+ ;;
+ "-r"|"--remove")
+ if [ ! -z "$2" ]; then
+ if [ ! -z "$LIST_PKGS" ]; then
+ removepkg /$ROOT/$PKG_LIST_DIR/$1-[0-9]*
+ fi
+ fi
+ ;;
+ "-s"|"--search")
+ if [ ! -z "$2" ]; then
+ eval "grep -l '\/$2$' /$ROOT/$PKG_LIST_DIR/*"
+ fi
+ ;;
+ "-d"|"--description")
+ if [ ! -z "$2" ]; then
+ for file in $LIST_PKGS; do
+ pack="`package_name $file`"
+ echo -e " Package description for $file:\n"
+ sed -n "/^$pack:/ { s/$pack://; p; }" $file
+ done
+ else
+ head_line
+ exit 1
+ fi
+ ;;
+ *)
+ if [ ! -z "$LIST_PKGS" ]; then
+ for pack in $LIST_PKGS; do
+ echo $pack
+ done
+ else
+ if [ ! -z "$ROOT" ]; then
+ echo "$1: package not found on /$ROOT/$PKG_LIST_DIR"
+ exit 1
+ else
+ echo "$1: package not found on /$PKG_LIST_DIR"
+ exit 1
+ fi
+ fi
+ ;;
+esac
+
diff --git a/src/mkbuild b/src/mkbuild
new file mode 100755
index 0000000..9be4a16
--- /dev/null
+++ b/src/mkbuild
@@ -0,0 +1,1904 @@
+#!/bin/bash
+#
+# mkbuild: SlackBuild script maker
+# feedback: rudsonaalves at yahoo.com.br
+#
+# mkbuild 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.
+#
+# mkbuild 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
+#
+# Based in model generic.SlackBuild from Luis
+# Version $Rev$ - $Author$
+#
+
+#--------------------------------------------------------------------
+# Functions
+#--------------------------------------------------------------------
+
+function mkbuild_use {
+
+ # mkbuild help function
+ echo -e "${red}NAME${normal}
+ mkbuild - create SlackBuild script from ${green}.mkbuild${normal} input file
+
+${red}SYNOPSIS
+ mkbuild${normal} [${green}OPTIONS${normal}] [${green}mkbuild_file${normal}]
+
+${red}DESCRIPTION${normal}
+ [${green}mkbuild_file${normal}] input file with build rules and variables
+
+ Input ${green}OPTIONS${normal}:
+ ${red}-a${normal}, ${red}--author${normal} ${green}<author_name>${normal}
+ author name
+ ${red}-ai${normal}, ${red}--author_initials${normal} ${green}<initials>${normal}
+ author signature
+ ${red}-bn${normal}, ${red}--build-number${normal}
+ change build number
+ ${red}-cs${normal}, ${red}--const_string${normal} ${green}<string>${normal}
+ construction string to source name
+ ${red}-j${normal}, ${red}--jobs${normal} ${green}<jobs_number>${normal}
+ Number of jobs to run simultaneously
+ ${red}-md${normal}, ${red}--model${normal} ${green}<SlackBuild_model>${normal}
+ SlackBuild model file
+ ${red}-npss${normal}, ${red}--nps-strip${normal}
+ Number of prefix slashes to strip
+ ${red}-pf${normal}, ${red}--patch-files${normal}
+ List of patch files
+ ${red}-pn${normal}, ${red}--pkg_name${normal} ${green}<package_name>${normal}
+ package name
+ ${red}--prefix${normal} <install_dir>${normal}
+ Prefix install directory
+ ${red}-pv${normal}, ${red}--pkg_version${normal} ${green}<version>${normal}
+ package version
+ ${red}-sn${normal}, ${red}--src_name${normal} ${green}<source_name>${normal}
+ source name
+ ${red}-u${normal}, ${red}--url${normal} ${green}<url_address>${normal}
+ url address to source
+
+ Program options:
+ ${red}-d${normal}, ${red}--debug${normal}
+ enable debug mode
+ ${red}-ss${normal}, ${red}--submit-slackbuild${normal}
+ submit SlackBuilds in local svn SlackBuild tree
+ ${red}-sm${normal}, ${red}--submit-mkbuild${normal}
+ submit .mkbuild in local svn mkbuild tree
+ ${red}-sa${normal}, ${red}--submit-all${normal}
+ submit SlackBuild and .mkbuild files in local svn tree
+ ${red}-cs${normal}, ${red}--commit-slackbuild${normal}
+ commit SlackBuilds in svn SlackBuild tree
+ ${red}-cm${normal}, ${red}--commit-mkbuild${normal}
+ commit .mkbuild in svn mkbuild tree
+ ${red}-ca${normal}, ${red}--commit-all${normal}
+ commit SlackBuild and .mkbuild files in svn tree
+ ${red}-im${normal}, ${red}--import-mkbuilds${normal}
+ import mkbuild repository in a svn tree
+ ${red}-is${normal}, ${red}--import-slackbuilds${normal}
+ import SlackBuild repository in a svn tree
+ ${red}-ia${normal}, ${red}-i${normal}, ${red}--import-all${normal}, ${red}--import${normal}
+ import mkbuild and SlackBuild repositories in a svn tree
+ ${red}--status${normal}
+ print mkbuild and SlackBuild svn repositories status
+ ${red}-ls${normal}, ${red}--list${normal}
+ list mkbuild folder contents
+ ${red}-h${normal}, ${red}--help${normal}
+ this help mesage
+ ${red}-n${normal}, ${red}--new${normal} ${green}<mkbuild_name>${normal}
+ start a new mkbuild configure file
+ ${red}-s${normal}, ${red}--search${normal} ${green}<mkbuild_name>${normal}
+ search for a ${green}<mkbuild_name>${normal} file
+ ${red}--sync${normal}
+ synchronize mkbuilds repository
+ ${red}-v${normal}, ${red}--version${normal}
+ program version
+ ${red}-V${normal}, ${red}--verbose${normal}
+ print debug information
+ ${red}-e${normal}, ${red}--edit${normal}
+ edit a mkbuild
+ ${red}-um${normal}, ${red}--update-manifest${normal}
+ update manifest file
+ ${red}-wc${normal}, ${red}--working-copy${normal}
+ create an unversioned mkbuild working copy
+ ${red}--get-param-copy${normal}
+ get a parameter from a given mkbuild
+
+${red}EXAMPLES${normal}
+ ${red}mkbuild -sa pyrex.mkbuild${normal}
+ build pyrex.SlackBuild and submit .mkbuild and .SlackBuild in
+ Slack.Sarava local tree.
+ ${red}mkbuild -a \"Jose Araujo\" -ai \"ja\" -n pyrex${normal}
+ make a basic pyrex.mkbuild with author name \"Jose Araujo\" and
+ author signature \"ja\".
+ ${red}mkbuild --prefix /usr/local pyrex.mkbuild${normal}
+ build pyrex.SlackBuild with prefix /usr/local and pyrex.mkbuild
+ variables and options definitions.
+
+${red}AUTHOR${normal}
+ Written by ${blue}Rudson R. Alves${normal}
+
+${red}AVAILABILITY${normal}
+ by svn: ${yellow}svn checkout http://slack.sarava.org/simplepkg${normal}
+
+${red}REPORTING BUGS${normal}
+ Report bugs to <${blue}rudsonaalves[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."
+}
+
+function set_parameters {
+
+ # Get and set mkbuild variables with parameters input
+ # Use: set_parameters $@
+ # where $@ are the parameters input
+ #
+ # Parameter evaluation
+ ACTION="build"
+
+ local search match
+
+ while [ "$1" ]; do
+ case $1 in
+ '-bn'|'--build-number')
+ # Build Number
+ BUILD_NUMBER=$2
+ is_number $BUILD_NUMBER || handle_error "$ERROR_NOT_NUMBER" "--build-number"
+ shift
+ ;;
+ '-ss'|'--submit-slackbuild')
+ # Submit SlackBuild file
+ SUBMIT_SLACKBUILD=$on
+ ;;
+ '-sm'|'--submit-mkbuild')
+ # Submit mkbuild file
+ SUBMIT_MKBUILD=$on
+ ;;
+ '-sa'|'--submit-all')
+ # Submit SlackBuild and mkbuild file
+ SUBMIT_SLACKBUILD=$on
+ SUBMIT_MKBUILD=$on
+ ;;
+ '-cs'|'--commit-slackbuild')
+ # Commit SlackBuild file
+ ACTION="commit_slackbuild"
+ set_mkbuild_name $2
+ break # we need to break otherwise commit log message is evalued
+ ;;
+ '-cm'|'--commit-mkbuild')
+ # commit mkbuild file
+ ACTION="commit_mkbuild"
+ set_mkbuild_name $2
+ break # we need to break otherwise commit log message is evalued
+ ;;
+ '-ca'|'--commit-all')
+ # Commit SlackBuild and mkbuild file
+ ACTION="commit_all"
+ set_mkbuild_name $2
+ break # we need to break otherwise commit log message is evalued
+ ;;
+ '-is'|'--import-slackbuilds')
+ # Import SlackBuilds
+ ACTION="import_slackbuilds"
+ set_mkbuild_name $2
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '-im'|'--import-mkbuilds')
+ # Import mkbuilds
+ ACTION="import_mkbuilds"
+ set_mkbuild_name $2
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '-ia'|'-i'|'--import-all'|'--import')
+ # Import SlackBuilds and mkbuilds
+ ACTION="import_all"
+ set_mkbuild_name $2
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '-ds'|'--delete-slackbuild')
+ # Delete SlackBuild
+ ACTION="delete_slackbuild"
+ set_mkbuild_name $2
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '-dm'|'--delete-mkbuild')
+ # Delete mkbuild
+ ACTION="delete_mkbuild"
+ set_mkbuild_name $2
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '-da'|'--delete-all')
+ # Delete mkbuild and SlackBuild
+ ACTION="delete_all"
+ set_mkbuild_name $2
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '--status')
+ # Repository status
+ ACTION="status"
+ set_mkbuild_name $2
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '-ls'|'--list')
+ # List mkbuild folder contents
+ ACTION="list"
+ set_mkbuild_name $2
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '-um'|'--update-manifest')
+ ACTION="update_manifest"
+ set_mkbuild_name $2
+ SOURCE_FILE="$3"
+ shift 2
+ ;;
+ '-n'|'--new')
+ # New mkbuild configure file
+ set_mkbuild_name $2
+ ACTION="new"
+ shift
+ ;;
+ '-s'|'--search')
+ # Search for a mkbuild file
+ set_mkbuild_name $2
+ ACTION='search'
+ ;;
+ '-e'|'--edit')
+ # Open mkbuild with $EDITOR
+ set_mkbuild_name $2
+ ACTION='edit'
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '-wc'|'--working-copy')
+ # Create an unversioned mkbuild working copy
+ set_mkbuild_name $2
+ ACTION='working_copy'
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '--get-param')
+ # Get parameter for a given mkbuild
+ set_mkbuild_name $2
+ ACTION='get_param'
+ break # we need to break otherwise specific arguments are evalued
+ ;;
+ '-d'|'--debug')
+ # Debug mode
+ set -x
+ ;;
+ '-h'|'--help' )
+ # Show help mesage
+ mkbuild_use && exit 0
+ ;;
+ '--sync' )
+ # Synchronize mkbuilds repository
+ mkbuild_update_keyring
+ sync_svn_repo $MKBUILDS_DIR $MKBUILDS_SVN
+ exit $?
+ ;;
+ '-v'|'--version')
+ # Show program version
+ eecho $normal "\n$BASENAME version $PROG_VERSION\n"
+ ;;
+ '-V' | '--verbose')
+ # Enable verbose mode
+ VERBOSE=1
+ ;;
+ '-a'|'--author')
+ # Enter with author name
+ AUTHOR=$2
+ [ ${AUTHOR:0:1} = "-" ] && handle_error $ERROR_MKBUILD_INPUT_PAR AUTHOR
+ shift
+ ;;
+ '-ai'|'--author_initials')
+ # Enter with author name
+ AUTHOR_INITIALS=$2
+ [ ${AUTHOR_INITIALS:0:1} = "-" ] && handle_error $ERROR_MKBUILD_INPUT_PAR AUTHOR_INITIALS
+ shift
+ ;;
+ '-cs'|'--const_string')
+ # Enter with construction source name string
+ CONST_STRING=$2
+ [ ${CONST_STRING:0:1} = "-" ] && handle_error $ERROR_MKBUILD_INPUT_PAR CONST_STRING
+ shift
+ ;;
+ '-md'|'--model')
+ # Enter with SlackBuild model
+ MODEL=$2
+ [ ${MODEL:0:1} = "-" ] && handle_error $ERROR_MKBUILD_INPUT_PAR MODEL
+ shift
+ ;;
+ '-j'|'--jobs')
+ # Enter with SlackBuild model
+ NUMJOBS=$2
+ [ ${NUMJOBS:0:1} = "-" ] && handle_error $ERROR_MKBUILD_INPUT_PAR NUMJOBS
+ ! is_number $NUMJOBS && handle_error $ERROR_NOT_NUMBER NUMJOBS
+ NUMJOBS="-j$NUMJOBS"
+ shift
+ ;;
+ '--prefix')
+ # Enter with SlackBuild model
+ PREFIX=$2
+ [ ${PREFIX:0:1} = "-" ] && handle_error $ERROR_MKBUILD_INPUT_PAR PREFIX
+ shift
+ ;;
+ '-pn'|'--pkg_name')
+ # Enter with package name
+ PKG_NAME=$2
+ [ ${PKG_NAME:0:1} = "-" ] && handle_error $ERROR_MKBUILD_INPUT_PAR PKG_NAME
+ shift
+ ;;
+ '-pv'|'pkg_version')
+ # Enter with package version
+ VERSION=$2
+ [ ${VERSION:0:1} = "-" ] && handle_error $ERROR_MKBUILD_INPUT_PAR VERSION
+ shift
+ ;;
+ '-sn'|'--src_name')
+ # Enter with source name
+ SRC_NAME=$2
+ [ ${SRC_NAME:0:1} = '-' ] && handle_error $ERROR_MKBUILD_INPUT_PAR SRC_NAME
+ shift
+ ;;
+ '-u'|'--url')
+ # Enter with url address
+ URL=$2
+ [ ${URL:0:1} = '-' ] && handle_error $ERROR_MKBUILD_INPUT_PAR URL
+ shift
+ ;;
+ '-pf'|'--patch-files')
+ # Path files list
+ PATCH_FILES=$2
+ [ ${PATCH_FILES:0:1} = '-' ] && handle_error $ERROR_MKBUILD_INPUT_PAR PATCH_FILES
+ shift
+ ;;
+ '-npss'|'--nps-strip')
+ # Number of prefix slashes to strip
+ NPS_STRIP=$2
+ [ ${NPS_STRIP:0:1} = '-' ] && handle_error $ERROR_MKBUILD_INPUT_PAR NPS_STRIP
+ shift
+ ;;
+ *)
+ # mkbuild input file
+ set_mkbuild_name $1
+ ;;
+ esac
+ 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`"
+
+ if [ ! -z "$search" ]; then
+ for match in $search; do
+ MKBUILD_NAME="$match"
+ WORK="`dirname $match`"
+ break
+ done
+ else
+ if [ "$ACTION" == "build" ]; then
+ ACTION='new'
+ fi
+ fi
+
+ fi
+
+ MKBUILD_NAME="${MKBUILD_NAME//.mkbuild}.mkbuild"
+ MKBUILD_BASENAME="`basename $MKBUILD_NAME .mkbuild`"
+
+}
+
+function get_variable {
+
+ # Get variable value from mkbuild file (MKBUILD_NAME)
+ [ $# -ne 1 ] && handle_error $ERROR_PAR_NUMBER
+ [ -z $MKBUILD_NAME ] && echo "Warning: no [mkbuild_file]." && return 0
+
+ sed -n '1,/^#>>/ p' $MKBUILD_NAME | grep "^\[\[${1}\]\]" | tail -n 1 | cut -f2- -d= | sed -e 's/^"//' -e 's/"$//'
+
+}
+
+function edit_file {
+
+ # Edit file $3, by change string [[$1]] to $2
+ [ $# -ne 3 ] && handle_error $ERROR_PAR_NUMBER
+
+ eval "sed -i 's¦\[\[$1\]\]¦$2¦g' $3"
+
+}
+
+function edit_file_full {
+
+ # Edit file $3, by change string $1 to $2
+ [ $# -ne 3 ] && handle_error $ERROR_PAR_NUMBER
+
+ eval "sed -i 's¦$1¦$2¦' $3"
+
+}
+
+function start_build {
+
+ # Build initial sections
+ [ $# -ne 1 ] && handle_error $ERROR_PAR_NUMBER
+
+ edit_file "SLACKBUILD AUTHOR" "$AUTHOR" $1
+ edit_file "SLACKBUILD AUTHOR INITIALS" "$AUTHOR_INITIALS" $1
+ edit_file "SOURCE NAME" "$SRC_NAME" $1
+ edit_file "PROGRAM NAME" "$PKG_NAME" $1
+ edit_file "PACKAGE NAME" "$PKG_NAME" $1
+ edit_file "DECOMPRESSOR" "$DECOMPRESSOR" $1
+ edit_file "DECOMPRESSOR TEST FLAG" "$DECOMPRESSOR_TEST_FLAG" $1
+ edit_file "PROGRAM URL" "$URL" $1
+ if [ "$ARCH" == "noarch" ]; then
+ sed -i 's/^ARCH=.*$/ARCH="noarch"/' $1
+ else
+ edit_file "ARCH" "$ARCH" $1
+ fi
+ edit_file "NUMBER OF JOBS" "$NUMJOBS" $1
+ edit_file "VERSION" "$VERSION" $1
+ edit_file "SOURCE NAME CONSTRUCTION STRING" "$CONST_STRING" $1
+ edit_file "EXTENSION" "$EXTENSION" $1
+ edit_file "MKBUILD COMPRESS" "$MKBUILD_COMPRESS" $1
+ edit_file "DOWNLOAD FOLDER URL" "$URL_BASE" $1
+ edit_file "OTHER CONFIGURE ARGS" "$OPTIONS" $1
+ edit_file "DOCUMENTATION FILES" "$DOCFILES" $1
+ edit_file "PREFIX" "$PREFIX" $1
+ edit_file "UNPACKER" "$UNPACKER" $1
+ edit_file "UNPACKER FLAGS" "$UNPACKER_FLAGS" $1
+ edit_file "BUILD NUMBER" "$BUILD_NUMBER" $1
+ edit_file "PATCH FILES" "$PATCH_FILES" $1
+ edit_file "NUMBER OF PREFIX SLASHES TO STRIP" "$NPS_STRIP" $1
+
+ edit_file_full "\$EXTENSION" "$EXTENSION" $1
+
+}
+
+function clear_files {
+
+ # Remove temporary files
+ [ ! -z $AUX_TMP ] && rm $AUX_TMP 2>/dev/null
+ [ ! -z $SLACKBUILD_TEMP ] && rm $SLACKBUILD_TEMP 2>/dev/null
+ [ ! -z $DIFF_FILE ] && rm $DIFF_FILE 2>/dev/null
+ if [ "`ls $TMP/`" == "" ]; then
+ rm -rf $TMP
+ fi
+ chmod 755 *.SlackBuild 2>/dev/null
+
+}
+
+function set_status {
+
+ # Set status section
+ # $1 - Section
+ # $2 - Status
+ # $3 - file
+ [ $# -ne 3 ] && handle_error $ERROR_PAR_NUMBER
+ if [ "`get_status $1 $3`" != "all" ]; then
+ verbose "Section $1 $2"
+ eval "sed -i 's/^<$1>.*$/<$1> $2/' $3"
+ else
+ echo "Warning: Section $1 have status all. Can't change!"
+ fi
+
+}
+
+function get_status {
+
+ # Get status from section
+ # $1 - Section
+ # $2 - file
+ [ $# -ne 2 ] && handle_error $ERROR_PAR_NUMBER
+ eval "sed '/^<$1>.*$/! d' $2"
+
+}
+
+function get_mkbuild_status {
+
+ # Get status from mkbuild file
+ # $1 section
+ eval "sed '/^#>>/,/<</ ! d; /^#/ d; /: *$1$/! d; s/^ *\(.*\):.*$/\1/' $MKBUILD_NAME"
+}
+
+function activate_sections {
+
+ # Enable and disable sections
+ ACTIONS_LIST=`sed '/^#>>/,/<</ ! d; /^#/ d ' $MKBUILD_NAME | tr -d ' '`
+ for i in $ACTIONS_LIST; do
+ STATUS=`echo $i | cut -f1 -d:`
+ SECTION=`echo $i | cut -f2 -d:`
+ set_status $SECTION $STATUS $SLACKBUILD_TEMP
+ done
+
+}
+
+function build_slackbuild {
+
+ # Clean SlackBuild
+ # Make SlackBuild backup
+ [ -e $SLACKBUILD ] && mv $SLACKBUILD $SLACKBUILD.old
+ # Remove off sections
+ sed -i '/^<[a-z].*> off/, /^<\/[a-z].*>$/ d' $SLACKBUILD_TEMP
+ # Remove sections names
+ sed -i '/^<.*$/ d' $SLACKBUILD_TEMP
+ # Remove clear lines
+ # isto pode ser feito com "cat -s SLACKBUILD_TEMP ..."
+ #sed -i ':i ; $! N; s/\n/Ø/ ; t i ; s/Ø\{3,\}/ØØ/g ; s/Ø/\n/g' $SLACKBUILD_TEMP
+ cat -s $SLACKBUILD_TEMP > $SLACKBUILD
+ # Remove from frist line do #!/... line
+ #sed '1,/^#\!/ {/^#\!/ b; d }' $SLACKBUILD_TEMP > $SLACKBUILD
+ sed -i '1,/^#\!/ {/^#\!/ b; d }' $SLACKBUILD
+
+}
+
+function section_edit {
+
+ # Edits a section substituting its content
+ [ -z $MKBUILD_NAME ] && return 0
+
+ SECTION_LIST=`grep '^#>[a-z]' $MKBUILD_NAME | cut -c3-`
+
+ # Check for sections change
+ [ -z "$SECTION_LIST" ] && return 0
+
+ # Change sections
+ for i in $SECTION_LIST; do
+ verbose "Change section $i"
+ if [ "$i" = "slackdesc" ]; then
+ # Special slackdesc section
+ slackdesc_edit > $AUX_TMP
+ mv $AUX_TMP $SLACKBUILD_TEMP
+ else
+ # Others sections
+ section_change $i
+ fi
+ done
+
+}
+
+function slackdesc_edit {
+
+ # Edit slackdesc section
+ sed -n '1,/|-----/ { /<slackdesc>/ b; /|-----/ b; p; }' $SLACKBUILD_TEMP
+ echo -n $PKG_NAME | tr [a-z+\-] " "
+ echo -n "|-----handy-ruler"
+ let N=18+${#PKG_NAME}
+ for i in `seq $N $SLACKDESC_LEN`; do
+ echo -n "-"
+ done
+ echo -en "|\n"
+
+ sed -n '/#>slackdesc/,/#<slackdesc/ { /^#/ b; p }' $MKBUILD_NAME
+ sed '1, /\[\[SLACK-DESC\]\]/ d' $SLACKBUILD_TEMP
+
+}
+
+function section_change {
+
+ # Change section lines
+ [ $# -ne 1 ] && handle_error $ERROR_PAR_NUMBER
+
+ # Copy first half
+ eval "sed '1,/^<$1>/! d' $SLACKBUILD_TEMP > $AUX_TMP"
+ # Paste new section
+ eval "sed -n '/#>$1/,/#<$1/ { /^#>/ b; /^#</ b; p }' $MKBUILD_NAME >> $AUX_TMP"
+ # Copy second halt
+ eval "sed '/^<\/$1>/,$ ! d' $SLACKBUILD_TEMP >> $AUX_TMP"
+
+ mv $AUX_TMP $SLACKBUILD_TEMP
+
+}
+
+function make_slack_required {
+
+ # Build slack-required file
+ [ -e $WORK/slack-required ] && mv $WORK/slack-required $WORK/slack-required.old
+ [ -z "$SLACK_REQUIRED" ] && return 0
+
+ echo -e "# Dependency list to $SRC_NAME\n#\n# dependency [condition] [version]]" > $WORK/slack-required
+
+ echo $SLACK_REQUIRED | sed 's/:/\n/g' | while read i; do
+ REQ=`echo $i | awk '{ print $1 }'`
+ CON=`echo $i | awk '{ print $2 }'`
+ VER=`echo $i | awk '{ print $3 }'`
+ echo -e "$REQ\t\t$CON\t\t$VER" >> $WORK/slack-required
+ done
+
+}
+
+function change_other_parameters {
+
+ # Change other parameters started by '[[' in .mkbuild file
+ sed '1,/#>>/ ! d' $MKBUILD_NAME | grep -v '^#' | grep '^\[\[[A-Za-z]' | \
+ while read i; do
+ CHANGE="`echo $i | sed 's/\[\[\(.*\)\]\]=\"\(.*\)\"/\1/'`"
+ VALUE="`echo $i | sed 's/\[\[\(.*\)\]\]=\"\(.*\)\"/\2/'`"
+ edit_file "$CHANGE" "$VALUE" $SLACKBUILD
+ done
+
+}
+
+function get_slackbuild_path {
+
+ # Search for SlackBuild Path in order:
+ # - command line parameter;
+ # - mkbuild parameters file;
+ # - SlackBuild tree;
+ # - Gentool-portage internet tree;
+ # - default path (others/unclassified/$PKG_NAME).
+
+ # Start AUX_PATH with command line parameter
+ AUX_PATH="$SLACKBUILD_PATH"
+
+ # Get in mkbuild
+ [ -z "$AUX_PATH" ] && AUX_PATH=`validate_parameter "$SLACKBUILD_PATH" "SLACKBUILD PATH" ""`
+
+ # SlackBuild path in SlackBuild tree
+ [ -z "$AUX_PATH" ] && AUX_PATH=`cd $SLACKBUILDS_DIR && find . -name $SLACKBUILD | sed -e 's/^\.\///' | xargs dirname 2>/dev/null`
+
+ # SlackBuild path default
+ [ -z "$AUX_PATH" ] && AUX_PATH="others/unclassified/$PKG_NAME"
+
+ # Down case SlackBuild path
+ eval "echo $AUX_PATH" | tr [A-Z] [a-z]
+
+}
+
+function apply_mkpatch {
+
+ # Apply mkpatch if exist
+ sed -n '/#p>/,/#p</ { /^#/ b; p }' $MKBUILD_NAME > $DIFF_FILE
+ if [ -s $DIFF_FILE ]; then
+ mkpatch $DIFF_FILE $SLACKBUILD_TEMP > $AUX_TMP || handle_error $?
+ [ ! -s $AUX_TMP ] && handle_error 1
+ cp $AUX_TMP $SLACKBUILD_TEMP
+ [ $VERBOSE -eq $on ] && ( echo -e "\nApply mkpath ..."; cat $DIFF_FILE )
+ fi
+
+}
+
+# ----------------------------------------------------------------
+# svn functions
+# ----------------------------------------------------------------
+
+function submit_slackbuild {
+
+ # Submit SlackBuild in local Slack.Sarava tree
+ echo -e "\nSubmiting $SLACKBUILD"
+
+ local candidate oldplace
+
+ # check SlackBuilds directory
+ [ ! -e $SLACKBUILDS_DIR ] && createpkg --sync
+
+ # change to SlackBuilds directory
+ cd $SLACKBUILDS_DIR/
+
+ # Add SlackBuild scripts
+ # check path
+ [ ! -e $SLACKBUILD_PATH ] && svn_mkdir $SLACKBUILD_PATH
+
+ # add SlackBuild
+ svn_copy $WORK/`basename $SLACKBUILD` $SLACKBUILD_PATH
+
+ # check and add slack-required
+ [ -e $WORK/slack-required ] && svn_copy $WORK/slack-required $SLACKBUILD_PATH
+
+ for i in `ls $WORK | grep -E -v '(SlackBuild|old|slack-required|.mkbuild$|.tmp$)\*{0,1}$'`; do
+ svn_copy $WORK/$i $SLACKBUILD_PATH
+ done
+
+ # remove stuff in old places
+ for candidate in $(find . -name $(basename $SLACKBUILD)); do
+ oldplace="`dirname $candidate | sed -e 's/^\.\///'`"
+ if [ "$oldplace" != "$SLACKBUILD_PATH" ]; then
+ echo "Removing SlackBuild found at old path $oldplace"
+ svn_del $oldplace
+ fi
+ done
+
+ if [ "$SIGN_MANIFESTS" -eq $on ]; then
+ repo_gpg_key $SLACKBUILDS_DIR
+ fi
+
+ cd $WORK
+
+}
+
+function submit_mkbuild {
+
+ # Submit mkbuild in local mkbuild Slack.Sarava tree
+ echo -e "\nSubmiting $MKBUILD_NAME"
+
+ local candidate oldplace
+
+ # Check mkbuild directory
+ [ ! -d $MKBUILDS_DIR ] && build_svn_repo $MKBUILDS_DIR $MKBUILDS_SVN
+
+ # Get mkbuild path in parameter file
+ MKBUILD_PATH=$SLACKBUILD_PATH
+
+ # Change to mkbuilds directory
+ cd $MKBUILDS_DIR/
+
+ # Check path
+ [ ! -e $MKBUILD_PATH ] && svn_mkdir $MKBUILD_PATH
+
+ # Add relevant files
+ for i in `ls $WORK | grep -E -v '(SlackBuild|old|slack-required|.tmp$)\*{0,1}$'`; do
+ if [ "`basename $i`" != "$DIST_SRC_NAME" ]; then
+ if ! is_the_same $MKBUILD_PATH $WORK; then
+ svn_copy $WORK/$i $MKBUILD_PATH
+ else
+ svn_add $WORK/$i
+ fi
+ fi
+ done
+
+ # Remove stuff in old places
+ for candidate in $(find . -name $(basename $MKBUILD_NAME)); do
+ oldplace="`dirname $candidate | sed -e 's/^\.\///'`"
+ if [ "$oldplace" != "$MKBUILD_PATH" ]; then
+ echo "Removing mkbuild found at old path $oldplace"
+ svn_del $oldplace
+ fi
+ done
+
+ submit_cleanup
+
+ cd $WORK
+
+}
+
+function submit_cleanup {
+
+ # Remove files that should not be stored at the mkbuilds repository
+ if is_the_same $MKBUILD_PATH $WORK; then
+ (
+ cd $WORK
+ rm -f *.old *.tmp *.SlackBuild slack-required $DIST_SRC_NAME
+ )
+ fi
+
+}
+
+function import_mkbuilds {
+
+ # import mkbuilds into a subversion repository
+ # usage: repository_import [repository]
+
+ local repository="$1"
+
+ if [ -z "$repository" ]; then
+ repository="file:////var/svn/mkbuilds"
+ fi
+
+ repository_import $MKBUILDS_DIR $repository
+
+}
+
+function import_slackbuilds {
+
+ # import SlackBuilds into a subversion repository
+ # usage: repository_import [repository]
+
+ local repository="$1"
+
+ if [ -z "$repository" ]; then
+ repository="file:////var/svn/slackbuilds"
+ fi
+
+ repository_import $SLACKBUILDS_DIR $repository
+
+}
+
+function repository_status {
+
+ local cwd
+
+ if svn_folder $MKBUILDS_DIR; then
+ echo "Status of $MKBUILDS_DIR."
+ cwd="`pwd`"
+ cd $MKBUILDS_DIR && su_svn status
+ cd $cwd
+ fi
+
+ if svn_folder $SLACKBUILDS_DIR; then
+ cwd="`pwd`"
+ echo "Status of $SLACKBUILDS_DIR."
+ cd $SLACKBUILDS_DIR && su_svn status
+ cd $cwd
+ fi
+
+ exit 0
+
+}
+
+# ----------------------------------------------------------------
+# general functions
+# ----------------------------------------------------------------
+
+function validate_parameter {
+
+ # Validate parameter in .mkbuild file
+ [ $# -ne 3 ] && handle_error $ERROR_PAR_NUMBER
+
+ if [ ! -z "$1" ]; then
+ echo "$1"
+ else
+ local STRING="`get_variable "$2"`"
+ if [ ! -z "$STRING" ]; then
+ echo "$STRING"
+ else
+ echo "$3"
+ fi
+ fi
+
+}
+
+function decompress_find {
+
+ # Find decompressor program and test flag
+ case $EXTENSION in
+ 'gz'|'GZ')
+ DECOMPRESSOR="gunzip"
+ DECOMPRESSOR_TEST_FLAG="-t"
+ ;;
+ 'bz2'|'BZ2')
+ DECOMPRESSOR="bunzip2"
+ DECOMPRESSOR_TEST_FLAG="-t"
+ ;;
+ 'zip'|'ZIP')
+ DECOMPRESSOR="unzip"
+ DECOMPRESSOR_TEST_FLAG="-t"
+ ;;
+ *)
+ handle_error $ERROR_MKBUILD_CONSTRUCTION "DECOMPRESSOR"
+ ;;
+ esac
+
+}
+
+function load_parameters {
+
+ # Load Createpkg parameters
+ SOURCE_DIR="`eval_parameter SOURCE_DIR /var/simplepkg/sources`"
+ SLACKBUILDS_DIR="`eval_parameter SLACKBUILDS_DIR /var/simplepkg/slackbuilds`"
+ [ ! -d $SLACKBUILDS_DIR ] && mkdir -p $SLACKBUILDS_DIR
+
+ MKBUILDS_DIR="`eval_parameter MKBUILDS_DIR /var/simplepkg/mkbuilds`"
+ [ ! -d $SLACKBUILDS_DIR ] && mkdir -p $SLACKBUILDS_DIR
+
+ SLACKBUILDS_SVN="`eval_parameter SLACKBUILDS_DIR http://slack.sarava.org/slackbuilds`"
+ MKBUILDS_SVN="`eval_parameter MKBUILDS_SVN http://slack.sarava.org/mkbuilds`"
+ SVN_USER="`eval_parameter MKBUILDS_SVN_USER`"
+ SVN_GROUP="`eval_parameter MKBUILDS_SVN_GROUP`"
+
+ COLOR_MODE="`eval_parameter COLOR_MODE none`"
+ TMP="`eval_parameter TMP /tmp`"
+ [ ! -e $TMP ] && mkdir -p $TMP
+
+ MKBUILD_COMPRESS="`eval_parameter MKBUILD_COMPRESS tgz`"
+ MKBUILD_AUTHOR="`eval_parameter MKBUILD_AUTHOR`"
+ MKBUILD_AUTHOR_INITIALS="`eval_parameter MKBUILD_AUTHOR_INITIALS`"
+
+ SIGN_MANIFESTS="`eval_boolean_parameter SIGN_MANIFESTS $off`"
+ SIGN_MANIFESTS_USER="`eval_parameter SIGN_MANIFESTS_USER`"
+ SIGN_MANIFESTS_KEYID="`eval_parameter SIGN_MANIFESTS_KEYID`"
+ SIGN_MANIFESTS_WITH_GPG_AGENT="`eval_boolean_parameter SIGN_MANIFESTS_WITH_GPG_AGENT $off`"
+
+ if [ ! -z "$SIGN_MANIFESTS_KEYID" ]; then
+ SIGN_MANIFESTS_KEYID="`echo $SIGN_MANIFESTS_KEYID | tr '[:lower:]' '[:upper:]'`"
+ fi
+
+ if [ "$SIGN_MANIFESTS_WITH_GPG_AGENT" -eq $on ]; then
+ GPG_AGENT_OPTION="--use-agent"
+ else
+ GPG_AGENT_OPTION=""
+ fi
+
+ # For use at common.sh functions
+ SIGN="$SIGN_MANIFESTS"
+ SIGN_KEYID="$SIGN_MANIFESTS_KEYID"
+ SIGN_USER="$SIGN_MANIFESTS_USER"
+
+ if [ "$SIGN_MANIFESTS" -eq $on ]; then
+ get_sign_user
+ fi
+
+}
+
+function file_metainfo {
+
+ # get integrity file metadata
+ # usage: file_metainfo <file> <file_type> <manifest_file>
+
+ local sum="" file="$1" file_type="`echo $2 | tr '[:lower:]' '[:upper:]'`"
+ local size algo candidate folders path manifest_file="$3"
+ local dist_name="`basename $file`"
+
+ if [ -d "$file" ]; then
+ return
+ fi
+
+ if [ -z "$file_type" ]; then
+ file_type="AUX"
+ fi
+
+ if [ ! -e "$file" ]; then
+ if [ "$file_type" == "DIST" ]; then
+
+ # Add DIST information only if source is not under revision control
+ if [ $SVN_MOD -eq $on -o $GIT_MOD -eq $on ]; then
+ return
+ fi
+
+ # Force DIST file name at Manifest
+ dist_name="$DIST_SRC_NAME"
+
+ # Determine file location
+ get_dist_file
+
+ # Update Manifest metadata
+ if [ -e "$DIST_SRC_LOCATION" ]; then
+ file="$DIST_SRC_LOCATION"
+ else
+ echo "$file_type $dist_name " >> $manifest_file # end space is important
+ return 1
+ fi
+
+ elif [ "$file_type" == "PATCH" ]; then
+
+ # Determine file location
+ get_patch_file $file
+
+ # Update Manifest metadata
+ if [ -e "$DOWNLOADED_PATCH_LOCATION" ]; then
+ file="$DOWNLOADED_PATCH_LOCATION"
+ else
+ echo "$file_type $dist_name " >> $manifest_file # end space is important
+ return 1
+ fi
+
+ else
+ echo "$file_type $dist_name " >> $manifest_file # end space is important
+ return 1
+ fi
+ fi
+
+ for algo in md5 rmd160 sha1 sha256 sha512; do
+ sum="$sum `echo $algo | tr '[:lower:]' '[:upper:]'` `gethash $algo $file`"
+ done
+
+ echo $file_type $dist_name `file_size $file` $sum >> $manifest_file
+
+ if [ "$file_type" == "DIST" ] || [ "$file_type" == "PATCH" ]; then
+ echo "Please make sure that the following hashes are correct:"
+ grep -e "^$file_type $dist_name " $manifest_file
+ fi
+
+}
+
+function update_manifest_info {
+
+ # update manifest metainfo for a given file
+ # usage: update_manifest_info <file> <file_type>
+
+ local tmpfile file="$1" file_type="`echo $2 | tr '[:lower:]' '[:upper:]'`"
+
+ if [ -z "$file_type" ]; then
+ file_type="`file_extension $file | tr '[:lower:]' '[:upper:]'`"
+ fi
+
+ # Update Manifest file
+ if [ ! -e "$WORK/Manifest" ]; then
+ touch $WORK/Manifest
+ fi
+
+ # Set temporary file
+ tmpfile="`mktemp $TMP/mkbuild_manifest.XXXXXX`"
+
+ # Update metadata
+ sed -e "/^$file_type `basename $file` /d" $WORK/Manifest > $tmpfile
+ file_metainfo $file $file_type $tmpfile
+
+ if [ "$?" != "0" ]; then
+ echo "Could not add hashes for $file on Manifest: file not found."
+ echo "Please do it with --update-manifest."
+ fi
+
+ # Save Manifest changes
+ strip_gpg_signature $tmpfile | sort > $WORK/Manifest
+
+ rm -f $tmpfile
+
+}
+
+function edit_manifest {
+
+ local option="$1"
+
+ # Check if existing Manifest is properly signed
+ if ! check_manifest_signature; then
+ echo "Invalid signature at $WORK/Manifest, aborting."
+ return 1
+ fi
+
+ # Update Manifest file
+ echo "Updating Manifest..."
+
+ # Update mkbuild metainformation
+ update_manifest_info $WORK/`basename $MKBUILD_NAME`
+
+ # Update SlackBuild information
+ update_manifest_info $WORK/`basename $SLACKBUILD`
+
+ # Update slack-required information
+ if [ -e "$WORK/slack-required" ]; then
+ update_manifest_info $WORK/slack-required
+ fi
+
+ if [ "$option" == "--update" ]; then
+ # Add DIST information only if source is not under revision control
+ if [ $SVN_MOD -eq $on -o $GIT_MOD -eq $on ]; then
+ echo "Source is under version control system, not adding hashes to Manifest."
+ else
+ echo "Updating DIST information at $MKBUILD_NAME Manifest..."
+
+ # Determine file location
+ get_dist_file $SOURCE_FILE
+
+ # Update Manifest metadata
+ if [ -e "$DIST_SRC_LOCATION" ]; then
+ update_manifest_info $DIST_SRC_LOCATION dist
+ else
+ echo "Can't get $DIST_SRC_NAME."
+ fi
+ fi
+ else
+ # Add source code information if its not already there
+ if ! grep -q -e "^DIST $DIST_SRC_NAME " $WORK/Manifest; then
+ update_manifest_info $DIST_SRC_NAME dist
+ fi
+ fi
+
+ # Update patches
+ for i in `find $WORK | grep -E '(.diff$|.diff.gz$|.diff.bz2$|.patch$|.patch.gz$|.patch.bz2$)\*{0,1}$'`; do
+ if [ ! -d "$WORK/$i" ] && ! grep -q -e "^PATCH `basename $i` " $WORK/Manifest; then
+ update_manifest_info $i patch
+ fi
+ done
+
+ # Update patches from URLs
+ for i in $PATCH_URLS; do
+ if ! grep -q -e "^PATCH `basename $i` " $WORK/Manifest; then
+ update_manifest_info $i patch
+ fi
+ done
+
+ # Update miscelaneous information
+ for i in `find $WORK | grep -E -v '(SlackBuild|old|slack-required|.mkbuild$|.tmp$|Manifest$)\*{0,1}$' | \
+ grep -E -v '(.diff$|.diff.gz$|.diff.bz2$|.patch$|.patch.gz$|.patch.bz2$)\*{0,1}$' | \
+ grep -v "/\.svn"`; do
+ # Avoid folders, dotfiles and DIST files
+ if [ ! -d "$WORK/$i" ] && \
+ [ "`basename $i`" != "$DIST_SRC_NAME" ] && \
+ ! echo "`basename $i`" | grep -q -e "^\."; then
+ update_manifest_info $i misc
+ fi
+ done
+
+ # Finally, sign the Manifest
+ sign_manifest
+
+}
+
+function get_file {
+
+ # download a file
+ # usage: download_file <file_type> <url> [file] [dist_name]
+
+ local folder folders path candidate
+ local file_type="`echo $1 | tr '[:lower:]' '[:upper:]'`"
+ local url="$2" file="$3" file_name="$4"
+ local protocol="`echo $url| cut -d : -f 1 | tr '[:upper:]' '[:lower:]'`"
+
+ if [ -z "$file_name" ]; then
+ if [ "$file_type" == "DIST" ]; then
+ file_name="$DIST_SRC_NAME"
+ else
+ file_name="`basename $url`"
+ fi
+ fi
+
+ # Clean global var
+ DOWNLOADED_FILE_LOCATION=""
+
+ # Determine file location
+ if [ -d "$file" ]; then
+
+ folder="$file"
+ file="$file_name"
+ for candidate in $(find $folder -name $(basename $file)); do
+ if [ ! -z "$candidate" ]; then
+ break 2
+ fi
+ done
+
+ if [ ! -z "$candidate" ]; then
+ echo "Using $(basename $candidate) found at $(dirname $candidate) to hash at the Manifest."
+ file="$candidate"
+ else
+ echo "Can't find $file at $folder."
+ return 1
+ fi
+
+ elif [ -z "$file" ]; then
+
+ file="$file_name"
+ folders="$WORK $TMP $SOURCE_DIR"
+ if ! is_the_same /tmp $TMP; then
+ folders="$folders /tmp"
+ fi
+
+ echo "Trying to find $(basename $file) at $folders..."
+
+ for path in $folders; do
+ for candidate in $(find $path -name $(basename $file) 2> /dev/null); do
+ if [ ! -z "$candidate" ]; then
+ break 2
+ fi
+ done
+ done
+
+ if [ ! -z "$candidate" ]; then
+
+ echo "Using $(basename $candidate) found at $(dirname $candidate) to hash at the Manifest."
+ file="$candidate"
+
+ elif [ "$protocol" == "https" ] || \
+ [ "$protocol" == "http" ] || \
+ [ "$protocol" == "ftp" ]; then
+
+ # Try to donwload the file
+ echo "File $file not found, trying to download it..."
+ if [ ! -e "$file" ]; then
+ if is_writable_folder $SOURCE_DIR/$PKG_NAME; then
+ file="$SOURCE_DIR/$PKG_NAME/`basename $file_name`"
+ wget "$url" -O "$file"
+ if [ "$?" != "0" ]; then
+ echo "Could not download $file"
+ return 1
+ fi
+ elif is_writable_folder $TMP; then
+ file="$TMP/`basename $file_name`"
+ if [ ! -e "$file" ]; then
+ wget "$url" -O "$file"
+ if [ "$?" != "0" ]; then
+ echo "Could not download $file"
+ return 1
+ fi
+ fi
+ elif ! is_the_same /tmp $TMP; then
+ file="/tmp/`basename $file_name`"
+ if [ ! -e "$file" ]; then
+ wget "$url" -O "$file"
+ if [ "$?" != "0" ]; then
+ echo "Could not download $file"
+ return 1
+ fi
+ fi
+ else
+ echo "Could not download $file"
+ return 1
+ fi
+ fi
+ fi
+ fi
+
+ if [ -e "$file" ]; then
+ DOWNLOADED_FILE_LOCATION="$file"
+ fi
+
+}
+
+function get_dist_file {
+
+ # get package source code
+ # usage: get_dist_file <url> [file_name]
+
+ DIST_SRC_LOCATION=""
+ get_file dist $DIST_SRC_URL
+ DIST_SRC_LOCATION="$DOWNLOADED_FILE_LOCATION"
+
+}
+
+function get_patch_file {
+
+ # get a patch
+ # usage: get_patch <file_name>
+
+ local patch_url file_name="$1"
+
+ if [ -z "$file_name" ]; then
+ return 1
+ fi
+
+ DOWNLOADED_PATCH_LOCATION=""
+
+ for patch_url in $PATCH_URLS; do
+ if [ "`basename $file_name`" == "`basename $patch_url`" ]; then
+ get_file patch $patch_url
+ DOWNLOADED_PATCH_LOCATION="$DOWNLOADED_FILE_LOCATION"
+ break
+ fi
+ done
+
+}
+
+function update_manifest {
+
+ # Get mkbuild values
+ get_mkbuild_values
+
+ # Update the Manifest
+ edit_manifest --update
+
+}
+
+function if_previous_error {
+
+ if [ "$?" != "0" ]; then
+ handle_error $*
+ fi
+
+}
+
+function verbose {
+
+ if [ $VERBOSE -eq $on ]; then
+ echo $*
+ fi
+
+}
+
+function get_mkbuild_values {
+
+ # Get values
+ # Author name
+ AUTHOR=${AUTHOR:="`get_variable "SLACKBUILD AUTHOR"`"}
+ [ -z "$AUTHOR" ] && handle_error $ERROR_MKBUILD_CONSTRUCTION "SLACKBUILD AUTHOR"
+ verbose "[[SLACKBUILD AUTHOR]]=\"$AUTHOR\""
+
+ # Author initials
+ STR_MOUNT=`echo $AUTHOR | sed 's/ /\n/g' | sed 's/^\([A-Z]\).*/\1/' | sed ':i; $!N; s/\n//; ti' | tr [A-Z] [a-z]`
+ AUTHOR_INITIALS="`validate_parameter "$AUTHOR_INITIALS" "SLACKBUILD AUTHOR INITIALS" "$STR_MOUNT"`"
+ if_previous_error $ERROR_MKBUILD_CONSTRUCTION "SLACKBUILD AUTHOR INITIALS"
+ verbose "[[SLACKBUILD AUTHOR INITIALS]]=\"$AUTHOR_INITIALS\""
+
+ # URL program
+ URL=`validate_parameter "$URL" "DOWNLOAD FOLDER URL" ""`
+ if_previous_error handle_error $ERROR_MKBUILD_CONSTRUCTION "URL"
+ verbose "[[URL]]=\"$URL\""
+
+ AUX=`get_mkbuild_status "svn_source"`
+ SVN_MOD=`convert_boolean "$AUX"`
+
+ AUX=`get_mkbuild_status "git_source"`
+ GIT_MOD=`convert_boolean "$AUX"`
+
+ # Check sections
+ if [ $SVN_MOD -eq $on -o $GIT_MOD -eq $on -o $URL == "" ]; then
+ LIST_OFF="download_source md5sum_download_and_check_0 md5sum_download_and_check_1 gpg_signature_check untar_source"
+ verbose -e "\nCheck subversion or empty URL"
+ for i in $LIST_OFF; do
+ if [ `get_mkbuild_status "$i"` != "off" ]; then
+ handle_error $ERROR_MKBUILD_VCS
+ else
+ verbose -e "off: $i is ok."
+ fi
+ done
+ fi
+
+ STR_MOUNT="`echo $URL | sed 's/.*\.\([a-z0-9]\+\)$/\1/'`"
+ if [ $STR_MOUNT = "gz" -o $STR_MOUNT = "tgz" -o $STR_MOUNT = "bz2" -o $STR_MOUNT = "zip" ]; then
+ SOURCE_NAME=`basename $URL`
+ URL_BASE=`dirname $URL`
+ else
+ URL_BASE=$URL
+ fi
+ verbose "[[DOWNLOAD FOLDER URL]]=\"$URL_BASE\""
+
+ if [ $SVN_MOD -eq $off ] && [ $GIT_MOD -eq $off ]; then
+ # Extension
+ EXTENSION=`validate_parameter "$EXTENSION" "EXTENSION" "$STR_MOUNT"`
+ if_previous_error handle_error $ERROR_MKBUILD_CONSTRUCTION "EXTENSION"
+ verbose "[[EXTENSION]]=\"$EXTENSION\""
+
+ # Unpacker
+ UNPACKER=`validate_parameter "$UNPACKER" "UNPACKER" "tar"`
+ if_previous_error handle_error $ERROR_MKBUILD_CONSTRUCTION "UNPACKER"
+ verbose "[[UNPACKER]]=\"$UNPACKER\""
+
+ # Unpacker flags
+ [ "$UNPACKER" == "tar" ] && STR_MOUNT="--no-same-owner --no-same-permissions -xvf" || STR_MOUNT=""
+ UNPACKER_FLAGS=`validate_parameter "$UNPACKER_FLAGS" "UNPACKER FLAGS" "$STR_MOUNT"`
+ if_previous_error handle_error $ERROR_MKBUILD_CONSTRUCTION "UNPACKER FLAGS"
+ verbose "[[UNPACKER_FLAGS]]=\"$UNPACKER_FLAGS\""
+
+ # Decompressor program and test flag
+ DECOMPRESSOR=`validate_parameter "$DECOMPRESSOR" "DECOMPRESSOR" ""`
+ [ -z $DECOMPRESSOR ] && decompress_find
+ verbose "[[DECOMPRESSOR]]=\"$DECOMPRESSOR\""
+
+ DECOMPRESSOR_TEST_FLAG=`validate_parameter "$DECOMPRESSOR_TEST_FLAG" "DECOMPRESSOR TEST FLAG" ""`
+ if_previous_error handle_error $ERROR_MKBUILD_CONSTRUCTION "DECOMPRESSOR TEST FLAG"
+ verbose "[[DECOMPRESSOR TEST FLAG]]=\"$DECOMPRESSOR_TEST_FLAG\""
+ fi
+
+ # Build number
+ BUILD_NUMBER=`validate_parameter "$BUILD_NUMBER" "BUILD NUMBER" "1"`
+ if_previous_error handle_error $ERROR_MKBUILD_CONSTRUCTION "BUILD NUMBER"
+
+ # Build archteture
+ ARCH=`validate_parameter "$ARCH" "ARCH" "i486"`
+ verbose "[[ARCH]]=\"$ARCH\""
+
+ # Source name
+ STR_MOUNT=`echo $SOURCE_NAME | sed -r 's/(.*)-(.*)\.(.*\..*)$/\1/'`
+ SRC_NAME=`validate_parameter "$SRC_NAME" "SOURCE NAME" "$STR_MOUNT"`
+ if_previous_error handle_error $ERROR_MKBUILD_CONSTRUCTION "SOURCE NAME"
+ verbose "[[SOURCE NAME]]=\"$SRC_NAME\""
+
+ # SOURCE NAME cannot be empty
+ if [ -z "$SRC_NAME" ]; then
+ echo "SOURCE NAME is empty."
+ handle_error $ERROR_MKBUILD_CONSTRUCTION "SOURCE NAME"
+ fi
+
+ # Package name
+ STR_MOUNT=$SRC_NAME
+ PKG_NAME=`validate_parameter "$PKG_NAME" "PACKAGE NAME" "$STR_MOUNT"`
+ verbose "[[PACKAGE NAME]]=\"$PKG_NAME\""
+
+ # PACKAGE NAME cannot be empty
+ if [ -z "$PKG_NAME" ]; then
+ echo "PACKAGE NAME is empty."
+ handle_error $ERROR_MKBUILD_CONSTRUCTION "PACKAGE NAME"
+ fi
+
+ # Version
+ STR_MOUNT=`echo $SOURCE_NAME | sed -r 's/(.*)-(.*)\.(.*\..*)$/\2/'`
+ VERSION=`validate_parameter "$VERSION" "VERSION" "$STR_MOUNT"`
+ if_previous_error handle_error $ERROR_MKBUILD_CONSTRUCTION "VERSION"
+ verbose "[[VERSION]]=\"$VERSION\""
+
+ # Source name construction string
+ CONST_STRING="`validate_parameter "$CONST_STRING" "SOURCE NAME CONSTRUCTION STRING" "\\\$SRC_NAME-\\\$VERSION.tar.$EXTENSION"`"
+ verbose "[[SOURCE NAME CONSTRUCTION STRING]]=\"$CONST_STRING\""
+
+ # Build Source Name
+ [ -z $SOURCE_NAME ] && SOURCE_NAME=`eval "echo $CONST_STRING"`
+ verbose "SOURCE_NAME=\"$SOURCE_NAME\""
+
+ # Eval source code name and URL
+ DIST_SRC_NAME="`eval "echo $CONST_STRING"`" # we need this to strip some escape strings
+ DIST_SRC_NAME="`eval "echo $DIST_SRC_NAME"`" # twice does the job
+ DIST_SRC_URL="`eval "echo $URL_BASE"`" # we need this to strip some escape strings
+ DIST_SRC_URL="`eval "echo $DIST_SRC_URL"`" # twice does the job
+ DIST_SRC_URL="$DIST_SRC_URL/$DIST_SRC_NAME"
+
+ # Documentations list
+ DEFAULT_DOCFILES="NEWS TODO README AUTHORS INSTALL ChangeLog MAINTAINERS COPYING LICENSE SIGNATURE readme.*"
+ DOCFILES=`validate_parameter "$DOCFILES" "DOCUMENTATION FILES" "$DEFAULT_DOCFILES"`
+ verbose "[[DOCUMENTATION FILES]]=\"$DOCFILES\""
+
+ # ./configure option
+ OPTIONS=`validate_parameter "$OPTIONS" "OTHER CONFIGURE ARGS" ""`
+ verbose "[[OTHER CONFIGURE ARGS]]=\"$OPTIONS\""
+
+ # PREFIX
+ PREFIX=`validate_parameter "$PREFIX" "PREFIX" "/usr"`
+ verbose "[[PREFIX]]=\"$PREFIX\""
+
+ # Number of jobs
+ NUMJOBS=`validate_parameter "$NUMJOBS" "NUMBER OF JOBS" ""`
+ is_number $NUMJOBS && NUMJOBS="-j${NUMJOBS}"
+ verbose "[[NUMBER OF JOBS]]=\"$NUMJOBS\""
+
+ # Make slack-required file
+ SLACK_REQUIRED=`validate_parameter "$SLACK_REQUIRED" "SLACK REQUIRED" ""`
+ verbose "[[SLACK REQUIRED]]=\"$SLACK_REQUIRED\""
+
+ # SlackBuild model
+ MODEL=`validate_parameter "$MODEL" "SLACKBUILD MODEL" "generic.mkSlackBuild"`
+ verbose "[[SLACKBUILD MODEL]]=\"$MODEL\""
+
+ # PATCH FILES
+ PATCH_FILES=`validate_parameter "$PATCH_FILES" "PATCH FILES" ""`
+ verbose "[[PATCH_FILES]]=\"$PATCH_FILES\""
+
+ # PATCH URLs
+ PATCH_URLS=`validate_parameter "$PATCH_URLS" "PATCH URLS" ""`
+ verbose "[[PATCH_URLS]]=\"$PATCH_URLS\""
+
+ # Strip the smallest prefix containing num leading slashes from each file name found in the patch file.
+ NPS_STRIP=`validate_parameter "$NPS_STRIP" "NUMBER OF PREFIX SLASHES TO STRIP" "1"`
+ verbose "[[NUMBER OF PREFIX SLASHES TO STRIP]]=\"$NPS_STRIP\""
+
+ # SlackBuild path
+ # SlackBuild path in mkbuild parameters file
+ SLACKBUILD=$WORK/${PKG_NAME}.SlackBuild
+ SLACKBUILD_PATH=`get_slackbuild_path`
+ verbose "[[SLACKBUILD PATH]]=\"$SLACKBUILD_PATH\""
+
+}
+
+function make_slackbuild {
+
+ #--------------------------------------------------------------
+ #- Start build SlackBuild -
+ #--------------------------------------------------------------
+
+ # Get mkbuild values
+ get_mkbuild_values
+
+ verbose -e "\nStart SlackBuild make"
+ SLACKBUILD_TEMP=$SLACKBUILD.tmp
+ cp $MODEL_DIR/$MODEL $SLACKBUILD_TEMP
+
+ # Apply mkpatch
+ verbose -e "\nMkpatch section ..."
+ apply_mkpatch
+
+ # On/Off sections
+ verbose -e "\nEnable/disable sections ..."
+ activate_sections
+
+ # Change sections
+ verbose -e "\nEdit sections ..."
+ section_edit
+
+ # Change strings from model
+ verbose -e "\nChange strings in $PACKAGE.SlackBuild model..."
+ start_build $SLACKBUILD_TEMP
+
+ # Remove off sections
+ verbose -e "\nRemove off sections ..."
+ build_slackbuild
+
+ # Make slack-required file
+ verbose -e "\nMake slack-required file ..."
+ make_slack_required
+
+ if [ -e slack-required ]; then
+ DEPENDENCY_LIST="`cat $WORK/slack-required | awk '{print $1}' | grep '^[a-z]' | tr '\012' ' '`"
+ edit_file "REQUIRES" "$DEPENDENCY_LIST" $SLACKBUILD
+ else
+ edit_file "REQUIRES" " " $SLACKBUILD
+ fi
+
+ # Others changes
+ verbose -e "\nEdit other [[]] parameters ..."
+ change_other_parameters
+
+ if [ "$SIGN_MANIFESTS" -eq $on ]; then
+ mkbuild_update_keyring
+ repo_gpg_key $MKBUILDS_DIR
+ fi
+
+ # Update Manifest file
+ edit_manifest
+
+ if [ "$?" == "0" ]; then
+
+ # Commit SlackBuild
+ [ $SUBMIT_SLACKBUILD -eq $on ] && submit_slackbuild
+
+ # Commit mkbuild
+ [ $SUBMIT_MKBUILD -eq $on ] && submit_mkbuild
+ fi
+
+}
+
+function create_mkbuild {
+
+ # Create a new .mkbuild parameters-file
+ cp $MODEL_DIR/model.mkbuild $MKBUILD_NAME
+
+ if [ -z "$AUTHOR" ] && [ ! -z "$MKBUILD_AUTHOR" ]; then
+ AUTHOR="$MKBUILD_AUTHOR"
+ fi
+
+ if [ -z "$AUTHOR_INITIALS" ] && [ ! -z "$MKBUILD_AUTHOR_INITIALS" ]; then
+ AUTHOR_INITIALS="$MKBUILD_AUTHOR_INITIALS"
+ fi
+
+ # Package Author
+ if [ ! -z "$AUTHOR" ]; then
+ edit_file "YOUR NAME" "${AUTHOR}" $MKBUILD_NAME
+ # Package Author Signature
+ if [ -z "$AUTHOR_INITIALS" ]; then
+ AUTHOR_INITIALS=`echo $AUTHOR | tr '[A-Z]' '[a-z]' | sed 's/ /\n/g' | sed 's/^\([a-z]\).*/\1/' | sed ':i ; $! N ; s/\n// ; t i'`
+ fi
+ edit_file "YOUR SIGNATURE" "${AUTHOR_INITIALS}" $MKBUILD_NAME
+ fi
+
+ # Change Default SourceForge URL
+ [ -z "$URL" ] && URL="http://downloads.sourceforge.net/[[PKG NAME]]/"
+ edit_file "DEFAULT URL" "${URL}" $MKBUILD_NAME
+
+ # Change Package Name
+ edit_file "PKG NAME" "${MKBUILD_NAME//.mkbuild}" $MKBUILD_NAME
+
+ # Change SlackBuild Path
+ if [ ! -z "$MKBUILD_PATH" ]; then
+ edit_file_full "\[\[SLACKBUILD PATH\]\]=.*" "\[\[SLACKBUILD PATH\]\]=\"`regexp_slash $MKBUILD_PATH`\"" $MKBUILD_NAME
+ fi
+
+ # Print .mkbuild name
+ echo "$MKBUILD_NAME"
+
+}
+
+function search_mkbuild {
+
+ # find a given mkbuild
+ # usage: search_mkbuild [-i]
+
+ if [ "$MKBUILD_NAME" == ".mkbuild" ]; then
+ list_mkbuilds
+ return
+ fi
+
+ if [ ! -z "$MKBUILD_PATH" ]; then
+ if echo $name | grep -q -e "\.mkbuild$"; then
+ if [ -d "$MKBUILDS_DIR/$MKBUILD_PATH" ]; then
+ find $MKBUILDS_DIR/$MKBUILD_PATH -name $MKBUILD_NAME
+ else
+ find $MKBUILDS_DIR -name $MKBUILD_NAME
+ fi
+ else
+ if [ -d "$MKBUILDS_DIR/$MKBUILD_PATH" ]; then
+ find $MKBUILDS_DIR/$MKBUILD_PATH -name '*.mkbuild'
+ fi
+ fi
+ else
+ if [ "$1" == "-i" ]; then
+ # case insensitive mode
+ find $MKBUILDS_DIR -iname $MKBUILD_NAME
+ else
+ find $MKBUILDS_DIR -name $MKBUILD_NAME
+ fi
+ fi
+
+}
+
+function set_mkbuild_name {
+
+ local name="$1"
+
+ MKBUILD_PATH=""
+
+ if [ ! -z "$name" ]; then
+ MKBUILD_NAME="`basename $name`"
+ fi
+
+ if echo $name | grep -q "/"; then
+ if echo $name | grep -q -e "\.mkbuild$"; then
+ MKBUILD_NAME="`basename $name`"
+ MKBUILD_PATH="`dirname $name`"
+ else
+ MKBUILD_PATH="$name"
+ fi
+ else
+ MKBUILD_NAME="${name//.mkbuild}.mkbuild"
+ fi
+
+}
+
+function list_mkbuilds {
+
+ # list all available mkbuilds
+ # usage: list_mkbuilds
+
+ list_builds $MKBUILDS_DIR mkbuild
+
+}
+
+function edit_mkbuild {
+
+ # edit a mkbuild
+ # usage: edit_mkbuild
+
+ if [ -e "$MKBUILD_NAME" ]; then
+ if [ -z "$EDITOR" ]; then
+ EDITOR="vi"
+ fi
+ $EDITOR $MKBUILD_NAME
+ else
+ echo "Not found: $MKBUILD_NAME"
+ return 1
+ fi
+
+}
+
+function mkbuild_update_keyring {
+
+ # Update keyring using GPG-KEY from
+ # mkbuild repository
+
+ update_keyring $MKBUILDS_DIR/GPG-KEY
+
+}
+
+function sign_manifest {
+
+ # sign manifest file
+ # usage: sign_manifest
+
+ if [ "$SIGN_MANIFESTS" -eq $on ]; then
+ echo "Signing Manifest..."
+ if [ ! -z "$SIGN_USER" ] && [ "`whoami`" != "$SIGN_USER" ]; then
+ su $SIGN_USER -c "gpg $GPG_AGENT_OPTION --clearsign -u $SIGN_KEYID $WORK/Manifest"
+ mv $WORK/Manifest.asc $WORK/Manifest
+ else
+ gpg $GPG_AGENT_OPTION --clearsign -u $SIGN_KEYID $WORK/Manifest
+ mv $WORK/Manifest.asc $WORK/Manifest
+ fi
+ fi
+
+}
+
+function check_manifest_signature {
+
+ # check if a manifest signature is valid
+ # usage: check_manifest_signature
+
+ if [ -e "$WORK/Manifest" ]; then
+ if grep -q -- "-----BEGIN PGP SIGNED MESSAGE-----" $WORK/Manifest; then
+ echo "Checking existing Manifest signature..."
+ mkbuild_update_keyring
+ if [ ! -z "$SIGN_USER" ] && [ "`whoami`" != "$SIGN_USER" ]; then
+ su $SIGN_USER -c "gpg --verify $WORK/Manifest"
+ if [ "$?" != "0" ]; then
+ return 1
+ fi
+ else
+ gpg --verify $WORK/Manifest
+ if [ "$?" != "0" ]; then
+ return 1
+ fi
+ fi
+ fi
+ fi
+
+}
+
+function delete_mkbuild {
+
+ # delete content from a mkbuild folder
+ # usage: delete_mkbuilds [file]
+
+ local folder candidate file="$1"
+ local name="`basename $MKBUILD_NAME .mkbuild`.mkbuild"
+
+ for candidate in `find $MKBUILDS_DIR -name $name`; do
+ folder="`dirname $candidate`"
+ if [ -d "$folder" ]; then
+ if [ -z "$1" ]; then
+ # Delete the whole mkbuild folder
+ svn_del $folder
+ elif [ -e "$folder/$file" ]; then
+ svn_del $folder/$file
+ fi
+ fi
+ done
+
+}
+
+function delete_slackbuild {
+
+ # delete content from a SlackBuild folder
+ # usage: delete_slackbuilds [file]
+
+ local folder candidate file="$1"
+ local name="`basename $MKBUILD_NAME .mkbuild`.SlackBuild"
+
+ for candidate in `find $SLACKBUILDS_DIR -name $name`; do
+ folder="`dirname $candidate`"
+ if [ -d "$folder" ]; then
+ if [ -z "$1" ]; then
+ # Delete the whole mkbuild folder
+ svn_del $folder
+ elif [ -e "$folder/$file" ]; then
+ svn_del $folder/$file
+ fi
+ fi
+ done
+
+}
+
+function list_mkbuild_contents {
+
+ if [ -e "$MKBUILD_NAME" ]; then
+ ls `dirname $MKBUILD_NAME`
+ else
+ echo "Not found: $MKBUILD_NAME"
+ return 1
+ fi
+
+}
+
+function working_copy {
+
+ local copy tmpfolder name
+
+ if [ -e "$MKBUILD_NAME" ]; then
+ name="$(basename $MKBUILD_NAME .mkbuild)"
+ copy="$(basename $(basename $MKBUILD_NAME .mkbuild))"
+ if [ -d "$copy" ]; then
+ tmpfolder="`mktemp $name.XXXXXX`"
+ mv $copy $tmpfolder/
+ fi
+ rsync -av --exclude=".svn" --exclude=".git" `dirname $MKBUILD_NAME`/ $copy/ &> /dev/null
+ echo "Working copy for $name set at $(pwd)/$name."
+ else
+ echo "Not found: $MKBUILD_NAME"
+ return 1
+ fi
+
+}
+
+function get_param {
+
+ # get a parameter from a mkbuild file
+ # usage: get_param <parameter>
+
+ local parameter="`echo $* | tr '[:lower:]' '[:upper:] | tr -d '"' | tr -d "'"'`"
+
+ if [ -e "$MKBUILD_NAME" ]; then
+ grep -e "\[\[$parameter\]\]" $MKBUILD_NAME | cut -d = -f 2 | tr -d '"' | tr -d "'"
+ fi
+
+}
+
+# ----------------------------------------------------------------
+
+#=============================
+# Main Program
+#=============================
+
+# Common functions
+COMMON_SH="/usr/libexec/simplepkg/common.sh"
+PROG_VERSION="`echo '$Rev$' | sed -e 's/[^0-9]//g'`"
+BASENAME="`basename $0`"
+WORK=`pwd`
+LANG=en_US
+EXIT_CODE=0
+
+if [ -f "$COMMON_SH" ]; then
+ source $COMMON_SH
+else
+ echo $error "$BASENAME: file $COMMON_SH not found. Check your $BASENAME installation"
+fi
+
+# Start constants
+set_constants
+
+# Set submit off
+SUBMIT_SLACKBUILD=$off
+SUBMIT_MKBUILD=$off
+# Set verbose off
+VERBOSE=$off
+SVN_MOD=$off
+
+# Load /etc/simplepkg/simplepkg.conf parameters
+load_parameters
+
+# Select color mode: gray, color or none (*)
+color_select $COLOR_MODE
+
+# Auxiliar file
+AUX_TMP=/tmp/mkbuild_tmp.$RANDOM
+DIFF_FILE=/tmp/mkbuild.diff.$RANDOM
+# Derectory to SlackBuild models
+MODEL_DIR=${MODEL_DIR:="/etc/simplepkg/defaults/mkbuild"}
+# SlackDesk line length
+SLACKDESC_LEN=78
+
+# Load error codes
+error_codes
+
+# Show help if has no arguments
+[ $# -eq 0 ] && mkbuild_use && exit 1
+
+# Configure input parameters
+set_parameters "$@"
+
+verbose -e "$BASENAME version $PROG_VERSION\n"
+case $ACTION in
+ 'update_manifest')
+ shift
+ update_manifest $*
+ ;;
+ 'commit_slackbuild')
+ shift 2
+ commit_changes $SLACKBUILDS_DIR $MKBUILD_BASENAME: $*
+ ;;
+ 'commit_mkbuild')
+ shift 2
+ commit_changes $MKBUILDS_DIR $MKBUILD_BASENAME: $*
+ ;;
+ 'commit_all')
+ shift 2
+ commit_changes $SLACKBUILDS_DIR $MKBUILD_BASENAME: $*
+ commit_changes $MKBUILDS_DIR $MKBUILD_BASENAME: $*
+ ;;
+ 'import_slackbuilds')
+ shift
+ import_slackbuilds $*
+ ;;
+ 'import_mkbuilds')
+ shift
+ import_mkbuilds $*
+ ;;
+ 'import_all')
+ shift
+ import_mkbuilds $*
+ import_slackbuilds $*
+ ;;
+ 'delete_slackbuild')
+ delete_slackbuild
+ ;;
+ 'delete_mkbuild')
+ delete_mkbuild
+ ;;
+ 'delete_all')
+ delete_mkbuild
+ delete_slackbuild
+ ;;
+ 'new')
+ create_mkbuild
+ ;;
+ 'build')
+ make_slackbuild
+ ;;
+ 'search')
+ search_mkbuild -i
+ ;;
+ 'status')
+ repository_status
+ ;;
+ 'list')
+ list_mkbuild_contents
+ ;;
+ 'edit')
+ edit_mkbuild
+ ;;
+ 'working_copy')
+ working_copy
+ ;;
+ 'get_param')
+ shift 2
+ get_param $*
+ ;;
+esac
+
+# Clear temporary files
+verbose -e "\nRemove temporary files ..."
+clear_files
+exit $EXIT_CODE
diff --git a/src/mkjail b/src/mkjail
new file mode 100755
index 0000000..4b00c38
--- /dev/null
+++ b/src/mkjail
@@ -0,0 +1,115 @@
+#!/bin/bash
+#
+# mkjail: chroot jail maker
+# feedback: rhatto at riseup.net | GPL
+#
+# Mkjail 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.
+#
+# Mkjail 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
+#
+# $Rev$ - $Author$
+#
+
+COMMON="/usr/libexec/simplepkg/common.sh"
+BASENAME="`basename $0`"
+
+if [ -f "$COMMON" ]; then
+ source $COMMON
+else
+ echo "error: file $COMMON found, check your `basename $0` installation"
+ exit 1
+fi
+
+function usage {
+
+ echo "usage: [ARCH=arch] [VERSION=version] [ROOT=/otherroot] $BASENAME <jail-name> [template]"
+ exit 1
+
+}
+
+function exec_post_install_scripts {
+
+ # exec post installation scripts
+ # usage: exec_post_install_script <jail-root> <jail-name>
+
+ local list
+
+ if [ -z "$2" ]; then
+ return 1
+ fi
+
+ echo "$BASENAME: executing template scripts..."
+ if [ -d "`template_scripts`" ]; then
+ for file in `template_scripts`/*; do
+ if [ -x "$file" ]; then
+ $file $1 $2
+ fi
+ done
+ fi
+
+}
+
+function jailist_update {
+
+ # update the jail list file
+ # usage: jailist_update <jail-path>
+
+ if [ "$ADD_TO_JAIL_LIST" == "1" ]; then
+ touch $JAIL_LIST
+ if ! grep -q -e "^$1\$" $JAIL_LIST; then
+ echo $1 >> $JAIL_LIST
+ fi
+ fi
+
+}
+
+if [ -z "$1" ]; then
+ usage
+else
+ server="$1"
+ eval_config $BASENAME -u
+fi
+
+if [ ! -z "$2" ]; then
+ search_template $2
+ result="$?"
+else
+ search_default_template
+ result="$?"
+fi
+
+if [ "$result" != "0" ]; then
+ exit 1
+fi
+
+TEMPLATE="`template_packages`"
+
+if [ ! -d "$JAIL_ROOT/$server" ]; then
+ mkdir -p $JAIL_ROOT/$server
+else
+ if [ ! -z "`ls $JAIL_ROOT/$server | grep -v 'lost+found'`" ]; then
+ echo $BASENAME: error: folder $JAIL_ROOT/$server already exists and seens to be not empty
+ echo $BASENAME: probably the jail $1 already exists
+ exit 1
+ fi
+fi
+
+echo "Instaling packages into $JAIL_ROOT/$server..."
+echo "Using template $TEMPLATE."
+
+install_packages
+copy_template_files $JAIL_ROOT/$server
+set_jail_perms $JAIL_ROOT/$server
+jailist_update $JAIL_ROOT/$server
+exec_post_install_scripts $JAIL_ROOT $server
+
+echo $BASENAME: done creating $server jail
+
diff --git a/src/mkpatch b/src/mkpatch
new file mode 100644
index 0000000..bbf990b
--- /dev/null
+++ b/src/mkpatch
@@ -0,0 +1,145 @@
+#!/bin/bash
+#
+# mkpatch: Simple patch program to .mkbuild models
+# feedback: rudsonaalves at yahoo.com.br | gpl
+#
+# mkbuild 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.
+#
+# mkbuild 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
+#
+# Input:
+# - $1 Diff_File
+# - #2 Source_File
+#
+# Version:
+PROG_VERSION=1.1
+BASENAME=`basename $0`
+
+function get_line {
+
+ # get a line $1 from file $2
+ [ $# -ne 2 ] && exit $ERROR_PAR_NUMBER
+ ! is_number $1 && exit $ERROR_NOT_NUMBER
+ [ ! -e $2 ] && exit $ERROR_FILE_NOTFOUND
+
+ sed "$1 q;d" $2
+}
+
+function get_diff_line {
+
+ # get diff line e return:
+ # - Action in Diff_Action
+ # - Diff Line in Diff_Str_Line
+ if [ $1 -gt $Diff_N_Lines ]; then
+ Diff_Action=" "
+ Diff_Str_Line=""
+ return 0
+ fi
+ Line=`get_line $1 $2`
+ Diff_Action=`echo "$Line" | cut -c1`
+ Diff_Str_Line=`echo "$Line" | cut -c2-`
+}
+
+
+# ----------------------------------------------------------------
+# ------------------- mkpatch program ----------------------------
+# common.sh library start
+COMMON_SH="/usr/libexec/simplepkg/common.sh"
+if [ -f "$COMMON_SH" ]; then
+ source $COMMON_SH
+else
+ echo "$BASENAME: file $COMMON_SH not found. Check your $BASENAME installation"
+fi
+
+# Load error codes
+error_codes
+# ----------------
+
+if [ "$1" = "--help" -o "$1" = "-h" ]; then
+ echo "Use: $BASENAME <diff_file> <source_file>"
+ exit $ERROR_HELP
+fi
+
+# Check input parameters
+[ $# -ne 2 ] && exit $ERROR_PAR_NUMBER
+[ ! -e $1 ] && exit $ERROR_FILE_NOTFOUND
+[ ! -e $2 ] && exit $ERROR_FILE_NOTFOUND
+
+# Start variables
+Diff_File=$1
+Source_File=$2
+Diff_N_Lines=`wc -l $1 | cut -f1 -d" "`
+Source_N_Lines=`wc -l $2 | cut -f1 -d" "`
+
+# Start vars
+Diff_Line=1
+Diff_Pointer=1
+Status_Diff=0
+
+# Get frist Diff_File line
+get_diff_line $Diff_Line $Diff_File || exit $?
+
+Source_Line=1
+# Get frist Source_File line
+Source_Str_Line=`get_line $Source_Line $Source_File` || exit $?
+while [ $Source_Line -le $Source_N_Lines ]; do
+ # make Actions
+ case $Diff_Action in
+ '-')
+ if [ "$Source_Str_Line" = "$Diff_Str_Line" ]; then
+ Status_Diff=1
+ let Diff_Line++
+ else
+ Diff_Line=$Diff_Pointer
+ Status_Diff=0
+ echo "$Source_Str_Line"
+ fi
+ get_diff_line $Diff_Line $Diff_File || exit $?
+ let Source_Line++
+ Source_Str_Line=`get_line $Source_Line $Source_File` || exit $?
+ ;;
+ '+')
+ echo "$Diff_Str_Line"
+ let Diff_Line++
+ get_diff_line $Diff_Line $Diff_File || exit $?
+ ;;
+ ' ')
+ if [ "$Source_Str_Line" = "$Diff_Str_Line" ]; then
+ Status_Diff=1
+ let Diff_Line++
+ else
+ Status_Diff=0
+ Diff_Line=$Diff_Pointer
+ fi
+ echo "$Source_Str_Line"
+ get_diff_line $Diff_Line $Diff_File || exit $?
+ let Source_Line++
+ Source_Str_Line=`get_line $Source_Line $Source_File` || exit $?
+ ;;
+ '=')
+ let Diff_Line++
+ Status_Diff=0
+ Diff_Pointer=$Diff_Line
+ get_diff_line $Diff_Line $Diff_File || exit $?
+ ;;
+ *)
+ echo "Invalid diff action."
+ exit $ERROR_MKPATCH
+ ;;
+ esac
+done
+
+# Make others addline "+" in the end file
+while [ "$Diff_Action" = "+" -a $Diff_Line -le $Diff_N_Lines ]; do
+ echo "$Diff_Str_Line"
+ let Diff_Line++
+ get_diff_line $Diff_Line $Diff_File || exit $?
+done
diff --git a/src/mkpatch.new b/src/mkpatch.new
new file mode 100755
index 0000000..cacab52
--- /dev/null
+++ b/src/mkpatch.new
@@ -0,0 +1,145 @@
+#!/bin/bash
+#
+# MKPatch 2.0.0: Simple patch program to .mkbuild models
+# feedback: rudsonaalves at yahoo.com.br | gpl
+#
+# mkbuild 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.
+#
+# mkbuild 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
+#
+# Input:
+# - $1 Diff_File
+# - #2 Source_File
+#
+# Version:
+PROG_VERSION=2.0
+BASENAME=`basename $0`
+
+# Errors codes. From common.sh
+ERROR_FILE_NOTFOUND=${ERROR_FILE_NOTFOUND:=100}
+ERROR_PAR_NUMBER=${ERROR_PAR_NUMBER:=102}
+ERROR_MKPATCH=${ERROR_MKPATCH:=600}
+
+# check input arguments
+if [ "$1" = "--help" -o "$1" = "-h" ]; then
+ echo "Use: $BASENAME <diff_file> <source_file>"
+ exit $ERROR_HELP
+fi
+
+# check number of parameters
+[ $# -ne 2 ] && exit $ERROR_PAR_NUMBER
+
+# check diff_file exit
+[ ! -e $1 ] && exit $ERROR_FILE_NOTFOUND
+
+# check source_file exit
+[ ! -e $2 ] && exit $ERROR_FILE_NOTFOUND
+
+# Change IFS value to <ENTER> only
+OLD_IFS=$IFS
+IFS='
+'
+
+# Read vector from patch file
+index=0
+while read line; do
+ Diff_lines[index]="`echo $line | cut -c2-`"
+ Diff_action[index]="`echo $line | cut -c1`"
+ let index++
+done < $1
+let Diff_n_lines=index-1
+
+# Read vector from source file
+index=0
+while read line; do
+ Source_lines[index]="$line"
+ let index++
+done < $2
+let Source_n_lines=index-1
+
+# Rescue IFS value
+IFS=$OLD_IFS
+
+# Stating variables
+Source_index=0
+Diff_index=0
+Diff_pointer=0
+Status_diff=0
+
+# Output vector
+Output=""
+Output_index=0
+
+# Apply patch
+while [ $Source_index -le $Source_n_lines -a $Diff_index -le $Diff_n_lines ]; do
+ # make Actions
+ case "${Diff_action[Diff_index]}" in
+ '-')
+ if [ "${Source_lines[Source_index]}" == "${Diff_lines[Diff_index]}" ]; then
+ Status_diff=1
+ let Diff_index++
+ else
+ Diff_index=$Diff_pointer
+ Status_diff=0
+ Output[Output_index]="${Source_lines[Souce_index]}"
+ let Output_index++
+ fi
+ let Source_index++
+ ;;
+ '+')
+ Output[Output_index]="${Diff_lines[Diff_index]}"
+ let Diff_index++
+ let Output_index++
+ ;;
+ ' ')
+ if [ "${Source_lines[Source_index]}" == "${Diff_lines[Diff_index]}" ]; then
+ Status_diff=1
+ let Diff_index++
+ else
+ Status_diff=0
+ Diff_index=$Diff_pointer
+ fi
+ Output[Output_index]="${Source_lines[Source_index]}"
+ let Output_index++
+ let Source_index++
+ ;;
+ '=')
+ let Diff_index++
+ Status_diff=0
+ Diff_pointer=$Diff_index
+ ;;
+ '*')
+ echo "Invalid diff action."
+ exit $ERROR_MKPATCH
+ ;;
+ esac
+done
+
+# Check end of file mkSlackBuild
+if [ $Diff_index -gt $Diff_n_lines -a $Source_index -le $Source_n_lines ]; then
+ # write the rest of mkSlackBuild in Output vector
+ for index in `seq $Source_index $Source_n_lines`; do
+ Output[Output_index]="${Source_lines[index]}"
+ let Output_index++
+ done
+elif [ $Diff_index -le $Diff_n_lines ]; then
+ # Write others addlines, "+", in Output vector
+ while [ "${Diff_Action[Diff_index]}" == "+" ]; do
+ Output[Output_index]="${Diff_lines[Diff_index]}"
+ let Diff_index++
+ let Output_index++
+ done
+fi
+
+# Print Output file
+for index in `seq 1 $Output_index`; do
+ echo "${Output[$index-1]}"
+done
diff --git a/src/rebuildpkg b/src/rebuildpkg
new file mode 100755
index 0000000..65315ad
--- /dev/null
+++ b/src/rebuildpkg
@@ -0,0 +1,86 @@
+#!/bin/bash
+#
+# rebuildpkg: build a package from a /var/log/packages entry
+#
+# feedback: rhatto at riseup.net | gpl
+#
+# Rebuildpkg 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.
+#
+# Rebuildpkg 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
+#
+
+COMMON="/usr/libexec/simplepkg/common.sh"
+
+function usage {
+ echo "usage: ROOT=/otherroot `basename $0` <package-name>"
+}
+
+if [ -f "$COMMON" ]; then
+ source $COMMON
+else
+ echo "error: file $COMMON found, check your `basename $0` installation"
+ exit 1
+fi
+
+if [ -z "$1" ]; then
+ usage
+ exit 1
+fi
+
+pack="$1"
+
+for file in `ls $ROOT/var/log/packages/$pack*`; do
+ if [[ "`package_name $file.tgz`" == "$pack" ]]; then
+ package_file="$file"
+ break
+ fi
+done
+
+if [ -z "$package_file" ]; then
+ echo error: package $pack does not exist
+ exit 1
+fi
+
+if [ -d "$TMP/package-$pack" ]; then
+ rm -rf $TMP/package-$pack
+fi
+
+mkdir $TMP/package-$pack
+cd $TMP/package-$pack
+
+for file in `grep -v -e "^PACKAGE NAME:" -e "^UNCOMPRESSED PACKAGE SIZE:" \
+ -e "^COMPRESSED PACKAGE SIZE:" -e "^PACKAGE LOCATION:" \
+ -e "^PACKAGE DESCRIPTION:" -e "^$pack:" -e "^FILE LIST:" $package_file`; do
+
+ if [ "$file" != "install" ] && [ "$file" != "install/slack-desc" ] && [ "$file" != "install/doinst,sh" ]; then
+ if [ -d /$file ]; then
+ mkdir -p $TMP/package-$pack/$file
+ elif [ -f /$file ]; then
+ cp /$file $TMP/package-$pack/$file
+ else
+ echo file /$file was not found, please add it manually, exploding and making the package again
+ fi
+ fi
+
+done
+
+mkdir $TMP/package-$pack/install
+grep "^$pack:" $package_file > $TMP/package-$pack/install/slack-desc
+
+package_name="`grep "PACKAGE NAME:" $package_file | awk '{ print $3 }'`"
+
+if [ -f "$ROOT/var/log/scripts/$package_name" ]; then
+ cp $ROOT/var/log/scripts/$package_name $TMP/package-$pack/install/doinst.sh
+fi
+
+makepkg $package_name.$MKBUILD_COMPRESS
+mv $package_name.$MKBUILD_COMPRESS $TMP/
+echo "done: package rebuilt and stored at $TMP/$package_name.$MKBUILD_COMPRESS"
diff --git a/src/simplaret b/src/simplaret
new file mode 100755
index 0000000..7b157bb
--- /dev/null
+++ b/src/simplaret
@@ -0,0 +1,1194 @@
+#!/bin/bash
+#
+# simplaret: simplepkg's retrieval tool
+# feedback: rhatto at riseup.net | gpl
+#
+# Simplaret 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.
+#
+# Simplaret 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
+#
+# $Rev$ - $Author$
+#
+
+BASENAME="`basename $0`"
+COMMON="/usr/libexec/simplepkg/common.sh"
+
+if [ -f "$COMMON" ]; then
+ source $COMMON
+else
+ echo "error: file $COMMON found, check your $BASENAME installation"
+ exit 1
+fi
+
+if [ -f "$HOME/.simplepkg/repos.conf" ]; then
+ REPOS_CONF="$HOME/.simplepkg/repos.conf"
+elif [ -f "/etc/simplepkg/repos.conf" ]; then
+ REPOS_CONF="/etc/simplepkg/repos.conf"
+else
+ REPOS_CONF="/etc/simplepkg/defaults/repos.conf"
+fi
+
+function simplaret_usage {
+
+ echo "usage: [ARCH=otherarch] [VERSION=otherversion] $BASENAME [OPTION] package-name"
+ echo -e "\t OPTIONS: --help, --install, --update (or --sync), --upgrade, --search, --get, --get-patches, --purge, --remove"
+ exit 1
+
+}
+
+function simplaret_get_index {
+
+ for file in `simplaret_metafiles`; do
+ simplaret_download $1 $file $2 --no-verbose
+ done
+
+}
+
+function simplaret_backup_index {
+
+ for file in `simplaret_metafiles`; do
+ if [ -f "$1/$file" ]; then
+ mv $1/$file $1/$file.old
+ fi
+ done
+
+}
+
+function simplaret_check_index {
+
+ for file in `simplaret_metafiles`; do
+ if [ ! -f "$1/$file" ] && [ -f "$1/$file.old" ]; then
+ echo Restoring old $file to $1...
+ mv $1/$file.old $1/$file
+ else
+ rm -f $1/$file.old
+ fi
+ done
+
+}
+
+function simplaret_import_gpg_keys {
+
+ if [ "$SIGNATURE_CHECKING" == "$on" ]; then
+ check_gnupg
+ if [ -f "$1/GPG-KEY" ] && [ -f "$1/GPG-KEY.old" ]; then
+ if ! diff $1/GPG-KEY $1/GPG-KEY.old &> /dev/null; then
+ gpg --import < $1/GPG-KEY
+ fi
+ elif [ -f "$1/GPG-KEY" ]; then
+ gpg --import < $1/GPG-KEY
+ fi
+ fi
+
+}
+
+function simplaret_download {
+
+ # download a file from a repo to a folder
+ # usage: simplaret <repository_url> <package> <destination-folder> [--no-verbose]
+
+ local protocol file
+ local wget_timeout wget_passive_ftp wget_verbose
+ local curl_timeout curl_passive_ftp curl_verbose
+ local ncftpget_timeout ncftpget_passive_ftp
+
+ protocol="`echo $1 | cut -d : -f 1 | tr '[:upper:]' '[:lower:]'`"
+ file="`basename $2`"
+
+ if [ ! -d "$3" ]; then
+ mkdir -p $3
+ fi
+
+ if [ ! -z "$CONNECT_TIMEOUT" ] || [ "$CONNECT_TIMEOUT" != "0" ]; then
+ wget_timeout="--timeout $CONNECT_TIMEOUT"
+ ncftpget_timeout="-t $CONNECT_TIMEOUT"
+ curl_timeout="--connect-timeout $CONNECT_TIMEOUT"
+ fi
+
+ if [ "$4" == "--no-verbose" ]; then
+ wget_verbose="--no-verbose"
+ curl_verbose="-#"
+ echo ""
+ fi
+
+ if [ "$protocol" == "http" ] || [ "$protocol" == "https" ]; then
+
+ echo Getting $1/$2:
+ if [ "$HTTP_TOOL" == "wget" ]; then
+ wget $wget_timeout $wget_verbose $1/$2 -O $3/$file
+ elif [ "$HTTP_TOOL" == "curl" ]; then
+ curl $curl_timeout $curl_verbose $1/$2 > $3/$file
+ else
+ echo $BASENAME: error: invalid value for config variable HTTP_TOOL: $HTTP_TOOL
+ echo $BASENAME: please check your config file $CONF
+ exit 1
+ fi
+
+ elif [ "$protocol" == "ftp" ]; then
+ echo Getting $1/$2:
+
+ if [ "$PASSIVE_FTP" == "1" ]; then
+ wget_passive_ftp="--passive-ftp"
+ ncftpget_passive_ftp="-F"
+ curl_passive_ftp="--ftp-pasv"
+ fi
+
+ if [ "$FTP_TOOL" == "ncftpget" ]; then
+ ncftpget -c $ncftpget_timeout $ncftpget_passive_ftp $1/$2 > $3/$file
+ elif [ "$FTP_TOOL" == "wget" ]; then
+ wget $wget_timeout $wget_passive_ftp $wget_verbose $1/$2 -O $3/$file
+ elif [ "$FTP_TOOL" == "curl" ]; then
+ curl $curl_timeout $curl_passive_ftp $curl_verbose $1/$2 > $3/$file
+ else
+ echo $BASENAME: error: invalid value for config variable FTP_TOOL: $FTP_TOOL
+ echo $BASENAME: please check your config file $CONF
+ exit 1
+ fi
+
+ elif [ "$protocol" == "file" ]; then
+
+ url="`echo $1 | sed -e 's/file:\/\///'`"
+ if [ -f "$3/$file" ]; then
+ rm -f $3/$file
+ fi
+ echo -n "Copying $url/$2..."
+ if [ -f "$url/$2" ]; then
+ cp $url/$2 $3/$file 2> /dev/null
+ fi
+ if [ -f "$3/$file" ]; then
+ echo " done."
+ else
+ echo " failed."
+ fi
+
+ else
+
+ echo $BASENAME error: invalid protocol $protocol
+
+ fi
+
+}
+
+function simplaret_repository {
+
+ # return repository definitions from $REPOS_CONF file
+ # usage: simplaret_repository [root|repos|noarch|patches]
+
+ local definition
+
+ if [ -z "$1" ]; then
+ definition="ROOT"
+ else
+ definition="`echo $1 | tr '[:lower:]' '[:upper:]'`"
+ fi
+
+ if [ "$definition" == "REPOS" ] || [ "$definition" == "PATCHES" ]; then
+ definition="$definition-$ARCH-$VERSION"
+ elif [ "$definition" == "ROOT" ]; then
+ definition="$definition-$ARCH"
+ fi
+
+ grep -e "^$definition=" $REPOS_CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1
+
+}
+
+function simplaret_repository_name {
+
+ # return a repository name according the value of $repository
+
+ if [ -z "$repository" ]; then
+ false
+ elif echo $repository | grep -qe %; then
+ repository_name="`echo $repository | cut -d % -f 1`"
+ if [ -z "$repository_name" ]; then
+ echo $BASENAME: you should set a name for the repository $repository
+ echo $BASENAME: please correct your $REPOS_CONF
+ exit 1
+ fi
+ else
+ echo $BASENAME: you should set a name for the repository $repository
+ echo $BASENAME: please correct your $REPOS_CONF
+ exit 1
+ fi
+
+}
+
+function simplaret_repository_url {
+
+ # return a repository url according the value of $repository
+
+ if echo $repository | grep -qe %; then
+ repository_url="`echo $repository | cut -d % -f 2`"
+ if [ -z "$repository_url" ]; then
+ echo $BASENAME: you should set a url for the repository $repository
+ echo $BASENAME: please correct your $REPOS_CONF
+ exit 1
+ fi
+ else
+ echo $BASENAME: you should set a url for the repository $repository
+ echo $BASENAME: please correct your $REPOS_CONF
+ exit 1
+ fi
+
+ if [ "$repos_type" == "root" ]; then
+ simplaret_set_arch
+ distro="`basename $repository_url`"
+ if [ "$ARCH" == "x86_64" ] && [ "$distro" == "slackware" ]; then
+ distro="slackware64"
+ fi
+ repository_url="$repository_url/$distro-$VERSION/"
+ fi
+
+}
+
+function simplaret_set_storage_folder {
+
+ storage="$STORAGE/$ARCH/$VERSION/$repos_type"
+ if [ "$repos_type" == "noarch" ]; then
+ storage="$STORAGE/noarch"
+ elif [ "$repos_type" == "patches" ]; then
+ storage="$PATCHES_DIR/$ARCH/$VERSION"
+ fi
+
+}
+
+function simplaret_update {
+
+ local storage
+
+ echo Updating package information for arch $ARCH and version $VERSION...
+
+ for repos_type in patches root repos noarch; do
+
+ simplaret_set_storage_folder
+
+ for repository in `simplaret_repository $repos_type`; do
+
+ simplaret_repository_name
+ simplaret_repository_url
+
+ if [ ! -d "$storage/$repository_name" ]; then
+ mkdir -p $storage/$repository_name
+ else
+ simplaret_backup_index $storage/$repository_name
+ fi
+
+ simplaret_get_index $repository_url $storage/$repository_name
+ simplaret_import_gpg_keys $storage/$repository_name
+ simplaret_check_index $storage/$repository_name
+
+ unset repository_name repository_url repository_protocol
+
+ done
+ done
+
+}
+
+function simplaret_find_package {
+
+ # grep packages in a repository's file list
+ # usage: simplaret_find_package <package-name|-all> <repository-folder>
+
+ if [ "$1" == "-all" ]; then
+ grep -E -e "$(pkg_ext_grep .)$" $2/`simplaret_filelist` | awk '{ print $8 }'
+ else
+ grep $1 $2/`simplaret_filelist` | awk '{ print $8 }' | grep -E -e "$(pkg_ext_grep .)$"
+ fi
+
+}
+
+function simplaret_show_package {
+
+ # print a package result
+ # usage: simplaret_show_package <package-file-name> [--basename-only|--filename-only|--formatted]
+
+ if [ "$2" == "--basename-only" ]; then
+ echo `basename $1`
+ elif [ "$2" == "--filename-only" ]; then
+ echo $1
+ elif [ "$2" == "--formatted" ]; then
+ echo $1,$repos_type,$repository
+ else
+ if echo $1 | grep -q "/patches/"; then
+ patch="(patch)"
+ fi
+ if [ "$repos_type" == "noarch" ]; then
+ echo $name repository $repository_name: `basename $1` $patch
+ else
+ echo $name repository $repository_name, arch: $ARCH, version: $VERSION: `basename $1` $patch
+ fi
+ fi
+ unset patch
+
+}
+
+function simplaret_filelist {
+
+ if [ "$repos_type" == "patches" ]; then
+ echo FILE_LIST
+ else
+ echo FILELIST.TXT
+ fi
+
+}
+
+function simplaret_metafiles {
+
+ if [ "$SIGNATURE_CHECKING" == "$on" ]; then
+ echo `simplaret_filelist` CHECKSUMS.md5 GPG-KEY
+ else
+ echo `simplaret_filelist` CHECKSUMS.md5
+ fi
+
+}
+
+function simplaret_search {
+
+ # search packages
+ # usage: simplaret_search [package-name] [-display_mode]
+ # display_mode can be any accepted by simplaret_show_package
+
+ local priority priority_match message pattern mode
+
+ if [ ! -z "$1" ] && ! echo $1 | grep -q -e "^-"; then
+ pattern="$1"
+ mode="$2"
+ else
+ pattern="-all"
+ mode="$1"
+ fi
+
+ for repos_type in patches root repos noarch; do
+
+ name="`echo $repos_type | tr '[:lower:]' '[:upper:]'`"
+ simplaret_set_storage_folder
+
+ for repository in `simplaret_repository $repos_type`; do
+
+ simplaret_repository_name
+
+ if [ ! -f "$storage/$repository_name/`simplaret_filelist`" ]; then
+ if [ "$WARNING" != "0" ] || [ ! -z "$SILENT" ]; then
+ if [ "$repos_type" == "noarch" ]; then
+ message=""
+ else
+ message="on arch $ARCH version $VERSION"
+ fi
+ echo warning: no file list for $repository_name repository $repository_name $message
+ echo please do a simplaret --update
+ fi
+ else
+
+ if [ "$repos_type" == "root" ]; then
+ # root repositories has ROOT_PRIORITY
+ for priority in $ROOT_PRIORITY; do
+ for file in `simplaret_find_package $pattern $storage/$repository_name | grep "/$priority/"`; do
+ simplaret_show_package $file $mode
+ done
+ priority_match="$priority_match|/$priority/"
+ done
+ # now we should return all matches that are not part of ROOT_PRIORITY
+ priority_match="`echo $priority_match | sed -e 's/^|//'`"
+ for file in `simplaret_find_package $pattern $storage/$repository_name | grep -E -v $priority_match`; do
+ simplaret_show_package $file $mode
+ done
+ priority_match=""
+ elif [ "$repos_type" == "repos" ]; then
+ # repos repositories has REPOS_PRIORITY
+ for priority in $REPOS_PRIORITY; do
+ for file in `simplaret_find_package $pattern $storage/$repository_name | grep "/$priority/"`; do
+ simplaret_show_package $file $mode
+ done
+ priority_match="$priority_match|/$priority/"
+ done
+ # now we should return all matches that are not part of REPOS_PRIORITY
+ priority_match="`echo $priority_match | sed -e 's/^|//'`"
+ for file in `simplaret_find_package $pattern $storage/$repository_name | grep -E -v $priority_match`; do
+ simplaret_show_package $file $mode
+ done
+ priority_match=""
+ else
+ for file in `simplaret_find_package $pattern $storage/$repository_name`; do
+ simplaret_show_package $file $mode
+ done
+ fi
+
+ fi
+
+ done
+ done
+
+}
+
+function simplaret_purge {
+
+ # purge simplaret package cache
+ # usage: simplaret_purge [-w N]
+
+ local mtime mtime_message which and_patches
+
+ if [ "$1" == "-w" ] && [ ! -z "$2" ]; then
+ mtime="-mtime +`echo "$2*7" | bc -l`"
+ mtime_message="older than $2 weeks"
+ elif [ "$SIMPLARET_PURGE_WEEKS" != "0" ]; then
+ mtime="-mtime +`echo "$SIMPLARET_PURGE_WEEKS*7" | bc -l`"
+ mtime_message="older than $SIMPLARET_PURGE_WEEKS weeks"
+ else
+ mtime=""
+ mtime_mesage=""
+ fi
+
+ which="root repos noarch"
+ and_patches=""
+
+ if [ "$SIMPLARET_PURGE_PATCHES" == "1" ]; then
+ which="patches $which"
+ and_patches="including patches"
+ fi
+
+ if [ -z "$SILENT" ]; then
+ if [ -z "$mtime_message" ]; then
+ echo "$BASENAME: purging all packages for:"
+ else
+ echo "$BASENAME: purging all packages $mtime_message for:"
+ fi
+ echo -e "\t- Arch $ARCH and version $VERSION $and_patches"
+ echo -e "\t- Noarch folder"
+ fi
+
+ for repos_type in $which; do
+
+ simplaret_set_storage_folder
+
+ for file in `find $storage/ $mtime 2> /dev/null`; do
+ for extension in `pkg_ext` asc meta txt slack-required; do
+ if echo $file | grep -qe ".$extension$"; then
+ rm $file
+ fi
+ done
+ done
+
+ done
+
+ if [ -z "$SILENT" ]; then
+ echo $BASENAME: done purging simplaret cache
+ echo $BASENAME: please run $BASENAME --update to retrieve new package listings on this arch and version
+ fi
+
+}
+
+function simplaret_search_and_delete {
+
+ # search and delete packages
+ # usage: simplaret_search_and_delete <package> <folder> [--silent]
+
+ local file candidate place basename name version build
+ local name_version name_build
+
+ name="`package_name $1`"
+
+ if [ "$name" != "$1" ]; then
+ # searching by full package filename
+ name_version="`package_version $1`"
+ name_build="`package_build $1`"
+ name_ext="`package_ext $1`"
+
+ # search wheter the package filename is in the repositories
+ if [ "`simplaret_search $1 | grep $1 | wc -l`" == "0" ]; then
+ echo "Error: package not found: $1"
+ return 1
+ fi
+
+ for file in `eval find $2/ $(pkg_ext_find $name*) 2> /dev/null`; do
+ candidate="`basename $file`"
+ version="`package_version $candidate`"
+ build="`package_build $candidate`"
+ ext="`package_ext $candidate`"
+ if [ "`package_name $candidate`" == "$name" ]; then
+
+ if [ "$name_version" == "$version" ] && \
+ [ "$name_build" == "$build" ] && \
+ [ "$name_ext" == "$ext" ]; then
+ LAST_DOWNLOADED_PACKAGE="$file"
+ if [ "$3" != "--silent" ]; then
+ echo Package $candidate already downloaded
+ # echo Package $candidate stored at `dirname $file`
+ else
+ true
+ # echo $file
+ fi
+ return 1
+ else
+ place="`dirname $file`"
+ basename="`strip_pkg_ext $file`"
+ rm -f $file
+ rm -f $place/$candidate.slack-required
+ rm -f $file.asc $place/$basename.meta $place/$basename.txt
+ break
+ fi
+
+ fi
+ done
+
+ else
+
+ for file in `eval find $2/ $(pkg_ext_find $name*) 2> /dev/null`; do
+ candidate="`basename $file`"
+ version="`package_version $candidate`"
+ build="`package_build $candidate`"
+ ext="`package_ext $candidate`"
+ if [ "`package_name $candidate`" == "$name" ]; then
+ # check if has the same version and build number, otherwise erase the old one
+ for result in `simplaret_search $(package_name $candidate) --basename-only`; do
+ if [ "`package_name $candidate`" == "`package_name $result`" ]; then
+
+ if [ "$version" == "`package_version $result`" ] && \
+ [ "$build" == "`package_build $result`" ] && \
+ [ "$ext" == "`package_ext $result`" ]; then
+ LAST_DOWNLOADED_PACKAGE="$file"
+ if [ "$3" != "--silent" ]; then
+ echo Package $candidate already downloaded
+ # echo Package $candidate stored at `dirname $file`
+ else
+ true
+ # echo $file
+ fi
+ return 1
+ else
+ place="`dirname $file`"
+ basename="`strip_pkg_ext $file`"
+ rm -f $file
+ rm -f $place/$candidate.slack-required
+ rm -f $file.asc $place/$basename.meta $place/$basename.txt
+ break
+ fi
+
+ fi
+ done
+ fi
+ done
+
+ fi
+
+}
+
+function simplaret_get {
+
+ # get a package
+ # usage: simplaret_get <package-name|package-file-name> [--silent]
+
+ local silent generate_patches search search_results
+ local name version build
+
+ # prevent user to stay in $storage
+ cd
+
+ name="`package_name $1`"
+
+ if [ "$name" != "$1" ]; then
+ # simplaret_get was called with the package file
+ # name and not with just the package name
+ version="`package_version $1`"
+ build="`package_build $1`"
+ else
+ version=""
+ build=""
+ fi
+
+ # first search for an already downloaded package
+ for repos_type in patches root repos noarch; do
+
+ simplaret_set_storage_folder
+ simplaret_search_and_delete $1 $storage $2
+
+ if [ "$?" == "1" ]; then
+ return 0
+ fi
+
+ done
+
+ # then search for the package in the repositories
+ search="`simplaret_search $1 --formatted`"
+ search_results="`echo "$search" | wc -l`"
+
+ for result in $search; do
+
+ # remaining search results
+ let search_results--
+
+ file="`echo $result | cut -d , -f 1`"
+ repos_type="`echo $result | cut -d , -f 2`"
+ repository="`echo $result | cut -d , -f 3`"
+
+ simplaret_set_storage_folder
+ simplaret_repository_name
+
+ candidate="`basename $file`"
+ if [ "`package_name $candidate`" == "$name" ]; then
+
+ if [ ! -z "$build" ] && [ ! -z "$version" ]; then
+ # simplaret_get was called with the package file
+ # name and not with just the package name
+ if [ "$version" != "`package_version $candidate`" ] && \
+ [ "$build" != "`package_build $candidate`" ]; then
+ # the package version and/or build doesnt matched
+ # the desired one
+ continue
+ fi
+ fi
+
+ simplaret_repository_url
+
+ # if repos_type == root, the package is a patch and
+ # STORE_ROOT_PATCHES_ON_PATCHES_DIR config parameter is enabled, then
+ # save it on $PATCHES_DIR/root-$repository_name, so all patches
+ # are placed in the same tree
+ if [ "$repos_type" == "root" ] && \
+ [ "$STORE_ROOT_PATCHES_ON_PATCHES_DIR" == "1" ] && echo $file | grep -q "patches"; then
+ folder="$PATCHES_DIR/$ARCH/$VERSION/root-$repository_name"
+ generate_patches="1"
+ else
+ folder="$storage/$repository_name"
+ fi
+
+ # download the package
+ simplaret_download $repository_url $file $folder
+
+ if [ -f "$folder/$candidate.asc" ]; then
+ rm $folder/$candidate.asc
+ fi
+
+ if [ -f "$folder/$name.slack-required" ]; then
+ rm $folder/$name.slack-required
+ fi
+
+ # download the signature, if exist
+ if simplaret_check_url $repository_url/$file.asc; then
+ simplaret_download $repository_url $file.asc $folder
+ fi
+
+ # download slack-required, if exist
+ if simplaret_check_url $repository_url/`dirname $file`/$name.slack-required; then
+ simplaret_download $repository_url `dirname $file`/$name.slack-required $folder
+ fi
+
+ if [ ! -f "$folder/$candidate" ]; then
+ LAST_DOWNLOADED_PACKAGE="0"
+ if [ "$2" != "--silent" ]; then
+ echo Error downloading $candidate from $repos_type repository $repository_url, please check your settings
+ fi
+ # check if there's also more repositories to try
+ if [ "$SIMPLARET_DOWNLOAD_FROM_NEXT_REPO" != "1" ]; then
+ return 1
+ else
+ if [ "$2" != "--silent" ]; then
+ echo Trying to fetch $candidate from the next repository...
+ fi
+ if (($search_results <= 0)); then
+ return 1
+ fi
+ fi
+ else
+ LAST_DOWNLOADED_PACKAGE="$folder/$candidate"
+ if [ "$2" != "--silent" ]; then
+ silent=""
+ echo Package $candidate stored at $folder
+ else
+ # echo $folder/$candidate
+ silent="--silent"
+ fi
+ if [ "$SIGNATURE_CHECKING" == "$on" ]; then
+ if [ -f "$folder/$candidate.asc" ]; then
+ gpg --verify $folder/$candidate.asc $folder/$candidate
+ if [ "$?" != "0" ]; then
+ echo "Package signature does not match. Removing package."
+ rm -f $folder/$candidate.asc $folder/$candidate
+ LAST_DOWNLOADED_PACKAGE=""
+ return 1
+ fi
+ else
+ echo "Missing signature. Removing package."
+ rm -f $folder/$candidate.asc $folder/$candidate
+ LAST_DOWNLOADED_PACKAGE=""
+ return 1
+ fi
+ fi
+ # generate the patches FILE_LIST and PACKAGES.TXT if needed
+ if [ "$generate_patches" == "1" ]; then
+ gen_patches_filelist $folder
+ gen_packages_txt $folder
+ gen_md5_checksums $folder
+ fi
+ simplaret_checksum $storage/$repository_name/CHECKSUMS.md5 $folder/$candidate $silent
+ return $?
+ fi
+
+ fi
+
+ done
+
+}
+
+function simplaret_search_and_process_patch {
+
+ local package_version package_build installed_version pack
+ local installed_build repos_type get is_patch package_match
+
+ # get just the file and package name
+ sugested_filename="`echo $sugested | cut -d , -f 1`"
+ sugested_pack="`package_name $sugested_filename`"
+
+ # search if its installed in the jail
+ if grep -q -e "^$sugested_pack$" $PACKAGES_TMP; then
+
+ # get the repository type
+ repos_type="`echo $sugested | cut -d , -f 2`"
+
+ if echo $sugested | grep -q "patches"; then
+ is_patch="yes"
+ else
+ is_patch="no"
+ fi
+
+ # now split the file name into pieces
+ package_version="`package_version $sugested_filename`"
+ package_build="`package_build $sugested_filename`"
+
+ # check if the patch was already downloaded
+ if echo "$DOWNLOADED_PATCHES" | grep -q " $ARCH:$VERSION:$sugested_pack "; then
+ #if [ "$IS_UPGRADE" != "1" ]; then
+ #echo Package $sugested_pack already downloaded
+ #echo "Jail $root needs package $sugested_pack (already downloaded, skipping)"
+ return
+ #fi
+ fi
+
+ pack="`echo $sugested_pack | sed -e 's/\+/\\\+/'`"
+ installed="`check_installed $pack $root`"
+ installed_version="`package_version $installed.tgz`"
+ installed_build="`package_build $installed.tgz`"
+
+ get="no"
+
+ # if needed, download the patch
+ if [ "$repos_type" == "patches" ]; then
+
+ if [ "$package_version" != "$installed_version" ] || [ "$package_build" != "$installed_build" ]; then
+ get="yes"
+ package_match="no"
+ elif [ "$DOWNLOAD_EVEN_APPLIED_PATCHES" == "1" ]; then
+ get="yes"
+ fi
+
+ elif [ "$repos_type" == "root" ] && [ "$is_patch" == "yes" ]; then
+
+ if [ "$package_version" != "$installed_version" ] || [ "$package_build" != "$installed_build" ]; then
+ get="yes"
+ package_match="no"
+ elif [ "$DOWNLOAD_EVEN_APPLIED_PATCHES" == "1" ]; then
+ get="yes"
+ fi
+
+ else
+ # here, we're dealing with repositories other than ROOT and REPOS,
+ # so we need to check if either version or build number are different,
+ # otherwise all installed packages would be downloaded
+ if [ "$package_version" != "$installed_version" ] || [ "$package_build" != "$installed_build" ]; then
+ get="yes"
+ package_match="no"
+ fi
+ fi
+
+ # finally, get the package
+ if [ "$get" == "yes" ]; then
+ if [ "$IS_UPGRADE" == "1" ]; then
+ if [ "$package_match" == "no" ]; then
+ simplaret_install $sugested_pack
+ else
+ simplaret_get $sugested_pack
+ fi
+ else
+ simplaret_get $sugested_pack
+ fi
+ if [ "$?" == "0" ]; then
+ DOWNLOADED_PATCHES="$DOWNLOADED_PATCHES $ARCH:$VERSION:$sugested_pack " # the ending space is important
+ fi
+ fi
+
+ fi
+
+ unset get
+
+}
+
+function simplaret_get_jail_patches {
+
+ # get patches from a jail
+ # usage: simplaret_get_jail_patches <jail-folder>
+
+ local oldarch oldversion
+
+ if [ ! -z "$1" ]; then
+ root="$1"
+ else
+ root="/"
+ fi
+
+ # save current arch and version
+ oldarch="$ARCH"
+ oldversion="$VERSION"
+
+ ARCH="`default_arch $root`"
+ VERSION="`default_version $root`"
+
+ # in case there's something wrong with the jail, abort
+ if [ -z "$VERSION" ] || [ -z "$ARCH" ]; then
+ return
+ fi
+
+ # we need to do that for each arch/version pairs, but just once for each pair
+ if ! echo "$DISTRO_UPDATED" | grep -q " $ARCH:$VERSION "; then
+ simplaret_update
+ DISTRO_UPDATED="$DISTRO_UPDATED $ARCH:$VERSION " # the ending space is important
+ echo ""
+ fi
+
+ # installed packages at $root
+ PACKAGES_TMP=/tmp/simplaret_packages.$RANDOM
+ rm -f $PACKAGES_TMP ; touch $PACKAGES_TMP ; chmod 600 $PACKAGES_TMP
+ ls -1 $root/var/log/packages/ | sed -e 's/-[^-]*-[^-]*-[^-]*$//' > $PACKAGES_TMP
+
+ echo Fetching patches for arch $ARCH and version $VERSION for jail $root
+
+ # list all available patches from PATCHES and ROOT repositories
+ for sugested in `simplaret_search --formatted | grep patches | grep -v ",repos," | grep -v ",noarch,"`; do
+ simplaret_search_and_process_patch
+ done
+
+ # grab patches from every other places
+ if [ "$CONSIDER_ALL_PACKAGES_AS_PATCHES" == "1" ]; then
+
+ for sugested in `simplaret_search --formatted | grep patches | grep ",repos," | grep ",noarch,"`; do
+ simplaret_search_and_process_patch
+ done
+
+ for sugested in `simplaret_search --formatted | grep -v patches`; do
+ simplaret_search_and_process_patch
+ done
+
+ fi
+
+ rm $PACKAGES_TMP
+
+ # restore arch and version
+ ARCH="$oldarch"
+ VERSION="$oldversion"
+
+}
+
+function simplaret_get_patches {
+
+ local jailpath
+
+ if [ "$1" == "--upgrade" ]; then
+ IS_UPGRADE="1"
+ fi
+
+ if [ ! -z "$ROOT" ]; then
+ simplaret_get_jail_patches $ROOT
+ return $?
+ fi
+
+ # first get patches from the root system
+ simplaret_get_jail_patches
+
+ # then get the needed patches for each installed jail
+ if [ -s "$JAIL_LIST" ]; then
+ for jailpath in `cat $JAIL_LIST`; do
+ if [ -d "$jailpath/var/log/packages" ]; then
+ ROOT="$jailpath"
+ simplaret_get_jail_patches $jailpath
+ fi
+ done
+ fi
+
+ ROOT=""
+
+}
+
+function simplaret_checksum {
+
+ # simplaret_checksum <md5file> <file-name> [--silent]
+
+ if [ ! -f "$1" ] || [ ! -f "$2" ]; then
+ if [ "$3" != "--silent" ]; then
+ echo Checksum error: file not found
+ fi
+ return 1
+ fi
+
+ pack="`basename $2`"
+ checksum="`grep -e "$pack\$" $1 | awk '{ print $1 }'`"
+
+ if [ -z "$checksum" ]; then
+ echo file $2 not in checksum $1
+ return 1
+ elif [ "$checksum" != "`md5sum $2 | awk '{ print $1 }'`" ]; then
+ if [ "$3" != "--silent" ]; then
+ echo Checksum mismatch for file `basename $file`
+ fi
+ return 1
+ else
+ if [ "$3" != "--silent" ]; then
+ echo Checksum ok for file `basename $file`
+ fi
+ return 0
+ fi
+
+}
+
+function simplaret_install {
+
+ # download and install a package
+ # usage: simplaret_install <package-name1|package-file-name1> ... [--skip-checks]
+
+ local package root jail_arch jail_version slack_required dep dependency tmp
+ local name version build
+
+ for package in $*; do
+
+ if [ "$package" == "--skip-checks" ]; then
+ continue
+ fi
+
+ name="`package_name $package`"
+
+ root="/$ROOT"
+ mkdir -p $root/var/log/setup/tmp
+
+ if [ "`echo $package | sed -e 's/\(..\).*/\1/g'`" == "--" ]; then
+ echo $BASENAME: install: syntax error: expected package name
+ return 1
+ fi
+
+ # now we check if ARCH and VERSION from the
+ # repository are the same of the jail
+ if ! echo $* | grep -q -- "--skip-checks"; then
+ jail_arch="`default_arch $root`"
+ jail_version="`default_version $root`"
+ if [ "$ARCH" != "$jail_arch" ]; then
+ echo "$BASENAME: requested repository arch ($ARCH) doesn't match jail arch ($jail_arch)"
+ echo "$BASENAME: please use \"$BASENAME --get $package --skip-checks\" to ignore this warning and install anyway"
+ return
+ elif [ "$VERSION" != "$jail_version" ]; then
+ echo "$BASENAME: requested repository version ($VERSION) doesn't match jail version ($jail_version)"
+ echo "$BASENAME: please use \"$BASENAME --get $package --skip-checks\" to ignore this warning and install anyway"
+ return 1
+ fi
+ fi
+
+ # package="`simplaret_get $package --silent`"
+ simplaret_get $package --silent
+ package="$LAST_DOWNLOADED_PACKAGE"
+
+ if [ "$package" != "0" ] && [ ! -z "$package" ]; then
+ slack_required="`dirname $package`/$name.slack-required"
+ if [ -f "$package" ]; then
+
+ if [ -f "$slack_required" ] && [ "$DEPENDENCY_CHECKING" == "1" ]; then
+ # TODO: check dependency versions
+ # this routine checks for dependencies in package's slack-required
+ # procedure adapted from createpkg script
+ ( grep -v '^#' $slack_required | awk '{ print $1 }' | while read dep; do
+ if [ ! -z "$dep" ]; then
+ dependency="`echo $dep | awk '{ print $package }'`"
+ simplaret_solve_dep $name $dependency $root
+ fi
+ true
+ done )
+ fi
+
+ ROOT=$root upgradepkg --install-new $package
+ LAST_DOWNLOADED_PACKAGE="0"
+
+ else
+ echo "Error: could not install package $package: file not found"
+ LAST_DOWNLOADED_PACKAGE="0"
+ return 1
+ fi
+ else
+ echo "Error: could not install package $package"
+ LAST_DOWNLOADED_PACKAGE="0"
+ return 1
+ fi
+
+ done
+
+}
+
+function simplaret_set_arch {
+
+ # set correct value for ARCH
+
+ local repos_type new_arch
+
+ # any arch defined in ARCH_i486 that hasn't an entry
+ # on $REPOS_CONF will be mapped to i486
+
+ ARCH_i486=" nocona prescott pentium4m pentium4 pentium-m pentium3m pentium3 "
+ ARCH_i486="$ARCH_i486 pentium2 i686 pentium-pro i586 pentium-mmx pentium i486 "
+ ARCH_i486="$ARCH_i486 athlon-mp athlon-xp athlon4 athlon-tbird athlon k6 k6-2 "
+ ARCH_i486="$ARCH_i486 k6-3 winchip-c6 winchip2 c3 c3-2 "
+
+ # any arch defined in ARCH_x86_64 that hasn't an entry
+ # on $REPOS_CONF will be mapped to x86_64
+
+ ARCH_x86_64=" k8 opteron athlon64 athlon-fx x86_64 "
+
+ for repos_type in patches root repos noarch; do
+ if [ -z "`simplaret_repository $repos_type`" ]; then
+ # there's no repository definition for that arch
+ if echo "$ARCH_i486" | grep -q " $ARCH "; then
+ new_arch="i486"
+ elif echo "$ARCH_x86_64" | grep -q " $ARCH "; then
+ new_arch="x86_64"
+ else
+ echo "$BASENAME: error: no repository definition for arch $ARCH"
+ echo "$BASENAME: please check your $CONF and $REPOS_CONF config files"
+ exit 1
+ fi
+ else
+ return
+ fi
+ done
+
+ echo "$BASENAME: changing arch from $ARCH to $new_arch"
+
+ ARCH="$new_arch"
+
+}
+
+function simplaret_check_url {
+
+ # check if a given url exist, use just with small files
+ # usage: simplaret_check_url <url>
+
+ if [ -z "$1" ]; then
+ return 1
+ fi
+
+ if echo $1 | grep -q -e "^file:///"; then
+ url="`echo $1 | sed -e 's/file:\/\///'`"
+ if [ -e "$url" ]; then
+ return 0
+ else
+ return 1
+ fi
+ fi
+
+ if [ ! -z "$CONNECT_TIMEOUT" ] || [ "$CONNECT_TIMEOUT" != "0" ]; then
+ curl_timeout="--connect-timeout $CONNECT_TIMEOUT"
+ fi
+
+ if [ "`curl $curl_timeout -I $1 2> /dev/null | head -n 1 | awk '{ print $2 }'`" == "200" ]; then
+ # server gave a 200 response, so the url exist
+ return 0
+ else
+ # the url is missing
+ return 1
+ fi
+
+}
+
+function simplaret_solve_dep {
+
+ # solve dependency for a package
+ # this function was adapted from createpkg script
+ # usage: simplaret_solve_dep <package-name> <package-depencency-name> [root-folder]
+
+ local installed check exit_code
+
+ local package="$1"
+ local pack="$2"
+ local root="/$3"
+
+ pack="`echo $pack| sed -e 's/\+/\\\+/'`"
+ installed="`check_installed $pack $root`"
+ check=$?
+
+ if [ -z "$installed" ]; then
+ if [ $check -ne 0 ]; then
+ echo "$BASENAME: processing $1 dependency $pack"
+ # simplaret_install $pack
+ SIMPLARET_CHILD=$SIMPLARET_CHILD ROOT=$root ARCH=$ARCH VERSION=$VERSION \
+ simplaret --install $pack
+ fi
+ fi
+
+}
+
+function simplaret_remove {
+
+ # remove packages
+ # usage: simplaret_remove <package1> [<package2> ... <packageN>]
+
+ for package in $*; do
+ ROOT=/$ROOT removepkg $package
+ done
+
+}
+
+function simplaret_req_arg {
+
+ # requires arg
+
+ if [ -z "$1" ]; then
+ simplaret_usage;
+ fi
+
+}
+
+if [ -z "$1" ]; then
+ simplaret_usage
+ exit 1
+else
+ eval_config $BASENAME
+ set_constants
+fi
+
+# This is used to show how many children process we have
+if [ -z "$SIMPLARET_CHILD" ]; then
+ SIMPLARET_CHILD="1"
+else
+ let SIMPLARET_CHILD++
+fi
+
+BASENAME="`basename $0`[$SIMPLARET_CHILD]"
+
+case $1 in
+ "--update" | "update" | "--sync" | "sync" ) simplaret_update ;;
+ "--upgrade" | "upgrade") simplaret_get_patches --upgrade ;;
+ "--get-patches" | "get-patches") simplaret_get_patches ;;
+ "--search" | "search") shift ; simplaret_req_arg $1 ; simplaret_search $* ;;
+ "--get" | "get") shift ; simplaret_req_arg $1 ; simplaret_get $* ;;
+ "--purge" | "purge") shift ; simplaret_purge $* ;;
+ "--install" | "install") shift ; simplaret_req_arg $1 ; simplaret_install $* ;;
+ "--remove" | "remove") shift ; simplaret_req_arg $1 ; simplaret_remove $* ;;
+ "--help" | "help") simplaret_usage ;;
+ *)
+ if echo $1 | grep -q -v '^--'; then
+ simplaret_install $*
+ else
+ simplaret_usage
+ fi
+ ;;
+esac
+
diff --git a/src/simpletrack b/src/simpletrack
new file mode 100755
index 0000000..31b7225
--- /dev/null
+++ b/src/simpletrack
@@ -0,0 +1,66 @@
+#!/bin/bash
+#
+# simpletrack $Id$: slacktrack/altertrack wrapper from simplepkg suite
+# feedback: rhatto at riseup.net | gpl
+#
+# Simpletrack 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.
+#
+# Simpletrack 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
+#
+
+PRIORITY=${SLACKTRACK_PRIORITY:=slacktrack-real slacktrack altertrack}
+BASENAME="`basename $0`"
+
+function slacktrack {
+
+ $1 -b $REPOS -x $TMP,$SRC_DIR,/dev -jefkzp "$PACKAGE-$VERSION-$ARCH-$BUILD.$MKBUILD_COMPRESS" "./$2"
+
+}
+
+function slacktrack-real {
+
+ $1 -b $REPOS -x $TMP,$SRC_DIR,/dev -jefkzp "$PACKAGE-$VERSION-$ARCH-$BUILD.$MKBUILD_COMPRESS" "./$2"
+
+}
+
+function altertrack {
+
+ $1 -b $REPOS -x $TMP,$SRC_DIR,/dev -jefkzp "$PACKAGE-$VERSION-$ARCH-$BUILD.$MKBUILD_COMPRESS" "./$2"
+
+}
+
+# -----------------------------------------------------
+# main
+# -----------------------------------------------------
+
+if [ -z "$1" ]; then
+ echo "usage: $BASENAME [options] <build-script>"
+ exit 1
+elif [ ! -f "$1" ]; then
+ echo "$1: file not found"
+ exit 1
+fi
+
+for tracker in $PRIORITY; do
+ path="`which $tracker 2> /dev/null`"
+ found="$?"
+ if [ "$found" == "0" ]; then
+ echo $BASENAME: using $tracker...
+ $tracker $path $*
+ break
+ fi
+done
+
+if [ "$found" != "0" ]; then
+ echo "Can't find any suitable tracker among $PRIORITY"
+ echo "Does slacktrack package is installed in your system?"
+ exit 1
+fi
diff --git a/src/templatepkg b/src/templatepkg
new file mode 100755
index 0000000..c107bd8
--- /dev/null
+++ b/src/templatepkg
@@ -0,0 +1,987 @@
+#!/bin/bash
+#
+# templatepkg: template maintenance script from simplepkg suite
+# feedback: rhatto at riseup.net | gpl
+#
+# Templatepkg 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.
+#
+# Templatepkg 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
+#
+# $Rev$ - $Author$
+#
+
+COMMON="/usr/libexec/simplepkg/common.sh"
+BASENAME="`basename $0`"
+
+if [ -f "$COMMON" ]; then
+ source $COMMON
+ eval_config $BASENAME
+else
+ echo "error: file $COMMON found, check your $BASENAME installation"
+ exit 1
+fi
+
+function usage_summary {
+
+ echo "options are:"
+ echo ""
+ echo " -c | --create: create a template from a jail or existing template"
+ echo " -u | --update: update a template from a jail"
+ echo " -a | --add: add files into a template"
+ echo " -d | --delete: delete files or folders from a template"
+ echo " -s | --sync: sync $TEMPLATE_FOLDER working copy"
+ echo " -e | --export: export $TEMPLATE_FOLDER to a svn repository"
+ echo " -i | --import: grab $TEMPLATE_FOLDER from a svn repository"
+ echo " -r | --remove: remove a template"
+ echo " -l | --list: list templates"
+ echo " -b | --batch-edit: add or edit post-installation scripts"
+ echo " -p | --pack: create a package from a template"
+ echo " -t | --template-edit: edit template package list"
+ echo " -h | --help: display this summary"
+ echo ""
+
+}
+
+function display_help {
+
+ # display help
+ # usage: help [help-topic]
+
+ local option
+
+ if [ -z "$1" ]; then
+ echo "type $BASENAME --help <option> for aditional help"
+ usage_summary
+ exit
+ fi
+
+ option="$1"
+
+ if ! echo $option | grep -q -e "^-"; then
+ option="-`echo $option | sed -e 's/--/-/' -e 's/\(.\).*/\1/'`"
+ else
+ option="`echo $option | sed -e 's/--/-/' -e 's/\(..\).*/\1/'`"
+ fi
+
+ echo "$BASENAME: help for option $option:"
+ echo ""
+
+ usage_summary | grep -e "^ $option"
+
+ echo ""
+ case $option in
+
+ "-c" | "--create")
+ echo " $BASENAME $option <template> [jail-root|template-name]"
+ ;;
+ "-u" | "--update")
+ echo " $BASENAME $option <template> [jail-root]"
+ ;;
+ "-a" | "--add")
+ echo " $BASENAME $option <template> <file-name> [jail-root]"
+ echo ""
+ echo " file-name: the file or directory to be added"
+ echo " jail-root: the jail under file-name is located"
+ ;;
+ "-d" | "--delete")
+ echo " $BASENAME $option <template> <file-name> [jail-root]"
+ echo ""
+ echo " file-name: the file or directory to be removed"
+ echo " jail-root: if specified, the file is also removed from the jail"
+ ;;
+ "-s" | "--sync")
+ echo " $BASENAME $option"
+ ;;
+ "-e" | "--export")
+ echo " $BASENAME $option <svn-repository>"
+ ;;
+ "-i" | "--import")
+ echo " $BASENAME $option <svn-repository>"
+ ;;
+ "-r" | "--remove")
+ echo " $BASENAME $option <template-name>"
+ ;;
+ "-l" | "--list")
+ echo " $BASENAME $option [path]"
+ ;;
+ "-b" | "--batch-edit")
+ echo " $BASENAME $option <template-name> <script-name>"
+ ;;
+ "-p" | "--pack")
+ echo " $BASENAME $option <template-name> [version] [build] [arch]"
+ ;;
+ "-t" | "--template-edit")
+ echo " $BASENAME $option <template-name>"
+ ;;
+ "-h" | "--help")
+ echo " -h | --help: display this help."
+ ;;
+ *)
+ echo $BASENAME: invalid help option $option
+ esac
+
+ case $option in
+ "-c" | "-u" | "-a")
+ echo ""
+ echo " if ommited, jail-root defaults to /"
+ ;;
+ esac
+
+ echo ""
+
+}
+
+function usage {
+
+ echo "usage: $BASENAME <option> [<template> [arguments]]"
+ usage_summary
+ exit
+
+}
+
+function import_export_templates {
+
+ # import from or export to $TEMPLATE_FOLDER in a svn repository
+ # usage: template_export <import|export> <repository>
+
+ local templates templates_folder basedir repository mode preposition
+ local repository_type repository_path
+
+ if [ "$?" != 0 ]; then
+ usage
+ exit 1
+ elif ! templates_under_svn; then
+ echo $BASENAME: simplepkg not configured to use svn
+ exit 1
+ fi
+
+ templates_folder="$TEMPLATE_FOLDER"
+ templates="`basename $TEMPLATE_FOLDER`"
+ basedir="`dirname $templates_folder`"
+ mode="$1"
+ repository="$2"
+ preposition="from"
+
+ valid_svn_repo $repository
+
+ if [ ! -z "$2" ]; then
+
+ if ! svn_folder $templates_folder; then
+
+ cd $basedir
+
+ if [ "$mode" == "export" ]; then
+ preposition="to"
+ check_and_create_svn_repo $repository
+ echo Exporting templates to $repository...
+ svn import $templates/ $repository/ -m "initial import"
+ if [ "$?" != "0" ]; then
+ echo $BASENAME: export failed
+ exit 1
+ fi
+ fi
+
+ if [ -d "templates" ]; then
+ mv $templates $templates.old
+ fi
+
+ echo Checking out templates from $repository...
+ svn checkout $repository $templates
+
+ if [ "$?" == "0" ]; then
+ rm -rf $templates.old
+ else
+ rm -rf $templates
+ mv $templates.old $templates
+ echo $BASENAME: $mode failed
+ exit 1
+ fi
+
+ else
+ echo "$BASENAME: $templates_folder seens to be already $mode""ed $preposition $repository"
+ exit 1
+ fi
+
+ fi
+
+}
+
+function template_create {
+
+ # create a new template
+
+ local template_base info_commit orig_template list
+ local orig_packages orig_perms orig_scripts orig_files
+
+ if [ ! -d "`dirname $TEMPLATE_BASE`" ]; then
+
+ echo Creating template `basename $TEMPLATE_BASE`...
+
+ if templates_under_svn && svn_folder `dirname $TEMPLATE_BASE`; then
+ cd `dirname $TEMPLATE_BASE`
+ svn mkdir `dirname $TEMPLATE_BASE`
+ else
+ mkdir -p `dirname $TEMPLATE_BASE`
+ fi
+
+ else
+ echo $BASENAME: template `basename $TEMPLATE_BASE` already exists
+ exit 1
+ fi
+
+ touch `template_perms`
+ touch `template_packages`
+
+ if templates_under_svn && svn_folder `dirname $TEMPLATE_BASE`; then
+
+ cd `dirname $TEMPLATE_BASE`
+
+ if ! svn_check `template_files`; then
+ svn mkdir `template_files`
+ info_commit="yes"
+ else
+ mkdir -p `template_files`
+ fi
+
+ if ! svn_check `template_scripts`; then
+ svn mkdir `template_scripts`
+ info_commit="yes"
+ else
+ mkdir -p `template_scripts`
+ fi
+
+ if ! svn_check `template_packages`; then
+ svn add `template_packages`
+ info_commit="yes"
+ fi
+
+ if ! svn_check `template_perms`; then
+ svn add `template_perms`
+ info_commit="yes"
+ fi
+
+ elif templates_under_svn && svn_folder "$TEMPLATE_FOLDER"; then
+
+ mkdir `template_files` `template_scripts`
+ cd $TEMPLATE_FOLDER
+ svn add `basename $TEMPLATE_BASE`
+ info_commit="yes"
+
+ else
+ mkdir `template_files` `template_scripts`
+ fi
+
+ if [ -d "/$ROOT" ]; then
+ template_update
+ elif [ ! -z "$ROOT" ]; then
+
+ # copy from an existing template
+
+ if [ -d "$TEMPLATE_FOLDER/$ROOT" ]; then
+ orig_template="$TEMPLATE_FOLDER/$ROOT"
+ elif [ -d "$BASE_CONF/templates/$ROOT" ]; then
+ orig_template="$BASE_CONF/templates/$ROOT"
+ elif [ -d "$BASE_CONF/defaults/templates/$ROOT" ]; then
+ orig_template="$BASE_CONF/defaults/templates/$ROOT"
+ else
+ return 1
+ fi
+
+ if [ -e "$orig_template/$ROOT/packages" ]; then
+ orig_packages="$orig_template/$ROOT/packages"
+ orig_perms="$orig_template/$ROOT/perms"
+ orig_scripts="$orig_template/$ROOT/scripts"
+ orig_files="$orig_template/$ROOT/files"
+ else
+ orig_packages="$orig_template/$ROOT.template"
+ orig_perms="$orig_template/$ROOT.perms"
+ orig_scripts="$orig_template/$ROOT.s"
+ orig_files="$orig_template/$ROOT.d"
+ fi
+
+ if [ -f "$orig_perms" ]; then
+ cat $orig_perms > `template_perms`
+ fi
+
+ if [ -f "$orig_packages" ]; then
+ cat $orig_packages > `template_packages`
+ fi
+
+ if templates_under_svn && svn_folder $orig_template; then
+
+ cd `dirname $TEMPLATE_BASE`
+
+ list="`ls $orig_files/ 2> /dev/null`"
+ if [ ! -z "$list" ]; then
+ echo Copying files to the new template...
+ rsync -av --exclude=.svn $orig_files/ `template_files`/
+ svn add `basename $(template_files)`/*
+ info_commit="yes"
+ fi
+
+ list="`ls $orig_scripts/ 2> /dev/null`"
+ if [ ! -z "$list" ]; then
+ echo Copying scripts to the new template...
+ rsync -av --exclude=.svn $orig_scripts/ `template_scripts`/
+ svn add `basename $(template_scripts)`/*
+ info_commit="yes"
+ fi
+
+ else
+
+ list="`ls $orig_files/ 2> /dev/null`"
+ if [ ! -z "$list" ]; then
+ echo Copying files to the new template...
+ rsync -av $orig_files/ `template_files`/
+ fi
+
+ list="`ls $orig_scripts/ 2> /dev/null`"
+ if [ ! -z "$list" ]; then
+ echo Copying scripts to the new template...
+ rsync -av $orig_scripts/ `template_scripts`/
+ fi
+
+ fi
+
+ else
+ echo $BASENAME: warning: no root directory defined
+ fi
+
+ if [ "$info_commit" == "yes" ] && [ -z "$SILENT" ]; then
+ echo "Please run 'jail-commit --all' to add files under $file into the svn repository"
+ fi
+
+}
+
+function template_update {
+
+ # update the template package list
+
+ check_template_exist
+
+ if [ ! -d "$ROOT/var/log/packages" ]; then
+ echo $ROOT/var/log/packages: directory not found
+ exit 1
+ fi
+
+ echo Checking package list for template `basename $TEMPLATE_BASE`...
+
+ for package in `ls -1 $ROOT/var/log/packages/`; do
+ pack=`package_name $package`
+ if [ -f $TEMPLATE ]; then
+ if ! `grep -v -e "^#" $TEMPLATE | cut -d : -f 1 | awk '{ print $1 }' | grep -q -e "^$pack\$"`; then
+ echo $pack >> $TEMPLATE
+ echo Adding $pack # on $TEMPLATE
+ fi
+ else
+ echo $pack >> $TEMPLATE
+ echo Adding $pack # on $TEMPLATE
+ fi
+ done
+
+ # check if each package from the template is installed
+ grep -v -e "^#" $TEMPLATE | cut -d : -f 1 | awk '{ print $1 }' | while read pack; do
+
+ if [ ! -z "$pack" ]; then
+ unset found
+ for candidate in `ls $ROOT/var/log/packages/$pack* 2> /dev/null`; do
+ candidate="`package_name $candidate`"
+ if [ "$pack" == "$candidate" ]; then
+ found="1"
+ break
+ fi
+ done
+ if [ "$found" != "1" ]; then
+ # remove a non-installed package from the template
+ sed "/^$pack$/d" $TEMPLATE | sed "/^$pack $/d" | sed "/^$pack:*/d" | sed "/^$pack */d" > $TEMPLATE.tmp
+ cat $TEMPLATE.tmp > $TEMPLATE
+ rm -f $TEMPLATE.tmp
+ echo Removing $pack # from $TEMPLATE
+ fi
+ fi
+
+ done
+
+ if ! svn_check `template_packages` && svn_folder `dirname $TEMPLATE_BASE`; then
+ cd `dirname $TEMPLATE_BASE`
+ svn add `basedir $(template_packages)`
+ fi
+
+}
+
+function template_add {
+
+ # add a file in a template
+ # usage: template_add <jail-root> <file>
+
+ local info_commit cwd
+
+ if [ -z "$1" ] || [ -z "$2" ]; then
+ return 1
+ fi
+
+ check_template_exist
+
+ jail="/$1"
+ file="$2"
+
+ if [ -a "`template_files`/$file" ]; then
+ if [ -d "`template_files`/$file" ]; then
+
+ echo $BASENAME: folder `slash $file` already on `template_files`, checking for contents
+
+ cd $jail
+ for candidate in `find $file`; do
+ if [ ! -a "`template_files`/$candidate" ]; then
+ mkdir -p `template_files`/`dirname $candidate`
+ cp -a $jail/$candidate `template_files`/$candidate
+ if templates_under_svn && svn_folder `template_files`; then
+ cwd="`pwd`"
+ cd `template_files`
+ svn add ./$candidate
+ if [ "$?" != "0" ]; then
+ echo $BASENAME: error adding `slash $candidate` into the revision system
+ fi
+ cd $cwd
+ info_commit="yes"
+ else
+ echo Added `slash $jail/$candidate` on `slash $(template_files)/$candidate`
+ fi
+ fi
+ done
+
+ if [ "$info_commit" == "yes" ] && [ -z "$SILENT" ]; then
+ echo "Please run 'jail-commit --all' to add files under `slash $file` into the svn repository"
+ fi
+
+ else
+ echo $BASENAME: file `slash $file` already on `template_files`
+ exit 1
+ fi
+ else
+
+ if [ -a "$jail/$file" ]; then
+
+ destination="`echo $(template_files)/$file | sed -e 's/\/$//'`"
+
+ if templates_under_svn && svn_folder `template_files`; then
+
+ candidate="./`dirname $file`"
+
+ if ! svn_folder `template_files`/$candidate; then
+ mkdir -p `template_files`/$candidate
+ cd `template_files`/`dirname $candidate`
+ while true; do
+ if svn_folder $(pwd); then
+ svn add `basename $candidate`
+ break
+ else
+ candidate="`basename $(pwd)`"
+ cd ..
+ fi
+ done
+ fi
+
+ cp -a $jail/$file $destination
+
+ cwd="`pwd`"
+ cd `template_files`
+ svn add ./$file
+
+ if [ "$?" != "0" ]; then
+ echo $BASENAME: error adding `slash $candidate` into the revision system
+ else
+ if [ -z "$SILENT" ]; then
+ echo "Please run 'jail-commit --all' to add `slash $file` into the svn repository"
+ fi
+ fi
+
+ cd $cwd
+
+ else
+
+ mkdir -p `template_files`/`dirname $file`/
+ cp -a $jail/$file $destination
+ echo Added `slash $jail/$file` on `slash $destination`
+
+ fi
+
+ else
+ echo $BASENAME: `slash $jail/$file`: file not found
+ exit 1
+ fi
+ fi
+
+}
+
+function check_template_exist {
+
+ # check if a template exists
+ # and create missing components
+
+ local components
+
+ components="`template_packages` `template_perms` `template_files` `template_scripts`"
+
+ if [ ! -d "`dirname $TEMPLATE_BASE`" ]; then
+ echo $BASENAME: template not found
+ exit 1
+ fi
+
+ for component in $components; do
+
+ if [ ! -e "$component" ]; then
+
+ echo "$BASENAME: template component not found: $component; creating..."
+
+ cd `dirname $TEMPLATE_BASE`
+
+ if [ "$component" == "perms" ] || [ "$component" == "template" ]; then
+ touch $component
+ else
+ mkdir $component
+ fi
+
+ if templates_under_svn && svn_folder `dirname $TEMPLATE_BASE`; then
+ svn add $component
+ info_commit="yes"
+ fi
+
+ elif templates_under_svn && svn_folder `dirname $TEMPLATE_BASE` && \
+ ! svn_check $component; then
+
+ cd `dirname $TEMPLATE_BASE`
+ svn add $component
+ info_commit="yes"
+
+ fi
+
+ done
+
+ if [ "$info_commit" == "yes" ] && [ -z "$SILENT" ]; then
+ echo "Please run 'jail-commit --all' to add new files in the svn repository"
+ fi
+
+}
+
+function template_delete {
+
+ # delete a file from a template
+ # usage: template_delete <file> [jail-root]
+
+ if [ -e "`template_files`/$1" ]; then
+
+ # first try to remove the file from the template
+ if templates_under_svn && svn_folder `template_files`; then
+ cd `template_files`
+ svn del --force ./$1 || rm -rf ./$1
+ if [ -z "$SILENT" ]; then
+ echo "Please run 'jail-commit --all' to del $1 in the svn repository"
+ fi
+ else
+ rm -rf `template_files`/$1
+ echo Removed $1 from `template_files`
+ fi
+
+ # then, if requested, remove the file from the jail
+ if [ ! -z "$2" ]; then
+ if [ ! -d "$2" ]; then
+ echo $BASENAME: jail not found: $2
+ elif [ -e "$2/$1" ]; then
+ rm -rf $2/$1
+ echo Removed $1 from jail $2
+ else
+ echo $BASENAME: file not found: $2/$1
+ fi
+ fi
+
+ elif [ -e "`template_scripts`/$1" ]; then
+ if templates_under_svn && svn_folder `template_scripts`; then
+ cd `template_scripts`
+ svn del --force ./$1 || rm -rf ./$1
+ if [ -z "$SILENT" ]; then
+ echo "Please run 'jail-commit --all' to del $1 in the svn repository"
+ fi
+ else
+ rm -rf `template_scripts`/$1
+ echo Removed $1 from `template_scripts`
+ fi
+ else
+ if [ ! -d "`template_files`" ]; then
+ echo $BASENAME: template folder `template_files` not found
+ else
+ echo $BASENAME: file $1 not found at `template_files`
+ fi
+ exit 1
+ fi
+
+}
+
+function template_remove {
+
+ # remove a template
+ # usage: template_remove
+
+ local basedir template
+
+ basedir="`dirname $TEMPLATE_BASE`"
+ template="`basename $basedir`"
+
+ if [ ! -d "$basedir" ]; then
+ echo $BASENAME: template $template does not exist
+ exit 1
+ fi
+
+ if templates_under_svn && svn_folder $basedir; then
+ cd $TEMPLATE_FOLDER
+ svn update
+ svn del --force $template
+ if [ "$?" != "0" ]; then
+ echo $BASENAME: error deleting template $template
+ else
+ svn commit -m "deleted $template"
+ if [ "$?" != "0" ]; then
+ echo $BASENAME: error commiting to svn repository
+ fi
+ fi
+ else
+ rm -rf $basedir
+ fi
+
+}
+
+function template_list {
+
+ # list templates
+ # usage: template_list [path]
+
+ local list basedir template
+
+ if [ "$TEMPLATE_STORAGE_STYLE" != "own-folder" ] && \
+ [ "$TEMPLATE_STORAGE_STYLE" != "compact" ]; then
+ echo "$BASENAME: option only available if TEMPLATE_STORAGE_STYLE configured as 'own-folder' or 'compact'"
+ return 1
+ fi
+
+ if echo $1 | grep -q "/" || [ ! -z "$1" ]; then
+
+ template="`echo $1 | cut -d "/" -f 1`"
+
+ if [ -e "$BASE_CONF/defaults/templates/$1" ]; then
+ list="`ls $BASE_CONF/defaults/templates/$1 2> /dev/null`"
+ if [ "$?" == "0" ]; then
+ list="`echo $list | xargs`"
+ echo "In the default template $template: $list"
+ fi
+ fi
+
+ if [ -e "$TEMPLATE_FOLDER/$1" ]; then
+ list="`ls $TEMPLATE_FOLDER/$1 2> /dev/null`"
+ if [ "$?" == "0" ]; then
+ list="`echo $list | xargs`"
+ echo "In the custom template $template: $list"
+ fi
+ fi
+
+ else
+
+ list="`ls $BASE_CONF/defaults/templates/$1 2> /dev/null`"
+ if [ "$?" == "0" ]; then
+ list="`echo $list | xargs`"
+ echo "Default templates: $list"
+ fi
+
+ list="`ls $TEMPLATE_FOLDER/$1 2> /dev/null`"
+ if [ "$?" == "0" ]; then
+ list="`echo $list | xargs`"
+ echo "Custom templates: $list"
+ fi
+
+ fi
+
+}
+
+function template_post_install_edit {
+
+ # add or edit a post-installation script
+ # usage: template_post_install_edit <script-name>
+
+ if [ -z "$1" ]; then
+ echo $BASENAME: no template specified
+ exit 1
+ elif echo $1 | grep -q "/"; then
+ echo $BASENAME: error: invalid script name $1
+ fi
+
+ if [ -f "`template_scripts`/$1" ]; then
+ sha1sum="`sha1sum $(template_scripts)/$1`"
+ if [ ! -z "$EDITOR" ]; then
+ $EDITOR `template_scripts`/$1
+ else
+ vi `template_scripts`/$1
+ fi
+ if [ "$sha1sum" != "`sha1sum $(template_scripts)/$1`" ] && \
+ svn_folder `dirname $TEMPLATE_BASE` && [ -z "$SILENT" ]; then
+ echo "Please run 'jail-commit --all' to send changes to the repository"
+ fi
+ else
+
+ if [ -e "`template_scripts`/$1" ]; then
+
+ echo $BASENAME: file `template_scripts`/$1 not a regular file
+
+ elif [ -d "`template_scripts`" ]; then
+
+ touch `template_scripts`/$1
+ chmod +x `template_scripts`/$1
+
+ if svn_folder `template_scripts`; then
+ cd `template_scripts`
+ svn add $1
+ if [ -z "$SILENT" ]; then
+ echo "Please run 'jail-commit --all' to send the script to the repository"
+ fi
+ fi
+
+ echo "$BASENAME: script created; run templatepkg -p `basename $TEMPLATE_BASE` $1 again to edit it"
+
+ else
+ echo $BASENAME: folder not found: `template_scripts`
+ fi
+
+ fi
+
+}
+
+function template_edit {
+
+ # edit a template package list
+ # usage: template_edit
+
+ if [ -f "`template_packages`" ]; then
+ sha1sum="`sha1sum $(template_packages)`"
+ if [ ! -z "$EDITOR" ]; then
+ $EDITOR `template_packages`
+ else
+ vi `template_packages`
+ fi
+ if [ "$sha1sum" != "`sha1sum $(template_packages)`" ] && \
+ svn_folder `dirname $TEMPLATE_BASE` && [ -z "$SILENT" ]; then
+ echo "Please run 'jail-commit --all' to send changes to the repository"
+ fi
+ elif [ -e "`template_packages`" ]; then
+ echo $BASENAME: file `template_packages` not a regular file
+ else
+ echo $BASENAME: file not found: `template_packages`
+ fi
+
+}
+
+function require {
+
+ # requires a string
+ # usage: require [string]
+
+ if [ -z "$1" ]; then
+ usage
+ fi
+
+}
+
+function setroot {
+
+ # set ROOT variable
+ # usage: setroot <value1> <value2>
+
+ if [ -z "$1" ]; then
+ ROOT="/"
+ else
+ ROOT="$1"
+ fi
+
+}
+
+function create_doinst {
+
+ # create a doinst.sh from a template perms file
+ # usage: create_doinst <doinst-path>
+
+ rm -f $1/doinst.sh
+
+ if [ -s "`template_perms`" ]; then
+ echo Creating doinst.sh...
+ cat `template_perms` | while read entry; do
+ file="`echo $entry | cut -d ";" -f 1`"
+ if [ -e "`template_files`/$file" ]; then
+ owner="`echo $entry | cut -d ";" -f 2`"
+ group="`echo $entry | cut -d ";" -f 3`"
+ perms="`echo $entry | cut -d ";" -f 4`"
+ echo "( chmod $perms /$file )" >> $1/doinst.sh
+ echo "( chown $owner:$group /$file )" >> $1/doinst.sh
+ fi
+ done
+ fi
+
+}
+
+function package_template {
+
+ # make a package from a template
+ # usage: package_template [version] [build] [arch]
+
+ local template version build arch
+
+ template="`basename $TEMPLATE_BASE`"
+
+ if [ ! -d "`template_files`" ]; then
+ $BASENAME: folder not found: `template_files`
+ return 1
+ fi
+
+ echo Buiding package for template $template...
+
+ if [ -z "$1" ]; then
+ version="1"
+ else
+ version="$1"
+ fi
+
+ if [ -z "$2" ]; then
+ build="1"
+ else
+ build="$2"
+ fi
+
+ if [ -z "$3" ]; then
+ arch="noarch"
+ else
+ arch="$3"
+ fi
+
+ TMP=${TMP:=/tmp}
+ rm -rf $TMP/templatepkg
+ mkdir -p $TMP/templatepkg
+
+ rsync -av --exclude=.svn `template_files`/ $TMP/templatepkg/
+ mkdir $TMP/templatepkg/install
+ create_doinst $TMP/templatepkg/install
+
+ echo "template-$template: template-$template" > $TMP/templatepkg/install/slack-desc
+ echo "template-$template: " >> $TMP/templatepkg/install/slack-desc
+ echo "template-$template: simplepkg template $template" >> $TMP/templatepkg/install/slack-desc
+
+ for ((n=1;n<=8;n++)); do
+ echo "template-$template: " >> $TMP/templatepkg/install/slack-desc
+ done
+
+ cd $TMP/templatepkg
+
+ makepkg -c n -l y $TMP/template-$template-$version-noarch-$build.$MKBUILD_COMPRESS
+
+ cd $TMP
+ rm -rf templatepkg
+
+}
+
+# -----------------------------------------------------
+# main
+# -----------------------------------------------------
+
+if [ ! -z "$2" ]; then
+ search_template $2 --new
+fi
+
+TEMPLATE="`template_packages`"
+
+if [ "$1" == "-u" ] || [ "$1" == "--update" ]; then
+
+ require $2
+ setroot $3
+ template_update
+
+elif [ "$1" == "-c" ] || [ "$1" == "--create" ]; then
+
+ require $2
+ setroot $3
+ template_create
+
+elif [ "$1" == "-a" ] || [ "$1" == "--add" ]; then
+
+ require $2
+
+ if [ -z "$3" ]; then
+ usage
+ else
+ setroot $4
+ fi
+
+ template_add $ROOT $3
+
+elif [ "$1" == "-d" ] || [ "$1" == "--delete" ]; then
+
+ require $2
+
+ if [ -z "$3" ]; then
+ usage
+ else
+ template_delete $3 $4
+ fi
+
+elif [ "$1" == "-s" ] || [ "$1" == "--sync" ]; then
+
+ if templates_under_svn && svn_folder $TEMPLATE_FOLDER; then
+ ( cd $TEMPLATE_FOLDER && svn update )
+ true
+ fi
+
+elif [ "$1" == "-e" ] || [ "$1" == "--export" ]; then
+
+ require $2
+ import_export_templates export $2
+
+elif [ "$1" == "-i" ] || [ "$1" == "--import" ]; then
+
+ require $2
+ import_export_templates import $2
+
+elif [ "$1" == "-r" ] || [ "$1" == "--remove" ]; then
+
+ require $2
+ template_remove
+
+elif [ "$1" == "-l" ] || [ "$1" == "--list" ]; then
+
+ template_list $2
+
+elif [ "$1" == "-b" ] || [ "$1" == "--batch-edit" ]; then
+
+ require $3
+ template_post_install_edit $3
+
+elif [ "$1" == "-t" ] || [ "$1" == "--template-edit" ]; then
+
+ require $2
+ template_edit
+
+elif [ "$1" == "-p" ] || [ "$1" == "--pack" ]; then
+
+ require $2
+ shift ; shift
+ package_template $*
+
+elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+
+ display_help $2
+
+else
+ usage
+fi
+