#!/bin/bash

mkdir -p /home/container/discord_bot /home/container/server
cd '/home/container/discord_bot'
npm install
pm2 start bot.js

cd /home/container/server
echo 'Starting server on port ' "$PORT"

MODIFIED_STARTUP=`echo ${STARTUP} | perl -pe 's@\{\{(.*?)\}\}@$ENV{$1}@g'`
echo "Startup: ${MODIFIED_STARTUP}"
eval stdbuf -oL -i0 ${MODIFIED_STARTUP}

# Using stdbuf to force unbuffered output since server is not directly connected to terminal and is buffering output
#stdbuf -oL ./server -port "$PORT"
