From 65f52ead41dc6df73671ddd3a8c6a2edecb6dfb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Fri, 21 Jul 2017 14:58:13 +0200 Subject: Initial base files ... more to come --- utils/identify | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 utils/identify (limited to 'utils/identify') diff --git a/utils/identify b/utils/identify new file mode 100644 index 0000000..2223d8f --- /dev/null +++ b/utils/identify @@ -0,0 +1,55 @@ +# vim:ft=sh:noexpandtab +# Identify and set some variables that can be used later by operations + +# Variables: +# DC_OS - Operation system kernel name (uname -s) +# DC_OS_VERSION - Version of kernel used (uname -r) +# DC_ARCH - Machine architecture (uname -m) +# DC_DISTRIBUTION - Distribution of operation system +# DC_INIT - Init system used (service manager) +# On Archlinux: +# DC_PACAUR - This is set to "true" if pacaur is installed on archlinux + +DC_OS="$(uname -s)" +DC_OS_VERSION="$(uname -r)" +DC_ARCH="$(uname -m)" + +if [ "$DC_OS" = "Linux" ]; then + if [ -f /etc/arch-release ]; then + DC_DISTRIBUTION="arch" + elif [ -f /etc/turris-version ]; then + DC_DISTRIBUTION="turris" + elif [ -f /etc/os-release ]; then + # Use as DISTRIBUTION ID field + DC_DISTRIBUTION="$(sed -nE 's/^ID=(.*)/\1/p' /etc/os-release)" + else + DC_DISTRIBUTION="unknown" + fi + # Identify init (only systemd and openrc are supported on linux) + if pidof systemd >/dev/null; then + # Systemd is running on accessed machine + DC_INIT="systemd" + elif pidof procd >/dev/null; then + DC_INIT="procd" + elif rc-status -v 2>/dev/null >/dev/null; then + DC_INIT="openrc" + else + DC_INIT="unknown" + fi + echo_dbg "Detected Linux. Distribution $DC_DISTRIBUTION. With $DC_INIT init system." +elif [ "$DC_OS" = "FreeBSD" ]; then + DC_DISTRIBUTION="FreeBSD" # This makes no sense on FreeBSD so set same as OS + DC_INIT="FreeBSD" + echo_dbg "Detected FreeBSD." +else + echo_die "Unknown or unsupported kernel detected on accessed machine." +fi + +# Archlinux +DC_PACAUR=false +if [ "$DC_DISTRIBUTION" = "arch" ]; then + if which pacaur >/dev/null; then + DC_PACAUR=true + echo_dbg "Accessed machine has pacaur" + fi +fi -- cgit v1.2.3