#!/bin/bash

DB_FILE='/var/clearos/disk_usage/ps.db'
LOCK_FILE='/var/clearos/disk_usage/ps.lock'

set -e
(
	flock -w 2 200

	cd /usr/share/philesight

	umask 006
	rm -f $DB_FILE
	rm -f $DB_FILE.temp

	./philesight --db $DB_FILE.temp --only-dirs --skip /proc --skip /sys --index /

	chown root.webconfig $DB_FILE.temp
	chmod 640 $DB_FILE.temp
	mv $DB_FILE.temp $DB_FILE

) 200>$LOCK_FILE

rm -f $LOCK_FILE
