eole-gitea/pretemplate/01-gitea-init

97 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# Install and initialize gitea
# Variables
WKDIR="/srv/forge"
USER="git"
GROUP="gitservice"
GECOS="Gitea User"
USERSHELL="/bin/bash"
HOMEDIR="${WKDIR}/${USER}"
OS="linux"
ARCH="amd64"
APPVERSION="1.8.2"
APPNAME="gitea"
APPBINARY="gitea"
APPSIG="7C9E68152594688862D62AF62D9AE806EC1592E2"
APPASC="${APPNAME}-${APPVERSION}-${OS}-${ARCH}.asc"
KEYSERV="pgp.mit.edu"
DLSERV="dl.gitea.io"
APPDIR="${WKDIR}/gitea"
APPBINDIR="${APPDIR}/bin"
APPCONFDIR="/etc/${APPNAME}"
if [[ -d ${APPCONFDIR} ]]
then
exit 0
fi
proxy=$(CreoleGet activer_proxy_client non)
if [[ ${proxy} == "oui" ]]
then
prAddr=$(CreoleGet proxy_client_adresse)
prPort=$(CreoleGet proxy_client_port)
export HTTP_PROXY=http://${prAddr}:${prPort}
export http_proxy=http://${prAddr}:${prPort}
export HTTPS_PROXY=http://${prAddr}:${prPort}
export https_proxy=http://${prAddr}:${prPort}
fi
if [[ ! -d ${APPDIR} ]]
then
mkdir -p ${APPDIR}
chown ${USER}:${GROUP} ${APPDIR} -R
fi
# Create app user and group
groupadd ${GROUP}
adduser \
--shell ${USERSHELL} \
--gecos "${GECOS}" \
--ingroup ${GROUP} \
--disabled-password \
--home ${HOMEDIR} \
${USER}
# Create app structure
mkdir -p ${APPDIR}/{custom,data,indexers,public,log}
chown ${USER}:${GROUP} ${APPDIR}/{data,indexers,log}
chmod 750 ${APPDIR}/{data,indexers,log}
mkdir ${APPCONFDIR}
chown root:${GROUP} ${APPCONFDIR}
chmod 770 ${APPCONFDIR}
if [[ ! -d ${APPBINDIR} ]]
then
mkdir -p ${APPBINDIR}
chown ${USER}:${GROUP} ${APPBINDIR}
fi
cd $APPBINDIR
if [[ ! -f ${APPBINARY} ]]
then
wget -O ${APPBINARY} https://${DLSERV}/${APPNAME}/${APPVERSION}/${APPNAME}-${APPVERSION}-${OS}-${ARCH}
if [[ $? -eq 0 ]]
then
chmod +x ${APPBINARY}
else
echo "Error downloading binary for ${APPNAME}"
return 123
fi
fi
if [[ ! -f ${APPASC} ]]
then
wget -O ${APPASC} https://${DLSERV}/${APPNAME}/${APPVERSION}/${APPASC}
gpg --keyserver ${KEYSERV} --recv ${APPSIG}
gpg --verify ${APPNAME}-${APPVERSION}-${OS}-${ARCH}.asc ${APPBINARY}
fi
cd -