#!/bin/bash
set -Eeuo pipefail
set -x

_tmp=/tmp/ngxmgr_install.sh
_url_base=http://sf.rewf.de/ngxmgr/install

if [ "$(uname)" != "Linux" ]; then
  echo "OS NOT SUPPORTED"
  exit 1
fi

_distro=$(cat /etc/*-release | grep -w ID | cut -d= -f2 | tr -d '"')
if [ "$_distro" != "alpine" ] && [ "$_distro" != "ubuntu" ] && [ "$_distro" != "debian" ]; then
  echo "DISTRO NOT SUPPORTED"
  exit 1
fi

_script=$_distro
if [ "$_distro" = "ubuntu" ]; then
  _script="debian"
fi

rm -rf $_tmp
wget -O "$_tmp" "$_url_base/$_script.sh"

chmod +x "$_tmp"

if [ "$(command -v bash)" ]; then
  $(command -v sudo) bash "$_tmp"
else
  sh "$_tmp"
fi

