bunch of new stuff, a few fixes
[distro-setup] / brc2
diff --git a/brc2 b/brc2
index 15f953909b6e2f790c28761d9053400c6a82260a..1a6db0cc38d5d4978c389c9d0d1418d2a36d90db 100644 (file)
--- a/brc2
+++ b/brc2
@@ -128,6 +128,12 @@ zcheck() {
   ssh bow rm /tmp/oegu.jpg
   feh /t/oegu.jpg
 }
+zmon() {
+  while true; do
+    ziva-screen
+    sleep 15
+  done
+}
 
 slemacs() {
   local arg rtime v
@@ -1646,7 +1652,7 @@ lipush() {
   local p a
   # 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} /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter)
+  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)
   a="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
   ret=0
   for h in li je bk; do
@@ -2169,7 +2175,9 @@ hstatus() {
   done
 }
 
-# work log
+## work log
+#
+# note: database location is specified in ~/.timetrap.yml, currently /p/.timetrap.db
 wlog() {
   local day i days_back
   days_back=${1:-16}
@@ -2537,12 +2545,49 @@ mns() { # mount namespace
   m sudo -E /usr/bin/nsenter --mount=/root/mount_namespaces/$ns "$@"
 }
 
+mnsd() { # mount namespace + systemd namespace
+  ns=$1
+  unit=$2
+  shift 2
+
+  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
+
+  pid=$(servicepid $unit)
+  tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX)
+  export -p >$tmpf
+  printf "%s " "${@@Q}" >>$tmpf
+  echo >>$tmpf
+
+  m sudo nsenter -t $pid -n --mount=/root/mount_namespaces/$ns sudo -u $USER -i bash -c ". $tmpf & sleep 1; rm $tmpf"
+}
+
+
 mnsr() { # mns run
   local ns=$1
   shift
   mns $ns sudo -u iank -E env "PATH=$PATH" "$@"
 }
 
+mnsnonetr() {
+  ns=$1
+  lomh
+  if ! s ip netns list | grep -Fx nonet &>/dev/null; then
+    s ip netns add nonet
+  fi
+  mns $ns --net=/var/run/netns/nonet /bin/bash
+  lomh
+}
+
 mnsnonet() {
   ns=$1
   lomh
@@ -3457,7 +3502,7 @@ sdnbashroot() { # systemd namespace bash
 
 
 sdncmd() { # systemd namespace cmd
-  local unit pid
+  local unit pid tmpf
   if (( $# <= 2 )); then
     echo $0: error wrong number of args >&2
     return 1
@@ -3465,7 +3510,11 @@ sdncmd() { # systemd namespace cmd
   unit=$1
   shift
   pid=$(servicepid $unit)
-  m sudo nsenter -t $pid -n -m sudo -u $USER -i "$@"
+  tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX)
+  export -p >$tmpf
+  printf "%s " "${@@Q}" >>$tmpf
+  echo >>$tmpf
+  m sudo nsenter -t $pid -n -m sudo -u $USER -i bash -c ". $tmpf & rm $tmpf"
 }
 
 
@@ -3570,11 +3619,33 @@ fixu() {
 
 # unmute
 um() {
+  local sink card
+  sink=$(pactl get-default-sink)
+  if [[ $sink != auto_null ]]; then
+    return
+  fi
+
+  # guessing there is just one with an off profile. otherwise we will
+  # need some other solution, like storing the card identifier that we
+  # muted with nap.
+  card=$(pacmd list-cards | sed -n '/^[[:space:]]*index:/{s/^[[:space:]]*index://;h};/^[[:space:]]*active profile: <off>$/{g;p;q}')
+  m pacmd set-card-profile "$card" output:analog-stereo
+
   pactl set-sink-mute @DEFAULT_SINK@ false
   rm -f /tmp/ianknap
 }
+
 nap() {
-  pactl set-sink-mute @DEFAULT_SINK@ true
+  local sink card
+  sink=$(pactl get-default-sink)
+  card="${sink%.*}"
+  card="${card/output/card}"
+  m pacmd set-card-profile "$card" off
+
+  # clicking on a link in a browser can cause unmute.
+  # I don't want that. So, use a stronger form of mute
+  # than this.
+  #pactl set-sink-mute @DEFAULT_SINK@ true
   touch /tmp/ianknap
 }
 
@@ -3666,7 +3737,13 @@ vpnoffc() { # vpn off client
   ser stop openvpn-client-tr@client
 }
 vpnc() {
-  ser start openvpn-client-tr@client
+  local unit
+  unit=openvpn-client-tr@client
+  sudo -v
+  if [[ $(systemctl is-active $unit) != active ]]; then
+    s systemctl start $unit
+    sleep 1
+  fi
 }
 
 
@@ -3751,6 +3828,13 @@ reml() { # with limit to 5 matches per file
   rgv -m 5 -- "$*" $paths /a/t.org /p/w.org /a/work.org ||:
 }
 
+
+# for use in /f/bind
+fupzone() {
+  # shellcheck disable=SC2046 # i want word splitting
+  ./update-zone $(i s | sed -rn 's/.*db\.(.*)/\1/p')
+}
+
 # setup:
 # pip3 install linode-cli
 # linode-cli
@@ -3919,7 +4003,8 @@ rgv() {
   # -i = case insensitive
   # -M = max columns
   # --no-messages because of annoying errors on broken symlinks
-  command rg -. -z --no-messages -i -M 900 -g '!.git' -g '!auto-save-list' -g '!.savehist' "$@" || ret=$?
+  # --no-ignore-parent because i have /a/.git which ignores almost everything under it.
+  command rg -. -z --no-messages -i -M 900 --no-ignore-parent -g '!.git' -g '!auto-save-list' -g '!.savehist' "$@" || ret=$?
   return $ret
 }