#!/bin/bash
if [ "$EUID" -ne 0 ]
  then echo "Please run as root"
  exit
fi
add-apt-repository universe || true  # ubuntu only
apt update
apt full-upgrade -y
apt install -y git
cd /root
read -p "HTTP proxy (e.g. proxy:8080, enter to skip):" PROXY
if [ -z "$PROXY" ]; then
    git clone https://panel.ubicast.eu/git/mediaserver/envsetup.git -b stable
else
    git -c "http.proxy=$PROXY" clone https://panel.ubicast.eu/git/mediaserver/envsetup.git -b stable
    git config --global http.sslVerify false
    echo "SKYREACH_SSL_VERIFY='0'" >> /root/envsetup/conf.sh
    echo "Remember to run this after this script completes:"
    echo "export https_proxy='http://proxy:8080'"
    echo "export http_proxy='http://proxy:8080'"
fi
cd envsetup
read -p "Paste deployment key (e.g. XXX-XXX-XXX-XXX):" KEY
echo "SKYREACH_ACTIVATION_KEY='$KEY'" >> /root/envsetup/conf.sh
echo "All done, you can now run /root/envsetup/launcher.sh something"
