+hostname setting

This commit is contained in:
m3tam3re 2025-04-11 10:00:48 +02:00
parent 81b2811569
commit 1980fa4178
2 changed files with 69 additions and 7 deletions

View File

@ -65,6 +65,14 @@ setup_latest_version() {
local target_version=$1 local target_version=$1
local dir_name=$2 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..." echo "⬇️ Downloading version $target_version..."
TEMP_DIR=$(mktemp -d) 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 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" echo "❌ Failed to clone repository"
return 1 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 # Copy files from clone to target directory
cp -r "$CLONE_DIR"/* "$dir_name/" cp -r "$CLONE_DIR"/* "$dir_name/"
@ -88,19 +102,31 @@ setup_latest_version() {
# Function to setup from template # Function to setup from template
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 # Create backup if directory is not empty
if [ -n "$(ls -A)" ]; then if [ -n "$(ls -A)" ]; then
local CURRENT_VERSION=$(date +%Y%m%d_%H%M%S) local CURRENT_VERSION=$(date +%Y%m%d_%H%M%S)
local backup_dir="backup_${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..." echo "📑 Creating backup in $backup_dir..."
mkdir -p "$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/" \; find . -maxdepth 1 ! -name "." ! -name ".." ! -name "$backup_dir" -exec cp -r {} "$backup_dir/" \;
echo "✅ Backup created successfully" echo "✅ Backup created successfully"
# Clean current directory except backup # Clean current directory except backup
echo "🗑️ Cleaning current directory..." echo "🗑️ Cleaning current directory..."
find . -maxdepth 1 ! -name "." ! -name ".." ! -name "$backup_dir" -exec rm -rf {} \; find . -maxdepth 1 ! -name "." ! -name ".." ! -name "$backup_dir" -exec rm -rf {} \;
fi }
# Get and setup latest version # Get and setup latest version
local LATEST_VERSION=$(get_latest_version) local LATEST_VERSION=$(get_latest_version)

View File

@ -86,6 +86,20 @@ show_changelog() {
perform_update() { perform_update() {
local target_version=$1 local target_version=$1
local backup_dir=$2 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..." echo "⬇️ Downloading version $target_version..."
TEMP_DIR=$(mktemp -d) 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 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" echo "❌ Failed to clone repository"
return 1 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 # Remove current directory contents except backup
echo "🗑️ Cleaning current directory..." echo "🗑️ Cleaning current directory..."
@ -109,11 +129,27 @@ perform_update() {
echo "📋 Installing new version..." echo "📋 Installing new version..."
cp -r "$CLONE_DIR"/* . cp -r "$CLONE_DIR"/* .
# Restore configuration files from backup # Verify essential files were copied
echo "🔄 Restoring configuration files..." if [ ! -f "flake.nix" ]; then
cp -r "${backup_dir}/config.json" \ echo "❌ Error: Failed to copy new version files"
"${backup_dir}/env" . 2>/dev/null || true 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 return 0
} }