#!/bin/bash

#Current version of libre.sh to be installed 
LIBRE_VERSION=1.1
# System env vars 

## domain handling 

### TODO : Specify you template repo ROOT 

TEMPLATES_ROOT=lab.libreho.st/libre.sh/compose/ 

### TODO : change to your domain vendor ( ovh , online, )
DOMAIN_SERVER=namecheap

###  Namecheap specific
NAMECHEAP_URL="namecheap.com"
NAMECHEAP_API_USER="pierreo"
NAMECHEAP_API_KEY=

### ovh specific 
OVH_URL="eu.api.ovh.com"
OVH_API_USER=""
OVH_API_KEY=


IP="curl -s http://icanhazip.com/"
FirstName="Pierre"
LastName="Ozoux"
Address=""
PostalCode=""
Country="Portugal"
Phone="+351.967184553"
EmailAddress="pierre@ozoux.net"
City="Lisbon"
CountryCode="PT"
## Backup
BACKUP_DESTINATION=root@xxxxx:port
## SMTP
MAIL_USER=
MAIL_PASS=
MAIL_HOST=mail.indie.host
MAIL_PORT=587



echo "Welcome to libre.sh installer"
echo "WIP"


# STEP add kernel parameter

# STEP Define environnement

echo " setting up system variables"


# STEP "install docker-compose" 
# TODO : Fix a version for docker compose ? 

mkdir -p /opt/bin &&\
dockerComposeVersion=$(curl -s https://api.github.com/repos/docker/compose/releases/latest|grep tag_name|cut -d'"' -f4) &&\
curl -L https://github.com/docker/compose/releases/download/$dockerComposeVersion/docker-compose-`uname -s`-`uname -m` > /opt/bin/docker-compose &&\
chmod +x /opt/bin/docker-compose



# STEP install Libre.sh

echo " installing libre.sh" 

git clone https://lab.libreho.st/libre.sh/compose.libre.sh /libre.sh 
mkdir -p /{data,system}
mkdir /data/trash 
cp /libre.sh/unit-files/* /etc/systemd/system && systemctl daemon-reload 
systemctl enable web-net.service 
systemctl start web-net.service 
mkdir -p /opt/bin 
cp /libre.sh/utils/* /opt/bin/


# STEP add /opt/bin path


echo " - updating PATH" 
cat > /etc/profile.d/libre.sh <<EOF
export PATH=$PATH:/opt/bin
EOF
chmod 644 /etc/profile.d/libre.sh
