From a89d9bb6772093290a0b2bc55ad638157510b68e Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 20 Jul 2024 03:50:38 +0200 Subject: [PATCH] Add function for configuring user settings --- scripts/Common/OS/users.fish | 2 +- scripts/Common/Scripts/config.fish | 4 ++++ scripts/Common/Scripts/software.fish | 22 +++++++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/scripts/Common/OS/users.fish b/scripts/Common/OS/users.fish index c3b810f6..6404fb9a 100644 --- a/scripts/Common/OS/users.fish +++ b/scripts/Common/OS/users.fish @@ -1,7 +1,7 @@ #!/bin/env fish set -l dir (status dirname) source "$dir/../Scripts/config.fish" -set -l users (getConfig valhalla.users --apply "builtins.attrNames" --json) +set -l users (getUsers) for name in (echo "$users" | jq '.[]' --raw-output0 | string split0) diff --git a/scripts/Common/Scripts/config.fish b/scripts/Common/Scripts/config.fish index f0452b49..5d2b96d3 100644 --- a/scripts/Common/Scripts/config.fish +++ b/scripts/Common/Scripts/config.fish @@ -4,6 +4,10 @@ function getConfig -S -a property evalModule "$CONFIG_MODULE" "$property" $argv[2..] end +function getUsers -S + getConfig valhalla.users --apply "builtins.attrNames" --json +end + function isSet -S -a property not test "$(getConfig "$property" --json)" = "null" end diff --git a/scripts/Common/Scripts/software.fish b/scripts/Common/Scripts/software.fish index 6c3ae551..af134368 100644 --- a/scripts/Common/Scripts/software.fish +++ b/scripts/Common/Scripts/software.fish @@ -1,16 +1,36 @@ #!/bin/env fish begin + set -l dir (status dirname) + function installSW end function configureSW end - function runInstaller -a action + function userConfig -a user + end + + function runInstaller -V dir -a action if [ -z "$action" ] || [ "$action" = "install" ] installSW $argv[2..] else if [ "$action" = "configure" ] configureSW $argv[2..] + + source "$dir/config.fish" + set -l users (getUsers) + + for name in (echo "$users" | jq '.[]' --raw-output0 | string split0) + runInstaller userConfig "$name" + end + else if [ "$action" = "userConfig" ] + set -l name $argv[2] + + if [ -z "$name" ] + set name "$USER" + end + + userConfig "$name" $argv[3..] end end end