From 85e4f3c44aa01c6fea732965a747f26731adab73 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Sat, 13 Jun 2020 14:23:57 +0200 Subject: move some scripts from bin/hibiki to bin --- bin/compose | 10 +++++++++ bin/enter | 54 +++++++++++++++++++++++++++++++++++++++++++++ bin/hibiki/compose | 10 --------- bin/hibiki/enter | 44 ------------------------------------- bin/hibiki/vncez | 23 -------------------- bin/hibiki/wfez | 38 -------------------------------- bin/vncez | 23 ++++++++++++++++++++ bin/wfez | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 151 insertions(+), 115 deletions(-) create mode 100755 bin/compose create mode 100755 bin/enter delete mode 100755 bin/hibiki/compose delete mode 100755 bin/hibiki/enter delete mode 100755 bin/hibiki/vncez delete mode 100755 bin/hibiki/wfez create mode 100755 bin/vncez create mode 100755 bin/wfez (limited to 'bin') diff --git a/bin/compose b/bin/compose new file mode 100755 index 0000000..e4a5dbd --- /dev/null +++ b/bin/compose @@ -0,0 +1,10 @@ +#!/bin/sh +cwd="$PWD" +container_cwd="/run/cwd/$(basename "$cwd")" +exec docker run \ + --rm -it \ + --net host \ + --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \ + --mount type=bind,src="$cwd",dst="$container_cwd" \ + -w "$container_cwd" \ + docker/compose:latest $@ diff --git a/bin/enter b/bin/enter new file mode 100755 index 0000000..d646541 --- /dev/null +++ b/bin/enter @@ -0,0 +1,54 @@ +#!/bin/sh +set -e +[ -n "$DEBUG" ] && set -x + +target= +img="" +dockerfile="${PWD}/Dockerfile" +become= +priv= + +usage() { + printf "usage: %s OPTIONS -- [DOCKER RUN ARGS]\n" "$(basename "$0")" + printf "\n" + printf " -t TARGET\n" + printf " -i IMAGE\n" + printf " -f DOCKERFILE\n" + printf " -u (become user)\n" + printf " -D (run with elevated privileged, but not privileged)\n" + printf "\n" + printf "Enter the container defined in Dockerfile, with \$PWD mounted at /src\n" + exit 2 +} + +while getopts t:i:f:uDh o; do + case $o in + t) target="$OPTARG" ;; + i) img="$OPTARG" ;; + f) dockerfile="$OPTARG" ;; + u) become=1 ;; + D) priv=1 ;; + h|?) usage ;; + esac +done +shift $((OPTIND - 1)) + +[ -z "$img" ] && img="$(basename "$(dirname "$(readlink -f -- "$dockerfile")")")" + +extra_args= +[ -n "$become" ] && extra_args="${extra_args}--user=$(id -u):$(id -g) " +[ -n "$priv" ] && { + extra_args="${extra_args}--tmpfs=/run --tmpfs=/sys/fs/cgroup "; + extra_args="${extra_args}--sysctl=net.ipv4.ip_forward=1 "; + extra_args="${extra_args}--security-opt=apparmor:unconfined --security-opt=seccomp:unconfined "; + extra_args="${extra_args}--cap-add NET_ADMIN --cap-add SYS_ADMIN --cap-add SYS_RESOURCE "; + extra_args="${extra_args}--tmpfs=/var/lib/docker "; +} + +# allow setting this to some non-file value to skip building +# > enter -i alpine -f none +# for a quick alpine based container with $PWD mounted in +[ -f "$dockerfile" ] && \ + docker build --tag="$img" --target="$target" --file="$dockerfile" "$(dirname "$dockerfile")" + +exec docker run --rm -it --mount=type=bind,src="$PWD",dst=/src -w /src $@ $extra_args "$img" diff --git a/bin/hibiki/compose b/bin/hibiki/compose deleted file mode 100755 index e4a5dbd..0000000 --- a/bin/hibiki/compose +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -cwd="$PWD" -container_cwd="/run/cwd/$(basename "$cwd")" -exec docker run \ - --rm -it \ - --net host \ - --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \ - --mount type=bind,src="$cwd",dst="$container_cwd" \ - -w "$container_cwd" \ - docker/compose:latest $@ diff --git a/bin/hibiki/enter b/bin/hibiki/enter deleted file mode 100755 index 67a9806..0000000 --- a/bin/hibiki/enter +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh -set -e -[ -n "$DEBUG" ] && set -x - -target= -img="" -dockerfile="${PWD}/Dockerfile" -become= - -usage() { - printf "usage: %s OPTIONS -- [DOCKER RUN ARGS]\n" "$(basename "$0")" - printf "\n" - printf " -t TARGET\n" - printf " -i IMAGE\n" - printf " -f DOCKERFILE\n" - printf " -u (become user)\n" - printf "\n" - printf "Enter the container defined in Dockerfile, with \$PWD mounted at /src\n" - exit 2 -} - -while getopts t:i:f:uh o; do - case $o in - t) target="$OPTARG" ;; - i) img="$OPTARG" ;; - f) dockerfile="$OPTARG" ;; - u) become=1 ;; - h|?) usage ;; - esac -done -shift $((OPTIND - 1)) - -[ -z "$img" ] && img="$(basename "$(dirname "$(readlink -f -- "$dockerfile")")")" - -extra_args= -[ -n "$become" ] && extra_args="--user=$(id -u):$(id -g)" - -# allow setting this to some non-file value to skip building -# > enter -i alpine -f none -# for a quick alpine based container with $PWD mounted in -[ -f "$dockerfile" ] && \ - docker build --tag="$img" --target="$target" --file="$dockerfile" "$(dirname "$dockerfile")" - -exec docker run --rm -it --mount=type=bind,src="$PWD",dst=/src -w /src $@ $extra_args "$img" diff --git a/bin/hibiki/vncez b/bin/hibiki/vncez deleted file mode 100755 index fa132f9..0000000 --- a/bin/hibiki/vncez +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -set -e - -if [ -n "$1" ]; then - printf "usage: %s\n" "$(basename "$0")" - printf "\n" - printf "launches wayvnc(1), wshowkeys(1) and remmina(1)\n" - exit 2 -fi - -trap '{ pkill wshowkeys; pkill wayvnc; pkill remmina; }' EXIT - -echo "=> starting wshowkeys" -swaymsg exec "wshowkeys -a bottom -a left -F 'Iosevka Sparkle 25' -t 1" >/dev/null -echo "=> starting wayvnc" -swaymsg exec "wayvnc 0.0.0.0 5500" >/dev/null -echo "=> starting remmina" -swx -g "1820,50 720x450" -b none -s -I "org.remmina.Remmina" remmina -c "$HOME"/.local/share/remmina/group_vnc_wayvnc_localhost-5500.remmina - -while true; do - sleep $((1024*1024)) -done diff --git a/bin/hibiki/wfez b/bin/hibiki/wfez deleted file mode 100755 index d2f296c..0000000 --- a/bin/hibiki/wfez +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -# set -x - -output_file=${1:-"${HOME}/Videos/rec_$(now).mkv"} -audio_output=${WF_AOUT:-alsa_output.pci-0000_00_1f.3.analog-stereo} -audio_input=${WF_AIN:-alsa_input.pci-0000_00_1f.3.analog-stereo} -video_output=${WF_VOUT:-DP-5} -showkeys=${WF_KEYS} - -mux_sink=${WF_ASINK} -if [ -z "${mux_sink}" ]; then - mux_sink=wf-mux - mux_sink_id= - output_loopback_id= - input_loopback_id= - prepare_mux_sink() { - mux_sink_id=$(pactl load-module module-null-sink sink_name="${mux_sink}") - output_loopback_id=$(pactl load-module module-loopback sink="${mux_sink}" source="${audio_output}.monitor") - input_loopback_id=$(pactl load-module module-loopback sink="${mux_sink}" source="${audio_input}") - } - teardown_mux_sink() { - pactl unload-module "${mux_sink_id}" - pactl unload-module "${output_loopback_id}" - pactl unload-module "${input_loopback_id}" - } - trap '{ teardown_mux_sink >/dev/null; }' EXIT - prepare_mux_sink >/dev/null -fi - -if [ -n "${showkeys}" ]; then - echo "Starting wshowkeys on ${video_output}" - echo "WARNING: currently the -o flag to force display to a specific output is not implemented" >&2 - sway exec "wshowkeys -a bottom -a left -F 'Iosevka Sparkle 25' -t 1 -o ${video_output}" >/dev/null - trap '{ pkill wshowkeys; }' EXIT -fi - -wf-recorder -c h264_vaapi -d /dev/dri/renderD128 -o "${video_output}" -a "${mux_sink}.monitor" -f "${output_file}" diff --git a/bin/vncez b/bin/vncez new file mode 100755 index 0000000..660db41 --- /dev/null +++ b/bin/vncez @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +if [ -n "$1" ]; then + printf "usage: %s\n" "$(basename "$0")" + printf "\n" + printf "launches wayvnc(1), wshowkeys(1) and remmina(1)\n" + exit 2 +fi + +trap '{ pkill wshowkeys; pkill wayvnc; pkill remmina; }' EXIT + +# echo "=> starting wshowkeys" +# swaymsg exec "wshowkeys -a bottom -a left -F 'Iosevka Sparkle 25' -t 1" >/dev/null +echo "=> starting wayvnc" +swaymsg exec "wayvnc -c dmabuf 0.0.0.0 5500" >/dev/null +echo "=> starting remmina" +swx -g "1820,50 720x450" -b none -s -I "org.remmina.Remmina" remmina -c "$HOME"/.local/share/remmina/group_vnc_wayvnc_localhost-5500.remmina + +while true; do + sleep $((1024*1024)) +done diff --git a/bin/wfez b/bin/wfez new file mode 100755 index 0000000..50f485d --- /dev/null +++ b/bin/wfez @@ -0,0 +1,64 @@ +#!/bin/sh +set -e +[ -n "$DEBUG" ] && set -x + +if [ "$1" = "-h" ]; then + printf "usage: %s [FILE]\n" "$(basename "$0")" + printf "\n" + printf "Launches wf-recorder(1) with optimized settings.\n" + printf "If FILE is omitted, \$HOME/Videos/rec_TIMESTAMP.mkv is used.\n" + printf "Optionally environment vars can be used to tune things:\n" + printf " WF_AOUT - defaults to default pulseaudio sink\n" + printf " WF_AIN - defaults to default pulseaudio source\n" + printf " WF_AMUX - override creation of an pulseaudio sink for muxing\n" + printf " WF_VOUT - limit to output, defaults to focused output (swq current output)\n" + printf " WF_KEYS - launches wshowkeys(1)\n" + exit 2 +fi + +output_file=${1:-"${HOME}/Videos/rec_$(now).mkv"} +audio_output=${WF_AOUT} +audio_input=${WF_AIN} +video_output=${WF_VOUT} +showkeys=${WF_KEYS} +mux_sink=${WF_AMUX} + +[ -z "${audio_output}" ] && audio_output=$(pacmd dump | grep "set-default-sink" | cut -d' ' -f2) +[ -z "${audio_input}" ] && audio_input=$(pacmd dump | grep "set-default-source" | cut -d' ' -f2) +[ -z "${video_output}" ] && video_output=$(swq current output) + +if [ "${WF_AIN}" = "none" ] && [ -z "${WF_AMUX}" ]; then + echo "mux: ${audio_output}" + mux_sink="${audio_output}" +fi + +if [ -z "${mux_sink}" ]; then + mux_sink=wf-mux + mux_sink_id= + output_loopback_id= + input_loopback_id= + prepare_mux_sink() { + mux_sink_id=$(pactl load-module module-null-sink sink_name="${mux_sink}" channels=2) + output_loopback_id=$(pactl load-module module-loopback sink="${mux_sink}" source="${audio_output}.monitor" remix=true) + input_loopback_id=$(pactl load-module module-loopback sink="${mux_sink}" source="${audio_input}" remix=true) + } + teardown_mux_sink() { + pactl unload-module "${mux_sink_id}" + pactl unload-module "${output_loopback_id}" + pactl unload-module "${input_loopback_id}" + } + trap '{ teardown_mux_sink >/dev/null; }' EXIT + prepare_mux_sink >/dev/null + echo "mux: ${mux_sink}" +fi + +if [ -n "${showkeys}" ]; then + echo "Starting wshowkeys on ${video_output}" + echo "WARNING: currently the -o flag to force display to a specific output is not implemented" >&2 + # -o ${video_output} + sway exec "wshowkeys -a bottom -a left -F 'Iosevka Sparkle 25' -t 1" >/dev/null + trap '{ pkill wshowkeys; }' EXIT +fi + +set -x +wf-recorder -c h264_vaapi -d /dev/dri/renderD128 -o "${video_output}" -a "${mux_sink}.monitor" -f "${output_file}" -- cgit 1.4.1