#!/bin/bash
set -x

dir_data=/data/.acme.sh
app_cmd=$dir_data/acme.sh
dir_config=$dir_data/config
dir_certs=$dir_data/certs
export LE_WORKING_DIR=$dir_data
export LE_CONFIG_HOME=$dir_config


command -v curl || {
	command -v apk && apk -U upgrade && apk add curl
	command -v apt-get && apt-get -qqy update && apt-get -qqy install curl
}
url_acmesh='https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh'
curl -o /tmp/acme.sh $url_acmesh && chmod +x /tmp/acme.sh


mkdir -p $dir_data $dir_config $dir_certs
/tmp/acme.sh \
	--home $dir_data \
	--cert-home $dir_certs \
	--config-home $dir_config
	--no-cron \
	--no-profile \
	--force \
	--install-online

$app_cmd --config-home $dir_config -v

