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
87 source /a
/bin
/log-quiet
/logq-function
90 # if [[ -s /a/opt/alacritty/extra/completions/alacritty.bash ]]; then
91 # source /a/opt/alacritty/extra/completions/alacritty.bash
95 source /a
/bin
/ds
/beet-data
106 m pactl unload-module module-loopback
107 m pactl unload-module module-null-sink
108 m pactl unload-module module-remap-source
110 IFS
=" " read -r -a sources
<<<"$(pacmd list-sources | sed -rn 's/.*name: <([^>]+).*/\1/p')"
114 for s
in ${sources[@]}; do
121 m pactl load-module module-null-sink sink_name
=ianinput sink_properties
=device.description
=ianinputs
123 m pactl load-module module-loopback
source=${sources[i]} sink_dont_move
=true sink
=ianinput
125 pactl load-module module-remap-source source_name
=iancombine master
=ianinput.monitor source_properties
=device.description
=iancombine
129 # For testing restrictive ssh.
133 sed '/^ *IdentityFile/d' ~
/.ssh
/config
>$d/config
134 s
command ssh -F $d/config
-i /q
/root
/h
"$@"
138 # For testing restrictive rsync
142 sed '/^ *IdentityFile/d' ~
/.ssh
/config
>$d/config
143 s rsync
-e "ssh -F $d/config -i /q/root/h" "$@"
146 # rsync as root and avoid the default restrictive h key & config.
148 s rsync
-e "ssh -F /root/.ssh/confighome" "$@"
152 ssh bow DISPLAY
=:0 scrot
/tmp
/oegu.jpg
153 scp bow
:/tmp
/oegu.jpg
/t
154 ssh bow
rm /tmp
/oegu.jpg
168 if [[ $arg == [89]0Etiona
* ]]; then
170 rtime
=${arg#*Etiona} # remote time
171 if [[ ! $rtime ]]; then
174 dir
=/a
/opt
/emacs-trisquel
${v}-nox/.iank
175 ltime
=$
(stat
-c%Y
$dir/e
/e
/.emacs.d
/init.el
)
176 if (( ltime
> rtime
)); then
177 m rsync
-rptL --delete --filter=". /b/ds/sl/rsync-filter" $dir "$remote":/home
/iank
183 local f
=/home
/iank
/.emacs.d
/init.el
184 sl
--sl-test-cmd ". /etc/os-release ; printf %s \${VERSION//[^a-zA-Z0-9]/}; test -e $f && stat -c%Y $f" --sl-test-hook slemacs
"$@"
188 # Run this manually after .emacs.d changes. Otherwise, to check if
189 # files changed with find takes 90ms. sl normally only adds 25ms. We
190 # could cut it down to 10ms if we put things on a btrfs filesystem and
191 # looked for changes there, or used some inotify thing, but that seems
192 # like too much work.
193 egh
() { # emacs gnuhope
194 RSYNC_RSH
=ssh m rsync
-rptL --delete --filter=". /b/ds/sl/rsync-filter" /a
/opt
/emacs-trisquel9-nox
/.iank lists2d.fsf.org
:.ianktrisquel_9
195 RSYNC_RSH
=ssh m rsync
-rptL --delete --filter=". /b/ds/sl/rsync-filter" /a
/opt
/emacs-trisquel8-nox
/.iank lists2d.fsf.org
:/home
/iank
198 local shell
="bash -s"
199 if [[ $HOSTNAME != kw
]]; then
200 shell
="ssh kw.office.fsf.org"
204 sudo mkdir /root/.ianktrisquel_9
205 sudo rsync -rptL --delete --filter=". /b/ds/sl/rsync-filter" /a/opt/emacs-trisquel9-nox/.iank /root/.ianktrisquel_9
206 rsync -rptL --delete --filter=". /b/ds/sl/rsync-filter" /a/opt/emacs-trisquel8-nox/.iank /home/iank
210 rm-docker-iptables
() {
211 s iptables
-S | gr docker | gr
-- -A |
sed 's/-A/-D/'|
while read -r l
; do sudo iptables
$l; done
212 s iptables
-S -t nat | gr docker | gr
-- -A |
sed 's/-A/-D/'|
while read -r l
; do sudo iptables
-t nat
$l; done
213 s iptables
-S | gr docker | gr
-- -N |
sed 's/-N/-X/'|
while read -r l
; do sudo iptables
$l; done
214 s iptables
-S -t nat | gr docker | gr
-- -N |
sed 's/-N/-X/'|
while read -r l
; do sudo iptables
-t nat
$l; done
217 # usage mkschroot [-] distro codename packages
218 # - means no piping in of sources.list
220 # note some useful post mkschroot i've used in the past
221 # tu /nocow/schroot/flidas/etc/sudoers <<EOF
222 # $USER ALL=(ALL) NOPASSWD: ALL
223 # Defaults env_keep += SUDOD
224 # Defaults always_set_home
227 # sd /nocow/schroot/flidas//etc/locale.gen <<'EOF'
230 # s schroot -c flidas locale-gen
231 # s schroot -c flidas update-locale LANG=en_US.UTF-8
234 local sources force repo n distro
236 while [[ $1 == -* ]]; do
238 -f) force
=true
; shift ;;
241 if [[ ! -s $sources ]]; then
242 echo mkschroot
: error
: sources
file $sources does not exist or is empty
253 repo
=http
://mirror.fsf.org
/trisquel
/
256 repo
=http
://archive.ubuntu.com
/ubuntu
/
259 repo
=http
://deb.debian.org
/debian
/
265 if ! $force && schroot
-l |
grep -xFq chroot
:$n; then
266 echo "$0: $n schroot already installed, skipping"
271 sd
/etc
/schroot
/chroot.d
/$n.conf
<<EOF
277 preserve-environment=true
281 if [[ ! -e $d/bin
]]; then
283 # resolvconf otherwise schroot fails with
284 # cp: not writing through dangling symlink '/var/run/schroot/mount/flidas-7a2362e0-81b3-4848-92c1-610203ef5976/etc/resolv.conf'
285 sudo debootstrap
--exclude=resolvconf
$n $d $repo
287 if [[ $sources ]]; then
288 sudo
install -m 644 $sources $d/etc
/apt
/sources.list
290 sudo chroot
$d apt-get update
291 sudo DEBIAN_FRONTEND
=noninteractive chroot
$d apt-get
-y dist-upgrade
--purge --auto-remove
292 sudo
cp -P {,$d}/etc
/localtime
293 if (( ${#apps[@]} )); then
294 sudo DEBIAN_FRONTEND
=noninteractive schroot
-c $n -- apt-get
install --allow-unauthenticated -y ${apps[@]}
299 # note: this is incomplete and untested.
300 # https://wiki.archlinux.org/index.php/Install_Arch_Linux_from_existing_Linux#Creating_a_chroot
303 mirror
=https
://mirrors.edge.kernel.org
/archlinux
/iso
/latest
/
304 tarball
=$
(curl
-s $mirror |
sed -nr 's/.*"(archlinux-bootstrap-.*-x86_64.tar.gz)".*/\1/p')
305 wget
-O /tmp
/arch.
tar.gz https
://mirrors.edge.kernel.org
/archlinux
/iso
/latest
/$tarball
306 s mkdir
-p /nocow
/schroot
/arch
307 cd _
/nocow
/schroot
/arch
308 s
sed -i '/## United States/,/^$/s,^#,,' etc
/pacman.d
/mirrorlist
309 # error: could not determine cachedir mount point /var/cache/pacman/pkg
310 s
sed -i /^CheckSpace
/d etc
/pacman.conf
311 chroot .
/bin
/bash
-s <<'EOF'
313 pacman-key --populate archlinux
316 # example of building an aur package:
317 # pacman -Sy base-devel wget
319 # f=$target/etc/sudoers
320 # line='iank ALL=(ALL) NOPASSWD: ALL'
321 # if [[ ! -e $f ]] || ! grep -xF "$line" $f; then
325 # wget https://aur.archlinux.org/cgit/aur.git/snapshot/anbox-image-gapps.tar.gz
326 # tar xzf anbox-image-gapps.tar.gz
327 # cd anbox-image-gapps
332 # clock back in to timetrack from last entry
334 sqlite3
/p
/.timetrap.db
"update entries set end = NULL where id = (select max(id) from entries);"
338 # s sshfs bu@$host:/bu/home/md /bu/mnt -o reconnect,ServerAliveInterval=20,ServerAliveCountMax=30 -o allow_other
341 echo all
>/etc
/exim
4/no-delay-eximids
344 echo >/etc
/exim
4/no-delay-eximids
348 local -a array tmpstr delayon
350 if grep -qFx all
/etc
/exim
4/no-delay-eximids
; then
354 echo all
>/etc
/exim
4/no-delay-eximids
356 tmpstr
=$
(exiqgrep
-i -r.\
*)
357 mapfile
-t array
<<<"$tmpstr"
360 echo >/etc
/exim
4/no-delay-eximids
365 eid
="$(exipick -i -r.\*|h1)"
366 sed -n "/^all$/p;\$a $eid" /etc
/exim
4/no-delay-eximids
372 printf "%s\n" "$eid" >>/etc
/exim
4/no-delay-eximids
379 /a
/f
/gnulib
/build-aux
/gnupload
"$@"
385 f
=(/p
/c
/firefox
*/compatibility.ini
)
386 if (( ${#f[@]} )); then
393 s checkrestart
-b /a
/bin
/ds
/checkrestart-blacklist
-pv
396 cp-blocked-domains-to-brains
() {
397 cp /a
/f
/ans
/roles
/exim
/files
/mx
/simple
/etc
/exim
4/bad-sender_domains
/a
/f
/brains
/sysadmin
/kb
/blocked_email_domains.mdwn
399 cp-blocked-domains-to-ansible
() {
400 cp /a
/f
/brains
/sysadmin
/kb
/blocked_email_domains.mdwn
/a
/f
/ans
/roles
/exim
/files
/mx
/simple
/etc
/exim
4/bad-sender_domains
406 hrcat
/m
/md
/daylert
/{cur
,new
}/*
411 rm -f /m
/md
/daylert
/{cur
,new
}/*
417 hrcat
/m
/md
/alerts
/{cur
,new
}/*
420 ssh bk.b8.nz
"shopt -s nullglob; hrcat /m/md/INBOX/new/* /m/md/INBOX/cur/*"
424 rm -f /m
/md
/alerts
/{cur
,new
}/*
426 ssh bk.b8.nz
"shopt -s nullglob; rm -f /m/md/INBOX/new/* /m/md/INBOX/cur/*"
431 find /var
/local
/cron-errors
/home
/iank
/cron-errors
/sysd-mail-once-state
-type f
433 ralerts
() { # remote alerts
435 # this list is duplicated in check-remote-mailqs
436 for h
in bk je li frodo x3wg kdwg sywg
; do
439 if [[ $HOSTNAME == "${h%wg}" ]]; then
443 $shell find /var
/local
/cron-errors
/home
/iank
/cron-errors
/sysd-mail-once-state
-type f || ret
=$?
451 # pushd in case current directory has an ansible.cfg file
452 pushd /a
/xans
>/dev
/null
453 ansible-playbook
-v -l ${1:- $(hostname -f)} site.yml
457 pushd /a
/work
/ans
>/dev
/null
458 time ansible-playbook
-i inventory adhoc.yml
"$@"
462 pushd /a
/bin
/distro-setup
/a
>/dev
/null
463 ansible-playbook site.yml
"$@"
468 # googling android emulator libGL error: failed to load driver: r600
469 # lead to http://stackoverflow.com/a/36625175/14456
470 export ANDROID_EMULATOR_USE_SYSTEM_LIBS
=1
471 /a
/opt
/android-studio
/bin
/studio.sh
"$@" & r
474 # Convert brains file path to url and vice versa
475 # usage: brains [URL_OR_PATH]
477 _iki-convert brains.fsf.org
/wiki
"$@"
480 _iki-convert gluestick.office.fsf.org
"$@"
485 local url url_prefix path input repo_dir dir url_dir url name
487 name
="${url_prefix%%.*}"
493 read -r -p "enter path or url"$
'\n' input
497 path
="$repo_dir/${input##http*://"$url_prefix"/}"
498 # for files like x.jpg, we dont need to convert the extension.
499 if [[ $path == */ ]]; then
501 # brains adds trailing slash, but without trailing is still
502 # valid. We can't be totally sure whether to add mdwn, but we
503 # can guess based on the existence of the file. We can't be sure
504 # because it could be a file like x.jpg, that we just don't have
506 elif [[ ! -f $path && -e $path.mdwn
]]; then
509 j
printf "%s\n" "$path"
513 url_dir
=$
(echo "$path" |
sed -r "s,^(/a)?$repo_dir/,,")
514 url
="https://$url_prefix/$url_dir"
515 if [[ $url == *.mdwn
]]; then
524 # Generate beet smartplaylists for navidrome.
525 # for going in the reverse direction, run
526 # /b/ds/navidrome-playlist-export
527 beetsmartplaylists
() {
528 install -m 0700 -d /tmp
/ianbeetstmp
530 # kill off any playlists we deleted. they will still need manual
531 # killing from a navidrome client.
532 rm -rf /i
/converted
/beetsmartplaylists
533 mkdir
-p /i
/converted
/beetsmartplaylists
534 for f
in /tmp
/ianbeetstmp
/*; do
535 sed 's,^/i/m,/i/converted,;s,\.flac$,.mp3,' "$f" >"/i/converted/beetsmartplaylists/${f##*/}"
538 rmdir /tmp
/ianbeetstmp
541 # internal function for beetrating, in case we need to ssh
543 local tmp rating path cpath sqlpath userid
544 # plucked this from the db. im the only user.
545 userid
=23cc2eb9-e35e-4811-a0f0-d5f0dd6eb634
546 while read -r rating path
; do
547 cpath
="/i/converted${path#/i/m}" # converted path
550 cpath
="${cpath%.*}.mp3"
553 if [[ ! -e $cpath ]]; then
554 echo "beetraing: error: this should not happen, path does not exist: $cpath"
557 sqlpath
="${cpath//\'/\'\'}"
558 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';")
559 if [[ $old_rating ]]; then
560 if [[ $old_rating != "$rating" ]]; then
561 echo "setting rating $old_rating -> $rating $cpath"
562 # https://stackoverflow.com/a/50317320
563 # we got a timeout error once. arbitrarily chose 15 seconds.
564 sqlite3
/i
/navidrome
/navidrome.db
".timeout 15000" "
565 update annotation set rating = $rating
567 select media_file.id from annotation inner join media_file on annotation.item_id = media_file.id
568 where media_file.path = '$sqlpath' and annotation.item_type = 'media_file' );"
571 echo "setting rating $rating $cpath"
572 # /a/opt/navidrome/persistence/sql_annotations.go v0.48.0
573 # https://www.sqlite.org/lang_insert.html
574 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';"
579 # Export beets ratings into navidrome
582 if [[ $HOSTNAME != kd
]]; then
583 ssh_prefix
="ssh b8.nz"
585 # shellcheck disable=SC2016 # obvious reason
586 beet
ls -f '$rating $path' $nav_convert_query |
$ssh_prefix beetrating-stdin
589 # Do transcoding and hardlinking of audio files for navidrome.
593 # a bunch of effort to ignore output we dont care about...
594 sed 's/^format_item:.*/format_item: ignore_this/' ~
/.config
/beets
/config.yaml
>$tmpf
595 beet
-c $tmpf convert
-y $nav_convert_query > >(grep -vFx 'ignore_this' ||
:) 2> >(grep -v '^convert: Skipping' ||
:)
598 # This deletes files in the converted directory which should no longer
599 # be there due to a rename of the unconverted file.
600 beetconvert-rm-extras
() {
604 # shellcheck disable=SC2016 # obvious reason
605 beet
ls -f '$path' $nav_convert_query >"$tmpf"
606 ## begin removal of files that are leftover from previous conversion,
607 # eg, previously rated > 1, now rated 1.
609 convertedpath
="/i/converted${l#/i/m}"
610 case $convertedpath in
611 *.flac
) convertedpath
="${convertedpath%.flac}.mp3" ;;
613 paths
[$convertedpath]=t
616 find /i
/converted
-path /i
/converted
/beetsmartplaylists
-prune -o \
( -type f
-print \
) -name '*.mp3' -o -name '*.m4a' >"$tmpf"
618 if [[ ! ${paths[$l]} ]]; then
621 # note: the pruning is duplicative of filtering on name, but whatever.
626 beets-gen-playlists
() {
628 local -a query_array query_str
629 for i
in "${!bpla[@]}"; do
631 eval "query_array=(${bpla[$i]})"
632 for str
in "${query_array[@]}"; do
633 query_str
+=("\"$str\"")
637 query: '${query_str[@]}'
642 # beet playlist. use beetag with a playlist name
644 local playlist playlist_regex
647 for playlist
in "${!bpla[@]}"; do
648 printf "%s\n" "$playlist"
655 playlist_regex
='[a-z0-9_]'
656 if [[ ! $playlist =~
$playlist_regex ]]; then
657 echo "bpl: error unexpected chars in playlist: $playlist"
660 # all but last arg as options
661 eval beetag
-r "${*:1:$# - 1}" "${bpla[$playlist]}"
663 complete
-W "${!bpla[*]}" bpl
666 # beet modify quietly
670 # a bunch of effort to ignore output we dont care about...
671 sed 's/^format_item:.*/format_item: ignore_this/' ~
/.config
/beets
/config.yaml
>$tmpf
672 beet
-c $tmpf modify
-y "$@" > >(grep -vFx -e 'ignore_this' -e 'Modifying 1 items.' ||
:)
678 # https://stackoverflow.com/a/5722874
679 kill %% 2>/dev
/null ||
:; wait %% 2>/dev
/null ||
:
685 printf "%s=%s " "$arg" "${!arg}"
690 # Must be called from beetag for variables to be setup
692 local -i i j col_total row
col button_total row_total remainder_cols remainder_term
694 button_total
=${#button_map[@]}
695 row_total
=$
(( button_total
/ col_total
))
696 remainder_cols
=$
(( button_total
% col_total
))
698 #dv button_total row_total remainder_cols
700 # - 3 is just a constant that helps things work in practice.
701 if [[ $LINES ]] && (( LINES
- 3 < scrolled
)); then
703 for (( i
=0; i
<button_total
; i
++)); do
704 row
=$
(( i
/ col_total
))
705 col=$
(( i
% col_total
))
706 remainder_term
=$remainder_cols
707 if (( col < remainder_term
)); then
710 j
=$
(( col * row_total
+ row
+ remainder_term
))
711 # avoid double newline when we have exactly row * col buttons
712 if (( i
== button_total
- 1 )); then
713 printf "%s %s" ${buttons[j]} ${button_map[j]}
714 elif (( i
% col_total
== col_total
-1 )); then
715 printf "%s %s\n" ${buttons[j]} ${button_map[j]}
717 printf "%s %-15s" ${buttons[j]} ${button_map[j]}
723 y other genres z fg player ' = toggle play 1-5 rate ] repeat1
724 ; previous _ = delete up/down skip mpv vol,pause,seek
731 # Must be called from beetag for variables to be setup
734 scrolled
=$
(( scrolled
+ $1 ))
736 if $erasable_line; then
737 # https://stackoverflow.com/a/71286261
738 # erase line / delete line in terminal
739 printf '\033[1A\033[K'
743 # meant to be called from beetag
745 if $erasable_line; then
746 # https://stackoverflow.com/a/71286261
747 printf '\033[1A\033[K'
752 # meant to be called from beetag
754 if jobs -p |
grep -q .
&>/dev
/null
; then
755 printf "%s\n" "$*" | socat
- /tmp
/mpvsock
>/dev
/null ||
:
758 # meant to be called from beetag
761 # note: testing for background jobs will output nothing if we are in a pipeline
762 printf "%s\n" "$*" | socat
- /tmp
/mpvsock ||
:
765 # meant to be called from beetag
766 mpvrpc-percent-pos
() {
767 mpvrpco
'{ "command": ["get_property", "percent-pos"] }' | jq .data |
sed 's/\..*/%/' 2>/dev
/null ||
:
770 # run if not running.
772 # Note: this does not work with shell scripts as they are normally
773 # invoked, because the ps output has the interpreter at the start.
774 # A workaround is to invoke the command in that format, or we could
775 # do various other workarounds.
777 # background, this relies on how ps converts newlines in arguments to spaces, and
778 # assumes we won't be searching for a command with spaces in its arguments
780 # shellcheck disable=SC2009 # pgrep has no fixed string option, plus see above.
781 if ps h
-o args
-C "${1##*/}" |
grep -Fxqv "$*" &>/dev
/null ||
[[ $?
== 141 ]]; then
785 # variation of above: run or wait if running
788 pid
=$
(ps h
-o 'pid,args' -C "${1##*/}" |
sed -r 's/^[[:space:]]*([0-9]+)[[:space:]](.*)/\1\n\2/' |
grep -B1 -Fx "$*" |
head -n1 ||
: )
790 # https://unix.stackexchange.com/questions/427115/listen-for-exit-of-process-given-pid
791 tail --pid="$pid" -f /dev
/null
798 local path nextpath cachedir finalpath nextpath count
799 cachedir
=$HOME/.iank-music-cache
803 # note: logic duplicated in beetpull
805 if [[ $HOSTNAME == kd
]]; then
810 finalpath
="$cachedir${path#/i/m}"
811 rowir rsync
--partial -a --inplace --mkpath "b8.nz:$path" "$finalpath"
812 finalnextpath
="$cachedir${nextpath#/i/m}"
813 count
=$
(pgrep
-a -f "^rsync --partial -a --inplace --mkpath $cachedir" ||
[[ $?
== 1 ]] )
814 # allow us to start 2 rsyncs in the background
815 if [[ $count == [01] ]]; then
816 rinr rsync
--partial -a --inplace --mkpath "b8.nz:$nextpath" "$finalnextpath" &
821 mpvrpc
'{ "command": ["loadfile", "'"$finalpath"'"] }'
825 # usage: beetag [-r] [-s] QUERY
826 # it lists the query, reads an input char for tagging one by one.
828 # note, you may want to change the play command for doing rapid taging
829 # by immediately jumping forward into the song. this is set in the beets
832 # (available buttons: ` \ ) ] [ and non-printing chars, see
833 # https://stackoverflow.com/questions/10679188/casing-arrow-keys-in-bash
836 # note: after foregrounding the player, must quit it to get back. can't ctrl-c.
838 # keys I dont need help to remember:
844 local last_genre_i fstring tag id char new_item char_i genre tag remove doplay i j random path
845 local do_rare_genres read_wait
help line lsout tmp ls_line skip_lookback
846 local escape_char escaped_input expected_input skip_input_regex right_pad erasable_line seek_sec
847 local pl_state_path pl_state_dir pl_state_file tmpstr
848 local new_random pl_seed_path seed_num seed_file
fmt first_play repeat1
849 local -a buttons button_map ids tags tmp_tags initial_ls ls_lines paths
851 local -i i j volume scrolled id_count line_int skip_start pre_j_count head_count skip_lookback
852 local -i overflow_lines overflow
856 escape_char
=$
(printf "\u1b")
857 scrolled
=999 # more than any $LINES
858 ### begin arg processing ###
877 echo beetag
: error expected a query arg
>&2
880 ### end arg processing ###
882 # note: I used to do beetpull here, but mpv + ssfs on slowish
883 # connection leads to bad/buggy result.
890 last_genre_i
=$
(( ${#common_genres[@]} - 1 ))
891 buttons
=( {a..p
} {r..w
} {6.
.8} , .
/ - "=")
892 button_map
=(${common_genres[@]} ${pl_tags[@]})
894 for tag
in "${pl_tags[@]}"; do
895 fstring
+="%ifdef{$tag,$tag }"
898 for (( i
=0; i
<${#buttons[@]}; i
++ )); do
899 button_i
[${buttons[i]}]=$i
902 # note: this structure of files is rather haphazard.
903 seed_num
=1 # later we might want a few
904 seed_file
=seed
$seed_num
906 pl_state_file
=$seed_num
910 pl_state_dir
=/i
/info
/pl-state
911 if [[ $playlist ]]; then
912 pl_state_dir
=$pl_state_dir/$playlist
914 pl_state_dir
=$pl_state_dir/nopl
916 pl_state_path
=$pl_state_dir/$pl_state_file
917 pl_seed_path
=$pl_state_dir/$seed_file
920 if $new_random ||
[[ ! -r $pl_seed_path ]]; then
921 mkdir
-p $pl_state_dir
922 { base64
< /dev
/urandom |
head -c 200 ||
:; echo; } > $pl_seed_path
925 # PijokVipiotOzeph is just a random string for a delimiter
926 # shellcheck disable=SC2016 # false positive
927 fmt='%ifdef{rating,$rating }'"$fstring"'$genre | $title - $artist - $album $length $id PijokVipiotOzeph $path'
928 # shellcheck disable=SC2016 # obvious reason
929 tmpstr
=$
(beet
ls -f "$fmt" "$@" |
{ if $random; then sort -R --random-source=$pl_seed_path; else cat; fi; } )
930 mapfile
-t initial_ls
<<<"$tmpstr"
931 if [[ ! ${initial_ls[0]} ]]; then
932 echo "beetag: error: no result from beet ls $*"
935 id_count
=${#initial_ls[@]}
936 for line
in "${initial_ls[@]}"; do
937 path
="${line#*PijokVipiotOzeph }"
938 # https://github.com/koalaman/shellcheck/issues/2171
939 # shellcheck disable=SC2190 # bug in shellcheck, looking at paths from an earlier function
941 line_no_path
="${line% PijokVipiotOzeph*}"
942 id
="${line_no_path##* }"
944 right_pad
="${line_no_path%% |*}"
945 ls_line
="$(printf %-11s "$right_pad")${line_no_path#"$right_pad"}"
946 ls_lines
+=("$ls_line")
954 if [[ $playlist ]]; then
955 if [[ -r $pl_state_path ]]; then
956 j
=$
(cat $pl_state_path)
960 # i only care to see a smallish portion of the list when starting.
961 head_count
=$
(( LINES
- 20 ))
962 head_start
=$
(( j
- head_count
/ 2 ))
963 if (( head_start
< 0 )); then
966 for (( i
=head_start
; i
< head_count
&& i
< id_count
; i
++ )); do
967 ls_line
="${ls_lines[$i]}"
968 if (( i
== j
)); then
975 #{ mpv --profile=a --volume=$volume --idle 2>&1 & } 2>/dev/null
976 mpv
--profile=a
--volume=$volume --idle &
977 # if we dont sleep, can expect an error like this:
978 # socat[1103381] E connect(5, AF=1 "/tmp/mpvsock", 14): Connection refused
985 lsout
="${ls_lines[j]}"
986 tags
=( ${lsout%%,*} )
988 printf "██ %s\n" "$lsout"
991 # https://stackoverflow.com/a/7687716
992 # note: duplicated down below
994 # notes on old method of invoking mpv each time:
995 # https://superuser.com/questions/305933/preventing-bash-from-displaying-done-when-a-background-command-finishes-execut
996 # we can't disown or run in a subshell or set +m because all that
997 # disabled job control from working properly in ways we want.
998 # todo: figure out some kind of answer to this. I think the solution
999 # is that we are waiting in 2 second intervals and checking if the
1000 # background job exists. Instead, we should make mpv just idle
1001 # when it is done with a song and then send it a command to play a new track.
1002 #{ mpv --profile=a --volume=$volume "$path" 2>&1 & } 2>/dev/null
1004 #{ beet play "--args=--volume=$volume" "id:$id" 2>&1 & } 2>/dev/null
1006 # on slow systems, we may need to wait like .3 seconds before mpv
1007 # is ready. so impatiently check until it is ready
1008 if $first_play; then
1010 for (( i
=0; i
<20; i
++ )); do
1011 if [[ $
(mpvrpco
'{ "command": ["get_property", "idle-active"] }' 2>/dev
/null | jq .data
) == true
]]; then
1012 mpvrpc-loadfile
"$path" 2>/dev
/null
1018 mpvrpc-loadfile
"$path"
1026 read -rsN1 -t $read_wait char || ret
=$?
1028 # Automatically skip to the next song if this one ends, unless
1029 # we turn off the autoplay.
1030 if (( ret
== 142 )) ||
[[ ! $char ]]; then
1031 if jobs -p |
grep -q .
&>/dev
/null
&& \
1032 [[ $
(mpvrpco
'{ "command": ["get_property", "idle-active"] }' | jq .data
) == false
]]; then
1042 if [[ $char == $
'\n' ]]; then
1052 echo "play toggled off"
1056 mpvrpc-loadfile
"$path"
1063 m beet
rm --delete --force "id:$id"
1064 beetag-nostatus
4 # guessing. dont want to test atm
1068 beetmq
"id:$id" rating
=$char
1072 volume
=$
(( volume
- 5 ))
1073 if (( volume
< 0 )); then
1079 if (( volume
> 130 )); then
1084 mpvrpc
'{ "command": ["set_property", "volume", '$volume'] }'
1095 echo repeat1
=$repeat1
1103 if $do_rare_genres; then
1104 do_rare_genres
=false
1105 button_map
=(${common_genres[@]} ${pl_tags[@]})
1106 last_genre_i
=$
(( ${#rare_genres[@]} - 1 ))
1109 button_map
=(${rare_genres[@]} ${pl_tags[@]})
1110 last_genre_i
=$
(( ${#rare_genres[@]} - 1 ))
1113 for (( i
=0; i
<${#buttons[@]}; i
++ )); do
1114 button_i
[${buttons[i]}]=$i
1116 for (( i
=0; i
<${#button_map[@]}; i
++ )); do
1117 echo ${buttons[i]} ${button_map[i]}
1123 # if we ctrl-z, it will put the whole function into sleep. so
1124 # basically, we can't return from a foregrounded mpv like we
1125 # would like to without some strange mechanism I can't think
1126 # of. So, instead, detect ctrl-c and wait a while for prompt
1127 # input. One idea would be to use a music player like mpd where
1128 # we can send it messages.
1137 # output time if we aren't already paused
1138 if [[ $
(mpvrpco
'{ "command": ["get_property", "pause"] }' | jq .data
) == false
]]; then
1140 #date -d @"$(mpvrpco '{ "command": ["get_property", "playback-time"] }' | jq .data)" +%M:%S ||:
1144 # originally found this solution, which worked fine.
1145 #kill -STOP %% &>/dev/null
1147 mpvrpc
'{ "command": ["cycle", "pause"] }'
1152 read -rsn2 escaped_input
1153 skip_input_regex
="^[0-9]+$"
1154 case $escaped_input in
1155 # up char: show all the songs, use less
1159 if (( j
- skip_lookback
> skip_start
)); then
1160 skip_start
=$
(( j
- skip_lookback
))
1162 beetag-nostatus $
(( id_count
- skip_start
- 1 ))
1165 for (( i
=skip_start
; i
< id_count
; i
++ )); do
1166 if (( i
== j
)); then
1167 echo " * ${ls_lines[i]}"
1170 echo "$line_int | ${ls_lines[i]}"
1177 # skip forward, but show the last few songs anyways.
1180 if (( j
- skip_lookback
> skip_start
)); then
1181 skip_start
=$
(( j
- skip_lookback
))
1183 beetag-nostatus $
(( id_count
- skip_start
- 1 ))
1186 overflow_lines
=$LINES
1187 for (( i
=skip_start
; i
< overflow_lines
- 1 && i
< id_count
; i
++ )); do
1188 ls_line
="${ls_lines[i]}"
1189 overflow
=$
(( ${#ls_line} / ( COLUMNS
- 1 ) ))
1190 overflow_lines
=$
(( overflow_lines
- overflow
))
1191 if (( i
== j
)); then
1195 echo "$line_int | $ls_line"
1211 mpvrpc
'{ "command": ["seek", "'$seek_sec'"] }'
1215 expected_input
=false
1218 if $expected_input; then
1226 if [[ $skip_input =~
$skip_input_regex ]]; then
1227 pre_j_count
=$
(( j
- skip_start
))
1228 j
=$
(( j
+ skip_input
- pre_j_count
))
1229 if (( skip_input
< pre_j_count
)); then
1237 char_i
=${button_i[$char]}
1238 new_item
=${button_map[$char_i]}
1239 if [[ ! $char_i ||
! $new_item ]]; then
1240 echo "error: no mapping of input: $char found, try again"
1243 if (( char_i
<= last_genre_i
)); then
1244 m beetmq
"id:$id" genre
=$new_item
1248 for tag
in ${tags[@]}; do
1249 if [[ $new_item == "$tag" ]]; then
1257 m beetmq
"id:$id" "$new_item!"
1260 m beetmq
"id:$id" $new_item=t
1265 if (( j
< id_count
- 1 )); then
1271 if [[ $playlist ]]; then
1272 echo $j >$pl_state_path
1277 # usage: FILE|ALBUM_DIR [GENRE]
1279 local import_path genre_arg single_track_arg
1281 if [[ ! -e $import_path ]]; then
1282 echo "beetadd error: path does not exist"
1285 genre_arg
="--set genre=$2"
1287 if [[ -f $import_path ]]; then
1290 beet import
--set totag
=t
$single_track_arg $genre_arg "$import_path"
1292 beet modify
-y totag
:t
"totag!"
1295 # update navidrome music data after doing beets tagging
1300 # this function would naturally just be part of beetconvert,
1301 # but we want beetrating to happen sooner so that our ssh auth dialog
1302 # happens earlier. Currently 17 seconds for that.
1303 m beetconvert-rm-extras
1304 m beetsmartplaylists
1307 # pull in beets library locally
1309 local sshfs_host sshfs_cmd
1311 if [[ $HOSTNAME == kd
]]; then
1314 if [[ ! -e /i
]]; then
1316 s chown iank
:iank
/i
1318 sshfs_cmd
="sshfs -o ServerAliveInterval=15,reconnect $sshfs_host:/i /i"
1319 if ! pgrep
-f "^$sshfs_cmd$" >/dev
/null
; then
1324 # remove all playlists in navidrome, for when I make big
1325 # playlist name changes and just want to scrap everything.
1329 if [[ $HOSTNAME != kd
]]; then
1330 echo "error: run on kd"
1333 sqlite3
/i
/navidrome
/navidrome.db
"select id from playlist" >$tmpf
1334 while read -r id
; do
1336 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"
1343 # This is not perfect but generally good enough. It escapes all
1344 # metachars listed man 3 pcrepattern.
1346 sed 's/[]\\^$.[|()?*+{}]/[&]/g; s/\^/\\^/g' <<<"$*"
1349 # usage beegenre QUERY
1351 # beet set genre for QUERY based on existing artist most used genre on
1353 # inverse of query for each artist found in QUERY. If query starts with
1354 # "artist:" it is used as the artist instead of each artist in QUERY.
1357 local count artist artregex genre singleartist tmpf tmpf2
1358 local -a artists genres
1369 if $singleartist; then
1370 # shellcheck disable=SC2016 # obvious reason
1371 beet
ls -f '$genre' "$artist" "${@/#/^}" |
sort |
uniq -c |
sort -n |
tail -n1 >$tmpf
1372 read -r count genre
<$tmpf ||
:
1373 beet modify
"$artist" "$@" genre
=$genre
1375 # shellcheck disable=SC2016 # obvious reason
1376 beet
ls -f '$artist' "$@" |
sort -u >$tmpf
1377 while read -r artist
; do
1378 artregex
=$
(er
"$artist")
1379 # shellcheck disable=SC2016 # obvious reason
1380 beet
ls -f '$genre' "artist::^$artregex$" "${@/#/^}" |
sort |
uniq -c |
sort -n |
tail -n1 >$tmpf2
1381 read -r count genre
<$tmpf2 ||
continue
1382 if [[ $count ]]; then
1383 artists
+=("$artregex")
1385 echo "beet modify -y $* \"artist::^$artist$\" genre=$genre # $count"
1388 read -r -N 1 -s -p "Y/n " char
1391 for (( i
=0; i
<${#artists[@]}; i
++ )); do
1392 beet modify
-y "$@" "artist::^${artists[i]}$" genre
=${genre[i]}
1405 date +%F_
%T
%:::z
-d "$(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<"$indate")" "$@"
1408 # fudCaHougfirp is a random string
1414 } |
sed -r 's/-0([45])( |$)/fudCaHougfirp0\100/;s/_/T/;s/[:-]//g;s/fudCaHougfirp/-/'
1419 while read -r line
; do
1420 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
1421 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*}"
1422 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}"
1423 mid
="${line:${#pre}:22}"
1424 echo "$pre$(btrbk-date "$mid")$post"
1431 jr
-u btrbk-run
-u btrbk
-u switch-mail-host
"$@"
1435 btrbk-host-debug-show-host
() {
1438 for host in $remote $alt local; do
1439 if line
=$
(grep -P "\S*$f" /tmp
/b
/s
/$host.log
); then
1440 if [[ $snaphost ]]; then
1441 e error
: snaphost
=$snaphost, host=$host line
="$line"
1443 if [[ $line == ssh* ]]; then
1444 tmp
="${line#ssh://}"
1445 snaphost
="${tmp%%/*}"
1451 echo $snaphost $f | btrbk-date-sed
1455 # If we get a btrfs receive error like this:
1456 # ERROR: ... clone: did not find source subvol
1457 # running this command will help track down the problem.
1458 # Alter remote= and alt=. When I used it, remote is
1459 # the host having the error when I push a snapshot.
1460 # Alt is just the other host that takes snapshots
1461 # besides the local host.
1462 btrbk-host-debug
() {
1468 for host in $remote $alt; do
1469 h
=$
(ssh $host hostname
)
1470 rsync
-a /var
/log
/btrbk
$host:/var
/log
/btrbk
/var
/log
/btrbk
/$h
1471 grr
'\bsnapshot success' /var
/log
/btrbk
/$h >/tmp
/b
/$h.log
1473 ## this takes a while, we only want to do it on 1st run
1474 # if [[ -s /tmp/b/$host.log ]]; then continue; fi
1475 # ssh $host journalctl -u btrbk-run -u btrbk -u switch-mail-host >/tmp/b/$host.log
1477 gr
'\bsnapshot success' /var
/log
/btrbk
/*.log
>/tmp
/b
/local.log
1480 gr
'\bsnapshot success' $f >s
/$f
1485 for f
in "${localq[@]}"; do
1490 for f
in $
(ssh $remote "cd /mnt/root/btrbk; echo q.*"); do
1491 if [[ ! ${localq_a[$f]} ]]; then
1495 btrbk-host-debug-show-host
"${localq[@]}"
1496 if (( ${#remoteq[@]} >= 1 )); then
1497 echo "=== $remote only ===="
1498 btrbk-host-debug-show-host
${remoteq[@]}
1503 # note, to check for glue records
1504 # First, find some the .org nameservers:
1505 # dig +trace iankelling.org
1507 # dig ns1.iankelling.org @b0.org.afilias-nst.org.
1509 # Now, compare for a domain that does have glue records setup (note the A
1510 # and AAAA records in ADDITIONAL SECTION, those are glue records like the
1511 # one I'm asking for):
1513 # $ dig ns1.gnu.org @b0.org.afilias-nst.org.
1515 # todo: make sm pull/push use systemd instead of the journal cat command
1516 bbk
() { # btrbk wrapper
1520 systemctl is-active btrbk.timer || active
=false
1522 ser stop btrbk.timer
1524 btrbk_is_active
=$
(systemctl is-active btrbk.service ||
:)
1525 case $btrbk_is_active in
1526 inactive|failed
) : ;;
1528 echo "bbk: error: systemctl is-active btrbk.service output: $btrbk_is_active"
1529 if $active; then ser start btrbk.timer
; fi
1533 # todo: consider changing this to srun and having the args come
1534 # from a file like /etc/default/btrbk, like is done in exim
1535 s jdo btrbk-run
"$@"
1538 echo bbk
: WARNING
: btrbk.timer not restarted due to failure
1540 ser start btrbk.timer
1547 fai-monitor | pee
cat "fai-monitor-gui -"
1550 bfg
() { java
-jar /a
/opt
/bfg-1.12
.14.jar
"$@"; }
1553 xclock
-digital -update 1 -face 'arial black-80:bold'
1556 nnn
() { /a
/opt
/nnn
-H "$@"; }
1558 locat
() { # log-once cat
1561 files
=(/var
/local
/cron-errors
/* /home
/iank
/cron-errors
/* /sysd-mail-once-state
/*)
1562 case ${#files[@]} in
1579 # usage: first get an adb shell on the phone.
1581 # just followed instructions in readme at
1582 # https://github.com/Yuubi-san/ceb-tools
1583 # tried to use ceb2txt but it failed because of schema
1584 # slightly different than what it expected.
1585 cheogram-get-logs
() {
1586 #adb shell rm -r /storage/emulated/0/Download/Cheogram/Backup
1587 read -r -p "do cheogram backup on phone, do not enable extra cheogram data. press any key when done"
1590 adb pull
/storage
/emulated
/0/Download
/Cheogram
/Backup
1591 sqlite3 b
</a
/opt
/ceb-tools
/schema.sql
1592 echo "note: the next step took 39 seconds last time i measured"
1593 # expected failure: Error: near line 1: in prepare, table accounts has no column named pinned_mechanism (1)
1594 # the sql needs an update
1595 /a
/opt
/ceb-tools
/ceb2sqlgz Backup
/iank@fsf.org.ceb
<pas | gunzip | sqlite3 b ||
:
1599 # usage: cheologs [DAYS_LIMIT]
1600 # default days is 100
1606 datetime(substr(timeSent,0,11), 'unixepoch'),
1607 replace(replace(counterpart,'@fsf.org',''),
1608 '@conference.fsf.org',''),
1611 where timeSent > $(( (EPOCHSECONDS - days * 60 * 60 * 24) * 1000 ))
1613 sqlite3
/p
/cheogram
/b
".mode tabs" "$q" |
less
1619 # timezone compared to utc. note: this takes the current offset, so if daylight savings change
1620 # happened in the looking back period, this won't account for it.
1621 zone_offset
=$
(( $
( date +%z |
sed 's/[^1-9-]*//g' ) * 60 * 60))
1622 case $zone_offset in
1624 *) zone_offset
="+ $zone_offset"
1626 echo zone_offset
=$zone_offset
1629 datetime(substr(timeSent,0,11) $zone_offset, 'unixepoch'),
1632 where timeSent > $(( (EPOCHSECONDS - days * 60 * 60 * 24) * 1000 ))
1633 and counterpart = 'office@conference.fsf.org/iank'
1635 sqlite3
/p
/cheogram
/b
".mode tabs" "$q" |
sed 's/ /./' |
less
1638 # version of jdo for my non-root user
1640 # comparison of alternative logging methods:
1642 # systemd-run command (what this function does)
1644 # If there is a user prompt, the program will detect that it is not
1645 # connected to a terminal and act in a non-interactive way, skipping
1646 # the prompt. This has the benefit that you know exactly how the
1647 # program will act if you want to move it into a service that runs
1650 # If run with sudo and command is a shell script which does a sleep,
1651 # it can (sometimes?) output some extra whitespace in front of
1652 # messages, more for each subsequent message. This can be avoided by
1653 # becoming root first.
1655 # It logs the command's pid and exit code, which is nice.
1658 ### command |& ts | tee file.log
1660 # If there is a user prompt, like "read -p prompt var", it will hang
1661 # without outputting the prompt.
1663 # I've had a few times where ts had an error and I wasn't totally sure
1664 # if it was really the command or ts having the problem.
1666 # Sometimes some output will get hidden until you hit enter.
1669 ### command |& pee cat logger
1671 # This seems to work. I need to test more.
1674 ### command |& logger -s
1676 # User prompts get confusingly prefixed to earlier output, and all log
1677 # entries get prefixed with annoying priority level.
1682 # Had a few problems. One major one is that it exited in the middle of
1683 # a command on systemctl daemon-reload
1685 # Related commands which can log a whole session: script, sudo, screen
1686 local cmd cmd_name jr_pid ret
1691 if [[ $cmd != /* ]]; then
1692 cmd
=$
(type -P "$cmd")
1695 journalctl
-qn2 -f -u "$cmd_name" &
1696 # Trial and error of time needed to avoid missing initial lines.
1697 # .5 was not reliable. 1 was not reliable. 2 was not reliable
1700 # note, we could have a version that does system --user, but if for example
1701 # it does sudo ssh, that will leave a process around that we can't kill
1702 # and it will leave the unit hanging around in a failed state needing manual
1703 # killing of the process.
1704 s systemd-run
--uid "$(id -u)" --gid "$(id -g)" \
1705 -E SSH_AUTH_SOCK
=/run
/openssh_agent \
1706 --unit "$cmd_name" --wait --collect "$cmd" "$@" || ret
=$?
1707 # The sleep lets the journal output its last line
1708 # before the prompt comes up.
1710 kill $jr_pid &>/dev
/null ||
:
1713 # this avoids any err-catch
1714 (( ret
== 0 )) ||
return $ret
1717 # service run, and watch the output
1722 journalctl
-qn2 -f -u $unit &
1723 systemctl start
$unit
1725 kill $jr_pid &>/dev
/null ||
:
1730 sm
() { # switch mail host
1734 keyhash
=$
(s ssh-keygen
-lf /root
/.ssh
/home |
awk '{print $2}')
1735 tmp
=$
(s ssh-add
-l |
awk '$2 == "'$keyhash'"' ||
:)
1736 if [[ ! $tmp ]]; then
1737 s ssh-add
/root
/.ssh
/home
1739 s jdo switch-mail-host
"$@"
1742 sh2
() { # switch host2
1746 keyhash
=$
(s ssh-keygen
-lf /root
/.ssh
/home |
awk '{print $2}')
1747 tmp
=$
(s ssh-add
-l |
awk '$2 == "'$keyhash'"')
1748 if [[ ! $tmp ]]; then
1749 s ssh-add
/root
/.ssh
/home
1752 s jdo switch-host2
"$@"
1756 # shellcheck disable=SC2120
1758 # note, i had --delete-excluded, but that deletes all files in --exclude-from on
1759 # the remote site, which doesn't make sense, so not sure why i had it.
1761 # excluding emacs for now
1762 #p=(/a/opt/{emacs-debian11{,-nox},mu,emacs} /a/bin /a/exe /a/h /a/c /p/c/machine_specific/vps{,.hosts})
1763 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
)
1764 a
="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
1766 for h
in li je bk
; do
1767 m s rsync
"$@" $a ${p[@]} /p
/c
/machine_specific
/$h root@
$h.b8.nz
:/
1768 ## only li is debian11
1769 #p[0]=/a/opt/emacs-trisuqel10
1770 #p[1]=/a/opt/emacs-trisquel10-nox
1772 m s rsync
"$@" -ahviSAXPH root@li.b8.nz
:/a
/h
/proposed-comments
/ /a
/h
/proposed-comments || ret
=$?
1775 bkpush
() { # no emacs. for running faster.
1776 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
)
1777 a
="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
1779 m rsync
"$@" $a ${p[@]} /p
/c
/machine_specific
/bk root@bk.b8.nz
:/ || ret
=$?
1782 jepush
() { # no emacs. for running faster.
1783 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
)
1784 a
="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
1786 m rsync
"$@" $a ${p[@]} /p
/c
/machine_specific
/je root@je.b8.nz
:/ || ret
=$?
1791 dsign iankelling.org expertpathologyreview.com zroe.org amnimal.ninja
1795 ssh $h.b8.nz
<<'EOF'
1805 ssh $h.b8.nz
<<'EOF'
1817 local f
=/var
/lib
/bind
/db.b8.nz
1820 m sudo
rm -fv $f.jnl
$f.signed.jnl
1821 m sudo
install -m 644 -o bind -g bind /p
/c
/machine_specific
/vps
/bind-initial
/db.b8.nz
$f
1825 # keys generated like this
1826 # because of https://ftp.isc.org/isc/dnssec-guide/dnssec-guide.pdf
1827 # https://blog.apnic.net/2019/05/23/how-to-deploying-dnssec-with-bind-and-ubuntu-server/
1829 # key length is longer than that guide because
1830 # we are using those at fsf and when old key lengths
1831 # become insecure, I want some extra time to update.
1832 # dnsecgen (in brc2)
1835 dnssec-keygen
-a RSASHA256
-b 2048 $zone
1836 dnssec-keygen
-f KSK
-a RSASHA256
-b 4096 $zone
1837 for f
in K
"$zone".
*.key
; do
1838 # eg Kb8.nz.+008+47995.key tag=47995
1839 # in dnsimple, you add the long string from this.
1840 # in gandi, you add the long string from the .key file,
1841 # then see that the digest matches the ds.
1842 echo "tag is the number after DS"
1843 dnssec-dsfromkey
-a SHA-256
$f
1845 # For b8.nz, we let bind read the keys and sign, and
1846 # right now they have root ownership, so let them
1848 chmod g
+r .
/*.private
1851 # create .signed file
1852 # note: full paths probably not needed.
1855 local zone
=${arg#db.}
1856 local dir
=/p
/c
/machine_specific
/vps
/filesystem
/var
/lib
/bind
1857 dnssec-signzone
-S -e +31536000 -o $zone -K $dir -d $dir $dir/db.
$zone
1861 # set day start for use in other programs.
1862 # expected to do be in a format like 830, or 800 or 1300.
1865 echo $1 >/b
/data
/daystart
1867 cat /b
/data
/daystart
1871 #### begin bitcoin related things
1873 local f
=/etc
/bitcoin
/bitcoin.conf
1874 # importprivkey will timeout if using the default of 15 mins.
1875 # upped it to 1 hour.
1876 bitcoin-cli
-rpcclienttimeout=60000 -"$(s grep rpcuser= $f)" -"$(s grep rpcpassword= $f)" "$@"
1878 btcusd
() { # $1 btc in usd
1880 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
1881 printf "$%s\n" "$price"
1883 printf "$%.2f\n" "$(echo "scale
=4; $price * $1"| bc -l)"
1886 usdbtc
() { # $1 usd in btc
1888 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
1889 printf "$%s\n" "$price"
1891 # 100 mil satoshi / btc. 8 digits after the 1.
1892 printf "%.8f btc\n" "$(echo "scale
=10; $1 / $price "| bc -l)"
1895 satoshi
() { # $1 satoshi in usd
1897 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
1898 price
=$
(echo "scale=10; $price * 0.00000001"|
bc -l)
1899 printf "$%f\n" "$price"
1901 printf "$%.2f\n" "$(echo "scale
=10; $price * $1"| bc -l)"
1905 # Bitcoin holds open the wallet file. this causes problems for a
1906 # secondary computer running bitcoin and receiving a backup (as of
1907 # 2023). However, in 2024-02, I ran a backup where a receiving machine
1908 # had the wallet enabled and there was no error, so I don't know if this
1909 # is still an issue or likely it is an inconsistent behavior.
1911 # As a workaround, this function is for enabling the wallet when I want
1912 # to use it and leave it disabled otherwise.
1917 if [[ ! $
(readlink
-f /var
/lib
/bitcoind
/wallets
) == /q
/wallets
]]; then
1918 if systemctl
--quiet is-active bitcoind
; then
1919 if [[ -e /tmp
/no-bitcoinon
]]; then
1922 if [[ $EUID == 0 ]]; then
1923 m
install -T -o iank
-g iank
/dev
/null
/tmp
/no-bitcoinon
1925 m
touch /tmp
/no-bitcoinon
1931 m s
ln -s /q
/wallets
/var
/lib
/bitcoind
1932 sudo chown
-h bitcoin
:bitcoin
/var
/lib
/bitcoind
/wallets
1934 m ser start bitcoind
1936 m
rm /tmp
/no-bitcoinon
1945 if [[ $
(readlink
-f /var
/lib
/bitcoind
/wallets
) == /q
/wallets
]]; then
1946 if systemctl
--quiet is-active bitcoind
; then
1947 if [[ -e /tmp
/no-bitcoinon
]]; then
1950 if [[ $EUID == 0 ]]; then
1951 m
install -T -o iank
-g iank
/dev
/null
/tmp
/no-bitcoinon
1953 m
touch /tmp
/no-bitcoinon
1959 echo note
: bitcoind not active
1961 m
rm /var
/lib
/bitcoind
/wallets
1963 # note, starting bitcoin always fails, but it actually
1964 # succeeds. But this is strangely not consistent.
1965 m ser start bitcoind
1967 m
rm /tmp
/no-bitcoinon
1972 #### end bitcoin related things
1976 cbfstool
() { /a
/opt
/coreboot
/build
/cbfstool
"$@"; }
1982 cp /a
/bin
/data
/COPYING
"$@"
1984 cp /a
/bin
/data
/COPYING .
1991 cp /a
/bin
/data
/LICENSE
"$@"
1993 cp /a
/bin
/data
/LICENSE .
2000 # First paragraph is to avoid people being confused about why a
2001 # file is apache licensed.
2003 # I, Ian Kelling, follow the GNU license recommendations at
2004 # https://www.gnu.org/licenses/license-recommendations.en.html. They
2005 # recommend that small programs, < 300 lines, be licensed under the
2006 # Apache License 2.0. This file contains or is part of one or more small
2007 # programs. If a small program grows beyond 300 lines, I plan to switch
2008 # its license to GPL.
2010 # Copyright 2024 Ian Kelling
2012 # Licensed under the Apache License, Version 2.0 (the "License");
2013 # you may not use this file except in compliance with the License.
2014 # You may obtain a copy of the License at
2016 # http://www.apache.org/licenses/LICENSE-2.0
2018 # Unless required by applicable law or agreed to in writing, software
2019 # distributed under the License is distributed on an "AS IS" BASIS,
2020 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2021 # See the License for the specific language governing permissions and
2022 # limitations under the License.
2028 # apply apache to git tracked bash files + README, except files with A?GPL3 header.
2029 apache-apply-repo
() {
2030 for f
in $
(git ls-files
); do
2031 [[ -L $f ||
! -f $f ]] && continue
2032 if [[ $f != README
]]; then
2033 if ! grep -n '^#!/bin/bash' $f |
grep ^
1: &>/dev
/null
; then continue; fi
2034 if head -n 10 $f |
grep 'it under the terms of the GNU General Public License as published by' &>/dev
/null
; then continue; fi
2042 if head -n1 "$file"|
grep -E '^#!/bin/bash\b' &>/dev
/null
; then
2056 # strip out the apache license from a file.
2058 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
2062 if type -p chromium
&>/dev
/null
; then
2066 cmd
="schroot -c bullseye chromium"
2067 CHROMIUM_FLAGS
='--enable-remote-extensions' $cmd & r
2073 # pipe to this, or just type like a shell
2076 tee >(ssh frodo.b8.nz
) >(ssh x2
) >(ssh tp.b8.nz
) >(ssh kw
) >(ssh tp.b8.nz
)
2080 for host in x2 kw tp.b8.nz x3.b8.nz frodo.b8.nz
; do
2086 debian_pick_mirror
() {
2087 # netselect-apt finds a fast mirror.
2088 # but we need to replace the mirrors ourselves,
2089 # because it doesnt do that. best it can do is
2090 # output a basic sources file
2091 # here we get the server it found, get the main server we use
2092 # then substitute all instances of one for the other in the sources file
2093 # and backup original to /etc/apt/sources.list-original.
2094 # this is idempotent. the only way to identify debian sources is to
2095 # note the original server, so we put it in a comment so we can
2096 # identify it later.
2098 file=$
(mktemp
-d)/f
# safe way to get file name without creating one
2099 sudo netselect-apt
-o "$file" ||
return 1
2100 url
=$
(grep ^
\\w
$file |
head -n1 |
awk '{print $2}')
2101 sudo
cp -f /etc
/apt
/sources.list
/etc
/apt
/sources.list-original
2102 sudo
sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc
/apt
/sources.list
2106 digdiff @ns
{1,2}.iankelling.org
"$@"
2116 /b
/ds
/distro-begin |
& ts ||
return $?
2117 /b
/ds
/distro-end |
& ts ||
return $?
2123 /b
/ds
/distro-begin |
& ts ||
return $?
2129 /b
/ds
/distro-end |
& ts ||
return $?
2142 envload
() { # load environment from a previous: export > file
2143 local file=${1:-$HOME/.${USER}_env}
2144 eval "$(export | sed 's/^declare -x/export -n/')"
2145 while IFS
= read -r line
; do
2146 # declare -x makes variables local to a function
2147 eval ${line/#declare -x/export}
2151 failfunc
() { asdf a b c
; }
2152 failfunc2
() { failfunc d e f
; }
2154 # one that comes with distros is too old for newer devices
2156 /a
/opt
/android-platform-tools
/fastboot
"$@";
2159 kdecd
() { /usr
/lib
/x86_64-linux-gnu
/libexec
/kdeconnectd
; }
2162 cat /sys
/class
/power_supply
/BAT
0/capacity
2165 # List of apps to install/update
2166 # Create from existing manually installed apps by doing
2168 # fdroidcl search -i, then manually removing
2169 # automatically installed/preinstalled apps
2172 # # my attempt at recovering from boot loop:
2173 # # in that case, boot to recovery (volume up, home button, power, let go of power after samsun logo)
2175 # mount /dev/block/mmcblk0p12 /data
2177 # find -iname '*appname*'
2179 # usually good enough to just rm -rf /data/app/APPNAME
2182 # # causes replicant to crash
2183 # org.quantumbadger.redreader
2184 # org.kde.kdeconnect_tp
2186 # not broke, but wont work without gps
2187 #com.zoffcc.applications.zanavi
2188 # not broke, but not using atm
2189 #com.nutomic.syncthingandroid
2190 # # doesn\'t work on replicant
2191 #net.sourceforge.opencamera
2194 net.mullvad.mullvadvpn
2196 io.github.subhamtyagi.lastlauncher
2198 com.biglybt.android.client
2199 de.marmaro.krt.ffupdater
2200 me.ccrama.redditslide
2201 org.fedorahosted.freeotp
2203 com.alaskalinuxuser.justnotes
2204 com.artifex.mupdf.viewer.app
2205 com.danielkim.soundrecorder
2208 com.jmstudios.redmoon
2210 org.kde.kdeconnect_tp
2213 cz.martykan.forecastie
2214 de.danoeh.antennapod
2216 de.marmaro.krt.ffupdater
2217 eu.siacs.conversations
2219 im.vector.alpha
# riot
2220 info.papdt.blackblub
2221 me.tripsit.tripmobile
2223 net.minetest.minetest
2228 org.smssecure.smssecure
2230 sh.
ftp.rocketninelabs.meditationassistant.opensource
2232 # https://forum.xda-developers.com/android/software-hacking/wip-selinux-capable-superuser-t3216394
2237 local -A installed updated
2239 # tried putting this in go buildscript cronjob,
2240 # but it failed with undefined: os.UserCacheDir. I expect its due to
2241 # an environment variable missing, but its easier just to stick it here.
2242 m go get
-u mvdan.cc
/fdroidcl ||
return 1
2244 if fdroidcl search
-u |
grep ^org.fdroid.fdroid
; then
2245 fdroidcl
install org.fdroid.fdroid
2249 for p
in $
(fdroidcl search
-i|
grep -o "^\S\+"); do
2252 for p
in $
(fdroidcl search
-u|
grep -o "^\S\+"); do
2255 for p
in ${fdroid_pkgs[@]}; do
2256 if ! ${installed[$p]:-false}; then
2257 m fdroidcl
install $p
2258 # sleeps are just me being paranoid since replicant has a history of crashing when certain apps are installed
2262 for p
in ${!installed[@]}; do
2263 if ! ${updated[$p]:-true}; then
2264 m fdroidcl
install $p
2270 firefox-default-profile
() {
2271 local key value section
2275 file=/p
/c
/subdir_files
/.mozilla
/firefox
/profiles.ini
2276 sed -ri "/^ *$key/d" "$file"
2277 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*${key}[[:space:]=]/d};/ *\[$section\]/a $key=$value" "$file"
2279 fdhome
() { #firefox default home profile
2280 firefox-default-profile Profile0
2284 firefox-default-profile Profile4
2288 if type -P firefox
&>/dev
/null
; then
2296 firefox
-P alt
"$@" >/dev
/null
2>&1
2302 local dname
="${PWD##*/}"
2303 local m
="/a/tmp/$dname-missing"
2304 local d
="/a/tmp/$dname-diff"
2305 [[ -e $d ]] && rm "$d"
2306 [[ -e $m ]] && rm "$m"
2309 while read -r line
; do
2310 fsfile
="$1${line#.}"
2311 if [[ -e "$fsfile" ]]; then
2312 md5diff
"$line" "$fsfile" && tee -a "/a/tmp/$dname-diff" <<< "$fsfile $line"
2315 echo "$line" >> "$m"
2316 msize
=$
((msize
+ 1))
2318 done < <(find .
-type f
)
2321 (( msize
<= 100 )) && cat $m
2326 # expected output, with different tmp dirs
2327 # /tmp/tmp.HDPbwMqdC9/c/d ./c/d
2328 # /a/tmp/tmp.qLDkYxBYPM-missing
2339 echo different
> $x/c
/d
2345 # test whether missing files were renamed, generally for use with fsdiff
2346 # $1 = fsdiff output file, $2 = directory to compare to. pwd = fsdiff dir
2347 # echos non-renamed files
2351 { sums
+=( "$(md5sum < "$x")" ) ; } 2>/dev
/null
2353 while read -r line
; do
2354 { missing_sum
=$
(md5sum < "$line") ; } 2>/dev
/null
2356 for x
in "${sums[@]}"; do
2357 if [[ $missing_sum == "$x" ]]; then
2362 $renamed ||
echo "$line"
2368 # F = fullscren, z = random, Z = auto zoom
2369 command feh
--auto-rotate -FzZ "$@"
2375 firefox
-P default
"$@" >/dev
/null
2>&1
2379 git config user.email ian@iankelling.org
2382 # at least in flidas, things rely on gpg being gpg1
2384 if type -P gpg2
&>/dev
/null
; then
2392 local email
=iank@fsf.org
2393 git send-email
--notes "--envelope-sender=<$email>" \
2394 --suppress-cc=self
"$@"
2397 gup
() { /a
/f
/gnulib
/build-aux
/gnupload
"$@"; }
2399 dejagnu
() { /a
/opt
/dejagnu
/dejagnu
"$@"; }
2402 # do git status on published repos.
2405 cd "$(readlink -f $x)"/..
2406 status
=$
(i status
-s) ||
pwd
2407 if [[ $status ]]; then
2410 printf "%s\n" "$status"
2418 # note: database location is specified in ~/.timetrap.yml, currently /p/.timetrap.db
2420 local day i days_back
2422 for (( i
=days_back
; i
>=0; i--
)); do
2423 day
=$
( date +%F
-d @$
((EPOCHSECONDS
- 86400*i
)) )
2424 date "+%a %b %d" -d @$
((EPOCHSECONDS
- 86400*i
)) |
tr '\n' ' '
2425 /a
/opt
/timetrap
/bin
/t d
-ftotal -s $day -e $day all
-m '^w|lunch$'
2428 to
() { t out
-a "$@"; }
2429 ti
() { t
in -a "$@"; }
2435 in_secs
="$(date -d "${*//[_.]/ }" +%s)"
2436 m t out
-a "$(date +%F.%T -d @$(( in_secs + 60*45 )) )"
2441 # help me focus. opens 2 windows.
2443 /p
/c
/proc
/focus
/linux-amd64
/focus
&
2449 # Display a list of the active window title
2450 # i've been on with 10 second samples going back
2451 # 5 minutes. If I've been on one window for 10 seconds
2452 # or longer, then display the second count.
2454 # Press any key to exit.
2457 killall arbtt-capture
&>/dev
/null ||
:
2458 rm -f ~
/.arbtt
/capture.log
2459 arbtt-capture
--sample-rate=10 &
2463 # i first thought to sleep and capture ctrl-c, but it seems we can't
2464 # capture control-c, unless maybe we implement the commands in a
2465 # separate script or maybe add err-cleanup to err. Anyways, this
2466 # method is superior because any single char exits.
2467 read -rsN1 -t 5 char || ret
=$?
2468 if (( ret
== 142 )) ||
[[ ! $char ]]; then
2470 #e ret=$ret char=$char
2473 killall arbtt-capture ||
:
2481 local i j l sec blanks line
2482 local -a arbtt_lines
2483 if [[ ! -e ~
/.arbtt
/capture.log
]]; then
2486 blanks
=$
(( LINES
- 34 ))
2487 for (( i
=0; i
< blanks
; i
++ )); do
2494 # https://stackoverflow.com/questions/56486272/how-to-concat-multiple-fields-to-same-line-with-jq
2495 arbtt_lines
=$
(arbtt-dump
-l 30 -t json | \
2496 jq
-r '.[] | [ ( .inactive / 1000 | floor ) , ( .windows[] | select (.active == true) |.title) ] | @tsv' |
tac)
2497 for line
in "${arbtt_lines[@]}"; do
2498 read -r sec l
<<<"$line"
2499 if (( j
>= LINES
)); then
2502 if (( i
% 6 == 0 && i
>= 2 )); then
2504 echo "## $(( i / 6 + 1 )) ##"
2506 if (( sec
> 10 )); then
2507 printf "%3d %s\n" $sec "$l" |
sed -r "s/^(.{$COLUMNS}).*/\1/"
2509 printf " %s\n" "$l" |
sed -r "s/^(.{$COLUMNS}).*/\1/"
2514 while (( j
< 34 && j
< LINES
)); do
2522 # from the log, show only the currently active window, and the number of
2523 # seconds of input inactivity.
2524 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}' ; }
2527 /a
/opt
/idea-IC-163.7743
.44/bin
/idea.sh
"$@" & r
2531 d
=/var
/lib
/znc
/moddata
/log
/iank
/
2532 for n
in freenode libera
; do
2535 for x
in "#$1/"*; do
2540 if [[ -e $tmp ]]; then
2544 sed \"s
/^.
/${base%log}/\" ${files[@]}|
sort -n
2550 sl root@iankelling.org ilogs-local
"$@"
2557 d
=/var
/lib
/znc
/moddata
/log
/iank
/
2558 for n
in freenode libera
; do
2559 if [[ ! -d $d$n/"$chan" ]]; then
2565 echo $x; sed "s/^./${x%log}/" $x; hr
;
2571 chan
="${1:-#fsfsys}"
2572 # use * instead of -r since that does sorted order
2573 sl root@iankelling.org ilog-local
"$chan" |
less +G
2577 if type gio
&> /dev
/null
; then
2579 elif type gvfs-open
&> /dev
/null
; then
2584 # another alternative is run-mailcap
2589 # grep -Evi -e "^(\S+\s+){4}(sudo|sshd|cron)\[\S*:" \
2590 # -e "^(\S+\s+){4}systemd\[\S*: (starting|started) (btrfsmaintstop|dynamicipupdate|spamd dns bug fix cronjob|rss2email)\.*$"
2593 # journalctl -n 10000 -f "$@" | jfilter
2595 # jr() { journalctl "$@" | jfilter | less ; }
2596 # jrf() { journalctl -n 200 -f "$@" | jfilter; }
2599 ## old version for model01. i need to get that firmware working again.
2600 # kff() { # keyboardio firmware flash. you must hold down the tilde key
2601 # pushd /a/opt/Model01-Firmware
2602 # # if we didn't want this yes hack, then remove "shell read" from
2603 # # /a/opt/Kaleidoscope/etc/makefiles/sketch.mk
2604 # yes $'\n' | VERBOSE=1 make flash
2610 pushd /a
/opt
/Kaleidoscope
/examples
/Devices
/Keyboardio
/Model100
2616 local umask_orig name
2617 if (( $# != 1 )); then
2618 e expected
1 arg
>&2
2624 wg genkey |
tee $name-priv.key | wg pubkey
> $name-pub.key
2630 # note: 1, 4, 5 are occupied by mail wireguard
2640 local host ipsuf f files
2641 for host in ${!vpn_ips[@]}; do
2642 ipsuf
=${vpn_ips[$host]}
2644 u
/a
/bin
/ds
/machine_specific
/$host/filesystem
/etc
/systemd
/system
/openvpn-client-tr@.service
<<EOF
2646 Description=OpenVPN tunnel for %I
2647 After=syslog.target network-online.target
2648 Wants=network-online.target
2649 Documentation=man:openvpn(8)
2650 Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
2651 Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
2652 Requires=iptables.service
2656 RuntimeDirectory=openvpn-client
2657 RuntimeDirectoryMode=0710
2658 WorkingDirectory=/etc/openvpn/client
2659 ExecStart=/usr/sbin/openvpn --suppress-timestamps --nobind --config /etc/openvpn/client/%i.conf
2660 # todo, try reenabling this from the default openvpn,
2661 # it was disabled so we could do bind mounts as a command,
2662 # but now systemd handles it
2663 #CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE
2665 # DeviceAllow=/dev/null rw
2666 # DeviceAllow=/dev/net/tun rw
2668 # we use .1 to make this be on a different network than kd, so that we can
2669 # talk to transmission on kd from remote host, and still use this
2671 ExecStartPre=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.174.$ipsuf start %i
2672 ExecStartPre=/sbin/iptables-restore /a/bin/distro-setup/transmission-firewall/netns.rules
2673 # allow wireguard network to connect
2674 ExecStartPre=/usr/sbin/ip r add 10.8.0.0/24 via 10.174.$ipsuf.1 dev veth1-client
2675 ExecStopPost=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns stop %i
2677 BindReadOnlyPaths=/etc/tr-resolv:/run/systemd/resolve:norbind /etc/basic-nsswitch:/etc/resolved-nsswitch:norbind
2680 WantedBy=multi-user.target
2685 for host in ${!vpn_ips[@]}; do
2686 ipsuf
=${vpn_ips[$host]}
2688 local-data-ptr: "10.2.0.$ipsuf $host.b8.nz"
2691 } | u
/b
/ds
/ptr-data
2694 for host in ${!vpn_ips[@]}; do
2695 ipsuf
=${vpn_ips[$host]}
2697 $host A 10.2.0.$ipsuf
2698 ${host}wg A 10.8.0.$ipsuf
2699 ${host}vp A 10.5.5.$ipsuf
2700 ${host}tr A 10.174.$ipsuf.2
2703 } | cedit vpn-ips-update
/p
/c
/machine_specific
/vps
/bind-initial
/db.b8.nz ||
:
2706 echo checking
for stray files
:
2709 cd /a
/bin
/ds
/machine_specific
2711 files
=( */filesystem
/etc
/systemd
/system
/openvpn-client-tr@.service
)
2714 for f
in "${files[@]}"; do
2716 if [[ ! ${vpn_ips[$host]} ]]; then
2717 e
/a
/bin
/ds
/machine_specific
/$host/filesystem
/etc
/systemd
/system
/openvpn-client-tr@.service
2721 cd /p
/c
/machine_specific
2723 files
=( */filesystem
/etc
/wireguard
/wghole.conf
)
2726 for f
in "${files[@]}"; do
2728 if [[ ! ${vpn_ips[$host]} ]]; then
2729 e
/p
/c
/machine_specific
/$host/filesystem
/etc
/wireguard
/wghole.conf
2730 e cedit
-s $host /p
/c
/machine_specific
/li
/filesystem
/etc
/wireguard
/wgmail.conf
'<<<""'
2735 # usage host ipsuf [extrahost]
2737 # If the keys already exist and you want new ones, remove them:
2738 # rm /p/c/machine_specific/$host/filesystem/etc/wireguard/hole-{priv,pub}.key
2740 # extrahost is a host/cidr that is allowed to go be routed through the
2743 if (( $# < 2 ||
$# > 3 )); then
2744 e expected
2-3 arg of hostname
, ip suffix
, and extrahost
>&2
2747 local host ipsuf umask_orig vpn_allowed
2753 for vpn_host
in ${!vpn_ips[@]}; do
2754 if [[ $vpn_host == "$host" ]]; then
2757 vpn_allowed
+=",10.174.${vpn_ips[$vpn_host]}.2/32"
2759 mkdir
-p /p
/c
/machine_specific
/$host/filesystem
/etc
/wireguard
2761 cd /p
/c
/machine_specific
/$host/filesystem
/etc
/wireguard
2764 if [[ ! -s hole-priv.key ||
! -s hole-pub.key
]]; then
2765 wg genkey |
tee hole-priv.key | wg pubkey
> hole-pub.key
2767 cat >wghole.conf
<<EOF
2769 # contents hole-priv.key
2770 PrivateKey = $(cat hole-priv.key)
2772 Address = 10.8.0.$ipsuf/24
2773 # https://dev.to/tangramvision/what-they-don-t-tell-you-about-setting-up-a-wireguard-vpn-1h2g
2774 # ||: makes the systemd service not fail due to the failed command
2775 PostUp = ping -w10 -c1 10.8.0.1 ||:
2778 # li. called wgmail on that server
2779 PublicKey = CTFsje45qLAU44AbX71Vo+xFJ6rt7Cu6+vdMGyWjBjU=
2780 AllowedIPs = 10.8.0.0/24$vpn_allowed$extrahost
2781 Endpoint = 72.14.176.105:1194
2782 PersistentKeepalive = 25
2785 # old approach. systemd seems to work fine and cleaner.
2786 rm -f ..
/network
/interfaces.d
/wghole
2787 cedit
-q $host /p
/c
/machine_specific
/li
/filesystem
/etc
/wireguard
/wgmail.conf
<<EOF || [[ $? == 1 ]]
2789 PublicKey = $(cat hole-pub.key)
2790 AllowedIPs = 10.8.0.$ipsuf/32,10.174.${vpn_ips[$host]}.2/32
2796 mns
() { # mount namespace
2799 s mkdir
-p /root
/mount_namespaces
2800 if ! sudo mountpoint
/root
/mount_namespaces
>/dev
/null
; then
2801 m sudo mount
--bind /root
/mount_namespaces
/root
/mount_namespaces
2803 m sudo mount
--make-private /root
/mount_namespaces
2804 if [[ ! -e /root
/mount_namespaces
/$ns ]]; then
2805 m sudo
touch /root
/mount_namespaces
/$ns
2807 if ! sudo mountpoint
/root
/mount_namespaces
/$ns >/dev
/null
; then
2808 m sudo unshare
--propagation slave
--mount=/root
/mount_namespaces
/$ns /bin
/true
2810 m sudo
-E /usr
/bin
/nsenter
--mount=/root
/mount_namespaces
/$ns "$@"
2813 mnsd
() { # mount namespace + systemd namespace
2818 s mkdir
-p /root
/mount_namespaces
2819 if ! sudo mountpoint
/root
/mount_namespaces
>/dev
/null
; then
2820 m sudo mount
--bind /root
/mount_namespaces
/root
/mount_namespaces
2822 m sudo mount
--make-private /root
/mount_namespaces
2823 if [[ ! -e /root
/mount_namespaces
/$ns ]]; then
2824 m sudo
touch /root
/mount_namespaces
/$ns
2826 if ! sudo mountpoint
/root
/mount_namespaces
/$ns >/dev
/null
; then
2827 m sudo unshare
--propagation slave
--mount=/root
/mount_namespaces
/$ns /bin
/true
2830 pid
=$
(servicepid
$unit)
2831 tmpf
=$
(mktemp
--tmpdir $unit.XXXXXXXXXX
)
2833 printf "%s " "${@@Q}" >>$tmpf
2836 m sudo nsenter
-t $pid -n --mount=/root
/mount_namespaces
/$ns sudo
-u $USER -i bash
-c ". $tmpf & sleep 1; rm $tmpf"
2843 mns
$ns sudo
-u iank
-E env
"PATH=$PATH" "$@"
2849 if ! s ip netns list |
grep -Fx nonet
&>/dev
/null
; then
2850 s ip netns add nonet
2852 mns
$ns --net=/var
/run
/netns
/nonet
/bin
/bash
2859 if ! s ip netns list |
grep -Fx nonet
&>/dev
/null
; then
2860 s ip netns add nonet
2862 mns
$ns --net=/var
/run
/netns
/nonet sudo
-E -u iank
/bin
/bash
2868 # l = the loopback device
2870 # get sudo pass cached right away
2871 if ! sudo
-nv 2>/dev
/null
; then
2874 if [[ $1 == /* ]]; then
2877 if mns
$base mountpoint
-q /mnt
/$base; then
2880 l
=$
(losetup
-j $fs_file |
sed -rn 's/^([^ ]+): .*/\1/p' |
head -n1 ||
:)
2882 l
=$
(sudo losetup
-f)
2883 m sudo losetup
$l $fs_file
2885 if ! sudo cryptsetup status
/dev
/mapper
/$base &>/dev
/null
; then
2886 if ! m sudo cryptsetup luksOpen
$l $base; then
2887 m sudo losetup
-d $l
2891 m sudo mkdir
-p /mnt
/$base
2892 m mns
$base mount
/dev
/mapper
/$base /mnt
/$base
2893 m mns
$base chown
$USER:$USER /mnt
/$base
2897 if mns
$base mountpoint
/mnt
/$base &>/dev
/null
; then
2898 m mns
$base umount
/mnt
/$base
2900 if sudo cryptsetup status
/dev
/mapper
/$base &>/dev
/null
; then
2901 if ! m sudo cryptsetup luksClose
/dev
/mapper
/$base; then
2902 echo lom
: failed cryptsetup luksClose
/dev
/mapper
/$base
2906 l
=$
(losetup
-l --noheadings |
awk '$6 ~ /\/'$base'$/ {print $1}')
2908 m sudo losetup
-d $l
2910 echo lom
: warning
: no loopback device found
2915 # mu personality. for original, just run mp. for 2, run mp 2.
2916 # this is partly duplicated in mail-setup
2920 if ! killall mu
; then
2927 echo error
: mu not dead
2932 set -- /m
/mucache ~
/.cache
/mu
/m
/.mu ~
/.config
/mu
2937 if [[ -e $f && ! -L $f ]]; then
2940 m
ln -sf -T $target $f
2946 local md dst ln_path src two
2950 -2) two
=true
shift ;;
2962 for d
in /m
/md
/$md /m
/4e
2/$md; do
2963 if [[ -d $d && ! -L $d ]]; then
2968 if [[ ! $src ]]; then
2969 echo "error: could not find $md" >&2
2973 m
ln -sf -T $dst $ln_path
2983 ### begin copied from mdenable, but different d ###
2984 for d
in /m
/4e
/$md /m
/4e
2/$md; do
2985 if [[ -d $d && ! -L $d ]]; then
2990 if [[ ! $src ]]; then
2991 echo "error: could not find $md" >&2
2994 ### end copy from mdenable ###
2996 if [[ -L $dst ]]; then m
rm $dst; fi
3002 markdown
"$1" >/tmp
/mdtest.html
3003 firefox
/tmp
/mdtest.html
3006 mo
() { xset dpms force off
; } # monitor off
3009 # seems to be the best gpu decoding on my nvidia 670.
3010 # vlc gets similar or better framerate, but is much darker output on my test movie at least.
3015 echo 0f | sudo
tee -a /sys
/kernel
/debug
/dri
/0/pstate
3018 # going back to the default slow clock, and slower fan:
3019 # echo 07 | sudo tee -a /sys/kernel/debug/dri/0/pstate
3020 if [[ $DISPLAY ]]; then
3021 mpv
--vo=vdpau
--hwdec=auto
"$@"
3023 # waylandvk seems to work the same
3024 mpv
--gpu-context=wayland
--hwdec=auto
3029 mpv
--profile=d
"$@";
3032 mpv
--profile=a
"$@";
3034 # mpv all media files in . or $1
3036 local -a extensions arg
3037 # get page source of https://en.wikipedia.org/w/index.php?title=Video_file_format&action=edit
3038 # into /a/x.log, then
3039 # grep '^| *\.' /a/x.log | sed 's/| *//;s/,//g'
3041 # note: to join them together for a regex, do:
3042 # old=; for e in ${extensions[@]/./}; do if [[ ! $old ]]; then old=$e; continue; fi; echo -n "$old|"; old=$e; done; echo $e
3065 .mpg .mp2 .mpeg .mpe .mpv
3075 arg
=("(" -iname "*${extensions[0]}")
3076 for (( i
=1 ; i
< ${#extensions[@]}; i
++ )); do
3077 arg
+=(-o -iname "*${extensions[i]}")
3082 #find $dir "${arg[@]}" -size +200k
3083 find $dir "${arg[@]}" -size +200k
-exec mpv
--profile=d
'{}' +
3086 mpv
--profile=s
"$@";
3094 d
=( /var
/lib
/znc
/moddata
/log
/iank
/{freenode
,libera
} )
3095 # use * instead of -r since that does sorted order
3096 ssh root@iankelling.org
"for f in ${d[*]}; do cd \$f/#$1; grep '\<iank.*' *; done" | cut
--complement -c12-16
3102 d
=/var
/lib
/znc
/moddata
/log
/iank
/freenode
3103 ssh root@iankelling.org
"cd $d; find . -mtime -60 -type f -exec grep '\<iank.*' {} +" |
sed -r 's,^..([^/]*)/(.{11})(.{5})(.{8}).,\2\4 \1,' |
sort
3106 # The way pidgin logs with xmpp (maybe related to running cheogram too)
3107 # is that there are sometimes duplicates, and sometimes the a log file
3108 # is for a specific day yet logs messages for subsequent days, and the
3109 # only way to realize that is to notice that the timestamps rolled over
3110 # into a new day, you can't see it in isolation. So, basically, pidgin
3111 # logs are really annoying to read a grep of my messages to find the
3112 # date and time I said when I started and stopped working, so I'm trying
3113 # out a new client: profanity.
3115 c
/p
/c
/.purple
/logs
/jabber
/iank@fsf.org
/office@conference.fsf.org.chat
3116 for x
in *.html
; do html2text
-o ${x%.html}.txt
$x; done;
3117 # shellcheck disable=SC2016 # false positive on ${
3118 grep -A1 ') iank:' .
/*.txt \
3119 |
sed -r 's/^(.{10})[^ ]*\.txt:\(?([^ ]*)[[:space:]](..). iank:/\1_\2_\3/
3122 s/^[^ ]*\.txt:\((.{2}).(.{2}).(.{4}) (.{8}) (.{2})\)?/\3-\1-\2_\4_\5/' \
3123 |
sed -n 'x;1d;0~2{G;s/\n/ /;p};${x;p}'
3129 pushd /home
/iank
/.local
/share
/profanity
/chatlogs
/iank_at_fsf.org
/rooms
/office_at_conference.fsf.org
3131 logcount
=${#logs[@]}
3132 if (( logcount
> 15 )); then
3133 i
=$
(( logcount
- 15 ))
3137 # usually do this on monday, sometimes later
3138 if [[ $
(date +%A
) == Monday
]]; then
3139 min_date
=$
(date -d 'monday 2 weeks ago' +%s
)
3141 min_date
=$
(date -d 'monday 3 weeks ago' +%s
)
3143 for (( ; i
< logcount
; i
++ )); do
3145 d
=$
(date -d "$(head -n1 $log|awk '{print $1}')" +%s
)
3146 if (( d
< min_date
)); then
3149 if awk '$3 == "iank:"' $log |
sed -r 's/^(.{10}).(.{8})[^ ]+(.*)/\1_\2\3/' |
grep .
; then
3157 # Tail all recent prof logs. Copying from profanity has unwanted line breaks
3158 # especially for links.
3165 ssh b8.nz profr-local
3173 d0
="$(date +%Y_%m_%d).log"
3174 d1
="$(date -d '1 day ago' +%Y_%m_%d).log"
3176 files
=(/d
/p
/profanity
/chatlogs
/iank_at_fsf.org
/{*,rooms
/*}/{$d0,$d1})
3178 if (( ${#files[@]} > 0 )); then
3179 cat "${files[@]}" |
sort |
tail -n 40
3184 # Tail pms in the last day, for the case where we restart profanity and
3185 # didn't check for pms beforehand. Assume the most recent logs are on kd.
3186 # If that isn't the case, use prof-recent-local
3193 ssh b8.nz prof-recent-local
3197 prof-recent-local
() {
3198 local d dates
date files f
3199 # consider making the day count passed by parameter. note: this works: $(date -d '2 day ago' +%Y_%m_%d)
3200 dates
=("$(date +%Y_%m_%d)" "$(date -d '1 day ago' +%Y_%m_%d)" )
3201 for d
in /d
/p
/profanity
/chatlogs
/iank_at_fsf.org
/!(rooms
); do
3203 for date in ${dates[@]}; do
3205 if [[ -e $f ]]; then
3209 if (( ${#files[@]} >= 1 )); then
3210 cat ${files[@]} |
tail
3222 ssh b8.nz prof-recent-sort
3227 prof-recent-sort
() {
3228 local d dates
date files f
3229 # consider making the day count passed by parameter. note: this works: $(date -d '2 day ago' +%Y_%m_%d)
3230 dates
=("$(date +%Y_%m_%d)" "$(date -d '1 day ago' +%Y_%m_%d)" )
3232 for d
in /d
/p
/profanity
/chatlogs
/iank_at_fsf.org
/!(rooms
); do
3233 for date in ${dates[@]}; do
3235 if [[ -e $f ]]; then
3240 for f
in "${files[@]}"; do
3246 # usage: debvm DEBIAN_VERSION RAM_MB
3248 local ver ram fname src
3251 # * is because it might have -backports in the name. we only expect 1 expansion
3252 fnames
=( debian-
$ver-*nocloud-
"$(dpkg --print-architecture)".qcow2
)
3253 if (( ${#fnames[@]} >= 2 )); then
3254 echo "error: iank: unexpected multiple files"
3257 fname
="${fnames[0]}"
3258 src
=/a
/opt
/roms
/$fname
3259 if [[ ! -f $src ]]; then
3260 echo debvm
: not found
$src, download from eg
: https
://cloud.debian.org
/images
/cloud
/buster
/latest
/
3264 # note, in fai-revm we do this: not sure why, maybe because of br device
3265 # --graphics spice,listen=0.0.0.0
3266 m s virt-install
--osinfo debian11
--rng /dev
/urandom
-n deb
${ver}tmp
--import -r $ram --vcpus 2 --disk /t
/$fname --graphics spice
3267 # note: to ssh into this machine will require host key generation: ssh-keygen -A
3269 # random: for cvs2git on gnu www, use debian 10. I could use trisquel,
3270 # but happen to want to try out the debian cloud images. the upstream
3271 # requires python2 and hasn't really changed since the version in d10.
3273 # apt install cvs2git cvs
3274 # # 7G was not enough
3275 # mount -o mode=1777,nosuid,nodev,size=34G -t tmpfs tmpfs /tmp
3276 # cvs2git --encoding utf_8 --fallback-encoding ascii --dumpfile=dump www-rsync/www |& tee /tmp/l
3277 ## www-rsync is an rsynced copy of the cvsfrom savannah
3281 local time time_sec time_pretty days
3283 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
3288 if ! time_pretty
=$
(date +%F.
%R
-d @
$time); then
3289 echo bad
time: $time
3292 echo $time_pretty "$l"
3293 time_sec
=${time%%.*}
3294 # only look at the last 18 days. generally just use this for timesheet.
3295 if (( time_sec
< EPOCHSECONDS
- 60 * 60 * 24 * days
)); then break; fi
3300 sqlite3
-separator ' ' /p
/c
/subdir_files
/.local
/share
/gajim
/logs.db
"select time, message from logs where contact_name = 'iank'" |
less
3304 sqlite3
-separator ' ' /p
/c
/subdir_files
/.local
/share
/gajim
/logs.db
"select time, message from logs" |
less
3309 e
"lspci -nnk|gr -iA2 net"
3310 lspci
-nnk|gr
-iA2 net
3312 e
"s lshw -C network"
3314 sudo lshw
-C network
3318 ser stop NetworkManager
3319 ser disable NetworkManager
3320 ser stop NetworkManager-wait-online.service
3321 ser disable NetworkManager-wait-online.service
3323 sudo resolvconf
-d NetworkManager
3329 ser start NetworkManager
3335 oathtool
--totp -b "$*" | xclip
-selection clipboard
3337 # run cmd and copy output
3339 "$@" |
& pee
"xclip -r -selection clipboard" cat
3342 # xorg copy. copy text piped into command
3344 xclip
-r -selection clipboard
3348 pee
"xclip -r -selection clipboard" cat
3352 # from http://askubuntu.com/questions/456021/remove-vocals-from-mp3-and-get-only-instrumentals
3353 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
3356 pfind
() { #find *$1* in $PATH
3357 [[ $# != 1 ]] && { echo requires
1 argument
; return 1; }
3359 IFS
=: pathArray
=($PATH); unset IFS
3360 find "${pathArray[@]}" -iname "*$1*"
3364 # trash-restore lists everything that has been trashed at or below CWD
3365 # This picks out files just in CWD, not subdirectories,
3366 # which also match grep $1, usually use $1 for a time string
3367 # which you get from running restore-trash once first
3370 # last condition is to not ask again for ones we skipped
3371 while name
="$( echo | restore-trash | gr "$PWD/[^
/]\
+$
" | gr "$1" )" \
3372 && [[ $name ]] && (( $
(wc -l <<<"$name") >= nth
)); do
3373 name
="$(echo "$name" | head -n $nth | tail -n 1 )"
3374 read -r -p "$name [Y/n] " ask
3375 if [[ ! $ask ||
$ask == [Yy
] ]]; then
3376 x
=$
( echo "$name" | gr
-o "^\s*[0-9]*" )
3377 echo $x | restore-trash
> /dev
/null
3378 elif [[ $ask == [Nn
] ]]; then
3388 rld
/a
/h
/_site
/ li
:/var
/www
/iankelling.org
/html
3393 # fixes the menu bar in xmonad. this won\'t be needed when xmonad
3394 # packages catches up on some changes in future (this is written in
3397 # geekosaur: so youll want to upgrade to xmonad 0.13 or else use a
3398 # locally modified XMonad.Hooks.ManageDocks that doesnt set the
3399 # work area; turns out it\'s impossible to set correctly if you are
3400 # not a fully EWMH compliant desktop environment
3402 # geekosaur: chrome shows one failure mode, qt/kde another, other
3403 # gtk apps a third, ... I came up with a setting that works for me
3404 # locally but apparently doesnt work for others, so we joined the
3405 # other tiling window managers in giving up on setting it at all
3407 xprop
-root -remove _NET_WORKAREA
3411 # reviewboard, used at my old job
3412 #rbpipe() { rbt post -o --diff-filename=- "$@"; }
3413 #rbp() { rbt post -o "$@"; }
3421 r2e
() { command r2e
-d /p
/c
/rss2email.json
-c /p
/c
/rss2email.cfg
"$@"; }
3422 # only run on MAIL_HOST. simpler to keep this on one system.
3423 r2eadd
() { # usage: name url
3424 # initial setup of rss2email:
3425 # r2e new r2e@iankelling.org
3426 # that initializes files, and sets default email.
3427 # symlink to the config doesnt work, so I copied it to /p/c
3428 # and then use cli option to specify explicit path.
3429 # Only option changed from default config is to set
3432 # or else for a few feeds, the from address is set by the feed, and
3433 # if I fail delivery, then I send a bounce message to that from
3434 # address, which makes me be a spammer.
3436 r2e add
$1 "$2" $1@r2e.iankelling.org
3437 # get up to date and dont send old entries now:
3438 r2e run
--no-send $1
3441 rspicy
() { # usage: HOST DOMAIN
3442 # connect to spice vm remote host. use vspicy for local host
3444 # shellcheck disable=SC2087
3446 sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
3447 sed -rn "s/.*port='([0-9]+).*/\1/p"
3450 if [[ $port ]]; then
3451 spicy
-h $1 -p $port
3453 echo "error: no port found. check that the domain is running."
3459 # s gem install scss-lint
3460 pushd /a
/opt
/thoughtbot-guides
3463 scss-lint
-c /a
/opt
/thoughtbot-guides
/style
/sass
/.scss-lint.yml
"$@"
3467 sk
-e 2120,245 /b
/ds
/brc
/b
/ds
/brc2
3472 out
=${2:-${1%.*}.sh}
3474 script -t -c "mpv --no-config --no-resume-playback --no-terminal --no-audio-display '$1'" $tmp/typescript
2>$tmp/timing
3475 # todo, the current sleep seems pretty good, but it
3476 # would be nice to have an empirical measurement, or
3477 # some better wait to sync up.
3479 # note: --loop-file=no prevents it from hanging if you have that
3480 # set to inf the mpv config.
3481 # --loop=no prevents it from exit code 3 due to stdin if you
3482 # had it set to inf in mpv config.
3484 # args go to mpv, for example --volume=80, 50%
3485 cat >$out <<EOFOUTER
3487 trap "trap - TERM && kill 0" INT TERM ERR; set -e
3488 ( sleep .2; scriptreplay <( cat <<'EOF'
3492 $(cat $tmp/typescript)
3495 base64 -d - <<'EOF'| mpv --loop=no --loop-file=no --no-terminal --no-audio-display "\$@" -
3504 smeld
() { # ssh meld usage host1 host2 file
3505 meld
<(ssh $1 cat $3) <(ssh $2 cat $3)
3509 PATH
=/usr
/local
/spdhackfix
:$PATH command spd
"$@"
3512 spamf
() { # spamtest on FILE
3513 if (( $# != 1 )); then
3514 e spamtest error
: expected
1 arg
, filename
>&2
3517 sdncmdroot spamassassin sudo
-u Debian-exim spamassassin
-t --cf='score PYZOR_CHECK 0' <"$1"
3523 declare -gi _seq
; _seq
+=1
3524 echo "test body" | m
mail -s "test mail from $HOSTNAME, $_seq" "${@:-root@localhost}"
3525 # for testing to send from an external address, you can do for example
3526 # -fian@iank.bid -aFrom:ian@iank.bid web-6fnbs@mail-tester.com
3527 # note in exim, you can retry a deferred message
3529 # MSG_ID is in /var/log/exim4/mainlog, looks like 1ccdnD-0001nh-EN
3532 # to test sieve, use below command. for fsf mail, see offlineimap-sync script
3533 # make modifications, then copy to live file, use -eW to actually modify mailbox
3535 # Another option is to use sieve-test SCRIPT MAIL_FILE. note,
3536 # sieve-test doesnt know about envelopes, Im not sure if sieve-filter does.
3538 # sieve with output filter. arg is mailbox, like INBOX.
3539 # This depends on dovecot conf, notably mail_location in /etc/dovecot/conf.d/10-mail.conf
3541 # always run this first, edit the test files, then run the following
3543 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
3546 c ~
/sieve
; cp personal
{test,}.sieve
; cp lists
{test,}.sieve
; cp personalend
{test,}.sieve
3547 sieve-filter
-eWv ~
/sieve
/maintest.sieve
${1:-INBOX} delete
&> /tmp
/testsieve.log
3548 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
3553 # printf "subject\nbody\n" | alertme
3558 To: alerts@iankelling.org
3565 To: alerts@iankelling.org
3577 To: daylert@iankelling.org
3584 To: daylert@iankelling.org
3593 # alert when a page goes live.
3595 local quiet url tmpdir
3598 # dont send a diff of the html. some html is not very readable
3604 tmpdir
="$(mktemp -d)"
3607 if wget
-q "$url"; then
3614 sleep $
(( 120 + RANDOM
% 300 ))
3618 # alert on changes to a webpage (just the base page that curl gets)
3619 # usage: weblert URL [SUBJECT...]
3621 local u old new quiet
3624 # dont send a diff of the html. some html is not very readable
3631 subject
="${*:-weblert}"
3632 old
=$
(curl
-s "$u") ||
:
3634 new
=$
(curl
-s "$u") ||
:
3635 if [[ $old && $new ]]; then
3636 if [[ $new != "$old" ]]; then
3638 echo | daylertme
"$subject"
3640 diff <(printf "%s\n" "$old") <(printf "%s\n" "$new") | daylertme
"$subject" ||
:
3645 sleep $
(( 60 + RANDOM
% 120 ))
3651 # shellcheck disable=SC1090 # expected
3652 source "$(type -p torsocks)" on
3656 less /var
/log
/exim
4/mymain
3662 # testmail above calls sendmail, which is a link to exim/postfix.
3663 # its docs dont say a way of adding an argument
3664 # to sendmail to turn on debug output. We could make a wrapper, but
3665 # that is a pain. Exim debug args are documented here:
3666 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
3668 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-building_and_installing_exim.html
3669 # note, for exim daemon, you can turn on debug options by
3670 # adding -d, etc to COMMONOPTIONS in
3671 # /etc/default/exim4
3673 # to specify recipients other than those in to, cc, bcc, you can use the cli args, eg:
3674 # exim -t 'test@zroe.org, t2@zroe.org' <<'EOF'
3676 # -t = get recipient from header
3678 From: ian@iankelling.org
3685 This is a test message.
3692 exim
-d -f '<>' $to <<EOF
3693 From: Mail Delivery System <Mailer-Daemon@gnu.org>
3695 Subject: Mail delivery failed: returning message to sender
3697 This message was created automatically by mail delivery software.
3706 # https://askubuntu.com/questions/160945/is-there-a-way-to-disable-a-laptops-internal-keyboard
3707 id
=$
(xinput
--list --id-only 'AT Translated Set 2 keyboard')
3708 if xinput list |
grep -F '∼ AT Translated Set 2 keyboard' &>/dev
/null
; then
3709 echo enabling keyboard
3710 # find the first slave keyboard number, they are all the same in my output.
3711 # if they werent, worst case we would need to save the slave number somewhere
3712 # when it got disabled.
3713 slave
=$
(xinput list |
sed -n 's/.*slave \+keyboard (\([0-9]*\)).*/\1/p' |
head -n1)
3714 xinput reattach
$id $slave
3723 (sleep "$(calc "$
* * 60")" && mpv
--no-config --volume 50 /a
/bin
/data
/alarm.mp3
) > /dev
/null
2>&1 &
3726 ## usage: to connect to my main transmission daemon from a different host, run this
3727 trans-remote-route
() {
3730 trg
() { transmission-remote-gtk
& r
; }
3731 # TODO: this wont work transmission.lan doesnt exist
3733 # example, set global upload limit to 100 kilobytes:
3735 TR_AUTH
=":$(jq -r .profiles[0].password ~/.config/transmission-remote-gtk/config.json)" transmission-remote transmission.lan
-ne "$@"
3742 for (( i
=0; i
< retries
- 1; i
++ )); do
3754 if [[ -e $1 && ! -w $1 ||
! -w $
(dirname "$1") ]]; then
3757 # full path for using in some initial setup steps
3761 # execute exim in its namespace. Useful args like -Mrm
3765 ecmd
="/usr/sbin/exim4 -C /etc/exim4/my.conf"
3766 if ip a show veth1-mail
&>/dev
/null
; then
3769 sdncmdroot exim4
$ecmd "$@"
3773 # get pid of systemd service
3777 pid
=$
(systemctl show
--property MainPID
--value "$unit")
3782 dir
=/sys
/fs
/cgroup
/system.slice
3783 if [[ ! -d $dir ]]; then
3784 # t10 and older directory.
3785 dir
=/sys
/fs
/cgroup
/systemd
/system.slice
3788 # 0 or empty. This file includes the MainPid, so I expect we
3789 # could just get this in the first place, but i don't know if that
3790 # is always the case.
3791 pid
=$
(head -n1 $dir/${unit%.service}.service
/cgroup.procs
)
3795 printf "%s\n" "$pid"
3801 sdnbash
() { # systemd namespace bash
3803 if (( $# != 1 )); then
3804 echo $0: error wrong number of args
>&2
3808 pid
=$
(servicepid
$unit)
3809 m sudo nsenter
-t $pid -n -m sudo
-u $USER -i bash
3812 sdnbashroot
() { # systemd namespace bash as root
3814 if (( $# != 1 )); then
3815 echo $0: error wrong number of args
>&2
3819 pid
=$
(servicepid
$unit)
3820 m sudo nsenter
-t $pid -n -m bash
3824 # systemd namespace cmd
3825 # usage: UNIT CMD...
3828 if (( $# <= 1 )); then
3829 echo $0: error wrong number of args
>&2
3834 pid
=$
(servicepid
$unit)
3835 tmpf
=$
(mktemp
--tmpdir $unit.XXXXXXXXXX
)
3837 printf "%s " "${@@Q}" >>$tmpf
3839 m sudo nsenter
-t $pid -n -m sudo
-u $USER -i bash
-c ". $tmpf & rm $tmpf"
3842 sdncmdroot
() { # systemd namespace root command
3844 if (( $# < 2 )); then
3845 echo $0: error wrong number of args
>&2
3850 pid
=$
(servicepid
$unit)
3851 m sudo nsenter
-t $pid -n -m "$@"
3859 # we use wireguard now, use mailnnbash.
3861 # m sudo nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*mail.conf") -n -m sudo -u $USER -i bash
3869 spamdpid
=$
(systemctl show
--property MainPID
--value spamassassin
)
3870 m sudo nsenter
-t $spamdpid -n -m sudo
-u Debian-exim spamassassin
"$@"
3877 s nmtui-connect
"$@"
3881 local unit pid ns mailnn
3882 # mailvpn would belong on the list if using openvpn
3883 for unit
in mailnn unbound dovecot spamassassin exim4 radicale
; do
3884 pid
=$
(servicepid
$unit)
3885 echo debug
: unit
=$unit pid
=$pid
3886 if [[ ! $pid ]]; then
3887 echo failed to
find pid
for unit
=$unit
3890 if ! ns
=$
(s readlink
/proc
/$pid/ns
/net
); then
3891 echo failed to
find ns
for unit
=$unit pid
=$pid
3894 if [[ $mailnn ]]; then
3895 if [[ $ns != "$mailnn" ]]; then
3896 echo "$unit ns $ns != $mailnn"
3907 sdncmd openvpn-client-tr@client.service
"$@"
3910 sdncmd openvpn-client-tr@client.service bash
3913 sdncmdroot openvpn-client-tr@client.service bash
3918 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
3919 local vpn_service
=openvpn-client
3921 local vpn_service
=openvpn
3924 [[ $1 ]] ||
{ echo need arg
; return 1; }
3925 journalctl
--unit=$vpn_service@
$1 -f -n0 &
3926 # sometimes the journal doesnt open until after the vpn output
3927 # has happened. hoping this fixes that.
3929 sudo systemctl start
$vpn_service@
$1
3930 # sometimes the ask-password agent does not work and needs a delay.
3932 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779240
3933 # noticed around 8-2017 after update from around stretch release
3934 # on debian testing, even though the bug is much older.
3935 sudo systemd-tty-ask-password-agent
3940 ls -lad /run
/user
/1000
3941 stats
=$
(stat
-c%a-
%g-
%u
/run
/user
/1000)
3942 if [[ $stats != 700-1000-1000 ]]; then
3943 m s
chmod 700 /run
/user
/1000; m s chown iank.iank
/run
/user
/1000
3950 sink
=$
(pactl get-default-sink
)
3951 if [[ $sink == auto_null
]]; then
3952 # guessing there is just one with an off profile. otherwise we will
3953 # need some other solution, like storing the card identifier that we
3955 card
=$
(pacmd list-cards |
sed -n '/^[[:space:]]*index:/{s/^[[:space:]]*index://;h};/^[[:space:]]*active profile: <off>$/{g;p;q}')
3956 m pacmd set-card-profile
"$card" output
:analog-stereo
3959 m pactl set-sink-mute @DEFAULT_SINK@ false
3965 sink
=$
(pactl get-default-sink
)
3967 card
="${card/output/card}"
3968 m pacmd set-card-profile
"$card" off
3970 # clicking on a link in a browser can cause unmute.
3971 # I don't want that. So, use a stronger form of mute
3973 #pactl set-sink-mute @DEFAULT_SINK@ true
3978 # systemctl is-enabled / status / cat says nothing, instead theres
3979 # some obscure symlink. paths copied from man systemd.unit.
3980 # possibly also usefull, but incomplete, doesnt show units not loaded in memory:
3981 # seru list-dependencies --reverse --all UNIT
3984 local -a dirs search
3990 ~
/.config
/systemd
/user.control
/*
3991 $XDG_RUNTIME_DIR/systemd
/user.control
/*
3992 $XDG_RUNTIME_DIR/systemd
/transient
/*
3993 $XDG_RUNTIME_DIR/systemd
/generator.early
/*
3994 ~
/.config
/systemd
/user
/*
3996 $XDG_RUNTIME_DIR/systemd
/user
/*
3998 $XDG_RUNTIME_DIR/systemd
/generator
/*
3999 ~
/.local
/share
/systemd
/user
/*
4000 /usr
/lib
/systemd
/user
/*
4001 $XDG_RUNTIME_DIR/systemd
/generator.late
/*
4006 /etc
/systemd
/system.control
/*
4007 /run
/systemd
/system.control
/*
4008 /run
/systemd
/transient
/*
4009 /run
/systemd
/generator.early
/*
4010 /etc
/systemd
/system
/*
4011 /etc
/systemd
/systemd.attached
/*
4012 /run
/systemd
/system
/*
4013 /run
/systemd
/systemd.attached
/*
4014 /run
/systemd
/generator
/*
4015 /lib
/systemd
/system
/*
4016 /run
/systemd
/generator.late
/*
4020 for f
in "${search[@]}"; do
4021 [[ -d $f ]] ||
continue
4028 # dirs is just so we write out the directory names, ls does it when there is 2 or more dirs.
4044 read -r _ link _ istls
< <(resolvectl dnsovertls tunfsf
)
4047 *) echo fixvpndns error
: unexpected istls value
: $istls >&2; return 1 ;;
4049 s busctl call org.freedesktop.resolve1
/org
/freedesktop
/resolve1 org.freedesktop.resolve1.Manager SetLinkDNSOverTLS is
$link no
4053 [[ $1 ]] ||
{ echo need arg
; return 1; }
4054 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
4055 local vpn_service
=openvpn-client
4057 local vpn_service
=openvpn
4059 sudo systemctl stop
$vpn_service@
$1
4061 vpnoffc
() { # vpn off client
4062 ser stop openvpn-client-tr@client
4066 unit
=openvpn-client-tr@client
4068 if [[ $
(systemctl is-active
$unit) != active
]]; then
4069 s systemctl start
$unit
4075 vspicy
() { # usage: VIRSH_DOMAIN
4076 # connect to vms made with virt-install
4077 spicy
-p "$(sudo virsh dumpxml "$1"|grep "<graphics.
*type='spice'"|\
4078 sed -r "s
/.
*port
='([0-9]+).*/\1/")"
4082 cat-new-files /m/4e/INBOX/new
4086 if (( $# != 1 )) ; then
4087 echo wakehours: error: expected 1 arg, got $# >&2
4090 sec=$(( EPOCHSECONDS - $( date +%s -d $1am ) ))
4091 printf "%d:%02d\n" $(( sec / 60 / 60)) $(( (sec / 60) % 60 ))
4094 calvis() { # calendar visualize
4095 install -m 600 /dev/null /tmp/calendar-bytes
4098 # shellcheck disable=SC2059 # intentional for the hex formatting
4099 printf "\x$(printf "%x" $char)" >>/tmp/calendar-bytes
4101 done < <(grep -v '[#-]' /p/calendar-data)
4102 /p
/c
/proc
/calendar
/linux-amd64
/calendar
4105 wtr
() { curl wttr.in
/boston
; }
4107 xevkb
() { xev
-event keyboard
; }
4112 printf "running: %s\n" "$*"
4117 # https://electrum.readthedocs.io/en/latest/tor.html
4118 # https://github.com/spesmilo/electrum-docs/issues/129
4119 s rsync
-ptog --chown bitcoin
:bitcoin ~
/.Xauthority
/var
/lib
/bitcoind
/.Xauthority
4120 sudo
-u bitcoin DISPLAY
=$DISPLAY XAUTHORITY
=/var
/lib
/bitcoind
/.Xauthority
/a
/opt
/electrum-4.2
.1-x86_64.AppImage
-p socks5
:localhost
:9050
4123 sudo
-u bitcoin DISPLAY
=$DISPLAY XAUTHORITY
=/var
/lib
/bitcoind
/.Xauthority
/a
/opt
/monero-gui-v0.17
.3.2/monero-wallet-gui
4129 rg
"$@" /p
/w.org
/a
/t.org
/a
/work.org
/b
4132 # re all my files more expansively
4137 find $paths -not \
( -name .svn
-prune -o -name .git
-prune \
4138 -o -name .hg
-prune -o -name .editor-backups
-prune \
4139 -o -name .undo-tree-history
-prune \
) 2>/dev
/null |
grep -iP --color=auto
-- "$*" ||
:
4140 rgv
$local_rgv_args -g "!bash_unpublished" -- "$*" $paths /a
/work.org ||
:
4142 reml
() { # rem with limit to 5 matches per file
4143 local_rgv_args
="-m 5"
4150 find $paths -not \
( -name .svn
-prune -o -name .git
-prune \
4151 -o -name .hg
-prune -o -name .editor-backups
-prune \
4152 -o -name .undo-tree-history
-prune \
) 2>/dev
/null |
grep -iP --color=auto
-- "$*" ||
:
4153 rgv
$local_rgv_args -- "$*" $paths /a
/t.org
/p
/w.org ||
:
4155 repl
() { # rem with limit to 5 matches per file
4156 local local_rgv_args
="-m 5"
4161 # re on common fsf files
4164 paths
="/f/gluestick /f/brains /f/s /c"
4165 find $paths -not \
( -name .svn
-prune -o -name .git
-prune \
4166 -o -name .hg
-prune -o -name .editor-backups
-prune \
4167 -o -name .undo-tree-history
-prune \
) 2>/dev
/null |
grep -iP --color=auto
-- "$*" ||
:
4168 rgv
-- "$*" $paths /a
/work.org ||
:
4172 # for use in /f/bind
4174 # shellcheck disable=SC2046 # i want word splitting
4175 .
/update-zone $
(i s |
sed -rn 's/.*db\.(.*)/\1/p')
4179 # pip3 install linode-cli
4182 local input ip id tmp
4190 linode-cli
--json --pretty linodes create
--root_pass loxHuceygomGisun |
tee $tmp
4191 read -r ip id
<<<"$(tail -n+2 $tmp | jq -r '.[0].ipv4[0] , .[0].id')"
4192 for string
in $ip $id; do
4196 echo "livp9: bad value ip=$ip id=$id input=$input"
4204 if timeout
4 ssh $ip :; then
4212 apt-get -qq -y install ffmpeg rsync
4216 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
4217 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
4218 rsync
$ip:vp
9/$input vp9
4219 linode-cli linodes delete
$id
4223 # we also have a file in /a/c/...konsole...
4224 local f
=$HOME/.config
/konsolerc
4225 setini DefaultProfile profileian.profile
"Desktop Entry" $f
4226 setini Favorites profileian.profile
"Favorite Profiles" $f
4227 setini ShowMenuBarByDefault false KonsoleWindow
$f
4228 setini TabBarPosition Top TabBar
$f
4232 while read -r k v
; do
4233 # shellcheck disable=SC2154
4234 setini
$k $v sakura
/a
/c
/subdir_files
/.config
/sakura
/sakura.conf
4236 colorset1_back rgb(33,37,39)
4240 disable_numbered_tabswitch true
4241 scroll_lines 10000000
4246 # make a page of links found in the files $@. redirect output
4248 gr
-oh 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' "$@" | \
4249 rev |
sort -u |
rev |
sed 's,.*,<a href="\0">\0</a><br\>,'
4252 reset-xscreensaver
() {
4253 # except for spash, i set these by setting gui options in
4254 # xscreensaver-command -demo
4255 # then finding the corresponding option in .xscreensaver
4256 # spash, i happened to notice in .xscreensaver
4258 # dpmsOff, monitor doesnt come back on using old free software supported nvidia card
4259 cat > /home
/iank
/.xscreensaver
<<'EOF'
4262 dpmsStandby: 0:07:00
4263 dpmsSuspend: 0:08:00
4267 lockTimeout: 0:06:00
4274 # very useful, copy directory structure 3 deep. add remove /*/ to change level
4275 # rsync -aivh --exclude '/*/*/*/' -f"+ */" -f"- *" SRC DEST
4278 # * stuff that makes sense to be at the end
4279 if [[ "$SUDOD" ]]; then
4280 # allow failure, for example if we are sudoing into a user with diffferent/lesser permissions.
4283 elif [[ -d /a
]] && [[ $PWD == "$HOME" ]] && [[ $
- == *i
* ]]; then
4291 # for mitmproxy to get a newer python.
4292 # commented until i want to use it because it
4293 # noticably slows bash startup
4297 if [[ $EUID == 0 ||
! -e ~
/.pyenv
/bin
]]; then
4298 echo "error: dont be root. make sure pyenv is installed"
4301 export PATH
="$HOME/.pyenv/bin:$PATH"
4302 eval "$(pyenv init -)"
4303 eval "$(pyenv virtualenv-init -)"
4308 # I have the git repo and a release. either one should work.
4309 # I have both because I was trying to solve an issue that
4310 # turned out to be unrelated.
4311 # ARDUINO_PATH=/a/opt/Arduino/build/linux/work
4313 ## i should have documented this...
4314 # based on https://github.com/keyboardio/Kaleidoscope
4315 export KALEIDOSCOPE_DIR
=/a
/opt
/Kaleidoscope
4317 # They want to be added to the start, but i think
4318 # that should be avoided unless we really need it.
4319 path-add
--end ~
/.npm-global
4322 path-add
--end $HOME/.cargo
/bin
4324 if type -P rg
&>/dev
/null
; then
4325 # --no-messages because of annoying errors on broken symlinks
4326 # -z = search .gz etc files
4327 # -. = search dotfiles
4328 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 $?
; }
4329 #fails if not exist. ignore
4330 complete
-r rg
2>/dev
/null ||
:
4335 # rg with respecting vcs ignore files
4338 # settings that are turned off for pipes, keep them on.
4339 # Found by searching for "terminal" in --help
4343 # -. = search dotfiles
4344 # -z = search zipped files
4345 # -i = case insensitive
4347 # --no-messages because of annoying errors on broken symlinks
4348 # --no-ignore-parent because i have /a/.git which ignores almost everything under it.
4349 command rg
-n --heading -.
-z --no-messages -i -M 900 --no-ignore-parent -g '!.git' -g '!auto-save-list' -g '!.savehist' "$@" || ret
=$?
4354 echo "$(tput setaf 5 2>/dev/null ||:)â–ˆ coresite â–ˆ$(tput sgr0 2>/dev/null||:)"
4356 echo "$(tput setaf 5 2>/dev/null ||:)â–ˆ office â–ˆ$(tput sgr0 2>/dev/null||:)"
4359 amallq
() { # amall quiet
4364 sedi
-r '/alertmanager.url/s/@prom.office/@prom/' ~
/.config
/amtool
/config.yml
4368 sedi
-r '/alertmanager.url/s/@prom.fsf/@prom.office.fsf/' ~
/.config
/amtool
/config.yml
4372 amall silence query
"$@"
4374 # amtool silence add
4376 amall silence add
"$@"
4378 # amtool silence force
4380 amall silence add x
!="1"
4383 # note: not sure if quoting of this arg is correct
4384 amfsf silence expire
"$(amfsf silence query -q)"
4385 amoffice silence expire
"$(amoffice silence query -q)"
4389 youtube-dl-update
() {
4390 sudo wget https
://yt-dl.org
/downloads
/latest
/youtube-dl
-O /usr
/local
/bin
/youtube-dl
4391 sudo
chmod a
+rx
/usr
/local
/bin
/youtube-dl
4394 # https://github.com/yt-dlp/yt-dlp/wiki/Installation
4396 sudo curl
-L https
://github.com
/yt-dlp
/yt-dlp
/releases
/latest
/download
/yt-dlp
-o /usr
/local
/bin
/yt-dlp
4397 sudo
chmod a
+rx
/usr
/local
/bin
/yt-dlp
# Make executable
4401 mpv
--ytdl ytdl_path
=/usr
/local
/bin
/yt-dlp
"$@"
4404 # taken from default changes to bashrc and bash_profile
4405 path-add
--end --ifexists $HOME/.rvm
/bin
4406 # also had ruby bin dir, but moved that to environment.sh
4407 # so its included in overall env
4410 # ya, hacky hardcoded hostnames in 2023. we could do better
4412 local -a failed_hosts hosts
4416 kd x3.office.fsf.org syw
4425 for host in ${hosts[@]}; do
4427 if ! scp
/b
/fai
/fai
/config
/files
/usr
/local
/bin
/hssh
/IANK root@
$host:/usr
/local
/bin
/hssh
; then
4428 failed_hosts
+=($host)
4431 if (( ${#failed_hosts[@]} >= 1 )); then
4432 echo failed_hosts
=${failed_hosts[*]}
4445 # <#part type="image/jpeg" filename="/home/iank/2023-12-24-ski-trip.jpg" disposition=attachment> <#/part>
4450 if [[ ! -s $f ]]; then
4451 e
"error: empty or non-existent file $f"
4456 echo '<#part type="image/jpeg" filename="'"$(rl "$f")"'" disposition=attachment> <#/part>'
4461 units
"tempC($1)" tempF
4465 units
"tempF($1)" tempC
4468 # requires dns/firewall setup first
4470 web-conf
-e ian@iankelling.org
-f 8000 - apache2 live.iankelling.org
<<'EOF'
4471 <Location "/fsf.webm">
4473 AuthName "basic_auth"
4475 # htpasswd -c icecast-fsf-htpasswd USERNAME
4476 AuthUserFile "/etc/icecast-fsf-htpasswd"
4479 <Location "/fsf-tech.webm">
4481 AuthName "basic_auth"
4482 AuthUserFile "/etc/icecast-fsf-tech-htpasswd"
4488 # obs screen switching of
4490 ls -l /tmp
/no-obs-auto-scene-switch
4491 touch /tmp
/no-obs-auto-scene-switch
4493 # obs screen switching on
4495 ls -l /tmp
/no-obs-auto-scene-switch
4496 if [[ -e /tmp
/no-obs-auto-scene-switch
]]; then
4497 rm -f /tmp
/no-obs-auto-scene-switch
4501 obs-gen-profiles
() {
4502 local p
=/p
/c
/basic
/profiles
4503 sed 's/fsf-sysops/fsf-tech/g' $p/fsfsysops
/basic.ini
>$p/fsftech
/basic.ini
4504 sed 's/fsf-sysops/fsf/g' $p/fsfsysops
/basic.ini
>$p/fsf
/basic.ini
4507 # terminal clear. like clear, but put the prompt at the bottom,
4508 # useful for obs streaming the bottom half of a terminal window.
4510 for ((i
=i
; i
<COLUMNS
; i
++)); do
4516 export BASEFILE_DIR
=/a
/bin
/fai-basefiles
4518 #export ANDROID_HOME=/a/opt/android-home
4519 # https://f-droid.org/en/docs/Installing_the_Server_and_Repo_Tools/
4520 #export USE_SDK_WRAPPER=yes
4521 #PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
4523 # didnt get drush working, if I did, this seems like the
4524 # only good thing to include for it.
4525 # Include Drush completion.
4526 # if [ -f "/home/ian/.drush/drush.complete.sh" ] ; then
4527 # source /home/ian/.drush/drush.complete.sh
4534 # https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
4535 # i added an extra condition as gentoo xorg guide says depending on
4536 # $DISPLAY is fragile.
4537 if [[ ! $DISPLAY && $XDG_VTNR == 1 ]] && shopt -q login_shell
&& isarch
; then
4542 # ensure no bad programs appending to this file will have an affect