blob: 74a79eb639811dd4ef2b1795407a26fef724bf98 (
plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#!/bin/bash
########################################################################################################################
# apt-list-bin-packages-from-src.sh
########################################################################################################################
#
# All rights reserved Ⓒ 2017-2023 sdxlive.com
#
# Written by Jean-Christophe Manciot <jcmanciot@sdxlive.com>
#
# Licensed under a GPLv3 License.
# You may not use this file except in compliance with the License. You may obtain a copy of the License at
#
# https://www.gnu.org/licenses/gpl-3.0.md
#
# The licensor cannot revoke these freedoms as long as you follow the license terms.
#
# Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made.
# You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
#
########################################################################################################################
########################################################################################################################
#
# Listing all apt binary deb packages from a source package for the amd64 architecture.
#
########################################################################################################################
#
# Requirements:
# ------------
#
# - We assume that apt is already installed.
#
########################################################################################################################
#
# Parameters:
# ----------
#
# - <src_package_name>: name of the source package
# - <src_package_version>: version of the source package
#
#######################################################################################################################
#
# Usage: example
# -----
#
# readarray -t bin_packages < <(apt-list-bin-packages-from-src.sh binutils 2.41-4)
#
########################################################################################################################
# set -x
# Expanding aliases
shopt -s expand_aliases
# Escaping the '$.*+?|/(){}[\]^' characters for later awk searched string
# Letters, digits and '-' must not be escaped
alias escape_awk_ere_search_string=$'sed -e \'s|[]\/$.*+?|^(){}[]|\\\&|g\''
# '
src_package_name=$1
src_package_version=$2
PARAMETERS_NUMBER=2
case "$#" in
${PARAMETERS_NUMBER})
;;
*)
echo -e ''$_{1..180}'\b-'
echo Wrong number of parameters: $(basename $0) $@
echo -e ''$_{1..180}'\b-'
exit 1
;;
esac
if [[ ! $(apt-cache showsrc "$src_package_name" 2>&1) =~ 'Unable to locate package' ]]; then
awk_esc_src_package_version="$(echo "$src_package_version" | escape_awk_ere_search_string)"
criteria="Version: $awk_esc_src_package_version"
# Kudos to RavinderSingh13 @https://stackoverflow.com/a/49664200/9299396
apt-cache showsrc "$src_package_name" | awk '
/^Package:[[:blank:]]/{
if(val) {print value};
flag=1;
value=val=""}
/^'"$criteria"'/ && flag {val=1}
/^$/ {flag=""}
flag{
value=value?value ORS $0:$0
}
END{
if(val) {print value}}
' | awk "/^Package-List:/{flag=1; next} /^[^:]+: /{flag=0} flag" | grep ' deb ' | grep -P "arch=(.*all|.*any|.*amd64)" | awk '{print $1}' | sort -u
fi
exit $?
|