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 source /a
/bin
/small-misc-bash
/psg-function
33 # for x in /a/bin/bash_unpublished/source-!(.#*); do echo source $x; done
34 source /a
/bin
/bash_unpublished
/source-semi-priv
35 source /a
/bin
/bash_unpublished
/source-state
37 source /a
/bin
/log-quiet
/logq-function
46 complete
-F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr
50 if which anki
&>/dev
/null
; then
53 schroot
-c anki
-- anki
59 hrcat
/m
/md
/alerts
/new
/* /m
/md
/alerts
/cur
/*
64 files
=(/m
/md
/alerts
/new
/* /m
/md
/alerts
/cur
/*)
65 if (( ${#files[@]} )); then
73 # pushd in case current directory has an ansible.cfg file
74 pushd /a
/xans
>/dev
/null
75 ansible-playbook
-v -l ${1:- $(hostname -f)} site.yml
79 pushd /a
/work
/ansible-configs
>/dev
/null
80 time ansible-playbook
-v -i inventory adhoc.yml
"$@"
84 pushd /a
/bin
/distro-setup
/a
>/dev
/null
85 ansible-playbook site.yml
90 # googling android emulator libGL error: failed to load driver: r600
91 # lead to http://stackoverflow.com/a/36625175/14456
92 export ANDROID_EMULATOR_USE_SYSTEM_LIBS
=1
93 /a
/opt
/android-studio
/bin
/studio.sh
"$@" &r
;
99 sl
$h <<'EOF' || return 1
102 f=/var/lib/bind/db.b8.nz
105 s install -m 644 -o bind -g bind /p/c/machine_specific/linode/bind-initial/db.b8.nz $f
111 bbk
() { # btrbk wrapper
114 systemctl is-active btrbk.timer || active
=false
116 ser disable btrbk.timer
118 if systemctl is-active btrbk.service
; then
119 $active && ser
enable btrbk.timer
120 echo "cron btrbk is already running"
125 btrbk-run
"$@" | pee
cat "systemd-cat -t btrbk-run"
126 $active && ser
enable btrbk.timer
129 bfg
() { java
-jar /a
/opt
/bfg-1.12
.14.jar
"$@"; }
132 xclock
-digital -update 1 -face 'arial black-80:bold'
140 switch-mail-host
$1 $HOSTNAME | pee
cat "systemd-cat -t switch-mail-host"
147 switch-mail-host
$HOSTNAME $1 | pee
cat "systemd-cat -t switch-mail-host"
150 # note, i had --delete-excluded, but that deletes all files in --exclude-from on
151 # the remote site, which doesn't make sense, so not sure why i had it.
153 p
=(/a
/bin
/a
/exe
/a
/h
/a
/c
/p
/c
/machine_specific
/linode
{,.hosts
} /a
/opt
/{emacs
,emacs-debianstable
,mu
})
154 a
="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
156 m rsync $@
$a ${p[@]} /p
/c
/machine_specific
/l2 root@l2.b8.nz
:/ || ret
=$?
157 m rsync $@
$a ${p[@]} /p
/c
/machine_specific
/li root@li.b8.nz
:/ || ret
=$?
158 m rsync $@
-ahviSAXPH root@iankelling.org
:/a
/h
/proposed-comments
/ /a
/h
/proposed-comments || ret
=$?
161 lipushnoe
() { # noe = noemacs. for running faster.
162 rsync $@
--delete-excluded -ahviSAXPH --specials --devices --delete --relative \
163 --exclude-from=/p
/c
/li-rsync-excludes
/a
/bin
/a
/exe
/a
/h
/a
/c
/p
/c
/machine_specific
/li root@li
:/
166 #### begin bitcoin related things
168 local f
=/etc
/bitcoin
/bitcoin.conf
169 # importprivkey will timeout if using the default of 15 mins.
170 # upped it to 1 hour.
171 bitcoin-cli
-rpcclienttimeout=60000 -$
(s
grep rpcuser
= $f) -$
(s
grep rpcpassword
= $f) "$@"
173 btcusd
() { # $1 btc in usd
175 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
176 printf "$%s\n" "$price"
178 printf "$%.2f\n" "$(echo "scale
=4; $price * $1"| bc -l)"
181 usdbtc
() { # $1 usd in btc
183 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
184 printf "$%s\n" "$price"
186 # 100 mil satoshi / btc. 8 digits after the 1.
187 printf "%.8f btc\n" "$(echo "scale
=10; $1 / $price "| bc -l)"
190 satoshi
() { # $1 satoshi in usd
192 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
193 price
=$
(echo "scale=10; $price * 0.00000001"|
bc -l)
194 printf "$%f\n" "$price"
196 printf "$%.2f\n" "$(echo "scale
=10; $price * $1"| bc -l)"
199 #### end bitcoin related things
203 cbfstool
() { /a
/opt
/coreboot
/build
/cbfstool
"$@"; }
209 cp /a
/bin
/data
/COPYING
"$@"
211 cp /a
/bin
/data
/COPYING .
218 cp /a
/bin
/data
/LICENSE
"$@"
220 cp /a
/bin
/data
/LICENSE .
225 if type -p chromium
&>/dev
/null
; then
229 cmd
="schroot -c stretch chromium"
230 CHROMIUM_FLAGS
='--enable-remote-extensions' $cmd &r
236 # pipe to this, or just type like a shell
238 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)
242 for host in x2 kw tp.b8.nz x3.b8.nz frodo.b8.nz
; do
248 debian_pick_mirror
() {
249 # netselect-apt finds a fast mirror.
250 # but we need to replace the mirrors ourselves,
251 # because it doesnt do that. best it can do is
252 # output a basic sources file
253 # here we get the server it found, get the main server we use
254 # then substitute all instances of one for the other in the sources file
255 # and backup original to /etc/apt/sources.list-original.
256 # this is idempotent. the only way to identify debian sources is to
257 # note the original server, so we put it in a comment so we can
260 file=$
(mktemp
-d)/f
# safe way to get file name without creating one
261 sudo netselect-apt
-o "$file" ||
return 1
262 url
=$
(grep ^
\\w
$file |
head -n1 |
awk '{print $2}')
263 sudo
cp -f /etc
/apt
/sources.list
/etc
/apt
/sources.list-original
264 sudo
sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc
/apt
/sources.list
268 digdiff @ns
{1,2}.iankelling.org
"$@"
276 *DISTRO-BEGIN
!*|
*DISTRO
!*)
277 /b
/ds
/distro-begin ||
return $?
280 *DISTRO-END
!*|
*DISTRO
!*)
281 /b
/ds
/distro-end ||
return $?
293 envload
() { # load environment from a previous: export > file
294 local file=${1:-$HOME/.${USER}_env}
295 eval "$(export | sed 's/^declare -x/export -n/')"
296 while IFS
= read -r line
; do
297 # declare -x makes variables local to a function
298 eval ${line/#declare -x/export}
303 # one that comes with distros is too old for newer devices
305 /a
/opt
/android-platform-tools
/fastboot
"$@";
308 kdecd
() { /usr
/lib
/x86_64-linux-gnu
/libexec
/kdeconnectd
; }
310 # List of apps to install/update
311 # Create from existing manually installed apps by doing
313 # fdroidcl search -i, then manually removing
314 # automatically installed/preinstalled apps
317 # # my attempt at recovering from boot loop:
318 # # in that case, boot to recovery (volume up, home button, power, let go of power after samsun logo)
320 # mount /dev/block/mmcblk0p12 /data
322 # find -iname '*appname*'
324 # usually good enough to just rm -rf /data/app/APPNAME
327 # # causes replicant to crash
328 # org.quantumbadger.redreader
329 # org.kde.kdeconnect_tp
331 # not broke, but wont work without gps
332 #com.zoffcc.applications.zanavi
333 # not broke, but not using atm
334 #com.nutomic.syncthingandroid
335 # # doesn\'t work on replicant
336 #net.sourceforge.opencamera
339 de.marmaro.krt.ffupdater
340 me.ccrama.redditslide
341 org.fedorahosted.freeotp
343 com.alaskalinuxuser.justnotes
344 com.artifex.mupdf.viewer.app
345 com.danielkim.soundrecorder
347 com.ghostsq.commander
349 com.jmstudios.redmoon
351 org.kde.kdeconnect_tp
354 cz.martykan.forecastie
357 de.marmaro.krt.ffupdater
358 eu.siacs.conversations
360 im.vector.alpha
# riot
362 me.tripsit.tripmobile
364 net.minetest.minetest
369 org.smssecure.smssecure
371 sh.
ftp.rocketninelabs.meditationassistant.opensource
373 # https://forum.xda-developers.com/android/software-hacking/wip-selinux-capable-superuser-t3216394
378 local -A installed updated
381 if fdroidcl search
-u |
grep ^org.fdroid.fdroid
; then
382 fdroidcl
install org.fdroid.fdroid
386 for p
in $
(fdroidcl search
-i|
grep -o "^\S\+"); do
389 for p
in $
(fdroidcl search
-u|
grep -o "^\S\+"); do
392 for p
in ${fdroid_pkgs[@]}; do
393 if ! ${installed[$p]:-false}; then
395 # sleeps are just me being paranoid since replicant has a history of crashing when certain apps are installed
399 for p
in ${!installed[@]}; do
400 if ! ${updated[$p]:-true}; then
407 firefox-default-profile
() {
408 key
=Default value
=1 section
=$1
409 file=/p
/c
/subdir_files
/.mozilla
/firefox
/profiles.ini
410 sed -ri "/^ *$key/d" "$file"
411 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d};/ *\[$section\]/a $key=$value" "$file"
413 fdhome
() { #firefox default home profile
414 firefox-default-profile Profile0
418 firefox-default-profile Profile4
422 if type -P firefox
&>/dev
/null
; then
432 firefox
-P alt
"$@" >/dev
/null
2>&1
438 local dname
="${PWD##*/}"
439 local m
="/a/tmp/$dname-missing"
440 local d
="/a/tmp/$dname-diff"
441 [[ -e $d ]] && rm "$d"
442 [[ -e $m ]] && rm "$m"
445 while read -r line
; do
447 if [[ -e "$fsfile" ]]; then
448 md5diff
"$line" "$fsfile" && tee -a "/a/tmp/$dname-diff" <<< "$fsfile $line"
454 done < <(find .
-type f
)
457 (( msize
<= 100 )) && cat $m
461 # expected output, with different tmp dirs
462 # /tmp/tmp.HDPbwMqdC9/c/d ./c/d
463 # /a/tmp/tmp.qLDkYxBYPM-missing
473 echo different
> $x/c
/d
478 # test whether missing files were renamed, generally for use with fsdiff
479 # $1 = fsdiff output file, $2 = directory to compare to. pwd = fsdiff dir
480 # echos non-renamed files
484 { sums
+=( "$(md5sum < "$x")" ) ; } 2>/dev
/null
486 while read -r line
; do
487 { missing_sum
=$
(md5sum < "$line") ; } 2>/dev
/null
489 for x
in "${sums[@]}"; do
490 if [[ $missing_sum == "$x" ]]; then
495 $renamed ||
echo "$line"
501 # F = fullscren, z = random, Z = auto zoom
502 command feh
-FzZ "$@"
508 firefox
-P default
"$@" >/dev
/null
2>&1
513 git config user.email ian@iankelling.org
517 # at least in flidas, things rely on gpg being gpg1
523 local email
=ian@iankelling.org
524 if readlink ~
/.mu |
grep fsf
&>/dev
/null
; then
527 git send-email
--notes "--envelope-sender=<$email>" \
528 --suppress-cc=self
"$@"
533 # do git status on published repos.
536 cd $
(readlink
-f $x)/..
537 status
=$
(i status
-s) ||
pwd
538 if [[ $status ]]; then
541 printf "%s\n" "$status"
549 /a
/opt
/idea-IC-163.7743
.44/bin
/idea.sh
"$@" &r
553 if type gvfs-open
&> /dev
/null
; then
558 # another alternative is run-mailcap
562 grep -Evi -e "^(\S+\s+){4}(sudo|sshd|cron)\[\S*:" \
563 -e "^(\S+\s+){4}systemd\[\S*: (starting|started) (btrfsmaintstop|dynamicipupdate|spamd dns bug fix cronjob|rss2email)\.*$"
566 journalctl
-n 10000 -f "$@" | jfilter
568 jr
() { journalctl
"$@" | jfilter |
less ; }
569 jrf
() { journalctl
-f "$@" | jfilter
; }
572 kff
() { # keyboardio firmware flash
573 pushd /a
/bin
/distro-setup
/Arduino
/Model01-Firmware
574 yes $
'\n' |
make flash
582 if [[ $1 == /* ]]; then
584 if mountpoint
/mnt
/$base; then
589 if ! sudo cryptsetup luksOpen
$l $base; then
593 sudo mkdir
-p /mnt
/$base
594 sudo mount
/dev
/mapper
/$base /mnt
/$base
595 sudo chown
$USER:$USER /mnt
/$base
598 sudo umount
/mnt
/$base
599 l
=$
(sudo cryptsetup status
/dev
/mapper
/$base|
sed -rn 's/^\s*device:\s*(.*)/\1/p')
600 sudo cryptsetup luksClose
/dev
/mapper
/$base ||
return 1
611 [[ -e $src ]] ||
{ set +x
; return 1; }
612 mv -T $src $dst ||
{ set +x
; return 1; }
615 mu index
--maildir=/m
/4e
623 [[ -e $src ]] ||
{ set +x
; return 1; }
624 if [[ -L $dst ]]; then rm $dst; fi
631 markdown
"$1" >/tmp
/mdtest.html
632 firefox
/tmp
/mdtest.html
637 mo
() { xset dpms force off
; } # monitor off
640 e
"lspci -nnk|gr -iA2 net"
641 lspci
-nnk|gr
-iA2 net
643 e
"s lshw -C network"
650 ser stop NetworkManager
652 s resolvconf
-d NetworkManager
658 ser start NetworkManager
664 oathtool
--totp -b "$@" | xclip
-selection clipboard
669 # from http://askubuntu.com/questions/456021/remove-vocals-from-mp3-and-get-only-instrumentals
670 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
673 pfind
() { #find *$1* in $PATH
674 [[ $# != 1 ]] && { echo requires
1 argument
; return 1; }
676 IFS
=: pathArray
=($PATH); unset IFS
677 find "${pathArray[@]}" -iname "*$1*"
681 # trash-restore lists everything that has been trashed at or below CWD
682 # This picks out files just in CWD, not subdirectories,
683 # which also match grep $1, usually use $1 for a time string
684 # which you get from running restore-trash once first
687 # last condition is to not ask again for ones we skipped
688 while name
="$( echo | restore-trash | gr "$PWD/[^
/]\
+$
" | gr "$1" )" \
689 && [[ $name ]] && (( $
(wc -l <<<"$name") >= nth
)); do
690 name
="$(echo "$name" | head -n $nth | tail -n 1 )"
691 read -r -p "$name [Y/n] " ask
692 if [[ ! $ask ||
$ask == [Yy
] ]]; then
693 x
=$
( echo "$name" | gr
-o "^\s*[0-9]*" )
694 echo $x | restore-trash
> /dev
/null
695 elif [[ $ask == [Nn
] ]]; then
705 rld
/a
/h
/_site
/ li
:/var
/www
/iankelling.org
/html
710 # fixes the menu bar in xmonad. this won\'t be needed when xmonad
711 # packages catches up on some changes in future (this is written in
714 # geekosaur: so youll want to upgrade to xmonad 0.13 or else use a
715 # locally modified XMonad.Hooks.ManageDocks that doesnt set the
716 # work area; turns out it\'s impossible to set correctly if you are
717 # not a fully EWMH compliant desktop environment
719 # geekosaur: chrome shows one failure mode, qt/kde another, other
720 # gtk apps a third, ... I came up with a setting that works for me
721 # locally but apparently doesnt work for others, so we joined the
722 # other tiling window managers in giving up on setting it at all
724 xprop
-root -remove _NET_WORKAREA
728 # reviewboard, used at my old job
729 #rbpipe() { rbt post -o --diff-filename=- "$@"; }
730 #rbp() { rbt post -o "$@"; }
741 hr
; echo dnsmasq is $
(systemctl is-active dnsmasq
)
742 f
=/var
/run
/dnsmasq
/resolv.conf
743 hr
; echo $f:; ccat
$f
744 f
=/etc
/dnsmasq-servers.conf
745 hr
; echo $f:; ccat
$f
748 # only run on MAIL_HOST. simpler to keep this on one system.
749 r2eadd
() { # usage: name url
750 # initial setup of rss2email:
751 # r2e new r2e@iankelling.org
752 # that initializes files, and sets default email.
753 # symlink to the config doesnt work, so I copied it to /p/c
754 # and then use cli option to specify explicit path.
755 # Only option changed from default config is to set
758 # or else for a few feeds, the from address is set by the feed, and
759 # if I fail delivery, then I send a bounce message to that from
760 # address, which makes me be a spammer.
762 r2e add
$1 "$2" $1@r2e.iankelling.org
763 # get up to date and dont send old entries now:
766 r2e
() { command r2e
-d /p
/c
/rss2email.json
-c /p
/c
/rss2email.cfg
"$@"; }
768 rspicy
() { # usage: HOST DOMAIN
769 # connect to spice vm remote host. use vspicy for local host
771 # shellcheck disable=SC2087
773 sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
774 sed -rn "s/.*port='([0-9]+).*/\1/p"
780 echo "error: no port found. check that the domain is running."
786 # s gem install scss-lint
787 pushd /a
/opt
/thoughtbot-guides
790 scss-lint
-c /a
/opt
/thoughtbot-guides
/style
/sass
/.scss-lint.yml
"$@"
797 script -t -c "mpv --no-config --no-resume-playback --no-terminal --no-audio-display '$1'" $tmp/typescript
2>$tmp/timing
798 # todo, the current sleep seems pretty good, but it
799 # would be nice to have an empirical measurement, or
800 # some better wait to sync up.
802 # note: --loop-file=no prevents it from hanging if you have that
803 # set to inf the mpv config.
804 # --loop=no prevents it from exit code 3 due to stdin if you
805 # had it set to inf in mpv config.
807 # args go to mpv, for example --volume=80, 50%
810 trap "trap - TERM && kill 0" INT TERM ERR; set -e
811 ( sleep .2; scriptreplay <( cat <<'EOF'
815 $(cat $tmp/typescript)
818 base64 -d - <<'EOF'| mpv --loop=no --loop-file=no --no-terminal --no-audio-display "\$@" -
827 smeld
() { # ssh meld usage host1 host2 file
828 meld
<(ssh $1 cat $3) <(ssh $2 cat $3)
832 PATH
=/usr
/local
/spdhackfix
:$PATH command spd
"$@"
839 # ssh, copy my universal config over if needed.
841 # By default .bashrc is sourced for ALL ssh commands. This is wonky.
842 # Normally, this file is not sourced when a script is run, but we can
843 # override that by having #!/bin/bash -l. I want the same thing for ssh
844 # commands. when a local script runs an ssh command, bashrc should not be
845 # sourced, unless we use a modified command.
847 # So, in my bashrc, test for conditions of noninteractive ssh and return
848 # if so. And we don't keep the rest of the code in .bashrc, because
849 # even though we return, we parse the whole file which can cause errors
852 # To test for an overriding condition: bash builtin vars and env show no
853 # difference in ssh vs local, except shell level which is not
854 # reliable. one option is to use an environment variable. env variables
855 # sent across ssh are strictly limited. We could override an obscure
856 # unused LC_var, like telephone, but I don't want to run into some edge
857 # case where that messes things up. I choose to set SendEnv and
858 # AcceptEnv ssh config vars to allow the environment variable BRC to
859 # propagate across ssh, and for hosts I don't control, I start an inner
860 # shell with it set, which doubles up as a way to have a nondefault
863 # inspired from https://github.com/Russell91/sshrc
866 local args info_date info_t
type now tmp tmp2 old sshinfo cmd haveinfo dorsync info_sec
870 # ssh [-1246Antivivisectionist] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
871 # [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-L address]
872 # [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option]
873 # [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] [user@]hostname
878 -[1246AaCfGgKkMNnqsTtVvXxYy
])
881 -[bcDEeFIiLlmOopQRSWw
])
882 # -oOption etc is valid
883 if (( ${#1} >= 3 )); then
886 args
+=("$1" "$2"); shift 2
895 if [[ ! $remote ]]; then
896 echo $0: error hostname required
>&2
901 tmpa
=(/p
/sshinfo
/???????????
"$remote")
903 if [[ -e $sshinfo ]]; then
907 tmp
=${sshinfo[0]##*/}
910 if [[ $type == b
]]; then
912 if (( $
(stat
-c%Y
/b
/ds
/brc
) > info_sec || $
(stat
-c%Y
/b
/ds
/.bashrc
) > info_sec
)); then
919 # use this weird yes thing to ensure we know ssh succeeded
920 tmp
=$
(command ssh "${args[@]}" "$remote" "if test -e /a/bin/ds/.bashrc -a -L .bashrc; then echo yes; fi") ||
return
921 if [[ $tmp == yes ]]; then
927 if $dorsync ||
! $haveinfo; then
928 sshinfo
=/p
/sshinfo
/$now$type"$remote"
932 if [[ $type == b
]]; then
934 RSYNC_RSH
="ssh ${args[*]}" rsync
-rptL /b
/ds
/sl
/.iank
"$remote":
938 # Theres a couple ways to do this. im not sure whats best,
939 # but relying on bash 4.4+ escape quoting seems most reliable.
940 command ssh "${args[@]}" "$remote" \
941 BRC
=t bash
-c '.\ .iank/.bashrc\;"\"\$@\""' bash
${@@Q}
942 elif [[ ! -t 0 ]]; then
943 # This case is when commands are being piped to ssh.
944 # Normally, no bashrc gets sourced.
945 # But, since we are doing all this, lets source it because we can.
946 cat <(echo . .iank
/.bashrc
) - |
command ssh "${args[@]}" "$remote" BRC
=t bash
948 command ssh -t "${args[@]}" "$remote" BRC
=t INPUTRC
=.iank
/.inputrc bash
--rcfile .iank
/.bashrc
952 BRC
=t
command ssh "${args[@]}" "$remote" ${@@Q}
954 command ssh "${args[@]}" "$remote" BRC
=t bash
-l
959 ssh -oControlMaster=no
-oControlPath=/ "$@"
961 # kill off old shared socket then ssh
964 while [[ $1 == -* ]]; do
968 m pkill
-f "^ssh: /tmp/ssh_mux_${USER}_${1#*@}_22_"
969 m
ssh "${opts[@]}" "$@"
973 BRC
=t
command ssh "$@"
979 declare -gi _seq
; _seq
+=1
980 echo "test body" | m
mail -s "test mail from $HOSTNAME, $_seq" "${@:-root@localhost}"
981 # for testing to send from an external address, you can do for example
982 # -fian@iank.bid -aFrom:ian@iank.bid web-6fnbs@mail-tester.com
983 # note in exim, you can retry a deferred message
985 # MSG_ID is in /var/log/exim4/mainlog, looks like 1ccdnD-0001nh-EN
988 # to test sieve, use below command. for fsf mail, see offlineimap-sync script
989 # make modifications, then copy to live file, use -eW to actually modify mailbox
991 # Another option is to use sieve-test SCRIPT MAIL_FILE. note,
992 # sieve-test doesnt know about envelopes, Im not sure if sieve-filter does.
994 # sieve with output filter. arg is mailbox, like INBOX.
995 # This depends on dovecot conf, notably mail_location in /etc/dovecot/conf.d/10-mail.conf
998 sieve-filter
"$@" 2> >(head; tail) >/tmp
/testsieve.log
&& sed -rn '/^Performed actions:/,/^[^ ]/{/^ /p}' /tmp
/testsieve.log |
sort |
uniq -c
1001 # always run this first, edit the test files, then run the following
1003 _dosieve ~
/sieve
/maintest.sieve
${1:-INBOX} delete
1006 c ~
/sieve
; cp personal
{test,}.sieve
; cp lists
{test,}.sieve
; cp personalend
{test,}.sieve
1007 _dosieve ~
/sieve
/main.sieve
-eW ${1:-INBOX} delete
1012 # testmail above calls sendmail, which is a link to exim/postfix.
1013 # its docs dont say a way of adding an argument
1014 # to sendmail to turn on debug output. We could make a wrapper, but
1015 # that is a pain. Exim debug args are documented here:
1016 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
1018 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-building_and_installing_exim.html
1019 # note, for exim daemon, you can turn on debug options by
1020 # adding -d, etc to COMMONOPTIONS in
1021 # /etc/default/exim4
1023 # to specify recipients other than those in to, cc, bcc, you can use the cli args, eg:
1024 # exim -i 'test@zroe.org, t2@zroe.org' <<'EOF'
1028 From: i@dmarctest.b8.nz
1029 To: mailman@dev.fsf.org
1031 Reply-to: rtest@iankelling.org
1033 This is a test message.
1040 # https://askubuntu.com/questions/160945/is-there-a-way-to-disable-a-laptops-internal-keyboard
1041 id
=$
(xinput
--list --id-only 'AT Translated Set 2 keyboard')
1042 if xinput list |
grep -F '∼ AT Translated Set 2 keyboard' &>/dev
/null
; then
1043 echo enabling keyboard
1044 # find the first slave keyboard number, they are all the same in my output.
1045 # if they werent, worst case we would need to save the slave number somewhere
1046 # when it got disabled.
1047 slave
=$
(xinput list |
sed -n 's/.*slave \+keyboard (\([0-9]*\)).*/\1/p' |
head -n1)
1048 xinput reattach
$id $slave
1057 (sleep $
(calc
"$* * 60") && mpv
--no-config --volume 50 /a
/bin
/data
/alarm.mp3
) > /dev
/null
2>&1 &
1060 trg
() { transmission-remote-gtk
&r
; }
1062 # example, set global upload limit to 100 kilobytes:
1064 TR_AUTH
=":$(jq -r .profiles[0].password ~/.config/transmission-remote-gtk/config.json)" transmission-remote transmission.lan
-ne "$@"
1070 dir
="$(dirname "$1")"
1071 if [[ -e $1 && ! -w $1 ||
! -w $
(dirname "$1") ]]; then
1074 # full path for using in some initial setup steps
1079 #m s nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*pia.conf") -n -m "$@"
1080 m s nsenter
-t $
(pgrep
-f "/usr/sbin/openvpn .* --config /etc/openvpn/.*client.conf") -n -m "$@"
1083 vpncmd gksudo
-u iank
"firefox -no-remote -P vpn" &r
1086 vpncmd gksudo
-u iank
"$*"
1094 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
1095 local vpn_service
=openvpn-client
1097 local vpn_service
=openvpn
1100 [[ $1 ]] ||
{ echo need arg
; return 1; }
1101 journalctl
--unit=$vpn_service@
$1 -f -n0 &
1102 s systemctl start
$vpn_service@
$1
1103 # sometimes the ask-password agent does not work and needs a delay.
1105 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779240
1106 # noticed around 8-2017 after update from around stretch release
1107 # on debian testing, even though the bug is much older.
1108 s systemd-tty-ask-password-agent
1112 [[ $1 ]] ||
{ echo need arg
; return 1; }
1113 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
1114 local vpn_service
=openvpn-client
1116 local vpn_service
=openvpn
1118 s systemctl stop
$vpn_service@
$1
1124 vspicy
() { # usage: VIRSH_DOMAIN
1125 # connect to vms made with virt-install
1126 spicy
-p $
(sudo virsh dumpxml
"$1"|
grep "<graphics.*type='spice'"|\
1127 sed -r "s/.*port='([0-9]+).*/\1/")
1131 cat-new-files
/m
/4e
/INBOX
/new
1134 wtr
() { curl wttr.in
/boston
; }
1136 xevkb
() { xev
-event keyboard
; }
1140 # from curl cheat.sh/:bash_completion
1141 _cheatsh_complete_curl
()
1144 _get_comp_words_by_ref
-n : cur
1147 #cur="${COMP_WORDS[COMP_CWORD]}"
1148 prev
="${COMP_WORDS[COMP_CWORD-1]}"
1149 opts
="$(curl -s cheat.sh/:list | sed s@^@cheat.sh/@)"
1151 if [[ ${cur} == cheat.sh
/* ]] ; then
1152 COMPREPLY
=( $
(compgen
-W "${opts}" -- ${cur}) )
1153 __ltrim_colon_completions
"$cur"
1157 complete
-F _cheatsh_complete_curl curl
1163 # we also have a file in /a/c/...konsole...
1164 local f
=$HOME/.config
/konsolerc
1165 setini DefaultProfile profileian.profile
"Desktop Entry" $f
1166 setini Favorites profileian.profile
"Favorite Profiles" $f
1167 setini ShowMenuBarByDefault false KonsoleWindow
$f
1168 setini TabBarPosition Top TabBar
$f
1172 while -r read k v
; do
1173 # shellcheck disable=SC2154
1174 setini
$k $v sakura
/a
/c
/subdir_files
/.config
/sakura
/sakura.conf
1176 colorset1_back rgb(33,37,39
1180 disable_numbered_tabswitch true
1181 scroll_lines 10000000
1186 reset-xscreensaver
() {
1187 # except for spash, i set these by setting gui options in
1188 # xscreensaver-command -demo
1189 # then finding the corresponding option in .xscreensaver
1190 # spash, i happened to notice in .xscreensaver
1192 # dpmsOff, monitor doesnt come back on using old free software supported nvidia card
1193 cat > /home
/iank
/.xscreensaver
<<'EOF'
1196 dpmsStandby: 0:02:00
1197 dpmsSuspend: 0:03:00
1201 lockTimeout: 0:03:00
1208 # * stuff that makes sense to be at the end
1209 if [[ "$SUDOD" ]]; then
1212 elif [[ -d /a
]] && [[ $PWD == "$HOME" ]] && [[ $
- == *i
* ]]; then
1221 # for mitmproxy to get a newer python.
1222 # commented until i want to use it because it
1223 # noticably slows bash startup
1227 if [[ $EUID == 0 ||
! -e ~
/.pyenv
/bin
]]; then
1228 echo "error: dont be root. make sure pyenv is installed"
1231 export PATH
="$HOME/.pyenv/bin:$PATH"
1232 eval "$(pyenv init -)"
1233 eval "$(pyenv virtualenv-init -)"
1237 export GOPATH
=$HOME/go
1238 path-add
$GOPATH/bin
1239 path-add
/usr
/local
/go
/bin
1241 # I have the git repo and a release. either one should work.
1242 # I have both because I was trying to solve an issue that
1243 # turned out to be unrelated.
1244 # ARDUINO_PATH=/a/opt/Arduino/build/linux/work
1245 export ARDUINO_PATH
=/a
/opt
/arduino-1.8
.9
1247 # They want to be added to the start, but i think
1248 # that should be avoided unless we really need it.
1249 path-add
--end ~
/.npm-global
1251 path-add
--end $HOME/.cargo
/bin
1253 # taken from default changes to bashrc and bash_profile
1254 path-add
--end $HOME/.rvm
/bin
1255 path-add
--end $HOME/.gem
/ruby
/2.3.0/bin
1258 export BASEFILE_DIR
=/a
/bin
/fai-basefiles
1260 #export ANDROID_HOME=/a/opt/android-home
1261 # https://f-droid.org/en/docs/Installing_the_Server_and_Repo_Tools/
1262 #export USE_SDK_WRAPPER=yes
1263 #PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
1265 # didnt get drush working, if I did, this seems like the
1266 # only good thing to include for it.
1267 # Include Drush completion.
1268 # if [ -f "/home/ian/.drush/drush.complete.sh" ] ; then
1269 # source /home/ian/.drush/drush.complete.sh
1273 # https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
1274 # i added an extra condition as gentoo xorg guide says depending on
1275 # $DISPLAY is fragile.
1276 if [[ ! $DISPLAY && $XDG_VTNR == 1 ]] && shopt -q login_shell
&& isarch
; then
1281 # ensure no bad programs appending to this file will have an affect