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`
49 local archive expression pri name highpri shortest
50 local policy
="${1:-$(apt-cache policy)}"
54 # c = component (licensing component)
55 # l = label (Debian{,-Security,-Updates})
56 local d
=$
(distro-name
)
57 # goto b for archive lines we are interested in, a for lines we arent
58 # print priority + archive name. priority is in
59 # the previous line from the archive line.
60 # case insensitive, because $d is lower and we are matching with first char upper
61 read -rd '' expression
<<EOF ||:
62 /o=$d/I!b a;/l=$d/I!b a;/c=main/!b a b b;
63 : a;s/^ *([-0-9]+).*/\1/;h;b;
64 : b;s/^.*a=([^,]+).*/ \1/;H;x;s/\n//;p
66 while read -r pri name
; do
67 # in ubuntu, we get archives like flidas, flidas-updates, all the same pri,
68 # so just pick the shortest one.
69 if [[ ! $highpri ]]; then
74 if [[ $pri != $highpri ]]; then
77 if (( ${#shortest} > ${#name} )); then
80 done < <(echo "$policy" |
sed -rn "$expression" |
sort -rn)
87 [[ $
(debian-archive
) == testing
]]
89 # I only do testing or stable.
91 [[ $
(debian-archive
) == stable
]]
96 local policy
="$(apt-cache policy)"
97 archive
=$
(debian-archive
"$policy")
98 echo "$policy" |
sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q"
100 debian-codename-compat
() {
101 local n
=$
(debian-codename
)
113 [[ $
(distro-name
) == fedora
]]
116 [[ $
(distro-name
) == debian
]]
119 [[ $
(distro-name
) == arch
]]
122 [[ $
(distro-name
) == ubuntu
]]
125 [[ $
(distro-name
) == trisquel
]]
127 # is debian/apt based
128 isdeb
() { command -v apt-get
&>/dev
/null
; }