X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=brc2;h=6ac51839640d6b111de332c2196a89468ff154f4;hb=HEAD;hp=104907e67c76f2d4df1f737ff986a3300d9db381;hpb=989554cab0d0c59d1aab20496ba9550acd17e6e6;p=distro-setup diff --git a/brc2 b/brc2 index 104907e..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 } @@ -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 } @@ -4932,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