2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4 # this gets sourced. shebang is just for file mode detection
11 source /a
/bin
/distro-setup
/path-add-function
13 # add this with absolute paths as needed for better security
14 #path-add --end /path/to/node_modules/.bin
16 # pip3 --user things go here:
17 path-add
--end ~
/.local
/bin
18 path-add
--ifexists --end /a
/work
/libremanage
19 path-add
--ifexists --end /a
/opt
/adt-bundle
*/tools
/a
/opt
/adt-bundle
*/platform-tools
20 path-add
--ifexists --end /a
/opt
/scancode-toolkit-3.0
.2
27 # generated instead of dynamic for the benefit of shellcheck
28 #for x in /a/bin/distro-functions/src/* /a/bin/!(githtml)/*-function?(s); do echo source $x ; done
29 source /a
/bin
/distro-functions
/src
/identify-distros
30 source /a
/bin
/distro-functions
/src
/package-manager-abstractions
31 source /a
/bin
/log-quiet
/logq-function
32 # for x in /a/bin/bash_unpublished/source-!(.#*); do echo source $x; done
33 source /a
/bin
/bash_unpublished
/source-semi-priv
34 source /a
/bin
/bash_unpublished
/source-state
36 source /a
/bin
/log-quiet
/logq-function
45 complete
-F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr
49 if which anki
&>/dev
/null
; then
52 schroot
-c anki
-- anki
58 hrcat
/m
/md
/alerts
/new
/* /m
/md
/alerts
/cur
/*
63 files
=(/m
/md
/alerts
/new
/* /m
/md
/alerts
/cur
/*)
64 if (( ${#files[@]} )); then
72 # pushd in case current directory has an ansible.cfg file
73 pushd /a
/xans
>/dev
/null
74 ansible-playbook
-v -l ${1:- $(hostname -f)} site.yml
78 pushd /a
/work
/ansible-configs
>/dev
/null
79 time ansible-playbook
-v -i inventory adhoc.yml
"$@"
83 pushd /a
/bin
/distro-setup
/a
>/dev
/null
84 ansible-playbook site.yml
89 # googling android emulator libGL error: failed to load driver: r600
90 # lead to http://stackoverflow.com/a/36625175/14456
91 export ANDROID_EMULATOR_USE_SYSTEM_LIBS
=1
92 /a
/opt
/android-studio
/bin
/studio.sh
"$@" &r
;
98 sl
$h <<'EOF' || return 1
101 f=/var/lib/bind/db.b8.nz
104 sudo install -m 644 -o bind -g bind /p/c/machine_specific/linode/bind-initial/db.b8.nz $f
110 bbk
() { # btrbk wrapper
115 systemctl is-active btrbk.timer || active
=false
119 if [[ $
(systemctl is-active btrbk.service ||
:) != inactive
]]; then
120 echo "cron btrbk is already running"
121 if $active; then ser start btrbk.timer
; fi
126 jrun
-p btrbk btrbk-run
"$@"
129 echo bbk
: WARNING
: btrbk.timer not restarted due to failure
131 ser start btrbk.timer
137 bfg
() { java
-jar /a
/opt
/bfg-1.12
.14.jar
"$@"; }
140 xclock
-digital -update 1 -face 'arial black-80:bold'
145 # just passing on -INT doesnt work.
148 if [[ ! -e /proc
/$pid ]]; then
149 if [[ $old_int_trap ]]; then
158 jrun
() { # journal run. run args, log to journal, tail and grep the journal.
159 # Note, an alternative without systemd would be something like ts.
160 # Note: I tried doing cmd | pee "sudo systemd-cat" cat, but that
161 # had some problems like ctrl-c didnt work or something.
162 local pid pattern sedscript cmd_name ended
171 sedscript
="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[[0-9]+]: ([^ ]*\/)?$cmd_name: exiting with status [0-9]+\$/q"
172 # We use >() so that $! is the pid of journalctl, otherwise its the sed pid and then
173 # if we kill that, it takes journalctl about 10 seconds to catch up, and we get
174 # an annoying message about job finishing then.
175 journalctl
-qn2 -f &> >(sed -nr "$sedscript") &
176 # We kill this in prompt-command for the case that we ctrl-c the
177 # systemd-cat. i dont know any way to trap ctrl-c and still run the
178 # normal action for it. There might be a way, unsure.
180 systemd-cat
-t "$cmd_name" "$@" || ret
=$?
182 echo "jrun: ERROR: $* returned $ret"
184 # This justs lets the journal output its last line
185 # before the prompt comes up.
187 kill $jr_pid &>/dev
/null ||
:
196 jrun
-p btrbk switch-mail-host
"$@"
201 # note, i had --delete-excluded, but that deletes all files in --exclude-from on
202 # the remote site, which doesn't make sense, so not sure why i had it.
204 p
=(/a
/bin
/a
/exe
/a
/h
/a
/c
/p
/c
/machine_specific
/linode
{,.hosts
} /a
/opt
/{emacs-debianstable
,mu
})
205 a
="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
207 m rsync
"$@" $a ${p[@]} /p
/c
/machine_specific
/l2 root@l2.b8.nz
:/ || ret
=$?
208 m rsync
"$@" $a ${p[@]} /p
/c
/machine_specific
/li root@li.b8.nz
:/ || ret
=$?
209 m rsync
"$@" -ahviSAXPH root@iankelling.org
:/a
/h
/proposed-comments
/ /a
/h
/proposed-comments || ret
=$?
212 lipushnoe
() { # noe = noemacs. for running faster.
213 rsync
"$@" --delete-excluded -ahviSAXPH --specials --devices --delete --relative \
214 --exclude-from=/p
/c
/li-rsync-excludes
/a
/bin
/a
/exe
/a
/h
/a
/c
/p
/c
/machine_specific
/li root@li
:/
217 #### begin bitcoin related things
219 local f
=/etc
/bitcoin
/bitcoin.conf
220 # importprivkey will timeout if using the default of 15 mins.
221 # upped it to 1 hour.
222 bitcoin-cli
-rpcclienttimeout=60000 -$
(s
grep rpcuser
= $f) -$
(s
grep rpcpassword
= $f) "$@"
224 btcusd
() { # $1 btc in usd
226 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
227 printf "$%s\n" "$price"
229 printf "$%.2f\n" "$(echo "scale
=4; $price * $1"| bc -l)"
232 usdbtc
() { # $1 usd in btc
234 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
235 printf "$%s\n" "$price"
237 # 100 mil satoshi / btc. 8 digits after the 1.
238 printf "%.8f btc\n" "$(echo "scale
=10; $1 / $price "| bc -l)"
241 satoshi
() { # $1 satoshi in usd
243 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
244 price
=$
(echo "scale=10; $price * 0.00000001"|
bc -l)
245 printf "$%f\n" "$price"
247 printf "$%.2f\n" "$(echo "scale
=10; $price * $1"| bc -l)"
250 #### end bitcoin related things
254 cbfstool
() { /a
/opt
/coreboot
/build
/cbfstool
"$@"; }
260 cp /a
/bin
/data
/COPYING
"$@"
262 cp /a
/bin
/data
/COPYING .
269 cp /a
/bin
/data
/LICENSE
"$@"
271 cp /a
/bin
/data
/LICENSE .
276 if type -p chromium
&>/dev
/null
; then
280 cmd
="schroot -c stretch chromium"
281 CHROMIUM_FLAGS
='--enable-remote-extensions' $cmd &r
287 # pipe to this, or just type like a shell
290 tee >(ssh frodo.b8.nz
) >(ssh x2
) >(ssh tp.b8.nz
) >(ssh kw
) >(ssh tp.b8.nz
)
294 for host in x2 kw tp.b8.nz x3.b8.nz frodo.b8.nz
; do
300 debian_pick_mirror
() {
301 # netselect-apt finds a fast mirror.
302 # but we need to replace the mirrors ourselves,
303 # because it doesnt do that. best it can do is
304 # output a basic sources file
305 # here we get the server it found, get the main server we use
306 # then substitute all instances of one for the other in the sources file
307 # and backup original to /etc/apt/sources.list-original.
308 # this is idempotent. the only way to identify debian sources is to
309 # note the original server, so we put it in a comment so we can
312 file=$
(mktemp
-d)/f
# safe way to get file name without creating one
313 sudo netselect-apt
-o "$file" ||
return 1
314 url
=$
(grep ^
\\w
$file |
head -n1 |
awk '{print $2}')
315 sudo
cp -f /etc
/apt
/sources.list
/etc
/apt
/sources.list-original
316 sudo
sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc
/apt
/sources.list
320 digdiff @ns
{1,2}.iankelling.org
"$@"
329 *DISTRO-BEGIN
!*|
*DISTRO
!*)
331 /b
/ds
/distro-begin ||
return $?
335 *DISTRO-END
!*|
*DISTRO
!*)
337 /b
/ds
/distro-end ||
return $?
350 envload
() { # load environment from a previous: export > file
351 local file=${1:-$HOME/.${USER}_env}
352 eval "$(export | sed 's/^declare -x/export -n/')"
353 while IFS
= read -r line
; do
354 # declare -x makes variables local to a function
355 eval ${line/#declare -x/export}
359 failfunc
() { asdf a b c
; }
360 failfunc2
() { failfunc d e f
; }
362 # one that comes with distros is too old for newer devices
364 /a
/opt
/android-platform-tools
/fastboot
"$@";
367 kdecd
() { /usr
/lib
/x86_64-linux-gnu
/libexec
/kdeconnectd
; }
369 # List of apps to install/update
370 # Create from existing manually installed apps by doing
372 # fdroidcl search -i, then manually removing
373 # automatically installed/preinstalled apps
376 # # my attempt at recovering from boot loop:
377 # # in that case, boot to recovery (volume up, home button, power, let go of power after samsun logo)
379 # mount /dev/block/mmcblk0p12 /data
381 # find -iname '*appname*'
383 # usually good enough to just rm -rf /data/app/APPNAME
386 # # causes replicant to crash
387 # org.quantumbadger.redreader
388 # org.kde.kdeconnect_tp
390 # not broke, but wont work without gps
391 #com.zoffcc.applications.zanavi
392 # not broke, but not using atm
393 #com.nutomic.syncthingandroid
394 # # doesn\'t work on replicant
395 #net.sourceforge.opencamera
398 de.marmaro.krt.ffupdater
399 me.ccrama.redditslide
400 org.fedorahosted.freeotp
402 com.alaskalinuxuser.justnotes
403 com.artifex.mupdf.viewer.app
404 com.danielkim.soundrecorder
406 com.ghostsq.commander
408 com.jmstudios.redmoon
410 org.kde.kdeconnect_tp
413 cz.martykan.forecastie
416 de.marmaro.krt.ffupdater
417 eu.siacs.conversations
419 im.vector.alpha
# riot
421 me.tripsit.tripmobile
423 net.minetest.minetest
428 org.smssecure.smssecure
430 sh.
ftp.rocketninelabs.meditationassistant.opensource
432 # https://forum.xda-developers.com/android/software-hacking/wip-selinux-capable-superuser-t3216394
437 local -A installed updated
439 # tried putting this in go buildscript cronjob,
440 # but it failed with undefined: os.UserCacheDir. I expect its due to
441 # an environment variable missing, but its easier just to stick it here.
442 m go get
-u mvdan.cc
/fdroidcl ||
return 1
444 if fdroidcl search
-u |
grep ^org.fdroid.fdroid
; then
445 fdroidcl
install org.fdroid.fdroid
449 for p
in $
(fdroidcl search
-i|
grep -o "^\S\+"); do
452 for p
in $
(fdroidcl search
-u|
grep -o "^\S\+"); do
455 for p
in ${fdroid_pkgs[@]}; do
456 if ! ${installed[$p]:-false}; then
457 m fdroidcl
install $p
458 # sleeps are just me being paranoid since replicant has a history of crashing when certain apps are installed
462 for p
in ${!installed[@]}; do
463 if ! ${updated[$p]:-true}; then
464 m fdroidcl
install $p
470 firefox-default-profile
() {
471 key
=Default value
=1 section
=$1
472 file=/p
/c
/subdir_files
/.mozilla
/firefox
/profiles.ini
473 sed -ri "/^ *$key/d" "$file"
474 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d};/ *\[$section\]/a $key=$value" "$file"
476 fdhome
() { #firefox default home profile
477 firefox-default-profile Profile0
481 firefox-default-profile Profile4
485 if type -P firefox
&>/dev
/null
; then
495 firefox
-P alt
"$@" >/dev
/null
2>&1
501 local dname
="${PWD##*/}"
502 local m
="/a/tmp/$dname-missing"
503 local d
="/a/tmp/$dname-diff"
504 [[ -e $d ]] && rm "$d"
505 [[ -e $m ]] && rm "$m"
508 while read -r line
; do
510 if [[ -e "$fsfile" ]]; then
511 md5diff
"$line" "$fsfile" && tee -a "/a/tmp/$dname-diff" <<< "$fsfile $line"
517 done < <(find .
-type f
)
520 (( msize
<= 100 )) && cat $m
524 # expected output, with different tmp dirs
525 # /tmp/tmp.HDPbwMqdC9/c/d ./c/d
526 # /a/tmp/tmp.qLDkYxBYPM-missing
536 echo different
> $x/c
/d
541 # test whether missing files were renamed, generally for use with fsdiff
542 # $1 = fsdiff output file, $2 = directory to compare to. pwd = fsdiff dir
543 # echos non-renamed files
547 { sums
+=( "$(md5sum < "$x")" ) ; } 2>/dev
/null
549 while read -r line
; do
550 { missing_sum
=$
(md5sum < "$line") ; } 2>/dev
/null
552 for x
in "${sums[@]}"; do
553 if [[ $missing_sum == "$x" ]]; then
558 $renamed ||
echo "$line"
564 # F = fullscren, z = random, Z = auto zoom
565 command feh
-FzZ "$@"
571 firefox
-P default
"$@" >/dev
/null
2>&1
575 git config user.email ian@iankelling.org
578 # at least in flidas, things rely on gpg being gpg1
584 local email
=ian@iankelling.org
585 if readlink ~
/.mu |
grep fsf
&>/dev
/null
; then
588 git send-email
--notes "--envelope-sender=<$email>" \
589 --suppress-cc=self
"$@"
593 # do git status on published repos.
596 cd $
(readlink
-f $x)/..
597 status
=$
(i status
-s) ||
pwd
598 if [[ $status ]]; then
601 printf "%s\n" "$status"
608 /a
/opt
/idea-IC-163.7743
.44/bin
/idea.sh
"$@" &r
613 # use * instead of -r since that does sorted order
614 ssh root@iankelling.org
"cd /var/lib/znc/moddata/log/iank/freenode/$chan && hr && for x in *; do echo \$x; cat \$x; hr; done" |
less +G
618 if type gio
&> /dev
/null
; then
620 elif type gvfs-open
&> /dev
/null
; then
625 # another alternative is run-mailcap
629 grep -Evi -e "^(\S+\s+){4}(sudo|sshd|cron)\[\S*:" \
630 -e "^(\S+\s+){4}systemd\[\S*: (starting|started) (btrfsmaintstop|dynamicipupdate|spamd dns bug fix cronjob|rss2email)\.*$"
633 journalctl
-n 10000 -f "$@" | jfilter
635 jr
() { journalctl
"$@" | jfilter |
less ; }
636 jrf
() { journalctl
-n 200 -f "$@" | jfilter
; }
639 kff
() { # keyboardio firmware flash
640 pushd /a
/bin
/distro-setup
/Arduino
/Model01-Firmware
641 yes $
'\n' |
make flash
649 if [[ $1 == /* ]]; then
651 if mountpoint
/mnt
/$base; then
656 if ! sudo cryptsetup luksOpen
$l $base; then
660 sudo mkdir
-p /mnt
/$base
661 sudo mount
/dev
/mapper
/$base /mnt
/$base
662 sudo chown
$USER:$USER /mnt
/$base
665 sudo umount
/mnt
/$base
666 l
=$
(sudo cryptsetup status
/dev
/mapper
/$base|
sed -rn 's/^\s*device:\s*(.*)/\1/p')
667 sudo cryptsetup luksClose
/dev
/mapper
/$base ||
return 1
678 [[ -e $src ]] ||
{ set +x
; return 1; }
679 mv -T $src $dst ||
{ set +x
; return 1; }
682 mu index
--maildir=/m
/4e
690 [[ -e $src ]] ||
{ set +x
; return 1; }
691 if [[ -L $dst ]]; then rm $dst; fi
698 markdown
"$1" >/tmp
/mdtest.html
699 firefox
/tmp
/mdtest.html
702 mo
() { xset dpms force off
; } # monitor off
705 chan
=${1:-fsf-office}
706 # use * instead of -r since that does sorted order
707 ssh root@iankelling.org
"cd /var/lib/znc/moddata/log/iank/freenode/#$chan; grep '\<iank.*' *"
711 e
"lspci -nnk|gr -iA2 net"
712 lspci
-nnk|gr
-iA2 net
714 e
"s lshw -C network"
720 ser stop NetworkManager
721 ser disable NetworkManager
722 ser stop NetworkManager-wait-online.service
723 ser disable NetworkManager-wait-online.service
725 sudo resolvconf
-d NetworkManager
731 ser start NetworkManager
737 oathtool
--totp -b "$@" | xclip
-selection clipboard
742 # from http://askubuntu.com/questions/456021/remove-vocals-from-mp3-and-get-only-instrumentals
743 pactl load-module module-ladspa-sink sink_name
=Karaoke master
=alsa_output.usb-Audioengine_Audioengine_D1-00.analog-stereo plugin
=karaoke_1409 label
=karaoke control
=-30
746 pfind
() { #find *$1* in $PATH
747 [[ $# != 1 ]] && { echo requires
1 argument
; return 1; }
749 IFS
=: pathArray
=($PATH); unset IFS
750 find "${pathArray[@]}" -iname "*$1*"
754 # trash-restore lists everything that has been trashed at or below CWD
755 # This picks out files just in CWD, not subdirectories,
756 # which also match grep $1, usually use $1 for a time string
757 # which you get from running restore-trash once first
760 # last condition is to not ask again for ones we skipped
761 while name
="$( echo | restore-trash | gr "$PWD/[^
/]\
+$
" | gr "$1" )" \
762 && [[ $name ]] && (( $
(wc -l <<<"$name") >= nth
)); do
763 name
="$(echo "$name" | head -n $nth | tail -n 1 )"
764 read -r -p "$name [Y/n] " ask
765 if [[ ! $ask ||
$ask == [Yy
] ]]; then
766 x
=$
( echo "$name" | gr
-o "^\s*[0-9]*" )
767 echo $x | restore-trash
> /dev
/null
768 elif [[ $ask == [Nn
] ]]; then
778 rld
/a
/h
/_site
/ li
:/var
/www
/iankelling.org
/html
783 # fixes the menu bar in xmonad. this won\'t be needed when xmonad
784 # packages catches up on some changes in future (this is written in
787 # geekosaur: so youll want to upgrade to xmonad 0.13 or else use a
788 # locally modified XMonad.Hooks.ManageDocks that doesnt set the
789 # work area; turns out it\'s impossible to set correctly if you are
790 # not a fully EWMH compliant desktop environment
792 # geekosaur: chrome shows one failure mode, qt/kde another, other
793 # gtk apps a third, ... I came up with a setting that works for me
794 # locally but apparently doesnt work for others, so we joined the
795 # other tiling window managers in giving up on setting it at all
797 xprop
-root -remove _NET_WORKAREA
801 # reviewboard, used at my old job
802 #rbpipe() { rbt post -o --diff-filename=- "$@"; }
803 #rbp() { rbt post -o "$@"; }
815 hr
; s ss
-lpn 'sport = 53'
816 if systemctl is-enabled dnsmasq
&>/dev
/null ||
[[ $
(systemctl is-active dnsmasq ||
:) != inactive
]]; then
817 # this will fail is dnsmasq is failed
818 hr
; m ser status dnsmasq |
cat ||
:
819 f
=/var
/run
/dnsmasq
/resolv.conf
820 hr
; echo $f:; ccat
$f
821 hr
; m grr
'^ *(servers-file|server) *=|^ *no-resolv *$' /etc
/dnsmasq.conf
/etc
/dnsmasq.d
822 f
=/etc
/dnsmasq-servers.conf
823 hr
; echo $f:; ccat
$f
825 if systemctl is-enabled systemd-resolved
&>/dev
/null ||
[[ $
(systemctl is-active systemd-resolved ||
:) != inactive
]]; then
826 hr
; m ser status systemd-resolved |
cat ||
:
827 hr
; m systemd-resolve
--status
836 #sudo systemctl restart dnsmasq
839 # only run on MAIL_HOST. simpler to keep this on one system.
840 r2eadd
() { # usage: name url
841 # initial setup of rss2email:
842 # r2e new r2e@iankelling.org
843 # that initializes files, and sets default email.
844 # symlink to the config doesnt work, so I copied it to /p/c
845 # and then use cli option to specify explicit path.
846 # Only option changed from default config is to set
849 # or else for a few feeds, the from address is set by the feed, and
850 # if I fail delivery, then I send a bounce message to that from
851 # address, which makes me be a spammer.
853 r2e add
$1 "$2" $1@r2e.iankelling.org
854 # get up to date and dont send old entries now:
857 r2e
() { command r2e
-d /p
/c
/rss2email.json
-c /p
/c
/rss2email.cfg
"$@"; }
859 rspicy
() { # usage: HOST DOMAIN
860 # connect to spice vm remote host. use vspicy for local host
862 # shellcheck disable=SC2087
864 sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
865 sed -rn "s/.*port='([0-9]+).*/\1/p"
871 echo "error: no port found. check that the domain is running."
877 # s gem install scss-lint
878 pushd /a
/opt
/thoughtbot-guides
881 scss-lint
-c /a
/opt
/thoughtbot-guides
/style
/sass
/.scss-lint.yml
"$@"
885 sk
-e 2120,245 /b
/ds
/brc
/b
/ds
/brc2
892 script -t -c "mpv --no-config --no-resume-playback --no-terminal --no-audio-display '$1'" $tmp/typescript
2>$tmp/timing
893 # todo, the current sleep seems pretty good, but it
894 # would be nice to have an empirical measurement, or
895 # some better wait to sync up.
897 # note: --loop-file=no prevents it from hanging if you have that
898 # set to inf the mpv config.
899 # --loop=no prevents it from exit code 3 due to stdin if you
900 # had it set to inf in mpv config.
902 # args go to mpv, for example --volume=80, 50%
905 trap "trap - TERM && kill 0" INT TERM ERR; set -e
906 ( sleep .2; scriptreplay <( cat <<'EOF'
910 $(cat $tmp/typescript)
913 base64 -d - <<'EOF'| mpv --loop=no --loop-file=no --no-terminal --no-audio-display "\$@" -
922 smeld
() { # ssh meld usage host1 host2 file
923 meld
<(ssh $1 cat $3) <(ssh $2 cat $3)
927 PATH
=/usr
/local
/spdhackfix
:$PATH command spd
"$@"
931 sudo systemctl
suspend
934 # ssh, copy my universal config over if needed.
936 # By default .bashrc is sourced for ALL ssh commands. This is wonky.
937 # Normally, this file is not sourced when a script is run, but we can
938 # override that by sourcing ~/.bashrc. I want the same thing for ssh
939 # commands. when a local script runs an ssh command, bashrc should not be
940 # sourced, unless we use a modified command.
942 # So, in my bashrc, test for conditions of noninteractive ssh and return
943 # if so. And we don't keep the rest of the code in .bashrc, because
944 # even though we return, we parse the whole file which can cause errors
947 # To test for an overriding condition: bash builtin vars and env show no
948 # difference in ssh vs local, except shell level which is not
949 # reliable. one option is to use an environment variable. env variables
950 # sent across ssh are strictly limited. We could override an obscure
951 # unused LC_var, like telephone, but I don't want to run into some edge
952 # case where that messes things up. I choose to set SendEnv and
953 # AcceptEnv ssh config vars to allow the environment variable BRC to
954 # propagate across ssh, and for hosts I don't control, I start an inner
955 # shell with it set, which doubles up as a way to have a nondefault
958 # inspired from https://github.com/Russell91/sshrc
961 local args info_date info_t
type now tmp tmp2 old sshinfo cmd haveinfo dorsync info_sec
965 # ssh [-1246Antivivisectionist] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
966 # [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-L address]
967 # [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option]
968 # [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] [user@]hostname
973 -[1246AaCfGgKkMNnqsTtVvXxYy
])
976 -[bcDEeFIiLlmOopQRSWw
]*)
977 # -oOption etc is valid
978 if (( ${#1} >= 3 )); then
981 args
+=("$1" "$2"); shift 2
990 if [[ ! $remote ]]; then
991 echo $0: error hostname required
>&2
996 tmpa
=(/p
/sshinfo
/???????????
"$remote")
998 if [[ -e $sshinfo ]]; then
1002 tmp
=${sshinfo[0]##*/}
1005 if [[ $type == b
]]; then
1007 for f
in /b
/ds
/sl
/.iank
/*; do
1008 if (( $
(stat
-L -c%Y
$f) > info_sec
)); then
1016 # use this weird yes thing to ensure we know ssh succeeded
1017 if ! tmp
=$
(command ssh "${args[@]}" "$remote" "if test -e /a/bin/ds/.bashrc -a -L .bashrc; then echo yes; fi"); then
1018 echo failed sl
test. doing plain
ssh -v
1019 command ssh -v "${args[@]}" "$remote"
1021 if [[ $tmp == yes ]]; then
1029 RSYNC_RSH
="ssh ${args[*]}" rsync
-rptL /b
/ds
/sl
/.iank
"$remote":
1031 if $dorsync ||
! $haveinfo; then
1032 sshinfo
=/p
/sshinfo
/$now$type"$remote"
1036 if [[ $type == b
]]; then
1037 if (( ${#@} )); then
1039 # Theres a couple ways to do this. im not sure whats best,
1040 # but relying on bash 4.4+ escape quoting seems most reliable.
1041 command ssh "${args[@]}" "$remote" \
1042 BRC
=t bash
-c '.\ .iank/.bashrc\;"\"\$@\""' bash
${@@Q}
1043 elif [[ ! -t 0 ]]; then
1044 # This case is when commands are being piped to ssh.
1045 # Normally, no bashrc gets sourced.
1046 # But, since we are doing all this, lets source it because we can.
1047 cat <(echo . .iank
/.bashrc
) - |
command ssh "${args[@]}" "$remote" BRC
=t bash
1049 command ssh -t "${args[@]}" "$remote" BRC
=t INPUTRC
=.iank
/.inputrc bash
--rcfile .iank
/.bashrc
1053 BRC
=t
command ssh "${args[@]}" "$remote" ${@@Q}
1055 command ssh "${args[@]}" "$remote" BRC
=t bash
1060 sl
-oControlMaster=no
-oControlPath=/ "$@"
1062 # kill off old shared socket then ssh
1064 m
ssh -O exit "$@" ||
[[ $?
== 255 ]]
1069 BRC
=t
command ssh "$@"
1075 declare -gi _seq
; _seq
+=1
1076 echo "test body" | m
mail -s "test mail from $HOSTNAME, $_seq" "${@:-root@localhost}"
1077 # for testing to send from an external address, you can do for example
1078 # -fian@iank.bid -aFrom:ian@iank.bid web-6fnbs@mail-tester.com
1079 # note in exim, you can retry a deferred message
1081 # MSG_ID is in /var/log/exim4/mainlog, looks like 1ccdnD-0001nh-EN
1084 # to test sieve, use below command. for fsf mail, see offlineimap-sync script
1085 # make modifications, then copy to live file, use -eW to actually modify mailbox
1087 # Another option is to use sieve-test SCRIPT MAIL_FILE. note,
1088 # sieve-test doesnt know about envelopes, Im not sure if sieve-filter does.
1090 # sieve with output filter. arg is mailbox, like INBOX.
1091 # This depends on dovecot conf, notably mail_location in /etc/dovecot/conf.d/10-mail.conf
1094 sieve-filter
"$@" 2> >(head; tail) >/tmp
/testsieve.log
&& sed -rn '/^Performed actions:/,/^[^ ]/{/^ /p}' /tmp
/testsieve.log |
sort |
uniq -c
1097 # always run this first, edit the test files, then run the following
1099 _dosieve ~
/sieve
/maintest.sieve
${1:-INBOX} delete
1102 c ~
/sieve
; cp personal
{test,}.sieve
; cp lists
{test,}.sieve
; cp personalend
{test,}.sieve
1103 _dosieve ~
/sieve
/main.sieve
-eW ${1:-INBOX} delete
1108 # testmail above calls sendmail, which is a link to exim/postfix.
1109 # its docs dont say a way of adding an argument
1110 # to sendmail to turn on debug output. We could make a wrapper, but
1111 # that is a pain. Exim debug args are documented here:
1112 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
1114 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-building_and_installing_exim.html
1115 # note, for exim daemon, you can turn on debug options by
1116 # adding -d, etc to COMMONOPTIONS in
1117 # /etc/default/exim4
1119 # to specify recipients other than those in to, cc, bcc, you can use the cli args, eg:
1120 # exim -i 'test@zroe.org, t2@zroe.org' <<'EOF'
1124 From: i@dmarctest.b8.nz
1125 To: mailman@dev.fsf.org
1127 Reply-to: rtest@iankelling.org
1129 This is a test message.
1136 # https://askubuntu.com/questions/160945/is-there-a-way-to-disable-a-laptops-internal-keyboard
1137 id
=$
(xinput
--list --id-only 'AT Translated Set 2 keyboard')
1138 if xinput list |
grep -F '∼ AT Translated Set 2 keyboard' &>/dev
/null
; then
1139 echo enabling keyboard
1140 # find the first slave keyboard number, they are all the same in my output.
1141 # if they werent, worst case we would need to save the slave number somewhere
1142 # when it got disabled.
1143 slave
=$
(xinput list |
sed -n 's/.*slave \+keyboard (\([0-9]*\)).*/\1/p' |
head -n1)
1144 xinput reattach
$id $slave
1153 (sleep $
(calc
"$* * 60") && mpv
--no-config --volume 50 /a
/bin
/data
/alarm.mp3
) > /dev
/null
2>&1 &
1156 trg
() { transmission-remote-gtk
&r
; }
1158 # example, set global upload limit to 100 kilobytes:
1160 TR_AUTH
=":$(jq -r .profiles[0].password ~/.config/transmission-remote-gtk/config.json)" transmission-remote transmission.lan
-ne "$@"
1166 dir
="$(dirname "$1")"
1167 if [[ -e $1 && ! -w $1 ||
! -w $
(dirname "$1") ]]; then
1170 # full path for using in some initial setup steps
1175 #m s nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*pia.conf") -n -m "$@"
1176 m s nsenter
-t $
(pgrep
-f "/usr/sbin/openvpn .* --config /etc/openvpn/.*client.conf") -n -m "$@"
1179 vpncmd gksudo
-u iank
"firefox -no-remote -P vpn" &r
1182 vpncmd gksudo
-u iank
"$*"
1190 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
1191 local vpn_service
=openvpn-client
1193 local vpn_service
=openvpn
1196 [[ $1 ]] ||
{ echo need arg
; return 1; }
1197 journalctl
--unit=$vpn_service@
$1 -f -n0 &
1198 sudo systemctl start
$vpn_service@
$1
1199 # sometimes the ask-password agent does not work and needs a delay.
1201 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779240
1202 # noticed around 8-2017 after update from around stretch release
1203 # on debian testing, even though the bug is much older.
1204 sudo systemd-tty-ask-password-agent
1208 [[ $1 ]] ||
{ echo need arg
; return 1; }
1209 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
1210 local vpn_service
=openvpn-client
1212 local vpn_service
=openvpn
1214 sudo systemctl stop
$vpn_service@
$1
1216 vpnoffc
() { # vpn off client
1217 ser stop openvpn-nn@client
1220 ser start openvpn-nn@client
1224 vspicy
() { # usage: VIRSH_DOMAIN
1225 # connect to vms made with virt-install
1226 spicy
-p $
(sudo virsh dumpxml
"$1"|
grep "<graphics.*type='spice'"|\
1227 sed -r "s/.*port='([0-9]+).*/\1/")
1231 cat-new-files
/m
/4e
/INBOX
/new
1234 wtr
() { curl wttr.in
/boston
; }
1236 xevkb
() { xev
-event keyboard
; }
1238 ziva
() { e
"toot! i love dancing. fart"; }
1242 # from curl cheat.sh/:bash_completion
1243 _cheatsh_complete_curl
()
1246 _get_comp_words_by_ref
-n : cur
1249 #cur="${COMP_WORDS[COMP_CWORD]}"
1250 prev
="${COMP_WORDS[COMP_CWORD-1]}"
1251 opts
="$(curl -s cheat.sh/:list | sed s@^@cheat.sh/@)"
1253 if [[ ${cur} == cheat.sh
/* ]] ; then
1254 COMPREPLY
=( $
(compgen
-W "${opts}" -- ${cur}) )
1255 __ltrim_colon_completions
"$cur"
1259 complete
-F _cheatsh_complete_curl curl
1265 # we also have a file in /a/c/...konsole...
1266 local f
=$HOME/.config
/konsolerc
1267 setini DefaultProfile profileian.profile
"Desktop Entry" $f
1268 setini Favorites profileian.profile
"Favorite Profiles" $f
1269 setini ShowMenuBarByDefault false KonsoleWindow
$f
1270 setini TabBarPosition Top TabBar
$f
1274 while read -r k v
; do
1275 # shellcheck disable=SC2154
1276 setini
$k $v sakura
/a
/c
/subdir_files
/.config
/sakura
/sakura.conf
1278 colorset1_back rgb(33,37,39
1282 disable_numbered_tabswitch true
1283 scroll_lines 10000000
1288 reset-xscreensaver
() {
1289 # except for spash, i set these by setting gui options in
1290 # xscreensaver-command -demo
1291 # then finding the corresponding option in .xscreensaver
1292 # spash, i happened to notice in .xscreensaver
1294 # dpmsOff, monitor doesnt come back on using old free software supported nvidia card
1295 cat > /home
/iank
/.xscreensaver
<<'EOF'
1298 dpmsStandby: 0:02:00
1299 dpmsSuspend: 0:03:00
1303 lockTimeout: 0:03:00
1310 # * stuff that makes sense to be at the end
1311 if [[ "$SUDOD" ]]; then
1312 # allow failure, for example if we are sudoing into a user with diffferent/lesser permissions.
1315 elif [[ -d /a
]] && [[ $PWD == "$HOME" ]] && [[ $
- == *i
* ]]; then
1324 # for mitmproxy to get a newer python.
1325 # commented until i want to use it because it
1326 # noticably slows bash startup
1330 if [[ $EUID == 0 ||
! -e ~
/.pyenv
/bin
]]; then
1331 echo "error: dont be root. make sure pyenv is installed"
1334 export PATH
="$HOME/.pyenv/bin:$PATH"
1335 eval "$(pyenv init -)"
1336 eval "$(pyenv virtualenv-init -)"
1340 export GOPATH
=$HOME/go
1341 path-add
$GOPATH/bin
1342 path-add
/usr
/local
/go
/bin
1344 # I have the git repo and a release. either one should work.
1345 # I have both because I was trying to solve an issue that
1346 # turned out to be unrelated.
1347 # ARDUINO_PATH=/a/opt/Arduino/build/linux/work
1348 export ARDUINO_PATH
=/a
/opt
/arduino-1.8
.9
1350 # They want to be added to the start, but i think
1351 # that should be avoided unless we really need it.
1352 path-add
--end ~
/.npm-global
1354 path-add
--end $HOME/.cargo
/bin
1356 # taken from default changes to bashrc and bash_profile
1357 path-add
--end $HOME/.rvm
/bin
1358 path-add
--end $HOME/.gem
/ruby
/2.3.0/bin
1361 export BASEFILE_DIR
=/a
/bin
/fai-basefiles
1363 #export ANDROID_HOME=/a/opt/android-home
1364 # https://f-droid.org/en/docs/Installing_the_Server_and_Repo_Tools/
1365 #export USE_SDK_WRAPPER=yes
1366 #PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
1368 # didnt get drush working, if I did, this seems like the
1369 # only good thing to include for it.
1370 # Include Drush completion.
1371 # if [ -f "/home/ian/.drush/drush.complete.sh" ] ; then
1372 # source /home/ian/.drush/drush.complete.sh
1376 # https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
1377 # i added an extra condition as gentoo xorg guide says depending on
1378 # $DISPLAY is fragile.
1379 if [[ ! $DISPLAY && $XDG_VTNR == 1 ]] && shopt -q login_shell
&& isarch
; then
1384 # ensure no bad programs appending to this file will have an affect