#!/bin/sh

uci -q batch <<-EOF >/dev/null
	delete ucitrack.@amule[-1]
	add ucitrack amule
	set ucitrack.@amule[-1].init=amule
	commit ucitrack
EOF

while [ ! $(grep -e "amule" ${IPKG_INSTROOT}/etc/passwd) ]
do 
    gid=$(awk -v min=1000 -v max=1500 'BEGIN{srand(); print int(min+rand()*(max-min+1))}')
    echo amule:x:0:0:99999:7::: >> ${IPKG_INSTROOT}/etc/shadow
    grep -e ":$gid:" ${IPKG_INSTROOT}/etc/passwd || ( \
	echo "amule:x:$gid:amule" >> ${IPKG_INSTROOT}/etc/group ; \
	echo "amule:x:$gid:$gid:amule:/var/run/amule:/bin/false" >> ${IPKG_INSTROOT}/etc/passwd )
done

mkdir -p ${IPKG_INSTROOT}/etc/amule/
touch ${IPKG_INSTROOT}/etc/amule/addresses.dat
touch ${IPKG_INSTROOT}/etc/amule/ipfilter_static.dat
touch ${IPKG_INSTROOT}/etc/amule/shareddir.dat

rm -f /tmp/luci-indexcache
exit 0
