Skip to content

Update unit4_project.sh #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 26 additions & 30 deletions Scripts/unit4_project.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
#!/bin/bash
set -e # Exit on any error

red='\033[0;31m'
green='\033[0;32m'
none='\033[0m'

echo "[UNIT 4 PROJECT] Starting script..."

# Are pip3 and Slowloris already installed?
# Check if Slowloris is already installed
if command -v pip3 &> /dev/null; then
if pip3 freeze | grep -iq "Slowloris" ; then
echo -e "${green}[UNIT 4 PROJECT]${none} Slowloris already installed."
if pip3 show slowloris &> /dev/null; then
echo -e "${green}[UNIT 4 PROJECT]${none} Slowloris is already installed."
exit 0
fi
fi

echo "The slowloris library is installed."

# Install curl, gnupg2, ca-certificates, lsb-release, and ubuntu-keyring
sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring

# Import NGINX signing key
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

# Add NGINX to sources list
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list

# Pin NGINX packages
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx

# Update package lists
echo "[UNIT 4 PROJECT] Updating package lists..."
sudo apt update

# Install dependencies
echo "[UNIT 4 PROJECT] Installing required dependencies..."
sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring python3-pip

# Install NGINX
echo "[UNIT 4 PROJECT] Installing NGINX..."
curl -fsSL https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx
sudo apt update
sudo apt install -y nginx

# Install Python
sudo apt install -y python3-pip

# Install Slowloris
sudo pip3 install slowloris

# Did pip3 and Slowloris install?
if command -v pip3 &> /dev/null; then
if pip3 freeze | grep -i "Slowloris" ; then
echo -e "${green}[UNIT 4 PROJECT]${none} Slowloris successfully installed."
exit 0
fi
# TODO: For CodePath (Will this break the system if installed)-Otherwise slowloris won't install properly
echo "[UNIT 4 PROJECT] Installing Slowloris..."
sudo pip3 install --break-system-packages slowloris

# Verify installation
if pip3 show slowloris &> /dev/null; then
echo -e "${green}[UNIT 4 PROJECT]${none} Slowloris successfully installed."
exit 0
else
echo -e "${red}[UNIT 4 PROJECT]${none} ERROR: Slowloris did not install correctly!"
exit 1
fi
echo -e "${red}[UNIT 4 PROJECT]${none} ERROR: Slowloris did not install correctly!"
exit 1