summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e03e998)
raw | patch | inline | side by side (parent: e03e998)
author | Ian Kelling <ian@iankelling.org> | |
Wed, 23 Oct 2019 02:42:07 +0000 (22:42 -0400) | ||
committer | Ian Kelling <ian@iankelling.org> | |
Wed, 23 Oct 2019 02:42:07 +0000 (22:42 -0400) |
16 files changed:
.bashrc | patch | blob | history | |
.iank/.bashrc | [deleted symlink] | patch | blob | history |
.iank/.inputrc | [deleted symlink] | patch | blob | history |
.iank/brc | [deleted symlink] | patch | blob | history |
Makefile | patch | blob | history | |
brc | patch | blob | history | |
brc2 | patch | blob | history | |
conflink | patch | blob | history | |
distro-end | patch | blob | history | |
rootsshsync | patch | blob | history | |
sl/.iank/.bashrc | [new symlink] | patch | blob |
sl/.iank/.inputrc | [new symlink] | patch | blob |
sl/.iank/brc | [new symlink] | patch | blob |
sl/.iank/ll-function | [moved from .iank/ll-function with 100% similarity] | patch | blob | history |
ssh-emacs-setup | patch | blob | history | |
system-status | patch | blob | history |
index c27af43a08e607c9c6f863c551c552608add152d..ac3ec039e4d35ea9e63723692b173836776a3978 100644 (file)
--- a/.bashrc
+++ b/.bashrc
#exec 2>>/a/tmp/bashlog
-# By default this file 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 something similar for ssh
-# commands. when a local script runs an ssh command, this file should not be
-# sourced by default, but we should be able to override that.
-#
-# So here we test for conditions of a script under ssh and return if so.
-# And we don't keep the rest of the code in this file, because even
-# though we return, we already parsed the whole code, and as I develop
-# the code, the parsing can have errors, which can screw up cronjobs
-# etc.
-#
-# To test for an overriding condition, we have a few options. one is to
-# use an environment variable. env variables sent across ssh are
-# strictly limited. ssh -t which sets $SSH_TTY, but within a script that
-# won't work because tty allocation will fail. However, I do use -t for
-# strange hosts, so we consider it an indicator. We could override an
-# obscure unused LC_var, like telephone, but I don't want to run into
-# some edge case where that messes things up. we could transfer a file
-# which we could test for, but I can't think of a way to make that
-# inherently limited to a single ssh command. I choose to set SendEnv
-# and AcceptEnv ssh config vars to allow the environment variable
-# BASH_LOGIN_SHELL to propagate across ssh. This also requires that we
-# wrap ssh in interactive shells, because, once we export the var, it
-# will go into scripts, and we want it to be nondefault there.
-#
-# -c is set whenever a command is passed to ssh
-# -i is set whenever a command is not passed
+# see comments in brc2 sl() function for background.
if [[ $SSH_CONNECTION ]] \
- && [[ $- == *c* ]] \
- && [[ $- != *i* ]] \
- && { [[ ! $SSH_TTY ]] || [[ $BASH_LOGIN_SHELL == false ]] ; } ; then
+ && [[ $BRC != t ]]; then
return 0
else
diff --git a/.iank/.bashrc b/.iank/.bashrc
--- a/.iank/.bashrc
+++ /dev/null
@@ -1 +0,0 @@
-../.bashrc
\ No newline at end of file
diff --git a/.iank/.inputrc b/.iank/.inputrc
--- a/.iank/.inputrc
+++ /dev/null
@@ -1 +0,0 @@
-../.inputrc
\ No newline at end of file
diff --git a/.iank/brc b/.iank/brc
--- a/.iank/brc
+++ /dev/null
@@ -1 +0,0 @@
-../brc
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 37aeef9fbd87a65f0338795bdf492da792cad631..3c19e63bfad5093117a5dff68de533520b14536a 100644 (file)
--- a/Makefile
+++ b/Makefile
all: ~/.local/distro-begin ~/.local/distro-end
-~/.local/distro-begin: distro-begin mail-setup /a/bin/buildscripts/emacs
+~/.local/distro-begin: distro-begin mail-setup /a/bin/buildscripts/emacs ssh-emacs-setup
distro-begin
~/.local/distro-end: distro-end distro-pkgs pkgs primary-setup /a/bin/buildscripts/tor-browser /a/bin/buildscripts/go /a/bin/buildscripts/rust /a/bin/buildscripts/misc
index 33e664616c36487ad7f0b426e6d3c25e303eea3f..9e368d471a21a93ec3d4786e2513c0f442f5be5f 100644 (file)
--- a/brc
+++ b/brc
e() { echo "$@"; }
-# echo var. print var including escapes, etc
+# echo args
+ea() {
+ if (( ! $# )); then
+ echo no args
+ fi
+ for arg; do
+ printf "%qEOL\n" "${arg}"
+ printf "%s" "${arg}" |& hexdump -C
+ done
+}
+# echo vars. print var including escapes, etc
ev() {
- printf "%qEOL\n" "${!1}"
- printf "%s" "${!1}" |& hexdump -C
+ if (( ! $# )); then
+ echo no args
+ fi
+ for arg; do
+ printf "%qEOL\n" "${!arg}"
+ printf "%s" "${!arg}" |& hexdump -C
+ done
}
index fb14eaa76a854fda26146cf4f356126078620606..220f1241890f111bbf114f9fc5e1685342f2a768 100644 (file)
--- a/brc2
+++ b/brc2
fi
}
+acat() {
+ shopt -s nullglob
+ hrcat /m/md/alerts/new/* /m/md/alerts/cur/*
+ shopt -u nullglob
+}
+aclear() {
+ shopt -s nullglob
+ files=(/m/md/alerts/new/* /m/md/alerts/cur/*)
+ if (( ${#files[@]} )); then
+ rm -f ${files[@]}
+ fi
+ shopt -u nullglob
+ system-status _
+}
+
ap() {
# pushd in case current directory has an ansible.cfg file
pushd /a/xans >/dev/null
/a/opt/android-studio/bin/studio.sh "$@" &r;
}
+bindpush() {
+ lipush || return 1
+ for h in li l2; do
+ sl $h <<'EOF' || return 1
+set -e
+conflink
+f=/var/lib/bind/db.b8.nz
+ser stop bind9
+s rm -fv $f.jnl
+s install -m 644 -o bind -g bind /p/c/machine_specific/linode/bind-initial/db.b8.nz $f
+ser restart bind9
+EOF
+ done
+}
bbk() { # btrbk wrapper
c /
local p a
p=(/a/bin /a/exe /a/h /a/c /p/c/machine_specific/linode{,.hosts} /a/opt/{emacs,emacs-debianstable,mu})
a="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
- rsync $@ $a ${p[@]} root@l2.b8.nz:/
- rsync $@ $a ${p[@]} /p/c/machine_specific/li root@iankelling.org:/
- rsync $@ -ahviSAXPH root@iankelling.org:/a/h/proposed-comments/ /a/h/proposed-comments
+ ret=0
+ m rsync $@ $a ${p[@]} /p/c/machine_specific/l2 root@l2.b8.nz:/ || ret=$?
+ m rsync $@ $a ${p[@]} /p/c/machine_specific/li root@li.b8.nz:/ || ret=$?
+ m rsync $@ -ahviSAXPH root@iankelling.org:/a/h/proposed-comments/ /a/h/proposed-comments || ret=$?
+ return $ret
}
lipushnoe() { # noe = noemacs. for running faster.
rsync $@ --delete-excluded -ahviSAXPH --specials --devices --delete --relative \
--exclude-from=/p/c/li-rsync-excludes /a/bin /a/exe /a/h /a/c /p/c/machine_specific/li root@li:/
}
-
#### begin bitcoin related things
btc() {
local f=/etc/bitcoin/bitcoin.conf
sudo sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc/apt/sources.list
sudo apt-get update
}
+dig() {
+ command dig +nostats +nocmd "$@"
+}
+# Output with sections sorted, and removal of query id, so 2 dig outputs can be diffed.
+digsort() {
+ local sec
+ sec=
+ dig +nordflag "$@" | sed -r 's/^(;; ->>HEADER<<-.*), id: .*/\1/' | while read -r l; do
+ if [[ $l == [^\;]* ]]; then
+ sec+="$l"$'\n'
+ else
+ if [[ $sec ]]; then
+ printf "%s" "$sec" | sort
+ sec=
+ fi
+ printf "%s\n" "$l"
+ fi
+ done
+}
+# note: only the soa master nameserver will respond with
+# ra "recursive answer" flag. That difference is meaningless afaik.
+# Same thing happens with gnu nameservers.
+digme() {
+ digsort "$@" @ns1.iankelling.org | tee /tmp/digme
+ diff -u /tmp/digme <(digsort "$@" @ns2.iankelling.org)
+}
+
dup() {
local ran_d
}
# ssh, copy my universal config over if needed.
+
+# 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
+# commands. when a local script runs an ssh command, bashrc should not be
+# sourced, unless we use a modified command.
+#
+# So, in my bashrc, test for conditions of noninteractive ssh and return
+# if so. And we don't keep the rest of the code in .bashrc, because
+# even though we return, we parse the whole file which can cause errors
+# as we develop it.
+#
+# To test for an overriding condition: bash builtin vars and env show no
+# difference in ssh vs local, except shell level which is not
+# reliable. one option is to use an environment variable. env variables
+# sent across ssh are strictly limited. We could override an obscure
+# unused LC_var, like telephone, but I don't want to run into some edge
+# case where that messes things up. I choose to set SendEnv and
+# AcceptEnv ssh config vars to allow the environment variable BRC to
+# propagate across ssh, and for hosts I don't control, I start an inner
+# shell with it set, which doubles up as a way to have a nondefault
+# bashrc.
sl() {
# inspired from https://github.com/Russell91/sshrc
- local args info_date info_t type now tmp old sshinfo
+ local args info_date info_t type now tmp tmp2 old sshinfo cmd haveinfo dorsync info_sec
declare -a args tmpa
now=$(date +%s)
esac
done
remote="$1"; shift
- old=false
+ if [[ ! $remote ]]; then
+ echo $0: error hostname required >&2
+ return 1
+ fi
+ dorsync=false
+ haveinfo=false
tmpa=(/p/sshinfo/???????????"$remote")
sshinfo=${tmpa[0]}
if [[ -e $sshinfo ]]; then
+ haveinfo=true
+ fi
+ if $haveinfo; then
tmp=${sshinfo[0]##*/}
- info_date=${tmp::11}
- type=${info_date: -1}
- info_date=${info_date::10}
- info_sec=$(date -d @$info_date +%s)
- # debug
- #e $(( $(stat -c%Y /b/ds/brc) - $(date -d @$info_date +%s) ))
- if (( $(stat -c%Y /b/ds/brc) > info_sec || $(stat -c%Y /b/ds/.bashrc) > info_sec )); then
- old=true
+ tmp2=${tmp::11}
+ 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
fi
else
+ dorsync=true
# use this weird yes thing to ensure we know ssh succeeded
- tmp=$(command ssh "${args[@]}" "$remote" "if test -e /p/sshinfo; then echo yes; fi") || return
+ tmp=$(command ssh "${args[@]}" "$remote" "if test -e /a/bin/ds/.bashrc -a -L .bashrc; then echo yes; fi") || return
if [[ $tmp == yes ]]; then
type=a
else
type=b
- old=true
fi
fi
+ if $dorsync || ! $haveinfo; then
+ sshinfo=/p/sshinfo/$now$type"$remote"
+ touch $sshinfo
+ chmod 666 $sshinfo
+ fi
if [[ $type == b ]]; then
- if $old; then
- RSYNC_RSH="ssh ${args[*]}" rsync -rptL /b/ds/.iank "$remote":
- rm -f $sshinfo
- sshinfo=/p/sshinfo/$now$type"$remote"
- touch $sshinfo
- chmod 666 $sshinfo
+ if $dorsync; then
+ RSYNC_RSH="ssh ${args[*]}" rsync -rptL /b/ds/sl/.iank "$remote":
fi
if (( ${#@} )); then
# Theres a couple ways to do this. im not sure whats best,
# but relying on bash 4.4+ escape quoting seems most reliable.
-
- command ssh -t "${args[@]}" "$remote" "INPUTRC=.iank/.inputrc bash --rcfile .iank/.bashrc -c ${@@Q}"
- # this way is bad
- # command ssh -t "${args[@]}" "$remote" "printf \"%s; exit\" \"$*\" >.iank/brc2
- #INPUTRC=.iank/.inputrc bash --rcfile .iank/.bashrc"
-
+ command ssh "${args[@]}" "$remote" \
+ BRC=t bash -c '"\"\$@\""' bash ${@@Q}
else
- command ssh -t "${args[@]}" "$remote" "INPUTRC=.iank/.inputrc bash --rcfile .iank/.bashrc"
+ # -t gives us an interactive shell for normal ssh. -l makes us use the rcfile when piping commands.
+ command ssh -t "${args[@]}" "$remote" BRC=t INPUTRC=.iank/.inputrc bash --rcfile .iank/.bashrc -l
fi
else
- BASH_LOGIN_SHELL=true command ssh "$remote" "$@"
+ BRC=t command ssh "$remote" "$@"
fi
}
sss() { # ssh solo
}
# plain limited ssh
ssh() {
- BASH_LOGIN_SHELL=true command ssh "$@"
+ BRC=t command ssh "$@"
}
diff --git a/conflink b/conflink
index d72f98c29e775a1aa7b6bbf9c0a7689687864c3c..0ae24c332cce236812b3d2521bd332edd8f96934 100755 (executable)
--- a/conflink
+++ b/conflink
lnf() { /a/exe/lnf "$@"; }
now=$(date +%s)
-f=~/.local/conflink
-fast=false
-if [[ -e $f ]] && (( $(stat -c %Y $f) > $now - 60*60*24 )); then
- fast=true
-fi
+
+# error prone
+#f=~/.local/conflink
+# fast=false
+# if [[ -e $f ]] && (( $(stat -c %Y $f) > $now - 60*60*24 )); then
+# fast=true
+# fi
if [[ $1 == -f ]]; then # f for fast
fast=true
shift
diff --git a/distro-end b/distro-end
index 7f2f12ca453c095cf53b9027d60dcdafe76f1a24..317852291a0d21fb83764c2d7225f0c5a0f5dd66 100755 (executable)
--- a/distro-end
+++ b/distro-end
WantedBy=multi-user.target
EOF
ser daemon-reload
- m sgo znc
+ # avoid restarting if possible, reconnecting to irc is annoying.
+ if [[ $(ser is-active znc) != active ]]; then
+ m sgo znc
+ fi
###### stop znc setup #####
end
diff --git a/rootsshsync b/rootsshsync
index 1a39d463494954d3f9f890a88a058345a86905d6..668f8a3d7ed931ea2a65130c050b9c7e9326ca66 100755 (executable)
--- a/rootsshsync
+++ b/rootsshsync
fi
user_ssh_dir=$(eval echo ~$user)/.ssh
-if [[ ! -s $user_ssh_dir/config ]]; then
- echo missing $user_ssh_dir/config. bad sign. bailing >&2
+if [[ ! -s $user_ssh_dir/authorized_keys ]]; then
+ echo missing $user_ssh_dir/authorized_keys. bad sign. bailing >&2
exit 1
fi
diff --git a/sl/.iank/.bashrc b/sl/.iank/.bashrc
--- /dev/null
+++ b/sl/.iank/.bashrc
@@ -0,0 +1 @@
+../../.bashrc
\ No newline at end of file
diff --git a/sl/.iank/.inputrc b/sl/.iank/.inputrc
--- /dev/null
+++ b/sl/.iank/.inputrc
@@ -0,0 +1 @@
+../../.inputrc
\ No newline at end of file
diff --git a/sl/.iank/brc b/sl/.iank/brc
--- /dev/null
+++ b/sl/.iank/brc
@@ -0,0 +1 @@
+../../brc
\ No newline at end of file
diff --git a/.iank/ll-function b/sl/.iank/ll-function
diff --git a/ssh-emacs-setup b/ssh-emacs-setup
index ee1dd087ba8e9a443ce5135210996ff9c7db0371..80976f056df0eb22e1f135f42e4b6c4b180d6de6 100755 (executable)
--- a/ssh-emacs-setup
+++ b/ssh-emacs-setup
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
cd $(dirname $0)
-teeu /etc/ssh/ssh_config 'SendEnv INSIDE_EMACS BASH_LOGIN_SHELL COLUMNS'
-teeu /etc/ssh/sshd_config 'AcceptEnv INSIDE_EMACS BASH_LOGIN_SHELL COLUMNS'
+teeu /etc/ssh/ssh_config 'SendEnv INSIDE_EMACS BRC COLUMNS'
+teeu /etc/ssh/sshd_config 'AcceptEnv INSIDE_EMACS BRC COLUMNS'
# get rid of useless motd stuff
sed -i --follow-symlinks 's/^\s*PrintLastLog .*/PrintLastLog no/' /etc/ssh/sshd_config
rm -f /etc/update-motd.d/10-help-text /etc/update-motd.d/00-header
diff --git a/system-status b/system-status
index ddb5b738c28db81d1f4320ad10200de8b4f3f773..b3c22e4ea8126f1a24330b039aceef3803ed1d03 100755 (executable)
--- a/system-status
+++ b/system-status
chars+=("q $qlen")
fi
+ begin=false
cd /b/ds
if ! make -q ~/.local/distro-begin || [[ $(<~/.local/distro-begin) != 0 ]]; then
- chars+=("DISTRO-BEGIN!")
+ begin=true
fi
+ end=false
if ! make -q ~/.local/distro-end || [[ $(<~/.local/distro-end) != 0 ]]; then
+ end=true
+ fi
+
+ if $begin && $end; then
+ chars+=("DISTRO!")
+ elif $begin; then
+ chars+=("DISTRO-BEGIN!")
+ elif $end; then
chars+=("DISTRO-END!")
fi
for d in /a/bin/distro-setup /p/c; do
cd $d
+ if [[ ! -e .git ]]; then
+ # some hosts i dont push all of /p/c
+ continue
+ fi
untracked=$(git ls-files -o --exclude-standard)
if [[ $untracked && $(find $untracked -mmin $fminplus -type f -print -quit) ]]; then
v conflink: untracked in $d
fi
done
if (( maxtime < now - 60*60 )); then
- chars+=("OLD-SNAPSHOT!")
+ chars+=("OLD-SNAP!")
snapshotmsg="/o snapshot older than 1 hour"
fi
lo -1 old-snapshot $snapshotmsg