~zenomat/scripts

9523783a150663d3296ddef57f7d1cc604a81606 — zeno 3 months ago 1903956 main
updated a bit
10 files changed, 408 insertions(+), 17 deletions(-)

A arr.sh
A gpg-pinentry-loopback
M lock -rwxr-xr-x => -rw-r--r--
A prep-lock
A remarkable/reStream.sh
A remarkable/remarkable-cli-tooling
A remarkable/resync.py
M startup
M status
M statusbar/timer
A arr.sh => arr.sh +106 -0
@@ 0,0 1,106 @@
#!/usr/bin/env bash

if [ ! -z $radarr_eventtype ]; then
	service="Radarr"
	notType=$radarr_eventtype
	title=$radarr_movie_title
	health_issue_level=$radarr_health_issue_level
	health_issue_message=$radarr_health_issue_message
	health_issue_trigger=$radarr_health_issue_type
	notification_string="\"$title\""
fi
if [ ! -z "$sonarr_eventtype" ]; then
	service="Sonarr"
	notType=$sonarr_eventtype
	title=$sonarr_series_title
	episode_count=$sonarr_release_episodecount
	health_issue_level=$sonarr_health_issue_level
	health_issue_message=$sonarr_health_issue_message
	health_issue_trigger=$sonarr_health_issue_type
	notification_string="\"$title\" ($episode_count Episodes)"
fi
if [ "$notType" = "Test" ]; then
	curl \
		-u zeno:GrLdt59TpNq3va \
		-H "X-Title: $service notification test" \
		-H "X-Tags: warning" \
		-d "Test notification" \
		https://ntfy.groundzeno.net/private
	exit 0
fi
if [ "$notType" = "Grab" ]; then
	curl \
		-u zeno:GrLdt59TpNq3va \
		-H "X-Title: $service download" \
		-H "X-Tags: arrow_down" \
		-d "Started downloading $notification_string" \
		https://ntfy.groundzeno.net/private
	exit 0
fi
if [ "$notType" = "Download" ]; then
	curl \
		-u zeno:GrLdt59TpNq3va \
		-H "X-Title: $service download" \
		-H "X-Tags: white_check_mark,arrow_down" \
		-d "Finished downloading $notification_string" \
		https://ntfy.groundzeno.net/private
	exit 0
fi
if [ "$notType" = "Rename" ]; then
	curl \
		-u zeno:GrLdt59TpNq3va \
		-H "X-Title: $service rename" \
		-H "X-Tags: arrows_counterclockwise" \
		-d "Renamed $notification_string" \
		https://ntfy.groundzeno.net/private
	exit 0
fi
if [ "$notType" = "EpisodeFileDelete" ]; then
	curl \
		-u zeno:GrLdt59TpNq3va \
		-H "X-Title: $service delete episode(s)" \
		-H "X-Tags: bucket" \
		-d "Deleted $sonarr_episodefile_episodetitles from $sonarr_series_title" \
		https://ntfy.groundzeno.net/private
	exit 0
fi
if [ "$notType" = "SeriesDelete" ]; then
	curl \
		-u zeno:GrLdt59TpNq3va \
		-H "X-Title: $service delete series" \
		-H "X-Tags: bucket" \
		-d "Deleted $sonarr_series_title" \
		https://ntfy.groundzeno.net/private
	exit 0
fi
if [ "$notType" = "HealthIssue" ]; then
	if [ "$health_issue_level" = "Ok" ]; then
		health_emoji="green_circle"
	fi
	if [ "$health_issue_level" = "Notice" ]; then
		health_emoji="yellow_circle"
	fi
	if [ "$health_issue_level" = "Warning" ]; then
		health_emoji="orange_circle"
	fi
	if [ "$health_issue_level" = "Error" ]; then
		health_emoji="read_circle"
	fi
	curl \
		-u zeno:GrLdt59TpNq3va \
		-H "X-Title: $service health issue" \
		-H "X-Tags: $health_emoji" \
		-d "From $health_issue_trigger: $health_issue_message" \
		https://ntfy.groundzeno.net/private
	exit 0
