From 1980fa41787d9bd5da0873d342d18634ec051c76 Mon Sep 17 00:00:00 2001 From: m3tam3re Date: Fri, 11 Apr 2025 10:00:48 +0200 Subject: [PATCH] +hostname setting --- install.sh | 30 ++++++++++++++++++++++++++++-- update.sh | 46 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index 50f304a..e31c106 100755 --- a/install.sh +++ b/install.sh @@ -65,6 +65,14 @@ setup_latest_version() { local target_version=$1 local dir_name=$2 + # Safety check: Ensure we're in the self-host-playbook directory + local current_dir=$(basename "$(pwd)") + if [ "$current_dir" != "self-host-playbook" ]; then + echo "❌ Error: Must be in 'self-host-playbook' directory to setup latest version" + echo "Current directory: $(pwd)" + return 1 + } + echo "⬇️ Downloading version $target_version..." TEMP_DIR=$(mktemp -d) @@ -78,7 +86,13 @@ setup_latest_version() { if ! nix flake clone --quiet "git+https://code.m3tam3re.com/m3tam3re/self-host-playbook?ref=v${target_version}" --dest "$CLONE_DIR" 2>/dev/null; then echo "❌ Failed to clone repository" return 1 - fi + } + + # Additional safety check before copying files + if [ ! -f "$CLONE_DIR/flake.nix" ]; then + echo "❌ Error: Downloaded content doesn't appear to be a valid self-host-playbook" + return 1 + } # Copy files from clone to target directory cp -r "$CLONE_DIR"/* "$dir_name/" @@ -88,19 +102,31 @@ setup_latest_version() { # Function to setup from template setup_from_template() { + # Ensure we're in the correct directory + local current_dir=$(basename "$(pwd)") + if [ "$current_dir" != "self-host-playbook" ]; then + echo "❌ Error: Must be in 'self-host-playbook' directory" + exit 1 + } + # Create backup if directory is not empty if [ -n "$(ls -A)" ]; then local CURRENT_VERSION=$(date +%Y%m%d_%H%M%S) local backup_dir="backup_${CURRENT_VERSION}_$(date +%Y%m%d_%H%M%S)" echo "📑 Creating backup in $backup_dir..." mkdir -p "$backup_dir" + # Add safety check for backup creation + if [ ! -d "$backup_dir" ]; then + echo "❌ Error: Failed to create backup directory" + exit 1 + } find . -maxdepth 1 ! -name "." ! -name ".." ! -name "$backup_dir" -exec cp -r {} "$backup_dir/" \; echo "✅ Backup created successfully" # Clean current directory except backup echo "🗑️ Cleaning current directory..." find . -maxdepth 1 ! -name "." ! -name ".." ! -name "$backup_dir" -exec rm -rf {} \; - fi + } # Get and setup latest version local LATEST_VERSION=$(get_latest_version) diff --git a/update.sh b/update.sh index e7a0057..191c97f 100644 --- a/update.sh +++ b/update.sh @@ -86,6 +86,20 @@ show_changelog() { perform_update() { local target_version=$1 local backup_dir=$2 + + # Ensure we're in the correct directory + local current_dir=$(basename "$(pwd)") + if [ "$current_dir" != "self-host-playbook" ]; then + echo "❌ Error: Must be in 'self-host-playbook' directory" + return 1 + } + + # Verify essential files exist before proceeding + if [ ! -f "config.json" ] || [ ! -d "env" ]; then + echo "❌ Error: Essential files missing. Are you in the correct directory?" + return 1 + } + echo "⬇️ Downloading version $target_version..." TEMP_DIR=$(mktemp -d) @@ -99,7 +113,13 @@ perform_update() { if ! nix flake clone --quiet "git+https://code.m3tam3re.com/m3tam3re/self-host-playbook?ref=v${target_version}" --dest "$CLONE_DIR" 2>/dev/null; then echo "❌ Failed to clone repository" return 1 - fi + } + + # Verify downloaded content + if [ ! -f "$CLONE_DIR/flake.nix" ]; then + echo "❌ Error: Downloaded content appears invalid" + return 1 + } # Remove current directory contents except backup echo "🗑️ Cleaning current directory..." @@ -109,11 +129,27 @@ perform_update() { echo "📋 Installing new version..." cp -r "$CLONE_DIR"/* . - # Restore configuration files from backup - echo "🔄 Restoring configuration files..." - cp -r "${backup_dir}/config.json" \ - "${backup_dir}/env" . 2>/dev/null || true + # Verify essential files were copied + if [ ! -f "flake.nix" ]; then + echo "❌ Error: Failed to copy new version files" + return 1 + } + # Restore configuration files from backup with validation + echo "🔄 Restoring configuration files..." + if [ -f "${backup_dir}/config.json" ]; then + cp -r "${backup_dir}/config.json" . || { + echo "❌ Error: Failed to restore config.json" + return 1 + } + } + + if [ -d "${backup_dir}/env" ]; then + cp -r "${backup_dir}/env" . || { + echo "❌ Error: Failed to restore env directory" + return 1 + } + } return 0 }