Improve OS detection, exit on unsupported OSs
This commit is contained in:
parent
723e49488d
commit
0482efc7de
4 changed files with 31 additions and 1 deletions
9
docs/system_detection.md
Normal file
9
docs/system_detection.md
Normal file
|
@ -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.
|
|
@ -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"
|
||||
|
|
19
src/system.sh
Normal file
19
src/system.sh
Normal file
|
@ -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
|
||||
}
|
3
src/tori
3
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=
|
||||
|
|
Loading…
Reference in a new issue