#!/bin/bash

set -e

DIR="$(cd /usr/lib/harbor_installer && pwd)"
DATADIR="/var/lib/harbor"

set +o noglob

usage=$'Please set hostname and other necessary attributes in /etc/harbor.yml first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients.
Please set --with-trivy if needs enable Trivy in Harbor.'

# trivy is not enabled by default
with_trivy=$false

while [ $# -gt 0 ]; do
        case $1 in
            --help)
            note "$usage"
            exit 0;;
            --with-trivy)
            with_trivy=true;;
            *)
            note "$usage"
            exit 1;;
        esac
        shift || true
done

mkdir -p "${DATADIR}/input"
cp /etc/harbor.yml "${DATADIR}/input"

prepare_para=
if [ $with_trivy ]
then
    prepare_para="${prepare_para} --with-trivy"
fi

/usr/bin/python3 "${DIR}/prepare/main.py" prepare $prepare_para

#systemctl start suse_private_registry
echo "Now run 'cd ${DATADIR} && podman compose up'"
