X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=brc2;h=6ac51839640d6b111de332c2196a89468ff154f4;hb=refs%2Fheads%2Fmaster;hp=ff0d7a8c97f38dedbbd3d284df7553cef5fe3b18;hpb=3342374657bd712f14cd772378b23d2bca3382cb;p=distro-setup diff --git a/brc2 b/brc2 index ff0d7a8..fe5d60f 100644 --- 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 } @@ -2882,8 +2883,8 @@ EOF tmpf=$(mktemp) { printf "%s" "Host * " - sed -n '/^Host /h;/^IdentityFile .*\/home/{g;s/^Host//;s/ / !/gp}' /p/c/subdir_files/.ssh/config-static | tr '\n' ' ' - echo + sed -n '/^Host /h;/^IdentityFile .*\/home/{g;s/^Host//;s/ / !/gp}' /p/c/subdir_files/.ssh/config-static | tr '\n' ' ' \ + | sed -r 's/ *$/\n/' echo "IdentityFile ~/.ssh/work" } >$tmpf cedit -e work-identity /p/c/subdir_files/.ssh/config-static <$tmpf @@ -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 < AuthType Basic @@ -4769,8 +4840,23 @@ AuthUserFile "/etc/icecast-fsf-tech-htpasswd" Require valid-user 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() { ls -l /tmp/no-obs-auto-scene-switch @@ -4854,19 +4940,62 @@ klease() { } # ffs and switch the bash history on this terminal. -ffs() { - local last - last="${*: -1}" - if [[ $last && $last != -* && $last != sysops ]]; then - his - fi - command ffs "$@" -} +# disabled because I don't really need this and +# the history switching is annoying for debugging. +# +# ffs() { +# local last +# last="${*: -1}" +# if [[ $last && $last != -* && $last != sysops ]]; then +# his +# fi +# command ffs "$@" +# } i3gen() { /b/ds/i3-sway/gen } + +# insensitive find plus edit +ife() { + local tmps found_count i char file + local -a found_files + local -A button_file + tmps=$(ifn "$@") + mapfile -t found_files <<<"$tmps" + found_count=${#found_files[@]} + if (( ${#found_files[@]} == 1 )); then + m g ${found_files[0]} + else + i=0 + for button in {a..z}; do + button_file[$button]="${found_files[$i]}" + echo $button: ${found_files[$i]} + i=$(( i + 1 )) + if (( i >= found_count )); then + break + fi + done + read -rsN1 -t 5 char ||: + file="${button_file[$char]}" + + if [[ $file ]]; then + g "$file" + else + echo "no selection" + fi + 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 #export ANDROID_HOME=/a/opt/android-home