#!/bin/sh

set -e

THIS_PACKAGE=rpcbind
# update-rc.d levels
K=06

if [ -f /sbin/runit ]; then
  if [ -d /etc/sv ] && [ ! -d "/etc/sv/rpcbind" ]; then
    cp -r /usr/share/runit/sv/rpcbind /etc/sv/
    echo "Copying to /etc/sv"
  fi
fi

 if [ ! -e /lib/init-diversity ] && [ $(dpkg -l | grep -ic "runit-antix") -eq 1 ] && [ $(ps -p1 | grep -ic "runit") -eq 1 ]; then  
  #remove /etc/init.d/rpcbind if it exists since we are using runit
  if [ -f /etc/init.d/rpcbind ]; then 
      mkdir -p /etc/init.d/disabled
      mv /etc/init.d/rpcbind /etc/init.d/disabled/rpcbind
  fi 
  if [ ! -h "/etc/service/rpcbind" ]; then
    ln -s /etc/sv/rpcbind/ /etc/service/
  fi  
else
  if [ -x /etc/init.d/rpcbind ]; then
    update-rc.d rpcbind defaults $K >/dev/null 2>&1
  fi
fi

if [ "$1" = configure ] ; then
         adduser --force-badname --system --quiet --home /run/rpcbind --no-create-home _rpc
fi

#DEBHELPER#
