Created
December 19, 2025 05:35
-
-
Save krishnaglodha/92b6ebfeb3fb3b6e66a483c01abd5161 to your computer and use it in GitHub Desktop.
Basic Setup for new sever
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # ------------------------------- | |
| # Configuration (EDIT IF NEEDED) | |
| # ------------------------------- | |
| POSTGRES_VERSION=16 | |
| EMAIL="krishna@rottengrapes.tech" | |
| POSTGRES_PASSWORD='A0kWTaVk8E' | |
| # ------------------------------- | |
| # Utility functions | |
| # ------------------------------- | |
| log() { | |
| echo -e "\n[INFO] $1\n" | |
| } | |
| check_root() { | |
| if [ "$EUID" -ne 0 ]; then | |
| echo "Please run as root or using sudo" | |
| exit 1 | |
| fi | |
| } | |
| # ------------------------------- | |
| # Start | |
| # ------------------------------- | |
| check_root | |
| log "Updating system packages" | |
| apt update -y && apt upgrade -y | |
| # ------------------------------- | |
| # Install Nginx | |
| # ------------------------------- | |
| log "Installing Nginx" | |
| apt install -y nginx | |
| systemctl enable nginx | |
| systemctl start nginx | |
| # ------------------------------- | |
| # Install PostgreSQL + PostGIS | |
| # ------------------------------- | |
| log "Installing PostgreSQL and PostGIS" | |
| apt install -y wget gnupg2 lsb-release ca-certificates | |
| wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc \ | |
| | gpg --dearmor > /usr/share/keyrings/postgresql.gpg | |
| echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] \ | |
| http://apt.postgresql.org/pub/repos/apt \ | |
| $(lsb_release -cs)-pgdg main" \ | |
| > /etc/apt/sources.list.d/postgresql.list | |
| apt update -y | |
| apt install -y \ | |
| postgresql-${POSTGRES_VERSION} \ | |
| postgresql-contrib-${POSTGRES_VERSION} \ | |
| postgis \ | |
| postgresql-${POSTGRES_VERSION}-postgis-3 | |
| systemctl enable postgresql | |
| systemctl start postgresql | |
| # ------------------------------- | |
| # Secure PostgreSQL (basic) | |
| # ------------------------------- | |
| log "Configuring PostgreSQL" | |
| sudo -u postgres psql <<EOF | |
| ALTER USER postgres WITH PASSWORD 'A0kWTaVk8E'; | |
| EOF | |
| # ------------------------------- | |
| # Install Certbot (Let's Encrypt) | |
| # ------------------------------- | |
| log "Installing Certbot for Let's Encrypt" | |
| apt install -y certbot python3-certbot-nginx | |
| # ------------------------------- | |
| # Auto-renew SSL | |
| # ------------------------------- | |
| log "Enabling automatic SSL renewal" | |
| systemctl enable certbot.timer | |
| systemctl start certbot.timer | |
| # ------------------------------- | |
| # Firewall (optional but recommended) | |
| # ------------------------------- | |
| log "Configuring firewall" | |
| apt install -y ufw | |
| ufw allow OpenSSH | |
| ufw allow 'Nginx Full' | |
| ufw --force enable | |
| # ------------------------------- | |
| # Status Check | |
| # ------------------------------- | |
| log "Installation complete. Service status:" | |
| systemctl status nginx --no-pager | |
| systemctl status postgresql --no-pager | |
| certbot certificates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment