HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: //usr/openv/netbackup/logs/mklogdir
#!/bin/sh
# $Id$
# $Copyright: Copyright (c) 2016 Veritas Technologies LLC. All rights reserved VT25-0977-2658-84-51-3 $ 
#Log list that will be created. 1 specifies that the directory will be created WW

# Set umask to 022 to make sure files and directories
# are not created with world writable permissions.
umask 022


logs_list="admin;1
	backint;1
	bp;1
	bpVMreq;1
	bpVMutil;1
	bparchive;1
	bpbackup;1
	bpbkar;1
	bpbrm;0
	bpbrmds;0
	bpcd;0
	bpclimagelist;1
	bpclntcmd;1
	bpcompatd;0
	bpconverttouch;1
	bpdb2;1
	bpdbjobs;1
	bpdbm;0
	bpdbsbdb2;1
	bpdbsbora;1
	bpdhcp;1
	bpdm;0
	bpfilter;1
	bpfis;1
	bpfsmap;0
	bphdb;1
	bpinst;1
	bpjava-msvc;0
	bpjava-susvc;1
	bpjava-usvc;1
	bpjobd;0
	bpkeyutil;1
	bplist;1
	bpmount;1
	bpnbat;1
	bporaexp;1
	bporaexp64;1
	bporaimp;1
	bporaimp64;1
	bppfi;0
	bpps;1
	bprd;0
	bprestore;1
	bpstsinfo;1
	bpsynth;1
	bptm;0
	cluster;1
	dbclient;1
	exten_client;1
	infxbsa;1
	liveupdate;1
	mtfrd;1
	nbauditreport;1
	nbazd;0
	nbcert;1
	nbcssc;1
	nbdb;0
	nbdedupmts;0
	nbfp;0
	nbfsd;0
	nbidmap;0
	nbifs;1
	nbjsonformat;0
	nbliveup;1
	nblogadm;1
	nblogadmagent;0
	nblogadmhelper;0
	nbmsw;1
	nboraadm;1
	nborabkupsets;1
	nbostpxy;1
	nbproxy;0
	nbregopsc;0
	nbrestorevm;1
	nbsqladm;1
    nbtelepush;0
	nbvault;0
	ncf;1
	patch;1
	spsdkservice;1
	sybackup;1
	symlogs;0
	tar;1
	user_ops;1
	vault;1
	vnetd;0
	vxms;0"

validate_command()
{
	cmd_r="$1"
	# Options that can be passed are : create,dryrun,list,fixFolderPerm
	if [ "$cmd_r" != "" ] ; then
		if [ ${cmd_r} = "create" -o \
			${cmd_r} = "list" -o \
			${cmd_r} = "dryrun" -o \
			${cmd_r} = "fixFolderPerm" ] ; then
			valid_cmd=1
			elif [ "${cmd_r}" = "help" ] ; then
			print_usage_and_exit
		else
			echo "Invalid Usage"
			print_usage_and_exit
		fi
	fi
}

print_usage_and_exit()
{
	echo "mklogdir [-create] [-dryrun] [logdirname ]"
	echo "mklogdir -fixFolderPerm [-dryrun] [logdirname ]"
	echo "mklogdir -list"
	exit 22
}
#Processes the request passed either for all directories or for specific directories
process_request()
{
	all=0
	if [ "$1" = "all" ] ; then
		# Going to be processing all directories
		all=1
	else
		logdir=$1
	fi

	if [ ${create_req} -eq 1 ] ; then
		if [ ${all} -eq 1 ] ; then
			perform_op_all_log_dir "create"
		else
			perform_op_log_dir "create" "${logdir}"
		fi

	elif [ ${fixFolderPerm_req} -eq 1 ] ; then
		if [ ${all} -eq 1 ] ; then
			perform_op_all_log_dir "fixFolderPerm"
		else
			perform_op_log_dir "fixFolderPerm" "${logdir}"
		fi
	else
		# This case will be encountered if user has specified mklogdir [logdirname]
		perform_op_log_dir "create" "${logdir}"
	fi
}

# Function to process operations for all log dirs
perform_op_all_log_dir()
{
	OP=$1
	for dir in ${logs_list}
	do
		# Parsing log list on delimiter ; and storing the output in $dirinfo
		dirinfo=`echo ${dir} | awk -F";" '{print $1,$2}'`
		set -- ${dirinfo}
		dirname=$1
		dircreationmode=$2
		if [ ${dircreationmode} -eq 1 ] ; then
			dircreationmode=1777
			mode_word="drwxrwxrwt"
		else
			dircreationmode=0755
			mode_word="drwxr-xr-x"
		fi
		case "${OP}" in
			'create')
				if [ ${dryrun_req} -eq 1 ] ; then
					echo "[${dirname}] will be created with [${dircreationmode}] permissions"
				else
					if [ ! -d $NBLOGS/${dirname} ] ; then
						mkdir $NBLOGS/${dirname}
						echo "Creating [${dirname}] with permissions [${dircreationmode}]"
					else
						echo "Directory [${dirname}] exists.Modifying its permission to [${dircreationmode}]"
					fi
					chmod ${dircreationmode} $NBLOGS/${dirname}
				fi
				;;
			'list')
				echo "Directory [${dirname}] will be created with [${dircreationmode}] permissions"
				;;
			'fixFolderPerm')
				if [ -d $NBLOGS/${dirname} ] ; then
					perform_op_log_dir "fixFolderPerm" "${dirname}"
				fi
				;;
		esac
	done
}

