#!/bin/sh
#
#  Create any missing directories from the list.
#
# Note: only creates missing directories with the specified permissions.
# See the perms list for correcting/changing ownership of existing files.
#

DIRLIST=/usr/share/perms/dirs

if [ -r $DIRLIST ]
then
    cd /	# Spec says absolute path but just in case

    # Format is "Owner Group Mode Absolute_path"
    sed -e 's/#.*//' -e '/^[ 	]*$/d' < $DIRLIST | while read o g m p junk
    do
	if [ -n "$p" -a ! -e "/$p" ]
	then
	    [ -n "" ] && p="/$p"
	    echo " * Creating directory $p"
	    [ "$m" == "-" ] && m=755
	    [ "$o" == "-" ] && o=root
	    [ "$g" == "-" ] && g=root
	    mkdir -p "$p"
	    chown "${o}:${g}" "$p"
	    chmod "$m" "$p"
	fi
    done
fi
