Commit c2ad5f20 authored by Vitaly Lipatov's avatar Vitaly Lipatov

epm-repolist: add regexp support

parent 437d2b29
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012, 2016, 2019, 2020, 2021 Etersoft # Copyright (C) 2012, 2016, 2019, 2020, 2021, 2025 Etersoft
# Copyright (C) 2012, 2016, 2019, 2020, 2021 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016, 2019, 2020, 2021, 2025 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -21,23 +21,28 @@ load_helper epm-sh-altlinux ...@@ -21,23 +21,28 @@ load_helper epm-sh-altlinux
__print_apt_sources_list() __print_apt_sources_list()
{ {
local regexp="$1"
shift
local i local i
for i in $@ ; do for i in $@ ; do
test -r "$i" || continue test -r "$i" || continue
grep -v -- "^.*#" $i grep -v -- "^.*#" $i
done | grep -v -- "^ *\$" done | grep -v -- "^ *\$" | grep -E "$regexp"
} }
__print_apt_sources_list_full() __print_apt_sources_list_full()
{ {
local regexp="$1"
shift
local i local i
for i in $@ ; do for i in $@ ; do
test -r "$i" || continue test -r "$i" || continue
grep -- "^[[:space:]]*#*[[:space:]]*rpm" $i grep -- "^[[:space:]]*#*[[:space:]]*rpm" $i
done | grep -v -- "^ *\$" done | grep -v -- "^ *\$" | grep -E "$regexp"
} }
# TODO: remove # TODO: remove
# print lists with active values
__print_apt_sources_list_list() __print_apt_sources_list_list()
{ {
local i local i
...@@ -56,21 +61,25 @@ __info_cyan() ...@@ -56,21 +61,25 @@ __info_cyan()
__print_apt_sources_list_verbose() __print_apt_sources_list_verbose()
{ {
local regexp="$1"
shift
local i local i
for i in $@ ; do for i in $@ ; do
test -r "$i" || continue test -r "$i" || continue
grep -v -- "^.*#" $i | grep -v -- "^ *\$" | grep -q . && __info_cyan "$i:" || continue grep -v -- "^.*#" $i | grep -v -- "^ *\$" | grep -q . && __info_cyan "$i:" || continue
grep -v -- "^.*#" $i | grep -v -- "^ *\$" | sed -e 's|^| |' grep -v -- "^.*#" $i | grep -v -- "^ *\$" | sed -e 's|^| |' | grep -E --color "$regexp"
done done
} }
__print_apt_sources_list_verbose_full() __print_apt_sources_list_verbose_full()
{ {
local regexp="$1"
shift
local i local i
for i in $@ ; do for i in $@ ; do
test -r "$i" || continue test -r "$i" || continue
grep -- "^[[:space:]]*#*[[:space:]]*rpm" $i | grep -v -- "^ *\$" | grep -q . && echo && __info_cyan "$i:" || continue grep -- "^[[:space:]]*#*[[:space:]]*rpm" $i | grep -v -- "^ *\$" | grep -q . && echo && __info_cyan "$i:" || continue
grep -- "^[[:space:]]*#*[[:space:]]*rpm" $i | grep -v -- "^ *\$" | sed -e 's|^| |' -e "s|\(.*#.*\)|$(set_color $WHITE)\1$(restore_color)|" grep -- "^[[:space:]]*#*[[:space:]]*rpm" $i | grep -v -- "^ *\$" | sed -e 's|^| |' -e "s|\(.*#.*\)|$(set_color $WHITE)\1$(restore_color)|" | grep -E --color "$regexp"
done done
} }
...@@ -79,18 +88,19 @@ print_apt_sources_list() ...@@ -79,18 +88,19 @@ print_apt_sources_list()
local LISTS='/etc/apt/sources.list /etc/apt/sources.list.d/*.list' local LISTS='/etc/apt/sources.list /etc/apt/sources.list.d/*.list'
if [ "$1" = "-a" ] || [ "$1" = "--all" ] ; then if [ "$1" = "-a" ] || [ "$1" = "--all" ] ; then
shift
if [ -n "$quiet" ] ; then if [ -n "$quiet" ] ; then
__print_apt_sources_list_full $LISTS __print_apt_sources_list_full "$*" $LISTS
else else
__print_apt_sources_list_verbose_full $LISTS __print_apt_sources_list_verbose_full "$*" $LISTS
fi fi
return return
fi fi
if [ -n "$quiet" ] ; then if [ -n "$quiet" ] ; then
__print_apt_sources_list $LISTS __print_apt_sources_list "$*" $LISTS
else else
__print_apt_sources_list_verbose $LISTS __print_apt_sources_list_verbose "$*" $LISTS
fi fi
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment