#!/bin/execlineb -P
fdmove -c 2 1

s6-envdir -I "/etc/sysconfig/backuppc"

# About backuppc logging management variables:
#
# LOG_DIR is the normal service logdir, it should be owned by the normal
# log_user.
#
# BACKUPPC_SERVER_LOGDIR is the directory whyere the BackupPC server 
# writes and self-manages its logs and other transient data. It should 
# be owned by the user BackupPC runs as.

importas -D "/var/log/backuppc"  log_dir        LOG_DIR
importas -s -D ""                extra_args     BACKUPPC_EXTRA_ARGS
importas -D "backuppc"           user           BACKUPPC_USER
importas -D "/run/backuppc"      rundir         BACKUPPC_RUNDIR
importas -D "${log_dir}/server"  server_logdir  BACKUPPC_SERVER_LOGDIR

s6-envdir -I /etc/sysconfig/backuppc


if { s6-mkdir -vp $rundir }
if { s6-envuidgid $user
     s6-chown -U  $rundir }

if { s6-mkdir -vp $server_logdir }
if { s6-envuidgid $user
     s6-chown -U  $server_logdir }

export S6_NOTIFICATION_FD 3

s6-setuidgid $user
/usr/libexec/backuppc/bin/BackupPC $extra_args
