aboutsummaryrefslogtreecommitdiff
path: root/utils/identify
diff options
context:
space:
mode:
authorKarel Kočí <karel.koci@nic.cz>2017-07-21 14:58:13 +0200
committerKarel Kočí <karel.koci@nic.cz>2017-07-21 14:58:13 +0200
commit65f52ead41dc6df73671ddd3a8c6a2edecb6dfb3 (patch)
tree31b650900406fd2f8f2b474a0806e35a95190c26 /utils/identify
downloadmulticonfig-65f52ead41dc6df73671ddd3a8c6a2edecb6dfb3.tar.gz
multiconfig-65f52ead41dc6df73671ddd3a8c6a2edecb6dfb3.tar.bz2
multiconfig-65f52ead41dc6df73671ddd3a8c6a2edecb6dfb3.zip
Initial base files ... more to come
Diffstat (limited to 'utils/identify')
-rw-r--r--utils/identify55
1 files changed, 55 insertions, 0 deletions
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