summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/bin/db-pkg-add99
1 files changed, 41 insertions, 58 deletions
diff --git a/src/bin/db-pkg-add b/src/bin/db-pkg-add
index 37c3887..6b9e154 100755
--- a/src/bin/db-pkg-add
+++ b/src/bin/db-pkg-add
@@ -1,74 +1,57 @@
#!/bin/bash
-CONFIG_DIR="$(dirname "$(readlink -e "$0")")/etc"
+CONFIG_DIR="$(dirname "$(readlink -e "${0}")")/etc"
source "${CONFIG_DIR}/xbs.cfg"
source "${SHARE_DIR}/db-functions"
-db-pkg-add_usage() {
- "usage: %s [-p platform] <repo> <arch> <pkgfile> ..." "${0##*/}"
+if [ "${#}" -lt '4' ]; then
+ "usage: %s <platform> <repo> <arch> <pkgfile> ..." "${0##*/}"
exit 1
-}
+fi
-db-pkg-add_run() {
- 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
- 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-pkg-add-usage
- fi
+plataform="${1}"
+repo="${2}"
+arch="${3}"
+pkg_files=("${@:4}")
- # Rename plataform name ($2) to easily script usage
- _platform_name="${2/\//+}" _platform_name="${_platform_name,,}"
+for '_platform' in "${PLATFORMS[@]}"; do
+ # Rename ("${plataform}") to easily script usage
+ _platform_name="${plataform/\//+}" _platform_name="${_platform_name,,}"
- if [ "${_platform_name}" == "${platform}" ]; then
- source "${CONFIG_DIR}/xbs.d/${_platform_name}.cfg"
+ if [ "${_platform_name}" == "${_platform}" ]; then
+ source "${CONFIG_DIR}/xbs.d/${_platform}.cfg"
- repo="$3"
- arch="$4"
- pkg_files=("${@:3}")
- repo_path="${REPO_DIR}/${_platform_name}/${repo}/os"
+ repo_path="${REPO_DIR}/${_platform}/${repo}/os"
- db-pkg-add_run
- fi
- ;;
- *)
- if [ $# -lt 3 ]; then
- db-pkg-add-usage
+ if ! check_repo_permission "${repo}"; then
+ die "You don't have permission to add packages to %s" "${repo}"
fi
- source "${CONFIG_DIR}/xbs.d/${platform}.cfg"
-
- repo="$1"
- arch="$2"
- pkg_files=("${@:3}")
- repo_path="${REPO_DIR}/${platform}/${repo}/os"
+ if [ "${arch}" == "{any}" ]; then
+ tarches=("${ARCHES[@]}")
+ else
+ tarches=("${arch}")
+ fi
- db-pkg-add_run
- ;;
- esac
+ for 'tarch' in "${tarches[@]}"; do
+ if [[ ! -d "${repo_path} ]]; then
+ die "This ${repo} doesn't exist"
+ elif [[ ! -d "${repo_path}/${tarch}" ]]; then
+ die "This ${repo} doesn't support ${arch} archictecture"
+ fi
+ 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
+ else
+ die "This ${plataform} doesn't exist"
+ fi
done