From 0482efc7de5a9c997103b1d7cbabf772ef5653a5 Mon Sep 17 00:00:00 2001 From: jutty Date: Sun, 7 Jul 2024 16:16:21 -0300 Subject: [PATCH] Improve OS detection, exit on unsupported OSs --- docs/system_detection.md | 9 +++++++++ src/index.sh | 1 + src/system.sh | 19 +++++++++++++++++++ src/tori | 3 ++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 docs/system_detection.md create mode 100644 src/system.sh diff --git a/docs/system_detection.md b/docs/system_detection.md new file mode 100644 index 0000000..88e6579 --- /dev/null +++ b/docs/system_detection.md @@ -0,0 +1,9 @@ +tori determines what is the running operating system through the output of `uname -s`. If it cannot get a descriptive enough, it will look for the `/etc/os-release` file. + +If a `/etc/os-release` file is present, it takes precedence over the output of `uname`. Both the `NAME` and `ID` values will be looked at. This is aimed at helping to disambiguate between different variants of the same operating system. + +The `NAME` value may be the only queried value if for the given supported operating system it is enough to disambiguate between the variants tori needs to be aware of. + +In case there is no `/etc/os-release` file found, the output of `uname` is the next value considered. + +If a supported operating system is not detected on neither of these, tori will exit with an error. diff --git a/src/index.sh b/src/index.sh index a2d03e6..401c982 100644 --- a/src/index.sh +++ b/src/index.sh @@ -3,3 +3,4 @@ . "$TORI_ROOT/src/package/package.sh" . "$TORI_ROOT/src/package/package_resolution.sh" . "$TORI_ROOT/src/utility.sh" +. "$TORI_ROOT/src/system.sh" diff --git a/src/system.sh b/src/system.sh new file mode 100644 index 0000000..4dd8529 --- /dev/null +++ b/src/system.sh @@ -0,0 +1,19 @@ +get_operating_system() { + local uname_output="$(uname -s)" + local os_release_name="$(cat \ + /etc/os-release | grep '^NAME=' | sed 's/NAME=//')" + local os_release_id="$(cat \ + /etc/os-release | grep '^ID=' | sed 's/ID=//')" + + log debug "uname OS: $uname_output" + log debug "os-release OS name: $os_release_name" + log debug "os-release OS ID: $os_release_id" + + if [ "$os_release_name" = FreeBSD ]; then + echo "FreeBSD" + return 0 + else + log fatal "Unsupported operating system" + return 1 + fi +} diff --git a/src/tori b/src/tori index a025a5d..078ee42 100755 --- a/src/tori +++ b/src/tori @@ -1,5 +1,6 @@ #! /usr/bin/env sh +# paths VERSION="0.0.4 2024-06-30" TORI_ROOT="$HOME/tori" CONFIG_ROOT="$HOME/.config/tori" @@ -16,7 +17,7 @@ parameter="$2" set_opts - ## global constants -OS="$(uname -s)" +OS="$(get_operating_system)" ## global state base_files=