summaryrefslogtreecommitdiff
path: root/src/bin/db-pkg-add
diff options
context:
space:
mode:
authorcoadde [Márcio Alexandre Silva Delgado] <coadde@parabola.nu>2015-08-26 18:05:53 -0300
committercoadde [Márcio Alexandre Silva Delgado] <coadde@parabola.nu>2015-08-26 18:05:53 -0300
commitaf870591f68546a1ffd248314b1a01e09d6c1235 (patch)
tree812f4c8e19ae000125e8786b2708ec787a1ac9a0 /src/bin/db-pkg-add
parent3e61a1e9cce6969a351a86a7a057b69d77325ffc (diff)
rename db-repo-add -> db-pkg-add, due it confusing repo with pkg_file
Diffstat (limited to 'src/bin/db-pkg-add')
-rwxr-xr-xsrc/bin/db-pkg-add81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/bin/db-pkg-add b/src/bin/db-pkg-add
new file mode 100755
index 0000000..509161f
--- /dev/null
+++ b/src/bin/db-pkg-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-pkg-add_usage() {
+ "usage: %s [-p platform] <repo> <arch> <pkgfile> ..." "${0##*/}"
+ exit 1
+}
+
+db-pkg-add_check-repo-permission() {
+ if ! check_repo_permission "$repo"; then
+ die "You don't have permission to add packages to %s" "${repo}"
+ fi
+}
+
+db-pkg-add_check-arch-if-any() {
+ if [ "$arch" == "any" ]; then
+ tarches=("${ARCHES[@]}")
+ else
+ tarches=("$arch")
+ fi
+}
+
+db-pkg-add_exec() {
+ db-pkg-add_check-repo-permission
+ db-pkg-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-pkg-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-pkg-add_run
+ fi
+ ;;
+ *)
+ if [ $# -lt 3 ]; then
+ db-pkg-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-pkg-add_run
+ ;;
+ esac
+done