From 3e61a1e9cce6969a351a86a7a057b69d77325ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?coadde=20=5BM=C3=A1rcio=20Alexandre=20Silva=20Delgado=5D?= Date: Wed, 26 Aug 2015 17:59:45 -0300 Subject: port db-repo-add from xbs and fix db-init --- extra/xbs-lukeshu/db-repo-add | 41 ---------------------- src/bin/db-init | 18 ++++++---- src/bin/db-repo-add | 81 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 47 deletions(-) delete mode 100755 extra/xbs-lukeshu/db-repo-add create mode 100755 src/bin/db-repo-add diff --git a/extra/xbs-lukeshu/db-repo-add b/extra/xbs-lukeshu/db-repo-add deleted file mode 100755 index 4611bdf..0000000 --- a/extra/xbs-lukeshu/db-repo-add +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -. "$(dirname "$(readlink -e "$0")")/config" -. "$(dirname "$(readlink -e "$0")")/db-functions" - -if [ $# -lt 3 ]; then - msg "usage: %s ..." "${0##*/}" - exit 1 -fi - -repo="$1" -arch="$2" -pkgfiles=("${@:3}") - -ftppath="$FTP_BASE/$repo/os" - -if ! check_repo_permission "$repo"; then - die "You don't have permission to add packages to %s" "${repo}" -fi - -if [ "$arch" == "any" ]; then - tarches=("${ARCHES[@]}") -else - tarches=("$arch") -fi - -for tarch in "${tarches[@]}"; do - repo_lock "$repo" "$tarch" || exit 1 -done - -for tarch in "${tarches[@]}"; do - for pkgfile in "${pkgfiles[@]}"; do - if [[ ! -f "${FTP_BASE}/${repo}/os/${arch}/${pkgfile##*/}" ]]; then - die "Package file %s not found in %s" "${pkgfile##*/}" "${FTP_BASE}/${repo}/os/${arch}/" - else - msg "Adding %s to [%s]..." "$pkgfile" "$repo" - fi - done - arch_repo_add "${repo}" "${tarch}" "${pkgfiles[@]}" - repo_unlock "$repo" "$tarch" -done diff --git a/src/bin/db-init b/src/bin/db-init index e63bf5a..37ad299 100755 --- a/src/bin/db-init +++ b/src/bin/db-init @@ -3,13 +3,19 @@ CONFIG_DIR="$(dirname "$(readlink -e "$0")")/etc" -source "${CONFIG_DIR}"/dbscripts{.d/{db-functions,main},}.cfg +source "${CONFIG_DIR}/dbscripts.d/db-functions.cfg" +source "${CONFIG_DIR}/dbscripts.d/main.cfg" +source "${CONFIG_DIR}/dbscripts.cfg" -db-init-usage() { - msg "Usage: %s [platform1 platform2 ... platformX]" "${0##*/}" +db-init_usage() { + msg "usage: %s [platform1 platform2 ... platformX]" "${0##*/}" exit 1 } +db-init_run() { + mkdir -p -- "${REPO_DIR}"/{"${PKG_MAIN_POOLS}","${SRC_MAIN_POOLS}"} "${CLEANUP_DESTDIR}" "${SOURCE_CLEANUP_DESTDIR}" "${STAGING}" +} + for 'platform' in "${PLATFORMS[@]}"; do if [ -n $1 ]; then for '_platform' in "$@"; do @@ -19,7 +25,7 @@ for 'platform' in "${PLATFORMS[@]}"; do if [ "${_platform_name}" == "${platform}" ]; then source "${CONFIG_DIR}/dbscripts.d/${_platform_name}.cfg" - mkdir -p -- "${REPO_DIR}"/{"${PKG_MAIN_POOLS}","${SRC_MAIN_POOLS}"} "${CLEANUP_DESTDIR}" "${SOURCE_CLEANUP_DESTDIR}" "${STAGING}" + db-init_run else db-init-usage fi @@ -27,8 +33,8 @@ for 'platform' in "${PLATFORMS[@]}"; do else source "${CONFIG_DIR}/dbscripts.d/${platform}.cfg" - mkdir -p -- "${REPO_DIR}"/{"${PKG_MAIN_POOLS}","${SRC_MAIN_POOLS}"} "${CLEANUP_DESTDIR}" "${SOURCE_CLEANUP_DESTDIR}" "${STAGING}" + db-init_run fi done -# "$(dirname "$(readlink -e "$0")")/db-repo-add" -p "${_platform}" "${PKG_REPOS[@]}" +# "${BIN_DIR}/db-repo-add" -p "${_platform}" "${PKG_REPOS[@]}" diff --git a/src/bin/db-repo-add b/src/bin/db-repo-add new file mode 100755 index 0000000..c31fdd9 --- /dev/null +++ b/src/bin/db-repo-add @@ -0,0 +1,81 @@ +#!/bin/bash + +CONFIG_DIR="$(dirname "$(readlink -e "$0")")/etc" + +source "${CONFIG_DIR}/dbscripts.d/db-functions.cfg" +source "${CONFIG_DIR}/dbscripts.d/main.cfg" +source "${CONFIG_DIR}/dbscripts.cfg" + +db-repo-add_usage() { + "usage: %s [-p platform] ..." "${0##*/}" + exit 1 +} + +db-repo-add_check-repo-permission() { + if ! check_repo_permission "$repo"; then + die "You don't have permission to add packages to %s" "${repo}" + fi +} + +db-repo-add_check-arch-if-any() { + if [ "$arch" == "any" ]; then + tarches=("${ARCHES[@]}") + else + tarches=("$arch") + fi +} + +db-repo-add_exec() { + db-repo-add_check-repo-permission + db-repo-add_check-arch-if-any + for tarch in "${tarches[@]}"; do + repo_lock "$repo" "$tarch" || exit 1 + for pkg_file in "${pkg_files[@]}"; do + if [[ ! -f "${repo_path}/${arch}/${pkg_file##*/}" ]]; then + die "Package file %s not found in %s" "${pkg_file##*/}" "${repo_path}/${arch}/" + else + msg "Adding %s to [%s]..." "$pkg_file" "$repo" + fi + done + arch_repo_add "${repo}" "${tarch}" "${pkg_files[@]}" + repo_unlock "$repo" "$tarch" + done +} + +for 'platform' in "${PLATFORMS[@]}"; do + case "$1" in + --platform|-platform|-p) + if [ $# -lt 5 ]; then + db-repo-add-usage + fi + + # Rename plataform name ($2) to easily script usage + _platform_name="${2/\//+}" _platform_name="${_platform_name,,}" + + if [ "${_platform_name}" == "${platform}" ]; then + source "${CONFIG_DIR}/dbscripts.d/${_platform_name}.cfg" + + repo="$3" + arch="$4" + pkg_files=("${@:3}") + repo_path="${REPO_DIR}/${_platform_name}/${repo}/os" + + db-repo-add_run + fi + ;; + *) + if [ $# -lt 3 ]; then + db-repo-add-usage + fi + + source "${CONFIG_DIR}/dbscripts.d/${platform}.cfg" + + repo="$1" + arch="$2" + pkg_files=("${@:3}") + repo_path="${REPO_DIR}/${platform}/${repo}/os" + + db-repo-add_run + ;; + esac +done -- cgit v1.2.3