164 lines
4.7 KiB
Bash
164 lines
4.7 KiB
Bash
#!/bin/bash
|
|
|
|
case $(tty) in
|
|
# if we run on console, then terminate shell
|
|
/dev/tty[0-9]*)
|
|
# if we are root, exit after 5 minutes
|
|
# if we are user, exit after 10 minutes
|
|
case $(id -u) in
|
|
0)
|
|
TMOUT=${MSC_ROOT_TMOUT:-500}
|
|
;;
|
|
*)
|
|
TMOUT=${MSC_USER_TMOUT:-1000}
|
|
;;
|
|
esac
|
|
loginfo "Run in TTY -> set autologout \$TMOUT=$TMOUT" >&2
|
|
;;
|
|
*)
|
|
loginfo "Run in graphical terminal - set no autologout" >&2
|
|
unset TMOUT
|
|
;;
|
|
esac
|
|
|
|
# Load default values, functions, aliases for myshellconfig
|
|
if ! $SSHS; then
|
|
######################################################################################
|
|
# ls is not in color on all systems
|
|
export LS_OPTIONS='--color=auto'
|
|
eval "`dircolors`"
|
|
|
|
#######################################################################################
|
|
# User specific aliases and function
|
|
logdebug "notmpconf"
|
|
if [ -e ${MSC_BASE}/functions.sh ]; then
|
|
. ${MSC_BASE}/functions.sh
|
|
else
|
|
return
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ -d "${MSC_BASE}/bin" ] ; then
|
|
pathmunge "${MSC_BASE}/bin"
|
|
export PATH
|
|
fi
|
|
|
|
if [ -d "${MSC_BASE}/git-credential-pass" ] ; then
|
|
pathmunge "${MSC_BASE}/git-credential-pass"
|
|
export PATH
|
|
fi
|
|
|
|
if [ -f "${MSC_BASE}/aliases" ]; then
|
|
. "${MSC_BASE}/aliases"
|
|
fi
|
|
|
|
if [ -f ~/.bash_aliases ]; then
|
|
. ~/.bash_aliases
|
|
fi
|
|
|
|
|
|
if [ -f "${MSC_BASE}/PS1" ]; then
|
|
. "${MSC_BASE}/PS1"
|
|
fi
|
|
|
|
# Fehler anfang
|
|
#set -x
|
|
if [ -e "${MSC_BASH_COMPLETION}" ]; then
|
|
for i in $( ls "${MSC_BASH_COMPLETION}" ); do
|
|
. "${MSC_BASH_COMPLETION}/${i}"
|
|
done
|
|
unset i
|
|
fi
|
|
|
|
#set +x
|
|
# Fehler ende
|
|
|
|
if [ -f "${MSC_BASE}/myshell_load_fortmpconfig" ]; then
|
|
. "${MSC_BASE}/myshell_load_fortmpconfig"
|
|
fi
|
|
|
|
|
|
#########################################################################################
|
|
|
|
|
|
# Go HOME
|
|
#cd ${HOME}
|
|
|
|
# Start tmux if not defined as STARTTMUX in bashrc
|
|
logdebug "attach tmux?"
|
|
logdebug "TMUX: $TMUX"
|
|
logdebug "SSH_TTY: $SSH_TTY"
|
|
logdebug "TERM: $TERM"
|
|
logdebug "tmux@${USER}: $(systemctl status tmux@${USER}.service 1>/dev/null 2>&1; echo $? )"
|
|
if test $SSH_TTY; then
|
|
loginfo "i am remote"
|
|
if test ! $TMUX && test $TERM != screen; then
|
|
loginfo "no screen"
|
|
# if test $(systemctl status tmux@${USER}.service 1>/dev/null 2>&1; echo $? ) -eq 0; then
|
|
if tmux has-session -t User > /dev/null || tmux has-session -t "${USER}"; then
|
|
loginfo "tmux@${USER} is running"
|
|
loginfo "$(tmux list-sessions)"
|
|
STARTTMUXDEFAULT=${STARTTMUXREMOTEDEFAULT}
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
logdebug "STARTTMUXDEFAULT: ${STARTTMUXDEFAULT}"
|
|
|
|
unset -f pathmunge
|
|
|
|
else
|
|
# run with temporary config
|
|
|
|
logdebug "tmpconf"
|
|
case $TERM in
|
|
*screen*)
|
|
loginfo BASHRC: $BASHRC -> source it
|
|
#[ -e $BASHRC ] && . "$BASHRC"
|
|
if [ ! -z ${BASHRC+x} ]; then
|
|
if [ -e $BASHRC ] ; then
|
|
exec bash --rcfile "$BASHRC" -i /dev/null
|
|
else
|
|
exec bash -i
|
|
fi
|
|
else
|
|
exec bash -i
|
|
fi
|
|
|
|
;;
|
|
esac
|
|
|
|
fi
|
|
|
|
# Disable Ctrl+s to freeze terminal
|
|
# Source https://www.digitalocean.com/community/tutorials/how-to-use-bash-history-commands-and-expansions-on-a-linux-vps
|
|
stty -ixon
|
|
export HISTCONTROL=erasedups:ignorespace:ignoredups
|
|
export HISTIGNORE="ls:l:cd:exit:pwd:date:mencfs:"
|
|
export HISTTIMEFORMAT='%F %T '
|
|
export HISTSIZE=999999
|
|
|
|
loginfo "bashrc_add sourced" 2>&1 |tee -a ${MSC_LOGFILE} >&2
|
|
|
|
# Export several functions for being usable in subshells
|
|
export -f token
|
|
export -f sudo
|
|
export -f reachable
|
|
export -f reachable-default
|
|
|
|
|
|
|
|
|
|
[ -z "${SSH_IDENTITIES_DEFAULT_DIR+x}" ] && { SSH_IDENTITIES_DEFAULT_DIR="${HOME}/.ssh/identities"; export SSH_IDENTITIES_DEFAULT_DIR; }
|
|
[ -z "${SSH_AGENTS_DEFAULT_DIR+x}" ] && { SSH_AGENTS_DEFAULT_DIR="${HOME}/.ssh/agents"; export SSH_AGENTS_DEFAULT_DIR; }
|
|
[ -z "${SSH_AGENT_SOCKETS_DEFAULT_DIR+x}" ] && { SSH_AGENT_SOCKETS_DEFAULT_DIR="${HOME}/.ssh/agents"; export SSH_AGENT_SOCKETS_DEFAULT_DIR; }
|
|
[ -z "${SSH_AGENT_DEFAULT_OPTIONS+x}" ] && { SSH_AGENT_DEFAULT_OPTIONS='-t 7200'; export SSH_AGENT_DEFAULT_OPTIONS; }
|
|
[ -z "${SSH_ADD_DEFAULT_OPTIONS+x}" ] && { SSH_ADD_DEFAULT_OPTIONS="-t 7200"; export SSH_ADD_DEFAULT_OPTIONS; }
|
|
[ -z "${SSH_DEFAULT_IDENTITY+x}" ] && { SSH_DEFAULT_IDENTITY="default"; export SSH_DEFAULT_IDENTITY; }
|
|
|
|
[ -z "${SSH_AGENTS_DEFAULT_DIR+x}" ] || mkdir -p "${SSH_AGENTS_DEFAULT_DIR}"
|
|
|
|
|