fixup gitignore
[distro-setup] / brc2
diff --git a/brc2 b/brc2
index 02aa77f694d82e89289ce521761cd37978b0b8fb..7d94df1fc12e1011bc08fe6adaf3078fbad89a78 100644 (file)
--- a/brc2
+++ b/brc2
@@ -6,7 +6,9 @@
 
 # * settings
 
-HISTFILE=$HOME/.bh
+if [[ $HISTFILE ]]; then
+  HISTFILE=$HOME/.bh
+fi
 
 source /a/bin/distro-setup/path-add-function
 path-add /a/exe
@@ -21,6 +23,15 @@ path-add --ifexists --end /a/work/libremanage
 path-add --ifexists --end /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools
 path-add --ifexists --end /a/opt/scancode-toolkit-3.10.
 
+case $HOSTNAME in
+  sy|bo)
+    # https://askubuntu.com/questions/1254544/vlc-crashes-when-opening-any-file-ubuntu-20-04
+    if grep -qE '^VERSION_CODENAME="(nabia|focal)"' /etc/os-release &>/dev/null; then
+      export MESA_LOADER_DRIVER_OVERRIDE=i965
+    fi
+    ;;
+esac
+
 
 export WCDHOME=/a
 
@@ -50,6 +61,32 @@ fi
 
 # * functions
 
