2024-07-13 16:36:24 +00:00
|
|
|
#!/bin/env fish
|
|
|
|
begin
|
2024-07-20 01:50:38 +00:00
|
|
|
set -l dir (status dirname)
|
|
|
|
|
2024-11-02 12:50:51 +00:00
|
|
|
set -l actions \
|
|
|
|
install \
|
|
|
|
installSW \
|
|
|
|
configure \
|
|
|
|
configureSW \
|
|
|
|
userConfig \
|
|
|
|
userConfig
|
|
|
|
|
2024-11-02 12:55:21 +00:00
|
|
|
for i in (seq 2 2 (count $actions))
|
|
|
|
functions -e "$actions[$i]"
|
|
|
|
end
|
2024-07-13 16:36:24 +00:00
|
|
|
|
2024-10-11 23:01:01 +00:00
|
|
|
function runPSUserAction -a script action name
|
|
|
|
pwsh -CommandWithArgs '& $args[0] $args[1] @{ name=$args[2]; }' "$script" "$action" "$name"
|
|
|
|
end
|
|
|
|
|
2024-09-22 21:51:38 +00:00
|
|
|
function runPSUserConfig -a script name
|
2024-10-11 23:01:01 +00:00
|
|
|
runPSUserAction "$script" ConfigureUser "$name"
|
2024-09-22 21:51:38 +00:00
|
|
|
end
|
|
|
|
|
2024-11-02 12:50:51 +00:00
|
|
|
function inherit -V actions -a script -d "Inherits the installer from the specified script."
|
2024-10-11 23:54:31 +00:00
|
|
|
for i in (seq 1 2 (count $actions))
|
2024-11-02 12:50:51 +00:00
|
|
|
set -l action $actions[$i]
|
|
|
|
set -l functionName $actions[(math $i + 1)]
|
|
|
|
set -l baseName $functionName"Base"
|
2024-10-11 23:54:31 +00:00
|
|
|
|
2024-11-02 12:50:51 +00:00
|
|
|
function $baseName -V script -V action
|
|
|
|
fish "$script" $action $argv
|
2024-10-11 23:54:31 +00:00
|
|
|
end
|
|
|
|
|
2024-11-02 12:50:51 +00:00
|
|
|
function $functionName -V baseName
|
|
|
|
$baseName $argv
|
2024-10-11 23:54:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-09-21 15:32:49 +00:00
|
|
|
function runInstaller -V dir -a action
|
|
|
|
set -l path (status stack-trace | head -n4 | tail -n1 | string replace --regex -- '^\s*called on line \d+ of file (.*)$' '$1')
|
|
|
|
set -l name (basename (dirname $path))
|
|
|
|
runInstallerAction $name $argv
|
2024-07-20 01:50:38 +00:00
|
|
|
end
|
|
|
|
|
2024-11-02 12:50:51 +00:00
|
|
|
function runInstallerAction -V dir -V actions
|
2024-10-13 20:07:15 +00:00
|
|
|
argparse "force" -- $argv
|
|
|
|
set -l install
|
|
|
|
set -l args $_flag_force
|
|
|
|
set -l name $argv[1]
|
|
|
|
set -l action $argv[2]
|
2024-10-31 23:38:33 +00:00
|
|
|
source "$dir/settings.fish"
|
2024-09-13 12:47:07 +00:00
|
|
|
|
2024-10-13 20:07:15 +00:00
|
|
|
if [ -n "$_flag_force" ]
|
|
|
|
set force true
|
|
|
|
else
|
|
|
|
set force false
|
|
|
|
end
|
|
|
|
|
|
|
|
if isProgramEnabled $name || $force
|
|
|
|
set install true
|
|
|
|
else
|
|
|
|
set install false
|
|
|
|
end
|
|
|
|
|
2024-11-02 12:50:51 +00:00
|
|
|
if [ -z "$action" ]
|
|
|
|
set action install
|
|
|
|
end
|
2024-10-13 20:07:15 +00:00
|
|
|
|
2024-11-02 12:50:51 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
switch "$action"
|
|
|
|
case install
|
|
|
|
set message "Installing `$name`..."
|
|
|
|
|
|
|
|
function $postRun -V args -V name
|
|
|
|
runInstallerAction $args $name configure
|
|
|
|
|
|
|
|
if not isConfigured || [ "$USER" != (getConfig "valhalla.setupUser.name") ]
|
|
|
|
runInstallerAction $args $name userConfig
|
|
|
|
end
|
|
|
|
end
|
|
|
|
case configure
|
|
|
|
set message "Configuring `$name`..."
|
|
|
|
case userConfig
|
|
|
|
set -l user $argv[1]
|
|
|
|
set argv $argv[2..]
|
|
|
|
|
|
|
|
if [ -z "$user" ]
|
|
|
|
set user "$USER"
|
|
|
|
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
|
2024-09-21 15:32:49 +00:00
|
|
|
end
|
2024-07-13 16:36:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|