documentation
This commit is contained in:
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# Unix-style system checker - does one thing well
|
||||
set -e
|
||||
|
||||
# Check if running on NixOS
|
||||
check_nixos() {
|
||||
[ -f /etc/NIXOS ] || {
|
||||
echo "Not running on NixOS" >&2
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Check permissions (warn if root, but don't block)
|
||||
check_permissions() {
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "Warning: Running as root is not recommended" >&2
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Main check
|
||||
main() {
|
||||
case "${1:-}" in
|
||||
--nixos-only)
|
||||
check_nixos
|
||||
;;
|
||||
--permissions-only)
|
||||
check_permissions
|
||||
;;
|
||||
--quiet|-q)
|
||||
check_nixos >/dev/null 2>&1
|
||||
check_permissions >/dev/null 2>&1
|
||||
;;
|
||||
*)
|
||||
check_nixos
|
||||
check_permissions || true # Don't exit on root warning
|
||||
;;
|
||||
esac
|
||||
|
||||
# Output status for scripting
|
||||
if [[ "${OMNIXY_JSON:-}" == "1" ]]; then
|
||||
echo '{"nixos": true, "root": '$([ "$EUID" -eq 0 ] && echo "true" || echo "false")'}'
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user