general fixes
[distro-setup] / brc
diff --git a/brc b/brc
index d60af90a674155158c01557efad5eaf143c0c57c..32a2c66212893c101c8e7c57670f5486a6f613c8 100644 (file)
--- a/brc
+++ b/brc
@@ -774,6 +774,50 @@ EOF
   done
 }
 
   done
 }
 
+screenrtp() {
+
+  local ip port xoffset
+  read -r ip port xoffset <<<"$@"
+
+  setxenv
+
+  if [[ ! $port ]]; then
+    port=9999
+  fi
+
+  while true; do
+    # By default, plugged in screen goes to the right side, so we need an
+    # offset that is the same as the laptop's x resolution. If we are in
+    # mirror mode, then we don't need an offset.
+    if [[ ! $xoffset ]]; then
+      xoffset=0
+      laptop_x=$(xrandr | awk '$1 == "LVDS-1" {print $4}' | sed 's/x.*//') || { sleep 1; continue; }
+      total_x=$(xdpyinfo| awk '$1 == "dimensions:" {print $2}' | sed 's/x.*//') || { sleep 1; continue; }
+      screen2_res=$(xrandr | awk '$2 == "connected" && $1 != "LVDS-1" { print $3 }' | sed 's/+.*//')
+      if (( laptop_x < total_x )); then
+        xoffset=$laptop_x
+      fi
+    fi
+
+    m ffmpeg -probesize 50M -thread_queue_size 50 \
+      -video_size $screen2_res -f x11grab -framerate 30 -i :0.0+$xoffset.0 \
+      -vcodec libx264 -g 1 -tune zerolatency -preset ultrafast -pix_fmt yuv420p -x264-params repeat-headers=1 \
+      -f rtp_mpegts rtp://$ip:$port ||:
+
+
+    sleep 1
+  done
+}
+
+setxenv() {
+  if [[ ! $DISPLAY ]]; then
+    export DISPLAY=:0.0
+  fi
+  if [[ ! $XAUTHORITY ]]; then
+    export XAUTHORITY=$HOME/.Xauthority
+  fi
+}
+
 #### end fsf section
 
 
 #### end fsf section
 
 
@@ -815,25 +859,40 @@ fpst() { # file paste
 }
 
 _khfix-common() {
 }
 
 _khfix-common() {
-  local host ip port file key tmp
-  read -r host ip port < <(timeout -s 9 2 ssh -oBatchMode=yes -oControlMaster=no -oControlPath=/ -v $1 |& sed -rn "s/debug1: Connecting to ([^ ]+) \[([^\]*)] port ([0-9]+).*/\1 \2 \3/p" ||: )
+  local host ip port file key tmp ssh_host alias
+  ssh_host=$1
+  {
+    read -r host ip port
+    read -r alias;
+    # note ":graph:" is needed or else we get a trailing \r out of ssh,
+    # dunno why.  web search says terminals add \r, so I tried adding -T
+    # to turn off psuedo terminal, but it didnt help.
+  } < <(timeout -s 9 2 ssh -TN -oBatchMode=yes -oControlMaster=no -oControlPath=/ -v $ssh_host |&
+        sed -rn "s/debug1: Connecting to ([^ ]+) \[([^\]*)] port ([0-9]+).*/\1 \2 \3/p;
+s/^debug1: using hostkeyalias: ([[:graph:]]*).*/\1/p" ||: )
   file=$(readlink -f ~/.ssh/known_hosts)
   if [[ ! $ip ]]; then
     echo "khfix: ssh failed"
     return 1
   fi
   file=$(readlink -f ~/.ssh/known_hosts)
   if [[ ! $ip ]]; then
     echo "khfix: ssh failed"
     return 1
   fi
+  ip_entry=$ip
+  host_entry=$host
+  if [[ $alias ]]; then
+    host_entry="$alias"
+  fi
   if [[ $port != 22 ]]; then
     ip_entry="[$ip]:$port"
   if [[ $port != 22 ]]; then
     ip_entry="[$ip]:$port"
-    host_entry="[$host]:$port"
-  else
-    ip_entry=$ip
-    host_entry=$host
+    if [[ ! $alias ]]; then
+      host_entry="[$host]:$port"
+    fi
   fi
   fi
-  if [[ $host != "$ip" ]]; then
+  if [[ $host_entry != "$ip_entry" ]]; then
     tmp=$(mktemp)
     ssh-keygen -F "$host_entry" -f $file >$tmp || [[ $? == 1 ]] # 1 when it doesnt exist in the file
     if [[ -s $tmp ]]; then
       key=$(sed -r 's/^.*([^ ]+ +[^ ]+) *$/\1/' $tmp)
     tmp=$(mktemp)
     ssh-keygen -F "$host_entry" -f $file >$tmp || [[ $? == 1 ]] # 1 when it doesnt exist in the file
     if [[ -s $tmp ]]; then
       key=$(sed -r 's/^.*([^ ]+ +[^ ]+) *$/\1/' $tmp)
+    else
+      echo "khfix WARNING: did not find host entry:$host_entry in known_hosts"
     fi
     rm $tmp
     if [[ $key ]]; then
     fi
     rm $tmp
     if [[ $key ]]; then
@@ -845,12 +904,13 @@ _khfix-common() {
   ssh-keygen -F "$ip_entry" -f $file >$tmp || [[ $? == 1 ]]
   if [[ -s $tmp ]]; then
     key=$(sed -r 's/^.*([^ ]+ +[^ ]+) *$/\1/' $tmp)
   ssh-keygen -F "$ip_entry" -f $file >$tmp || [[ $? == 1 ]]
   if [[ -s $tmp ]]; then
     key=$(sed -r 's/^.*([^ ]+ +[^ ]+) *$/\1/' $tmp)
+  else
+    echo "khfix WARNING: did not find ip entry:$ip_entry in known_hosts"
   fi
   rm $tmp
   if [[ $key ]]; then
     grep -Fv "$key" "$file" | sponge "$file"
   fi
   fi
   rm $tmp
   if [[ $key ]]; then
     grep -Fv "$key" "$file" | sponge "$file"
   fi
-  ll ~/.ssh/known_hosts
 }
 khfix-r() { # known hosts fix without syncing to root user
   _khfix-common "$@" || return 1
 }
 khfix-r() { # known hosts fix without syncing to root user
   _khfix-common "$@" || return 1
@@ -1375,7 +1435,12 @@ egrinid() {
   sed -rn '/testignore|jtuttle|eximbackup/!s/^[^ ]+ ([^ ]+) [^ ]+ [^ ]+ <= ([^ ]+).* id=([^ ]+) T="(.*)" from (<[^ ]+> .*$)/\1 \5\n \3\n \4/p' <${1:-/var/log/exim4/mainlog}
 }
 etailin() {
   sed -rn '/testignore|jtuttle|eximbackup/!s/^[^ ]+ ([^ ]+) [^ ]+ [^ ]+ <= ([^ ]+).* id=([^ ]+) T="(.*)" from (<[^ ]+> .*$)/\1 \5\n \3\n \4/p' <${1:-/var/log/exim4/mainlog}
 }
 etailin() {
-  tail -F /var/log/exim4/mainlog | sed -rn '/testignore|jtuttle|eximbackup/!s/^[^ ]+ ([^ ]+) [^ ]+ [^ ]+ <= ([^ ]+).*T="(.*)" from (<[^ ]+> .*$)/\1 \4\n \3/p'
+  local -a tail_arg
+  tail_arg=(-n500)
+  if [[ $1 ]]; then
+    tail_arg=($@)
+  fi
+  tail "${tail_arg[@]}" -F /var/log/exim4/mainlog | sed -rn '/testignore|jtuttle|eximbackup/!s/^[^ ]+ ([^ ]+) [^ ]+ [^ ]+ <= ([^ ]+).*T="(.*)" from (<[^ ]+> .*$)/\1 \4\n \3/p'
 }
 
 
 }
 
 
@@ -2046,9 +2111,9 @@ nags() {
   /usr/bin/nagstamon &
 }
 
   /usr/bin/nagstamon &
 }
 
-# profanity screen
+# profanity tmux
 profsrc() {
 profsrc() {
-  screen -RD -S profanity
+  screen -L profanity a
 }
 
 # i dont want to wait for konsole to exit...
 }
 
 # i dont want to wait for konsole to exit...
@@ -2447,20 +2512,14 @@ sk() {
   local quotes others ret
   quotes=2048,2068,2086,2206,2254
   others=2029,2032,2033,2054,2164
   local quotes others ret
   quotes=2048,2068,2086,2206,2254
   others=2029,2032,2033,2054,2164
-  # Dont complain about sourced files if we aren't asking for them.
-  if [[ $1 != -x ]]; then
-    others+=,1091
-  fi
-  shellcheck -W 999 -e $quotes,$others "$@" || ret=$?
+  shellcheck -x -W 999 -e $quotes,$others "$@" || ret=$?
   if (( ret >= 1 )); then
     echo "A template comment to disable is now in clipboard. eg: # shellcheck disable=SC2206 # reason"
     cbs "# shellcheck disable=SC"
     return $ret
   fi
 }
   if (( ret >= 1 )); then
     echo "A template comment to disable is now in clipboard. eg: # shellcheck disable=SC2206 # reason"
     cbs "# shellcheck disable=SC"
     return $ret
   fi
 }
