51 lines
1.3 KiB
Bash
51 lines
1.3 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
|
|
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
|