distro specific fixes
[distro-setup] / brc2
diff --git a/brc2 b/brc2
index d46028dfddb744c985d3b90658ea963047787180..fe5d60fce42c9a8fb1a7b567ed0a2bce0517f77e 100644 (file)
--- a/brc2
+++ b/brc2
@@ -364,29 +364,30 @@ edelayon() {
 eqgo() {
   local -a array tmpstr delayon
   delayon=true
-  if grep -qFx all /etc/exim4/no-delay-eximids; then
+  if grep -qFx all /var/spool/exim4/gw/.no-delay-eximids; then
     delayon=false
   fi
   if $delayon; then
-    echo all >/etc/exim4/no-delay-eximids
+    echo all >/var/spool/exim4/gw/.no-delay-eximids
   fi
   tmpstr=$(exiqgrep -i -r.\*)
   mapfile -t array <<<"$tmpstr"
   enn -M "${array[@]}"
   if $delayon; then
-    echo >/etc/exim4/no-delay-eximids
+    echo >/var/spool/exim4/gw/.no-delay-eximids
   fi
 }
 eqgo1() {
   local eid
   eid="$(exipick -i -r.\*|h1)"
-  sed -n "/^all$/p;\$a $eid" /etc/exim4/no-delay-eximids
+  sed -n "/^all$/p;\$a $eid" /var/spool/exim4/gw/.no-delay-eximids
   enn -M "$eid"
 }
+# exim -M (in namespace and without delay)
 ennm() {
   local eid
   for eid; do
-    printf "%s\n" "$eid" >>/etc/exim4/no-delay-eximids
+    printf "%s\n" "$eid" >>/var/spool/exim4/gw/.no-delay-eximids
   done
   enn -M "$@"
 }
@@ -2036,12 +2037,12 @@ apache-strip() {
   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
 }
 
-chrome() {
+chro() {
   if type -p chromium &>/dev/null; then
     cmd=chromium
   else
     cd /
-    cmd="schroot -c bullseye chromium"
+    cmd="schroot -c bookworm chromium"
     CHROMIUM_FLAGS='--enable-remote-extensions' $cmd & r
   fi
 }
@@ -3032,40 +3033,59 @@ EOF
   )
 }
 
+# sudo maybe
+#
+# passes on any initial -* args to sudo.
+sudm() {
+  local arg
+  local -a sudo_opts
+  for arg; do
+    if [[ $arg == -* ]]; then
+      sudo_opts+=("$arg")
+      shift
+    else
+      break
+    fi
+  done
+  if [[ $EUID == 0 ]]; then
+    "$@"
+  else
+    sudo "${sudo_opts[@]}" "$@"
+  fi
+}
 
