Profile.d/global profile.sh

From 0xWIKI
Jump to: navigation, search
#!/bin/bash
# This script serves the purpose of setting up some nicely controlled initial settings
# and defaults for users of this server upon login

start()
{
	# Determine the tty
	IFS=/ ; i=0
	for p in $( tty ) ; do
		if ! [[ -z $p ]]; then
			term[$i]=$p ; i=$( expr $i + 1 )
		fi
	done
	term=${term[$( expr ${#term[@]} - 1)]}
	unset IFS

	# Determine whether or not the terminal is a tty or virtual console
	if [[ -z $( echo ${term} | grep -i 'tty' ) ]] ; then
		has_256=1
	else
		has_256=0
	fi

	# Is this the 'root' user?
	if [[ $( id -un ) = 'root' ]] ; then
		is_root=1
	else
		is_root=0
	fi

	# Set environment vars
	set_environment

	# Set up aliases
	set_aliases ${has_256} ${is_root}

	# Start unicode
	start_unicode

	# Custom commands
	run_commands ${is_root}
}

start_unicode()
{
	echo -n "Unicode support        : "

	if test -t 1 -a  -t 2; then
		echo "Supported, switching to unicode"
		echo -n -e '\033%G'
	else
		echo "Unsupported"
	fi
}

set_aliases()
{
	echo -n "Terminal color support : "

	# Color-support specific aliases
	if [[ $1 = 1 ]] ; then
		echo "256 colors"

		# Aliases
		alias vim='vim -T xterm-256color'
	else
		echo "16 colors"

		# Aliases
	fi

	# User-dependent aliases
	if ! [[ $2 = 1 ]] ; then
		alias who='/usr/bin/who | grep -v ^root'
		alias w='/usr/bin/w | grep -v ^root'
	fi

	# Non-dependent aliases
	alias ls='ls -lah --color=auto'
	alias grep='grep --color=auto'
	alias ps='ps axf -o ruser=User,tty=TTY,pid=PID,args=Command'
	alias su='su -l'
	alias cp='rsync -h --progress'
#	alias man='/usr/bin/vimviewer.sh man'
	alias less='/usr/bin/vimviewer.sh less'
	alias killall='killall -KILL'
}

set_environment()
{
	return 0
}

run_commands()
{
	# If the user is logged in as root
	if [[ $1 = 1 ]] ; then
		echo -en	# ATM this pretty much amounts to a no-op
	fi
}

# Run the script
start
Personal tools