From patchwork Fri Feb 24 16:22:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 6606 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4PNZt111lwz3x1w for ; Fri, 24 Feb 2023 16:22:17 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4PNZt03Kskz1ln; Fri, 24 Feb 2023 16:22:16 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4PNZt01b18z3019; Fri, 24 Feb 2023 16:22:16 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4PNZsy3dCqz2xPJ; Fri, 24 Feb 2023 16:22:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4PNZsw4dZvzBD; Fri, 24 Feb 2023 16:22:12 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1677255733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=obc7AvnU/W8TxAfGNjygUODZ2kw7OqvU+4N9bZkdA4g=; b=VkeRrxREuzWil+BVNQcB6S0uPCLYvmR4p++tL3I2WgXiKscbqjBEf7XbEHT/ea6FgCa6Rm EEYl+bbTPldQbYCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1677255733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=obc7AvnU/W8TxAfGNjygUODZ2kw7OqvU+4N9bZkdA4g=; b=f55HXlDKm9GeFGRTQZv4hOpCrp1jkSlPulkkIYWHZVNfa89XVHjGnIUhuAqKp8ok0WyI7q 72ljxsKpTXexgSSWCFjWU9BbMK66azjEuu0UXTkcnpavV/Hu112vLy8RHi29JvHl5P3gfF wnW+rT1KFKQtLC1LrMfVij2KxX4f0A2MogiAd2ARklsT/8ij2DGjlGEjLdB+gOg0KCwaxO C50h817kJ9xZYUop/o6mGyp309uIBZ9lbd5zf65YmoopSuqdrvYj1PkfFBTSodYApgOo9+ V86Zhw+BQ7st/PzRNfZzXTgdJAeNFmx2a2sCQSp9zbXa6cTEyEz6dPittlnJmg== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH 1/2] Add bash-completion file for the location command. Date: Fri, 24 Feb 2023 17:22:05 +0100 Message-Id: <20230224162206.89971-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: development@lists.ipfire.org, Hans-Christoph Steiner Errors-To: location-bounces@lists.ipfire.org Sender: "Location" From: Hans-Christoph Steiner Signed-off-by: Stefan Schantl --- bash-completion/location | 151 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 bash-completion/location diff --git a/bash-completion/location b/bash-completion/location new file mode 100644 index 0000000..66fc6c1 --- /dev/null +++ b/bash-completion/location @@ -0,0 +1,151 @@ +# location(1) completion -*- shell-script -*- +# +# bash-completion - part of libloc +# +# Copyright (C) 2020,2023 Hans-Christoph Steiner +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 2.1 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 Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . + +__location_init() { + if type -t _init_completion >/dev/null; then + _init_completion -n : || return + else + # manual initialization for older bash completion versions + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + fi + + (( $# >= 1 )) && __complete_${1} + __ltrim_colon_completions "$cur" +} + +__complete_options() { + case "${prev}" in + --directory) + _filedir -d + return 0;; + --cron) + COMPREPLY=( $( compgen -W "daily weekly monthly" -- $cur ) ) + return 0;; + --family) + COMPREPLY=( $( compgen -W "ipv6 ipv4" -- $cur ) ) + return 0;; + --format) + COMPREPLY=( $( compgen -W "ipset list nftables xt_geoip" -- $cur ) ) + return 0;; + esac + + case "$cur" in + -*) + COMPREPLY=( $( compgen -W "--help ${lopts}" -- $cur ) ) + return 0;; + esac +} + +__complete_dump() { + __complete_options +} + +__complete_get_as() { + __complete_options +} + +__complete_export() { + lopts="--directory --family --format" + __complete_options +} + +__complete_list_networks_by_as() { + lopts="--family --format" + __complete_options +} + +__complete_list_networks_by_cc() { + lopts="--family --format" + __complete_options +} + +__complete_list_networks_by_flags() { + lopts="--anonymous-proxy --satellite-provider --anycast --drop --family --format" + __complete_options +} + +__complete_list_bogons() { + lopts="--family --format" + __complete_options +} + +__complete_list_countries() { + lopts="--show-name --show-continent" + __complete_options +} + +__complete_lookup() { + __complete_options +} + +__complete_search_as() { + __complete_options +} + +__complete_update() { + lopts="--cron" + __complete_options +} + +__complete_version() { + __complete_options +} + +__complete_verify() { + __complete_options +} + +# for f in `location|grep -Eo '[a-z,-]+,[a-z,-]+'| sed 's/,/ /g'`; do printf '%s \\\n' $f; done|sort -u +__cmds=" \ +dump \ +export \ +get-as \ +list-bogons \ +list-countries \ +list-networks-by-as \ +list-networks-by-cc \ +list-networks-by-flags \ +lookup \ +search-as \ +update \ +verify \ +version \ +" + +for c in $__cmds; do + eval "_location_${c} () { + local cur prev lopts + __location_init ${c//-/_} + }" +done + +_location() { + local cmd + cmd=${COMP_WORDS[1]} + + [[ $__cmds == *\ $cmd\ * ]] && _location_${cmd} || { + (($COMP_CWORD == 1)) && COMPREPLY=( $( compgen -W "${__cmds}" -- $cmd ) ) + } +} + +complete -F _location location + +return 0 From patchwork Fri Feb 24 16:22:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 6608 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4PNZt31XLyz3x1w for ; Fri, 24 Feb 2023 16:22:19 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4PNZt05W1Zz2LN; Fri, 24 Feb 2023 16:22:16 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4PNZt02Bvmz302b; Fri, 24 Feb 2023 16:22:16 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4PNZsz3S8Vz2xYk; Fri, 24 Feb 2023 16:22:15 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4PNZsy3x9Nzgr; Fri, 24 Feb 2023 16:22:14 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1677255734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HNBlIIsNJMPOvA7Baw5sX5sGm/kWy9K65AWtMrtpIZE=; b=BokToyFCeOd9EkLZwhXnTHV4e+SbUJYU2UwrjR6Hpatp5IEBKpgccsycsmnRP9BtIpywMz ioHWRtaj85ddf2BA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1677255734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HNBlIIsNJMPOvA7Baw5sX5sGm/kWy9K65AWtMrtpIZE=; b=eZnHITkONAF07gm5wKOlbRANHNFRGCPt4ny/Y1uv3DYNOqPUdQIHiZ/pWxH6x/qCERWG4e qd3+Oi7RTyM26olBMIBrAhbVNoN/KLgfS1KhaeDqD+QTdUIDA0Zxhzjy46gxb8LCQj7BeA CAApg1lVlWMG+PdS33gR/SgjpYKNjc0Myd0vpCTwzBtEND1JdQzBeaj6RPKJgC6R/kgvWl sR8kcooBf2mTusYm5Jzw4wuVlrzkjEQX9tqGx658OvED85vZLZg+D0FRQ4lqeM3rEJpQY6 j7JSaaZG5i9YcIUemCi4tWF5Wy+Cs8GfokViVxPIGs7tv8Jqap+yS1TkdDppmQ== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH 2/2] Install bash-completion files. Date: Fri, 24 Feb 2023 17:22:06 +0100 Message-Id: <20230224162206.89971-2-stefan.schantl@ipfire.org> In-Reply-To: <20230224162206.89971-1-stefan.schantl@ipfire.org> References: <20230224162206.89971-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: development@lists.ipfire.org Errors-To: location-bounces@lists.ipfire.org Sender: "Location" Signed-off-by: Stefan Schantl --- Makefile.am | 9 +++++++++ configure.ac | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/Makefile.am b/Makefile.am index 4da2ec5..4edb9e9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,8 @@ if ENABLE_PERL BINDINGS += perl endif +bashcompletiondir = @bashcompletiondir@ + AM_CPPFLAGS = \ -include $(top_builddir)/config.h \ -DSYSCONFDIR=\""$(sysconfdir)"\" \ @@ -172,6 +174,13 @@ EXTRA_DIST += \ CLEANFILES += \ src/libloc.pc +#dist_bashcompletion_DATA = + +if BUILD_BASH_COMPLETION +dist_bashcompletion_DATA = \ + bash-completion/location +endif + dist_pkgpython_PYTHON = \ src/python/database.py \ src/python/downloader.py \ diff --git a/configure.ac b/configure.ac index edca1d4..e21574d 100644 --- a/configure.ac +++ b/configure.ac @@ -55,6 +55,41 @@ AC_CHECK_PROGS(ASCIIDOC, [asciidoc]) if test "${have_man_pages}" = "yes" && test -z "${ASCIIDOC}"; then AC_MSG_ERROR([Required program 'asciidoc' not found]) fi + +# - pkg-config ----------------------------------------------------------------- + +m4_ifndef([PKG_PROG_PKG_CONFIG], + [m4_fatal([Could not locate the pkg-config autoconf + macros. These are usually located in /usr/share/aclocal/pkg.m4. + If your macros are in a different location, try setting the + environment variable AL_OPTS="-I/other/macro/dir" before running + ./autogen.sh or autoreconf again. Make sure pkg-config is installed.])]) + +PKG_PROG_PKG_CONFIG +PKG_INSTALLDIR(['${usrlib_execdir}/pkgconfig']) + +# - bash-completion ------------------------------------------------------------ + +#enable_bash_completion=yes +AC_ARG_WITH([bashcompletiondir], + AS_HELP_STRING([--with-bashcompletiondir=DIR], [Bash completions directory]), + [], + [AS_IF([`$PKG_CONFIG --exists bash-completion`], [ + with_bashcompletiondir=`$PKG_CONFIG --variable=completionsdir bash-completion` + ], [ + with_bashcompletiondir=${datadir}/bash-completion/completions + ]) +]) + +AC_SUBST([bashcompletiondir], [$with_bashcompletiondir]) + +AC_ARG_ENABLE([bash-completion], + AS_HELP_STRING([--disable-bash-completion], [do not install bash completion files]), + [], [enable_bash_completion=yes] +) + +AM_CONDITIONAL([BUILD_BASH_COMPLETION], [test "x$enable_bash_completion" = xyes]) + # - debug ---------------------------------------------------------------------- AC_ARG_ENABLE([debug], @@ -206,6 +241,7 @@ AC_MSG_RESULT([ debug: ${enable_debug} systemd support: ${have_systemd} + bash-completion: ${enable_bash_completion} Bindings: perl: ${enable_perl}