# SPDX-License-Identifier: AGPL-3.0-or-later
# this gets sourced. shebang is just for file mode detection
-source /a/bin/errhandle/err
+# Use source ~/.bashrc instead of doing bash -l when running a script
+# so this can set extdebug and avoid the bash debugger.
+if [[ -s /a/bin/errhandle/err ]]; then
+ source /a/bin/errhandle/err
+elif [[ -s ~/.iank/err ]]; then
+ # shellcheck source=/a/bin/errhandle/err
+ source ~/.iank/err
+fi
# * settings
fi
if [[ -s /a/bin/small-misc-bash/ll-function ]]; then
- # shellcheck source=/a/bin/small-misc-bash/ll-function
source /a/bin/small-misc-bash/ll-function
elif [[ -s ~/.iank/ll-function ]]; then
+ # shellcheck source=/a/bin/small-misc-bash/ll-function
source ~/.iank/ll-function
fi
+
# * functions
find -L $1 -type f -not \( -name .svn -prune -o -name .git -prune \
-o -name .hg -prune -o -name .editor-backups -prune \
-o -name .undo-tree-history -prune \) \
- -exec bash -lc 'hr; echo "$1"; hr; cat "$1"' _ {} \; 2>/dev/null
+ -exec bash -c '. ~/.bashrc; hr; echo "$1"; hr; cat "$1"' _ {} \; 2>/dev/null
}
less /var/log/exim4/mainlog
}
eqcat() {
- exiqgrep -i | while read i; do
+ exiqgrep -i | while read -r i; do
exim -Mvh $i; hr; exim -Mvb $i; hr;
exigrep $i /var/log/exim4/mainlog; hr
done
}
grr() { # grep recursive
+ # Don't return 1 on nonmatch because this is meant to be
+ # interactive, not in a conditional.
if [[ ${#@} == 1 ]]; then
- grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto "$@" .
+ grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto "$@" . || [[ $? == 1 ]]
else
- grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto "$@"
+ grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto "$@" || [[ $? == 1 ]]
fi
}
rg() {
hr() { # horizontal row. used to break up output
- printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo {1..${COLUMNS:-60}})
+ printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo "{1..${COLUMNS:-60}}")
echo
}
esac
}
+psg () {
+ local x y help
+ help="Usage: psg [--help] GREP_ARGS
+grep ps and output in a nice format"
+ if [[ $1 == --help ]]; then
+ echo "$help"
+ return
+ fi
+ x=$(sudo ps -eF)
+ # final grep is because some commands tend to have a lot of trailing spaces
+ y=$(echo "$x" | grep -iP "$@" | grep -o '.*[^ ]') ||:
+ if [[ $y ]]; then
+ echo "$x" | head -n 1
+ echo "$y"
+ fi
+}
+
pubip() { curl -4s https://icanhazip.com; }
pubip6() { curl -6s https://icanhazip.com; }
whatismyip() { pubip; }
# shellcheck disable=SC2120
r() {
history -a # save history
+ trap ERR # this avoids a segfault
exit ${1:0}
# i had this redir, not sure why
# exit "$@" 2>/dev/null
# with root owned files.
#
if [[ $EUID != 0 || $1 == -* ]]; then
+ # shellcheck disable=SC2034
SUDOD="$PWD" sudo -i "$@"
else
"$@"
source /a/bin/distro-functions/src/identify-distros
source /a/bin/distro-functions/src/package-manager-abstractions
source /a/bin/log-quiet/logq-function
-source /a/bin/small-misc-bash/psg-function
# for x in /a/bin/bash_unpublished/source-!(.#*); do echo source $x; done
source /a/bin/bash_unpublished/source-semi-priv
source /a/bin/bash_unpublished/source-state
# do all tee.
# pipe to this, or just type like a shell
+# todo: test this
dat() {
- tee >(ssh frodo.b8.nz bash -l) >(ssh x2 bash -l) >(ssh tp.b8.nz bash -l) >(ssh kw bash -l) >(ssh tp.b8.nz bash -l)
+ tee >(ssh frodo.b8.nz) >(ssh x2) >(ssh tp.b8.nz) >(ssh kw) >(ssh tp.b8.nz)
}
da() { # do all
local host
# By default .bashrc is sourced for ALL ssh commands. This is wonky.
# Normally, this file is not sourced when a script is run, but we can
-# override that by having #!/bin/bash -l. I want the same thing for ssh
+# override that by sourcing ~/.bashrc. I want the same thing for ssh
# commands. when a local script runs an ssh command, bashrc should not be
# sourced, unless we use a modified command.
#
type=${tmp2: -1}
if [[ $type == b ]]; then
info_sec=${tmp::10}
- if (( $(stat -c%Y /b/ds/brc) > info_sec || $(stat -c%Y /b/ds/.bashrc) > info_sec )); then
- dorsync=true
- rm -f $sshinfo
- fi
+ for f in /b/ds/sl/.iank/*; do
+ if (( $(stat -L -c%Y $f) > info_sec )); then
+ dorsync=true
+ rm -f $sshinfo
+ break
+ fi
+ done
fi
else
dorsync=true
if [[ -t 0 ]]; then
BRC=t command ssh "${args[@]}" "$remote" ${@@Q}
else
- command ssh "${args[@]}" "$remote" BRC=t bash -l
+ command ssh "${args[@]}" "$remote" BRC=t bash
fi
fi
}
#!/bin/bash
source /a/bin/errhandle/err
-_errcatch_cleanup() {
+errcatch-cleanup() {
echo 1 >~/.local/conflink
}
-#!/bin/bash -l
-set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
-
+#!/bin/bash
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
-#!/bin/bash -l
+#!/bin/bash
# Copyright (C) 2016 Ian Kelling
# Licensed under the Apache License, Version 2.0 (the "License");
# limitations under the License.
# first 2 alternatives showed under ubuntu 14.04, second 2 under arch at 11/2015
-
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
if [[ $1 ]]; then
right_monitor_rotation=left
else
-#!/bin/bash -l
+#!/bin/bash
# this is from distro-end
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
pi kodi
-#!/bin/bash -l
+#!/bin/bash
# Copyright (C) 2016 Ian Kelling
# Licensed under the Apache License, Version 2.0 (the "License");
# Automated phabricator setup. Not currently using it,
# but it worked last time I tried it.
-set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
set -x
-#!/bin/bash -l
+#!/bin/bash
# Copyright (C) 2016 Ian Kelling
#
# Licensed under the Apache License, Version 2.0 (the "License");
### make ssh interactive shell run better. for when running line interactively line by line
-sudo bash -c 'source /a/c/.bashrc && source /a/exe/ssh-emacs-setup'
-
+sudo bash -c '/a/exe/ssh-emacs-setup'
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
##### setup error handling
interactive=true # set this to false to force set -x
[[ $- == *i* ]] || interactive=false
fi
source /a/bin/errhandle/err
-_errcatch_cleanup() {
+errcatch-cleanup() {
echo 1 >~/.local/distro-begin
}
-#!/bin/bash -l
+#!/bin/bash
# Copyright (C) 2019 Ian Kelling
# SPDX-License-Identifier: AGPL-3.0-or-later
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
### setup
source /a/bin/errhandle/err
exit 1
fi
-_errcatch_cleanup() {
+errcatch-cleanup() {
echo 1 >~/.local/distro-end
}
-#!/bin/bash -l
-
-source /a/bin/errhandle/err
+#!/bin/bash
+# Copyright (C) 2019 Ian Kelling
+# SPDX-License-Identifier: AGPL-3.0-or-later
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
usage() {
-#!/bin/bash -l
+#!/bin/bash
# Copyright (C) 2016 Ian Kelling
# Licensed under the Apache License, Version 2.0 (the "License");
# See the License for the specific language governing permissions and
# limitations under the License.
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
+
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
-#!/bin/bash -l
-set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+#!/bin/bash
+source ~/.bashrc
fqdn=$(hostname -f)
if ! echo | /a/exe/cedit fsf /etc/dnsmasq-servers.conf; then
if systemctl is-active dnsmasq >/dev/null; then
nscd -i hosts
- systemctl reload dnsmasq
+ systemctl restart dnsmasq
fi
fi
-#!/bin/bash -l
+#!/bin/bash
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
set -x
# Copyright (C) 2016 Ian Kelling
-#!/bin/bash -l
+#!/bin/bash
# Copyright (C) 2016 Ian Kelling
# Licensed under the Apache License, Version 2.0 (the "License");
# See the License for the specific language governing permissions and
# limitations under the License.
+source ~/.bashrc
+
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
fi
fi
e() { echo "$0: $*"; "$@"; }
- _errcatch_cleanup=stop
+ errcatch-cleanup() { stop; }
modify
# we leave it as is even when stopping, because we would like it to be default, but the only way
# to change the default is for every device, and I want to avoid that, even though I wouldn't mind, others users of this script might.
server=/mail.iankelling.org/127.0.1.1
EOF
if systemctl is-active dnsmasq >/dev/null; then
- m systemctl reload dnsmasq
+ m systemctl restart dnsmasq
m nscd -i hosts
fi
echo | /a/exe/cedit mail /etc/dnsmasq-servers.conf || [[ $? == 1 ]]
if systemctl is-active dnsmasq >/dev/null; then
m nscd -i hosts
- m systemctl reload dnsmasq
+ m systemctl restart dnsmasq # reload does not ensure new config is used
fi
m systemctl disable mailclean.timer &>/dev/null ||:
-#!/bin/bash -l
-set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+#!/bin/bash
+# Copyright (C) 2019 Ian Kelling
+# SPDX-License-Identifier: AGPL-3.0-or-later
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
# cd /k/music
# find -type f -name '*.flac' | while read -r f; do
# mkdir -p "../flacs/$(dirname "$f")"
--- /dev/null
+/a/bin/errhandle/err
\ No newline at end of file
-#!/bin/bash -l
+#!/bin/bash
# Copyright (C) 2016 Ian Kelling
# Licensed under the Apache License, Version 2.0 (the "License");
sudo "$0"
exit
fi
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
+
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
restore_new_btrbk=false
restore_old_btrbk=false
-cleanup() {
+errcatch-cleanup() {
if $restore_new_btrbk; then
e WARNING: due to failure, btrbk.timer may need manual restoration:
e $new_shell sudo systemctl start btrbk.timer
if $new_shell systemctl is-active btrbk.timer; then
m $new_shell sudo systemctl stop btrbk.timer
- _errcatch_cleanup=cleanup
restore_new_btrbk=true
fi
if $old_shell systemctl is-active btrbk.timer; then
m $old_shell sudo systemctl stop btrbk.timer
- _errcatch_cleanup=cleanup
restore_old_btrbk=true
fi
# ipv6 i think.
+if ! m btrbk-run -v $bbk_args $mp_args; then
+ ret=$?
+ err "failed initial btrbk"
+ exit $ret
+fi
+
m $old_shell /a/exe/primary-setup $new_hostname
-if ! m btrbk-run -v $bbk_args $mp_args; then
+if ! m btrbk-run -v $bbk_args -m /o; then
ret=$?
bang="$(printf "$(tput setaf 5)█$(tput sgr0)%.0s" 1 2 3 4 5 6 7)"
- e $bang failed btrbk. restoring old host as primary
+ e $bang failed btrbk of /o. restoring old host as primary
m $old_shell /a/exe/primary-setup localhost
exit $ret
fi
rm -f /etc/dnsmasq.d/untrusted-network.conf
nscd -i hosts
- systemctl reload dnsmasq
+ systemctl restart dnsmasq
fi
EOF
nscd -i hosts
- systemctl reload dnsmasq
+ systemctl restart dnsmasq
fi