explorer/os: get ID from /etc/os-release

/etc/os-release was introduced by systemd[1] and is now
more and more common; even on systems without systemd (e.g. lede).
In addition to detecting the OS based on specific attributes,
this file provides the ID marker to describe the OS.

This commit adds support for OS detection via /etc/os-release.
According to [2], it is already lowercase.

[1] http://0pointer.de/blog/projects/os-release
[2] https://www.freedesktop.org/software/systemd/man/os-release.html
This commit is contained in:
Philippe Grégoire 2017-08-19 16:41:50 -04:00
parent ceb97fd0ee
commit 69c6de9f9c
No known key found for this signature in database
GPG key ID: A14AA6DA679C2177

View file

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) # 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
# Copyright 2017, Philippe Gregoire <pg@pgregoire.xyz>
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -139,5 +140,12 @@ case "$uname_s" in
;; ;;
esac esac
if [ -f /etc/os-release ]; then
# already lowercase, according to:
# https://www.freedesktop.org/software/systemd/man/os-release.html
grep '^ID=' /etc/os-release | sed -e 's|^ID=||'
exit 0
fi
echo "Unknown OS" >&2 echo "Unknown OS" >&2
exit 1 exit 1