Streamline fish installer script
This commit is contained in:
parent
421cd32373
commit
027e0f9fd6
1 changed files with 65 additions and 42 deletions
|
@ -2,6 +2,14 @@
|
|||
begin
|
||||
set -l dir (status dirname)
|
||||
|
||||
set -l actions \
|
||||
install \
|
||||
installSW \
|
||||
configure \
|
||||
configureSW \
|
||||
userConfig \
|
||||
userConfig
|
||||
|
||||
functions -e installSW
|
||||
functions -e configureSW
|
||||
functions -e userConfig
|
||||
|
@ -14,24 +22,18 @@ begin
|
|||
runPSUserAction "$script" ConfigureUser "$name"
|
||||
end
|
||||
|
||||
function inherit -a script -d "Inherits the installer from the specified script."
|
||||
set -l actions \
|
||||
installSW \
|
||||
install \
|
||||
configureSW \
|
||||
configure \
|
||||
userConfig \
|
||||
userConfig
|
||||
|
||||
function inherit -V actions -a script -d "Inherits the installer from the specified script."
|
||||
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
|
||||
fish "$script" $actions[(math $i + 1)] $argv
|
||||
function $baseName -V script -V action
|
||||
fish "$script" $action $argv
|
||||
end
|
||||
|
||||
function $actions[$i] -V functionName
|
||||
$functionName $argv
|
||||
function $functionName -V baseName
|
||||
$baseName $argv
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -42,7 +44,7 @@ begin
|
|||
runInstallerAction $name $argv
|
||||
end
|
||||
|
||||
function runInstallerAction -V dir
|
||||
function runInstallerAction -V dir -V actions
|
||||
argparse "force" -- $argv
|
||||
set -l install
|
||||
set -l args $_flag_force
|
||||
|
@ -62,38 +64,59 @@ begin
|
|||
set install false
|
||||
end
|
||||
|
||||
if [ -z "$action" ] || [ "$action" = install ]
|
||||
if functions -q installSW && $install
|
||||
echo "Installing `$name`..."
|
||||
installSW $argv[3..]
|
||||
end
|
||||
if [ -z "$action" ]
|
||||
set action install
|
||||
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") ]
|
||||
runInstallerAction $args $name userConfig
|
||||
end
|
||||
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]
|
||||
switch "$action"
|
||||
case install
|
||||
set message "Installing `$name`..."
|
||||
|
||||
if [ -z "$user" ]
|
||||
set user "$USER"
|
||||
end
|
||||
function $postRun -V args -V name
|
||||
runInstallerAction $args $name configure
|
||||
|
||||
if isProgramEnabled "$name" "$user" || $force
|
||||
set install true
|
||||
else
|
||||
set install false
|
||||
end
|
||||
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 functions -q userConfig && $install
|
||||
echo "Configuring `$name` for `$user`..."
|
||||
userConfig "$user" $argv[4..]
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue