2016-04-17 08:07:26 +02:00
|
|
|
#!/hint/bash
|
2008-09-02 07:01:03 +02:00
|
|
|
|
2017-04-20 21:55:23 +02:00
|
|
|
. /usr/share/makepkg/util.sh
|
2017-04-18 20:20:49 +02:00
|
|
|
|
2018-02-16 04:26:24 +01:00
|
|
|
# global shell options for enhanced bash scripting
|
Globally set $PKGEXT to a bash extended glob representing valid choices.
The current glob `*.pkg.tar.?z` is both less restrictive and more
restrictive than makepkg, as it accepts any valid unicode character.
To be more exact, it's almost completely orthogonal to the one in makepkg.
makepkg only accepts .tar.gz, .tar.bz2, .tar.xz, .tar.lzo, .tar.lrz, and
.tar.Z and most of those fail to match against a two-char compression type.
dbscripts accepts .pkg.tar.💩z which incidentally is what I think of
cherry-picking xz and gz as supported methods.
Since this can be anything makepkg.conf accepts, it needs to be able to
match all that, unless we decide to perform additional restrictions in
which case we should still explicitly list each allowed extension. Using
bash extended globbing allows us to do this relatively painlessly.
Document the fact that this has *always* been some sort of glob, and
update the two cases where this was (not!) being evaluated by bash
[[ ... ]], to use a not-elegant-at-all proxy function is_globfile() to
evaluate globs *before* testing if they exist.
2018-02-16 04:34:36 +01:00
|
|
|
shopt -s extglob globstar nullglob
|
2018-02-16 04:26:24 +01:00
|
|
|
|
|
|
|
|
2010-11-22 12:31:28 +01:00
|
|
|
# Some PKGBUILDs need CARCH to be set
|
|
|
|
CARCH="x86_64"
|
|
|
|
|
2008-09-02 07:01:03 +02:00
|
|
|
# Useful functions
|
2008-11-22 03:31:13 +01:00
|
|
|
UMASK=""
|
|
|
|
set_umask () {
|
2018-02-13 02:50:57 +01:00
|
|
|
export UMASK="${UMASK:-$(umask)}"
|
2008-11-22 03:31:13 +01:00
|
|
|
umask 002
|
|
|
|
}
|
|
|
|
|
|
|
|
restore_umask () {
|
2018-03-16 02:47:58 +01:00
|
|
|
umask "$UMASK" >/dev/null
|
2008-11-22 03:31:13 +01:00
|
|
|
}
|
|
|
|
|
Globally set $PKGEXT to a bash extended glob representing valid choices.
The current glob `*.pkg.tar.?z` is both less restrictive and more
restrictive than makepkg, as it accepts any valid unicode character.
To be more exact, it's almost completely orthogonal to the one in makepkg.
makepkg only accepts .tar.gz, .tar.bz2, .tar.xz, .tar.lzo, .tar.lrz, and
.tar.Z and most of those fail to match against a two-char compression type.
dbscripts accepts .pkg.tar.💩z which incidentally is what I think of
cherry-picking xz and gz as supported methods.
Since this can be anything makepkg.conf accepts, it needs to be able to
match all that, unless we decide to perform additional restrictions in
which case we should still explicitly list each allowed extension. Using
bash extended globbing allows us to do this relatively painlessly.
Document the fact that this has *always* been some sort of glob, and
update the two cases where this was (not!) being evaluated by bash
[[ ... ]], to use a not-elegant-at-all proxy function is_globfile() to
evaluate globs *before* testing if they exist.
2018-02-16 04:34:36 +01:00
|
|
|
# Proxy function to check if a file exists. Using [[ -f ... ]] directly is not
|
|
|
|
# always wanted because we might want to expand bash globs first. This way we
|
|
|
|
# can pass unquoted globs to is_globfile() and have them expanded as function
|
|
|
|
# arguments before being checked.
|
|
|
|
is_globfile() {
|
|
|
|
[[ -f $1 ]]
|
|
|
|
}
|
|
|
|
|
2013-03-19 19:53:38 +01:00
|
|
|
# just like mv -f, but we touch the file and then copy the content so
|
|
|
|
# default ACLs in the target dir will be applied
|
|
|
|
mv_acl() {
|
|
|
|
rm -f "$2"
|
|
|
|
touch "$2"
|
|
|
|
cat "$1" >"$2" || return 1
|
|
|
|
rm -f "$1"
|
|
|
|
}
|
|
|
|
|
2010-08-08 15:03:27 +02:00
|
|
|
# set up general environment
|
2014-01-17 19:06:53 +01:00
|
|
|
WORKDIR=$(mktemp -dt "${0##*/}.XXXXXXXXXX")
|
2010-08-08 15:03:27 +02:00
|
|
|
LOCKS=()
|
2013-01-23 23:03:35 +01:00
|
|
|
REPO_MODIFIED=0
|
2010-08-08 15:03:27 +02:00
|
|
|
|
|
|
|
script_lock() {
|
2011-12-19 14:40:07 +01:00
|
|
|
local LOCKDIR="$TMPDIR/.scriptlock.${0##*/}"
|
2010-08-08 15:03:27 +02:00
|
|
|
if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then
|
2018-03-16 02:47:58 +01:00
|
|
|
local _owner="$(/usr/bin/stat -c %U "$LOCKDIR")"
|
2018-02-12 23:53:10 +01:00
|
|
|
error "Script %s is already locked by %s." "${0##*/}" "$_owner"
|
2010-08-08 15:03:27 +02:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
set_umask
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
script_unlock() {
|
2011-12-19 14:40:07 +01:00
|
|
|
local LOCKDIR="$TMPDIR/.scriptlock.${0##*/}"
|
2018-02-13 02:50:57 +01:00
|
|
|
if [[ ! -d $LOCKDIR ]]; then
|
2018-02-12 23:53:10 +01:00
|
|
|
warning "Script %s was not locked!" "${0##*/}"
|
2010-08-08 15:03:27 +02:00
|
|
|
restore_umask
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
rmdir "$LOCKDIR"
|
|
|
|
restore_umask
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
local l
|
|
|
|
local repo
|
|
|
|
local arch
|
|
|
|
|
|
|
|
trap - EXIT INT QUIT TERM
|
2018-03-16 02:47:58 +01:00
|
|
|
for l in "${LOCKS[@]}"; do
|
2010-08-08 15:03:27 +02:00
|
|
|
repo=${l%.*}
|
|
|
|
arch=${l#*.}
|
2018-02-13 02:50:57 +01:00
|
|
|
if [[ -d $TMPDIR/.repolock.$repo.$arch ]]; then
|
2018-02-12 23:53:10 +01:00
|
|
|
msg "Removing left over lock from [%s] (%s)" "$repo" "$arch"
|
2018-03-16 02:47:58 +01:00
|
|
|
repo_unlock "$repo" "$arch"
|
2010-08-08 15:03:27 +02:00
|
|
|
fi
|
|
|
|
done
|
2018-02-13 02:50:57 +01:00
|
|
|
if [[ -d $TMPDIR/.scriptlock.${0##*/} ]]; then
|
2018-02-12 23:53:10 +01:00
|
|
|
msg "Removing left over lock from %s" "${0##*/}"
|
2010-08-08 15:03:27 +02:00
|
|
|
script_unlock
|
|
|
|
fi
|
|
|
|
rm -rf "$WORKDIR"
|
2013-01-23 23:03:35 +01:00
|
|
|
|
|
|
|
if (( REPO_MODIFIED )); then
|
|
|
|
date +%s > "${FTP_BASE}/lastupdate"
|
|
|
|
fi
|
|
|
|
|
2018-03-16 02:47:58 +01:00
|
|
|
[[ -n $1 ]] && exit "$1"
|
2010-08-08 15:03:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
abort() {
|
2010-08-13 09:47:31 +02:00
|
|
|
msg 'Aborting...'
|
2010-08-08 15:03:27 +02:00
|
|
|
cleanup 0
|
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
2018-02-12 23:53:10 +01:00
|
|
|
error "$@"
|
2010-08-08 15:03:27 +02:00
|
|
|
cleanup 1
|
|
|
|
}
|
|
|
|
|
2010-08-13 08:20:27 +02:00
|
|
|
trap abort INT QUIT TERM HUP
|
2010-08-08 15:03:27 +02:00
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
|
2010-08-08 15:16:55 +02:00
|
|
|
#repo_lock <repo-name> <arch> [timeout]
|
2020-09-01 21:37:28 +02:00
|
|
|
repo_lock() {
|
|
|
|
local repo base=${1}; shift
|
|
|
|
for repo in ${base} ${base}-debug; do
|
|
|
|
_repo_lock ${repo} "${@}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_repo_lock () {
|
2010-08-08 15:03:27 +02:00
|
|
|
local LOCKDIR="$TMPDIR/.repolock.$1.$2"
|
2011-03-26 14:13:57 +01:00
|
|
|
local DBLOCKFILE="${FTP_BASE}/${1}/os/${2}/${1}${DBEXT}.lck"
|
2010-03-02 04:44:08 +01:00
|
|
|
local _count
|
|
|
|
local _trial
|
|
|
|
local _timeout
|
|
|
|
local _lockblock
|
|
|
|
local _owner
|
|
|
|
|
2010-12-09 06:52:34 +01:00
|
|
|
# This is the lock file used by repo-add and repo-remove
|
2018-02-13 02:50:57 +01:00
|
|
|
if [[ -f ${DBLOCKFILE} ]]; then
|
2018-03-16 02:47:58 +01:00
|
|
|
error "Repo [%s] (%s) is already locked by repo-{add,remove} process %s" "$1" "$2" "$(cat "$DBLOCKFILE")"
|
2011-03-26 14:13:57 +01:00
|
|
|
return 1
|
|
|
|
fi
|
2010-12-09 06:52:34 +01:00
|
|
|
|
2018-02-13 02:50:57 +01:00
|
|
|
if (( $# == 2 )); then
|
2010-08-08 15:16:55 +02:00
|
|
|
_lockblock=true
|
|
|
|
_trial=0
|
2018-02-13 02:50:57 +01:00
|
|
|
elif (( $# == 3 )); then
|
2010-08-08 15:16:55 +02:00
|
|
|
_lockblock=false
|
|
|
|
_timeout=$3
|
|
|
|
let _trial=$_timeout/$LOCK_DELAY
|
2008-09-02 07:01:03 +02:00
|
|
|
fi
|
2010-03-02 04:44:08 +01:00
|
|
|
|
|
|
|
_count=0
|
2018-03-14 21:52:05 +01:00
|
|
|
while (( _count <= _trial )) || [[ $_lockblock = true ]]; do
|
2010-08-08 15:16:55 +02:00
|
|
|
if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then
|
2018-03-16 02:47:58 +01:00
|
|
|
_owner="$(/usr/bin/stat -c %U "$LOCKDIR")"
|
2018-02-12 23:53:10 +01:00
|
|
|
warning "Repo [%s] (%s) is already locked by %s." "$1" "$2" "$_owner"
|
|
|
|
msg2 "Retrying in %s seconds..." "$LOCK_DELAY"
|
2010-08-08 15:16:55 +02:00
|
|
|
else
|
2018-02-13 02:39:30 +01:00
|
|
|
LOCKS+=("$1.$2")
|
2010-08-08 15:16:55 +02:00
|
|
|
set_umask
|
|
|
|
return 0
|
|
|
|
fi
|
2018-03-16 02:47:58 +01:00
|
|
|
sleep "$LOCK_DELAY"
|
2010-08-08 15:16:55 +02:00
|
|
|
let _count=$_count+1
|
2010-03-02 04:44:08 +01:00
|
|
|
done
|
2010-04-11 13:52:32 +02:00
|
|
|
|
2018-02-12 23:53:10 +01:00
|
|
|
error "Repo [%s] (%s) is already locked by %s. Giving up!" "$1" "$2" "$_owner"
|
2010-04-11 13:52:32 +02:00
|
|
|
return 1
|
2008-09-02 07:01:03 +02:00
|
|
|
}
|
|
|
|
|
2020-09-01 21:37:28 +02:00
|
|
|
#repo_unlock <repo-name> <arch>
|
|
|
|
repo_unlock () {
|
|
|
|
local repo base=${1}; shift
|
|
|
|
for repo in ${base} ${base}-debug; do
|
|
|
|
_repo_unlock ${repo} "${@}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_repo_unlock () {
|
2010-08-08 15:03:27 +02:00
|
|
|
local LOCKDIR="$TMPDIR/.repolock.$1.$2"
|
2018-02-13 02:50:57 +01:00
|
|
|
if [[ ! -d $LOCKDIR ]]; then
|
2018-02-12 23:53:10 +01:00
|
|
|
warning "Repo lock [%s] (%s) was not locked!" "$1" "$2"
|
2010-04-11 13:52:32 +02:00
|
|
|
restore_umask
|
|
|
|
return 1
|
2008-09-02 07:01:03 +02:00
|
|
|
else
|
2010-03-02 04:44:08 +01:00
|
|
|
rmdir "$LOCKDIR"
|
2010-04-11 13:52:32 +02:00
|
|
|
restore_umask
|
|
|
|
return 0
|
2008-09-02 07:01:03 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-11-22 21:44:42 +01:00
|
|
|
# usage: _grep_all_info pkgfile infofile key
|
|
|
|
_grep_all_info() {
|
|
|
|
local _ret=()
|
|
|
|
|
|
|
|
mapfile -t _ret < <(/usr/bin/bsdtar -xOqf "$1" "${2}" | grep "^${3} = ")
|
|
|
|
|
|
|
|
printf '%s\n' "${_ret[@]#${3} = }"
|
|
|
|
}
|
|
|
|
|
2009-07-14 23:49:29 +02:00
|
|
|
# usage: _grep_pkginfo pkgfile pattern
|
|
|
|
_grep_pkginfo() {
|
2018-11-22 21:44:42 +01:00
|
|
|
_grep_all_info "${1}" .PKGINFO "${2}" | tail -1
|
2009-07-14 23:49:29 +02:00
|
|
|
}
|
|
|
|
|
2016-02-08 14:26:23 +01:00
|
|
|
# usage: _grep_buildinfo pkgfile pattern
|
|
|
|
_grep_buildinfo() {
|
2018-11-22 21:44:42 +01:00
|
|
|
_grep_all_info "${1}" .BUILDINFO "${2}" | tail -1
|
2016-02-08 14:26:23 +01:00
|
|
|
}
|
2009-07-14 23:49:29 +02:00
|
|
|
|
2009-07-21 00:22:00 +02:00
|
|
|
# Get the package base or name as fallback
|
2009-07-09 17:24:15 +02:00
|
|
|
getpkgbase() {
|
|
|
|
local _base
|
|
|
|
|
2010-09-12 19:20:01 +02:00
|
|
|
_base="$(_grep_pkginfo "$1" "pkgbase")"
|
2018-02-13 02:50:57 +01:00
|
|
|
if [[ -z $_base ]]; then
|
2009-07-21 00:25:05 +02:00
|
|
|
getpkgname "$1"
|
2010-12-02 18:06:45 +01:00
|
|
|
else
|
|
|
|
echo "$_base"
|
2009-07-09 17:24:15 +02:00
|
|
|
fi
|
2010-12-02 18:06:45 +01:00
|
|
|
}
|
2009-07-09 17:24:15 +02:00
|
|
|
|
|
|
|
# Get the package name
|
2008-09-02 07:01:03 +02:00
|
|
|
getpkgname() {
|
2009-07-09 17:24:15 +02:00
|
|
|
local _name
|
2008-09-02 07:01:03 +02:00
|
|
|
|
2010-09-12 19:20:01 +02:00
|
|
|
_name="$(_grep_pkginfo "$1" "pkgname")"
|
2018-02-13 02:50:57 +01:00
|
|
|
if [[ -z $_name ]]; then
|
2018-02-12 23:53:10 +01:00
|
|
|
error "Package '%s' has no pkgname in the PKGINFO. Fail!" "$1"
|
2009-07-09 17:24:15 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$_name"
|
2008-09-02 07:01:03 +02:00
|
|
|
}
|
|
|
|
|
2009-02-13 21:09:46 +01:00
|
|
|
# Get the pkgver-pkgrel of this package
|
|
|
|
getpkgver() {
|
2009-07-09 17:24:15 +02:00
|
|
|
local _ver
|
|
|
|
|
2010-09-12 19:20:01 +02:00
|
|
|
_ver="$(_grep_pkginfo "$1" "pkgver")"
|
2018-02-13 02:50:57 +01:00
|
|
|
if [[ -z $_ver ]]; then
|
2018-02-12 23:53:10 +01:00
|
|
|
error "Package '%s' has no pkgver in the PKGINFO. Fail!" "$1"
|
2009-07-09 17:24:15 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2009-02-13 21:09:46 +01:00
|
|
|
|
2009-07-09 17:24:15 +02:00
|
|
|
echo "$_ver"
|
2009-02-13 21:09:46 +01:00
|
|
|
}
|
|
|
|
|
2010-08-14 20:15:50 +02:00
|
|
|
getpkgarch() {
|
|
|
|
local _ver
|
|
|
|
|
2010-09-12 19:20:01 +02:00
|
|
|
_ver="$(_grep_pkginfo "$1" "arch")"
|
2018-02-13 02:50:57 +01:00
|
|
|
if [[ -z $_ver ]]; then
|
2018-02-12 23:53:10 +01:00
|
|
|
error "Package '%s' has no arch in the PKGINFO. Fail!" "$1"
|
2010-08-14 20:15:50 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$_ver"
|
|
|
|
}
|
|
|
|
|
2021-12-16 19:25:57 +01:00
|
|
|
getpkgdesc() {
|
|
|
|
local _desc
|
|
|
|
|
|
|
|
_desc="$(_grep_pkginfo "$1" "pkgdesc")"
|
|
|
|
if [[ -z $_desc ]]; then
|
|
|
|
error "Package '%s' has no pkgdesc in the PKGINFO. Fail!" "$1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$_desc"
|
|
|
|
}
|
|
|
|
|
|
|
|
# TODO: We need to not depend on pkgdesc
|
|
|
|
# here be dragons
|
2020-06-14 21:59:52 +02:00
|
|
|
is_debug_package() {
|
|
|
|
local pkgfile=${1}
|
|
|
|
local pkgbase="$(getpkgbase "${pkgfile}")"
|
|
|
|
local pkgname="$(getpkgname "${pkgfile}")"
|
2021-12-16 19:25:57 +01:00
|
|
|
local pkgdesc="$(getpkgdesc "${pkgfile}")"
|
2020-06-14 21:59:52 +02:00
|
|
|
|
2021-12-16 19:25:57 +01:00
|
|
|
[[ ${pkgdesc} == "Detached debugging symbols for "* && ${pkgbase}-debug = ${pkgname} ]]
|
2020-06-14 21:59:52 +02:00
|
|
|
}
|
|
|
|
|
2014-09-10 01:04:25 +02:00
|
|
|
check_packager() {
|
|
|
|
local _packager
|
|
|
|
|
|
|
|
_packager=$(_grep_pkginfo "$1" "packager")
|
2018-02-13 02:50:57 +01:00
|
|
|
[[ -n $_packager && $_packager != 'Unknown Packager' ]]
|
2014-09-10 01:04:25 +02:00
|
|
|
}
|
|
|
|
|
2016-02-08 14:26:23 +01:00
|
|
|
check_buildinfo() {
|
2019-10-18 00:34:24 +02:00
|
|
|
/usr/bin/bsdtar -tqf "$1" .BUILDINFO >/dev/null 2>&1
|
2016-02-08 14:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
check_builddir() {
|
|
|
|
local _builddir
|
|
|
|
|
|
|
|
_builddir=$(_grep_buildinfo "$1" "builddir")
|
2018-02-13 02:50:57 +01:00
|
|
|
[[ -n $_builddir && $_builddir = '/build' ]]
|
2016-02-08 14:26:23 +01:00
|
|
|
}
|
|
|
|
|
2021-12-16 19:06:48 +01:00
|
|
|
# Non fatal getpkgfile expanding globs
|
|
|
|
maybe_getpkgfile() {
|
|
|
|
if (( $# != 1 )); then
|
|
|
|
exit 1
|
|
|
|
elif [[ ! -f ${1} ]]; then
|
|
|
|
exit 1
|
|
|
|
elif [[ ! -f ${1}.sig ]]; then
|
|
|
|
error "Package signature %s not found!" "$1.sig"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "${1}"
|
|
|
|
}
|
|
|
|
|
2010-02-21 16:54:10 +01:00
|
|
|
getpkgfile() {
|
2018-02-13 02:50:57 +01:00
|
|
|
if (( $# != 1 )); then
|
2010-08-13 09:47:31 +02:00
|
|
|
error 'No canonical package found!'
|
2010-02-21 16:54:10 +01:00
|
|
|
exit 1
|
2018-02-13 02:50:57 +01:00
|
|
|
elif [[ ! -f ${1} ]]; then
|
2018-02-12 23:53:10 +01:00
|
|
|
error "Package %s not found!" "$1"
|
2010-02-21 16:54:10 +01:00
|
|
|
exit 1
|
2018-02-13 02:50:57 +01:00
|
|
|
elif [[ ! -f ${1}.sig ]]; then
|
2014-06-19 02:33:06 +02:00
|
|
|
error "Package signature %s not found!" "$1.sig"
|
2011-04-02 13:19:05 +02:00
|
|
|
exit 1
|
2010-02-21 16:54:10 +01:00
|
|
|
fi
|
|
|
|
|
2018-03-16 02:47:58 +01:00
|
|
|
echo "${1}"
|
2010-02-21 16:54:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getpkgfiles() {
|
2018-02-13 02:50:57 +01:00
|
|
|
local f files
|
2014-06-18 18:07:09 +02:00
|
|
|
if ! printf '%s\n' "${@%\.*}" | awk 'a[$0]++{exit 1}'; then
|
2010-08-13 09:47:31 +02:00
|
|
|
error 'Duplicate packages found!'
|
2010-02-21 16:54:10 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-02-13 02:53:06 +01:00
|
|
|
for f in "$@"; do
|
|
|
|
files+=("$(getpkgfile "$f")") || exit 1
|
2010-02-21 16:54:10 +01:00
|
|
|
done
|
|
|
|
|
2018-03-16 02:47:58 +01:00
|
|
|
echo "${files[@]}"
|
2010-02-21 16:54:10 +01:00
|
|
|
}
|
|
|
|
|
2010-08-14 20:15:50 +02:00
|
|
|
check_pkgfile() {
|
|
|
|
local pkgfile=$1
|
2008-09-14 00:49:59 +02:00
|
|
|
|
2018-03-16 02:47:58 +01:00
|
|
|
local pkgname="$(getpkgname "${pkgfile}")" || return 1
|
|
|
|
local pkgver="$(getpkgver "${pkgfile}")" || return 1
|
|
|
|
local pkgarch="$(getpkgarch "${pkgfile}")" || return 1
|
2010-08-14 20:15:50 +02:00
|
|
|
|
2018-03-16 02:47:58 +01:00
|
|
|
in_array "${pkgarch}" "${ARCHES[@]}" 'any' || return 1
|
2010-08-14 22:38:52 +02:00
|
|
|
|
2018-03-16 02:47:58 +01:00
|
|
|
[[ ${pkgfile##*/} = "${pkgname}-${pkgver}-${pkgarch}"* ]]
|
2010-08-14 20:15:50 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 21:11:15 +02:00
|
|
|
# Check that the package file is consistent with the PKGBUILD in version control
|
|
|
|
check_pkgvcs() {
|
2010-08-14 20:15:50 +02:00
|
|
|
local pkgfile="${1}"
|
2018-06-26 21:11:15 +02:00
|
|
|
local repo="${2}"
|
2018-03-16 02:47:58 +01:00
|
|
|
local _pkgbase="$(getpkgbase "${pkgfile}")" || return 1
|
|
|
|
local _pkgname="$(getpkgname "${pkgfile}")" || return 1
|
|
|
|
local _pkgver="$(getpkgver "${pkgfile}")" || return 1
|
|
|
|
local _pkgarch="$(getpkgarch "${pkgfile}")" || return 1
|
2010-08-14 20:15:50 +02:00
|
|
|
|
2018-03-16 02:47:58 +01:00
|
|
|
in_array "${repo}" "${PKGREPOS[@]}" || return 1
|
2010-08-14 22:38:52 +02:00
|
|
|
|
2018-06-26 21:11:15 +02:00
|
|
|
local vcsver vcsnames=()
|
|
|
|
read -rd'\n' vcsver vcsnames < <(source_pkgbuild "${_pkgbase}" "repos/${repo}-${_pkgarch}"; \
|
|
|
|
get_full_version; echo "${pkgname[@]}")
|
|
|
|
read -ra vcsnames <<<"${vcsnames}"
|
2010-08-14 20:15:50 +02:00
|
|
|
|
2018-06-26 21:11:15 +02:00
|
|
|
[[ "${vcsver}" = "${_pkgver}" ]] || return 1
|
2020-06-14 21:59:52 +02:00
|
|
|
in_array "${_pkgname}" "${vcsnames[@]}" "${_pkgbase}-debug" || return 1
|
2010-09-12 12:47:34 +02:00
|
|
|
|
|
|
|
return 0
|
2008-09-14 00:49:59 +02:00
|
|
|
}
|
|
|
|
|
2010-12-02 18:06:45 +01:00
|
|
|
check_splitpkgs() {
|
|
|
|
local repo="${1}"
|
|
|
|
shift
|
2018-03-16 02:47:58 +01:00
|
|
|
local pkgfiles=("${@}")
|
2010-12-02 18:06:45 +01:00
|
|
|
local pkgfile
|
|
|
|
local pkgdir
|
2018-06-26 21:11:15 +02:00
|
|
|
local vcsname
|
2010-12-02 18:06:45 +01:00
|
|
|
|
|
|
|
mkdir -p "${WORKDIR}/check_splitpkgs/"
|
|
|
|
pushd "${WORKDIR}/check_splitpkgs" >/dev/null
|
|
|
|
|
2018-03-16 02:47:58 +01:00
|
|
|
for pkgfile in "${pkgfiles[@]}"; do
|
|
|
|
local _pkgbase="$(getpkgbase "${pkgfile}")"
|
|
|
|
local _pkgname="$(getpkgname "${pkgfile}")"
|
|
|
|
local _pkgarch="$(getpkgarch "${pkgfile}")"
|
2020-06-05 05:15:37 +02:00
|
|
|
local vcsnames=($(source_pkgbuild "${_pkgbase}" "repos/${repo}-${_pkgarch}"; echo "${pkgname[@]}"))
|
|
|
|
|
|
|
|
# not a split package
|
|
|
|
(( ${#vcsnames[@]} > 1 )) || continue
|
2020-06-14 21:59:52 +02:00
|
|
|
[[ ${_pkgbase}-debug = ${_pkgname} ]] && continue
|
2020-06-05 05:15:37 +02:00
|
|
|
|
2010-12-02 18:06:45 +01:00
|
|
|
mkdir -p "${repo}/${_pkgarch}/${_pkgbase}"
|
|
|
|
echo "${_pkgname}" >> "${repo}/${_pkgarch}/${_pkgbase}/staging"
|
2018-06-26 21:11:15 +02:00
|
|
|
printf '%s\n' "${vcsnames[@]}" >> "${repo}/${_pkgarch}/${_pkgbase}/vcs"
|
2010-12-02 18:06:45 +01:00
|
|
|
done
|
|
|
|
popd >/dev/null
|
|
|
|
|
|
|
|
for pkgdir in "${WORKDIR}/check_splitpkgs/${repo}"/*/*; do
|
2018-02-13 02:50:57 +01:00
|
|
|
[[ ! -d ${pkgdir} ]] && continue
|
2010-12-02 18:06:45 +01:00
|
|
|
sort -u "${pkgdir}/staging" -o "${pkgdir}/staging"
|
2018-06-26 21:11:15 +02:00
|
|
|
sort -u "${pkgdir}/vcs" -o "${pkgdir}/vcs"
|
|
|
|
if [[ ! -z "$(comm -13 "${pkgdir}/staging" "${pkgdir}/vcs")" ]]; then
|
2010-12-02 18:06:45 +01:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2010-09-05 13:32:27 +02:00
|
|
|
check_pkgrepos() {
|
|
|
|
local pkgfile=$1
|
|
|
|
|
2018-03-16 02:47:58 +01:00
|
|
|
local pkgname="$(getpkgname "${pkgfile}")" || return 1
|
|
|
|
local pkgver="$(getpkgver "${pkgfile}")" || return 1
|
|
|
|
local pkgarch="$(getpkgarch "${pkgfile}")" || return 1
|
2010-09-05 13:32:27 +02:00
|
|
|
|
Globally set $PKGEXT to a bash extended glob representing valid choices.
The current glob `*.pkg.tar.?z` is both less restrictive and more
restrictive than makepkg, as it accepts any valid unicode character.
To be more exact, it's almost completely orthogonal to the one in makepkg.
makepkg only accepts .tar.gz, .tar.bz2, .tar.xz, .tar.lzo, .tar.lrz, and
.tar.Z and most of those fail to match against a two-char compression type.
dbscripts accepts .pkg.tar.💩z which incidentally is what I think of
cherry-picking xz and gz as supported methods.
Since this can be anything makepkg.conf accepts, it needs to be able to
match all that, unless we decide to perform additional restrictions in
which case we should still explicitly list each allowed extension. Using
bash extended globbing allows us to do this relatively painlessly.
Document the fact that this has *always* been some sort of glob, and
update the two cases where this was (not!) being evaluated by bash
[[ ... ]], to use a not-elegant-at-all proxy function is_globfile() to
evaluate globs *before* testing if they exist.
2018-02-16 04:34:36 +01:00
|
|
|
is_globfile "${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXTS} && return 1
|
|
|
|
is_globfile "${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXTS}.sig && return 1
|
2018-02-13 02:50:57 +01:00
|
|
|
[[ -f ${FTP_BASE}/${PKGPOOL}/${pkgfile##*/} ]] && return 1
|
|
|
|
[[ -f ${FTP_BASE}/${PKGPOOL}/${pkgfile##*/}.sig ]] && return 1
|
2010-09-05 13:32:27 +02:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2018-12-02 17:28:20 +01:00
|
|
|
check_stagingrepos() {
|
|
|
|
local pkgfile=${1}
|
|
|
|
local pkgrepo=${2}
|
2019-01-13 21:00:44 +01:00
|
|
|
local pkgbase=$(getpkgbase "${pkgfile}")
|
2018-12-02 17:28:20 +01:00
|
|
|
local pkgname=$(getpkgname "${pkgfile}")
|
|
|
|
local pkgarch=$(getpkgarch "${pkgfile}")
|
|
|
|
local candidate candidates=()
|
|
|
|
|
|
|
|
if in_array "${pkgrepo}" "${STABLE_REPOS[@]}"; then
|
2019-01-13 21:00:44 +01:00
|
|
|
candidates+=($(find_repo_for_package "${pkgbase}" "${pkgarch}" "${TESTING_REPOS[@]}"))
|
2018-12-02 17:28:20 +01:00
|
|
|
fi
|
|
|
|
if in_array "${pkgrepo}" "${STABLE_REPOS[@]}" "${TESTING_REPOS[@]}"; then
|
2019-01-13 21:00:44 +01:00
|
|
|
candidates+=($(find_repo_for_package "${pkgbase}" "${pkgarch}" "${STAGING_REPOS[@]}"))
|
2018-12-02 17:28:20 +01:00
|
|
|
fi
|
|
|
|
(( ${#candidates[@]} == 0 )) && return 0
|
|
|
|
|
|
|
|
printf '%s\n' "${candidates[@]%-*}"
|
|
|
|
for candidate in "${candidates[@]}"; do
|
|
|
|
for candidate in "${STAGING}/${candidate%-*}"/*${PKGEXTS}; do
|
|
|
|
[[ ${pkgname} = $(getpkgname "${candidate}" 2>/dev/null) ]] && return 0
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2009-10-14 21:18:07 +02:00
|
|
|
#usage: chk_license ${license[@]}"
|
|
|
|
chk_license() {
|
2010-08-08 15:16:55 +02:00
|
|
|
local l
|
2018-02-12 23:53:10 +01:00
|
|
|
for l in "${@}"; do
|
2018-03-16 02:47:58 +01:00
|
|
|
in_array "${l}" "${ALLOWED_LICENSES[@]}" && return 0
|
2010-08-08 15:16:55 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
2009-10-14 21:18:07 +02:00
|
|
|
}
|
|
|
|
|
2021-10-01 20:49:53 +02:00
|
|
|
check_repo_configured() {
|
|
|
|
local repo=$1
|
|
|
|
|
|
|
|
local count=$(printf '%s\n' "${PKGREPOS[@]}" | grep --count --line-regexp "$repo")
|
|
|
|
[[ $count -gt 0 ]] && return 0
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2010-08-13 08:20:27 +02:00
|
|
|
check_repo_permission() {
|
|
|
|
local repo=$1
|
|
|
|
|
2018-02-13 02:50:57 +01:00
|
|
|
(( ${#PKGREPOS[@]} == 0 )) && return 1
|
|
|
|
[[ -z "${PKGPOOL}" ]] && return 1
|
2010-09-11 22:52:23 +02:00
|
|
|
|
2021-03-30 20:33:11 +02:00
|
|
|
in_array "${repo}" "${PKGREPOS[@]}" "${DEBUGREPOS[@]}" || return 1
|
2010-08-13 08:20:27 +02:00
|
|
|
|
2018-02-13 02:50:57 +01:00
|
|
|
[[ -w $FTP_BASE/${PKGPOOL} ]] || return 1
|
2010-08-13 08:20:27 +02:00
|
|
|
|
|
|
|
local arch
|
2018-03-16 02:47:58 +01:00
|
|
|
for arch in "${ARCHES[@]}"; do
|
2010-09-11 19:54:00 +02:00
|
|
|
local dir="${FTP_BASE}/${repo}/os/${arch}/"
|
2018-02-13 02:50:57 +01:00
|
|
|
[[ -w ${dir} ]] || return 1
|
|
|
|
[[ -f ${dir}${repo}${DBEXT} && ! -w ${dir}${repo}${DBEXT} ]] && return 1
|
|
|
|
[[ -f ${dir}${repo}${FILESEXT} && ! -w ${dir}${repo}${FILESEXT} ]] && return 1
|
2010-08-13 08:20:27 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
2010-09-02 14:50:04 +02:00
|
|
|
|
|
|
|
set_repo_permission() {
|
|
|
|
local repo=$1
|
|
|
|
local arch=$2
|
|
|
|
local dbfile="${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}"
|
2011-03-26 14:13:57 +01:00
|
|
|
local filesfile="${FTP_BASE}/${repo}/os/${arch}/${repo}${FILESEXT}"
|
2010-09-02 14:50:04 +02:00
|
|
|
|
2018-02-13 02:50:57 +01:00
|
|
|
if [[ -w ${dbfile} ]]; then
|
2010-09-02 14:50:04 +02:00
|
|
|
local group=$(/usr/bin/stat --printf='%G' "$(dirname "${dbfile}")")
|
2014-06-18 18:07:09 +02:00
|
|
|
chgrp "$group" "${dbfile}" || error "Could not change group of %s to %s" "$dbfile" "$group"
|
|
|
|
chgrp "$group" "${filesfile}" || error "Could not change group of %s to %s" "$filesfile" "$group"
|
|
|
|
chmod g+w "${dbfile}" || error "Could not set write permission for group %s to %s" "$group" "$dbfile"
|
2018-02-12 23:53:10 +01:00
|
|
|
chmod g+w "${filesfile}" || error "Could not set write permission for group %s to %s" "$group" "$filesfile"
|
2010-09-02 14:50:04 +02:00
|
|
|
else
|
2018-02-12 23:53:10 +01:00
|
|
|
error "You don't have permission to change %s" "$dbfile"
|
2010-09-02 14:50:04 +02:00
|
|
|
fi
|
|
|
|
}
|
2011-01-15 01:12:09 +01:00
|
|
|
|
2018-02-26 23:57:31 +01:00
|
|
|
arch_repo_modify() {
|
|
|
|
local action=$1
|
|
|
|
local repo=$2
|
|
|
|
local arch=$3
|
|
|
|
local pkgs=("${@:4}")
|
2011-01-15 01:12:09 +01:00
|
|
|
local dbfile="${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}"
|
|
|
|
|
2018-02-26 23:57:31 +01:00
|
|
|
if [[ ${action} = remove && ! -f ${dbfile} ]]; then
|
2018-02-12 23:53:10 +01:00
|
|
|
error "No database found at '%s'" "$dbfile"
|
2011-01-15 01:12:09 +01:00
|
|
|
return 1
|
|
|
|
fi
|
2018-02-26 23:57:31 +01:00
|
|
|
|
|
|
|
# package files for repo-add might be relative to repo dir
|
|
|
|
pushd "${dbfile%/*}" >/dev/null
|
2018-03-16 02:47:58 +01:00
|
|
|
/usr/bin/"repo-${action}" -q "${dbfile}" "${pkgs[@]}" \
|
2014-06-19 02:33:06 +02:00
|
|
|
|| error '%s' "repo-${action} ${dbfile@Q} ${pkgs[*]@Q}"
|
2011-01-15 01:12:09 +01:00
|
|
|
set_repo_permission "${repo}" "${arch}"
|
2018-02-26 23:57:31 +01:00
|
|
|
popd >/dev/null
|
2013-01-23 23:03:35 +01:00
|
|
|
|
|
|
|
REPO_MODIFIED=1
|
2011-01-15 01:12:09 +01:00
|
|
|
}
|
2012-10-27 14:32:39 +02:00
|
|
|
|
2018-11-22 21:44:42 +01:00
|
|
|
# Verify the existence of dependent packages needed by a given pkgfile
|
|
|
|
# usage: check_reproducible pkgfile
|
|
|
|
check_reproducible() {
|
|
|
|
local pkg dir pkgs=() pkgfile pkgfiles=()
|
|
|
|
|
|
|
|
mapfile -t pkgs < <(_grep_all_info "${1}" .BUILDINFO installed)
|
|
|
|
|
|
|
|
for pkg in "${pkgs[@]}"; do
|
|
|
|
local pkgname=${pkg%-*-*-*}
|
2019-07-13 20:58:07 +02:00
|
|
|
for dir in "${FTP_BASE}"/pool/* "${ARCHIVE_BASE}/packages/${pkgname:0:1}/${pkgname}" "${STAGING}"/**/; do
|
2018-11-22 21:44:42 +01:00
|
|
|
if pkgfile="$(getpkgfile "${dir}/${pkg}"${PKGEXTS} 2>/dev/null)"; then
|
|
|
|
pkgfiles+=("${pkgfile}")
|
|
|
|
continue 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
error "could not find existing or staged package for dependency %s" "${pkg}"
|
|
|
|
return 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2018-06-26 21:11:15 +02:00
|
|
|
. "$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")/db-functions-${VCS}"
|