shellcheck and fix checkrestart false positive
[distro-setup] / .bashrc
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4
5 # to debug
6 #set -x
7 # redirect output to log file. this doesn't work. todo figure out why
8 #exec 1>>/a/tmp/bashlog
9 #exec 2>>/a/tmp/bashlog
10
11
12 # By default this file is sourced for ALL ssh commands. This is wonky.
13 # Normally, this file is not sourced when a script is run, but we can
14 # override that by having #!/bin/bash -l. I want something similar for ssh
15 # commands. when a local script runs an ssh command, this file should not be
16 # sourced by default, but we should be able to override that.
17 #
18 # So here we test for conditions of a script under ssh and return if so.
19 # And we don't keep the rest of the code in this file, because even
20 # though we return, we already parsed the whole code, and as I develop
21 # the code, the parsing can have errors, which can screw up cronjobs
22 # etc. To test for an overriding condition, we have a few options. one
23 # is to use an environment variable. env variables sent across ssh are
24 # strictly limited. ssh -t which sets $SSH_TTY, but within a script that
25 # won't work because tty allocation will fail. We could override an
26 # obscure unused LC_var, like telephone, but I don't want to run into
27 # some edge case where that messes things up. we could transfer a file
28 # which we could test for, but I can't think of a way to make that
29 # inherently limited to a single ssh command. I choose to set SendEnv
30 # and AcceptEnv ssh config vars to allow the environment variable
31 # BASH_LOGIN_SHELL to propagate across ssh. This also requires that we
32 # wrap ssh in interactive shells, because, once we export the var, it
33 # will go into scripts and theres no way to automatically set it.
34
35
36 # first conditions show that we are an ssh command without an interactive shell
37 if [[ $SSH_CONNECTION ]] \
38 && [[ $- == *c* ]] \
39 && [[ ! $SSH_TTY ]] \
40 && [[ $- != *i* ]] \
41 && [[ $BASH_LOGIN_SHELL != true ]]; then
42 return 0
43 else
44 if [[ -r /etc/profile ]]; then
45 source /etc/profile
46 fi
47 _x=$(readlink -f ${BASH_SOURCE[0]})
48 _x=${_x%/*}/brc
49 if [[ -r $_x ]]; then
50 # shellcheck source=./brc
51 source $_x
52 fi
53 fi
54 # ensure no bad programs appending to this file will have an affect
55 return 0