+multimic() {
+  local i
+  local -a sources
+
+  m pactl unload-module module-loopback
+  m pactl unload-module module-null-sink
+  m pactl unload-module module-remap-source
+
+  sources=($(pacmd list-sources | sed -rn 's/.*name: <([^>]+).*/\1/p'))
+
+  if (( ! $# )); then
+    i=0
+    for s in ${sources[@]}; do
+      e $i $s
+      i=$(( i+1 ))
+    done
+    read -r l
+    set -- $l
+  fi
+  m pactl load-module module-null-sink sink_name=ianinput sink_properties=device.description=ianinputs
+  for i; do
+    m pactl load-module module-loopback source=${sources[i]} sink_dont_move=true sink=ianinput
+  done
+  pactl load-module module-remap-source source_name=iancombine master=ianinput.monitor source_properties=device.description=iancombine
+}
+
 hstest() {
   install-my-scripts
   d=$(mktemp -d)
@@ -466,14 +503,16 @@ lipush() {
   # note, i had --delete-excluded, but that deletes all files in --exclude-from on
   # the remote site, which doesn't make sense, so not sure why i had it.
   local p a
-  p=(/a/opt/{emacs-debian11{,-nox},mu,emacs} /a/bin /a/exe /a/h /a/c /p/c/machine_specific/vps{,.hosts})
+  # excluding emacs for now
+  #p=(/a/opt/{emacs-debian11{,-nox},mu,emacs} /a/bin /a/exe /a/h /a/c /p/c/machine_specific/vps{,.hosts})
+  p=(/a/bin /a/exe /a/h /a/c /p/c/machine_specific/vps{,.hosts})
   a="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
   ret=0
   for h in li je bk; do
-    m s rsync "$@" $a ${p[@]} /p/c/machine_specific/$h root@$h.b8.nz:/ || ret=$?
-    # only li is debian11
-    p[0]=/a/opt/emacs-ubuntu20.04
-    p[1]=/a/opt/emacs-ubuntu20.04-nox
+    m s rsync "$@" $a ${p[@]} /p/c/machine_specific/$h root@$h.b8.nz:/
+    ## only li is debian11
+    #p[0]=/a/opt/emacs-trisuqel10
+    #p[1]=/a/opt/emacs-trisquel10-nox
   done
   m s rsync "$@" -ahviSAXPH root@li.b8.nz:/a/h/proposed-comments/ /a/h/proposed-comments || ret=$?
   return $ret
@@ -515,15 +554,15 @@ EOF
 
 dnsup() {
   conflink -f
-  m ser reload bind9
+  m ser reload named
 }
 dnsb8() {
   local f=/var/lib/bind/db.b8.nz
-  m ser stop bind9
+  m ser stop named
   m sleep 1
   m sudo rm -fv $f.jnl
   m sudo install -m 644 -o bind -g bind /p/c/machine_specific/vps/bind-initial/db.b8.nz $f
-  m ser restart bind9
+  m ser restart named
 }
 dnsecgen() {
   # keys generated like this
@@ -725,6 +764,10 @@ fastboot() {
 
 kdecd() { /usr/lib/x86_64-linux-gnu/libexec/kdeconnectd; }
 
+bat() {
+  cat /sys/class/power_supply/BAT0/capacity
+}
+
 # List of apps to install/update
 # Create from existing manually installed apps by doing
 # fdroidcl update
@@ -1033,9 +1076,11 @@ jrf() { journalctl -n 200 -f "$@" ; }
 
 ccomp journalctl jtail jr jrf
 
-kff() { # keyboardio firmware flash
-  pushd /a/bin/distro-setup/Arduino/Model01-Firmware
-  yes $'\n' | make flash
+kff() { # keyboardio firmware flash. you must hold down the tilde key
+  pushd /a/opt/Model01-Firmware
+  # if we didn't want this yes hack, then remove "shell read" from
+  # /a/opt/Kaleidoscope/etc/makefiles/sketch.mk
+  yes $'\n' | VERBOSE=1 make flash
   popd
 }
 
@@ -1093,11 +1138,37 @@ EOF
 }
 
 
+mns() { # mount namespace
+  ns=$1
+  shift
+  s mkdir -p /root/mount_namespaces
+  if ! sudo mountpoint /root/mount_namespaces >/dev/null; then
+    m sudo mount --bind /root/mount_namespaces /root/mount_namespaces
+  fi
+  m sudo mount --make-private /root/mount_namespaces
+  if [[ ! -e /root/mount_namespaces/$ns ]]; then
+    m sudo touch /root/mount_namespaces/$ns
+  fi
+  if ! sudo mountpoint /root/mount_namespaces/$ns >/dev/null; then
+    m sudo unshare --propagation slave --mount=/root/mount_namespaces/$ns /bin/true
+  fi
+  m sudo -E /usr/bin/nsenter --mount=/root/mount_namespaces/$ns "$@"
+}
+
+mnsnonet() {
+  ns=$1
+  if ! s ip netns list | grep -Fx nonet &>/dev/null; then
+    s ip netns add nonet
+  fi
+  mns $ns --net=/var/run/netns/nonet sudo -E -u iank /bin/bash
+}
+
+
 lom() {
   local l base
   if [[ $1 == /* ]]; then
     base=${1##*/}
-    if mountpoint -q /mnt/$base; then
+    if mns $base mountpoint -q /mnt/$base; then
       return 0
     fi
     l=$(losetup -j $1 | sed -rn 's/^([^ ]+): .*/\1/p' | head -n1 ||:)
@@ -1112,12 +1183,12 @@ lom() {
       fi
     fi
     m sudo mkdir -p /mnt/$base
-    m sudo mount /dev/mapper/$base /mnt/$base
-    m sudo chown $USER:$USER /mnt/$base
+    m mns $base mount /dev/mapper/$base /mnt/$base
+    m mns $base chown $USER:$USER /mnt/$base
   else
     base=$1
-    if mountpoint /mnt/$base &>/dev/null; then
-      m sudo umount /mnt/$base
+    if mns $base mountpoint /mnt/$base &>/dev/null; then
+      m mns $base umount /mnt/$base
     fi
     if sudo cryptsetup status /dev/mapper/$base &>/dev/null; then
       if ! m sudo cryptsetup luksClose /dev/mapper/$base; then
@@ -1208,6 +1279,54 @@ mo() { xset dpms force off; } # monitor off
 mpvd() {
   mpv --profile=d "$@";
 }
+# mpv all media files in . or $1
+mpvm() {
+  local -a extensions arg
+  # get page source of https://en.wikipedia.org/w/index.php?title=Video_file_format&action=edit
+  # into /a/x.log, then
+  # grep '^| *\.' /a/x.log | sed 's/| *//;s/,//g'
+  extensions=(
+    .webm
+    .mkv
+    .flv
+    .flv
+    .vob
+    .ogv .ogg
+    .drc
+    .gif
+    .gifv
+    .mng
+    .avi
+    .MTS .M2TS .TS
+    .mov .qt
+    .wmv
+    .yuv
+    .rm
+    .rmvb
+    .viv
+    .asf
+    .amv
+    .mp4 .m4p .m4v
+    .mpg .mp2 .mpeg .mpe .mpv
+    .mpg .mpeg .m2v
+    .m4v
+    .svi
+    .3gp
+    .3g2
+    .mxf
+    .roq
+    .nsv
+  )
+  arg=("(" -iname "*${extensions[0]}")
+  for (( i=1 ; i < ${#extensions[@]}; i++ )); do
+    arg+=(-o -iname "*${extensions[i]}")
+  done
+  arg+=(")")
+  dir=${1:-.}
+  # debug:
+  #find $dir "${arg[@]}" -size +1M
+  find $dir "${arg[@]}" -size +1M -exec mpv --profile=d '{}' +
+}
 mpvs() {
   mpv --profile=s "$@";
 }
@@ -1250,6 +1369,10 @@ mygajim() {
   done
 }
 
+allmygajim() {
+  sqlite3 -separator ' ' /p/c/subdir_files/.local/share/gajim/logs.db "select time, message from logs where contact_name = 'iank'" | less
+}
+
 gajlogs() {
   sqlite3 -separator ' ' /p/c/subdir_files/.local/share/gajim/logs.db "select time, message from logs" | less
 }
@@ -1709,12 +1832,11 @@ mailnncheck() {
 
 
 vpncmd() {
-  m sudo -E env "PATH=$PATH" nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*client.conf") -n -m "$@"
-}
-vpnf() {
-  vpncmd sudo -E -u iank env "PATH=$PATH" abrowser -no-remote -P vpn & r
+  m sudo -E env "PATH=$PATH" nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*client.conf") -n "$@"
 }
+
 vpn2f() {
+  sudo -v
   vpncmd sudo -u iank env "PATH=$PATH" abrowser -no-remote -P vpn2 & r
 }
 
@@ -1870,7 +1992,15 @@ if [[ -e $f ]]; then
   source $f
 fi
 
-
+electrum() {
+  # https://electrum.readthedocs.io/en/latest/tor.html
+  # https://github.com/spesmilo/electrum-docs/issues/129
+  s rsync -ptog --chown bitcoin:bitcoin ~/.Xauthority /var/lib/bitcoind/.Xauthority
+  sudo -u bitcoin DISPLAY=$DISPLAY XAUTHORITY=/var/lib/bitcoind/.Xauthority /a/opt/electrum-4.2.1-x86_64.AppImage -p socks5:localhost:9050
+}
+monero() {
+  sudo -u bitcoin DISPLAY=$DISPLAY XAUTHORITY=/var/lib/bitcoind/.Xauthority /a/opt/monero-gui-v0.17.3.2/monero-wallet-gui
+}
 
 
 reset-konsole() {
@@ -1897,6 +2027,12 @@ scrollbar true
 EOF
 }
 
+# make a page of links found in the files $@. redirect output
+linkhtml() {
+  gr -oh 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' "$@" | \
+    rev | sort -u | rev | sed 's,.*,<a href="\0">\0</a><br\>,'
+}
+
 reset-xscreensaver() {
   # except for spash, i set these by setting gui options in
   # xscreensaver-command -demo
@@ -1955,7 +2091,9 @@ path-add /usr/local/go/bin
 # I have both because I was trying to solve an issue that
 # turned out to be unrelated.
 # ARDUINO_PATH=/a/opt/Arduino/build/linux/work
-export ARDUINO_PATH=/a/opt/arduino-1.8.15
+
+## i should have documented this...
+# based on https://github.com/keyboardio/Kaleidoscope
 export KALEIDOSCOPE_DIR=/a/opt/Kaleidoscope
 
 # They want to be added to the start, but i think