2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
23 # this gets sourced. shebang is just for file mode detection
28 if [[ $LESSHISTFILE == - ]]; then
31 elif [[ $HISTFILE ]]; then
35 source /a
/bin
/distro-setup
/path-add-function
37 # add this with absolute paths as needed for better security
38 #path-add --end /path/to/node_modules/.bin
40 #path-add --end /usr/lib/node_modules/corepack/shims/
42 # pip3 --user things go here:
43 path-add
--end ~
/.local
/bin
44 path-add
--ifexists --end /a
/work
/libremanage
45 path-add
--ifexists --end /a
/opt
/adt-bundle
*/tools
/a
/opt
/adt-bundle
*/platform-tools
46 path-add
--ifexists --end /a
/opt
/scancode-toolkit-3.10.
47 path-add
--ifexists --end /p
/bin
51 # https://askubuntu.com/questions/1254544/vlc-crashes-when-opening-any-file-ubuntu-20-04
52 if grep -qE '^VERSION_CODENAME="(nabia|focal)"' /etc
/os-release
&>/dev
/null
; then
53 export MESA_LOADER_DRIVER_OVERRIDE
=i965
64 # shellcheck disable=SC2034 # used in brc
65 SL_SSH_ARGS
="-F $HOME/.ssh/confighome"
72 # generated instead of dynamic for the benefit of shellcheck
73 #for x in /a/bin/distro-functions/src/* /a/bin/!(githtml)/*-function?(s); do echo source $x ; done
74 source /a
/bin
/distro-functions
/src
/identify-distros
75 source /a
/bin
/log-quiet
/logq-function
76 # for x in /a/bin/bash_unpublished/source-!(.#*); do echo source $x; done
77 source /a
/bin
/bash_unpublished
/source-semi-priv
78 source /a
/bin
/bash_unpublished
/source-state
80 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
83 export NOT_MAIL_HOST_P
=t
86 source /a
/bin
/ds
/beet-data
97 m pactl unload-module module-loopback
98 m pactl unload-module module-null-sink
99 m pactl unload-module module-remap-source
101 IFS
=" " read -r -a sources
<<<"$(pacmd list-sources | sed -rn 's/.*name: <([^>]+).*/\1/p')"
105 for s
in ${sources[@]}; do
112 m pactl load-module module-null-sink sink_name
=ianinput sink_properties
=device.description
=ianinputs
114 m pactl load-module module-loopback
source=${sources[i]} sink_dont_move
=true sink
=ianinput
116 pactl load-module module-remap-source source_name
=iancombine master
=ianinput.monitor source_properties
=device.description
=iancombine
120 # For testing restrictive ssh.
124 sed '/^ *IdentityFile/d' ~
/.ssh
/config
>$d/config
125 s
command ssh -F $d/config
-i /q
/root
/h
"$@"
129 # For testing restrictive rsync
133 sed '/^ *IdentityFile/d' ~
/.ssh
/config
>$d/config
134 s rsync
-e "ssh -F $d/config -i /q/root/h" "$@"
137 # rsync as root and avoid the default restrictive h key & config.
139 s rsync
-e "ssh -F /root/.ssh/confighome" "$@"
143 ssh bow DISPLAY
=:0 scrot
/tmp
/oegu.jpg
144 scp bow
:/tmp
/oegu.jpg
/t
145 ssh bow
rm /tmp
/oegu.jpg
159 if [[ $arg == [89]0Etiona
* ]]; then
161 rtime
=${arg#*Etiona} # remote time
162 if [[ ! $rtime ]]; then
165 dir
=/a
/opt
/emacs-trisquel
${v}-nox/.iank
166 ltime
=$
(stat
-c%Y
$dir/e
/e
/.emacs.d
/init.el
)
167 if (( ltime
> rtime
)); then
168 m rsync
-rptL --delete --filter=". /b/ds/sl/rsync-filter" $dir "$remote":/home
/iank
174 local f
=/home
/iank
/.emacs.d
/init.el
175 sl
--sl-test-cmd "sed -rn '/^VERSION=/{s/^.*=//;s/[^[:alnum:]]//gp}' /etc/os-release; test -e $f && stat -c%Y $f" --sl-test-hook slemacs
"$@"
179 # Run this manually after .emacs.d changes. Otherwise, to check if
180 # files changed with find takes 90ms. sl normally only adds 25ms. We
181 # could cut it down to 10ms if we put things on a btrfs filesystem and
182 # looked for changes there, or used some inotify thing, but that seems
183 # like too much work.
184 egh
() { # emacs gnuhope
185 RSYNC_RSH
=ssh m rsync
-rptL --delete --filter=". /b/ds/sl/rsync-filter" /a
/opt
/emacs-trisquel9-nox
/.iank lists2d.fsf.org
:.ianktrisquel_9
186 RSYNC_RSH
=ssh m rsync
-rptL --delete --filter=". /b/ds/sl/rsync-filter" /a
/opt
/emacs-trisquel8-nox
/.iank lists2d.fsf.org
:/home
/iank
189 local shell
="bash -s"
190 if [[ $HOSTNAME != kw
]]; then
191 shell
="ssh kw.office.fsf.org"
195 sudo mkdir /root/.ianktrisquel_9
196 sudo rsync -rptL --delete --filter=". /b/ds/sl/rsync-filter" /a/opt/emacs-trisquel9-nox/.iank /root/.ianktrisquel_9
197 rsync -rptL --delete --filter=". /b/ds/sl/rsync-filter" /a/opt/emacs-trisquel8-nox/.iank /home/iank
201 rm-docker-iptables
() {
202 s iptables
-S | gr docker | gr
-- -A |
sed 's/-A/-D/'|
while read -r l
; do sudo iptables
$l; done
203 s iptables
-S -t nat | gr docker | gr
-- -A |
sed 's/-A/-D/'|
while read -r l
; do sudo iptables
-t nat
$l; done
204 s iptables
-S | gr docker | gr
-- -N |
sed 's/-N/-X/'|
while read -r l
; do sudo iptables
$l; done
205 s iptables
-S -t nat | gr docker | gr
-- -N |
sed 's/-N/-X/'|
while read -r l
; do sudo iptables
-t nat
$l; done
208 # usage mkschroot [-] distro codename packages
209 # - means no piping in of sources.list
211 # note some useful post mkschroot i've used in the past
212 # tu /nocow/schroot/flidas/etc/sudoers <<EOF
213 # $USER ALL=(ALL) NOPASSWD: ALL
214 # Defaults env_keep += SUDOD
215 # Defaults always_set_home
218 # sd /nocow/schroot/flidas//etc/locale.gen <<'EOF'
221 # s schroot -c flidas locale-gen
222 # s schroot -c flidas update-locale LANG=en_US.UTF-8
225 local sources force repo n distro
227 while [[ $1 == -* ]]; do
229 -f) force
=true
; shift ;;
232 if [[ ! -s $sources ]]; then
233 echo mkschroot
: error
: sources
file $sources does not exist or is empty
244 repo
=http
://mirror.fsf.org
/trisquel
/
247 repo
=http
://archive.ubuntu.com
/ubuntu
/
250 repo
=http
://deb.debian.org
/debian
/
256 if ! $force && schroot
-l |
grep -xFq chroot
:$n; then
257 echo "$0: $n schroot already installed, skipping"
262 sd
/etc
/schroot
/chroot.d
/$n.conf
<<EOF
268 preserve-environment=true
272 if [[ ! -e $d/bin
]]; then
274 # resolvconf otherwise schroot fails with
275 # cp: not writing through dangling symlink '/var/run/schroot/mount/flidas-7a2362e0-81b3-4848-92c1-610203ef5976/etc/resolv.conf'
276 sudo debootstrap
--exclude=resolvconf
$n $d $repo
278 if [[ $sources ]]; then
279 sudo
install -m 644 $sources $d/etc
/apt
/sources.list
281 sudo chroot
$d apt-get update
282 sudo DEBIAN_FRONTEND
=noninteractive chroot
$d apt-get
-y dist-upgrade
--purge --auto-remove
283 sudo
cp -P {,$d}/etc
/localtime
284 if (( ${#apps[@]} )); then
285 sudo DEBIAN_FRONTEND
=noninteractive schroot
-c $n -- apt-get
install --allow-unauthenticated -y ${apps[@]}
290 # note: this is incomplete and untested.
291 # https://wiki.archlinux.org/index.php/Install_Arch_Linux_from_existing_Linux#Creating_a_chroot
294 mirror
=https
://mirrors.edge.kernel.org
/archlinux
/iso
/latest
/
295 tarball
=$
(curl
-s $mirror |
sed -nr 's/.*"(archlinux-bootstrap-.*-x86_64.tar.gz)".*/\1/p')
296 wget
-O /tmp
/arch.
tar.gz https
://mirrors.edge.kernel.org
/archlinux
/iso
/latest
/$tarball
297 s mkdir
-p /nocow
/schroot
/arch
298 cd _
/nocow
/schroot
/arch
299 s
sed -i '/## United States/,/^$/s,^#,,' etc
/pacman.d
/mirrorlist
300 # error: could not determine cachedir mount point /var/cache/pacman/pkg
301 s
sed -i /^CheckSpace
/d etc
/pacman.conf
302 chroot .
/bin
/bash
-s <<'EOF'
304 pacman-key --populate archlinux
307 # example of building an aur package:
308 # pacman -Sy base-devel wget
310 # f=$target/etc/sudoers
311 # line='iank ALL=(ALL) NOPASSWD: ALL'
312 # if [[ ! -e $f ]] || ! grep -xF "$line" $f; then
316 # wget https://aur.archlinux.org/cgit/aur.git/snapshot/anbox-image-gapps.tar.gz
317 # tar xzf anbox-image-gapps.tar.gz
318 # cd anbox-image-gapps
323 # clock back in to timetrack from last entry
325 sqlite3
/p
/.timetrap.db
"update entries set end = NULL where id = (select max(id) from entries);"
329 # s sshfs bu@$host:/bu/home/md /bu/mnt -o reconnect,ServerAliveInterval=20,ServerAliveCountMax=30 -o allow_other
332 echo all
>/etc
/exim
4/no-delay-eximids
335 echo >/etc
/exim
4/no-delay-eximids
339 local -a array tmpstr delayon
341 if grep -qFx all
/etc
/exim
4/no-delay-eximids
; then
345 echo all
>/etc
/exim
4/no-delay-eximids
347 tmpstr
=$
(exiqgrep
-i -r.\
*)
348 mapfile
-t array
<<<"$tmpstr"
351 echo >/etc
/exim
4/no-delay-eximids
356 eid
="$(exipick -i -r.\*|h1)"
357 sed -n "/^all$/p;\$a $eid" /etc
/exim
4/no-delay-eximids
363 printf "%s\n" "$eid" >>/etc
/exim
4/no-delay-eximids
370 /a
/f
/gnulib
/build-aux
/gnupload
"$@"
376 f
=(/p
/c
/firefox
*/compatibility.ini
)
377 if (( ${#f[@]} )); then
384 s checkrestart
-b /a
/bin
/ds
/checkrestart-blacklist
-pv
387 cp-blocked-domains-to-brains
() {
388 cp /a
/f
/ans
/roles
/exim
/files
/mx
/simple
/etc
/exim
4/bad-sender_domains
/a
/f
/brains
/sysadmin
/kb
/blocked_email_domains.mdwn
390 cp-blocked-domains-to-ansible
() {
391 cp /a
/f
/brains
/sysadmin
/kb
/blocked_email_domains.mdwn
/a
/f
/ans
/roles
/exim
/files
/mx
/simple
/etc
/exim
4/bad-sender_domains
397 hrcat
/m
/md
/daylert
/{cur
,new
}/*
402 rm -f /m
/md
/daylert
/{cur
,new
}/*
408 hrcat
/m
/md
/alerts
/{cur
,new
}/*
411 ssh bk.b8.nz
"shopt -s nullglob; hrcat /m/md/INBOX/new/* /m/md/INBOX/cur/*"
415 rm -f /m
/md
/alerts
/{cur
,new
}/*
417 ssh bk.b8.nz
"shopt -s nullglob; rm -f /m/md/INBOX/new/* /m/md/INBOX/cur/*"
422 find /var
/local
/cron-errors
/home
/iank
/cron-errors
/sysd-mail-once-state
-type f
424 ralerts
() { # remote alerts
426 # this list is duplicated in check-remote-mailqs
427 for h
in bk je li frodo x3wg kdwg sywg
; do
430 if [[ $HOSTNAME == "${h%wg}" ]]; then
434 $shell find /var
/local
/cron-errors
/home
/iank
/cron-errors
/sysd-mail-once-state
-type f || ret
=$?
442 # pushd in case current directory has an ansible.cfg file
443 pushd /a
/xans
>/dev
/null
444 ansible-playbook
-v -l ${1:- $(hostname -f)} site.yml
448 pushd /a
/work
/ans
>/dev
/null
449 time ansible-playbook
-i inventory adhoc.yml
"$@"
453 pushd /a
/bin
/distro-setup
/a
>/dev
/null
454 ansible-playbook site.yml
"$@"
459 # googling android emulator libGL error: failed to load driver: r600
460 # lead to http://stackoverflow.com/a/36625175/14456
461 export ANDROID_EMULATOR_USE_SYSTEM_LIBS
=1
462 /a
/opt
/android-studio
/bin
/studio.sh
"$@" & r
465 # Convert brains file path to url and vice versa
466 # usage: brains [URL_OR_PATH]
468 _iki-convert brains.fsf.org
/wiki
"$@"
471 _iki-convert gluestick.office.fsf.org
"$@"
476 local url url_prefix path input repo_dir dir url_dir url name
478 name
="${url_prefix%%.*}"
484 read -r -p "enter path or url"$
'\n' input
488 path
="$repo_dir/${input##http*://"$url_prefix"/}"
489 # for files like x.jpg, we dont need to convert the extension.
490 if [[ $path == */ ]]; then
492 # brains adds trailing slash, but without trailing is still
493 # valid. We can't be totally sure whether to add mdwn, but we
494 # can guess based on the existence of the file. We can't be sure
495 # because it could be a file like x.jpg, that we just don't have
497 elif [[ ! -f $path && -e $path.mdwn
]]; then
500 j
printf "%s\n" "$path"
504 url_dir
=$
(echo "$path" |
sed -r "s,^(/a)?$repo_dir/,,")
505 url
="https://$url_prefix/$url_dir"
506 if [[ $url == *.mdwn
]]; then
515 # Generate beet smartplaylists for navidrome.
516 # for going in the reverse direction, run
517 # /b/ds/navidrome-playlist-export
518 beetsmartplaylists
() {
519 install -m 0700 -d /tmp
/ianbeetstmp
521 # kill off any playlists we deleted. they will still need manual
522 # killing from a navidrome client.
523 rm -rf /i
/converted
/beetsmartplaylists
524 mkdir
-p /i
/converted
/beetsmartplaylists
525 for f
in /tmp
/ianbeetstmp
/*; do
526 sed 's,^/i/m,/i/converted,;s,\.flac$,.mp3,' "$f" >"/i/converted/beetsmartplaylists/${f##*/}"
529 rmdir /tmp
/ianbeetstmp
532 # internal function for beetrating, in case we need to ssh
534 local tmp rating path cpath sqlpath userid
535 # plucked this from the db. im the only user.
536 userid
=23cc2eb9-e35e-4811-a0f0-d5f0dd6eb634
537 while read -r rating path
; do
538 cpath
="/i/converted${path#/i/m}" # converted path
541 cpath
="${cpath%.*}.mp3"
544 if [[ ! -e $cpath ]]; then
545 echo "beetraing: error: this should not happen, path does not exist: $cpath"
548 sqlpath
="${cpath//\'/\'\'}"
549 old_rating
=$
(sqlite3
/i
/navidrome
/navidrome.db
"select rating from annotation inner join media_file on item_id = id where path = '$sqlpath' and item_type = 'media_file';")
550 if [[ $old_rating ]]; then
551 if [[ $old_rating != "$rating" ]]; then
552 echo "setting rating $old_rating -> $rating $cpath"
553 # https://stackoverflow.com/a/50317320
554 # we got a timeout error once. arbitrarily chose 15 seconds.
555 sqlite3
/i
/navidrome
/navidrome.db
".timeout 15000" "
556 update annotation set rating = $rating
558 select media_file.id from annotation inner join media_file on annotation.item_id = media_file.id
559 where media_file.path = '$sqlpath' and annotation.item_type = 'media_file' );"
562 echo "setting rating $rating $cpath"
563 # /a/opt/navidrome/persistence/sql_annotations.go v0.48.0
564 # https://www.sqlite.org/lang_insert.html
565 sqlite3
/i
/navidrome
/navidrome.db
".timeout 15000" "insert into annotation select '$(uuidgen)', '$userid', id, 'media_file', 0, NULL, $rating, 0, NULL from media_file where path = '$sqlpath';"
570 # Export beets ratings into navidrome
573 if [[ $HOSTNAME != kd
]]; then
574 ssh_prefix
="ssh b8.nz"
576 # shellcheck disable=SC2016 # obvious reason
577 beet
ls -f '$rating $path' $nav_convert_query |
$ssh_prefix beetrating-stdin
580 # Do transcoding and hardlinking of audio files for navidrome.
584 # a bunch of effort to ignore output we dont care about...
585 sed 's/^format_item:.*/format_item: ignore_this/' ~
/.config
/beets
/config.yaml
>$tmpf
586 beet
-c $tmpf convert
-y $nav_convert_query > >(grep -vFx 'ignore_this' ||
:) 2> >(grep -v '^convert: Skipping' ||
:)
589 # This deletes files in the converted directory which should no longer
590 # be there due to a rename of the unconverted file.
591 beetconvert-rm-extras
() {
595 # shellcheck disable=SC2016 # obvious reason
596 beet
ls -f '$path' $nav_convert_query >"$tmpf"
597 ## begin removal of files that are leftover from previous conversion,
598 # eg, previously rated > 1, now rated 1.
600 convertedpath
="/i/converted${l#/i/m}"
601 case $convertedpath in
602 *.flac
) convertedpath
="${convertedpath%.flac}.mp3" ;;
604 paths
[$convertedpath]=t
607 find /i
/converted
-path /i
/converted
/beetsmartplaylists
-prune -o \
( -type f
-print \
) -name '*.mp3' -o -name '*.m4a' >"$tmpf"
609 if [[ ! ${paths[$l]} ]]; then
612 # note: the pruning is duplicative of filtering on name, but whatever.
617 beets-gen-playlists
() {
619 local -a query_array query_str
620 for i
in "${!bpla[@]}"; do
622 eval "query_array=(${bpla[$i]})"
623 for str
in "${query_array[@]}"; do
624 query_str
+=("\"$str\"")
628 query: '${query_str[@]}'
633 # beet playlist. use beetag with a playlist name
635 local playlist playlist_regex
638 for playlist
in "${!bpla[@]}"; do
639 printf "%s\n" "$playlist"
646 playlist_regex
='[a-z0-9_]'
647 if [[ ! $playlist =~
$playlist_regex ]]; then
648 echo "bpl: error unexpected chars in playlist: $playlist"
651 # all but last arg as options
652 eval beetag
-r "${*:1:$# - 1}" "${bpla[$playlist]}"
654 complete
-W "${!bpla[*]}" bpl
657 # beet modify quietly
661 # a bunch of effort to ignore output we dont care about...
662 sed 's/^format_item:.*/format_item: ignore_this/' ~
/.config
/beets
/config.yaml
>$tmpf
663 beet
-c $tmpf modify
-y "$@" > >(grep -vFx -e 'ignore_this' -e 'Modifying 1 items.' ||
:)
669 # https://stackoverflow.com/a/5722874
670 kill %% 2>/dev
/null ||
:; wait %% 2>/dev
/null ||
:
676 printf "%s=%s " "$arg" "${!arg}"
681 # Must be called from beetag for variables to be setup
683 local -i i j col_total row
col button_total row_total remainder_cols remainder_term
685 button_total
=${#button_map[@]}
686 row_total
=$
(( button_total
/ col_total
))
687 remainder_cols
=$
(( button_total
% col_total
))
689 #dv button_total row_total remainder_cols
691 # - 3 is just a constant that helps things work in practice.
692 if [[ $LINES ]] && (( LINES
- 3 < scrolled
)); then
694 for (( i
=0; i
<button_total
; i
++)); do
695 row
=$
(( i
/ col_total
))
696 col=$
(( i
% col_total
))
697 remainder_term
=$remainder_cols
698 if (( col < remainder_term
)); then
701 j
=$
(( col * row_total
+ row
+ remainder_term
))
702 # avoid double newline when we have exactly row * col buttons
703 if (( i
== button_total
- 1 )); then
704 printf "%s %s" ${buttons[j]} ${button_map[j]}
705 elif (( i
% col_total
== col_total
-1 )); then
706 printf "%s %s\n" ${buttons[j]} ${button_map[j]}
708 printf "%s %-15s" ${buttons[j]} ${button_map[j]}
714 y other genres z fg player ' = toggle play 1-5 rate ] repeat1
715 ; previous _ = delete up/down skip mpv vol,pause,seek
722 # Must be called from beetag for variables to be setup
725 scrolled
=$
(( scrolled
+ $1 ))
727 if $erasable_line; then
728 # https://stackoverflow.com/a/71286261
729 # erase line / delete line in terminal
730 printf '\033[1A\033[K'
734 # meant to be called from beetag
736 if $erasable_line; then
737 # https://stackoverflow.com/a/71286261
738 printf '\033[1A\033[K'
743 # meant to be called from beetag
745 if jobs -p |
grep -q .
&>/dev
/null
; then
746 printf "%s\n" "$*" | socat
- /tmp
/mpvsock
>/dev
/null ||
:
749 # meant to be called from beetag
752 # note: testing for background jobs will output nothing if we are in a pipeline
753 printf "%s\n" "$*" | socat
- /tmp
/mpvsock ||
:
756 # meant to be called from beetag
757 mpvrpc-percent-pos
() {
758 mpvrpco
'{ "command": ["get_property", "percent-pos"] }' | jq .data |
sed 's/\..*/%/' 2>/dev
/null ||
:
761 # run if not running.
763 # Note: this does not work with shell scripts as they are normally
764 # invoked, because the ps output has the interpreter at the start.
765 # A workaround is to invoke the command in that format, or we could
766 # do various other workarounds.
768 # background, this relies on how ps converts newlines in arguments to spaces, and
769 # assumes we won't be searching for a command with spaces in its arguments
771 # shellcheck disable=SC2009 # pgrep has no fixed string option, plus see above.
772 if ps h
-o args
-C "${1##*/}" |
grep -Fxqv "$*" &>/dev
/null ||
[[ $?
== 141 ]]; then
776 # variation of above: run or wait if running
779 pid
=$
(ps h
-o 'pid,args' -C "${1##*/}" |
sed -r 's/^[[:space:]]*([0-9]+)[[:space:]](.*)/\1\n\2/' |
grep -B1 -Fx "$*" |
head -n1 ||
: )
781 # https://unix.stackexchange.com/questions/427115/listen-for-exit-of-process-given-pid
782 tail --pid="$pid" -f /dev
/null
789 local path nextpath cachedir finalpath nextpath count
790 cachedir
=$HOME/.iank-music-cache
794 # note: logic duplicated in beetpull
796 if [[ $HOSTNAME == kd
]]; then
801 finalpath
="$cachedir${path#/i/m}"
802 rowir rsync
--partial -a --inplace --mkpath "b8.nz:$path" "$finalpath"
803 finalnextpath
="$cachedir${nextpath#/i/m}"
804 count
=$
(pgrep
-a -f "^rsync --partial -a --inplace --mkpath $cachedir" ||
[[ $?
== 1 ]] )
805 # allow us to start 2 rsyncs in the background
806 if [[ $count == [01] ]]; then
807 rinr rsync
--partial -a --inplace --mkpath "b8.nz:$nextpath" "$finalnextpath" &
812 mpvrpc
'{ "command": ["loadfile", "'"$finalpath"'"] }'
816 # usage: beetag [-r] [-s] QUERY
817 # it lists the query, reads an input char for tagging one by one.
819 # note, you may want to change the play command for doing rapid taging
820 # by immediately jumping forward into the song. this is set in the beets
823 # (available buttons: ` \ ) ] [ and non-printing chars, see
824 # https://stackoverflow.com/questions/10679188/casing-arrow-keys-in-bash
827 # note: after foregrounding the player, must quit it to get back. can't ctrl-c.
829 # keys I dont need help to remember:
834 # todo: enter should also unpause
836 local last_genre_i fstring tag id char new_item char_i genre tag remove doplay i j random path
837 local do_rare_genres read_wait line lsout tmp ls_line skip_lookback
838 local escape_char escaped_input expected_input skip_input_regex right_pad erasable_line seek_sec
839 local pl_state_path pl_state_dir pl_state_file tmpstr
840 local new_random pl_seed_path seed_num seed_file
fmt first_play repeat1
841 local -a buttons button_map ids tags tmp_tags initial_ls ls_lines paths
843 local -i i j volume scrolled id_count line_int skip_start pre_j_count head_count skip_lookback
844 local -i overflow_lines overflow
848 escape_char
=$
(printf "\u1b")
849 scrolled
=999 # more than any $LINES
850 ### begin arg processing ###
869 echo beetag
: error expected a query arg
>&2
872 ### end arg processing ###
874 # note: I used to do beetpull here, but mpv + ssfs on slowish
875 # connection leads to bad/buggy result.
882 last_genre_i
=$
(( ${#common_genres[@]} - 1 ))
883 buttons
=( {a..p
} {r..w
} {6.
.8} , .
/ - "=")
884 button_map
=(${common_genres[@]} ${pl_tags[@]})
886 for tag
in "${pl_tags[@]}"; do
887 fstring
+="%ifdef{$tag,$tag }"
890 for (( i
=0; i
<${#buttons[@]}; i
++ )); do
891 button_i
[${buttons[i]}]=$i
894 # note: this structure of files is rather haphazard.
895 seed_num
=1 # later we might want a few
896 seed_file
=seed
$seed_num
898 pl_state_file
=$seed_num
902 pl_state_dir
=/i
/info
/pl-state
903 if [[ $playlist ]]; then
904 pl_state_dir
=$pl_state_dir/$playlist
906 pl_state_dir
=$pl_state_dir/nopl
908 pl_state_path
=$pl_state_dir/$pl_state_file
909 pl_seed_path
=$pl_state_dir/$seed_file
912 if $new_random ||
[[ ! -r $pl_seed_path ]]; then
913 mkdir
-p $pl_state_dir
914 { base64
< /dev
/urandom |
head -c 200 ||
:; echo; } > $pl_seed_path
917 # PijokVipiotOzeph is just a random string for a delimiter
918 # shellcheck disable=SC2016 # false positive
919 fmt='%ifdef{rating,$rating }'"$fstring"'$genre | $title - $artist - $album $length $id PijokVipiotOzeph $path'
920 # shellcheck disable=SC2016 # obvious reason
921 tmpstr
=$
(beet
ls -f "$fmt" "$@" |
{ if $random; then sort -R --random-source=$pl_seed_path; else cat; fi; } )
922 mapfile
-t initial_ls
<<<"$tmpstr"
923 if [[ ! ${initial_ls[0]} ]]; then
924 echo "beetag: error: no result from beet ls $*"
927 id_count
=${#initial_ls[@]}
928 for line
in "${initial_ls[@]}"; do
929 path
="${line#*PijokVipiotOzeph }"
930 # https://github.com/koalaman/shellcheck/issues/2171
931 # shellcheck disable=SC2190 # bug in shellcheck, looking at paths from an earlier function
933 line_no_path
="${line% PijokVipiotOzeph*}"
934 id
="${line_no_path##* }"
936 right_pad
="${line_no_path%% |*}"
937 ls_line
="$(printf %-11s "$right_pad")${line_no_path#"$right_pad"}"
938 ls_lines
+=("$ls_line")
946 if [[ $playlist ]]; then
947 if [[ -r $pl_state_path ]]; then
948 j
=$
(cat $pl_state_path)
952 # i only care to see a smallish portion of the list when starting.
953 head_count
=$
(( LINES
- 20 ))
954 head_start
=$
(( j
- head_count
/ 2 ))
955 if (( head_start
< 0 )); then
958 for (( i
=head_start
; i
< head_count
&& i
< id_count
; i
++ )); do
959 ls_line
="${ls_lines[$i]}"
960 if (( i
== j
)); then
967 #{ mpv --profile=a --volume=$volume --idle 2>&1 & } 2>/dev/null
968 mpv
--profile=a
--volume=$volume --idle &
969 # if we dont sleep, can expect an error like this:
970 # socat[1103381] E connect(5, AF=1 "/tmp/mpvsock", 14): Connection refused
977 lsout
="${ls_lines[j]}"
978 tags
=( ${lsout%%,*} )
980 printf "██ %s\n" "$lsout"
983 # https://stackoverflow.com/a/7687716
984 # note: duplicated down below
986 # notes on old method of invoking mpv each time:
987 # https://superuser.com/questions/305933/preventing-bash-from-displaying-done-when-a-background-command-finishes-execut
988 # we can't disown or run in a subshell or set +m because all that
989 # disabled job control from working properly in ways we want.
990 # todo: figure out some kind of answer to this. I think the solution
991 # is that we are waiting in 2 second intervals and checking if the
992 # background job exists. Instead, we should make mpv just idle
993 # when it is done with a song and then send it a command to play a new track.
994 #{ mpv --profile=a --volume=$volume "$path" 2>&1 & } 2>/dev/null
996 #{ beet play "--args=--volume=$volume" "id:$id" 2>&1 & } 2>/dev/null
998 # on slow systems, we may need to wait like .3 seconds before mpv
999 # is ready. so impatiently check until it is ready
1000 if $first_play; then
1002 for (( i
=0; i
<20; i
++ )); do
1003 if [[ $
(mpvrpco
'{ "command": ["get_property", "idle-active"] }' 2>/dev
/null | jq .data
) == true
]]; then
1004 mpvrpc-loadfile
"$path" 2>/dev
/null
1010 mpvrpc-loadfile
"$path"
1018 read -rsN1 -t $read_wait char || ret
=$?
1020 # Automatically skip to the next song if this one ends, unless
1021 # we turn off the autoplay.
1022 if (( ret
== 142 )) ||
[[ ! $char ]]; then
1023 if jobs -p |
grep -q .
&>/dev
/null
&& \
1024 [[ $
(mpvrpco
'{ "command": ["get_property", "idle-active"] }' | jq .data
) == false
]]; then
1034 if [[ $char == $
'\n' ]]; then
1044 echo "play toggled off"
1048 mpvrpc-loadfile
"$path"
1055 m beet
rm --delete --force "id:$id"
1056 beetag-nostatus
4 # guessing. dont want to test atm
1060 beetmq
"id:$id" rating
=$char
1064 volume
=$
(( volume
- 5 ))
1065 if (( volume
< 0 )); then
1071 if (( volume
> 130 )); then
1076 mpvrpc
'{ "command": ["set_property", "volume", '$volume'] }'
1087 echo repeat1
=$repeat1
1095 if $do_rare_genres; then
1096 do_rare_genres
=false
1097 button_map
=(${common_genres[@]} ${pl_tags[@]})
1098 last_genre_i
=$
(( ${#rare_genres[@]} - 1 ))
1101 button_map
=(${rare_genres[@]} ${pl_tags[@]})
1102 last_genre_i
=$
(( ${#rare_genres[@]} - 1 ))
1105 for (( i
=0; i
<${#buttons[@]}; i
++ )); do
1106 button_i
[${buttons[i]}]=$i
1108 for (( i
=0; i
<${#button_map[@]}; i
++ )); do
1109 echo ${buttons[i]} ${button_map[i]}
1115 # if we ctrl-z, it will put the whole function into sleep. so
1116 # basically, we can't return from a foregrounded mpv like we
1117 # would like to without some strange mechanism I can't think
1118 # of. So, instead, detect ctrl-c and wait a while for prompt
1119 # input. One idea would be to use a music player like mpd where
1120 # we can send it messages.
1129 # output time if we aren't already paused
1130 if [[ $
(mpvrpco
'{ "command": ["get_property", "pause"] }' | jq .data
) == false
]]; then
1132 #date -d @"$(mpvrpco '{ "command": ["get_property", "playback-time"] }' | jq .data)" +%M:%S ||:
1136 # originally found this solution, which worked fine.
1137 #kill -STOP %% &>/dev/null
1139 mpvrpc
'{ "command": ["cycle", "pause"] }'
1144 read -rsn2 escaped_input
1145 skip_input_regex
="^[0-9]+$"
1146 case $escaped_input in
1147 # up char: show all the songs, use less
1151 if (( j
- skip_lookback
> skip_start
)); then
1152 skip_start
=$
(( j
- skip_lookback
))
1154 beetag-nostatus $
(( id_count
- skip_start
- 1 ))
1157 for (( i
=skip_start
; i
< id_count
; i
++ )); do
1158 if (( i
== j
)); then
1159 echo " * ${ls_lines[i]}"
1162 echo "$line_int | ${ls_lines[i]}"
1169 # skip forward, but show the last few songs anyways.
1172 if (( j
- skip_lookback
> skip_start
)); then
1173 skip_start
=$
(( j
- skip_lookback
))
1175 beetag-nostatus $
(( id_count
- skip_start
- 1 ))
1178 overflow_lines
=$LINES
1179 for (( i
=skip_start
; i
< overflow_lines
- 1 && i
< id_count
; i
++ )); do
1180 ls_line
="${ls_lines[i]}"
1181 overflow
=$
(( ${#ls_line} / ( COLUMNS
- 1 ) ))
1182 overflow_lines
=$
(( overflow_lines
- overflow
))
1183 if (( i
== j
)); then
1187 echo "$line_int | $ls_line"
1203 mpvrpc
'{ "command": ["seek", "'$seek_sec'"] }'
1207 expected_input
=false
1210 if $expected_input; then
1218 if [[ $skip_input =~
$skip_input_regex ]]; then
1219 pre_j_count
=$
(( j
- skip_start
))
1220 j
=$
(( j
+ skip_input
- pre_j_count
))
1221 if (( skip_input
< pre_j_count
)); then
1229 char_i
=${button_i[$char]}
1230 new_item
=${button_map[$char_i]}
1231 if [[ ! $char_i ||
! $new_item ]]; then
1232 echo "error: no mapping of input: $char found, try again"
1235 if (( char_i
<= last_genre_i
)); then
1236 m beetmq
"id:$id" genre
=$new_item
1240 for tag
in ${tags[@]}; do
1241 if [[ $new_item == "$tag" ]]; then
1249 m beetmq
"id:$id" "$new_item!"
1252 m beetmq
"id:$id" $new_item=t
1257 if (( j
< id_count
- 1 )); then
1263 if [[ $playlist ]]; then
1264 echo $j >$pl_state_path
1269 # usage: FILE|ALBUM_DIR [GENRE]
1271 local import_path genre_arg single_track_arg
1273 if [[ ! -e $import_path ]]; then
1274 echo "beetadd error: path does not exist"
1277 genre_arg
="--set genre=$2"
1279 if [[ -f $import_path ]]; then
1282 beet import
--set totag
=t
$single_track_arg $genre_arg "$import_path"
1284 beet modify
-y totag
:t
"totag!"
1287 # update navidrome music data after doing beets tagging
1292 # this function would naturally just be part of beetconvert,
1293 # but we want beetrating to happen sooner so that our ssh auth dialog
1294 # happens earlier. Currently 17 seconds for that.
1295 m beetconvert-rm-extras
1296 m beetsmartplaylists
1299 # pull in beets library locally
1301 local sshfs_host sshfs_cmd
1303 if [[ $HOSTNAME == kd
]]; then
1306 if [[ ! -e /i
]]; then
1308 s chown iank
:iank
/i
1310 sshfs_cmd
="sshfs -o ServerAliveInterval=15,reconnect $sshfs_host:/i /i"
1311 if ! pgrep
-f "^$sshfs_cmd$" >/dev
/null
; then
1316 # remove all playlists in navidrome, for when I make big
1317 # playlist name changes and just want to scrap everything.
1321 if [[ $HOSTNAME != kd
]]; then
1322 echo "error: run on kd"
1325 sqlite3
/i
/navidrome
/navidrome.db
"select id from playlist" >$tmpf
1326 while read -r id
; do
1328 curl
--http1.1
--user "iank:$navidrome_pw" "https://b8.nz/rest/deletePlaylist.view?u=iank&s=sb219dvv7egnoe4i47k75cli0m&t=1c8f5575cd0fdf03deb971187c9c88b1&v=1.2.0&c=DSub&id=$id"
1335 # This is not perfect but generally good enough. It escapes all
1336 # metachars listed man 3 pcrepattern.
1338 sed 's/[]\\^$.[|()?*+{}]/[&]/g; s/\^/\\^/g' <<<"$*"
1341 # usage beegenre QUERY
1343 # beet set genre for QUERY based on existing artist most used genre on
1345 # inverse of query for each artist found in QUERY. If query starts with
1346 # "artist:" it is used as the artist instead of each artist in QUERY.
1349 local count artist artregex genre singleartist tmpf tmpf2
1350 local -a artists genres
1361 if $singleartist; then
1362 # shellcheck disable=SC2016 # obvious reason
1363 beet
ls -f '$genre' "$artist" "${@/#/^}" |
sort |
uniq -c |
sort -n |
tail -n1 >$tmpf
1364 read -r count genre
<$tmpf ||
:
1365 beet modify
"$artist" "$@" genre
=$genre
1367 # shellcheck disable=SC2016 # obvious reason
1368 beet
ls -f '$artist' "$@" |
sort -u >$tmpf
1369 while read -r artist
; do
1370 artregex
=$
(er
"$artist")
1371 # shellcheck disable=SC2016 # obvious reason
1372 beet
ls -f '$genre' "artist::^$artregex$" "${@/#/^}" |
sort |
uniq -c |
sort -n |
tail -n1 >$tmpf2
1373 read -r count genre
<$tmpf2 ||
continue
1374 if [[ $count ]]; then
1375 artists
+=("$artregex")
1377 echo "beet modify -y $* \"artist::^$artist$\" genre=$genre # $count"
1380 read -r -N 1 -s -p "Y/n " char
1383 for (( i
=0; i
<${#artists[@]}; i
++ )); do
1384 beet modify
-y "$@" "artist::^${artists[i]}$" genre
=${genre[i]}
1397 date +%F_
%T
%:::z
-d "$(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<"$indate")" "$@"
1400 # fudCaHougfirp is a random string
1406 } |
sed -r 's/-0([45])( |$)/fudCaHougfirp0\100/;s/_/T/;s/[:-]//g;s/fudCaHougfirp/-/'
1411 while read -r line
; do
1412 if [[ $line == *20[0-9][0-9][0-9][0-9][0-9][0-9]T
[0-9][0-9][0-9][0-9][0-9][0-9]-0[45]00* ]]; then
1413 pre
="${line%%20[0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]-0[45]00*}"
1414 post
="${line##*20[0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]-0[45]00}"
1415 mid
="${line:${#pre}:22}"
1416 echo "$pre$(btrbk-date "$mid")$post"
1423 jr
-u btrbk-run
-u btrbk
-u switch-mail-host
"$@"
1427 btrbk-host-debug-show-host
() {
1430 for host in $remote $alt local; do
1431 if line
=$
(grep -P "\S*$f" /tmp
/b
/s
/$host.log
); then
1432 if [[ $snaphost ]]; then
1433 e error
: snaphost
=$snaphost, host=$host line
="$line"
1435 if [[ $line == ssh* ]]; then
1436 tmp
="${line#ssh://}"
1437 snaphost
="${tmp%%/*}"
1443 echo $snaphost $f | btrbk-date-sed
1447 # If we get a btrfs receive error like this:
1448 # ERROR: ... clone: did not find source subvol
1449 # running this command will help track down the problem.
1450 # Alter remote= and alt=. When I used it, remote is
1451 # the host having the error when I push a snapshot.
1452 # Alt is just the other host that takes snapshots
1453 # besides the local host.
1454 btrbk-host-debug
() {
1460 for host in $remote $alt; do
1461 h
=$
(ssh $host hostname
)
1462 rsync
-a /var
/log
/btrbk
$host:/var
/log
/btrbk
/var
/log
/btrbk
/$h
1463 grr
'\bsnapshot success' /var
/log
/btrbk
/$h >/tmp
/b
/$h.log
1465 ## this takes a while, we only want to do it on 1st run
1466 # if [[ -s /tmp/b/$host.log ]]; then continue; fi
1467 # ssh $host journalctl -u btrbk-run -u btrbk -u switch-mail-host >/tmp/b/$host.log
1469 gr
'\bsnapshot success' /var
/log
/btrbk
/*.log
>/tmp
/b
/local.log
1472 gr
'\bsnapshot success' $f >s
/$f
1477 for f
in "${localq[@]}"; do
1482 for f
in $
(ssh $remote "cd /mnt/root/btrbk; echo q.*"); do
1483 if [[ ! ${localq_a[$f]} ]]; then
1487 btrbk-host-debug-show-host
"${localq[@]}"
1488 if (( ${#remoteq[@]} >= 1 )); then
1489 echo "=== $remote only ===="
1490 btrbk-host-debug-show-host
${remoteq[@]}
1495 # note, to check for glue records
1496 # First, find some the .org nameservers:
1497 # dig +trace iankelling.org
1499 # dig ns1.iankelling.org @b0.org.afilias-nst.org.
1501 # Now, compare for a domain that does have glue records setup (note the A
1502 # and AAAA records in ADDITIONAL SECTION, those are glue records like the
1503 # one I'm asking for):
1505 # $ dig ns1.gnu.org @b0.org.afilias-nst.org.
1507 # todo: make sm pull/push use systemd instead of the journal cat command
1508 bbk
() { # btrbk wrapper
1512 systemctl is-active btrbk.timer || active
=false
1514 ser stop btrbk.timer
1516 btrbk_is_active
=$
(systemctl is-active btrbk.service ||
:)
1517 case $btrbk_is_active in
1518 inactive|failed
) : ;;
1520 echo "bbk: error: systemctl is-active btrbk.service output: $btrbk_is_active"
1521 if $active; then ser start btrbk.timer
; fi
1525 # todo: consider changing this to srun and having the args come
1526 # from a file like /etc/default/btrbk, like is done in exim
1527 s jdo btrbk-run
"$@"
1530 echo bbk
: WARNING
: btrbk.timer not restarted due to failure
1532 ser start btrbk.timer
1539 fai-monitor | pee
cat "fai-monitor-gui -"
1542 bfg
() { java
-jar /a
/opt
/bfg-1.12
.14.jar
"$@"; }
1545 xclock
-digital -update 1 -face 'arial black-80:bold'
1548 nnn
() { /a
/opt
/nnn
-H "$@"; }
1550 locat
() { # log-once cat
1553 files
=(/var
/local
/cron-errors
/* /home
/iank
/cron-errors
/* /sysd-mail-once-state
/*)
1554 case ${#files[@]} in
1571 # usage: first get an adb shell on the phone.
1573 # just followed instructions in readme at
1574 # https://github.com/Yuubi-san/ceb-tools
1575 # tried to use ceb2txt but it failed because of schema
1576 # slightly different than what it expected.
1577 cheogram-get-logs
() {
1578 #adb shell rm -r /storage/emulated/0/Download/Cheogram/Backup
1579 read -r -p "do cheogram backup on phone, do not enable extra cheogram data. press any key when done"
1582 adb pull
/storage
/emulated
/0/Download
/Cheogram
/Backup
1583 sqlite3 b
</a
/opt
/ceb-tools
/schema.sql
1584 echo "note: the next step took 39 seconds last time i measured"
1585 # expected failure: Error: near line 1: in prepare, table accounts has no column named pinned_mechanism (1)
1586 # the sql needs an update
1587 /a
/opt
/ceb-tools
/ceb2sqlgz Backup
/iank@fsf.org.ceb
<pas | gunzip | sqlite3 b ||
:
1591 # usage: cheologs [DAYS_LIMIT]
1592 # default days is 100
1598 datetime(substr(timeSent,0,11), 'unixepoch'),
1599 replace(replace(counterpart,'@fsf.org',''),
1600 '@conference.fsf.org',''),
1603 where timeSent > $(( (EPOCHSECONDS - days * 60 * 60 * 24) * 1000 ))
1605 sqlite3
/p
/cheogram
/b
".mode tabs" "$q" |
less
1611 # timezone compared to utc. note: this takes the current offset, so if daylight savings change
1612 # happened in the looking back period, this won't account for it.
1613 zone_offset
=$
(( $
( date +%z |
sed 's/[^1-9-]*//g' ) * 60 * 60))
1614 case $zone_offset in
1616 *) zone_offset
="+ $zone_offset"
1618 echo zone_offset
=$zone_offset
1621 datetime(substr(timeSent,0,11) $zone_offset, 'unixepoch'),
1624 where timeSent > $(( (EPOCHSECONDS - days * 60 * 60 * 24) * 1000 ))
1625 and counterpart = 'office@conference.fsf.org/iank'
1627 sqlite3
/p
/cheogram
/b
".mode tabs" "$q" |
sed 's/ /./' |
less
1630 # version of jdo for my non-root user
1632 # comparison of alternative logging methods:
1634 # systemd-run command (what this function does)
1636 # If there is a user prompt, the program will detect that it is not
1637 # connected to a terminal and act in a non-interactive way, skipping
1638 # the prompt. This has the benefit that you know exactly how the
1639 # program will act if you want to move it into a service that runs
1642 # If run with sudo and command is a shell script which does a sleep,
1643 # it can (sometimes?) output some extra whitespace in front of
1644 # messages, more for each subsequent message. This can be avoided by
1645 # becoming root first.
1647 # It logs the command's pid and exit code, which is nice.
1650 ### command |& ts | tee file.log
1652 # If there is a user prompt, like "read -p prompt var", it will hang
1653 # without outputting the prompt.
1655 # I've had a few times where ts had an error and I wasn't totally sure
1656 # if it was really the command or ts having the problem.
1658 # Sometimes some output will get hidden until you hit enter.
1661 ### command |& pee cat logger
1663 # This seems to work. I need to test more.
1666 ### command |& logger -s
1668 # User prompts get confusingly prefixed to earlier output, and all log
1669 # entries get prefixed with annoying priority level.
1674 # Had a few problems. One major one is that it exited in the middle of
1675 # a command on systemctl daemon-reload
1677 # Related commands which can log a whole session: script, sudo, screen
1678 local cmd cmd_name jr_pid ret
1683 if [[ $cmd != /* ]]; then
1684 cmd
=$
(type -P "$cmd")
1687 journalctl
-qn2 -f -u "$cmd_name" &
1688 # Trial and error of time needed to avoid missing initial lines.
1689 # .5 was not reliable. 1 was not reliable. 2 was not reliable
1692 # note, we could have a version that does system --user, but if for example
1693 # it does sudo ssh, that will leave a process around that we can't kill
1694 # and it will leave the unit hanging around in a failed state needing manual
1695 # killing of the process.
1696 s systemd-run
--uid "$(id -u)" --gid "$(id -g)" \
1697 -E SSH_AUTH_SOCK
=/run
/openssh_agent \
1698 --unit "$cmd_name" --wait --collect "$cmd" "$@" || ret
=$?
1699 # The sleep lets the journal output its last line
1700 # before the prompt comes up.
1702 kill $jr_pid &>/dev
/null ||
:
1705 # this avoids any err-catch
1706 (( ret
== 0 )) ||
return $ret
1709 # service run, and watch the output
1714 journalctl
-qn2 -f -u $unit &
1715 systemctl start
$unit
1717 kill $jr_pid &>/dev
/null ||
:
1722 sm
() { # switch mail host
1726 keyhash
=$
(s ssh-keygen
-lf /root
/.ssh
/home |
awk '{print $2}')
1727 tmp
=$
(s ssh-add
-l |
awk '$2 == "'$keyhash'"' ||
:)
1728 if [[ ! $tmp ]]; then
1729 s ssh-add
/root
/.ssh
/home
1731 s jdo switch-mail-host
"$@"
1734 sh2
() { # switch host2
1738 keyhash
=$
(s ssh-keygen
-lf /root
/.ssh
/home |
awk '{print $2}')
1739 tmp
=$
(s ssh-add
-l |
awk '$2 == "'$keyhash'"')
1740 if [[ ! $tmp ]]; then
1741 s ssh-add
/root
/.ssh
/home
1744 s jdo switch-host2
"$@"
1748 # shellcheck disable=SC2120
1750 # note, i had --delete-excluded, but that deletes all files in --exclude-from on
1751 # the remote site, which doesn't make sense, so not sure why i had it.
1753 # excluding emacs for now
1754 #p=(/a/opt/{emacs-debian11{,-nox},mu,emacs} /a/bin /a/exe /a/h /a/c /p/c/machine_specific/vps{,.hosts})
1755 p
=(/a
/bin
/a
/exe
/a
/h
/a
/c
/p
/c
/machine_specific
/vps
{,.hosts
} /c
/roles
/prom_export
/files
/simple
/usr
/local
/bin
/fsf-install-node-exporter
/a
/opt
/fpaste
)
1756 a
="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
1758 for h
in li je bk
; do
1759 m s rsync
"$@" $a ${p[@]} /p
/c
/machine_specific
/$h root@
$h.b8.nz
:/
1760 ## only li is debian11
1761 #p[0]=/a/opt/emacs-trisuqel10
1762 #p[1]=/a/opt/emacs-trisquel10-nox
1764 m s rsync
"$@" -ahviSAXPH root@li.b8.nz
:/a
/h
/proposed-comments
/ /a
/h
/proposed-comments || ret
=$?
1767 bkpush
() { # no emacs. for running faster.
1768 p
=(/a
/bin
/a
/exe
/a
/h
/a
/c
/p
/c
/machine_specific
/vps
{,.hosts
} /c
/roles
/prom_export
/files
/simple
/usr
/local
/bin
/fsf-install-node-exporter
)
1769 a
="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
1771 m rsync
"$@" $a ${p[@]} /p
/c
/machine_specific
/bk root@bk.b8.nz
:/ || ret
=$?
1774 jepush
() { # no emacs. for running faster.
1775 p
=(/a
/bin
/a
/exe
/a
/h
/a
/c
/p
/c
/machine_specific
/vps
{,.hosts
} /c
/roles
/prom_export
/files
/simple
/usr
/local
/bin
/fsf-install-node-exporter
)
1776 a
="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
1778 m rsync
"$@" $a ${p[@]} /p
/c
/machine_specific
/je root@je.b8.nz
:/ || ret
=$?
1783 dsign iankelling.org expertpathologyreview.com zroe.org amnimal.ninja
1786 m
ssh $h.b8.nz dnsup
1792 m
ssh $h.b8.nz dnsb8
1801 local f
=/var
/lib
/bind
/db.b8.nz
1803 # jbk is like a temp file. dunno if removing it helps
1806 while pgrep
'^named$' &>/dev
/null
; do
1809 if (( i
> 100 )); then
1810 echo "dnsb8: error: timeout waiting for named to exit"
1814 m sudo
rm -fv $f.jnl
$f.signed.jnl
$f.jbk
1815 m sudo
install -m 644 -o bind -g bind /p
/c
/machine_specific
/vps
/bind-initial
/db.b8.nz
$f
1819 # keys generated like this
1820 # because of https://ftp.isc.org/isc/dnssec-guide/dnssec-guide.pdf
1821 # https://blog.apnic.net/2019/05/23/how-to-deploying-dnssec-with-bind-and-ubuntu-server/
1823 # key length is longer than that guide because
1824 # we are using those at fsf and when old key lengths
1825 # become insecure, I want some extra time to update.
1826 # dnsecgen (in brc2)
1829 dnssec-keygen
-a RSASHA256
-b 2048 $zone
1830 dnssec-keygen
-f KSK
-a RSASHA256
-b 4096 $zone
1831 for f
in K
"$zone".
*.key
; do
1832 # eg Kb8.nz.+008+47995.key tag=47995
1833 # in dnsimple, you add the long string from this.
1834 # in gandi, you add the long string from the .key file,
1835 # then see that the digest matches the ds.
1836 echo "tag is the number after DS"
1837 dnssec-dsfromkey
-a SHA-256
$f
1839 # For b8.nz, we let bind read the keys and sign, and
1840 # right now they have root ownership, so let them
1842 chmod g
+r .
/*.private
1845 # create .signed file
1846 # note: full paths probably not needed.
1849 local zone
=${arg#db.}
1850 local dir
=/p
/c
/machine_specific
/vps
/filesystem
/var
/lib
/bind
1851 dnssec-signzone
-S -e +31536000 -o $zone -K $dir -d $dir $dir/db.
$zone
1855 # set day start for use in other programs.
1856 # expected to do be in a format like 830, or 800 or 1300.
1859 echo $1 >/b
/data
/daystart
1861 cat /b
/data
/daystart
1865 #### begin bitcoin related things
1867 local f
=/etc
/bitcoin
/bitcoin.conf
1868 # importprivkey will timeout if using the default of 15 mins.
1869 # upped it to 1 hour.
1870 bitcoin-cli
-rpcclienttimeout=60000 -"$(s grep rpcuser= $f)" -"$(s grep rpcpassword= $f)" "$@"
1872 btcusd
() { # $1 btc in usd
1874 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
1875 printf "$%s\n" "$price"
1877 printf "$%.2f\n" "$(echo "scale
=4; $price * $1"| bc -l)"
1880 usdbtc
() { # $1 usd in btc
1882 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
1883 printf "$%s\n" "$price"
1885 # 100 mil satoshi / btc. 8 digits after the 1.
1886 printf "%.8f btc\n" "$(echo "scale
=10; $1 / $price "| bc -l)"
1889 satoshi
() { # $1 satoshi in usd
1891 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
1892 price
=$
(echo "scale=10; $price * 0.00000001"|
bc -l)
1893 printf "$%f\n" "$price"
1895 printf "$%.2f\n" "$(echo "scale
=10; $price * $1"| bc -l)"
1899 # Bitcoin holds open the wallet file. this causes problems for a
1900 # secondary computer running bitcoin and receiving a backup (as of
1901 # 2023). However, in 2024-02, I ran a backup where a receiving machine
1902 # had the wallet enabled and there was no error, so I don't know if this
1903 # is still an issue or likely it is an inconsistent behavior.
1905 # As a workaround, this function is for enabling the wallet when I want
1906 # to use it and leave it disabled otherwise.
1911 if [[ ! $
(readlink
-f /var
/lib
/bitcoind
/wallets
) == /q
/wallets
]]; then
1912 if systemctl
--quiet is-active bitcoind
; then
1913 if [[ -e /tmp
/no-bitcoinon
]]; then
1916 if [[ $EUID == 0 ]]; then
1917 m
install -T -o iank
-g iank
/dev
/null
/tmp
/no-bitcoinon
1919 m
touch /tmp
/no-bitcoinon
1925 m s
ln -s /q
/wallets
/var
/lib
/bitcoind
1926 sudo chown
-h bitcoin
:bitcoin
/var
/lib
/bitcoind
/wallets
1928 m ser start bitcoind
1930 m
rm /tmp
/no-bitcoinon
1939 if [[ $
(readlink
-f /var
/lib
/bitcoind
/wallets
) == /q
/wallets
]]; then
1940 if systemctl
--quiet is-active bitcoind
; then
1941 if [[ -e /tmp
/no-bitcoinon
]]; then
1944 if [[ $EUID == 0 ]]; then
1945 m
install -T -o iank
-g iank
/dev
/null
/tmp
/no-bitcoinon
1947 m
touch /tmp
/no-bitcoinon
1953 echo note
: bitcoind not active
1955 m
rm /var
/lib
/bitcoind
/wallets
1957 # note, starting bitcoin always fails, but it actually
1958 # succeeds. But this is strangely not consistent.
1959 m ser start bitcoind
1961 m
rm /tmp
/no-bitcoinon
1966 #### end bitcoin related things
1970 cbfstool
() { /a
/opt
/coreboot
/build
/cbfstool
"$@"; }
1976 cp /a
/bin
/data
/COPYING
"$@"
1978 cp /a
/bin
/data
/COPYING .
1985 cp /a
/bin
/data
/LICENSE
"$@"
1987 cp /a
/bin
/data
/LICENSE .
1994 # First paragraph is to avoid people being confused about why a
1995 # file is apache licensed.
1997 # I, Ian Kelling, follow the GNU license recommendations at
1998 # https://www.gnu.org/licenses/license-recommendations.en.html. They
1999 # recommend that small programs, < 300 lines, be licensed under the
2000 # Apache License 2.0. This file contains or is part of one or more small
2001 # programs. If a small program grows beyond 300 lines, I plan to switch
2002 # its license to GPL.
2004 # Copyright 2024 Ian Kelling
2006 # Licensed under the Apache License, Version 2.0 (the "License");
2007 # you may not use this file except in compliance with the License.
2008 # You may obtain a copy of the License at
2010 # http://www.apache.org/licenses/LICENSE-2.0
2012 # Unless required by applicable law or agreed to in writing, software
2013 # distributed under the License is distributed on an "AS IS" BASIS,
2014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2015 # See the License for the specific language governing permissions and
2016 # limitations under the License.
2022 # apply apache to git tracked bash files + README, except files with A?GPL3 header.
2023 apache-apply-repo
() {
2024 for f
in $
(git ls-files
); do
2025 [[ -L $f ||
! -f $f ]] && continue
2026 if [[ $f != README
]]; then
2027 if ! grep -n '^#!/bin/bash' $f |
grep ^
1: &>/dev
/null
; then continue; fi
2028 if head -n 10 $f |
grep 'it under the terms of the GNU General Public License as published by' &>/dev
/null
; then continue; fi
2036 if head -n1 "$file"|
grep -E '^#!/bin/bash\b' &>/dev
/null
; then
2050 # strip out the apache license from a file.
2052 # shellcheck disable=SC2044 # meh
2053 for f
in $
(find .
-type f
-maxdepth 1); do if head -n1 "$f"|
grep -E '^#!/bin/bash\b' &>/dev
/null
; then { head -n 20 $f |
tac |
sed '/^# limitations under the License.$/,/^# Copyright.*Ian Kelling$/d' |
tac; tail -n+21 $f; } |sponge
$f; fi ; done
2057 if type -p chromium
&>/dev
/null
; then
2061 cmd
="schroot -c bullseye chromium"
2062 CHROMIUM_FLAGS
='--enable-remote-extensions' $cmd & r
2068 # pipe to this, or just type like a shell
2071 tee >(ssh frodo.b8.nz
) >(ssh x2
) >(ssh tp.b8.nz
) >(ssh kw
) >(ssh tp.b8.nz
)
2075 for host in x2 kw tp.b8.nz x3.b8.nz frodo.b8.nz
; do
2081 debian_pick_mirror
() {
2082 # netselect-apt finds a fast mirror.
2083 # but we need to replace the mirrors ourselves,
2084 # because it doesnt do that. best it can do is
2085 # output a basic sources file
2086 # here we get the server it found, get the main server we use
2087 # then substitute all instances of one for the other in the sources file
2088 # and backup original to /etc/apt/sources.list-original.
2089 # this is idempotent. the only way to identify debian sources is to
2090 # note the original server, so we put it in a comment so we can
2091 # identify it later.
2093 file=$
(mktemp
-d)/f
# safe way to get file name without creating one
2094 sudo netselect-apt
-o "$file" ||
return 1
2095 url
=$
(grep ^
\\w
$file |
head -n1 |
awk '{print $2}')
2096 sudo
cp -f /etc
/apt
/sources.list
/etc
/apt
/sources.list-original
2097 sudo
sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc
/apt
/sources.list
2101 digdiff @ns
{1,2}.iankelling.org
"$@"
2111 /b
/ds
/distro-begin |
& ts ||
return $?
2112 /b
/ds
/distro-end |
& ts ||
return $?
2118 /b
/ds
/distro-begin |
& ts ||
return $?
2124 /b
/ds
/distro-end |
& ts ||
return $?
2137 envload
() { # load environment from a previous: export > file
2138 local file=${1:-$HOME/.${USER}_env}
2139 eval "$(export | sed 's/^declare -x/export -n/')"
2140 while IFS
= read -r line
; do
2141 # declare -x makes variables local to a function
2142 eval ${line/#declare -x/export}
2146 failfunc
() { asdf a b c
; }
2147 failfunc2
() { failfunc d e f
; }
2149 # one that comes with distros is too old for newer devices
2151 /a
/opt
/android-platform-tools
/fastboot
"$@";
2154 kdecd
() { /usr
/lib
/x86_64-linux-gnu
/libexec
/kdeconnectd
; }
2157 cat /sys
/class
/power_supply
/BAT
0/capacity
2160 # List of apps to install/update
2161 # Create from existing manually installed apps by doing
2163 # fdroidcl search -i, then manually removing
2164 # automatically installed/preinstalled apps
2167 # # my attempt at recovering from boot loop:
2168 # # in that case, boot to recovery (volume up, home button, power, let go of power after samsun logo)
2170 # mount /dev/block/mmcblk0p12 /data
2172 # find -iname '*appname*'
2174 # usually good enough to just rm -rf /data/app/APPNAME
2177 # # causes replicant to crash
2178 # org.quantumbadger.redreader
2179 # org.kde.kdeconnect_tp
2181 # not broke, but wont work without gps
2182 #com.zoffcc.applications.zanavi
2183 # not broke, but not using atm
2184 #com.nutomic.syncthingandroid
2185 # # doesn\'t work on replicant
2186 #net.sourceforge.opencamera
2189 net.mullvad.mullvadvpn
2191 io.github.subhamtyagi.lastlauncher
2193 com.biglybt.android.client
2194 de.marmaro.krt.ffupdater
2195 me.ccrama.redditslide
2196 org.fedorahosted.freeotp
2198 com.alaskalinuxuser.justnotes
2199 com.artifex.mupdf.viewer.app
2200 com.danielkim.soundrecorder
2203 com.jmstudios.redmoon
2205 org.kde.kdeconnect_tp
2208 cz.martykan.forecastie
2209 de.danoeh.antennapod
2211 de.marmaro.krt.ffupdater
2212 eu.siacs.conversations
2214 im.vector.alpha
# riot
2215 info.papdt.blackblub
2216 me.tripsit.tripmobile
2218 net.minetest.minetest
2223 org.smssecure.smssecure
2225 sh.
ftp.rocketninelabs.meditationassistant.opensource
2227 # https://forum.xda-developers.com/android/software-hacking/wip-selinux-capable-superuser-t3216394
2232 local -A installed updated
2234 # tried putting this in go buildscript cronjob,
2235 # but it failed with undefined: os.UserCacheDir. I expect its due to
2236 # an environment variable missing, but its easier just to stick it here.
2237 m go get
-u mvdan.cc
/fdroidcl ||
return 1
2239 if fdroidcl search
-u |
grep ^org.fdroid.fdroid
; then
2240 fdroidcl
install org.fdroid.fdroid
2244 for p
in $
(fdroidcl search
-i|
grep -o "^\S\+"); do
2247 for p
in $
(fdroidcl search
-u|
grep -o "^\S\+"); do
2250 for p
in ${fdroid_pkgs[@]}; do
2251 if ! ${installed[$p]:-false}; then
2252 m fdroidcl
install $p
2253 # sleeps are just me being paranoid since replicant has a history of crashing when certain apps are installed
2257 for p
in ${!installed[@]}; do
2258 if ! ${updated[$p]:-true}; then
2259 m fdroidcl
install $p
2265 firefox-default-profile
() {
2266 local key value section
2270 file=/p
/c
/subdir_files
/.mozilla
/firefox
/profiles.ini
2271 sed -ri "/^ *$key/d" "$file"
2272 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*${key}[[:space:]=]/d};/ *\[$section\]/a $key=$value" "$file"
2274 fdhome
() { #firefox default home profile
2275 firefox-default-profile Profile0
2279 firefox-default-profile Profile4
2283 if type -P firefox
&>/dev
/null
; then
2291 firefox
-P alt
"$@" >/dev
/null
2>&1
2297 local dname
="${PWD##*/}"
2298 local m
="/a/tmp/$dname-missing"
2299 local d
="/a/tmp/$dname-diff"
2300 [[ -e $d ]] && rm "$d"
2301 [[ -e $m ]] && rm "$m"
2304 while read -r line
; do
2305 fsfile
="$1${line#.}"
2306 if [[ -e "$fsfile" ]]; then
2307 md5diff
"$line" "$fsfile" && tee -a "/a/tmp/$dname-diff" <<< "$fsfile $line"
2310 echo "$line" >> "$m"
2311 msize
=$
((msize
+ 1))
2313 done < <(find .
-type f
)
2316 (( msize
<= 100 )) && cat $m
2321 # expected output, with different tmp dirs
2322 # /tmp/tmp.HDPbwMqdC9/c/d ./c/d
2323 # /a/tmp/tmp.qLDkYxBYPM-missing
2334 echo different
> $x/c
/d
2340 # test whether missing files were renamed, generally for use with fsdiff
2341 # $1 = fsdiff output file, $2 = directory to compare to. pwd = fsdiff dir
2342 # echos non-renamed files
2343 local x line found renamed
2346 { sums
+=( "$(md5sum < "$x")" ) ; } 2>/dev
/null
2348 while read -r line
; do
2349 { missing_sum
=$
(md5sum < "$line") ; } 2>/dev
/null
2351 for x
in "${sums[@]}"; do
2352 if [[ $missing_sum == "$x" ]]; then
2357 $renamed ||
echo "$line"
2363 # F = fullscren, z = random, Z = auto zoom
2364 command feh
--auto-rotate -FzZ "$@"
2370 firefox
-P default
"$@" >/dev
/null
2>&1
2374 git config user.email ian@iankelling.org
2377 # at least in flidas, things rely on gpg being gpg1
2379 if type -P gpg2
&>/dev
/null
; then
2387 local email
=iank@fsf.org
2388 git send-email
--notes "--envelope-sender=<$email>" \
2389 --suppress-cc=self
"$@"
2392 gup
() { /a
/f
/gnulib
/build-aux
/gnupload
"$@"; }
2394 dejagnu
() { /a
/opt
/dejagnu
/dejagnu
"$@"; }
2396 # do git status on published repos.
2400 cd "$(readlink -f $x)"/..
2401 status
=$
(i status
-s) ||
pwd
2402 if [[ $status ]]; then
2405 printf "%s\n" "$status"
2415 cd "$(readlink -f $x)"/..
2423 # note: database location is specified in ~/.timetrap.yml, currently /p/.timetrap.db
2425 local day i days_back
2427 for (( i
=days_back
; i
>=0; i--
)); do
2428 day
=$
( date +%F
-d @$
((EPOCHSECONDS
- 86400*i
)) )
2429 date "+%a %b %d" -d @$
((EPOCHSECONDS
- 86400*i
)) |
tr '\n' ' '
2430 /a
/opt
/timetrap
/bin
/t d
-ftotal -s $day -e $day all
-m '^w|lunch$'
2433 to
() { t out
-a "$@"; }
2434 ti
() { t
in -a "$@"; }
2440 in_secs
="$(date -d "${*//[_.]/ }" +%s)"
2441 m t out
-a "$(date +%F.%T -d @$(( in_secs + 60*45 )) )"
2446 # help me focus. opens 2 windows.
2448 /p
/c
/proc
/focus
/linux-amd64
/focus
&
2454 # Display a list of the active window title
2455 # i've been on with 10 second samples going back
2456 # 5 minutes. If I've been on one window for 10 seconds
2457 # or longer, then display the second count.
2459 # Press any key to exit.
2462 killall arbtt-capture
&>/dev
/null ||
:
2463 rm -f ~
/.arbtt
/capture.log
2464 arbtt-capture
--sample-rate=10 &
2468 # i first thought to sleep and capture ctrl-c, but it seems we can't
2469 # capture control-c, unless maybe we implement the commands in a
2470 # separate script or maybe add err-cleanup to err. Anyways, this
2471 # method is superior because any single char exits.
2472 read -rsN1 -t 5 char || ret
=$?
2473 if (( ret
== 142 )) ||
[[ ! $char ]]; then
2475 #e ret=$ret char=$char
2478 killall arbtt-capture ||
:
2486 local i j l sec blanks line
2487 local -a arbtt_lines
2488 if [[ ! -e ~
/.arbtt
/capture.log
]]; then
2491 blanks
=$
(( LINES
- 34 ))
2492 for (( i
=0; i
< blanks
; i
++ )); do
2499 # https://stackoverflow.com/questions/56486272/how-to-concat-multiple-fields-to-same-line-with-jq
2500 arbtt_lines
=$
(arbtt-dump
-l 30 -t json | \
2501 jq
-r '.[] | [ ( .inactive / 1000 | floor ) , ( .windows[] | select (.active == true) |.title) ] | @tsv' |
tac)
2502 for line
in "${arbtt_lines[@]}"; do
2503 read -r sec l
<<<"$line"
2504 if (( j
>= LINES
)); then
2507 if (( i
% 6 == 0 && i
>= 2 )); then
2509 echo "## $(( i / 6 + 1 )) ##"
2511 if (( sec
> 10 )); then
2512 printf "%3d %s\n" $sec "$l" |
sed -r "s/^(.{$COLUMNS}).*/\1/"
2514 printf " %s\n" "$l" |
sed -r "s/^(.{$COLUMNS}).*/\1/"
2519 while (( j
< 34 && j
< LINES
)); do
2527 # from the log, show only the currently active window, and the number of
2528 # seconds of input inactivity.
2529 arbtt-dump
"$@" |
grep -v '( )\|Current Desktop' |
sed -rn '/^[^ ]/{N;s/^(.{21})([0-9]*)[0-9]{3}m.*\(\*/\1\2/;s/^(.{21})[0-9]*.*\(\*/\1/;s/\n//;p}' ; }
2532 /a
/opt
/idea-IC-163.7743
.44/bin
/idea.sh
"$@" & r
2536 d
=/var
/lib
/znc
/moddata
/log
/iank
/
2537 for n
in freenode libera
; do
2540 for x
in "#$1/"*; do
2545 if [[ -e $tmp ]]; then
2549 sed \"s
/^.
/${base%log}/\" ${files[@]}|
sort -n
2555 sl root@iankelling.org ilogs-local
"$@"
2562 d
=/var
/lib
/znc
/moddata
/log
/iank
/
2563 for n
in freenode libera
; do
2564 if [[ ! -d $d$n/"$chan" ]]; then
2570 # *** are parts and joins and such, and they make reading hard.
2571 # I probably will want to see them sometimes, just have to
2573 echo $x; sed "s/^./${x%log}/;/\*\*\*/d" $x; hr
;
2580 chan
="${1:-#fsfsys}"
2581 # use * instead of -r since that does sorted order
2582 sl root@li.b8.nz ilog-local
"$chan" > $tmpf
2588 if type gio
&> /dev
/null
; then
2590 elif type gvfs-open
&> /dev
/null
; then
2595 # another alternative is run-mailcap
2600 # grep -Evi -e "^(\S+\s+){4}(sudo|sshd|cron)\[\S*:" \
2601 # -e "^(\S+\s+){4}systemd\[\S*: (starting|started) (btrfsmaintstop|dynamicipupdate|spamd dns bug fix cronjob|rss2email)\.*$"
2604 # journalctl -n 10000 -f "$@" | jfilter
2606 # jr() { journalctl "$@" | jfilter | less ; }
2607 # jrf() { journalctl -n 200 -f "$@" | jfilter; }
2610 ## old version for model01. i need to get that firmware working again.
2611 # kff() { # keyboardio firmware flash. you must hold down the tilde key
2612 # pushd /a/opt/Model01-Firmware
2613 # # if we didn't want this yes hack, then remove "shell read" from
2614 # # /a/opt/Kaleidoscope/etc/makefiles/sketch.mk
2615 # yes $'\n' | VERBOSE=1 make flash
2621 pushd /a
/opt
/Kaleidoscope
/examples
/Devices
/Keyboardio
/Model100
2627 local umask_orig name
2628 if (( $# != 1 )); then
2629 e expected
1 arg
>&2
2635 wg genkey |
tee $name-priv.key | wg pubkey
> $name-pub.key
2642 ssh iank@li.b8.nz conflink
2647 # if you change a host's ip, then run
2650 host-info-update
() {
2652 local -A vpn_ips host_ips host_macs nonvpn_ips all_ips
2653 local -a root_hosts nonroot_hosts
2655 # the hosts with no mac
2656 root_hosts
=( bk je li b8.nz
)
2657 for h
in ${root_hosts[@]}; do
2658 root_hosts
+=(${h}ex
)
2662 while read -r ip
host mac opts
; do
2663 if [[ $ip == *#* || ! $host ]]; then continue; fi
2668 for opt
in $opts; do
2683 nonvpn_ips
[$host]=$ip
2686 # note: the reason we have b8.nz suffix here but not for non_root
2687 # hosts is that it is for the User part, the IdentityFile part is
2688 # redundant to *.b8.nz. Also note ${host}i, we only setup those for vpn hosts, but there is no harm in overspecifying here.
2689 root_hosts
+=($host ${host}i
$host.b8.nz
${host}i.b8.nz
)
2690 root_hosts_a
[$host]=t
# a for associative array
2692 nonroot_hosts
+=($host ${host}i
)
2696 host_macs
[$host]=$mac
2699 done </p
/c
/host-info
2703 Host ${nonroot_hosts[@]}
2705 IdentityFile ~/.ssh/home
2707 Host ${root_hosts[@]}
2708 IdentityFile ~/.ssh/home
2711 for host in ${!vpn_ips[@]}; do
2712 ipsuf
=${vpn_ips[$host]}
2716 Port $((2200 + ipsuf))
2721 # convenience of one auth key entry
2722 for host in ${!all_ips[@]}; do
2724 Host $host ${host}i $host.b8.nz ${host}i.b8.nz
2725 HostKeyAlias $host.b8.nz
2728 } | cedit
/p
/c
/subdir_files
/.ssh
/config ||
[[ $?
== 1 ]]
2731 # hack to please emacs parser
2732 here_begin
="cat <<EOF"
2734 for host in ${!vpn_ips[@]}; do
2735 ipsuf=${vpn_ips[$host]}
2736 i_port=$(( 2200 + ipsuf ))
2739 option name ssh$host
2741 option src_dport $i_port
2743 option dest_ip \$l.$ipsuf
2747 option target ACCEPT
2748 option dest_port $i_port
2752 } >/p/c/cmc-firewall-data
2755 local host ipsuf f files
2757 # shellcheck disable=SC2016 # shellcheck doesnt know this is sed
2758 sedi '/edits below here are made automatically/,$d' /p/c/machine_specific/li/filesystem/etc/wireguard/wgmail.conf
2759 for host in ${!vpn_ips[@]}; do
2760 if [[ ${root_hosts_a[$host]} ]]; then
2761 # root machines dont actually need vpn, but
2762 # the classification still helps with other
2766 ipsuf=${vpn_ips[$host]}
2768 u /b/ds/machine_specific/li/filesystem/etc/openvpn/client-config-hole/$host <<EOF
2769 ifconfig-push 10.5.5.${vpn_ips[$host]} 255.255.255.0
2771 u /a/bin/ds/machine_specific/$host/filesystem/etc/systemd/system/openvpn-client-tr@.service <<EOF
2773 Description=OpenVPN tunnel for %I
2774 After=syslog.target network-online.target
2775 Wants=network-online.target
2776 Documentation=man:openvpn(8)
2777 Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
2778 Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
2779 Requires=iptables.service
2783 RuntimeDirectory=openvpn-client
2784 RuntimeDirectoryMode=0710
2785 WorkingDirectory=/etc/openvpn/client
2786 ExecStart=/usr/sbin/openvpn --suppress-timestamps --nobind --config /etc/openvpn/client/%i.conf
2787 # todo, try reenabling this from the default openvpn,
2788 # it was disabled so we could do bind mounts as a command,
2789 # but now systemd handles it
2790 #CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE
2792 # DeviceAllow=/dev/null rw
2793 # DeviceAllow=/dev/net/tun rw
2795 # we use .1 to make this be on a different network than kd, so that we can
2796 # talk to transmission on kd from remote host, and still use this
2798 ExecStartPre=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.174.$ipsuf start %i
2799 ExecStartPre=/sbin/iptables-restore /a/bin/distro-setup/transmission-firewall/netns.rules
2800 # allow wireguard network to connect
2801 ExecStartPre=/usr/sbin/ip r add 10.8.0.0/24 via 10.174.$ipsuf.1 dev veth1-client
2802 ExecStopPost=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns stop %i
2804 BindReadOnlyPaths=/etc/tr-resolv:/run/systemd/resolve:norbind /etc/basic-nsswitch:/etc/resolved-nsswitch:norbind
2807 WantedBy=multi-user.target
2813 for host in ${!host_ips[@]}; do
2814 ipsuf=${host_ips[$host]}
2815 # shellcheck disable=SC2016 # intentional
2816 echo 'local-data-ptr: "$l.'$ipsuf $host.b8.nz'"'
2823 for host in ${!host_macs[@]}; do
2824 ipsuf=${host_ips[$host]}
2825 echo "dhcp-host=${host_macs[$host]},set:$host,\$l.$ipsuf,$host"
2828 } | u /p/c/dnsmasq-data
2831 b8_ip=$(dig +short b8.nz @iankelling.org | tail -1)
2832 if [[ ! $b8_ip ]]; then
2833 echo "$0: error
: got empty b8.nz ip. returning
1"
2838 for host in ${!nonvpn_ips[@]}; do
2839 ipsuf=${nonvpn_ips[$host]}
2840 echo "$host A
10.2.0.
$ipsuf"
2842 for host in ${!vpn_ips[@]}; do
2843 ipsuf=${vpn_ips[$host]}
2845 $host A 10.2.0.$ipsuf
2846 ${host}wg A 10.8.0.$ipsuf
2847 ${host}vp A 10.5.5.$ipsuf
2848 ${host}tr A 10.174.$ipsuf.2
2851 } | cedit vpn-ips-update /p/c/machine_specific/vps/bind-initial/db.b8.nz ||:
2854 echo checking for stray files:
2857 while read -r dir path; do
2863 for f in "${files[@]}"; do
2865 if [[ ! ${vpn_ips[$host]} ]]; then
2870 /a/bin/ds/machine_specific filesystem/etc/systemd/system/openvpn-client-tr@.service
2871 /p/c/machine_specific filesystem/etc/wireguard/wghole.conf
2874 files=( /b/ds/machine_specific/li/filesystem/etc/openvpn/client-config-hole/* )
2875 for f in "${files[@]}"; do
2877 if [[ ! ${vpn_ips[$host]} ]]; then
2879 e ssh root@li.b8.nz rm -f $f
2885 printf "%s
" "Host
* "
2886 sed -n '/^Host /h;/^IdentityFile .*\/home/{g;s/^Host//;s/ / !/gp}' ~/.ssh/config | tr '\n' ' '
2887 echo "IdentityFile ~
/.ssh
/work
"
2888 } | cedit work-identity ~/.ssh/config || [[ $? == 1 ]]
2893 # usage host ipsuf [extrahost]
2895 # If the keys already exist and you want new ones, remove them:
2896 # rm /p/c/machine_specific/$host/filesystem/etc/wireguard/hole-{priv,pub}.key
2898 # extrahost is a host/cidr that is allowed to go be routed through the
2901 if (( $# < 2 || $# > 3 )); then
2902 e expected 2-3 arg of hostname, ip suffix, and extrahost >&2
2905 local host ipsuf umask_orig vpn_allowed
2911 for vpn_host in ${!vpn_ips[@]}; do
2912 if [[ $vpn_host == "$host" ]]; then
2915 vpn_allowed+=",10.174.
${vpn_ips[$vpn_host]}.2/32"
2917 mkdir -p /p/c/machine_specific/$host/filesystem/etc/wireguard
2919 cd /p/c/machine_specific/$host/filesystem/etc/wireguard
2922 if [[ ! -s hole-priv.key || ! -s hole-pub.key ]]; then
2923 wg genkey | tee hole-priv.key | wg pubkey > hole-pub.key
2925 cat >wghole.conf <<EOF
2927 # contents hole-priv.key
2928 PrivateKey = $(cat hole-priv.key)
2930 Address = 10.8.0.$ipsuf/24
2931 # https://dev.to/tangramvision/what-they-don-t-tell-you-about-setting-up-a-wireguard-vpn-1h2g
2932 # ||: makes the systemd service not fail due to the failed command
2933 PostUp = ping -w10 -c1 10.8.0.1 ||:
2936 # li. called wgmail on that server
2937 PublicKey = CTFsje45qLAU44AbX71Vo+xFJ6rt7Cu6+vdMGyWjBjU=
2938 AllowedIPs = 10.8.0.0/24$vpn_allowed$extrahost
2939 Endpoint = 72.14.176.105:1194
2940 PersistentKeepalive = 25
2943 # old approach. systemd seems to work fine and cleaner.
2944 rm -f ../network/interfaces.d/wghole
2945 cedit -q $host /p/c/machine_specific/li/filesystem/etc/wireguard/wgmail.conf <<EOF || [[ $? == 1 ]]
2947 PublicKey = $(cat hole-pub.key)
2948 AllowedIPs = 10.8.0.$ipsuf/32,10.174.${vpn_ips[$host]}.2/32
2954 mns() { # mount namespace
2957 s mkdir -p /root/mount_namespaces
2958 if ! sudo mountpoint /root/mount_namespaces >/dev/null; then
2959 m sudo mount --bind /root/mount_namespaces /root/mount_namespaces
2961 m sudo mount --make-private /root/mount_namespaces
2962 if [[ ! -e /root/mount_namespaces/$ns ]]; then
2963 m sudo touch /root/mount_namespaces/$ns
2965 if ! sudo mountpoint /root/mount_namespaces/$ns >/dev/null; then
2966 m sudo unshare --propagation slave --mount=/root/mount_namespaces/$ns /bin/true
2968 m sudo -E /usr/bin/nsenter --mount=/root/mount_namespaces/$ns "$@
"
2971 mnsd() { # mount namespace + systemd namespace
2976 s mkdir -p /root/mount_namespaces
2977 if ! sudo mountpoint /root/mount_namespaces >/dev/null; then
2978 m sudo mount --bind /root/mount_namespaces /root/mount_namespaces
2980 m sudo mount --make-private /root/mount_namespaces
2981 if [[ ! -e /root/mount_namespaces/$ns ]]; then
2982 m sudo touch /root/mount_namespaces/$ns
2984 if ! sudo mountpoint /root/mount_namespaces/$ns >/dev/null; then
2985 m sudo unshare --propagation slave --mount=/root/mount_namespaces/$ns /bin/true
2988 pid=$(servicepid $unit)
2989 tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX)
2991 printf "%s
" "${@@Q}" >>$tmpf
2994 m sudo nsenter -t $pid -n --mount=/root/mount_namespaces/$ns sudo -u $USER -i bash -c ".
$tmpf & sleep 1; rm $tmpf"
3001 mns $ns sudo -u iank -E env "PATH
=$PATH" "$@
"
3007 if ! s ip netns list | grep -Fx nonet &>/dev/null; then
3008 s ip netns add nonet
3010 mns $ns --net=/var/run/netns/nonet /bin/bash
3017 if ! s ip netns list | grep -Fx nonet &>/dev/null; then
3018 s ip netns add nonet
3020 mns $ns --net=/var/run/netns/nonet sudo -E -u iank /bin/bash
3026 # l = the loopback device
3028 # get sudo pass cached right away
3029 if ! sudo -nv 2>/dev/null; then
3032 if [[ $1 == /* ]]; then
3035 if mns $base mountpoint -q /mnt/$base; then
3038 l=$(losetup -j $fs_file | sed -rn 's/^([^ ]+): .*/\1/p' | head -n1 ||:)
3040 l=$(sudo losetup -f)
3041 m sudo losetup $l $fs_file
3043 if ! sudo cryptsetup status /dev/mapper/$base &>/dev/null; then
3044 if ! m sudo cryptsetup luksOpen $l $base; then
3045 m sudo losetup -d $l
3049 m sudo mkdir -p /mnt/$base
3050 m mns $base mount /dev/mapper/$base /mnt/$base
3051 m mns $base chown $USER:$USER /mnt/$base
3055 if mns $base mountpoint /mnt/$base &>/dev/null; then
3056 m mns $base umount /mnt/$base
3058 if sudo cryptsetup status /dev/mapper/$base &>/dev/null; then
3059 if ! m sudo cryptsetup luksClose /dev/mapper/$base; then
3060 echo lom: failed cryptsetup luksClose /dev/mapper/$base
3064 l=$(losetup -l --noheadings | awk '$6 ~ /\/'$base'$/ {print $1}')
3066 m sudo losetup -d $l
3068 echo lom: warning: no loopback device found
3073 # mu personality. for original, just run mp. for 2, run mp 2.
3074 # this is partly duplicated in mail-setup
3078 if ! killall mu; then
3085 echo error: mu not dead
3090 set -- /m/mucache ~/.cache/mu /m/.mu ~/.config/mu
3095 if [[ -e $f && ! -L $f ]]; then
3098 m ln -sf -T $target $f
3104 local md dst ln_path src two
3108 -2) two=true; shift ;;
3120 for d in /m/md/$md /m/4e2/$md; do
3121 if [[ -d $d && ! -L $d ]]; then
3126 if [[ ! $src ]]; then
3127 echo "error
: could not
find $md" >&2
3131 m ln -sf -T $dst $ln_path
3141 ### begin copied from mdenable, but different d ###
3142 for d in /m/4e/$md /m/4e2/$md; do
3143 if [[ -d $d && ! -L $d ]]; then
3148 if [[ ! $src ]]; then
3149 echo "error
: could not
find $md" >&2
3152 ### end copy from mdenable ###
3154 if [[ -L $dst ]]; then m rm $dst; fi
3160 markdown "$1" >/tmp/mdtest.html
3161 firefox /tmp/mdtest.html
3164 mo() { xset dpms force off; } # monitor off
3167 # seems to be the best gpu decoding on my nvidia 670.
3168 # vlc gets similar or better framerate, but is much darker output on my test movie at least.
3173 echo 0f | sudo tee -a /sys/kernel/debug/dri/0/pstate
3176 # going back to the default slow clock, and slower fan:
3177 # echo 07 | sudo tee -a /sys/kernel/debug/dri/0/pstate
3178 if [[ $DISPLAY ]]; then
3179 mpv --vo=vdpau --hwdec=auto "$@
"
3181 # waylandvk seems to work the same
3182 mpv --gpu-context=wayland --hwdec=auto
3187 mpv --profile=d "$@
";
3190 mpv --profile=a "$@
";
3192 # mpv all media files in . or $1
3194 local -a extensions arg
3195 # get page source of https://en.wikipedia.org/w/index.php?title=Video_file_format&action=edit
3196 # into /a/x.log, then
3197 # grep '^| *\.' /a/x.log | sed 's/| *//;s/,//g'
3199 # note: to join them together for a regex, do:
3200 # old=; for e in ${extensions[@]/./}; do if [[ ! $old ]]; then old=$e; continue; fi; echo -n "$old|
"; old=$e; done; echo $e
3223 .mpg .mp2 .mpeg .mpe .mpv
3233 arg=("(" -iname "*${extensions[0]}")
3234 for (( i=1 ; i < ${#extensions[@]}; i++ )); do
3235 arg+=(-o -iname "*${extensions[i]}")
3240 #find $dir "${arg[@]}" -size +200k
3241 find $dir "${arg[@]}" -size +200k -exec mpv --profile=d '{}' +
3244 mpv --profile=s "$@
";
3252 d=( /var/lib/znc/moddata/log/iank/{freenode,libera} )
3253 # use * instead of -r since that does sorted order
3254 ssh root@iankelling.org "for f
in ${d[*]}; do cd \
$f/#$1; grep '\<iank.*' *; done" | cut --complement -c12-16
3260 d
=/var
/lib
/znc
/moddata
/log
/iank
/freenode
3261 ssh root@iankelling.org
"cd $d; find . -mtime -60 -type f -exec grep '\<iank.*' {} +" |
sed -r 's,^..([^/]*)/(.{11})(.{5})(.{8}).,\2\4 \1,' |
sort
3264 # The way pidgin logs with xmpp (maybe related to running cheogram too)
3265 # is that there are sometimes duplicates, and sometimes the a log file
3266 # is for a specific day yet logs messages for subsequent days, and the
3267 # only way to realize that is to notice that the timestamps rolled over
3268 # into a new day, you can't see it in isolation. So, basically, pidgin
3269 # logs are really annoying to read a grep of my messages to find the
3270 # date and time I said when I started and stopped working, so I'm trying
3271 # out a new client: profanity.
3273 c
/p
/c
/.purple
/logs
/jabber
/iank@fsf.org
/office@conference.fsf.org.chat
3274 for x
in *.html
; do html2text
-o ${x%.html}.txt
$x; done;
3275 # shellcheck disable=SC2016 # false positive on ${
3276 grep -A1 ') iank:' .
/*.txt \
3277 |
sed -r 's/^(.{10})[^ ]*\.txt:\(?([^ ]*)[[:space:]](..). iank:/\1_\2_\3/
3280 s/^[^ ]*\.txt:\((.{2}).(.{2}).(.{4}) (.{8}) (.{2})\)?/\3-\1-\2_\4_\5/' \
3281 |
sed -n 'x;1d;0~2{G;s/\n/ /;p};${x;p}'
3287 pushd /home
/iank
/.local
/share
/profanity
/chatlogs
/iank_at_fsf.org
/rooms
/office_at_conference.fsf.org
3289 logcount
=${#logs[@]}
3290 if (( logcount
> 15 )); then
3291 i
=$
(( logcount
- 15 ))
3295 # usually do this on monday, sometimes later
3296 if [[ $
(date +%A
) == Monday
]]; then
3297 min_date
=$
(date -d 'monday 2 weeks ago' +%s
)
3299 min_date
=$
(date -d 'monday 3 weeks ago' +%s
)
3301 for (( ; i
< logcount
; i
++ )); do
3303 d
=$
(date -d "$(head -n1 $log|awk '{print $1}')" +%s
)
3304 if (( d
< min_date
)); then
3307 if awk '$3 == "iank:"' $log |
sed -r 's/^(.{10}).(.{8})[^ ]+(.*)/\1_\2\3/' |
grep .
; then
3315 # Tail all recent prof logs. Copying from profanity has unwanted line breaks
3316 # especially for links.
3323 ssh b8.nz profr-local
3331 d0
="$(date +%Y_%m_%d).log"
3332 d1
="$(date -d '1 day ago' +%Y_%m_%d).log"
3334 files
=(/d
/p
/profanity
/chatlogs
/iank_at_fsf.org
/{*,rooms
/*}/{$d0,$d1})
3336 if (( ${#files[@]} > 0 )); then
3337 cat "${files[@]}" |
sort |
tail -n 40
3342 # Tail pms in the last day, for the case where we restart profanity and
3343 # didn't check for pms beforehand. Assume the most recent logs are on kd.
3344 # If that isn't the case, use prof-recent-local
3351 ssh b8.nz prof-recent-local
3355 prof-recent-local
() {
3356 local d dates
date files f
3357 # consider making the day count passed by parameter. note: this works: $(date -d '2 day ago' +%Y_%m_%d)
3358 dates
=("$(date +%Y_%m_%d)" "$(date -d '1 day ago' +%Y_%m_%d)" )
3359 for d
in /d
/p
/profanity
/chatlogs
/iank_at_fsf.org
/!(rooms
); do
3361 for date in ${dates[@]}; do
3363 if [[ -e $f ]]; then
3367 if (( ${#files[@]} >= 1 )); then
3368 cat ${files[@]} |
tail
3380 ssh b8.nz prof-recent-sort
3385 prof-recent-sort
() {
3386 local d dates
date files f
3387 # consider making the day count passed by parameter. note: this works: $(date -d '2 day ago' +%Y_%m_%d)
3388 dates
=("$(date +%Y_%m_%d)" "$(date -d '1 day ago' +%Y_%m_%d)" )
3390 for d
in /d
/p
/profanity
/chatlogs
/iank_at_fsf.org
/!(rooms
); do
3391 for date in ${dates[@]}; do
3393 if [[ -e $f ]]; then
3398 for f
in "${files[@]}"; do
3404 # usage: debvm DEBIAN_VERSION RAM_MB
3406 local ver ram fname src
3409 # * is because it might have -backports in the name. we only expect 1 expansion
3410 fnames
=( debian-
$ver-*nocloud-
"$(dpkg --print-architecture)".qcow2
)
3411 if (( ${#fnames[@]} >= 2 )); then
3412 echo "error: iank: unexpected multiple files"
3415 fname
="${fnames[0]}"
3416 src
=/a
/opt
/roms
/$fname
3417 if [[ ! -f $src ]]; then
3418 echo debvm
: not found
$src, download from eg
: https
://cloud.debian.org
/images
/cloud
/buster
/latest
/
3422 # note, in fai-revm we do this: not sure why, maybe because of br device
3423 # --graphics spice,listen=0.0.0.0
3424 m s virt-install
--osinfo debian11
--rng /dev
/urandom
-n deb
${ver}tmp
--import -r $ram --vcpus 2 --disk /t
/$fname --graphics spice
3425 # note: to ssh into this machine will require host key generation: ssh-keygen -A
3427 # random: for cvs2git on gnu www, use debian 10. I could use trisquel,
3428 # but happen to want to try out the debian cloud images. the upstream
3429 # requires python2 and hasn't really changed since the version in d10.
3431 # apt install cvs2git cvs
3432 # # 7G was not enough
3433 # mount -o mode=1777,nosuid,nodev,size=34G -t tmpfs tmpfs /tmp
3434 # cvs2git --encoding utf_8 --fallback-encoding ascii --dumpfile=dump www-rsync/www |& tee /tmp/l
3435 ## www-rsync is an rsynced copy of the cvsfrom savannah
3439 local time time_sec time_pretty days
3441 sqlite3
-separator ' ' /p
/c
/subdir_files
/.local
/share
/gajim
/logs.db
"select time, message from logs where contact_name = 'iank' and jid_id = 17;" |
while read -r time l
; do
3446 if ! time_pretty
=$
(date +%F.
%R
-d @
$time); then
3447 echo bad
time: $time
3450 echo $time_pretty "$l"
3451 time_sec
=${time%%.*}
3452 # only look at the last 18 days. generally just use this for timesheet.
3453 if (( time_sec
< EPOCHSECONDS
- 60 * 60 * 24 * days
)); then break; fi
3458 sqlite3
-separator ' ' /p
/c
/subdir_files
/.local
/share
/gajim
/logs.db
"select time, message from logs where contact_name = 'iank'" |
less
3462 sqlite3
-separator ' ' /p
/c
/subdir_files
/.local
/share
/gajim
/logs.db
"select time, message from logs" |
less
3467 e
"lspci -nnk|gr -iA2 net"
3468 lspci
-nnk|gr
-iA2 net
3470 e
"s lshw -C network"
3472 sudo lshw
-C network
3476 ser stop NetworkManager
3477 ser disable NetworkManager
3478 ser stop NetworkManager-wait-online.service
3479 ser disable NetworkManager-wait-online.service
3481 sudo resolvconf
-d NetworkManager
3487 ser start NetworkManager
3493 oathtool
--totp -b "$*" | xclip
-selection clipboard
3495 # run cmd and copy output
3497 "$@" |
& pee
"xclip -r -selection clipboard" cat
3500 # xorg copy. copy text piped into command
3502 xclip
-r -selection clipboard
3506 pee
"xclip -r -selection clipboard" cat
3510 # from http://askubuntu.com/questions/456021/remove-vocals-from-mp3-and-get-only-instrumentals
3511 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
3514 pfind
() { #find *$1* in $PATH
3515 [[ $# != 1 ]] && { echo requires
1 argument
; return 1; }
3517 IFS
=: pathArray
=($PATH); unset IFS
3518 find "${pathArray[@]}" -iname "*$1*"
3522 # trash-restore lists everything that has been trashed at or below CWD
3523 # This picks out files just in CWD, not subdirectories,
3524 # which also match grep $1, usually use $1 for a time string
3525 # which you get from running restore-trash once first
3528 # last condition is to not ask again for ones we skipped
3529 while name
="$( echo | restore-trash | gr "$PWD/[^
/]\
+$
" | gr "$1" )" \
3530 && [[ $name ]] && (( $
(wc -l <<<"$name") >= nth
)); do
3531 name
="$(echo "$name" | head -n $nth | tail -n 1 )"
3532 read -r -p "$name [Y/n] " ask
3533 if [[ ! $ask ||
$ask == [Yy
] ]]; then
3534 x
=$
( echo "$name" | gr
-o "^\s*[0-9]*" )
3535 echo $x | restore-trash
> /dev
/null
3536 elif [[ $ask == [Nn
] ]]; then
3546 rld
/a
/h
/_site
/ li
:/var
/www
/iankelling.org
/html
3551 # fixes the menu bar in xmonad. this won\'t be needed when xmonad
3552 # packages catches up on some changes in future (this is written in
3555 # geekosaur: so youll want to upgrade to xmonad 0.13 or else use a
3556 # locally modified XMonad.Hooks.ManageDocks that doesnt set the
3557 # work area; turns out it\'s impossible to set correctly if you are
3558 # not a fully EWMH compliant desktop environment
3560 # geekosaur: chrome shows one failure mode, qt/kde another, other
3561 # gtk apps a third, ... I came up with a setting that works for me
3562 # locally but apparently doesnt work for others, so we joined the
3563 # other tiling window managers in giving up on setting it at all
3565 xprop
-root -remove _NET_WORKAREA
3569 # reviewboard, used at my old job
3570 #rbpipe() { rbt post -o --diff-filename=- "$@"; }
3571 #rbp() { rbt post -o "$@"; }
3579 r2e
() { command r2e
-d /p
/c
/rss2email.json
-c /p
/c
/rss2email.cfg
"$@"; }
3580 # only run on MAIL_HOST. simpler to keep this on one system.
3581 r2eadd
() { # usage: name url
3582 # initial setup of rss2email:
3583 # r2e new r2e@iankelling.org
3584 # that initializes files, and sets default email.
3585 # symlink to the config doesnt work, so I copied it to /p/c
3586 # and then use cli option to specify explicit path.
3587 # Only option changed from default config is to set
3590 # or else for a few feeds, the from address is set by the feed, and
3591 # if I fail delivery, then I send a bounce message to that from
3592 # address, which makes me be a spammer.
3594 r2e add
$1 "$2" $1@r2e.iankelling.org
3595 # get up to date and dont send old entries now:
3596 r2e run
--no-send $1
3599 rspicy
() { # usage: HOST DOMAIN
3600 # connect to spice vm remote host. use vspicy for local host
3602 # shellcheck disable=SC2087
3604 sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
3605 sed -rn "s/.*port='([0-9]+).*/\1/p"
3608 if [[ $port ]]; then
3609 spicy
-h $1 -p $port
3611 echo "error: no port found. check that the domain is running."
3617 # s gem install scss-lint
3618 pushd /a
/opt
/thoughtbot-guides
3621 scss-lint
-c /a
/opt
/thoughtbot-guides
/style
/sass
/.scss-lint.yml
"$@"
3625 sk
-e 2120,245 /b
/ds
/brc
/b
/ds
/brc2
3630 out
=${2:-${1%.*}.sh}
3632 script -t -c "mpv --no-config --no-resume-playback --no-terminal --no-audio-display '$1'" $tmp/typescript
2>$tmp/timing
3633 # todo, the current sleep seems pretty good, but it
3634 # would be nice to have an empirical measurement, or
3635 # some better wait to sync up.
3637 # note: --loop-file=no prevents it from hanging if you have that
3638 # set to inf the mpv config.
3639 # --loop=no prevents it from exit code 3 due to stdin if you
3640 # had it set to inf in mpv config.
3642 # args go to mpv, for example --volume=80, 50%
3643 cat >$out <<EOFOUTER
3645 trap "trap - TERM && kill 0" INT TERM ERR; set -e
3646 ( sleep .2; scriptreplay <( cat <<'EOF'
3650 $(cat $tmp/typescript)
3653 base64 -d - <<'EOF'| mpv --loop=no --loop-file=no --no-terminal --no-audio-display "\$@" -
3662 smeld
() { # ssh meld usage host1 host2 file
3663 meld
<(ssh $1 cat $3) <(ssh $2 cat $3)
3667 PATH
=/usr
/local
/spdhackfix
:$PATH command spd
"$@"
3670 spamf
() { # spamtest on FILE
3671 if (( $# != 1 )); then
3672 e spamtest error
: expected
1 arg
, filename
>&2
3675 sdncmdroot spamassassin sudo
-u Debian-exim spamassassin
-t --cf='score PYZOR_CHECK 0' <"$1"
3681 declare -gi _seq
; _seq
+=1
3682 echo "test body" | m
mail -s "test mail from $HOSTNAME, $_seq" "${@:-root@localhost}"
3683 # for testing to send from an external address, you can do for example
3684 # -fian@iank.bid -aFrom:ian@iank.bid web-6fnbs@mail-tester.com
3685 # note in exim, you can retry a deferred message
3687 # MSG_ID is in /var/log/exim4/mainlog, looks like 1ccdnD-0001nh-EN
3690 # to test sieve, use below command. for fsf mail, see offlineimap-sync script
3691 # make modifications, then copy to live file, use -eW to actually modify mailbox
3693 # Another option is to use sieve-test SCRIPT MAIL_FILE. note,
3694 # sieve-test doesnt know about envelopes, Im not sure if sieve-filter does.
3696 # sieve with output filter. arg is mailbox, like INBOX.
3697 # This depends on dovecot conf, notably mail_location in /etc/dovecot/conf.d/10-mail.conf
3699 # always run this first, edit the test files, then run the following
3701 sieve-filter ~
/sieve
/maintest.sieve
${1:-INBOX} delete
2> >(head; tail) >/tmp
/testsieve.log
&& sed -rn '/^Performed actions:/,/^[^ ]/{/^ /p}' /tmp
/testsieve.log |
sort |
uniq -c
3704 c ~
/sieve
; cp personal
{test,}.sieve
; cp lists
{test,}.sieve
; cp personalend
{test,}.sieve
3705 sieve-filter
-eWv ~
/sieve
/maintest.sieve
${1:-INBOX} delete
&> /tmp
/testsieve.log
3706 sed -r '/^info: filtering:/{h;d};/^info: msgid=$/N;/^info: msgid=.*left message in mailbox [^ ]+$/d;/^info: msgid=/{H;g};/^info: message kept in source mailbox.$/d' /tmp
/testsieve.log
3711 # printf "subject\nbody\n" | alertme
3716 To: alerts@iankelling.org
3723 To: alerts@iankelling.org
3735 To: daylert@iankelling.org
3742 To: daylert@iankelling.org
3751 # alert when a page goes live.
3753 local quiet url tmpdir
3756 # dont send a diff of the html. some html is not very readable
3762 tmpdir
="$(mktemp -d)"
3765 if wget
-q "$url"; then
3772 sleep $
(( 120 + RANDOM
% 300 ))
3776 # alert on changes to a webpage (just the base page that curl gets)
3777 # usage: weblert URL [SUBJECT...]
3779 local u old new quiet
3782 # dont send a diff of the html. some html is not very readable
3789 subject
="${*:-weblert}"
3790 old
=$
(curl
-s "$u") ||
:
3792 new
=$
(curl
-s "$u") ||
:
3793 if [[ $old && $new ]]; then
3794 if [[ $new != "$old" ]]; then
3796 echo | daylertme
"$subject"
3798 diff <(printf "%s\n" "$old") <(printf "%s\n" "$new") | daylertme
"$subject" ||
:
3803 sleep $
(( 60 + RANDOM
% 120 ))
3809 # shellcheck disable=SC1090 # expected
3810 source "$(type -p torsocks)" on
3814 less /var
/log
/exim
4/mymain
3820 # testmail above calls sendmail, which is a link to exim/postfix.
3821 # its docs dont say a way of adding an argument
3822 # to sendmail to turn on debug output. We could make a wrapper, but
3823 # that is a pain. Exim debug args are documented here:
3824 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
3826 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-building_and_installing_exim.html
3827 # note, for exim daemon, you can turn on debug options by
3828 # adding -d, etc to COMMONOPTIONS in
3829 # /etc/default/exim4
3831 # to specify recipients other than those in to, cc, bcc, you can use the cli args, eg:
3832 # exim -t 'test@zroe.org, t2@zroe.org' <<'EOF'
3834 # -t = get recipient from header
3836 From: ian@iankelling.org
3843 This is a test message.
3850 exim
-d -f '<>' $to <<EOF
3851 From: Mail Delivery System <Mailer-Daemon@gnu.org>
3853 Subject: Mail delivery failed: returning message to sender
3855 This message was created automatically by mail delivery software.
3864 # https://askubuntu.com/questions/160945/is-there-a-way-to-disable-a-laptops-internal-keyboard
3865 id
=$
(xinput
--list --id-only 'AT Translated Set 2 keyboard')
3866 if xinput list |
grep -F '∼ AT Translated Set 2 keyboard' &>/dev
/null
; then
3867 echo enabling keyboard
3868 # find the first slave keyboard number, they are all the same in my output.
3869 # if they werent, worst case we would need to save the slave number somewhere
3870 # when it got disabled.
3871 slave
=$
(xinput list |
sed -n 's/.*slave \+keyboard (\([0-9]*\)).*/\1/p' |
head -n1)
3872 xinput reattach
$id $slave
3881 (sleep "$(calc "$
* * 60")" && mpv
--no-config --volume 50 /a
/bin
/data
/alarm.mp3
) > /dev
/null
2>&1 &
3884 ## usage: to connect to my main transmission daemon from a different host, run this
3885 trans-remote-route
() {
3888 trg
() { transmission-remote-gtk
& r
; }
3889 # TODO: this wont work transmission.lan doesnt exist
3891 # example, set global upload limit to 100 kilobytes:
3893 TR_AUTH
=":$(jq -r .profiles[0].password ~/.config/transmission-remote-gtk/config.json)" transmission-remote transmission.lan
-ne "$@"
3900 for (( i
=0; i
< retries
- 1; i
++ )); do
3912 if [[ -e $1 && ! -w $1 ||
! -w $
(dirname "$1") ]]; then
3915 # full path for using in some initial setup steps
3919 # execute exim in its namespace. Useful args like -Mrm
3923 ecmd
="/usr/sbin/exim4 -C /etc/exim4/my.conf"
3924 if ip a show veth1-mail
&>/dev
/null
; then
3927 sdncmdroot exim4
$ecmd "$@"
3931 # get pid of systemd service
3935 pid
=$
(systemctl show
--property MainPID
--value "$unit")
3940 dir
=/sys
/fs
/cgroup
/system.slice
3941 if [[ ! -d $dir ]]; then
3942 # t10 and older directory.
3943 dir
=/sys
/fs
/cgroup
/systemd
/system.slice
3946 # 0 or empty. This file includes the MainPid, so I expect we
3947 # could just get this in the first place, but i don't know if that
3948 # is always the case.
3949 pid
=$
(head -n1 $dir/${unit%.service}.service
/cgroup.procs
)
3953 printf "%s\n" "$pid"
3959 sdnbash
() { # systemd namespace bash
3961 if (( $# != 1 )); then
3962 echo $0: error wrong number of args
>&2
3966 pid
=$
(servicepid
$unit)
3967 m sudo nsenter
-t $pid -n -m sudo
-u $USER -i bash
3970 sdnbashroot
() { # systemd namespace bash as root
3972 if (( $# != 1 )); then
3973 echo $0: error wrong number of args
>&2
3977 pid
=$
(servicepid
$unit)
3978 m sudo nsenter
-t $pid -n -m bash
3982 # systemd namespace cmd
3983 # usage: UNIT CMD...
3986 if (( $# <= 1 )); then
3987 echo $0: error wrong number of args
>&2
3992 pid
=$
(servicepid
$unit)
3993 tmpf
=$
(mktemp
--tmpdir $unit.XXXXXXXXXX
)
3995 printf "%s " "${@@Q}" >>$tmpf
3997 m sudo nsenter
-t $pid -n -m sudo
-u $USER -i bash
-c ". $tmpf & rm $tmpf"
4000 sdncmdroot
() { # systemd namespace root command
4002 if (( $# < 2 )); then
4003 echo $0: error wrong number of args
>&2
4008 pid
=$
(servicepid
$unit)
4009 m sudo nsenter
-t $pid -n -m "$@"
4017 # we use wireguard now, use mailnnbash.
4019 # m sudo nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*mail.conf") -n -m sudo -u $USER -i bash
4027 spamdpid
=$
(systemctl show
--property MainPID
--value spamassassin
)
4028 m sudo nsenter
-t $spamdpid -n -m sudo
-u Debian-exim spamassassin
"$@"
4035 s nmtui-connect
"$@"
4039 local unit pid ns mailnn
4040 # mailvpn would belong on the list if using openvpn
4041 for unit
in mailnn unbound dovecot spamassassin exim4 radicale
; do
4042 pid
=$
(servicepid
$unit)
4043 echo debug
: unit
=$unit pid
=$pid
4044 if [[ ! $pid ]]; then
4045 echo failed to
find pid
for unit
=$unit
4048 if ! ns
=$
(s readlink
/proc
/$pid/ns
/net
); then
4049 echo failed to
find ns
for unit
=$unit pid
=$pid
4052 if [[ $mailnn ]]; then
4053 if [[ $ns != "$mailnn" ]]; then
4054 echo "$unit ns $ns != $mailnn"
4065 sdncmd openvpn-client-tr@client.service
"$@"
4068 sdncmd openvpn-client-tr@client.service bash
4071 sdncmdroot openvpn-client-tr@client.service bash
4076 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
4077 local vpn_service
=openvpn-client
4079 local vpn_service
=openvpn
4082 [[ $1 ]] ||
{ echo need arg
; return 1; }
4083 journalctl
--unit=$vpn_service@
$1 -f -n0 &
4084 # sometimes the journal doesnt open until after the vpn output
4085 # has happened. hoping this fixes that.
4087 sudo systemctl start
$vpn_service@
$1
4088 # sometimes the ask-password agent does not work and needs a delay.
4090 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779240
4091 # noticed around 8-2017 after update from around stretch release
4092 # on debian testing, even though the bug is much older.
4093 sudo systemd-tty-ask-password-agent
4098 ls -lad /run
/user
/1000
4099 stats
=$
(stat
-c%a-
%g-
%u
/run
/user
/1000)
4100 if [[ $stats != 700-1000-1000 ]]; then
4101 m s
chmod 700 /run
/user
/1000; m s chown iank.iank
/run
/user
/1000
4108 sink
=$
(pactl get-default-sink
)
4109 if [[ $sink == auto_null
]]; then
4110 # guessing there is just one with an off profile. otherwise we will
4111 # need some other solution, like storing the card identifier that we
4113 card
=$
(pacmd list-cards |
sed -n '/^[[:space:]]*index:/{s/^[[:space:]]*index://;h};/^[[:space:]]*active profile: <off>$/{g;p;q}')
4114 m pacmd set-card-profile
"$card" output
:analog-stereo
4117 m pactl set-sink-mute @DEFAULT_SINK@ false
4123 sink
=$
(pactl get-default-sink
)
4125 card
="${card/output/card}"
4126 m pacmd set-card-profile
"$card" off
4128 # clicking on a link in a browser can cause unmute.
4129 # I don't want that. So, use a stronger form of mute
4131 #pactl set-sink-mute @DEFAULT_SINK@ true
4136 # systemctl is-enabled / status / cat says nothing, instead theres
4137 # some obscure symlink. paths copied from man systemd.unit.
4138 # possibly also usefull, but incomplete, doesnt show units not loaded in memory:
4139 # seru list-dependencies --reverse --all UNIT
4142 local -a dirs search
4148 ~
/.config
/systemd
/user.control
/*
4149 $XDG_RUNTIME_DIR/systemd
/user.control
/*
4150 $XDG_RUNTIME_DIR/systemd
/transient
/*
4151 $XDG_RUNTIME_DIR/systemd
/generator.early
/*
4152 ~
/.config
/systemd
/user
/*
4154 $XDG_RUNTIME_DIR/systemd
/user
/*
4156 $XDG_RUNTIME_DIR/systemd
/generator
/*
4157 ~
/.local
/share
/systemd
/user
/*
4158 /usr
/lib
/systemd
/user
/*
4159 $XDG_RUNTIME_DIR/systemd
/generator.late
/*
4164 /etc
/systemd
/system.control
/*
4165 /run
/systemd
/system.control
/*
4166 /run
/systemd
/transient
/*
4167 /run
/systemd
/generator.early
/*
4168 /etc
/systemd
/system
/*
4169 /etc
/systemd
/systemd.attached
/*
4170 /run
/systemd
/system
/*
4171 /run
/systemd
/systemd.attached
/*
4172 /run
/systemd
/generator
/*
4173 /lib
/systemd
/system
/*
4174 /run
/systemd
/generator.late
/*
4178 for f
in "${search[@]}"; do
4179 [[ -d $f ]] ||
continue
4186 # dirs is just so we write out the directory names, ls does it when there is 2 or more dirs.
4202 read -r _ link _ istls
< <(resolvectl dnsovertls tunfsf
)
4205 *) echo fixvpndns error
: unexpected istls value
: $istls >&2; return 1 ;;
4207 s busctl call org.freedesktop.resolve1
/org
/freedesktop
/resolve1 org.freedesktop.resolve1.Manager SetLinkDNSOverTLS is
$link no
4211 [[ $1 ]] ||
{ echo need arg
; return 1; }
4212 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
4213 local vpn_service
=openvpn-client
4215 local vpn_service
=openvpn
4217 sudo systemctl stop
$vpn_service@
$1
4219 vpnoffc
() { # vpn off client
4220 ser stop openvpn-client-tr@client
4224 unit
=openvpn-client-tr@client
4226 if [[ $
(systemctl is-active
$unit) != active
]]; then
4227 s systemctl start
$unit
4233 vspicy
() { # usage: VIRSH_DOMAIN
4234 # connect to vms made with virt-install
4235 spicy
-p "$(sudo virsh dumpxml "$1"|grep "<graphics.
*type='spice'"|\
4236 sed -r "s
/.
*port
='([0-9]+).*/\1/")"
4240 cat-new-files /m/4e/INBOX/new
4244 if (( $# != 1 )) ; then
4245 echo wakehours: error: expected 1 arg, got $# >&2
4248 sec=$(( EPOCHSECONDS - $( date +%s -d $1am ) ))
4249 printf "%d:%02d\n" $(( sec / 60 / 60)) $(( (sec / 60) % 60 ))
4252 calvis() { # calendar visualize
4253 install -m 600 /dev/null /tmp/calendar-bytes
4256 # shellcheck disable=SC2059 # intentional for the hex formatting
4257 printf "\x$(printf "%x" $char)" >>/tmp/calendar-bytes
4259 done < <(grep -v '[#-]' /p/calendar-data)
4260 /p
/c
/proc
/calendar
/linux-amd64
/calendar
4263 wtr
() { curl wttr.in
/boston
; }
4265 xevkb
() { xev
-event keyboard
; }
4270 printf "running: %s\n" "$*"
4275 # https://electrum.readthedocs.io/en/latest/tor.html
4276 # https://github.com/spesmilo/electrum-docs/issues/129
4277 s rsync
-ptog --chown bitcoin
:bitcoin ~
/.Xauthority
/var
/lib
/bitcoind
/.Xauthority
4278 sudo
-u bitcoin DISPLAY
=$DISPLAY XAUTHORITY
=/var
/lib
/bitcoind
/.Xauthority
/a
/opt
/electrum-4.2
.1-x86_64.AppImage
-p socks5
:localhost
:9050
4281 sudo
-u bitcoin DISPLAY
=$DISPLAY XAUTHORITY
=/var
/lib
/bitcoind
/.Xauthority
/a
/opt
/monero-gui-v0.17
.3.2/monero-wallet-gui
4287 faf |
grep -E "$@" ||
:
4293 rg
"$@" /p
/w.org
/a
/t.org
/a
/work.org
/b
4296 # re all my files more expansively
4300 find $paths -not \
( -name .svn
-prune -o -name .git
-prune \
4301 -o -name .hg
-prune -o -name .editor-backups
-prune \
4302 -o -name .undo-tree-history
-prune \
) 2>/dev
/null |
grep -iP --color=auto
-- "$*" ||
:
4303 rgv
$local_rgv_args -g "!bash_unpublished" -- "$*" $paths /a
/work.org ||
:
4305 reml
() { # rem with limit to 5 matches per file
4306 local_rgv_args
="-m 5"
4313 find $paths -not \
( -name .svn
-prune -o -name .git
-prune \
4314 -o -name .hg
-prune -o -name .editor-backups
-prune \
4315 -o -name .undo-tree-history
-prune \
) 2>/dev
/null |
grep -iP --color=auto
-- "$*" ||
:
4316 rgv
$local_rgv_args -- "$*" $paths /a
/t.org
/p
/w.org ||
:
4318 repl
() { # rem with limit to 5 matches per file
4319 local local_rgv_args
="-m 5"
4324 # re on common fsf files
4327 paths
="/f/gluestick /f/brains /f/s /c"
4328 find $paths -not \
( -name .svn
-prune -o -name .git
-prune \
4329 -o -name .hg
-prune -o -name .editor-backups
-prune \
4330 -o -name .undo-tree-history
-prune \
) 2>/dev
/null |
grep -iP --color=auto
-- "$*" ||
:
4331 rgv
-- "$*" $paths /a
/work.org ||
:
4335 # for use in /f/bind
4337 # shellcheck disable=SC2046 # i want word splitting
4338 .
/update-zone $
(i s |
sed -rn 's/.*db\.(.*)/\1/p')
4342 # pip3 install linode-cli
4345 local input ip id tmp
4353 linode-cli
--json --pretty linodes create
--root_pass loxHuceygomGisun |
tee $tmp
4354 read -r ip id
<<<"$(tail -n+2 $tmp | jq -r '.[0].ipv4[0] , .[0].id')"
4355 for string
in $ip $id; do
4359 echo "livp9: bad value ip=$ip id=$id input=$input"
4367 if timeout
4 ssh $ip :; then
4375 apt-get -qq -y install ffmpeg rsync
4379 m
ssh $ip ffmpeg
-nostdin -hide_banner -loglevel error
-i $input -g 192 -vcodec libvpx-vp9
-vf scale
=-1:720 -max_muxing_queue_size 9999 -b:v
750K
-pass 1 -an -f null
/dev
/null
4380 m
ssh $ip ffmpeg
-nostdin -hide_banner -loglevel error
-y -i $input -g 192 -vcodec libvpx-vp9
-tile-rows 2 -vf scale
=-1:720 -max_muxing_queue_size 9999 -b:v
750K
-pass 2 -c:a libvorbis
-qscale:a
5 vp
9/$input
4381 rsync
$ip:vp
9/$input vp9
4382 linode-cli linodes delete
$id
4386 # we also have a file in /a/c/...konsole...
4387 local f
=$HOME/.config
/konsolerc
4388 setini DefaultProfile profileian.profile
"Desktop Entry" $f
4389 setini Favorites profileian.profile
"Favorite Profiles" $f
4390 setini ShowMenuBarByDefault false KonsoleWindow
$f
4391 setini TabBarPosition Top TabBar
$f
4395 while read -r k v
; do
4396 # shellcheck disable=SC2154
4397 setini
$k $v sakura
/a
/c
/subdir_files
/.config
/sakura
/sakura.conf
4399 colorset1_back rgb(33,37,39)
4403 disable_numbered_tabswitch true
4404 scroll_lines 10000000
4409 # make a page of links found in the files $@. redirect output
4411 gr
-oh 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' "$@" | \
4412 rev |
sort -u |
rev |
sed 's,.*,<a href="\0">\0</a><br\>,'
4415 reset-xscreensaver
() {
4416 # except for spash, i set these by setting gui options in
4417 # xscreensaver-command -demo
4418 # then finding the corresponding option in .xscreensaver
4419 # spash, i happened to notice in .xscreensaver
4421 # dpmsOff, monitor doesnt come back on using old free software supported nvidia card
4422 cat > /home
/iank
/.xscreensaver
<<'EOF'
4425 dpmsStandby: 0:07:00
4426 dpmsSuspend: 0:08:00
4430 lockTimeout: 0:06:00
4437 # very useful, copy directory structure 3 deep. add remove /*/ to change level
4438 # rsync -aivh --exclude '/*/*/*/' -f"+ */" -f"- *" SRC DEST
4441 # * stuff that makes sense to be at the end
4442 if [[ "$SUDOD" ]]; then
4443 # allow failure, for example if we are sudoing into a user with diffferent/lesser permissions.
4446 elif [[ -d /a
]] && [[ $PWD == "$HOME" ]] && [[ $
- == *i
* ]]; then
4454 # for mitmproxy to get a newer python.
4455 # commented until i want to use it because it
4456 # noticably slows bash startup
4460 if [[ $EUID == 0 ||
! -e ~
/.pyenv
/bin
]]; then
4461 echo "error: dont be root. make sure pyenv is installed"
4464 export PATH
="$HOME/.pyenv/bin:$PATH"
4465 eval "$(pyenv init -)"
4466 eval "$(pyenv virtualenv-init -)"
4471 # I have the git repo and a release. either one should work.
4472 # I have both because I was trying to solve an issue that
4473 # turned out to be unrelated.
4474 # ARDUINO_PATH=/a/opt/Arduino/build/linux/work
4476 ## i should have documented this...
4477 # based on https://github.com/keyboardio/Kaleidoscope
4478 export KALEIDOSCOPE_DIR
=/a
/opt
/Kaleidoscope
4480 # They want to be added to the start, but i think
4481 # that should be avoided unless we really need it.
4482 path-add
--end ~
/.npm-global
4485 path-add
--end $HOME/.cargo
/bin
4487 if type -P rg
&>/dev
/null
; then
4488 # --no-messages because of annoying errors on broken symlinks
4489 # -z = search .gz etc files
4490 # -. = search dotfiles
4491 rg
() { command rg
-.
-z --no-messages -L -i -M 900 --no-ignore-parent --no-ignore-vcs -g '!.git' -g '!auto-save-list' -g '!.savehist' "$@" ||
return $?
; }
4492 #fails if not exist. ignore
4493 complete
-r rg
2>/dev
/null ||
:
4498 # rg with respecting vcs ignore files
4501 # settings that are turned off for pipes, keep them on.
4502 # Found by searching for "terminal" in --help
4506 # -. = search dotfiles
4507 # -z = search zipped files
4508 # -i = case insensitive
4510 # --no-messages because of annoying errors on broken symlinks
4511 # --no-ignore-parent because i have /a/.git which ignores almost everything under it.
4512 command rg
-n --heading -.
-z --no-messages -i -M 900 --no-ignore-parent -g '!.git' -g '!auto-save-list' -g '!.savehist' "$@" || ret
=$?
4517 echo "$(tput setaf 5 2>/dev/null ||:)â–ˆ coresite â–ˆ$(tput sgr0 2>/dev/null||:)"
4519 echo "$(tput setaf 5 2>/dev/null ||:)â–ˆ office â–ˆ$(tput sgr0 2>/dev/null||:)"
4522 amallq
() { # amall quiet
4527 sedi
-r '/alertmanager.url/s/@prom.office/@prom/' ~
/.config
/amtool
/config.yml
4531 sedi
-r '/alertmanager.url/s/@prom.fsf/@prom.office.fsf/' ~
/.config
/amtool
/config.yml
4535 amall silence query
"$@"
4537 # amtool silence add
4539 amall silence add
"$@"
4541 # amtool silence force
4543 amall silence add x
!="1"
4546 # note: not sure if quoting of this arg is correct
4547 amfsf silence expire
"$(amfsf silence query -q)"
4548 amoffice silence expire
"$(amoffice silence query -q)"
4552 youtube-dl-update
() {
4553 sudo wget https
://yt-dl.org
/downloads
/latest
/youtube-dl
-O /usr
/local
/bin
/youtube-dl
4554 sudo
chmod a
+rx
/usr
/local
/bin
/youtube-dl
4557 # https://github.com/yt-dlp/yt-dlp/wiki/Installation
4559 sudo curl
-L https
://github.com
/yt-dlp
/yt-dlp
/releases
/latest
/download
/yt-dlp
-o /usr
/local
/bin
/yt-dlp
4560 sudo
chmod a
+rx
/usr
/local
/bin
/yt-dlp
# Make executable
4564 mpv
--ytdl ytdl_path
=/usr
/local
/bin
/yt-dlp
"$@"
4567 # taken from default changes to bashrc and bash_profile
4568 path-add
--end --ifexists $HOME/.rvm
/bin
4569 # also had ruby bin dir, but moved that to environment.sh
4570 # so its included in overall env
4573 # ya, hacky hardcoded hostnames in 2023. we could do better
4575 local -a failed_hosts hosts
4579 kd.b8.nz x3.office.fsf.org syw x2.b8.nz
4588 for host in ${hosts[@]}; do
4590 if ! scp
/b
/fai
/fai
/config
/files
/usr
/local
/bin
/hssh
/IANK root@
$host:/usr
/local
/bin
/hssh
; then
4591 failed_hosts
+=($host)
4594 if (( ${#failed_hosts[@]} >= 1 )); then
4595 echo failed_hosts
=${failed_hosts[*]}
4608 # <#part type="image/jpeg" filename="/home/iank/2023-12-24-ski-trip.jpg" disposition=attachment> <#/part>
4613 if [[ ! -s $f ]]; then
4614 e
"error: empty or non-existent file $f"
4619 echo '<#part type="image/jpeg" filename="'"$(rl "$f")"'" disposition=attachment> <#/part>'
4624 units
"tempC($1)" tempF
4628 units
"tempF($1)" tempC
4631 # requires dns/firewall setup first
4633 web-conf
-e ian@iankelling.org
-f 8000 - apache2 live.iankelling.org
<<'EOF'
4634 <Location "/fsf.webm">
4636 AuthName "basic_auth"
4638 # htpasswd -c icecast-fsf-htpasswd USERNAME
4639 AuthUserFile "/etc/icecast-fsf-htpasswd"
4642 <Location "/fsf-tech.webm">
4644 AuthName "basic_auth"
4645 AuthUserFile "/etc/icecast-fsf-tech-htpasswd"
4651 # obs screen switching of
4653 ls -l /tmp
/no-obs-auto-scene-switch
4654 touch /tmp
/no-obs-auto-scene-switch
4656 # obs screen switching on
4658 ls -l /tmp
/no-obs-auto-scene-switch
4659 if [[ -e /tmp
/no-obs-auto-scene-switch
]]; then
4660 rm -f /tmp
/no-obs-auto-scene-switch
4664 obs-gen-profiles
() {
4665 local p
=/p
/c
/basic
/profiles
4666 sed 's/fsf-sysops/fsf-tech/g' $p/fsfsysops
/basic.ini
>$p/fsftech
/basic.ini
4667 sed 's/fsf-sysops/fsf/g' $p/fsfsysops
/basic.ini
>$p/fsf
/basic.ini
4670 # terminal clear. like clear, but put the prompt at the bottom,
4671 # useful for obs streaming the bottom half of a terminal window.
4673 for ((i
=0; i
<COLUMNS
; i
++)); do
4679 export BASEFILE_DIR
=/a
/bin
/fai-basefiles
4681 #export ANDROID_HOME=/a/opt/android-home
4682 # https://f-droid.org/en/docs/Installing_the_Server_and_Repo_Tools/
4683 #export USE_SDK_WRAPPER=yes
4684 #PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
4686 # didnt get drush working, if I did, this seems like the
4687 # only good thing to include for it.
4688 # Include Drush completion.
4689 # if [ -f "/home/ian/.drush/drush.complete.sh" ] ; then
4690 # source /home/ian/.drush/drush.complete.sh
4697 # https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
4698 # i added an extra condition as gentoo xorg guide says depending on
4699 # $DISPLAY is fragile.
4700 if [[ ! $DISPLAY && $XDG_VTNR == 1 ]] && shopt -q login_shell
&& isarch
; then
4705 # ensure no bad programs appending to this file will have an affect