-skx() {
-  sk -x "$@"
-}
+
 # sk with quotes. For checking scripts that we expect to take untrusted
 # input in order to verify we quoted vars.
 skq() {
 # sk with quotes. For checking scripts that we expect to take untrusted
 # input in order to verify we quoted vars.
 skq() {
@@ -2480,49 +2539,24 @@ skmodified() {
 }
 
 
 }
 
 
-# sk on all the files in current git repo (except those excluded)
+# sk on all the files in current git repo
 skgit() {
 skgit() {
-  local f toplevel orig_dir tmp skip pattern
-  local -a ls_files excludes
+  local f toplevel orig_dir tmp
+  local -a ls_files sk_files
   toplevel=$(git rev-parse --show-toplevel)
   if [[ $PWD != "$toplevel" ]]; then
     orig_dir=$PWD
     cd $toplevel
   fi
   toplevel=$(git rev-parse --show-toplevel)
   if [[ $PWD != "$toplevel" ]]; then
     orig_dir=$PWD
     cd $toplevel
   fi
-  excludes=(
-    'disabled/*'
-    # sourced from brc2
-    beet-data
-    # sourced from .bash_profile
-    .bashrc
-  )
-  no_check_sourced=(
-    .bash_profile
-  )
-  tmp=$(git ls-files | shuf)
+  # tracked & untracked files
+  tmp=$(git ls-files && git ls-files --others --exclude-standard)
   mapfile -t ls_files <<<"$tmp"
   for f in "${ls_files[@]}"; do
   mapfile -t ls_files <<<"$tmp"
   for f in "${ls_files[@]}"; do
-    skip=false
-    for pattern in "${excludes[@]}"; do
-      if [[ $f == $pattern ]]; then
-        skip=true
-        break
-      fi
-    done
-    if $skip; then continue; fi
-
-    check_source=-a
-    for pattern in "${no_check_sourced[@]}"; do
-      if [[ $f == "$pattern" ]]; then
-        check_source=
-        break
-      fi
-    done
     if sk-p "$f"; then
     if sk-p "$f"; then
-      printf "================= %s\n" "$f"
-      sk $check_source --color=always $f || [[ $? == 1 ]]
+      sk_files+=("$f")
     fi
   done
     fi
   done
+  sk "${sk_files[@]}"
   if [[ $orig_dir ]]; then
     cd $orig_dir
   fi
   if [[ $orig_dir ]]; then
     cd $orig_dir
   fi
@@ -2762,8 +2796,15 @@ sl() {
 slr() {
   sl --rsync "$@"
 }
 slr() {
   sl --rsync "$@"
 }
-sss() { # ssh solo
-  sl -oControlMaster=no -oControlPath=/ "$@"
+
+
+# ssh solo
+#
+# WARNING: If you are trying to use -i, remember that keys added to
+# agent previously will still be tried. Use ssh-add -D to remove all
+# keys from the agent.
+sss() {
+  ssh -oControlMaster=no -oControlPath=/ "$@"
 }
 # kill off old shared socket then ssh
 ssk() {
 }
 # kill off old shared socket then ssh
 ssk() {
@@ -3406,6 +3447,39 @@ if [[ $- == *i* ]]; then
 
 fi
 
 
 fi
 
+
+lp22viewers() {
+  v=0
+  roomv=(0 0)
+  rooms=(jupiter saturn)
+  for ip in 209.51.188.25 live.fsf.org; do
+    out=$(curl -sS --insecure https://$ip/)
+    for i in 0 1 2; do
+      room=${rooms[i]}
+      while read -r n; do
+        v=$((v+n))
+        roomv[$i]=$(( ${roomv[$i]} + n ))
+      done < <(printf "%s\n" "$out"  | grep -Po "$room.*?current[^0-9]*[0-9]*" | grep -o '[0-9]*$' )
+    done
+  done
+  printf "total: %s " $v
+  for i in 0 1; do
+    room=${rooms[i]}
+    printf "$room: %s " "${roomv[$i]}"
+  done
+  echo
+}
+
+arpflush() {
+  local default_route_dev
+  default_route_dev=$(ip r show default | sed 's/.*dev \([^ ]*\).*/\1/' | head -n1)
+  m s ip n flush dev "$default_route_dev"
+}
+
+dsh() {
+  command dsh -c "$@"
+}
+
 # * stuff that makes sense to be at the end
 
 
 # * stuff that makes sense to be at the end