#!/usr/bin/env bash # 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. export HOMEPATH="$(realpath ~)" export REALPATH=$(realpath ${0}) export INSTALLER_LOCATION_REAL=$(dirname ${REALPATH}) 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 ] 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 $RELATIVE_CSHENV_LOCATION exit fi install_shell_file ~/.login install_shell_file ~/.tcshrc backup_config_file ~/.vimrc backup_config_file ~/.vim echo "Installing vim setup" pushd ~ >& /dev/null ln -s `echo ${RELATIVE_CSHENV_LOCATION}`/vim .vim ln -s .vim/vimrc .vimrc popd >& /dev/null backup_config_file ~/.gitconfig echo "Installing git configuration" echo "[include]" >> ~/.gitconfig echo " path = ${CSHENV_LOCATION}/git/gitconfig" >> ~/.gitconfig echo "" >> ~/.gitconfig echo "[user]" >> ~/.gitconfig echo " email = adam@recursive.engineer" >> ~/.gitconfig echo " name = ADAM David Alan Martin" >> ~/.gitconfig echo "" >> ~/.gitconfig echo " signingKey = \"`hostname` Git\"" >> ~/.gitconfig echo "" >> ~/.gitconfig echo "[commit]" >> ~/.gitconfig echo " gpgSign = true" >> ~/.gitconfig backup_config_file ~/.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