fi
if [ "$notType" = "ApplicationUpdate" ]; then
	curl \
		-u zeno:GrLdt59TpNq3va \
		-H "X-Title: $service update" \
		-H "X-Tags: white_check_mark,arrow_up" \
		-d "Finished update to new version" \
		https://ntfy.groundzeno.net/private
	exit 0
fi
exit 1

A gpg-pinentry-loopback => gpg-pinentry-loopback +2 -0
@@ 0,0 1,2 @@
#!/usr/bin/bash
gpg --pinentry-mode loopback $@

M lock => lock +4 -4
@@ 1,9 1,9 @@
#!/bin/sh

scrot -q 100 'lock.png'
scrot -q 100 ./lock.png

betterlockscreen -u lock.png -b 0.9
betterlockscreen -u ./lock.png --span --blur 0.9

rm -rf lock.png
rm -rf ./lock.png

betterlockscreen -l blur dim
betterlockscreen -l blur

A prep-lock => prep-lock +16 -0
@@ 0,0 1,16 @@
#!/bin/bash

# if [ -z "$(lsusb | grep OnlyKey)" ]; then
logger "OnlyKey Removed or Changed"
sessionids=$(/bin/loginctl list-sessions | grep zeno | awk '{print $1}')
for id in $sessionids; do
	logger "Locking session id:" $id
	/bin/loginctl lock-session $id
done

ttys=$(w | grep zeno | grep -v xinit | grep tty | awk '{print $2}')
for tty in $ttys; do
	logger "Locking tty: " $tty
	pkill -9 -t $tty
done
# fi

A remarkable/reStream.sh => remarkable/reStream.sh +263 -0
@@ 0,0 1,263 @@
#!/bin/sh

# Current reStream.sh version
version="1.2.0"

# default values for arguments
remarkable="10.11.99.1"   # remarkable connected through USB
landscape=true            # rotate 90 degrees to the right
output_path=-             # display output through ffplay
format=-                  # automatic output format
webcam=false              # not to a webcam
hflip=false               # horizontal flip webcam
measure_throughput=false  # measure how fast data is being transferred
window_title=reStream     # stream window title is reStream
video_filters=""          # list of ffmpeg filters to apply
unsecure_connection=false # Establish a unsecure connection that is faster

# loop through arguments and process them
while [ $# -gt 0 ]; do
    case "$1" in
        -v | --version)
            echo "reStream version: v$version"
            exit
            ;;
        -p | --portrait)
            landscape=false
            shift
            ;;
        -s | --source)
            remarkable="$2"
            shift
            shift
            ;;
        -o | --output)
            output_path="$2"
            shift
            shift
            ;;
        -f | --format)
            format="$2"
            shift
            shift
            ;;
        -m | --measure)
            measure_throughput=true
            shift
            ;;
        -w | --webcam)
            webcam=true
            format="v4l2"

            # check if there is a modprobed v4l2 loopback device
            # use the first cam as default if there is no output_path already
            cam_path=$(v4l2-ctl --list-devices \
                | sed -n '/^[^\s]\+platform:v4l2loopback/{n;s/\s*//g;p;q}')

            # fail if there is no such device
            if [ -e "$cam_path" ]; then
                if [ "$output_path" = "-" ]; then
                    output_path="$cam_path"
                fi
            else
                echo "Could not find a video loopback device, did you"
                echo "sudo modprobe v4l2loopback"
                exit 1
            fi
            shift
            ;;
        --mirror)
            # do nothing if --webcam is not set
            hflip=true
            shift
            ;;
        -t | --title)
            window_title="$2"
            shift
            shift
            ;;
        -u | --unsecure-connection)
            unsecure_connection=true
            shift
            ;;
        -h | --help | *)
            echo "Usage: $0 [-p] [-u] [-s <source>] [-o <output>] [-f <format>] [-t <title>] [-m] [-w] [--hflip]"
            echo "Examples:"
            echo "	$0                              # live view in landscape"
            echo "	$0 -p                           # live view in portrait"
            echo "	$0 -s 192.168.0.10              # connect to different IP"
            echo "	$0 -o remarkable.mp4            # record to a file"
            echo "	$0 -o udp://dest:1234 -f mpegts # record to a stream"
            echo "	$0 -w --mirror                  # write to a webcam (yuv420p + resize + mirror)"
            echo "	$0 -u                           # establish a unsecure but faster connection"
            exit 1
            ;;
    esac
