From 69c6de9f9c7a5f6107a70f83004d17cb7771ca5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Gr=C3=A9goire?= Date: Sat, 19 Aug 2017 16:41:50 -0400 Subject: [PATCH 1/3] 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 --- cdist/conf/explorer/os | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cdist/conf/explorer/os b/cdist/conf/explorer/os index 094685ea..e0125c1b 100755 --- a/cdist/conf/explorer/os +++ b/cdist/conf/explorer/os @@ -1,6 +1,7 @@ #!/bin/sh # # 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) +# Copyright 2017, Philippe Gregoire # # This file is part of cdist. # @@ -139,5 +140,12 @@ case "$uname_s" in ;; 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 exit 1 From e88e9c357f77b1fbd92dcdcea70bd7e99aa7f328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Gr=C3=A9goire?= Date: Sat, 19 Aug 2017 16:49:19 -0400 Subject: [PATCH 2/3] fix formatting --- cdist/conf/explorer/os | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cdist/conf/explorer/os b/cdist/conf/explorer/os index e0125c1b..77c8a76a 100755 --- a/cdist/conf/explorer/os +++ b/cdist/conf/explorer/os @@ -141,10 +141,10 @@ case "$uname_s" in 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 + # 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 From 2b9bf3de248de66f8159e7f971a1d5299975d7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Gr=C3=A9goire?= Date: Sat, 19 Aug 2017 18:19:17 -0400 Subject: [PATCH 3/3] replace grep+sed by awk --- cdist/conf/explorer/os | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/explorer/os b/cdist/conf/explorer/os index 77c8a76a..d1f3ccb4 100755 --- a/cdist/conf/explorer/os +++ b/cdist/conf/explorer/os @@ -143,7 +143,7 @@ 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=||' + awk -F= '/^ID=/ {print $2;}' /etc/os-release exit 0 fi