summaryrefslogtreecommitdiff
path: root/db-functions
diff options
context:
space:
mode:
Diffstat (limited to 'db-functions')
-rw-r--r--db-functions158
1 files changed, 34 insertions, 124 deletions
diff --git a/db-functions b/db-functions
index 51fc1bd..6bab5a0 100644
--- a/db-functions
+++ b/db-functions
@@ -1,7 +1,7 @@
#!/bin/bash
# Some PKGBUILDs need CARCH to be set
-CARCH="x86_64"
+CARCH=$(. "$(librelib conf.sh)"; load_files makepkg; echo "$CARCH")
# Useful functions
UMASK=""
@@ -27,71 +27,14 @@ mv_acl() {
# set up general environment
WORKDIR=$(mktemp -dt "${0##*/}.XXXXXXXXXX")
LOCKS=()
+REPO_MODIFIED=0
-# check if messages are to be printed using color
-unset ALL_OFF BOLD BLUE GREEN RED YELLOW
-if [[ -t 2 ]]; then
- ALL_OFF="$(tput sgr0)"
- BOLD="$(tput bold)"
- BLUE="${BOLD}$(tput setaf 4)"
- GREEN="${BOLD}$(tput setaf 2)"
- RED="${BOLD}$(tput setaf 1)"
- YELLOW="${BOLD}$(tput setaf 3)"
-fi
-readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
-
-plain() {
- local mesg=$1; shift
- printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@"
-}
-
-msg() {
- local mesg=$1; shift
- printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@"
-}
-
-msg2() {
- local mesg=$1; shift
- printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@"
-}
-
-warning() {
- local mesg=$1; shift
- printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-error() {
- local mesg=$1; shift
- printf "${RED}==> ERROR${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-##
-# usage : in_array( $needle, $haystack )
-# return : 0 - found
-# 1 - not found
-##
-in_array() {
- local needle=$1; shift
- [[ -z $1 ]] && return 1 # Not Found
- local item
- for item in "$@"; do
- [[ $item = "$needle" ]] && return 0 # Found
- done
- return 1 # Not Found
-}
-
-##
-# usage : get_full_version( $epoch, $pkgver, $pkgrel )
-# return : full version spec, including epoch (if necessary), pkgver, pkgrel
-##
-get_full_version() {
- if [[ $1 -eq 0 ]]; then
- # zero epoch case, don't include it in version
- echo "$2-$3"
- else
- echo "$1:$2-$3"
- fi
-}
+# Used: plain, msg, msg2, warning, error, in_array, get_full_version, abort, die
+# Overwritten: cleanup
+# Ignored: stat_busy, stat_done,
+# setup_workdir, trab_abort, trap_exit,
+# lock, slock, lock_close
+. $(librelib common)
script_lock() {
local LOCKDIR="$TMPDIR/.scriptlock.${0##*/}"
@@ -137,17 +80,12 @@ cleanup() {
script_unlock
fi
rm -rf "$WORKDIR"
- [ "$1" ] && exit "$1"
-}
-abort() {
- msg 'Aborting...'
- cleanup 0
-}
+ if (( REPO_MODIFIED )); then
+ date +%s > "${FTP_BASE}/lastupdate"
+ fi
-die() {
- error "$@"
- cleanup 1
+ [ "$1" ] && exit "$1"
}
trap abort INT QUIT TERM HUP
@@ -171,7 +109,7 @@ repo_lock () {
return 1
fi
if [ -f "${FILESLOCKFILE}" ]; then
- error "Repo [%s] (%s) is already locked by repo-{add,remove} process %s" "$2" "$2" "$(<"$FILESLOCKFILE")"
+ error "Repo [%s] (%s) is already locked by repo-{add,remove} process %s" "$1" "$2" "$(<"$FILESLOCKFILE")"
return 1
fi
@@ -188,7 +126,7 @@ repo_lock () {
while [ "$_count" -le "$_trial" ] || "$_lockblock" ; do
if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then
_owner="$(/usr/bin/stat -c %U "$LOCKDIR")"
- warning "Repo [%s] (%s) is already locked by %s." "$1" "$2" "$_owner"
+ warning "Repo [%s] (%s) is already locked by %s." "${1}" "${2}" "$_owner"
msg2 "Retrying in %d seconds..." "$LOCK_DELAY"
else
LOCKS+=("$1.$2")
@@ -298,7 +236,7 @@ getpkgfile() {
exit 1
fi
- echo ${1}
+ echo "${1}"
}
getpkgfiles() {
@@ -340,7 +278,7 @@ check_pkgfile() {
fi
}
-check_pkgsvn() {
+check_pkgxbs() {
local pkgfile="${1}"
local _pkgbase="$(getpkgbase "${pkgfile}")"
[ $? -ge 1 ] && return 1
@@ -354,18 +292,11 @@ check_pkgsvn() {
in_array "${repo}" "${PKGREPOS[@]}" || return 1
- if [ ! -f "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}" ]; then
- mkdir -p "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}"
- svn export -q "${SVNREPO}/${_pkgbase}/repos/${repo}-${_pkgarch}/PKGBUILD" \
- "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}" >/dev/null
- [ $? -ge 1 ] && return 1
- fi
+ local xbsver="$(. "$(xbs releasepath "${_pkgbase}" "${repo}" "${_pkgarch}")/PKGBUILD"; get_full_version "${_pkgname}")"
+ [ "${xbsver}" == "${_pkgver}" ] || return 1
- local svnver="$(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; get_full_version "${epoch:-0}" "${pkgver}" "${pkgrel}")"
- [ "${svnver}" == "${_pkgver}" ] || return 1
-
- local svnnames=($(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo "${pkgname[@]}"))
- in_array "${_pkgname}" "${svnnames[@]}" || return 1
+ local xbsnames=($(. "$(xbs releasepath "${_pkgbase}" "${repo}" "${_pkgarch}")/PKGBUILD"; echo "${pkgname[@]}"))
+ in_array "${_pkgname}" "${xbsnames[@]}" || return 1
return 0
}
@@ -376,7 +307,7 @@ check_splitpkgs() {
local pkgfiles=("${@}")
local pkgfile
local pkgdir
- local svnname
+ local xbsname
mkdir -p "${WORKDIR}/check_splitpkgs/"
pushd "${WORKDIR}/check_splitpkgs" >/dev/null
@@ -390,22 +321,8 @@ check_splitpkgs() {
mkdir -p "${repo}/${_pkgarch}/${_pkgbase}"
echo "${_pkgname}" >> "${repo}/${_pkgarch}/${_pkgbase}/staging"
- if [ ! -f "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}" ]; then
- mkdir -p "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}"
-
- cp -r "${SVNREPO}/$repo/$_pkgbase/PKGBUILD" "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}" >/dev/null 2>&1 || \
- cp -r "${SVNREPO}/libre/$_pkgbase/PKGBUILD" "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}" >/dev/null 2>&1 || \
- cp -r "${SVNREPO}/libre-testing/$_pkgbase/PKGBUILD" "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/$_pkgbase">/dev/null 2>&1
-
- [[ $? -ge 1 ]] && {
- echo "Failed $_pkgbase-$_pkgver-$_pkgarch"
- return 1
- }
- fi
-
- local svnnames=($(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo "${pkgname[@]}"))
- for svnname in "${svnnames[@]}"; do
- echo "${svnname}" >> "${repo}/${_pkgarch}/${_pkgbase}/svn"
+ local xbsnames=($(. "$(xbs releasepath "${_pkgbase}" "${repo}" "${_pkgarch}")/PKGBUILD"; echo "${pkgname[@]}"))
+ printf '%s\n' "${xbsnames[@]}" >> "${repo}/${_pkgarch}/${_pkgbase}/xbs"
done
done
popd >/dev/null
@@ -413,8 +330,8 @@ check_splitpkgs() {
for pkgdir in "${WORKDIR}/check_splitpkgs/${repo}"/*/*; do
[ ! -d "${pkgdir}" ] && continue
sort -u "${pkgdir}/staging" -o "${pkgdir}/staging"
- sort -u "${pkgdir}/svn" -o "${pkgdir}/svn"
- if [ ! -z "$(comm -13 "${pkgdir}/staging" "${pkgdir}/svn")" ]; then
+ sort -u "${pkgdir}/xbs" -o "${pkgdir}/xbs"
+ if [ ! -z "$(comm -13 "${pkgdir}/staging" "${pkgdir}/xbs")" ]; then
return 1
fi
done
@@ -425,11 +342,11 @@ check_splitpkgs() {
check_pkgrepos() {
local pkgfile=$1
- local pkgname="$(getpkgname ${pkgfile})"
+ local pkgname="$(getpkgname "${pkgfile}")"
[ $? -ge 1 ] && return 1
- local pkgver="$(getpkgver ${pkgfile})"
+ local pkgver="$(getpkgver "${pkgfile}")"
[ $? -ge 1 ] && return 1
- local pkgarch="$(getpkgarch ${pkgfile})"
+ local pkgarch="$(getpkgarch "${pkgfile}")"
[ $? -ge 1 ] && return 1
[ -f "${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXT} ] && return 1
@@ -437,17 +354,6 @@ check_pkgrepos() {
[ -f "${FTP_BASE}/${PKGPOOL}/${pkgfile##*/}" ] && return 1
[ -f "${FTP_BASE}/${PKGPOOL}/${pkgfile##*/}.sig" ] && return 1
- local repo
- local arch
- for repo in "${PKGREPOS[@]}"; do
- for arch in "${ARCHES[@]}"; do
- [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXT} ] && return 1
- [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXT}.sig ] && return 1
- [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkgfile##*/}" ] && return 1
- [ -f "${FTP_BASE}/${repo}/os/${arch}/${pkgfile##*/}.sig" ] && return 1
- done
- done
-
return 0
}
@@ -472,7 +378,7 @@ check_repo_permission() {
[ -w "$FTP_BASE/${PKGPOOL}" ] || return 1
local arch
- for arch in ${ARCHES}; do
+ for arch in "${ARCHES[@]}"; do
local dir="${FTP_BASE}/${repo}/os/${arch}/"
[ -w "${dir}" ] || return 1
[ -f "${dir}${repo}"${DBEXT} -a ! -w "${dir}${repo}"${DBEXT} ] && return 1
@@ -490,7 +396,7 @@ set_repo_permission() {
if [ -w "${dbfile}" ]; then
local group=$(/usr/bin/stat --printf='%G' "$(dirname "${dbfile}")")
- chgrp "$group" "${dbfile}" || error "Could not change group of %s to %s" "${dbfile}" "$group"
+ 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}"
chmod g+w "${filesfile}" || error "Could not set write permission for group %s to %s" "$group" "${filesfile}"
@@ -512,6 +418,8 @@ arch_repo_add() {
|| error '%s' "repo-add -f ${repo}${FILESEXT} ${pkgs[*]}"
popd >/dev/null
set_repo_permission "${repo}" "${arch}"
+
+ REPO_MODIFIED=1
}
arch_repo_remove() {
@@ -530,4 +438,6 @@ arch_repo_remove() {
/usr/bin/repo-remove -q "${filesfile}" "${pkgs[@]}" \
|| error '%s' "repo-remove ${filesfile} ${pkgs[*]}"
set_repo_permission "${repo}" "${arch}"
+
+ REPO_MODIFIED=1
}