#!/bin/sh -e

##########################################################################
#   Script description:
#       Set default umask
#
#   Arguments:
#       umask in octal
#       
#   History:
#   Date        Name        Modification
#   2018-09-27  J Bacon     Begin
##########################################################################

usage()
{
    printf "Usage: $0 octal-umask\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# != 1 ]; then
    usage
fi

umask=$1
case `auto-ostype` in
FreeBSD)
    sed -i '' -e "s|umask=022|umask=$umask|g" /etc/login.conf
    cap_mkdb /etc/login.conf
    ;;

RHEL)
    # FIXME: How to ensure umask is set for all shells? ksh? zsh?
    for shell in sh csh; do
	printf "umask $umask\n" > /etc/profile.d/auto-umask.$shell
	chmod 644 /etc/profile.d/auto-umask.$shell
    done
    ;;

esac
