-
Notifications
You must be signed in to change notification settings - Fork 520
Expand file tree
/
Copy pathinstall_functions
More file actions
53 lines (45 loc) · 1.86 KB
/
Copy pathinstall_functions
File metadata and controls
53 lines (45 loc) · 1.86 KB
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
#
# Generate repo file under /etc/apt/sources.list.d/
#
function apt_add_repo() {
local -r repo_name="$1"
local -r repo_data="$3" # "http(s)://host/path/uri argument0 .. argumentN"
local -r include_src="${4:-yes}"
local -r kr_path="${5:-/usr/share/keyrings/${repo_name}.gpg}"
local -r repo_path="${6:-/etc/apt/sources.list.d/${repo_name}.list}"
echo "deb [signed-by=${kr_path}] ${repo_data}" > "${repo_path}"
if [[ "${include_src}" == "yes" ]] ; then
echo "deb-src [signed-by=${kr_path}] ${repo_data}" >> "${repo_path}"
fi
apt-get update -qq
}
#
# Generate repo file under /etc/yum.repos.d/
#
function dnf_add_repo() {
local -r repo_name="$1"
local -r repo_url="$3" # "http(s)://host/path/filename.repo"
local -r kr_path="${5:-/etc/pki/rpm-gpg/${repo_name}.gpg}"
local -r repo_path="${6:-/etc/yum.repos.d/${repo_name}.repo}"
curl -s -L "${repo_url}" \
| dd of="${repo_path}" status=progress
# | perl -p -e "s{^gpgkey=.*$}{gpgkey=file://${kr_path}}" \
}
#
# Keyrings default to
# /usr/share/keyrings/${repo_name}.gpg (debian/ubuntu) or
# /etc/pki/rpm-gpg/${repo_name}.gpg (rocky/RHEL)
#
function os_add_repo() {
local -r repo_name="$1"
local -r signing_key_url="$2"
local -r repo_data="$3" # "http(s)://host/path/uri argument0 .. argumentN"
local kr_path
if is_debuntu ; then kr_path="${5:-/usr/share/keyrings/${repo_name}.gpg}"
else kr_path="${5:-/etc/pki/rpm-gpg/${repo_name}.gpg}" ; fi
mkdir -p "$(dirname "${kr_path}")"
curl -fsS --retry-connrefused --retry 10 --retry-max-time 30 "${signing_key_url}" \
| gpg --import --no-default-keyring --keyring "${kr_path}"
if is_debuntu ; then apt_add_repo "${repo_name}" "${signing_key_url}" "${repo_data}" "${4:-yes}" "${kr_path}" "${6:-}"
else dnf_add_repo "${repo_name}" "${signing_key_url}" "${repo_data}" "${4:-yes}" "${kr_path}" "${6:-}" ; fi
}