-mns() { # mount namespace
+mns-setup() {
+  local ns
   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
+  sudm mkdir -p /root/mount_namespaces
+  if ! sudm mountpoint /root/mount_namespaces >/dev/null; then
+    m sudm 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
+  m sudm mount --make-private /root/mount_namespaces
+  if ! sudm test -e /root/mount_namespaces/$ns; then
+    m sudm 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
+  if ! sudm mountpoint /root/mount_namespaces/$ns >/dev/null; then
+    m sudm unshare --propagation slave --mount=/root/mount_namespaces/$ns /bin/true
   fi
-  m sudo -E /usr/bin/nsenter --mount=/root/mount_namespaces/$ns "$@"
+
+}
+
+mns() { # mount namespace
+  local ns
+  ns=$1
+  shift
+  mns-setup $ns
+  m sudm -E /usr/bin/nsenter --mount=/root/mount_namespaces/$ns "$@"
 }
 
 mnsd() { # mount namespace + systemd namespace
+  local ns unit
   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
+  mns-setup $ns
 
   pid=$(servicepid $unit)
   tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX)
@@ -3271,6 +3291,11 @@ mpvd() {
 mpva() {
   mpv --profile=a "$@";
 }
+# mpv for testing video quality, dont scale.
+mpvt() {
+  mpv --video-unscaled "$@";
+  }
+
 # mpv all media files in . or $1
 mpvm() {
   local -a extensions arg
@@ -3904,7 +3929,7 @@ torshell() {
 }
 
 eless2() {
-  less /var/log/exim4/mymain
+  less /var/log/exim4/nondmain
 }
 
 
@@ -4013,7 +4038,7 @@ tu() {
 enn() {
   local ecmd pid
 
-  ecmd="/usr/sbin/exim4 -C /etc/exim4/my.conf"
+  ecmd="/usr/sbin/exim4 -C /etc/exim4/nn-mainlog.conf"
   if ip a show veth1-mail &>/dev/null; then
     s $ecmd "$@"
   else
@@ -4103,6 +4128,25 @@ sdncmdroot() { # systemd namespace root command
 }
 
 
+# systemd network namespace (not mount) cmd
+# usage: UNIT CMD...
+sdnncmd() {
+  local unit pid tmpf
+  if (( $# <= 1 )); then
+    echo $0: error wrong number of args >&2
+    return 1
+  fi
+  unit=$1
+  shift
+  pid=$(servicepid $unit)
+  tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX)
+  export -p >$tmpf
+  printf "%s " "${@@Q}" >>$tmpf
+  echo >>$tmpf
+  m sudo nsenter -t $pid -n sudo -u $USER -i bash -c ". $tmpf & rm $tmpf"
+}
+
+
 mailnnbash() {
   sdnbash mailnn
 }
@@ -4610,7 +4654,15 @@ if type -P rg &>/dev/null; then
   # --no-messages because of annoying errors on broken symlinks
   # -z = search .gz etc files
   # -. = search dotfiles
-  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 $?; }
+  # -n --no-heading: show files and line numbers together allowing for clicking
+  rg() {
+    local path_arg
+    if [[ ${#@} == 1 ]]; then
+      path_arg=.
+    fi
+
+    command rg -. -z --no-messages -Lin --no-heading -M 900 --no-ignore-parent --no-ignore-vcs -g '!.git' -g '!auto-save-list' -g '!.savehist' "$@" $path_arg || return $?
+  }
   #fails if not exist. ignore
   complete -r rg 2>/dev/null ||:
 else
@@ -4619,7 +4671,10 @@ fi
 
 # rg with respecting vcs ignore files
 rgv() {
-  ret=0
+  local path_arg ret=0
+  if [[ ${#@} == 1 ]]; then
+    path_arg=.
+  fi
   # settings that are turned off for pipes, keep them on.
   # Found by searching for "terminal" in --help
   # --heading
@@ -4629,9 +4684,10 @@ rgv() {
   # -z = search zipped files
   # -i = case insensitive
   # -M = max columns
+  # -n --no-heading: show files and line numbers together allowing for clicking
   # --no-messages because of annoying errors on broken symlinks
   # --no-ignore-parent because i have /a/.git which ignores almost everything under it.
-  command rg -n --heading -. -z --no-messages -i -M 900 --no-ignore-parent -g '!.git' -g '!auto-save-list' -g '!.savehist' "$@" || ret=$?
+  command rg -n --no-heading -. -z --no-messages -i -M 900 --no-ignore-parent -g '!.git' -g '!auto-save-list' -g '!.savehist' "$@" $path_arg || ret=$?
   return $ret
 }
 
@@ -4750,9 +4806,24 @@ ftoc() {
   units "tempF($1)" tempC
 }
 
-# note: requires dns setup of live.iankelling.org, & if i'm home, port
-# forwarding in wrt-setup-local.  todo: automate that.
-local-icecast() {
+# local icecast
+localic() {
+  local mod=false
+  cedit live /p/c/machine_specific/vps/filesystem/var/lib/bind/db.iankelling.org <<'EOF' || mod=true
+live   CNAME   b8.nz.
+EOF
+  if $mod; then
+    ip=$(ip r show default | sed -r 's/.*src ([^ ]*).*/\1/' | head -n1)
+    if [[ ! $ip ]] && timeout 1 ping -c 1 $ip; then
+      echo "error: failed to get ip: $ip" >&2
+      exit 1
+    fi
+    cat >/p/c/cmc-firewall-data-http <<EOF
+http_ip=$ip
+EOF
+    bindpush
+    wrt-setup
+  fi
   web-conf -e ian@iankelling.org -f 8000 - apache2 live.iankelling.org  <<'EOF'
 <Location "/fsf.webm">
 AuthType Basic
@@ -4768,8 +4839,23 @@ AuthName "basic_auth"
 AuthUserFile "/etc/icecast-fsf-tech-htpasswd"
 Require valid-user
 </Location>
+EOF
+  s cat /etc/letsencrypt/live/live.iankelling.org/{fullchain,privkey}.pem | s dd of=/etc/icecast2/fullchainpluskey.pem
+  ser start icecast2
+}
+# li icecast
+liic() {
+  cedit live /p/c/machine_specific/vps/filesystem/var/lib/bind/db.iankelling.org <<'EOF' || bindpush
+live   A       72.14.176.105
+       AAAA    2600:3c00::f03c:91ff:fe6d:baf8
 EOF
 }
+# icecast rm -r
+icrmr() {
+  find /var/icecast -type f -delete
+  ssh li.b8.nz find /var/icecast -type f -delete
+}
+
 
 # obs screen switching of
 obof() {
@@ -4902,6 +4988,13 @@ ife() {
   fi
 }
 
+# decrease filesize without losing any noticeable quality. inspired from
+# https://gist.github.com/BlueSwordM/86dfcb6ab38a93a524472a0cbe4c4100
+ffsencode() {
+  in="$1"
+  out="$2"
+  ffmpeg -i "$in" -c:v libsvtav1 -crf 60 -preset 6 -g 60 -svtav1-params tune=0:enable-overlays=1:scd=1:scm=1 -pix_fmt yuv420p10le -c:a copy "$out"
+}
 
 export BASEFILE_DIR=/a/bin/fai-basefiles