mirror of
https://github.com/sbopkg/sbopkg
synced 2024-12-27 09:58:28 +01:00
sqg: Parallelize building for selected packages
Signed-off-by: Marcel Saegebarth <marcel.saegebarth@fairmas.com>
This commit is contained in:
parent
3b900ef977
commit
36bfb42170
2 changed files with 58 additions and 15 deletions
|
@ -1,8 +1,16 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# use filesystem for caching SlackBuilds
|
#
|
||||||
|
# Use file system for caching SlackBuilds.
|
||||||
|
#
|
||||||
SQG_TMP_DIR=${SQG_TMP_DIR:-/tmp/sqg}
|
SQG_TMP_DIR=${SQG_TMP_DIR:-/tmp/sqg}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Sanity checks:
|
||||||
|
# - sbopkg.conf is available
|
||||||
|
# - slackbuilds.org was synced with `rsync` or `git`
|
||||||
|
# - directory checks
|
||||||
|
#
|
||||||
sanity_checks () {
|
sanity_checks () {
|
||||||
if [ ! -e "$SBOPKG_CONF" ]; then
|
if [ ! -e "$SBOPKG_CONF" ]; then
|
||||||
echo "$SBOPKG_CONF not found."
|
echo "$SBOPKG_CONF not found."
|
||||||
|
@ -29,6 +37,9 @@ sanity_checks () {
|
||||||
mkdir -p "$SQG_TMP_DIR"
|
mkdir -p "$SQG_TMP_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Returns 1 if GNU Parallel is installed. Otherwise 0.
|
||||||
|
#
|
||||||
has_parallel () {
|
has_parallel () {
|
||||||
parallel --help &> /dev/null
|
parallel --help &> /dev/null
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
|
@ -38,11 +49,14 @@ has_parallel () {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Prints the help message.
|
||||||
|
#
|
||||||
usage () {
|
usage () {
|
||||||
local SCRIPT="$1"
|
local SCRIPT="$1"
|
||||||
|
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Usage: $SCRIPT -p <packagename(s)> | -a [-j]
|
Usage: $SCRIPT -p <packagename(s)> [-j #] | -a [-j #]
|
||||||
Options are:
|
Options are:
|
||||||
-p package(s) Creates queuefile(s) for individual package(s).
|
-p package(s) Creates queuefile(s) for individual package(s).
|
||||||
Multiple packages can be passed with quotes,
|
Multiple packages can be passed with quotes,
|
||||||
|
@ -63,6 +77,11 @@ EOF
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Parses and validates the amount of parallel processes defined by option -j.
|
||||||
|
# Returns the amount of jobs if value is an unsigned integer.
|
||||||
|
# Otherwise exits with code 1.
|
||||||
|
#
|
||||||
get_jobs () {
|
get_jobs () {
|
||||||
local JOBS=${1:-1}
|
local JOBS=${1:-1}
|
||||||
|
|
||||||
|
@ -76,6 +95,13 @@ get_jobs () {
|
||||||
return $JOBS
|
return $JOBS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tries to find the dependency listed in the SlackBuilds .info file and writes
|
||||||
|
# the path into a temporary file. If the package was already found, it gets the
|
||||||
|
# path from inside the temporary file to speed up the overall process.
|
||||||
|
# If the package path of the dependent package isn't empty, the function
|
||||||
|
# returns 1. Otherwise 0.
|
||||||
|
#
|
||||||
search_package () {
|
search_package () {
|
||||||
local REPO_DIR="$1"
|
local REPO_DIR="$1"
|
||||||
local SRCHAPP="$2"
|
local SRCHAPP="$2"
|
||||||
|
@ -95,6 +121,10 @@ search_package () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Parses the REQUIRES variable inside the SlackBuild .info file and recursively
|
||||||
|
# writes the dependent package name into the queue file.
|
||||||
|
#
|
||||||
parse_queuefile_requires () {
|
parse_queuefile_requires () {
|
||||||
local REPO_DIR="$1"
|
local REPO_DIR="$1"
|
||||||
local PARSEAPP="$2"
|
local PARSEAPP="$2"
|
||||||
|
@ -129,6 +159,9 @@ parse_queuefile_requires () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Starts the process of building the packages queue file.
|
||||||
|
#
|
||||||
build_queuefile () {
|
build_queuefile () {
|
||||||
local REPO_DIR="$1"
|
local REPO_DIR="$1"
|
||||||
local QUEUEDIR="$2"
|
local QUEUEDIR="$2"
|
||||||
|
@ -149,6 +182,9 @@ build_queuefile () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Processes all or given packages depending on option.
|
||||||
|
#
|
||||||
execute_build () {
|
execute_build () {
|
||||||
local REPO_DIR="$1"
|
local REPO_DIR="$1"
|
||||||
local QUEUEDIR="$2"
|
local QUEUEDIR="$2"
|
||||||
|
|
|
@ -51,22 +51,29 @@ REPO_BRANCH=${REPO_BRANCH:-$(cat /etc/slackware-version | awk '{print $2}')}
|
||||||
. /usr/libexec/sbopkg/sqg/functions
|
. /usr/libexec/sbopkg/sqg/functions
|
||||||
|
|
||||||
SCRIPT=${0##*/}
|
SCRIPT=${0##*/}
|
||||||
|
OPT_JOBS=1
|
||||||
|
OPT_ALL="no"
|
||||||
|
OPT_PACKAGES=""
|
||||||
|
|
||||||
sanity_checks
|
sanity_checks
|
||||||
|
|
||||||
case $1 in
|
while getopts "ap:j:h" OPT; do
|
||||||
-a)
|
case $OPT in
|
||||||
if [ "$2" == "-j" ] && [ -n $3 ]; then
|
a ) OPT_ALL="yes" ;;
|
||||||
get_jobs $3
|
p ) OPT_PACKAGES=$OPTARG ;;
|
||||||
JOBS=$?
|
j ) get_jobs "$OPTARG"; OPT_JOBS=$?; ;;
|
||||||
fi
|
h ) usage $SCRIPT; exit 0; ;;
|
||||||
shift;
|
? ) exit 1; ;;
|
||||||
execute_build "$REPO_DIR" "$QUEUEDIR" "" "yes" $JOBS ;;
|
esac
|
||||||
-p)
|
done
|
||||||
shift;
|
|
||||||
execute_build "$REPO_DIR" "$QUEUEDIR" "$@" "no" $JOBS ;;
|
if [ $OPTIND -eq 1 ]; then
|
||||||
*) usage $SCRIPT ;;
|
echo -e "Missing argument(s).\n"
|
||||||
esac
|
usage $SCRIPT
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
execute_build "$REPO_DIR" "$QUEUEDIR" "$OPT_PACKAGES" "$OPT_ALL" $OPT_JOBS
|
||||||
|
|
||||||
echo "Done."
|
echo "Done."
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue