#!/usr/bin/env sh

if [ -e "/opt/virtfusion/app/control/.env" ]; then
 printf "\n /!\ Existing installation detected! Exiting /!\ \\n\n"
exit 1
fi

v='no'

while [ $# -gt 0 ]; do
  case "$1" in
   --verbose) v="yes"  ;;
  esac
  shift
done

setenforce 0
apt update -y
apt-get install gnupg2 tar curl wget -y
echo "deb http://packages.virtfusion.net/debian bullseye main" > /etc/apt/sources.list.d/virtfusion.list

curl -s https://security.virtfusion.net/gpg.asc | gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/virtfusion.gpg --import
chmod 644 /etc/apt/trusted.gpg.d/virtfusion.gpg
apt update -y
apt-get install vf-php8 -y

wget -q https://install.virtfusion.net/installer.tar.gz -O /tmp/installer.tar.gz
cd /tmp || exit
tar -xzf /tmp/installer.tar.gz
cd /tmp/installer || exit

/opt/virtfusion/php/bin/php /tmp/installer/install.php control:debian-11 --toscreen=$v