#!/sbin/openrc-run

pidfile="/run/i2pd/i2pd.pid"
logfile="/var/log/i2pd/i2pd.log"
mainconf="/etc/i2pd/i2pd.conf"
tunconf="/etc/i2pd/tunnels.conf"
tundir="/etc/i2pd/tunnels.conf.d"

name="i2pd"
command="/usr/bin/i2pd"
command_args="--service --daemon --log=file --logfile=$logfile --conf=$mainconf --tunconf=$tunconf --tunnelsdir=$tundir --pidfile=$pidfile"
description="C++ daemon for accessing the I2P network"
required_dirs="/var/lib/i2pd"
required_files="$mainconf"
start_stop_daemon_args="--chuid i2pd"

depend() {
  need mountall
  use net
  after bootmisc
}

start_pre() {
  if [ -r /etc/default/i2pd ]; then
    . /etc/default/i2pd
  fi

  if [ "x$I2PD_ENABLED" != "xyes" ]; then
    ewarn "i2pd disabled in /etc/default/i2pd"
    exit 1
  fi

  checkpath -d -m 0755 -o i2pd:adm /var/log/i2pd
  checkpath -d -m 0755 -o i2pd:adm /run/i2pd
  checkpath -f -o i2pd:adm $logfile
  checkpath -f -o i2pd:adm $pidfile

  if [ -n "$DAEMON_OPTS" ]; then
    command_args="$command_args $DAEMON_OPTS"
  fi
}
