✨ add find-service-config script
Some checks failed
Build all NixOS Configurations / nix build (push) Failing after 20m25s
Some checks failed
Build all NixOS Configurations / nix build (push) Failing after 20m25s
This commit is contained in:
parent
2c95eb5946
commit
f52ff2dbcc
4 changed files with 54 additions and 0 deletions
|
@ -152,6 +152,7 @@
|
|||
inherit (self.packages.${system})
|
||||
otpmenu
|
||||
nsxiv
|
||||
find-service-config
|
||||
;
|
||||
})
|
||||
];
|
||||
|
@ -304,6 +305,7 @@
|
|||
boot.loader.systemd-boot.configurationLimit = lib.mkDefault 10;
|
||||
boot.loader.generic-extlinux-compatible.configurationLimit = lib.mkDefault 10;
|
||||
boot.loader.grub.configurationLimit = lib.mkDefault 10;
|
||||
environment.systemPackages = [ pkgs.find-service-config ];
|
||||
}
|
||||
)
|
||||
# My Structure
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
{
|
||||
packages.pkl = callPackage ./pkl { };
|
||||
packages.otpmenu = callPackage ./otpmenu { };
|
||||
packages.find-service-config = callPackage ./find-service-config { };
|
||||
#packages.sononym = callPackage ./sononym { };
|
||||
#packages.sononym-crawler = callPackage ./sononym-crawler { };
|
||||
|
||||
|
|
3
nix/packages/find-service-config/default.nix
Normal file
3
nix/packages/find-service-config/default.nix
Normal file
|
@ -0,0 +1,3 @@
|
|||
{ pkgs }:
|
||||
|
||||
pkgs.writers.writeBashBin "find-service-config" (pkgs.lib.fileContents ./find-service-config.sh)
|
48
nix/packages/find-service-config/find-service-config.sh
Normal file
48
nix/packages/find-service-config/find-service-config.sh
Normal file
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Funktion zum Anzeigen der Nutzung
|
||||
display_usage() {
|
||||
echo "Usage: $0 <service> <regex>"
|
||||
echo " <service>: Name des Systemdienstes"
|
||||
echo " <regex>: Regex für die Konfigurationsdatei"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Prüfen, ob genügend Argumente übergeben wurden
|
||||
if [ $# -ne 2 ]; then
|
||||
display_usage
|
||||
fi
|
||||
|
||||
SERVICE=$1
|
||||
REGEX=$2
|
||||
|
||||
# Holen der Service-Konfiguration
|
||||
description=$(systemctl cat "$SERVICE" 2>/dev/null)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Fehler: Service '$SERVICE' konnte nicht gefunden werden."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Durchsuchen der Ausgabe nach der gesamten Zeile, die mit ExecStart beginnt, und Aufspalten in Strings
|
||||
CONFIG_FILE=$(echo "$description" | grep -oP "(?<=ExecStart=).*" | tr ' ' '\n' | grep -E "$REGEX" | head -n 1)
|
||||
|
||||
if [ -n "$CONFIG_FILE" ]; then
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
echo "Gefundene Datei: $CONFIG_FILE"
|
||||
read -p "Möchten Sie den Inhalt der Datei anzeigen? (Y/n): " CONFIRM
|
||||
if [[ -z "$CONFIRM" || "$CONFIRM" =~ ^[Yy]$ ]]; then
|
||||
cat "$CONFIG_FILE"
|
||||
else
|
||||
echo "Anzeigen der Datei abgebrochen."
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
echo "Fehler: Gefundene Datei '$CONFIG_FILE' existiert nicht oder ist nicht lesbar."
|
||||
exit 3
|
||||
fi
|
||||
else
|
||||
echo "Fehler: Keine Datei gefunden, die dem Regex '$REGEX' entspricht."
|
||||
echo "Die aktuelle Ausgabe von 'systemctl cat $SERVICE':"
|
||||
echo "$description"
|
||||
exit 4
|
||||
fi
|
Loading…
Reference in a new issue