Overhaul the installation and detection mechanisms

This commit is contained in:
2026-06-22 09:47:14 -04:00
parent cab9f98ef9
commit 8db7a5a13e
3 changed files with 89 additions and 54 deletions
+65 -39
View File
@@ -3,47 +3,73 @@
# Yeah, my CSHENV Install script is written in Bourne shell. This is because # Yeah, my CSHENV Install script is written in Bourne shell. This is because
# CSH isn't a great scripting language, but it is a nice interactive shell. # CSH isn't a great scripting language, but it is a nice interactive shell.
export REALPATH=`realpath $0` export HOMEPATH="$(realpath ~)"
export INSTALLER_LOCATION=`dirname ${REALPATH}` export REALPATH=$(realpath ${0})
export CSHENV_LOCATION=`dirname ${INSTALLER_LOCATION}` export INSTALLER_LOCATION_REAL=$(dirname ${REALPATH})
export RELATIVE_CSHENV_LOCATION=`realpath --relative-to=${HOME} ${CSHENV_LOCATION}` export INSTALLER_LOCATION=$(echo ${INSTALLER_LOCATION_REAL} | sed -e 's,'"${HOMEPATH}"',~,')
export CSHENV_LOCATION_REAL=$(dirname ${INSTALLER_LOCATION_REAL})
export CSHENV_LOCATION=$(echo ${CSHENV_LOCATION_REAL} | sed -e 's,'"${HOMEPATH}"',~,')
export RELATIVE_CSHENV_LOCATION=$(echo ${CSHENV_LOCATION} | sed -e 's,~/,,')
export TMP_BASE=$(realpath ~/.cshenv/installer-backup/)
mkdir -p ${TMP_BASE}
#mkdir -p ${TMP_BASE}
export __TMP=$(mktemp -dp ${TMP_BASE})
backup_config_file()
{
__file="${1}"
mkdir -p ${__TMP}/ssh
echo "Checking for ${__file}"
if [ -e ${__file} ]
then
case ${__file} in
*ssh/config)
echo "Backing up ${__file} to ${__TMP}/ssh"
mv ${__file} ${__TMP}/ssh/$(basename ${__file} | sed -e's/\.//')
;;
*)
echo "Backing up ${__file} to ${__TMP}"
mv ${__file} ${__TMP}/$(basename ${__file} | sed -e's/\.//')
;;
esac
else
echo "${__file} does not exist, not backing up anything."
fi
}
install_shell_file()
{
__file="${1}"
backup_config_file ${1}
echo "Installing ${1}"
echo "source ${CSHENV_LOCATION}/startup_hooks/$(basename ${1} | sed -e's/\.//') "'!#:1' > ${1}
}
if [ -v CSHENV_DEBUG_INSTALLER ] if [ -v CSHENV_DEBUG_INSTALLER ]
then then
echo HOMEPATH: $HOMEPATH
echo REALPATH: $REALPATH
echo TMP_BASE: $TMP_BASE
echo __TMP: $__TMP
echo INSTALLER_LOCATION_REAL: $INSTALLER_LOCATION_REAL
echo INSTALLER_LOCATION: $INSTALLER_LOCATION
echo CSHENV_LOCATION: $CSHENV_LOCATION
echo RELATIVE_CSHENV_LOCATION: $RELATIVE_CSHENV_LOCATION
echo $CSHENV_LOCATION echo $CSHENV_LOCATION
echo $RELATIVE_CSHENV_LOCATION echo $RELATIVE_CSHENV_LOCATION
exit exit
fi fi
echo "Checking for ~/.login" install_shell_file ~/.login
if [ ! -e ~/.login ]
then
echo "Installing ~/.login"
echo "setenv CSHENV_DIR ${CSHENV_LOCATION}" >> ~/.login
echo 'source ${CSHENV_DIR}/startup_hooks/login' >> ~/.login
fi
echo "Checking for ~/.tcshrc" install_shell_file ~/.tcshrc
if [ ! -e ~/.tcshrc ]
then
echo "Installing ~/.tcshrc"
echo "setenv CSHENV_DIR ${CSHENV_LOCATION}" >> ~/.tcshrc
echo "setenv CSHENV_HIDE_SHELL_LEVEL_AT_ONE" >> ~/.tcshrc
echo 'source ${CSHENV_DIR}/startup_hooks/tcshrc' >> ~/.tcshrc
fi
echo "Checking for vim setup" backup_config_file ~/.vimrc
if [ -e ~/.vimrc ] backup_config_file ~/.vim
then
echo "Relocating vimrc"
mv ~/.vimrc ~/.vim/vimrc.old
fi
if [ -e ~/.vim ]
then
echo "Relocating vim setup"
mv ~/.vim ~/.vim.old
fi
echo "Installing vim setup" echo "Installing vim setup"
pushd ~ >& /dev/null pushd ~ >& /dev/null
@@ -51,11 +77,7 @@ ln -s `echo ${RELATIVE_CSHENV_LOCATION}`/vim .vim
ln -s .vim/vimrc .vimrc ln -s .vim/vimrc .vimrc
popd >& /dev/null popd >& /dev/null
if [ -e ~/.gitconfig ] backup_config_file ~/.gitconfig
then
echo "Relocating git setup"
mv ~/.gitconfig ~/.gitconfig-old
fi
echo "Installing git configuration" echo "Installing git configuration"
@@ -73,6 +95,10 @@ echo "" >> ~/.gitconfig
echo "[commit]" >> ~/.gitconfig echo "[commit]" >> ~/.gitconfig
echo " gpgSign = true" >> ~/.gitconfig echo " gpgSign = true" >> ~/.gitconfig
echo "Do not forget to add the following lines at the top and bottom of your ssh config:" backup_config_file ~/.ssh/config
echo "Match all\n Include ${CSHENV_LOCATION}/ssh/config"
echo "Match all\n Include ${CSHENV_LOCATION}/ssh/config" echo "Match all" >> ~/.ssh/config
echo " Include ${CSHENV_LOCATION}/ssh/prologue" >> ~/.ssh/config
echo "Match all" >> ~/.ssh/config
echo " Include ${CSHENV_LOCATION}/ssh/epilogue" >> ~/.ssh/config
+22 -13
View File
@@ -1,14 +1,33 @@
# This file will always be taken in. .login is now # This file will always be taken in. .login is now
# vestigial, and doesn't matter if first or second. # vestigial, and doesn't matter if first or second.
# These are the bits that would be in login: # Reset the CSHENV_DIR
# (TODO: Downgrade this from environment variable to shell variable)
unsetenv CSHENV_DIR
if( ! $?CSHENV_DIR ) then if( ! $?CSHENV_DIR ) then
if( $?CSHENV_DEBUG ) then
echo "CSHENV_DIR is not set. Guessing it based upon "'${1}'": ${1}"
endif
# Done twice to strip out the hooks dir and the hook itself.
setenv CSHENV_DIR ${1}_
setenv CSHENV_DIR `dirname ${CSHENV_DIR}`
setenv CSHENV_DIR `dirname ${CSHENV_DIR}`
if( $?CSHENV_DEBUG ) then
echo "CSHENV_DIR is auto set to ${CSHENV_DIR}"
endif
if( "." == $#CSHENV_DIR ) then
if( $?CSHENV_DEBUG ) then
echo "CSHENV_DIR is still not set. Using guessed default."
endif
set cshenv_fallback_dir
setenv CSHENV_DIR ~/cshenv setenv CSHENV_DIR ~/cshenv
endif
endif endif
if( $?CSHENV_DEBUG ) then if( $?CSHENV_DEBUG ) then
echo "Set CSHENV_DIR to: " ${CSHENV_DIR} echo "Set (in tcshrc hook) CSHENV_DIR to: " ${CSHENV_DIR}
endif endif
setenv LC_NUMERIC en_US.UTF-8 setenv LC_NUMERIC en_US.UTF-8
@@ -25,16 +44,6 @@ if( $?CSHENV_DEBUG ) then
echo "Starting tcshrc..." echo "Starting tcshrc..."
endif endif
#if( -z ${_} ) then
#echo $0
#setenv CSHENV_TCSHRC_PATH $0
#else
#echo ${_}
#setenv CSHENV_TCSHRC_PATH "${_}"
#endif
#echo tcshrc hook lives at: ${CSHENV_TCSHRC_PATH}
if( -c `tty` ) then if( -c `tty` ) then
if( $?CSHENV_DEBUG ) then if( $?CSHENV_DEBUG ) then
echo "Going to source core tcshrc..." echo "Going to source core tcshrc..."
+1 -1
View File
@@ -1,6 +1,6 @@
# CSHENV Aliases: # CSHENV Aliases:
alias resource source ${CSHENV_DIR}/startup_hooks/tcshrc alias resource 'source ${CSHENV_DIR}/startup_hooks/tcshrc ${CSHENV_DIR}/startup_hooks/tcshrc'
alias relog resource alias relog resource
alias rl relog alias rl relog