Skip to content

Instantly share code, notes, and snippets.

@idodeclare
Last active April 25, 2020 01:12
Show Gist options
  • Select an option

  • Save idodeclare/dcefcbd2defe08c683ea0a229c0d7068 to your computer and use it in GitHub Desktop.

Select an option

Save idodeclare/dcefcbd2defe08c683ea0a229c0d7068 to your computer and use it in GitHub Desktop.
OmniTI's auto_home.sh script
#!/bin/bash
# Script to automatically create home directories on demand, and mount them
# from BASE (default /export/home)
BASE=/export/home
ID=$(/bin/id $1 2>/dev/null)
if [[ -n "$ID" ]]; then
if [[ ! -d "$BASE/$1" ]]; then
DSET=$(/usr/sbin/zfs list -H -o mountpoint,zoned,name | gawk -v base=$BASE -v zone=$(zonename) '$1==base && ( $2=="off" || zone != "global" ) { print $3 }')
if [[ -n "$DSET" ]]; then
/usr/sbin/zfs create $DSET/$1
else
/bin/mkdir -p $BASE/$1
fi
cat > $BASE/$1/.bash_profile <<'EOF1'
PATH="/usr/ccs/bin:/usr/sfw/bin:/usr/gnu/bin:/usr/bin:/usr/sbin:/opt/omni/bin:/opt/OMNIperl/bin"
MANPATH=/usr/share/man:/opt/omni/share/man:/opt/omni/man
EDITOR=vi
PS1='\u@\h:\w\$ '
export PATH MANPATH EDITOR PS1
[[ $TERM == 'xterm' ]] && export TERM=dtterm
[[ $TERM == 'xterm-color' ]] && export TERM=dtterm
[[ -f ${HOME}/.bashrc ]] && . ${HOME}/.bashrc
EOF1
cat > $BASE/$1/.vimrc <<'EOF2'
set nocompatible backspace=2
set expandtab
set sts=4
set sw=4
syntax enable
EOF2
/bin/chown -R $1 $BASE/$1
fi
echo "localhost:$BASE/$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment