Compare commits

...

2 Commits

Author SHA1 Message Date
m3tam3re
a5473b700f +hostname setting 2025-04-11 10:22:34 +02:00
m3tam3re
8adf63860c +hostname setting 2025-04-11 10:22:20 +02:00
2 changed files with 18 additions and 40 deletions

View File

@ -71,7 +71,7 @@ setup_latest_version() {
echo "❌ Error: Must be in 'self-host-playbook' directory to setup latest version" echo "❌ Error: Must be in 'self-host-playbook' directory to setup latest version"
echo "Current directory: $(pwd)" echo "Current directory: $(pwd)"
return 1 return 1
} fi
echo "⬇️ Downloading version $target_version..." echo "⬇️ Downloading version $target_version..."
@ -86,13 +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 # Additional safety check before copying files
if [ ! -f "$CLONE_DIR/flake.nix" ]; then if [ ! -f "$CLONE_DIR/flake.nix" ]; then
echo "❌ Error: Downloaded content doesn't appear to be a valid self-host-playbook" echo "❌ Error: Downloaded content doesn't appear to be a valid self-host-playbook"
return 1 return 1
} fi
# 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/"
@ -107,7 +107,7 @@ setup_from_template() {
if [ "$current_dir" != "self-host-playbook" ]; then if [ "$current_dir" != "self-host-playbook" ]; then
echo "❌ Error: Must be in 'self-host-playbook' directory" echo "❌ Error: Must be in 'self-host-playbook' directory"
exit 1 exit 1
} fi
# Create backup if directory is not empty # Create backup if directory is not empty
if [ -n "$(ls -A)" ]; then if [ -n "$(ls -A)" ]; then
@ -119,7 +119,7 @@ setup_from_template() {
if [ ! -d "$backup_dir" ]; then if [ ! -d "$backup_dir" ]; then
echo "❌ Error: Failed to create backup directory" echo "❌ Error: Failed to create backup directory"
exit 1 exit 1
fi # Fixed: Changed } to fi fi
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"
@ -294,11 +294,11 @@ SSH_PUB_KEY=$(cat "${SSH_KEY_PATH}.pub") || {
echo echo
echo "🔑 Here is your public key:" echo "🔑 Here is your public key:"
echo echo
cat $SSH_KEY_PATH.pub cat "$SSH_KEY_PATH.pub"
echo "" echo ""
echo "📁 You can also find the keyfile here:" echo "📁 You can also find the keyfile here:"
echo echo
echo $SSH_KEY_PATH.pub echo "$SSH_KEY_PATH.pub"
echo echo
read -p "Press ENTER to continue or CTRL + C to abort..." read -p "Press ENTER to continue or CTRL + C to abort..."
@ -323,7 +323,7 @@ read -p " - Domain for Portainer: " PORTAINER_DOMAIN
read -p " - Domain for n8n: " N8N_DOMAIN read -p " - Domain for n8n: " N8N_DOMAIN
read -p " - Domain for Baserow: " BASEROW_DOMAIN read -p " - Domain for Baserow: " BASEROW_DOMAIN
echo echo
echo "5. How do you authentiate to the target machine?" echo "6. How do you authenticate to the target machine?"
echo "-------------------------------------------" echo "-------------------------------------------"
echo " 1) Password" echo " 1) Password"
echo " 2) SSH Key" echo " 2) SSH Key"
@ -346,7 +346,7 @@ esac
setup_from_template setup_from_template
echo echo
echo "6. Select your cloud provider:" echo "7. Select your cloud provider:"
echo " 1) AWS (Newer instances with NVMe)" echo " 1) AWS (Newer instances with NVMe)"
echo " 2) AWS (Older instances)" echo " 2) AWS (Older instances)"
echo " 3) Google Cloud Platform" echo " 3) Google Cloud Platform"

View File

@ -26,7 +26,7 @@ get_current_version() {
} }
get_latest_version() { get_latest_version() {
local LATEST_VERSION local latest_version
latest_version=$(curl -s "https://code.m3tam3re.com/api/v1/repos/m3tam3re/self-host-playbook/tags" | jq -r '.[] | select(.name | startswith("v")) | .name' | sort -V | tail -n1) latest_version=$(curl -s "https://code.m3tam3re.com/api/v1/repos/m3tam3re/self-host-playbook/tags" | jq -r '.[] | select(.name | startswith("v")) | .name' | sort -V | tail -n1)
@ -92,13 +92,13 @@ perform_update() {
if [ "$current_dir" != "self-host-playbook" ]; then if [ "$current_dir" != "self-host-playbook" ]; then
echo "❌ Error: Must be in 'self-host-playbook' directory" echo "❌ Error: Must be in 'self-host-playbook' directory"
return 1 return 1
} fi
# Verify essential files exist before proceeding # Verify essential files exist before proceeding
if [ ! -f "config.json" ] || [ ! -d "env" ]; then if [ ! -f "config.json" ] || [ ! -d "env" ]; then
echo "❌ Error: Essential files missing. Are you in the correct directory?" echo "❌ Error: Essential files missing. Are you in the correct directory?"
return 1 return 1
} fi
echo "⬇️ Downloading version $target_version..." echo "⬇️ Downloading version $target_version..."
@ -113,13 +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 # Verify downloaded content
if [ ! -f "$CLONE_DIR/flake.nix" ]; then if [ ! -f "$CLONE_DIR/flake.nix" ]; then
echo "❌ Error: Downloaded content appears invalid" echo "❌ Error: Downloaded content appears invalid"
return 1 return 1
} fi
# Remove current directory contents except backup # Remove current directory contents except backup
echo "🗑️ Cleaning current directory..." echo "🗑️ Cleaning current directory..."
@ -133,7 +133,7 @@ perform_update() {
if [ ! -f "flake.nix" ]; then if [ ! -f "flake.nix" ]; then
echo "❌ Error: Failed to copy new version files" echo "❌ Error: Failed to copy new version files"
return 1 return 1
} fi
# Restore configuration files from backup with validation # Restore configuration files from backup with validation
echo "🔄 Restoring configuration files..." echo "🔄 Restoring configuration files..."
@ -142,14 +142,14 @@ perform_update() {
echo "❌ Error: Failed to restore config.json" echo "❌ Error: Failed to restore config.json"
return 1 return 1
} }
} fi
if [ -d "${backup_dir}/env" ]; then if [ -d "${backup_dir}/env" ]; then
cp -r "${backup_dir}/env" . || { cp -r "${backup_dir}/env" . || {
echo "❌ Error: Failed to restore env directory" echo "❌ Error: Failed to restore env directory"
return 1 return 1
} }
} fi
return 0 return 0
} }
@ -157,28 +157,24 @@ perform_update() {
setup_ssh_config() { setup_ssh_config() {
local username=$1 local username=$1
local ip_address=$2 local ip_address=$2
local hostname=$3 # Add hostname parameter local hostname=$3
local ssh_config_dir="$HOME/.ssh" local ssh_config_dir="$HOME/.ssh"
local ssh_config_file="$ssh_config_dir/config" local ssh_config_file="$ssh_config_dir/config"
local ssh_key_file="$ssh_config_dir/self-host-playbook" local ssh_key_file="$ssh_config_dir/self-host-playbook"
# Create .ssh directory if it doesn't exist
mkdir -p "$ssh_config_dir" mkdir -p "$ssh_config_dir"
chmod 700 "$ssh_config_dir" chmod 700 "$ssh_config_dir"
# Create or append to SSH config using hostname as the Host name
local config_entry="Host $hostname local config_entry="Host $hostname
HostName $ip_address HostName $ip_address
User $username User $username
Port 2222 Port 2222
IdentityFile $ssh_key_file" IdentityFile $ssh_key_file"
# Check if entry already exists
if ! grep -q "Host $hostname" "$ssh_config_file" 2>/dev/null; then if ! grep -q "Host $hostname" "$ssh_config_file" 2>/dev/null; then
echo -e "\n$config_entry" >> "$ssh_config_file" echo -e "\n$config_entry" >> "$ssh_config_file"
echo "✅ Added SSH config entry" echo "✅ Added SSH config entry"
else else
# Update existing entry
sed -i.bak "/Host $hostname/,/IdentityFile.*/{ sed -i.bak "/Host $hostname/,/IdentityFile.*/{
s/HostName.*/HostName $ip_address/ s/HostName.*/HostName $ip_address/
s/User.*/User $username/ s/User.*/User $username/
@ -186,7 +182,6 @@ setup_ssh_config() {
echo "✅ Updated existing SSH config entry" echo "✅ Updated existing SSH config entry"
fi fi
# Set appropriate permissions
chmod 600 "$ssh_config_file" chmod 600 "$ssh_config_file"
} }
@ -195,18 +190,15 @@ update_config_value() {
local value=$2 local value=$2
local config_file="config.json" local config_file="config.json"
# Read existing config
local config local config
config=$(cat "$config_file") config=$(cat "$config_file")
# Update or add the field
if jq -e ".$key" "$config_file" >/dev/null 2>&1; then if jq -e ".$key" "$config_file" >/dev/null 2>&1; then
config=$(echo "$config" | jq --arg key "$key" --arg value "$value" '.[$key] = $value') config=$(echo "$config" | jq --arg key "$key" --arg value "$value" '.[$key] = $value')
else else
config=$(echo "$config" | jq --arg key "$key" --arg value "$value" '. + {($key): $value}') config=$(echo "$config" | jq --arg key "$key" --arg value "$value" '. + {($key): $value}')
fi fi
# Write back to file
echo "$config" | jq '.' > "$config_file" echo "$config" | jq '.' > "$config_file"
echo "✅ Updated $key in config.json" echo "✅ Updated $key in config.json"
} }
@ -214,13 +206,11 @@ update_config_value() {
install_deploy_rs() { install_deploy_rs() {
echo "🔧 Installing deploy-rs to user environment..." echo "🔧 Installing deploy-rs to user environment..."
# Check if deploy is already installed
if command -v deploy >/dev/null 2>&1; then if command -v deploy >/dev/null 2>&1; then
echo " deploy-rs is already installed" echo " deploy-rs is already installed"
return 0 return 0
fi fi
# Install deploy-rs using nix profile
if nix profile install 'github:serokell/deploy-rs'; then if nix profile install 'github:serokell/deploy-rs'; then
echo "✅ deploy-rs installed successfully" echo "✅ deploy-rs installed successfully"
else else
@ -229,12 +219,10 @@ install_deploy_rs() {
fi fi
} }
# Main script # Main script
echo "🔄 Self-Host Playbook Update Assistant" echo "🔄 Self-Host Playbook Update Assistant"
echo "======================================" echo "======================================"
# Check if we're in the right directory
if [ ! -f "config.json" ]; then if [ ! -f "config.json" ]; then
echo "❌ Error: config.json not found. Please run this script in your self-host-playbook directory." echo "❌ Error: config.json not found. Please run this script in your self-host-playbook directory."
exit 1 exit 1
@ -249,33 +237,27 @@ if [ -z "$USERNAME" ]; then
exit 1 exit 1
fi fi
# If IP address is not in config.json, prompt for it
if [ -z "$IP_ADDRESS" ]; then if [ -z "$IP_ADDRESS" ]; then
echo " No IP address found in config.json" echo " No IP address found in config.json"
read -p "Enter the IP address of your server: " IP_ADDRESS read -p "Enter the IP address of your server: " IP_ADDRESS
# Validate IP address format
if ! [[ $IP_ADDRESS =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then if ! [[ $IP_ADDRESS =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Error: Invalid IP address format" echo "❌ Error: Invalid IP address format"
exit 1 exit 1
fi fi
# Update config.json with the new IP address
update_config_value "ipAddress" "$IP_ADDRESS" update_config_value "ipAddress" "$IP_ADDRESS"
fi fi
# If hostname is not in config.json, prompt for it
if [ -z "$HOSTNAME" ]; then if [ -z "$HOSTNAME" ]; then
echo " No hostname found in config.json" echo " No hostname found in config.json"
read -p "Enter the hostname for your server: " HOSTNAME read -p "Enter the hostname for your server: " HOSTNAME
# Validate hostname format (basic validation)
if ! [[ $HOSTNAME =~ ^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$ ]]; then if ! [[ $HOSTNAME =~ ^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$ ]]; then
echo "❌ Error: Invalid hostname format" echo "❌ Error: Invalid hostname format"
exit 1 exit 1
fi fi
# Update config.json with the new hostname
update_config_value "hostname" "$HOSTNAME" update_config_value "hostname" "$HOSTNAME"
fi fi
@ -303,18 +285,14 @@ read -p "Do you want to update to version $LATEST_VERSION? (y/N) " -n 1 -r
echo echo
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
# Create backup
backup_dir="backup_${CURRENT_VERSION}_$(date +%Y%m%d_%H%M%S)" 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"
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/" \;
# Perform update
if perform_update "$LATEST_VERSION" "$backup_dir"; then if perform_update "$LATEST_VERSION" "$backup_dir"; then
echo echo
echo "✅ Update completed successfully!" echo "✅ Update completed successfully!"
# Setup SSH configuration
echo echo
echo "🔧 Setting up SSH configuration..." echo "🔧 Setting up SSH configuration..."
setup_ssh_config "$USERNAME" "$IP_ADDRESS" "$HOSTNAME" setup_ssh_config "$USERNAME" "$IP_ADDRESS" "$HOSTNAME"