summaryrefslogtreecommitdiff
path: root/db
blob: 372956bd5af1db4c4d63b3bd5d9077cb55e015df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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