Streamline fish installer script

This commit is contained in:
Manuel Thalmann 2024-11-02 13:50:51 +01:00
parent 6a2ba5799e
commit d553fd6c8f

View file

@ -2,6 +2,14 @@
begin begin
set -l dir (status dirname) set -l dir (status dirname)
set -l actions \
install \
installSW \
configure \
configureSW \
userConfig \
userConfig
functions -e installSW functions -e installSW
functions -e configureSW functions -e configureSW
functions -e userConfig functions -e userConfig
@ -14,24 +22,18 @@ begin
runPSUserAction "$script" ConfigureUser "$name" runPSUserAction "$script" ConfigureUser "$name"
end end
function inherit -a script -d "Inherits the installer from the specified script." function inherit -V actions -a script -d "Inherits the installer from the specified script."
set -l actions \
installSW \
install \
configureSW \
configure \
userConfig \
userConfig
for i in (seq 1 2 (count $actions)) for i in (seq 1 2 (count $actions))
set -l functionName "$actions[$i]Base" set -l action $actions[$i]
set -l functionName $actions[(math $i + 1)]
set -l baseName $functionName"Base"
function $functionName -V script -V actions -V i function $baseName -V script -V action
fish "$script" $actions[(math $i + 1)] $argv fish "$script" $action $argv
end end
function $actions[$i] -V functionName function $functionName -V baseName
$functionName $argv $baseName $argv
end end
end end
end end
@ -42,7 +44,7 @@ begin
runInstallerAction $name $argv runInstallerAction $name $argv
end end
function runInstallerAction -V dir function runInstallerAction -V dir -V actions
argparse "force" -- $argv argparse "force" -- $argv
set -l install set -l install
set -l args $_flag_force set -l args $_flag_force
@ -62,38 +64,59 @@ begin
set install false set install false
end end
if [ -z "$action" ] || [ "$action" = install ] if [ -z "$action" ]
if functions -q installSW && $install set action install
echo "Installing `$name`..." end
installSW $argv[3..]
end
runInstallerAction $args $name configure for i in (seq 1 2 (count $actions))
if [ "$action" = "$actions[$i]" ]
set -l message
set -l function $actions[(math $i + 1)]
set -l argv $argv[3..]
set -l postRun "__postRun"
functions -e $postRun
if not isConfigured || [ "$USER" != (getConfig "valhalla.setupUser.name") ] switch "$action"
runInstallerAction $args $name userConfig case install
end set message "Installing `$name`..."
else if [ "$action" = configure ]
if functions -q configureSW && $install
echo "Configuring `$name`..."
configureSW $argv[3..]
end
else if [ "$action" = userConfig ]
set -l user $argv[3]
if [ -z "$user" ] function $postRun -V args -V name
set user "$USER" runInstallerAction $args $name configure
end
if isProgramEnabled "$name" "$user" || $force if not isConfigured || [ "$USER" != (getConfig "valhalla.setupUser.name") ]
set install true runInstallerAction $args $name userConfig
else end
set install false end
end case configure
set message "Configuring `$name`..."
case userConfig
set -l user $argv[1]
set argv $argv[2..]
if functions -q userConfig && $install if [ -z "$user" ]
echo "Configuring `$name` for `$user`..." set user "$USER"
userConfig "$user" $argv[4..] end
if isProgramEnabled "$name" "$user" || $force
set install true
else
set install false
end
set message "Configuring `$name` for `$user`..."
end
if functions -q "$function" && $install
if [ -n "$message" ]
echo $message
end
"$function" $argv
end
if functions -q $postRun
$postRun
end
end end
end end
end end