#!/bin/bash
set -e

SETUP_DIR="/app/setup"
CONFIG_DIR="${SETUP_DIR}/config"
BURP="https://git.ziirish.me/ziirish/burp.git"
BURP_VERSION="1.4.40"

# Install burp
git clone $BURP
cd burp
git checkout tags/$BURP_VERSION
./configure --disable-ipv6
make -j
make install

# configure supervisord log rotation
cat > /etc/logrotate.d/supervisord <<EOF
/var/log/supervisor/*.log {
  weekly
  missingok
  rotate 52
  compress
  delaycompress
  notifempty
  copytruncate
}
EOF

# configure supervisord to start crond
cat > /etc/supervisor/conf.d/cron.conf <<EOF
[program:cron]
priority=20
directory=/tmp
command=/usr/sbin/cron -f
user=root
autostart=false
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
EOF

cp ${CONFIG_DIR}/burp/* /etc/burp/

cat >>/etc/crontab<<EOF
42 3,7,11,15,19,23 * * * root burp -c /etc/burp/demo1.conf -a t &>/dev/null
17 2,6,10,14,18,22 * * * root burp -c /etc/burp/demo2.conf -a t &>/dev/null
EOF

# cleanup
rm -rf /var/lib/apt/lists/*
