107 lines
3.7 KiB
Bash
Executable File
107 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# This script helps set up your VPS for hosting your website and Nextcloud
|
|
|
|
# Check if we can connect to the VPS
|
|
echo "Testing connection to VPS..."
|
|
if ! ssh root@66.179.188.130 "echo 'Connection successful'"; then
|
|
echo "Failed to connect to VPS. Please check your SSH configuration."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if Nginx is installed
|
|
echo "Checking if Nginx is installed..."
|
|
if ! ssh root@66.179.188.130 "which nginx > /dev/null"; then
|
|
echo "Nginx is not installed. Installing..."
|
|
ssh root@66.179.188.130 "apt update && apt install -y nginx"
|
|
else
|
|
echo "Nginx is already installed."
|
|
fi
|
|
|
|
# Check if Certbot is installed
|
|
echo "Checking if Certbot is installed..."
|
|
if ! ssh root@66.179.188.130 "which certbot > /dev/null"; then
|
|
echo "Certbot is not installed. Installing..."
|
|
ssh root@66.179.188.130 "apt update && apt install -y certbot python3-certbot-nginx"
|
|
else
|
|
echo "Certbot is already installed."
|
|
fi
|
|
|
|
# Create directory for the website
|
|
echo "Creating directory for the website..."
|
|
ssh root@66.179.188.130 "mkdir -p /var/www/boilerhaus.org"
|
|
|
|
# Create a temporary Nginx configuration without SSL
|
|
echo "Creating temporary Nginx configuration..."
|
|
cat > temp-boilerhaus.org.conf << EOF
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name boilerhaus.org www.boilerhaus.org cloud.boilerhaus.org git.boilerhaus.org;
|
|
|
|
root /var/www/boilerhaus.org;
|
|
index index.html;
|
|
|
|
location / {
|
|
try_files \$uri \$uri/ =404;
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# Upload temporary Nginx configuration
|
|
echo "Uploading temporary Nginx configuration..."
|
|
scp temp-boilerhaus.org.conf root@66.179.188.130:/etc/nginx/sites-available/boilerhaus.org
|
|
|
|
# Enable the site
|
|
echo "Enabling the site..."
|
|
ssh root@66.179.188.130 "ln -sf /etc/nginx/sites-available/boilerhaus.org /etc/nginx/sites-enabled/boilerhaus.org"
|
|
|
|
# Restart Nginx with temporary configuration
|
|
echo "Restarting Nginx with temporary configuration..."
|
|
ssh root@66.179.188.130 "systemctl restart nginx"
|
|
|
|
# Check for existing Nextcloud configuration
|
|
echo "Checking for existing Nextcloud configuration..."
|
|
if ssh root@66.179.188.130 "[ -d /var/www/nextcloud ]"; then
|
|
echo "Nextcloud directory found. Assuming Nextcloud is already installed."
|
|
|
|
# Ask if user wants to move Nextcloud to cloud subdomain
|
|
read -p "Do you want to move Nextcloud to cloud.boilerhaus.org? (y/n): " move_nextcloud
|
|
if [[ $move_nextcloud == "y" ]]; then
|
|
echo "Updating Nextcloud configuration..."
|
|
ssh root@66.179.188.130 "sed -i 's/\"trusted_domains\".*$/\"trusted_domains\" => [\"cloud.boilerhaus.org\"],/' /var/www/nextcloud/config/config.php"
|
|
fi
|
|
else
|
|
echo "Nextcloud directory not found. Please install Nextcloud manually after setting up the domains."
|
|
fi
|
|
|
|
# Check for Gitea port
|
|
echo "Checking if Gitea is running..."
|
|
if ssh root@66.179.188.130 "netstat -tuln | grep -q ':3000'"; then
|
|
echo "Gitea appears to be running on port 3000."
|
|
else
|
|
echo "Warning: Gitea doesn't seem to be running on the expected port (3000)."
|
|
echo "Please make sure Gitea is installed and running before proceeding."
|
|
read -p "Continue anyway? (y/n): " continue_anyway
|
|
if [[ $continue_anyway != "y" ]]; then
|
|
echo "Setup aborted. Please install and configure Gitea first."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Set up SSL certificates
|
|
echo "Setting up SSL certificates..."
|
|
ssh root@66.179.188.130 "certbot --nginx -d boilerhaus.org -d www.boilerhaus.org -d cloud.boilerhaus.org -d git.boilerhaus.org"
|
|
|
|
# Now upload the final configuration with SSL
|
|
echo "Uploading final Nginx configuration with SSL..."
|
|
scp boilerhaus.org.conf root@66.179.188.130:/etc/nginx/sites-available/boilerhaus.org
|
|
|
|
# Restart Nginx with final configuration
|
|
echo "Restarting Nginx with final configuration..."
|
|
ssh root@66.179.188.130 "systemctl restart nginx"
|
|
|
|
# Clean up temporary file
|
|
rm temp-boilerhaus.org.conf
|
|
|
|
echo "VPS setup complete!" |