Skip to content

Instantly share code, notes, and snippets.

@haasr
Last active September 21, 2023 00:15
Show Gist options
  • Save haasr/2f531302d3ea08a3961658962a5de441 to your computer and use it in GitHub Desktop.
Save haasr/2f531302d3ea08a3961658962a5de441 to your computer and use it in GitHub Desktop.
DigitalOcean Django project Initial setup script
#! /bin/bash -
# Set time zone
echo "> Setting timezone.."
sudo dpkg-reconfigure tzdata
# Initial upgrade/installs
echo "> Upgrading system.."
sudo apt update && sudo apt upgrade -y
echo "> Installing Nginx, utilities.."
sudo apt install certbot python3-certbot-nginx curl fail2ban gcc git libssl-dev libpq-dev net-tools nginx postgresql postgresql-contrib ufw -y
# Install additional python3 pacakages
echo "> Checking current python3 version.."
py_version=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
py_venv="python${py_version}-venv"
py_dev="python${py_version}-dev"
echo "> Installing python3 virtualenv and dev pacakages.."
sudo apt install $py_venv $py_dev -y
# Configure git
echo "> Configuring git.."
read -p " Full name: " git_fullname
read -p " Email: " git_email
git config --global user.name $git_fullname
git config --global user.email $git_email
# Create Github SSH key, configure SSH config with key
echo "> Creating Github SSH key.."
ssh-keygen -t rsa -b 4096 -f ~/.ssh/github -q -N ""
echo "> Adding github.com to SSH config"
echo "Hostname github.com" >> ~/.ssh/config
echo "User git" >> ~/.ssh/config
echo "IdentityFile ~/.ssh/github" >> ~/.ssh/config
echo "" >> ~/.ssh/config
echo "Below is your Github public key: "
echo $(cat ~/.ssh/github.pub)
echo ""
echo "Copy the public key to your clipboard and on Github,"
echo "go to Settings' > 'SSH and GPG Keys' > 'New SSH key'"
echo "and paste in the value."
echo "Press enter to proceed after you have added your"
read -p "public key on Github >"
echo "> Testing SSH key authentication with Github.."
ssh -T -o "StrictHostKeyChecking no" git@github.com
# Clone & configure repository
echo "> Cloning Django project repo.."
read -p "Repository clone URL (SSH): " clone_url
project_name="${clone_url##*/}"
project_name="${project_name%.*}"
git clone $clone_url
echo "> Configuring a new virtualenv"
python3 -m venv "${project_name}/venv"
source "${project_name}/venv/bin/activate"
pip3 install -r "${project_name}/requirements.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment