gemini-agate-image/entrypoint.sh

71 lines
1.6 KiB
Bash
Raw Normal View History

2021-02-20 20:47:59 +00:00
#!/bin/sh
2022-09-18 12:54:50 +00:00
set -e
2021-02-20 20:47:59 +00:00
create_new_cert(){
if [ ! -d "${GEMINI_CERT_PATH}" ]; then
mkdir ${GEMINI_CERT_PATH}
fi
openssl req -x509 -newkey rsa:4096 -keyout ${GEMINI_CERT_PATH}/key.rsa -out ${GEMINI_CERT_PATH}/cert.pem \
-days 3650 -nodes -subj "/CN=${GEMINI_DOMAIN}"
}
clone_repository(){
git clone ${GEMINI_GIT_REPO} ${GEMINI_GIT_PATH}
2022-09-18 12:54:50 +00:00
prepare_content
2021-02-20 20:47:59 +00:00
}
update_repository(){
if [ ! -d "${GEMINI_GIT_PATH}" ]; then
echo "Cloning repository in ${GEMINI_GIT_PATH}"
clone_repository
else
cd ${GEMINI_GIT_PATH}
git pull
2022-09-18 12:54:50 +00:00
prepare_content
fi
}
prepare_content(){
if [ "${GEMINI_KILN_BUILD}" == "true" ]; then
2022-09-18 13:19:32 +00:00
echo "Building content with kiln build ${GEMINI_KILN_SRC}"
cd ${GEMINI_GIT_PATH}
2022-09-18 13:11:07 +00:00
kiln build ${GEMINI_KILN_SRC}
2021-02-20 20:47:59 +00:00
fi
}
run_agate(){
/app/agate --content ${GEMINI_GIT_PATH}/${GEMINI_CONTENT_FOLDER} \
2022-09-18 12:54:50 +00:00
--certs ${GEMINI_CERT_PATH} \
--addr [::]:${GEMINI_PORT} \
--addr 0.0.0.0:${GEMINI_PORT} \
2021-02-20 20:47:59 +00:00
--hostname ${GEMINI_DOMAIN} \
--lang ${GEMINI_LANG}
}
default(){
if [ ! -f "${GEMINI_CERT_PATH}/cert.pem" ]; then
echo "No certs found in {GEMINI_CERT_PATH}. Creates new certificate."
create_new_cert
fi
if [ ! -d "${GEMINI_GIT_PATH}" ]; then
echo "Cloning repository in ${GEMINI_GIT_PATH}"
clone_repository
else
update_repository
fi
echo "Starting agate for gemini://${GEMINI_DOMAIN}"
run_agate
}
if [ "$#" -eq "1" ]; then
if [ "$1" = "run" ]; then
default
elif [ "$1" = "update" ]; then
update_repository
fi
else
echo "unknown command. launching default"
default
fi