ezirc/entrypoint.sh
2025-09-05 05:06:40 +00:00

52 lines
1.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
DATA_DIR=/data
TOR_DIR=${DATA_DIR}/tor
THELOUNGE_DIR=${DATA_DIR}/thelounge
NGIRCD_DIR=${DATA_DIR}/ngircd
mkdir -p "${TOR_DIR}" "${THELOUNGE_DIR}" "${NGIRCD_DIR}"
chown -R app:app "${DATA_DIR}"
# Start tor (uses DataDirectory as set in torrc)
su-exec app tor -f /etc/tor/torrc &
TORPID=$!
# Wait for hidden service hostname (give Tor up to 20s)
for i in $(seq 1 20); do
if [ -f "${TOR_DIR}/hidden_service/hostname" ]; then
break
fi
sleep 1
done
HS_NAME=`cat ${TOR_DIR}/hidden_service/hostname`
# Start ngircd (listening on 127.0.0.1:6667)
NGIRCD_CFG=${NGIRCD_DIR}/ngircd.conf
if [ ! -f "${NGIRCD_CFG}" ]; then
sed "s|%HS_NAME%|${HS_NAME}|g" "/etc/ngircd/ngircd.conf.template" > "${NGIRCD_CFG}"
mv /etc/ngircd/ngircd.motd ${NGIRCD_DIR}/ngircd.motd
chown -R app:app "${NGIRCD_DIR}/"
fi
ngircd -f ${NGIRCD_CFG} &
# Prepare The Lounge config from template if missing
THELOUNGE_CFG=${THELOUNGE_DIR}/config.js
if [ ! -f "${THELOUNGE_CFG}" ]; then
#THELOUNGE_NICK=${THELOUNGE_NICK:-DuckUser}
sed "s|%HS_NAME%|${HS_NAME}|g" "/thelounge-config.js.template" > "${THELOUNGE_CFG}"
chown app:app "${THELOUNGE_CFG}"
fi
echo ""
echo "Connect to http://${HS_NAME} on a Tor enabled browser, and don't forget to enable javascript."
echo ""
# Start The Lounge as non-root
export THELOUNGE_HOME=${THELOUNGE_DIR}
su-exec app /usr/bin/thelounge start
wait -n