fix btrbk service
[distro-setup] / .bashrc
1 # Copyright (C) 2016 Ian Kelling
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6
7 # http://www.apache.org/licenses/LICENSE-2.0
8
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # to debug
16 #set -x
17 # redirect output to log file. this doesn't work. todo figure out why
18 #exec 1>>/a/tmp/bashlog
19 #exec 2>>/a/tmp/bashlog
20
21
22 # By default this file is sourced for ALL ssh commands. This is wonky.
23 # Normally, this file is not sourced when a script is run, but we can
24 # override that by having #!/bin/bash -l. I want something similar for ssh
25 # commands. when a local script runs an ssh command, this file should not be
26 # sourced by default, but we should be able to override that.
27 #
28 # So here we test for conditions of a script under ssh and return if so.
29 # And we don't keep the rest of the code in this file, because even
30 # though we return, we already parsed the whole code, and as I develop
31 # the code, the parsing can have errors, which can screw up cronjobs
32 # etc. To test for an overriding condition, we have a few options. one
33 # is to use an environment variable. env variables sent across ssh are
34 # strictly limited. ssh -t which sets $SSH_TTY, but within a script that
35 # won't work because tty allocation will fail. We could override an
36 # obscure unused LC_var, like telephone, but I don't want to run into
37 # some edge case where that messes things up. we could transfer a file
38 # which we could test for, but I can't think of a way to make that
39 # inherently limited to a single ssh command. I choose to set SendEnv
40 # and AcceptEnv ssh config vars to allow the environment variable
41 # BASH_LOGIN_SHELL to propagate across ssh.
42
43 # assume we want ssh commands to source this file if we are sourcing it,
44 # and we haven't specified otherwise already
45 [[ ! $BASH_LOGIN_SHELL ]] && export BASH_LOGIN_SHELL=true
46 #BASH_LOGIN_SHELL=false # temporary override
47
48 # first conditions show that we are an ssh command without an interactive shell
49 if [[ $SSH_CONNECTION ]] \
50 && [[ $- == *c* ]] \
51 && [[ ! $SSH_TTY ]] \
52 && [[ $- != *i* ]] \
53 && [[ ! $BASH_LOGIN_SHELL == true ]]; then
54 return 0
55 else
56 if [[ -r /etc/profile ]]; then
57 source /etc/profile
58 fi
59 _x=$(readlink -f $BASH_SOURCE)
60 _x=${_x%/*}/brc
61 if [[ -r $_x ]]; then
62 source $_x
63 fi
64 fi
65 # ensure no bad programs appending to this file will have an affect
66 return 0