summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/enable-repo.py132
-rwxr-xr-xscripts/gen-cdefs.sh11
-rwxr-xr-xscripts/make-archive.sh23
-rwxr-xr-xscripts/make-doc.sh40
-rwxr-xr-xscripts/update-authors.sh7
-rwxr-xr-xscripts/upstream-version.sh9
6 files changed, 187 insertions, 35 deletions
diff --git a/scripts/enable-repo.py b/scripts/enable-repo.py
new file mode 100755
index 00000000..2b9319eb
--- /dev/null
+++ b/scripts/enable-repo.py
@@ -0,0 +1,132 @@
+#!/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()
diff --git a/scripts/gen-cdefs.sh b/scripts/gen-cdefs.sh
index ddb0aa7f..d56ab86d 100755
--- a/scripts/gen-cdefs.sh
+++ b/scripts/gen-cdefs.sh
@@ -2,8 +2,8 @@
# SPDX-License-Identifier: GPL-3.0-or-later
set -o pipefail -o errexit
-if [ "$2" != types ] && [ "$2" != functions ]; then
- echo "Usage: $0 libkres (types|functions)" >&2
+if [ "$2" != types ] && [ "$2" != functions ] && [ "$2" != variables ]; then
+ echo "Usage: $0 libkres (types|functions|variables)" >&2
echo " and input identifiers, one per line." >&2
echo " You need debug symbols in the library." >&2
echo
@@ -47,7 +47,7 @@ grep -v '^#\|^$' | while read -r ident; do
if [ "$2" = functions ]; then
output="$("${GDB[@]}" --ex "info functions ^$ident\$" \
| sed '0,/^All functions/ d; /^File .*:$/ d')"
- else # types
+ elif [ "$2" = types ]; then
case "$ident" in
struct\ *|union\ *|enum\ *)
output="$("${GDB[@]}" --ex "ptype $ident" \
@@ -63,6 +63,11 @@ grep -v '^#\|^$' | while read -r ident; do
| sed "0,/^type = /s/^type = /typedef /; $ s/$/ $ident;/")"
;;
esac
+ elif [ "$2" = variables ]; then
+ output="$("${GDB[@]}" --ex "info variables -q ^$ident\$" \
+ | sed -e '0,/^File .*:$/ d' -e '/^File .*:$/,$ d')"
+ else
+ exit 1
fi
# LuaJIT FFI blows up on "uint" type
output="$(echo "$output" | sed 's/\buint\b/unsigned int/g')"
diff --git a/scripts/make-archive.sh b/scripts/make-archive.sh
index 82703674..9f2be0ea 100755
--- a/scripts/make-archive.sh
+++ b/scripts/make-archive.sh
@@ -11,11 +11,14 @@ cd "$(dirname ${0})/.."
if ! git describe --tags --exact-match; then
# devel version
- GIT_HASH=$(git rev-parse --short HEAD )
- TIMESTAMP=$(date -u +'%s' 2>/dev/null)
+ VERSION_TAG=$(git describe --tags | cut -d- -f1)
+ VERSION=${VERSION_TAG#v}
+ GIT_HASH=$(git rev-parse --short=6 HEAD)
+ N_COMMITS=$(git rev-list $VERSION_TAG.. --count)
+ FULL_VERSION="$VERSION.dev$N_COMMITS+$GIT_HASH"
# modify and commit meson.build
- sed -i "s/^\(\s*version\s*:\s*'\)\([^']\+\)\('.*\)/\1\2.$TIMESTAMP.$GIT_HASH\3/" meson.build
+ sed -i "s/^\(\s*version\s*:\s*'\)\([^']\+\)\('.*\)/\1$FULL_VERSION\3/" meson.build
: changed version in meson.build, changes must be committed to git
git add meson.build
@@ -33,6 +36,14 @@ rm -rf build_dist ||:
meson build_dist
ninja -C build_dist dist
-# print path to generated tarball
-set +o xtrace
-find "${PWD}/build_dist/meson-dist/" -name "knot-resolver-*.tar.xz"
+# copy tarball to apkg path
+DIST_ARCHIVE=$(find "build_dist/meson-dist/" -name "knot-resolver-*.tar.xz")
+APKG_ARCHIVE="pkg/archives/dev/$(basename $DIST_ARCHIVE)"
+mkdir -p pkg/archives/dev
+cp "$DIST_ARCHIVE" "$APKG_ARCHIVE"
+
+# remove build directory
+rm -rf build_dist ||:
+
+# print path to generated tarball as expected by apkg
+echo "$APKG_ARCHIVE"
diff --git a/scripts/make-doc.sh b/scripts/make-doc.sh
index 35c4e73a..1723ada7 100755
--- a/scripts/make-doc.sh
+++ b/scripts/make-doc.sh
@@ -3,35 +3,23 @@
set -o errexit -o nounset
cd "$(dirname "${0}")/.."
-pushd doc
-doxygen
+# generate JSON schema for the manager's declarative config
+pushd manager
+## the following python command should hopefully run without any dependencies except for standard python
+mkdir -p ../doc/_static/
+python3 -m knot_resolver_manager.cli schema > ../doc/_static/config.schema.json
+generate-schema-doc --config expand_buttons=true ../doc/_static/config.schema.json ../doc/_static/schema_doc.html
popd
+# generating the user documentation
SPHINX=$(type -P sphinx-build-3 sphinx-build | head -n1)
rm -rf doc/html
-"$SPHINX" "$@" -b html -d doc/.doctrees doc doc/html
-
-if command -v makeinfo &>/dev/null; then
- rm -rf doc/texinfo
- ${SPHINX} ${@} -b texinfo -d doc/.doctrees doc doc/texinfo
-
- # Sphinx < 2 doesn't create a separate directory for figures, so if
- # necessary move them to the correct location and update the references in
- # the generated Texinfo file
- if [ ! -d doc/texinfo/knot-resolver-figures ]; then
- cd doc/texinfo
- mkdir knot-resolver-figures
- mv *.png *.svg knot-resolver-figures/
- sed -e 's/\(@image{\)/\1knot-resolver-figures\//' \
- knot-resolver.texi > knot-resolver.texi.tmp
- mv knot-resolver.texi.tmp knot-resolver.texi
- cd ../..
- fi
+"$SPHINX" "$@" -b html -d doc/user/.doctrees doc/user doc/html
- make -C doc/texinfo info
+pushd doc/dev
+doxygen
+popd
- mkdir doc/texinfo/.install
- mv doc/texinfo/knot-resolver.info \
- doc/texinfo/knot-resolver-figures \
- doc/texinfo/.install/
-fi
+# generating the developer documentation
+rm -rf doc/html/dev
+"$SPHINX" "$@" -b html -d doc/dev/.doctrees doc/dev doc/html/dev
diff --git a/scripts/update-authors.sh b/scripts/update-authors.sh
index a2ddc277..8ccb77ed 100755
--- a/scripts/update-authors.sh
+++ b/scripts/update-authors.sh
@@ -1,5 +1,12 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
+
+# avoid confusing changes in ordering
+if ! locale | grep -q '^LC_COLLATE=.*\.UTF-8'; then
+ echo 'Error: you need to run this script with an .UTF-8 locale.'
+ exit 2
+fi
+
set -o nounset -o xtrace
function spdx_originator_to_authors {
diff --git a/scripts/upstream-version.sh b/scripts/upstream-version.sh
new file mode 100755
index 00000000..77613b70
--- /dev/null
+++ b/scripts/upstream-version.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# return latest upstream version of Knot Resolver
+set -o errexit
+
+REPO=https://gitlab.nic.cz/knot/knot-resolver.git
+
+git ls-remote --tags --refs $REPO | cut -f2- | sed -n "s#^refs/tags/v##p" | sort -V | tail -1