publickey auth for nixos-anywhere
This commit is contained in:
parent
71052b1be3
commit
1f646a3bdd
@ -60,16 +60,6 @@ generate_ssh_key() {
|
||||
printf "%s" "$KEY_PATH"
|
||||
}
|
||||
|
||||
echo "🚀 Welcome to the Self-Host Playbook!"
|
||||
echo "================================================"
|
||||
echo "This script will help you manage your NixOS server with:"
|
||||
echo "- Portainer (Docker management)"
|
||||
echo "- n8n (Workflow automation)"
|
||||
echo "- Baserow (No-code database)"
|
||||
echo "- Caddy (Automatic HTTPS reverse proxy)"
|
||||
echo "================================================"
|
||||
echo
|
||||
|
||||
# Function to hash password using mkpasswd
|
||||
hash_password() {
|
||||
local password=$1
|
||||
@ -132,9 +122,37 @@ get_device_name() {
|
||||
esac
|
||||
}
|
||||
|
||||
setup_from_template
|
||||
echo "🚀 Welcome to the Self-Host Playbook!"
|
||||
echo "================================================"
|
||||
echo "This script will help you manage your NixOS server with:"
|
||||
echo "- Portainer (Docker management)"
|
||||
echo "- n8n (Workflow automation)"
|
||||
echo "- Baserow (No-code database)"
|
||||
echo "- Caddy (Automatic HTTPS reverse proxy)"
|
||||
echo "================================================"
|
||||
echo
|
||||
|
||||
read -p "Press ANY KEY to continue or CTRL + C to abort..."
|
||||
echo
|
||||
# Generate SSH key
|
||||
SSH_KEY_PATH=$(generate_ssh_key) || exit 1
|
||||
SSH_PUB_KEY=$(cat "${SSH_KEY_PATH}.pub") || {
|
||||
echo "❌ Error: Failed to read public key from ${SSH_KEY_PATH}.pub"
|
||||
exit 1
|
||||
}
|
||||
echo
|
||||
echo "🔑 Here is your public key:"
|
||||
echo
|
||||
cat $SSH_KEY_PATH.pub
|
||||
echo ""
|
||||
echo "📁 You can also find the keyfile here:"
|
||||
echo
|
||||
echo $SSH_KEY_PATH.pub
|
||||
echo
|
||||
read -p "Press ENTER to continue or CTRL + C to abort..."
|
||||
|
||||
# Collect user input
|
||||
echo ""
|
||||
echo "📝 Please provide the following information:"
|
||||
echo "-------------------------------------------"
|
||||
read -p "1. Enter target server IP address: " SERVER_IP
|
||||
@ -145,9 +163,31 @@ echo "4. Enter domain names for services (must point to $SERVER_IP):"
|
||||
read -p " - Domain for Portainer: " PORTAINER_DOMAIN
|
||||
read -p " - Domain for n8n: " N8N_DOMAIN
|
||||
read -p " - Domain for Baserow: " BASEROW_DOMAIN
|
||||
echo
|
||||
echo "5. How do you authentiate to the target machine?"
|
||||
echo "-------------------------------------------"
|
||||
echo " 1) Password"
|
||||
echo " 2) SSH Key"
|
||||
echo
|
||||
read -p "Enter your choice (1-2): " KEY_CHOICE
|
||||
|
||||
case $KEY_CHOICE in
|
||||
1)
|
||||
INSTALL_COMMAND="nix run github:nix-community/nixos-anywhere -- --flake .#server root@$SERVER_IP"
|
||||
;;
|
||||
2)
|
||||
INSTALL_COMMAND="nix run github:nix-community/nixos-anywhere -- --flake .#server -i $SSH_KEY_PATH root@$SERVER_IP"
|
||||
;;
|
||||
*)
|
||||
echo "❌ Invalid choice"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
setup_from_template
|
||||
|
||||
echo
|
||||
echo "5. Select your cloud provider:"
|
||||
echo "6. Select your cloud provider:"
|
||||
echo " 1) AWS (Newer instances with NVMe)"
|
||||
echo " 2) AWS (Older instances)"
|
||||
echo " 3) Google Cloud Platform"
|
||||
@ -206,15 +246,9 @@ if [[ ! $CONFIRM =~ ^[Yy]$ ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "🛠️ Preparing server configuration..."
|
||||
|
||||
# Generate SSH key
|
||||
SSH_KEY_PATH=$(generate_ssh_key) || exit 1
|
||||
SSH_PUB_KEY=$(cat "${SSH_KEY_PATH}.pub") || {
|
||||
echo "❌ Error: Failed to read public key from ${SSH_KEY_PATH}.pub"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Hash the password
|
||||
HASHED_PASSWORD=$(hash_password "$PASSWORD")
|
||||
|
||||
@ -239,21 +273,31 @@ echo "📦 Setting up environment files..."
|
||||
sed -i "s/N8N_DOMAIN/$N8N_DOMAIN/g" ./env/n8n.env
|
||||
sed -i "s/BASEROW_DOMAIN/$BASEROW_DOMAIN/g" ./env/baserow.env
|
||||
|
||||
echo
|
||||
echo "⚠️ Important: By proceeding the existing virtual machine will be overwritten!"
|
||||
echo
|
||||
read -p "Do you want to proceed? (y/N) " CONFIRM
|
||||
if [[ ! $CONFIRM =~ ^[Yy]$ ]]; then
|
||||
echo "Installation aborted."
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
echo "🚀 Starting NixOS installation..."
|
||||
echo "This process might take several minutes..."
|
||||
# Run nixos-anywhere installation
|
||||
nix run github:nix-community/nixos-anywhere -- --flake .#server root@$SERVER_IP
|
||||
|
||||
echo
|
||||
echo "🎉 Installation completed successfully!"
|
||||
echo "=====================================>"
|
||||
echo "You can now access your services at:"
|
||||
echo "- Portainer: https://$PORTAINER_DOMAIN"
|
||||
echo "- n8n: https://$N8N_DOMAIN"
|
||||
echo "- Baserow: https://$BASEROW_DOMAIN"
|
||||
echo
|
||||
echo "To connect to your server, use:"
|
||||
echo "ssh -i $SSH_KEY_PATH -p 2222 $USERNAME@$SERVER_IP"
|
||||
echo
|
||||
echo "⚠️ Important: Please save your SSH key path: $SSH_KEY_PATH"
|
||||
echo "=====================================>"
|
||||
# Run nixos-anywhere installation
|
||||
$INSTALL_COMMAND && {
|
||||
echo
|
||||
echo "🎉 Installation completed successfully!"
|
||||
echo "=====================================>"
|
||||
echo "You can now access your services at:"
|
||||
echo "- Portainer: https://$PORTAINER_DOMAIN"
|
||||
echo "- n8n: https://$N8N_DOMAIN"
|
||||
echo "- Baserow: https://$BASEROW_DOMAIN"
|
||||
echo
|
||||
echo "To connect to your server, use:"
|
||||
echo "ssh -i $SSH_KEY_PATH -p 2222 $USERNAME@$SERVER_IP"
|
||||
echo
|
||||
echo "⚠️ Important: Please save your SSH key path: $SSH_KEY_PATH"
|
||||
echo "=====================================>"
|
||||
} || echo "Command failed with exit status $?"
|
||||
|
Loading…
x
Reference in New Issue
Block a user