summaryrefslogtreecommitdiff
path: root/src/bin/db-repo-add
blob: c31fdd947795adda3ba82c0cf670b94205ea9d9f (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
#!/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] <repo> <arch> <pkgfile> ..." "${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