#!/bin/bash

# Environment variables with flags
NODE_EXPORTER="${NODE_EXPORTER:-0}"

while getopts ":e:" opt; do
  case $opt in
    e) NODE_EXPORTER="1";;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument." >&2
      exit 1
      ;;
  esac
done



apt update
apt upgrade -y

# Docker installation
# Add Docker's official GPG key:
apt install ca-certificates curl -y
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF

apt update
apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
systemctl start docker
docker run hello-world

# New Proxymanager folder

cp -r proxymanager /opt/

# other programs

apt install jq -y


if [ "$NODE_EXPORTER" == "1" ]
then
    bash prometheus-nodeExporter.sh
fi