Skip to content

Instantly share code, notes, and snippets.

@suhailroushan13
Created January 31, 2025 22:47
Show Gist options
  • Save suhailroushan13/bcbd1c420378c791ec1083a867dd7a21 to your computer and use it in GitHub Desktop.
Save suhailroushan13/bcbd1c420378c791ec1083a867dd7a21 to your computer and use it in GitHub Desktop.
Cloud New Script 2025
#!/bin/bash
# Ensure the script runs with root privileges
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Use sudo!"
exit 1
fi
# Get the default user (who ran sudo)
DEFAULT_USER=$SUDO_USER
USER_HOME=$(eval echo ~$DEFAULT_USER)
echo "Default user detected: $DEFAULT_USER"
echo "User home directory: $USER_HOME"
# Update and upgrade system
echo "Updating and upgrading system..."
sudo apt update && sudo apt upgrade -y
# Install necessary packages
echo "Installing essential packages..."
sudo apt install -y git
sudo apt install -y net-tools
sudo timedatectl set-timezone Asia/Kolkata
sudo apt-get install -y nginx
sudo apt install -y snapd
sudo snap install core
sudo apt-get install -y python3-certbot-nginx
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/
sudo apt install -y python3-pip
sudo apt-get autoremove -y
sudo apt full-upgrade -y
sudo apt install -y gcc
sudo apt install -y unzip
sudo apt install -y build-essential
sudo apt-get install -y manpages-dev
sudo apt install -y g++
sudo apt install -y ruby-full
# Configure Git for the default user
echo "Configuring Git for $DEFAULT_USER..."
sudo -u "$DEFAULT_USER" git config --global user.name "suhailroushan13"
sudo -u "$DEFAULT_USER" git config --global user.email "[email protected]"
# Verify Git config
echo "Git Global Config:"
sudo -u "$DEFAULT_USER" git config --global --list
# Generate SSH Key for the default user
echo "Generating SSH Key for $DEFAULT_USER..."
sudo -u "$DEFAULT_USER" mkdir -p "$USER_HOME/.ssh"
sudo -u "$DEFAULT_USER" ssh-keygen -t ed25519 -C "[email protected]" -f "$USER_HOME/.ssh/id_ed25519" -N ""
# Display SSH Public Key
echo "Here is your SSH public key (Add this to GitHub SSH keys):"
sudo -u "$DEFAULT_USER" cat "$USER_HOME/.ssh/id_ed25519.pub"
# Install NVM and Node.js for the default user
echo "Installing NVM for $DEFAULT_USER..."
sudo -u "$DEFAULT_USER" bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash'
# Load NVM for the default user
export NVM_DIR="$USER_HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && sudo -u "$DEFAULT_USER" bash -c "source $NVM_DIR/nvm.sh"
echo "Installing Node.js v22 for $DEFAULT_USER..."
sudo -u "$DEFAULT_USER" bash -c "source ~/.bashrc && nvm install 22"
# Install global npm packages for the default user
echo "Installing PM2 for $DEFAULT_USER..."
sudo -u "$DEFAULT_USER" npm i -g pm2
# Verify Node.js and npm versions
echo "Checking installed Node.js and npm versions..."
sudo -u "$DEFAULT_USER" node -v
sudo -u "$DEFAULT_USER" npm -v
# Nginx Configuration
echo "Configuring Nginx..."
cd /etc/nginx/sites-enabled/
sudo rm -rf *
cd /etc/nginx/sites-available
sudo touch domains
sudo ln -s /etc/nginx/sites-available/domains /etc/nginx/sites-enabled
# Test Nginx Configuration
echo "Testing Nginx Configuration..."
sudo nginx -t
# Restart Nginx
echo "Restarting Nginx..."
sudo systemctl restart nginx
echo "Installation and configuration completed successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment