summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcoadde [Márcio Alexandre Silva Delgado] <coadde@parabola.nu>2015-09-24 01:19:59 -0300
committercoadde [Márcio Alexandre Silva Delgado] <coadde@parabola.nu>2015-09-24 01:19:59 -0300
commitc012d95fbdc7a56073e63e4540e46fe6eef7e3ae (patch)
tree4d3989f5e79d0e0576faa7774fcdfc3214119250
parent6afd46394e4c4fdb5b1dacb57ad8a8f4914296a4 (diff)
add initial db scriptcoadde/dbscripts-multidistros
-rw-r--r--db109
1 files changed, 109 insertions, 0 deletions
diff --git a/db b/db
new file mode 100644
index 0000000..372956b
--- /dev/null
+++ b/db
@@ -0,0 +1,109 @@
+#!/bin/bash
+
+# DB script
+# Copyright (C) 2012-2015 Parabola Hackers <https://www.parabola.nu>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+##############################################################
+
+prefix_dir="$(dirname "$(readlink -e "${0}")")"
+bin_dir="${prefix_dir}"
+etc_dir="${prefix_dir}"/etc
+share_dir="${prefix_dir}"/share
+
+##############################################################
+
+source "${etc_dir}/dbscripts.cfg"
+source "${share_dir}/db-libremessages"
+source "${share_dir}/db-functions"
+
+##############################################################
+
+db_error_distro-not-found() {
+ die "This %s distribution doesn't exist" "${distro}"
+}
+
+db_rename-variable_distro-config() {
+ # Rename ("${_distro}") to easily script usage
+ _distro="${_distro/\//+}"
+ _distro="${_distros,,}"
+}
+
+db_source_distro-config() {
+ source "${distro_config}"
+}
+
+db_variable_distro-config() {
+ distro_config="${etc_dir}/dbscripts.d/${_distro}.cfg"
+}
+
+db-add() {
+ db-add_check-permission
+ db-pkg
+ for 'tarch' in "${tarches[@]}"; do
+ 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
+ pkg_repo_add "${repo}" "${tarch}" "${pkg_files[@]}"
+ repo_unlock "${repo}" "${tarch}"
+ done
+}
+
+db-add_check-permission() {
+ if ! check_repo_permission "${repo}"; then
+ die "You don't have permission to add packages to %s" "${repo}"
+ fi
+}
+
+db-init() {
+ mkdir -p -- "${root_dir}"/{"${native_packages_pool}","${native_sources_pool}"} "${cleanup_destination_directory}" "${source_cleanup_destination_directory}" "${staging_directory}"
+}
+
+##############################################################
+
+distributions=("${native_distributions[@]}" "${derivative_distributions[@]}")
+rules="${1}"
+case "${rules}" in
+ add|remove|rm)
+ # Add or remove package to repository defined in config
+
+ if [ "${#}" -lt '4' ]; then
+ msg "usage: %s <add || rm> <distro> <repo> <arch> <pkg_file> ..." "${0##*/}"
+ exit 1
+ }
+ distro="${2}"
+ repo="${3}"
+ arch="${4}"
+ pkg_files=("${@:5}")
+ for '_distro' in "${distributions[@]}"; do
+ db_rename-variable_distro-config
+ db_variable_distro-config
+ if [ -f "${distro_config}" ]; then
+ db_source_distro-config
+ if [ "${rules}" == 'add' ]; then
+ db-add
+ elif [ "${rules}" == 'rm' || "${rules}" == 'remove' ]; then
+ db-rm
+ fi
+ else
+ db_error_distro-not-found
+ fi
+ done
+ ;;
+esac