Compare commits
2 commits
dd2ae9b720
...
4b58f65fa1
Author | SHA1 | Date | |
---|---|---|---|
4b58f65fa1 | |||
e360a158b1 |
3 changed files with 78 additions and 39 deletions
|
@ -57,6 +57,7 @@ in {
|
||||||
linux.programs = {
|
linux.programs = {
|
||||||
docker = {
|
docker = {
|
||||||
services = {
|
services = {
|
||||||
|
anki-sync.enable = true;
|
||||||
drone.enable = true;
|
drone.enable = true;
|
||||||
forgejo.enable = true;
|
forgejo.enable = true;
|
||||||
jellyfin.enable = true;
|
jellyfin.enable = true;
|
||||||
|
|
|
@ -4,6 +4,7 @@ source "$dir/../../lib/action.fish"
|
||||||
|
|
||||||
function backupAction -V dir
|
function backupAction -V dir
|
||||||
source "$dir/../../lib/hooks.fish"
|
source "$dir/../../lib/hooks.fish"
|
||||||
|
source "$dir/../../lib/restoration.fish"
|
||||||
|
|
||||||
if not type -q getDeploymentScript
|
if not type -q getDeploymentScript
|
||||||
function getDeploymentScript
|
function getDeploymentScript
|
||||||
|
@ -13,45 +14,7 @@ function backupAction -V dir
|
||||||
end
|
end
|
||||||
|
|
||||||
set -l deployScript (getDeploymentScript)
|
set -l deployScript (getDeploymentScript)
|
||||||
|
initConfig --action backup
|
||||||
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
|
|
||||||
set -l keyVar VALHALLA_BACKUP_SERVER_KEY
|
|
||||||
set -l keyPath ~root/.config/port-valhalla/valhalla
|
|
||||||
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
|
|
||||||
set -l host "$VALHALLA_BACKUP_SERVER"
|
|
||||||
|
|
||||||
if [ -z "$$keyVar" ]
|
|
||||||
set -gx "$keyVar" "$keyPath"
|
|
||||||
sudo mkdir -p (dirname "$keyPath")
|
|
||||||
sudo ssh-keygen -f "$$keyVar" -N ""
|
|
||||||
end
|
|
||||||
|
|
||||||
if [ -z "$VALHALLA_BACKUP_SERVER_PORT" ]
|
|
||||||
set -x VALHALLA_BACKUP_SERVER_PORT 22
|
|
||||||
end
|
|
||||||
|
|
||||||
if [ -n "$VALHALLA_BACKUP_SERVER_USER" ]
|
|
||||||
set host "$VALHALLA_BACKUP_SERVER_USER@$host"
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
echo "Your public key is:"
|
|
||||||
sudo cat "$VALHALLA_BACKUP_SERVER_KEY.pub"
|
|
||||||
echo
|
|
||||||
echo "$(tput bold)This command should succeed without user interaction:$(tput sgr0)"
|
|
||||||
echo "sudo ssh -o PasswordAuthentication=no -i $(string escape -- "$VALHALLA_BACKUP_SERVER_KEY") -p $VALHALLA_BACKUP_SERVER_PORT $host true"
|
|
||||||
read -P "Press enter once you're done: "
|
|
||||||
echo
|
|
||||||
end
|
|
||||||
|
|
||||||
read -xP "Please specify the path to the directory to save the backup to: " VALHALLA_BACKUP_DIR
|
|
||||||
end
|
|
||||||
|
|
||||||
runHook backupSoftware || begin
|
runHook backupSoftware || begin
|
||||||
echo "Backing up software..."
|
echo "Backing up software..."
|
||||||
|
|
|
@ -1,3 +1,78 @@
|
||||||
|
set -l dir (status dirname)
|
||||||
|
|
||||||
|
function initConfig -V dir -d "Fetches the configuration by prompting the user to "
|
||||||
|
set -l disabled VALHALLA_BACKUP_DISABLED
|
||||||
|
|
||||||
|
if [ -z "$$disabled" ]
|
||||||
|
if [ -z "$VALHALLA_BACKUP_DIR" ]
|
||||||
|
argparse -i "action=" -- $argv
|
||||||
|
set -l index
|
||||||
|
set -l confirm fish "$dir/../../../lib/modules/partition/confirm.fish"
|
||||||
|
|
||||||
|
switch "$_flag_action"
|
||||||
|
case backup
|
||||||
|
set index 1
|
||||||
|
case restore
|
||||||
|
set index 2
|
||||||
|
case '*'
|
||||||
|
set index 3
|
||||||
|
end
|
||||||
|
|
||||||
|
if [ "$_flag_action" != restore ] || $confirm "Do you wish to restore a backup?"
|
||||||
|
set -l keyVar VALHALLA_BACKUP_SERVER_KEY
|
||||||
|
|
||||||
|
set -l keyPath ~/.config/port-valhalla/valhalla
|
||||||
|
set -l server (string repeat --count 3 (printf "%s\n" "Please specify the host name of the SSH server: "))
|
||||||
|
set -l port (string repeat --count 3 (printf "%s\n" "Please specify the port of the SSH server (default 22): "))
|
||||||
|
set -l user (string repeat --count 3 (printf "%s\n" "Please specify the name of the user to log in to the SSH server: "))
|
||||||
|
|
||||||
|
|
||||||
|
set -l ssh \
|
||||||
|
"Do you wish to store the backup on an SSH server?" \
|
||||||
|
"Do you wish to restore the backup from an SSH server?" \
|
||||||
|
"Do you wish to backup or restore files on an SSH server?"
|
||||||
|
|
||||||
|
set -l path \
|
||||||
|
"Please specify the path to the directory to save the backup to: " \
|
||||||
|
"Please specify the path to the directory to load the backup from: " \
|
||||||
|
"Please specify the path to the backup directory: "
|
||||||
|
|
||||||
|
if [ -z "$$keyVar" ]
|
||||||
|
set -gx "$keyVar" "$keyPath"
|
||||||
|
ssh-keygen -f "$keyPath" -N ""
|
||||||
|
end
|
||||||
|
|
||||||
|
if fish $confirm $ssh[$index] n
|
||||||
|
read -gxP $server[$index] VALHALLA_BACKUP_SERVER
|
||||||
|
read -gxP $port[$index] VALHALLA_BACKUP_SERVER_PORT
|
||||||
|
read -gxP $user[$index] VALHALLA_BACKUP_SERVER_USER
|
||||||
|
end
|
||||||
|
|
||||||
|
if [ -n "$VALHALLA_BACKUP_SERVER" ]
|
||||||
|
set -l sshArgs
|
||||||
|
|
||||||
|
if [ -n "$VALHALLA_BACKUP_SERVER_PORT" ]
|
||||||
|
set -a sshArgs -p "$VALHALLA_BACKUP_SERVER_PORT"
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
echo "$(tput bold)This command should succeed without user interaction:$(tput sgr0)"
|
||||||
|
echo "sudo ssh -o PasswordAuthentication=no -i $(string escape -- "$VALHALLA_BACKUP_SERVER_KEY") $sshArgs $VALHALLA_BACKUP_SERVER true"
|
||||||
|
read -P "Press enter once you're done: "
|
||||||
|
echo
|
||||||
|
end
|
||||||
|
|
||||||
|
read -gxP $path[$index] VALHALLA_BACKUP_DIR
|
||||||
|
else
|
||||||
|
set -gx "$disabled" 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function backupFiles
|
function backupFiles
|
||||||
if [ -n "$VALHALLA_BACKUP_DIR" ]
|
if [ -n "$VALHALLA_BACKUP_DIR" ]
|
||||||
argparse -i "base-directory=" -- $argv
|
argparse -i "base-directory=" -- $argv
|
||||||
|
|
Loading…
Reference in a new issue