blob: fd89e7b630eeed1637a7fe7df70c7544a87032d7 (
plain) (
tree)
|
|
# This script looks at each directory in /var/www/users and
# writes its name into a file name `sites` if it is not empty.
# Helper function to make a rolling backup of a file.
function roll_files {
BASE=$1
INDEX=$(($2-1))
while [[ $INDEX -ge 1 ]];
do
if [ -f "$BASE.$INDEX" ]; then
NEXT=$((INDEX+1))
mv "$BASE.$INDEX" "$BASE.$NEXT"
fi
INDEX=$((INDEX-1))
done
if [ -f $BASE ]; then
mv "$BASE" "$BASE.1"
fi
}
# Helper function to determine if a directory is empty
function is_empty {
[ -z "$(find $1/. -maxdepth 1 -name . -o -print 2>/dev/null | head -n 1)" ]
}
FILE=${1:-sites}
BU_COUNT=${2:-5}
roll_files $FILE $BU_COUNT
for d in /var/www/users/*; do
if [ -d $d ] && $( ! is_empty $d ); then
print $( echo $d | sed -e 's?^.*/??' ) >> $FILE
fi
done
|