+
+# standard date as used in logs
+datelog() {
+ date +%Y-%m-%d "$@"
+}
+
+# date in log appropriate format
+dtl() {
+ date "+%F %T" "$@"
+}
+
+# ts formatted
+tsf() {
+ command ts "%F %T" "$@"
+}
+
+# ts log. log command to log file.
+# usage: tsl LOG_PATH_PREFIX COMMAND...
+# example: tsl /root/command
+# log file will be like /root/command-2024-02-10.log
+tsl() {
+ local log_prefix log_path appending ret
+ if (( $# < 2 )); then
+ echo "tsl: error: expected >= 2 arguments, got $#" >&2
+ return 1
+ fi
+ log_prefix="$1"
+ if [[ $log_prefix == */* && ! -d ${log_prefix%*/} ]]; then
+ echo "tsl: error: expected directory at ${log_prefix%*/}" >&2
+ return 1
+ fi
+ log_path=$log_prefix-$(date +%Y-%m-%d).log
+ appending=false
+ if [[ -s $log_path ]]; then
+ appending=true
+ fi
+ shift
+ printf "%s\n" "CWD: $PWD, log: $log_path, running $*" | ts "%F %T" | tee -a "$log_path"
+ ret=0
+ "$@" |& ts "%F %T" | tee -a "$log_path" || ret=$?
+ printf "%s\n" "exit code $ret from command: $*" | ts "%F %T" | tee -a "$log_path"
+ if $appending; then
+ printf "%s\n" "note: this log file contains logs before those of previous command" | ts "%F %T" | tee -a "$log_path"
+ fi
+}
+
+disk-info() {
+ local cmds cmd
+ mapfile -t cmds <<'EOF'
+tail -n +1 /proc/mdstat /etc/mdadm/mdadm.conf /etc/fstab /etc/crypttab
+lsblk
+blkid
+ls -la /dev/disk/by-id
+EOF
+
+ for cmd in "${cmds[@]}"; do
+ cat <<EOF
+### $cmd
+
+\`\`\`
+EOF
+ $cmd
+ cat <<'EOF'
+
+```
+
+EOF
+ 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
+}
+