perform_op_log_dir()
{
	OP=$1
	logdir=$2
	for dir in ${logs_list}
	do
		dirinfo=`echo ${dir} | awk -F";" '{print $1,$2}'`
		set -- ${dirinfo}
		dirname=$1
		if [ "${dirname}" = "$logdir" ] ; then
			dircreationmode=$2
			if [ ${dircreationmode} -eq 1 ] ; then
				dircreationmode=1777
				mode_word="drwxrwxrwt"
			else
				dircreationmode=0755
				mode_word="drwxr-xr-x"
			fi
			case ${OP} in 
			'create')
				if [ ${dryrun_req} -eq 1 ] ; then
					echo "
					[${dirname}] will be created with [${dircreationmode}] permissions
					"
				else
					if [ ! -d $NBLOGS/${dirname} ] ; then
						mkdir $NBLOGS/${dirname}
						echo "Creating [${dirname}] with permissions [${dircreationmode}]"
					else
						echo "Directory [${dirname}] exists.Modifying its permission to [${dircreationmode}]"
					fi
					chmod ${dircreationmode} $NBLOGS/${dirname}
				fi
				;;
			'find')
				#Log directory specified is a valid NBU log directory
				found=1
				;;
			'display')
				echo "Directory [${dirname}] will be created with [${dircreationmode}] permissions"
				;;
			'fixFolderPerm')
				# Here, we will be verifying if the log folders exist with their appropriate permissions.
				dir_info=`find $NBLOGS/ -name "${dirname}" -type d -exec ls -ld '{}' \;`
				set -- ${dir_info}
				# fetch the existing directory permissions
				exist_dir_perms=`echo ${dir_info} | awk '{print $1}'`
				set -- ${exist_dir_perms}
				if [ "${mode_word}" != "${exist_dir_perms}" ] ; then
					echo "Will be setting permissions of "[${dirname}]" to "[${dircreationmode}]""
					if [ ${dryrun_req} -eq 1 ] ; then
						return
					else
						echo "Fixed "[${dirname}]" directory permisisons."
						chmod ${dircreationmode} $NBLOGS/${logdir}
					fi
				else
					echo "Directory [${dirname}] has appropriate permissions"
				fi
			esac
			break
			return
		fi
	done
}

create_req=0
dryrun_req=0
fixFolderPerm_req=0
list_req=0
n=0
NBLOGS=\/usr\/openv\/netbackup\/logs

if [ "$1" != "" ] ; then
	for ARG in $*
	do
		valid=0
		cmd=`echo "$ARG" | awk -F"-" '{print $2}'`
		validate_command ${cmd}
		case ${ARG} in
			'-create')
				create_req=1
				;;
			'-dryrun')
				dryrun_req=1
				;;
			'-list')
				list_req=1
				;;
			'-fixFolderPerm')
				fixFolderPerm_req=1
				;;
			*)
				# Adding log directories passed by commandline
				eval dir_list$n="$ARG"
				n=`expr $n + 1`
				;;
		esac
	done
else
	# Retaining the existing behaviour of mklogdir; if no command line parameter specified, we go ahead and create the log directories
	perform_op_all_log_dir "create"
	exit
fi

# Cannot specify create and fixFolderPerm_together
if [ ${create_req} -eq 1 ] ; then
	if [ ${fixFolderPerm_req} -eq 1 ] ; then
		echo "Invalid usage!"
		print_usage_and_exit
	fi
fi

if [ ${list_req} -eq 1 ] ; then
	if [ ${create_req} -eq 1 -o ${fixFolderPerm_req} -eq 1 -o ${dryrun_req} -eq 1 ] ; then
		echo "Invalid usage!"
		print_usage_and_exit
	else
		perform_op_all_log_dir "list"
	fi
fi

# If user specifies log dirs, process each of them in a loop
i=0

if [ ${n} -gt 0 ] ; then
	while [ ${i} -lt ${n} ] ;
	do
		found=0
		# Fetch the directory name from the array
		eval logdir=""\$dir_list$i""
		perform_op_log_dir "find" "${logdir}"
		if [ ${found} -eq 1 ] ; then
			process_request "${logdir}"
		else
			echo
			echo "Directory [${logdir}] requested for creation is not a valid NetBackup debug directory.Please try again"
		fi
		i=`expr $i + 1`
	done
else
	# No log directories specified in command line, going ahead and processing all
	process_request "all"
fi