#!/bin/bash # Script to generate Restic configuration with secure password set -e # Configuration should be sourced before running: source backup.env CONFIG_FILE="$RESTIC_CONFIG_FILE" REPO_PATH="$BACKUP_REPOSITORY" echo "=== Generating Restic Configuration ===" # Check if config already exists if [ -f "$CONFIG_FILE" ]; then echo "Configuration file already exists at $CONFIG_FILE" read -p "Do you want to overwrite it? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Aborted." exit 1 fi fi # Generate secure password (32 characters) echo "Generating secure password..." RESTIC_PASSWORD=$(openssl rand -base64 32) # Create configuration file echo "Creating configuration file..." cat > "$CONFIG_FILE" << EOF # Restic configuration for quantumrick backups # Generated on $(date) # Repository path export RESTIC_REPOSITORY="$REPO_PATH" # Repository password export RESTIC_PASSWORD="$RESTIC_PASSWORD" # Cache directory (optional) export RESTIC_CACHE_DIR="$RESTIC_CACHE_DIR" EOF # Set secure permissions chmod 600 "$CONFIG_FILE" echo "✅ Configuration file created at $CONFIG_FILE" echo "🔒 Password generated and saved securely" echo "" echo "⚠️ IMPORTANT: Save this password somewhere safe!" echo " If you lose it, you won't be able to restore your backups!" echo "" echo "📁 Password saved in: $CONFIG_FILE" echo " Use 'cat $CONFIG_FILE' to view the password if needed" echo ""