2024-11-02 17:26:21 +00:00
|
|
|
#!/bin/env fish
|
|
|
|
set -l dir (status dirname)
|
|
|
|
source "$dir/../../lib/action.fish"
|
|
|
|
|
|
|
|
function backupAction -V dir
|
|
|
|
source "$dir/../../lib/hooks.fish"
|
|
|
|
|
|
|
|
if not type -q getDeploymentScript
|
|
|
|
function getDeploymentScript
|
|
|
|
echo "No deployment script specified! No software will be installed." 1>&2
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
set -l deployScript (getDeploymentScript)
|
|
|
|
|
2024-11-23 16:26:12 +00:00
|
|
|
if [ -z "$VALHALLA_BACKUP_DIR" ]
|
|
|
|
if fish "$dir/../../../lib/modules/partition/confirm.fish" "Do you wish to store the backup on an SSH server?" n
|
2024-12-04 17:19:31 +00:00
|
|
|
set -l keyVar VALHALLA_BACKUP_SERVER_KEY
|
|
|
|
set -l keyPath ~root/.config/port-valhalla/valhalla
|
2024-11-23 16:26:12 +00:00
|
|
|
read -xP "Please specify the host name of the SSH server: " VALHALLA_BACKUP_SERVER
|
|
|
|
read -xP "Please specify the port of the SSH server (default 22): " VALHALLA_BACKUP_SERVER_PORT
|
|
|
|
read -xP "Please specify the name of the user to log in to the SSH server: " VALHALLA_BACKUP_SERVER_USER
|
2024-12-04 17:19:31 +00:00
|
|
|
|
|
|
|
if [ -z "$$keyVar" ]
|
|
|
|
set -gx "$keyVar" "$keyPath"
|
|
|
|
sudo mkdir -p (dirname "$keyPath")
|
|
|
|
sudo ssh-keygen -f "$$keyVar" -N ""
|
|
|
|
end
|
2024-11-29 00:13:58 +00:00
|
|
|
|
2024-11-23 16:26:12 +00:00
|
|
|
if [ -z "$VALHALLA_BACKUP_SERVER_PORT" ]
|
|
|
|
set -x VALHALLA_BACKUP_SERVER_PORT 22
|
|
|
|
end
|
2024-11-29 00:13:58 +00:00
|
|
|
|
2024-11-23 16:26:12 +00:00
|
|
|
echo
|
|
|
|
echo "$(tput setaf 3)==== WARNING ====$(tput sgr0)"
|
|
|
|
echo "For a seamless experience, please make sure that you are able to establish an unattended ssh connection using key authentication."
|
|
|
|
echo
|
2024-12-04 17:19:31 +00:00
|
|
|
echo "Your public key is:"
|
|
|
|
cat "$VALHALLA_BACKUP_SERVER_KEY"
|
|
|
|
echo
|
2024-11-23 16:26:12 +00:00
|
|
|
echo "$(tput bold)This command should succeed without user interaction:$(tput sgr0)"
|
2024-11-27 04:52:42 +00:00
|
|
|
echo "sudo ssh -o PasswordAuthentication=no -i $(string escape -- "$VALHALLA_BACKUP_SERVER_KEY") -p $VALHALLA_BACKUP_SERVER_PORT $VALHALLA_BACKUP_SERVER true"
|
2024-11-23 16:26:12 +00:00
|
|
|
read -P "Press enter once you're done: "
|
|
|
|
echo
|
2024-11-02 17:26:21 +00:00
|
|
|
end
|
|
|
|
|
2024-11-23 16:26:12 +00:00
|
|
|
read -xP "Please specify the path to the directory to save the backup to: " VALHALLA_BACKUP_DIR
|
2024-11-02 17:26:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
runHook backupSoftware || begin
|
|
|
|
echo "Backing up software..."
|
|
|
|
|
|
|
|
and if [ -n "$deployScript" ]
|
|
|
|
source $deployScript backup
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
runHook backupUsers || begin
|
|
|
|
if [ -n "$deployScript" ]
|
|
|
|
for name in (getUsers | jq '.[]' --raw-output0 | string split0)
|
|
|
|
echo "Backing up user `$name`..."
|
2024-11-28 21:11:56 +00:00
|
|
|
and source $deployScript userBackup --user $name
|
2024-11-02 17:26:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
runSetupUserAction backupAction
|