# See the License for the specific language governing permissions and
# limitations under the License.
-distro_name() {
+distro-name() {
if [[ -f /etc/fedora-release ]]; then
echo fedora
+ elif [[ -e /etc/os-release ]]; then
+ sed -rn 's/^ID=(.*)/\1/p' /etc/os-release
else
- grep "^ID=.*" /etc/os-release | sed 's/^ID=//'
+ echo "unknown distro"
+ return 1
fi
}
+
+distro-name-ver() {
+ echo `distro-name``debian-archive`
+}
+
+debian-archive() {
+ isdeb || return 0
+ local archive
+ local policy="${1:-$(apt-cache policy)}"
+ # a = archive
+ # n = codename
+ # o = origin
+ # c = component (licensing component)
+ # l = label (Debian{,-Security,-Updates})
+ { for archive in stable testing unstable; do
+ # print priority + archive name. priority is in
+ # the previous line after finding the archive.
+ read -rd '' expression <<EOF ||:
+/o=Debian,a=$archive,.*l=Debian,c=main/{x;s/^ *([-0-9]+).*/\1 $archive/p;q};h
+EOF
+ echo "$policy" | sed -rn "$expression"
+ done
+ } | sort -rn | head -n1 | grep -oE "\w+$"
+}
+
+
+isdebian-testing() {
+ [[ $(debian-archive) == testing ]]
+}
+# I only do testing or stable.
+isdebian-stable() {
+ [[ $(debian-archive) == stable ]]
+}
+
+debian-codename() {
+ isdeb || return 0
+ local policy="$(apt-cache policy)"
+ archive=$(debian-archive "$policy")
+ echo "$policy" | sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q"
+}
isfedora() {
- local d=$(distro_name)
- [[ $d == fedora ]] || return 1
+ [[ $(distro-name) == fedora ]]
}
isdebian() {
- local d=$(distro_name)
- [[ $d == debian ]] || return 1
+ [[ $(distro-name) == debian ]]
}
-isdeb() {
- local d=$(distro_name)
- [[ $d == debian || $d == ubuntu ]] || return 1
+isarch() {
+ [[ $(distro-name) == arch ]]
}
+# is debian/apt based
+isdeb() { command -v apt-get &>/dev/null; }
isubuntu() {
- local d=$(distro_name)
- [[ $d == ubuntu ]] || return 1
+ [[ $(distro-name) == ubuntu ]]
}