done

ssh_cmd() {
    echo "[SSH]" "$@" >&2
    ssh -o ConnectTimeout=1 \
        -o PasswordAuthentication=no \
        -o PubkeyAcceptedKeyTypes=+ssh-rsa \
        -o HostKeyAlgorithms=+ssh-rsa \
        "root@$remarkable" "$@"
}

# kill reStream on remarkable at the end.
# shellcheck disable=SC2016
exit_rm() {
    ssh_cmd 'kill $(pidof restream)'
}
trap exit_rm EXIT INT HUP

# SSH_CONNECTION is a variable on reMarkable => ssh '' instead of ssh ""
# shellcheck disable=SC2016
remarkable_ip() {
    ssh_cmd 'echo $SSH_CONNECTION' | cut -d\  -f3
}

# check if we are able to reach the remarkable
if ! ssh_cmd true; then
    echo "$remarkable unreachable or you have not set up an ssh key."
    echo "If you see a 'Permission denied' error, please visit"
    echo "https://github.com/rien/reStream/#installation for instructions."
    exit 1
fi

rm_version="$(ssh_cmd cat /sys/devices/soc0/machine)"

case "$rm_version" in
    "reMarkable 1.0")
        width=1408
        height=1872
        bytes_per_pixel=2
        fb_file="/dev/fb0"
        pixel_format="rgb565le"
        ;;
    "reMarkable 2.0")
        if ssh_cmd "[ -f /dev/shm/swtfb.01 ]"; then
            width=1404
            height=1872
            bytes_per_pixel=2
            fb_file="/dev/shm/swtfb.01"
            pixel_format="rgb565le"
        else
            width=1872
            height=1404
            bytes_per_pixel=1
            fb_file=":mem:"
            pixel_format="gray8"
            video_filters="$video_filters,transpose=2"
        fi
        ;;
    *)
        echo "Unsupported reMarkable version: $rm_version."
        echo "Please visit https://github.com/rien/reStream/ for updates."
        exit 1
        ;;
esac

# technical parameters
loglevel="info"
decompress="lz4 -d"

# check if lz4 is present on the host
if ! lz4 -V >/dev/null; then
    echo "Your host does not have lz4."
    echo "Please install it using the instruction in the README:"
    echo "https://github.com/rien/reStream/#installation"
    exit 1
fi

# check if restream binay is present on remarkable
if ssh_cmd "[ ! -f ~/restream ] && [ ! -f /opt/bin/restream ]"; then
    echo "The restream binary is not installed on your reMarkable."
    echo "Please install it using the instruction in the README:"
    echo "https://github.com/rien/reStream/#installation"
    exit 1
fi

# use pv to measure throughput if desired, else we just pipe through cat
if $measure_throughput; then
    if ! pv --version >/dev/null; then
        echo "You need to install pv to measure data throughput."
        exit 1
    else
        loglevel="error" # verbose ffmpeg output interferes with pv
        host_passthrough="pv"
    fi
else
    host_passthrough="cat"
fi

# store extra ffmpeg arguments in $@
set --

# rotate 90 degrees if landscape=true
$landscape && video_filters="$video_filters,transpose=1"

# Scale and add padding if we are targeting a webcam because a lot of services
# expect a size of exactly 1280x720 (tested in Firefox, MS Teams, and Skype for
# for business). Send a PR if you can get a higher resolution working.
if $webcam; then
    video_filters="$video_filters,format=pix_fmts=yuv420p"
    video_filters="$video_filters,scale=-1:720"
    video_filters="$video_filters,pad=1280:0:-1:0:#eeeeee"

    # Some applications, eg Zoom and Discord, mirror by default the webcam video
    # Restore the correct orientation
    $hflip && video_filters="$video_filters,hflip"
