#!/bin/csh -f
#+
# conk_script -- conk this OSIRIS account
#
# Purpose:
#       Remove all files in the existing account and replace them with
#       files from the ~osiris/config area.  Also, configure IRAF for HQ
#       accounts on papahaku.
#
# Usage:
#       conk_script
# 
# Arguments:
#       None
# 
# Output:
#       None
# 
# Restrictions:
#       Must be run from the account which is to be conked (e.g., deimos1)
# 
# Exit values:
#       0 = normal completion
#       1 = error
#
# Example:
#       1) To conk the deimos1 account, log into the appropriate computer
#       (papahaku at HQ, nuu at summit) as deimos1 and invoke this command:
#               ~deimos/config/conk_script
#
#-
# Modification history:
#       2001-Apr-30     GDW     Original version
#       2005-12-19      JM      No longer deletes .netscape and .mozilla
#       2008-Jul-22     GDW     Now removes .vnc directory
#       2008-Nov-14     jlyke   Now removes .vnc/passwd
#       2018-Jul-18     jlyke   Does not remove .vnc directory
#-----------------------------------------------------------------------

set buf = $0
set cmd = $buf:t
set usage = "Usage: $cmd"
set hq_host = papahaku

# try to determine who were are.  The INSTRUMENT envar may be
# undefined if the account is empty and there is not .cshrc file...
if ( $?INSTRUMENT ) then
        set instrument = $INSTRUMENT
else
        set instrument = `echo $USER | sed 's/[0-9]//g'`
endif

# prevent nuking the home account by accident...
if ( "$instrument" == "$USER" ) then
        printf "ERROR: cannot conk home account $USER\n"
        exit 1
endif

# define the directory from which to access files...
set config_path = /kroot/rel/default/data/conk
if ( ! -d $config_path ) then
        printf "ERROR: config directory $config_path not found\n"
        exit 1
endif

# delete all existing files in the directory EXCEPT for .rhosts and
# the '.snapshot' directory...
/usr/bin/find ~/{.??*,*} -prune \! \( -name .rhosts -o -name .snapshot -o -name .netscape -o -name .mozilla -o -name .ssh -o -name .ssh2 -o -name .vnc \) -exec \rm -fr {} \;

# now populate the directory with files from the config directory,
# excluding CVS directories...
# jlyke add "-L" option to "\cp -r" to follow symlinks
/usr/bin/find $config_path/{.??*,*} -prune \! -name CVS -exec \cp -r -L {} ~/ \;

# protect files with sensitive information...
foreach file (.rhosts .ssh/id_dsa .ssh/known_hosts .ssh/prng_seed .ssh/random_seed .ssh2/id_dsa_1024_a .vnc/passwd )
    if ( -e $file) chmod 600 $file
end

# finally, set up IRAF...
if ( $HOST == $hq_host ) then
    /sol/apps2/iraf2.11/irafbin/lmkiraf -noquery
endif


