#! /bin/bash set -e set -u VERSION=v0.0 SYN_HTTP_PORT=8008 SYN_HTTPS_PORT=8448 DISC_PORT=9006 RIOT_PORT=8889 DOMAIN=localhost function main() { cd "$(dirname "${BASH_SOURCE[0]}")" setup_modules build_modules | while read -r line; do echo EVAL: $line eval "$line" done run_modules } function setup_modules() { git submodule update for i in $(cat ./.gitmodules | grep path | awk '{print $NF}'); do pushd "./${i}" echo SETUP $(basename "$i") checkout_latest_tag popd done } function checkout_latest_tag() { git fetch --tags local tag="$(git tag | sort | tail -n 1)" git checkout $tag } function build_modules() { ( docker network create riot-matrix-net || true ) >&2 for i in $(cat ./.gitmodules | grep path | awk '{print $NF}' | sed 's/docker-matrix-riot/docker-matrix-riot-ptt/' ); do pushd "./${i}" >&2 echo BUILD $(basename "$i") >&2 build_module "$(basename "$i")" | tail -n 1 popd >&2 done } function build_module() { local basename="$1" local img="bel/$basename:$VERSION" local mnt="$(dirname "$(pwd)")/mnt/$basename" local pre=() local post=() local run="" local f=$(mktemp) local g=$(mktemp) case "$basename" in docker-matrix ) run="-p $SYN_HTTPS_PORT:$SYN_HTTPS_PORT -p $SYN_HTTP_PORT:$SYN_HTTP_PORT -p 3478:3478 $img start" post+=("docker run --rm -i -e SERVER_NAME=$DOMAIN -e REPORT_STATS=no -v $mnt:/data $img generate") post+=("sudo cp $mnt/homeserver.yaml $f") post+=("sed 's/enable_registration:.*/enable_registration: True/' $f > $g; mv $g $f") post+=("sed 's/enable_group_creation: false/enable_group_creation: true/' $f > $g; mv $g $f") post+=("sed 's/ - port: 8008/ - port: $SYN_HTTP_PORT/' $f > $g; mv $g $f") post+=("sed 's/ port: 8448/ port: $SYN_HTTPS_PORT/' $f > $g; mv $g $f") post+=("sed 's/ bind_addresses:.*/ bind_addresses: [\"::\", \"0.0.0.0\"]/' $f > $g; mv $g $f") post+=("sed 's/app_service_config_files.*$/app_service_config_files: [ \\/data\\/discord-registration.yaml ]/' $f > $g; mv $g $f") post+=("echo 'auto_join_rooms: [ \"#welcome:$DOMAIN\" ]' >> $f") post+=("sudo mv $f $mnt/homeserver.yaml") ;; docker-matrix-riot* ) run="-p $RIOT_PORT:$RIOT_PORT $img" post+=("touch $mnt/riot.im.conf") post+=("echo '-p $RIOT_PORT' > $mnt/riot.im.conf") post+=("echo '-A 0.0.0.0' >> $mnt/riot.im.conf") post+=("echo '-c 3500' >> $mnt/riot.im.conf") post+=("curl https://raw.githubusercontent.com/vector-im/riot-web/develop/config.sample.json > $mnt/config.json") post+=("sed 's/\"default_hs_url\".*/\"default_hs_url\":\"http:\\/\\/docker-matrix:8008\",/' $mnt/config.json > $f; mv $f $mnt/config.json") post+=("sed 's/\"default_is_url\".*/\"default_is_url\":\"http:\\/\\/docker-matrix:8008\",/' $mnt/config.json > $f; mv $f $mnt/config.json") #post+=("echo '--ssl' >> $mnt/config.json") #post+=("echo '--cert /data/cert.pem' >> $mnt/config.json") #post+=("echo '--key /data/key.pem' >> $mnt/config.json") ;; matrix-appservice-discord* ) run="-p $DISC_PORT:$DISC_PORT $img" post+=("cp config/config.sample.yaml $mnt/config.yaml") post+=("sed 's/ domain: .*$/ domain: $DOMAIN/' $mnt/config.yaml > $f; mv $f $mnt/config.yaml") post+=("sed 's/ homeserverUrl: .*$/ homeserverUrl: http:\\/\\/$DOMAIN:$SYN_HTTP_PORT/' $mnt/config.yaml > $f; mv $f $mnt/config.yaml") post+=("sed 's/ userStorePath:.*$/ userStorePath: \/data\/user-store.db/' $mnt/config.yaml > $f; mv $f $mnt/config.yaml") post+=("sed 's/ roomStorePath:.*$/ roomStorePath: \/data\/room-store.db/' $mnt/config.yaml > $f; mv $f $mnt/config.yaml") post+=("sed 's/ filename:.*$/ filename: \/data\/discord.db/' $mnt/config.yaml > $f; mv $f $mnt/config.yaml") post+=("npm install") post+=("npm run build") post+=("node build/src/discordas.js -r -u 'http:\\/\\/$DOMAIN:$DISC_PORT' -c $mnt/config.yaml") post+=("cp discord-registration.yaml ${mnt%$basename*}/docker-matrix/") post+=("cp discord-registration.yaml $mnt/discord-registration.yaml") ;; * ) return ;; esac mkdir -p "$mnt" for i in "${pre[@]:-}"; do eval "$i" done docker build -t $img . for i in "${post[@]}"; do eval "$i" done rm -f "$f" "$g" echo "docker run --name $basename --rm -d -v $mnt:/data --network riot-matrix-net --net-alias $basename $run" } function run_modules() { local run_cmds=("${@:-}") for cmd in "${run_cmds[@]}"; do echo RUN $(basename "$cmd") echo $cmd done } if [ "$0" == "${BASH_SOURCE[0]}" ]; then main "$@" fi