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 17:26:21 +00:00
|
|
|
set -l backupActions \
|
2024-11-02 19:56:54 +00:00
|
|
|
backup backupSW prepareBackup prepareBackup backupArgs getBackupArgs restore restoreSW \
|
|
|
|
userBackup userBackup prepareUserBackup prepareUserBackup userBackupArgs getUserBackupArgs userRestore userRestore
|
2024-11-02 17:26:21 +00:00
|
|
|
|
2024-11-02 12:50:51 +00:00
|
|
|
set -l actions \
|
2024-11-02 17:25:14 +00:00
|
|
|
install installSW \
|
|
|
|
configure configureSW \
|
2024-11-05 16:45:13 +00:00
|
|
|
userConfig userConfig \
|
|
|
|
dependencies installSWDependencies
|
2024-11-02 12:50:51 +00:00
|
|
|
|
2024-11-02 17:26:21 +00:00
|
|
|
set -a actions $backupActions
|
|
|
|
|
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-11-02 19:56:54 +00:00
|
|
|
for i in (seq 1 8 (count $backupActions))
|
|
|
|
set -l preRun $backupActions[(math $i + 3)]
|
2024-11-02 17:26:21 +00:00
|
|
|
set -l function $backupActions[(math $i + 1)]
|
2024-11-02 19:56:54 +00:00
|
|
|
set -l getArgs $backupActions[(math $i + 5)]
|
|
|
|
set -l restore $backupActions[(math $i + 7)]
|
2024-11-02 17:26:21 +00:00
|
|
|
|
|
|
|
for functionName in $function $restore
|
2024-11-02 19:56:54 +00:00
|
|
|
function $functionName -V dir -V preRun -V getArgs -V functionName -V restore
|
2024-11-02 17:26:21 +00:00
|
|
|
set -l args
|
|
|
|
|
|
|
|
if functions -q $getArgs
|
|
|
|
set args ($getArgs $argv)
|
|
|
|
end
|
|
|
|
|
|
|
|
if [ "$functionName" = "$restore" ] || [ -n "$args" ]
|
|
|
|
for arg in name user
|
|
|
|
set -l varName "_flag_$arg"
|
|
|
|
|
|
|
|
begin
|
|
|
|
set -l backup $argv
|
|
|
|
argparse -i "$arg=" -- $args
|
|
|
|
set -l argv $backup
|
|
|
|
end
|
2024-11-29 00:13:58 +00:00
|
|
|
|
2024-11-02 17:26:21 +00:00
|
|
|
if [ -z "$$varName" ]
|
|
|
|
argparse -i "$arg=" -- $argv
|
|
|
|
set -a args "--$arg" "$$varName"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
source "$dir/restoration.fish"
|
|
|
|
|
|
|
|
if [ "$functionName" != "$restore" ]
|
2024-11-02 19:56:54 +00:00
|
|
|
argparse -i "action=" -- $argv
|
|
|
|
|
|
|
|
if functions -q "$preRun"
|
|
|
|
"$preRun" $argv
|
|
|
|
end
|
|
|
|
|
2024-11-02 17:26:21 +00:00
|
|
|
backupFiles $args
|
|
|
|
else
|
|
|
|
restoreFiles $args
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-11-02 17:14:54 +00:00
|
|
|
function runPSUserAction
|
|
|
|
argparse -i "script=" "action=" "user=" -- $argv
|
|
|
|
|
|
|
|
if [ -z "$_flag_script" ]
|
|
|
|
set _flag_script $argv[1]
|
|
|
|
end
|
|
|
|
|
2024-12-11 00:12:52 +00:00
|
|
|
pwsh -NoProfile -CommandWithArgs '& $args[0] $args[1] @{ name=$args[2]; }' "$_flag_script" "$_flag_action" "$_flag_user"
|
2024-10-11 23:01:01 +00:00
|
|
|
end
|
|
|
|
|
2024-11-02 17:14:54 +00:00
|
|
|
function runPSUserConfig
|
|
|
|
runPSUserAction $argv --action ConfigureUser
|
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
|
2024-11-02 17:14:54 +00:00
|
|
|
argparse -i "action=" -- $argv
|
2024-11-02 12:50:51 +00:00
|
|
|
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
|
2024-11-02 17:14:54 +00:00
|
|
|
argparse -i "name=" -- $argv
|
|
|
|
|
|
|
|
if [ -z "$_flag_name" ]
|
|
|
|
set -l path (status stack-trace | head -n4 | tail -n1 | string replace --regex -- '^\s*called on line \d+ of file (.*)$' '$1')
|
|
|
|
set _flag_name (basename (dirname $path))
|
|
|
|
end
|
|
|
|
|
|
|
|
runInstallerAction --name "$_flag_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-11-29 00:13:58 +00:00
|
|
|
argparse -i force "name=" "action=" -- $argv
|
2024-10-13 20:07:15 +00:00
|
|
|
set -l install
|
2024-11-02 17:14:54 +00:00
|
|
|
set -l name $_flag_name
|
|
|
|
set -l action $_flag_action
|
|
|
|
set -l args $_flag_force --name "$name"
|
2024-11-29 00:13:58 +00:00
|
|
|
set -l dependencyFunction installSWDependencies
|
2024-11-05 16:45:13 +00:00
|
|
|
set -l installDependencies
|
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
|
|
|
|
|
2024-11-05 16:45:13 +00:00
|
|
|
if functions -q "$dependencyFunction"
|
|
|
|
set installDependencies __runSosftwareDependencyInstaller
|
|
|
|
functions -c "$dependencyFunction" "$installDependencies"
|
|
|
|
functions -e "$dependencyFunction"
|
|
|
|
end
|
|
|
|
|
2024-12-05 15:01:41 +00:00
|
|
|
if $force || isProgramEnabled $args
|
2024-10-13 20:07:15 +00:00
|
|
|
set install true
|
|
|
|
else
|
|
|
|
set install false
|
|
|
|
end
|
|
|
|
|
2024-11-02 12:50:51 +00:00
|
|
|
if [ -z "$action" ]
|
2024-11-02 17:14:54 +00:00
|
|
|
if [ -n "$argv[1]" ]
|
|
|
|
set action $argv[1]
|
|
|
|
set argv $argv[2..]
|
|
|
|
else
|
|
|
|
set action install
|
|
|
|
end
|
2024-11-02 12:50:51 +00:00
|
|
|
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)]
|
2024-11-29 00:13:58 +00:00
|
|
|
set -l preRun __preRun
|
|
|
|
set -l postRun __postRun
|
2024-11-02 17:26:21 +00:00
|
|
|
functions -e $preRun
|
2024-11-02 12:50:51 +00:00
|
|
|
functions -e $postRun
|
|
|
|
|
|
|
|
switch "$action"
|
|
|
|
case install
|
|
|
|
set message "Installing `$name`..."
|
|
|
|
|
2024-11-02 17:14:54 +00:00
|
|
|
function $postRun -V args
|
|
|
|
runInstallerAction $args --action configure
|
2024-11-02 12:50:51 +00:00
|
|
|
|
|
|
|
if not isConfigured || [ "$USER" != (getConfig "valhalla.setupUser.name") ]
|
2024-11-02 17:14:54 +00:00
|
|
|
runInstallerAction $args --action userConfig
|
2024-11-02 12:50:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
case configure
|
|
|
|
set message "Configuring `$name`..."
|
2024-11-02 17:26:21 +00:00
|
|
|
|
|
|
|
function $preRun -V args
|
|
|
|
runInstallerAction $args --action restore
|
|
|
|
end
|
|
|
|
case userConfig userBackup userRestore
|
2024-11-02 17:14:54 +00:00
|
|
|
argparse -i "user=" -- $argv
|
|
|
|
set -l user "$_flag_user"
|
2024-11-02 12:50:51 +00:00
|
|
|
|
|
|
|
if [ -z "$user" ]
|
|
|
|
set user "$USER"
|
2024-11-02 17:14:54 +00:00
|
|
|
set -a args --user "$user"
|
2024-11-02 12:50:51 +00:00
|
|
|
end
|
|
|
|
|
2024-12-05 15:01:41 +00:00
|
|
|
if $force || isProgramEnabled $args
|
2024-11-02 12:50:51 +00:00
|
|
|
set install true
|
|
|
|
else
|
|
|
|
set install false
|
|
|
|
end
|
|
|
|
|
2024-11-02 17:26:21 +00:00
|
|
|
switch "$action"
|
|
|
|
case userConfig
|
|
|
|
set message "Configuring `$name` for `$user`..."
|
|
|
|
|
|
|
|
function $preRun -V args
|
|
|
|
runInstallerAction $args --action userRestore
|
|
|
|
end
|
|
|
|
case userBackup
|
|
|
|
set message "Backing up `$name` for `$user`..."
|
|
|
|
case userRestore
|
|
|
|
set message "Restoring `$name` for `$user`..."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if functions -q $preRun
|
|
|
|
$preRun
|
2024-11-02 12:50:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if functions -q "$function" && $install
|
|
|
|
if [ -n "$message" ]
|
|
|
|
echo $message
|
|
|
|
end
|
|
|
|
|
2024-11-02 17:14:54 +00:00
|
|
|
"$function" $args $argv
|
2024-11-02 12:50:51 +00:00
|
|
|
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
|
2024-11-05 16:45:13 +00:00
|
|
|
|
|
|
|
if [ -n "$installDependencies" ]
|
|
|
|
"$installDependencies" --action "$action" $args $argv
|
|
|
|
functions -c "$installDependencies" "$dependencyFunction"
|
|
|
|
functions -e "$installDependencies"
|
|
|
|
end
|
2024-07-13 16:36:24 +00:00
|
|
|
end
|
|
|
|
end
|