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
49 ( .
/etc
/os-release
; echo ${VERSION_ID%%.*}; )
54 local archive expression pri name highpri shortest
55 local policy
="${1:-$(apt-cache policy)}" ||
return $?
59 # c = component (licensing component)
60 # l = label (Debian{,-Security,-Updates})
61 local d
=$
(distro-name
)
62 # goto b for archive lines we are interested in, a for lines we arent
63 # print priority + archive name. priority is in
64 # the previous line from the archive line.
65 # case insensitive, because $d is lower and we are matching with first char upper
66 read -rd '' expression
<<EOF ||:
67 /o=$d/I!b a;/l=$d/I!b a;/c=main/!b a b b;
68 : a;s/^ *([-0-9]+).*/\1/;h;b;
69 : b;s/^.*a=([^,]+).*/ \1/;H;x;s/\n//;p
71 while read -r pri name
; do
72 # in ubuntu, we get archives like flidas, flidas-updates, all the same pri,
73 # so just pick the shortest one.
74 if [[ ! $highpri ]]; then
79 if [[ $pri != $highpri ]]; then
82 if (( ${#shortest} > ${#name} )); then
85 done < <(echo "$policy" |
sed -rn "$expression" |
sort -rn ||
[[ $?
== 141 ]])
92 [[ $
(debian-archive
) == testing
]]
94 # I only do testing or stable.
96 [[ $
(debian-archive
) == stable
]]
101 local policy
="$(apt-cache policy)" ||
return $?
102 archive
=$
(debian-archive
"$policy")
103 echo "$policy" |
sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q" ||
[[ $?
== 141 ]]
105 debian-codename-compat
() {
106 local n
=$
(debian-codename
)
121 [[ $
(distro-name
) == fedora
]]
124 [[ $
(distro-name
) == debian
]]
127 [[ $
(distro-name
) == arch
]]
130 [[ $
(distro-name
) == ubuntu
]]
133 [[ $
(distro-name
) == trisquel
]]
135 # is debian/apt based
136 isdeb
() { command -v apt-get
&>/dev
/null
; }