2 # Copyright (C) 2014 Ian Kelling
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 if [[ -f /etc
/fedora-release
]]; then
20 elif [[ -e /etc
/os-release
]]; then
21 sed -rn 's/^ID=(.*)/\1/p' /etc
/os-release
22 elif type -p lsb_release
&>/dev
/null
; then
23 # well, this is more standard, but it's 2 ms vs 200 ms
24 x
=$
(lsb_release
-si); echo ${x,,}
31 distro-name-compat
() {
32 local x
=$
(distro-name
)
44 echo $
(distro-name
)$
(debian-archive
)
48 # Subshell keeps environment clean.
50 # in ubuntu the .x matters, trisquel it doesnt
51 if [[ $ID == ubuntu
]]; then
54 echo ${VERSION_ID%%.*}
61 local archive expression pri name highpri shortest
62 local policy
="${1:-$(apt-cache policy)}" ||
return $?
66 # c = component (licensing component)
67 # l = label (Debian{,-Security,-Updates})
68 local d
=$
(distro-name
)
69 # goto b for archive lines we are interested in, a for lines we arent
70 # print priority + archive name. priority is in
71 # the previous line from the archive line.
72 # case insensitive, because $d is lower and we are matching with first char upper
73 read -rd '' expression
<<EOF ||:
74 /o=$d/I!b a;/l=$d/I!b a;/c=main/!b a b b;
75 : a;s/^ *([-0-9]+).*/\1/;h;b;
76 : b;s/^.*a=([^,]+).*/ \1/;H;x;s/\n//;p
78 while read -r pri name
; do
79 # in ubuntu, we get archives like flidas, flidas-updates, all the same pri,
80 # so just pick the shortest one.
81 if [[ ! $highpri ]]; then
86 if [[ $pri != $highpri ]]; then
89 if (( ${#shortest} > ${#name} )); then
92 done < <(echo "$policy" |
sed -rn "$expression" |
sort -rn ||
[[ $?
== 141 ]])
96 # formatted for use in pfile() in package-manager-abstractions
99 local archive expression pri name highpri shortest
100 local policy
="${1:-$(apt-cache policy)}" ||
return $?
104 # c = component (licensing component)
105 # l = label (Debian{,-Security,-Updates})
106 read -rd '' expression
<<EOF ||:
107 /^ *([-0-9]+).*/{s/^ *([-0-9]+).*/\1/;h}
108 /^.*o=([^,]+).*/{s/^.*o=([^,]+).*/ \1/;H;x;s/\n//;p}
111 while read -r pri name
; do
112 if (( pri
> 0 )); then
113 if [[ ! $origins ]]; then
119 done < <(echo "$policy" |
sed -rn "$expression" |
sort -rn ||
[[ $?
== 141 ]])
124 [[ $
(debian-archive
) == testing
]]
126 # I only do testing or stable.
128 [[ $
(debian-archive
) == stable
]]
133 local policy
="$(apt-cache policy)" ||
return $?
134 archive
=$
(debian-archive
"$policy")
135 echo "$policy" |
sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q" ||
[[ $?
== 141 ]]
137 debian-codename-compat
() {
138 local n
=$
(debian-codename
)
159 [[ $
(distro-name
) == fedora
]]
162 [[ $
(distro-name
) == debian
]]
165 [[ $
(distro-name
) == arch
]]
168 [[ $
(distro-name
) == ubuntu
]]
171 [[ $
(distro-name
) == trisquel
]]
173 # is debian/apt based
174 isdeb
() { command -v apt-get
&>/dev
/null
; }