Compare commits
3 commits
df1ffcbedf
...
0482efc7de
Author | SHA1 | Date | |
---|---|---|---|
0482efc7de | |||
723e49488d | |||
e81f8f0227 |
7 changed files with 75 additions and 31 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.
|
|
@ -1,4 +1,6 @@
|
|||
. "$TORI_ROOT/src/check.sh"
|
||||
. "$TORI_ROOT/src/configuration.sh"
|
||||
. "$TORI_ROOT/src/package.sh"
|
||||
. "$TORI_ROOT/src/package/package.sh"
|
||||
. "$TORI_ROOT/src/package/package_resolution.sh"
|
||||
. "$TORI_ROOT/src/utility.sh"
|
||||
. "$TORI_ROOT/src/system.sh"
|
||||
|
|
27
src/package/package.sh
Normal file
27
src/package/package.sh
Normal file
|
@ -0,0 +1,27 @@
|
|||
# package management functions
|
||||
|
||||
get_user_packages() {
|
||||
cat $CONFIG_ROOT/packages | sort | uniq
|
||||
}
|
||||
|
||||
package_manager() {
|
||||
local command="$1"
|
||||
local manager
|
||||
local args__get_manually_installed
|
||||
local output
|
||||
|
||||
if [ $OS = "FreeBSD" ]; then
|
||||
manager="pkg"
|
||||
args__get_manually_installed='query -e "%a = 0" "%n"'
|
||||
fi
|
||||
|
||||
if [ "$command" = 'get_manually_installed' ]; then
|
||||
output=$(eval $manager $args__get_manually_installed)
|
||||
printf "$output"
|
||||
fi
|
||||
}
|
||||
|
||||
get_system_packages() {
|
||||
local packages=$(package_manager get_manually_installed)
|
||||
printf "$packages"
|
||||
}
|
|
@ -1,31 +1,3 @@
|
|||
# package management functions
|
||||
|
||||
get_user_packages() {
|
||||
cat $CONFIG_ROOT/packages | sort | uniq
|
||||
}
|
||||
|
||||
package_manager() {
|
||||
local command="$1"
|
||||
local manager
|
||||
local args__get_manually_installed
|
||||
local output
|
||||
|
||||
if [ $OS = "FreeBSD" ]; then
|
||||
manager="pkg"
|
||||
args__get_manually_installed='query -e "%a = 0" "%n"'
|
||||
fi
|
||||
|
||||
if [ "$command" = 'get_manually_installed' ]; then
|
||||
output=$(eval $manager $args__get_manually_installed)
|
||||
printf "$output"
|
||||
fi
|
||||
}
|
||||
|
||||
get_system_packages() {
|
||||
local packages=$(package_manager get_manually_installed)
|
||||
printf "$packages"
|
||||
}
|
||||
|
||||
resolve_packages() {
|
||||
local strategy=
|
||||
|
||||
|
@ -50,6 +22,8 @@ resolve_packages() {
|
|||
|
||||
if [ "$strategy" = 1 ]; then
|
||||
: # TODO
|
||||
elif [ $strategy -eq 6 ]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -68,6 +42,8 @@ resolve_packages() {
|
|||
|
||||
if [ $strategy -eq 1 ]; then
|
||||
: # TODO
|
||||
elif [ $strategy -eq 6 ]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
}
|
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
|
||||
}
|
5
src/tori
5
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"
|
||||
|
@ -13,8 +14,10 @@ TMP_DIR="/tmp/tori"
|
|||
argument="$1"
|
||||
parameter="$2"
|
||||
|
||||
set_opts -
|
||||
|
||||
## global constants
|
||||
OS="$(uname -s)"
|
||||
OS="$(get_operating_system)"
|
||||
|
||||
## global state
|
||||
base_files=
|
||||
|
|
|
@ -13,6 +13,14 @@ log() {
|
|||
fi
|
||||
}
|
||||
|
||||
set_opts() {
|
||||
sign="$1"
|
||||
|
||||
set "${sign}o" errexit
|
||||
set "${sign}o" nounset
|
||||
set "${sign}o" pipefail
|
||||
}
|
||||
|
||||
prepare_directories() {
|
||||
if ! [ -d "$TMP_DIR" ]; then
|
||||
mkdir "$TMP_DIR"
|
||||
|
|
Loading…
Reference in a new issue