aboutsummaryrefslogtreecommitdiff
path: root/utils/identify
blob: 2223d8fc3c22d3aaaf85caecdbe22d3c959cafc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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