2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
25 if [[ -f /etc
/fedora-release
]]; then
27 elif [[ -e /etc
/os-release
]]; then
28 sed -rn 's/^ID=(.*)/\1/p' /etc
/os-release
29 elif type -p lsb_release
&>/dev
/null
; then
30 # well, this is more standard, but it's 2 ms vs 200 ms
31 x
=$
(lsb_release
-si); echo ${x,,}
38 distro-name-compat
() {
39 local x
=$
(distro-name
)
51 echo $
(distro-name
)$
(debian-archive
)
55 # Subshell keeps environment clean.
57 # in ubuntu the .x matters, trisquel it doesnt
58 if [[ $ID == ubuntu
]]; then
61 echo ${VERSION_ID%%.*}
68 local archive expression pri name highpri shortest
69 local policy
="${1:-$(apt-cache policy)}" ||
return $?
73 # c = component (licensing component)
74 # l = label (Debian{,-Security,-Updates})
75 local d
=$
(distro-name
)
76 # goto b for archive lines we are interested in, a for lines we arent
77 # print priority + archive name. priority is in
78 # the previous line from the archive line.
79 # case insensitive, because $d is lower and we are matching with first char upper
80 read -rd '' expression
<<EOF ||:
81 /o=$d/I!b a;/l=$d/I!b a;/c=main/!b a b b;
82 : a;s/^ *([-0-9]+).*/\1/;h;b;
83 : b;s/^.*a=([^,]+).*/ \1/;H;x;s/\n//;p
85 while read -r pri name
; do
86 # in ubuntu, we get archives like flidas, flidas-updates, all the same pri,
87 # so just pick the shortest one.
88 if [[ ! $highpri ]]; then
93 if [[ $pri != $highpri ]]; then
96 if (( ${#shortest} > ${#name} )); then
99 done < <(echo "$policy" |
sed -rn "$expression" |
sort -rn ||
[[ $?
== 141 ]])
103 # formatted for use in pfile() in package-manager-abstractions
106 local archive expression pri name highpri shortest
107 local policy
="${1:-$(apt-cache policy)}" ||
return $?
111 # c = component (licensing component)
112 # l = label (Debian{,-Security,-Updates})
113 read -rd '' expression
<<EOF ||:
114 /^ *([-0-9]+).*/{s/^ *([-0-9]+).*/\1/;h}
115 /^.*o=([^,]+).*/{s/^.*o=([^,]+).*/ \1/;H;x;s/\n//;p}
118 while read -r pri name
; do
119 if (( pri
> 0 )); then
120 if [[ ! $origins ]]; then
126 done < <(echo "$policy" |
sed -rn "$expression" |
sort -rn ||
[[ $?
== 141 ]])
131 [[ $
(debian-archive
) == testing
]]
133 # I only do testing or stable.
135 [[ $
(debian-archive
) == stable
]]
140 local policy
="$(apt-cache policy)" ||
return $?
141 archive
=$
(debian-archive
"$policy")
142 echo "$policy" |
sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q" ||
[[ $?
== 141 ]]
144 debian-codename-compat
() {
145 local n
=$
(debian-codename
)
166 [[ $
(distro-name
) == fedora
]]
169 [[ $
(distro-name
) == debian
]]
172 [[ $
(distro-name
) == arch
]]
175 [[ $
(distro-name
) == ubuntu
]]
178 [[ $
(distro-name
) == trisquel
]]
180 # is debian/apt based
181 isdeb
() { command -v apt-get
&>/dev
/null
; }