diff options
author | Oto Šťáva <oto.stava@nic.cz> | 2024-07-10 16:38:26 +0200 |
---|---|---|
committer | Oto Šťáva <oto.stava@nic.cz> | 2024-07-11 13:51:45 +0200 |
commit | d068a95304a57306b732f45a5105be0357886f7c (patch) | |
tree | 6905f5d3d1b211ee6d51c1a358ca9efc8894776f /scripts | |
parent | .gitlab-ci: use newer Knot for make-archive (diff) | |
download | knot-resolver-d068a95304a57306b732f45a5105be0357886f7c.tar.xz knot-resolver-d068a95304a57306b732f45a5105be0357886f7c.zip |
drop libknot <=3.2.x support
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/enable-repo-cznic-labs.sh | 30 | ||||
-rwxr-xr-x | scripts/enable-repo.py | 132 |
2 files changed, 30 insertions, 132 deletions
diff --git a/scripts/enable-repo-cznic-labs.sh b/scripts/enable-repo-cznic-labs.sh new file mode 100755 index 00000000..cbc64c68 --- /dev/null +++ b/scripts/enable-repo-cznic-labs.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# enable CZ.NIC Labs Debian/Ubuntu repos - see https://pkg.labs.nic.cz/doc/ +set -e + +REPO=$1 +if [ -z "${REPO}" ]; then + echo "usage: $0 REPOSITORY" + echo -e "\nPlease see: https://pkg.labs.nic.cz/doc/" + exit 1 +fi +if [ "$(whoami)" != "root" ]; then + echo "ERROR: this script must be run as ROOT" + echo -e "\nTry running with sudo:\n\n sudo $0\n" + exit 2 +fi + +# update apt metadata and install requirements +apt-get update +apt-get install -y apt-transport-https ca-certificates lsb-release wget + +DISTRO=$(lsb_release -si | tr '[:upper:]' '[:lower:]') +CODENAME=$(lsb_release -sc) + +echo "Enabling $REPO repo on $DISTRO $CODENAME..." +# get repo signing key +wget -O /usr/share/keyrings/cznic-labs-pkg.gpg https://pkg.labs.nic.cz/gpg +# create repo entry +echo "deb [signed-by=/usr/share/keyrings/cznic-labs-pkg.gpg] https://pkg.labs.nic.cz/$REPO $CODENAME main" > /etc/apt/sources.list.d/cznic-labs-$REPO.list +# update apt metadata from the new repo +apt-get update diff --git a/scripts/enable-repo.py b/scripts/enable-repo.py deleted file mode 100755 index 2b9319eb..00000000 --- a/scripts/enable-repo.py +++ /dev/null @@ -1,132 +0,0 @@ -#!/usr/bin/python3 -""" -Enable Knot Resolver upstream repo on current system. - -Requires python3-distro. - -Run this as ROOT. -""" - -import argparse -import distro as distro_ -from pathlib import Path -from subprocess import run, PIPE -import sys - - -REPO_CHOICES = ['latest', 'testing', 'build'] - - -def detect_distro(): - return '%s-%s' % (distro_.id(), distro_.version()) - - -def parse_distro(distro): - id_, _, ver_ = distro.rpartition('-') - return id_, ver_ - - -def distro2obs(distro): - distro_id, distro_ver = parse_distro(distro) - if not str(distro_ver): - return None - if distro_id == 'debian': - return 'Debian_%s' % distro_ver - if distro_id == 'ubuntu': - return 'xUbuntu_%s' % distro_ver - if distro_id == 'opensuse-leap': - return 'openSUSE_Leap_%s' % distro_ver - return None - - -def show_info(): - print("distro ID: %s" % detect_distro()) - print("distro name: %s %s" % (distro_.name(), distro_.version(pretty=True))) - - -def enable_deb_repo(repo_id, distro): - obs_distro = distro2obs(distro) - if not obs_distro: - return fail('unsupported Debian-based distro: %s' % distro) - - requires = ['python3-requests', 'gnupg'] - print("installing required packages: %s" % ' '.join(requires)) - p = run(['apt', 'install', '-y'] + requires) - import requests - - sources_p = Path('/etc/apt/sources.list.d/%s.list' % repo_id) - sources_txt = 'deb http://download.opensuse.org/repositories/home:/CZ-NIC:/%s/%s/ /' % (repo_id, obs_distro) - key_url = 'https://download.opensuse.org/repositories/home:CZ-NIC:%s/%s/Release.key' % (repo_id, obs_distro) - print("writing sources list: %s" % sources_p) - with sources_p.open('wt') as f: - f.write(sources_txt + '\n') - print(sources_txt) - print("fetching key: %s" % key_url) - r = requests.get(key_url) - if not r.ok: - return fail('failed to fetch repo key: %s' % key_url) - key_txt = r.content.decode('utf-8') - print("adding key using `apt-key add`") - p = run(['apt-key', 'add', '-'], input=key_txt, encoding='utf-8') - if p.returncode != 0: - print('apt-key add failed :(') - run(['apt', 'update']) - print("%s repo added" % repo_id) - - -def enable_suse_repo(repo_id, distro): - obs_distro = distro2obs(distro) - if not obs_distro: - return fail('unsupported SUSE distro: %s' % distro) - - repo_url = 'https://download.opensuse.org/repositories/home:CZ-NIC:{repo}/{distro}/home:CZ-NIC:{repo}.repo'.format( - repo=repo_id, distro=obs_distro) - print("adding OBS repo: %s" % repo_url) - run(['zypper', 'addrepo', repo_url]) - run(['zypper', '--no-gpg-checks', 'refresh']) - - -def enable_repo(repo_id, distro): - distro_id, distro_ver = parse_distro(distro) - print("enable %s repo on %s" % (repo_id, distro)) - - if distro_id in ['debian', 'ubuntu']: - enable_deb_repo(repo_id, distro) - elif distro_id == 'opensuse-leap': - enable_suse_repo(repo_id, distro) - elif distro_id == 'arch': - print("no external repo needed on %s" % distro_id) - else: - fail("unsupported distro: %s" % distro_id) - - -def fail(msg): - print(msg) - sys.exit(1) - - -def main(): - parser = argparse.ArgumentParser( - description="Enable Knot Resolver repo on this system") - parser.add_argument('repo', choices=REPO_CHOICES, nargs='?', default=REPO_CHOICES[0], - help="repo to enable") - parser.add_argument('-d', '--distro', type=str, - help="override target distro (DISTRO-VERSION format)") - parser.add_argument('-i', '--info', action='store_true', - help="show distro information and exit") - - args = parser.parse_args() - if args.info: - show_info() - return - - distro = args.distro - if not distro: - distro = detect_distro() - - repo = 'knot-resolver-%s' % args.repo - enable_repo(repo, distro) - - -if __name__ == '__main__': - main() |