Update with support for mac

This commit is contained in:
2025-10-30 16:16:50 +01:00
parent 30871760b9
commit 5bdff0d436
9 changed files with 689 additions and 171 deletions
+196
View File
@@ -0,0 +1,196 @@
#!/bin/bash
# OS Detection and Path Configuration
# This script provides OS-specific paths and configurations
# Detect OS
DetectOS() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "linux"
else
echo "unknown"
fi
}
# Get config directory for Filebeat
GetFilebeatConfigDir() {
local os=$(DetectOS)
case "$os" in
macos)
echo "/usr/local/etc/filebeat"
;;
linux)
echo "/etc/filebeat"
;;
*)
echo "/etc/filebeat"
;;
esac
}
# Get config directory for Metricbeat
GetMetricbeatConfigDir() {
local os=$(DetectOS)
case "$os" in
macos)
echo "/usr/local/etc/metricbeat"
;;
linux)
echo "/etc/metricbeat"
;;
*)
echo "/etc/metricbeat"
;;
esac
}
# Get config directory for Logstash
GetLogstashConfigDir() {
local os=$(DetectOS)
case "$os" in
macos)
# Homebrew installation path
echo "/usr/local/etc/logstash"
;;
linux)
echo "/etc/logstash"
;;
*)
echo "/etc/logstash"
;;
esac
}
# Get logrotate/newsyslog config directory
GetLogRotateConfigDir() {
local os=$(DetectOS)
case "$os" in
macos)
# macOS uses newsyslog instead of logrotate
echo "/usr/local/etc/newsyslog.d"
;;
linux)
echo "/etc/logrotate.d"
;;
*)
echo "/etc/logrotate.d"
;;
esac
}
# Check if logrotate is available
IsLogRotateAvailable() {
local os=$(DetectOS)
case "$os" in
macos)
# macOS uses newsyslog
command -v newsyslog &> /dev/null
;;
linux)
command -v logrotate &> /dev/null
;;
*)
command -v logrotate &> /dev/null
;;
esac
}
# Get log rotation command
GetLogRotateCommand() {
local os=$(DetectOS)
case "$os" in
macos)
echo "newsyslog"
;;
linux)
echo "logrotate"
;;
*)
echo "logrotate"
;;
esac
}
# Check if thermal monitoring is supported
IsThermalMonitoringSupported() {
local os=$(DetectOS)
case "$os" in
macos)
# Check if osx-cpu-temp or powermetrics is available
command -v osx-cpu-temp &> /dev/null || [[ -x /usr/bin/powermetrics ]]
;;
linux)
# Check if thermal zones exist
[[ -e /sys/class/thermal/thermal_zone0/type ]]
;;
*)
return 1
;;
esac
}
# Check if power monitoring is supported
IsPowerMonitoringSupported() {
local os=$(DetectOS)
case "$os" in
macos)
# powermetrics requires sudo and is available on all recent macOS versions
[[ -x /usr/bin/powermetrics ]]
;;
linux)
# Check if Intel RAPL is available
[[ -r /sys/class/powercap/intel-rapl:0/energy_uj ]]
;;
*)
return 1
;;
esac
}
# Get OS-specific df flags for disk usage
GetDfFlags() {
local os=$(DetectOS)
case "$os" in
macos)
# macOS df doesn't support --output flag
echo ""
;;
linux)
echo "--output=target,used,size -B1"
;;
*)
echo ""
;;
esac
}
# Get service management command (systemctl vs launchctl)
GetServiceCommand() {
local os=$(DetectOS)
case "$os" in
macos)
echo "brew services"
;;
linux)
echo "systemctl"
;;
*)
echo "systemctl"
;;
esac
}
# Export functions for sourcing
export -f DetectOS
export -f GetFilebeatConfigDir
export -f GetMetricbeatConfigDir
export -f GetLogstashConfigDir
export -f GetLogRotateConfigDir
export -f IsLogRotateAvailable
export -f GetLogRotateCommand
export -f IsThermalMonitoringSupported
export -f IsPowerMonitoringSupported
export -f GetDfFlags
export -f GetServiceCommand