fi

# set each frame presentation time to the time it is received
video_filters="$video_filters,setpts=(RTCTIME - RTCSTART) / (TB * 1000000)"

set -- "$@" -vf "${video_filters#,}"

if [ "$output_path" = - ]; then
    output_cmd=ffplay

    window_title_option="-window_title $window_title"
else
    output_cmd=ffmpeg

    if [ "$format" != - ]; then
        set -- "$@" -f "$format"
    fi

    set -- "$@" "$output_path"
fi

set -e # stop if an error occurs

restream_options="-h $height -w $width -b $bytes_per_pixel -f $fb_file"

# shellcheck disable=SC2089
restream_rs="PATH=\"\$PATH:/opt/bin/:.\" restream $restream_options"
if $unsecure_connection; then
    listen_port=16789
    ssh_cmd "$restream_rs --listen $listen_port" &
    sleep 1 # give some time to restream.rs to start listening
    receive_cmd="nc $(remarkable_ip) $listen_port"
else
    receive_cmd="ssh_cmd $restream_rs"
fi

# shellcheck disable=SC2086,SC2090
$receive_cmd \
    | $decompress \
    | $host_passthrough \
    | (
        "$output_cmd" \
            -vcodec rawvideo \
            -loglevel "$loglevel" \
            -f rawvideo \
            -pixel_format "$pixel_format" \
            -video_size "$width,$height" \
            $window_title_option \
            -i - \
            "$@" \
            ;
        kill $$
    )

A remarkable/remarkable-cli-tooling => remarkable/remarkable-cli-tooling +1 -0
@@ 0,0 1,1 @@
Subproject commit 1a4979e3b8c4715d6e22f911105da0da2e63249a

A remarkable/resync.py => remarkable/resync.py +1 -0
@@ 0,0 1,1 @@
remarkable-cli-tooling/resync.py
\ No newline at end of file

M startup => startup +11 -4
@@ 1,6 1,8 @@
#!/bin/sh

killall posture.sh sxhkd mpd picom
#xrandr --output DP-0 --primary --right-of HDMI-0

killall posture.sh sxhkd mpd picom dunst

setxkbmap -option ctrl:nocaps
xmodmap -e 'keycode 108 = Mode_switch'


@@ 9,10 11,15 @@ xmodmap -e 'keycode 31 = i I Up'
xmodmap -e 'keycode 44 = j J Left'
xmodmap -e 'keycode 46 = l L Right'

xss-lock /home/zeno/scripts/lock &
$HOME/scripts/statusbar/posture.sh &
/usr/lib/kdeconnectd &
kdeconnect-indicator &
sxhkd &
mpd &
#$HOME/.config/polybar/launch_polybar.sh &
polybar bar &
~/.fehbg
picom -b
#hsetroot -solid \#1c1e20
dunst &
# picom -b
unclutter &
pactl load-module module-combine-sink sink_name="Simultaneous" slaves=alsa_output.usb-Corsair_Corsair_HS70_Wireless_Gaming_Headset-00.analog-stereo,alsa_output.pci-0000_0b_00.3.analog-stereo

M status => status +3 -8
@@ 6,14 6,9 @@ killall $NOTIFICATION

function volume() {
    pkill herbe
    volumedevice="DAC"
    mutedevice="Speaker"
    if [[ $(amixer get $mutedevice | tail -n1 | awk -F ' ' '{{print $3}}') == "[on]" ]]; then
	vol=$(amixer get $volumedevice | tail -n1 | awk -F ' ' '{{print $5}}' | sed 's/\[//' | sed 's/\]//')
    else
	vol="Muted"
    fi
    $NOTIFICATION $vol
	volume=$(pamixer --get-volume-human)

    $NOTIFICATION $volume
}

function datetime() {

M statusbar/timer => statusbar/timer +1 -1
@@ 1,1 1,1 @@
773
733