From 6802c7ca843e7cb8aad37ab0cb2364a7eb446f83 Mon Sep 17 00:00:00 2001 From: Adrian Amaglio Date: Wed, 20 Sep 2023 15:21:25 +0200 Subject: [PATCH] update --- gw.sh | 2 +- radicale_server.sh | 28 +++++++++++ redshift.sh | 115 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 137 insertions(+), 8 deletions(-) create mode 100755 radicale_server.sh diff --git a/gw.sh b/gw.sh index d68a59a..2dd9821 100755 --- a/gw.sh +++ b/gw.sh @@ -31,6 +31,6 @@ run iptables -A INPUT -i "$local_iface" -j ACCEPT run iptables -t nat -A POSTROUTING -o "$net_iface" -j MASQUERADE run iptables -A FORWARD -i $net_iface -o $local_iface -m state --state RELATED,ESTABLISHED -j ACCEPT run iptables -A FORWARD -i $local_iface -o $net_iface -j ACCEPT -run dnsmasq --dhcp-range=192.168.238.100,192.168.238.199,10m -d --server=9.9.9.9 +run dnsmasq --dhcp-range=192.168.238.100,192.168.238.199,10m -d --server=9.9.9.9 --listen-address 192.168.238.254 --interface "$local_iface" -p0 clean diff --git a/radicale_server.sh b/radicale_server.sh new file mode 100755 index 0000000..0239dda --- /dev/null +++ b/radicale_server.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -euo pipefail + +echo "vars" +htpasswd="$(mktemp)" +venv=~/.cache/radicale-venv +#locale_ip_addr="$(ip -o -4 a show dev usb0 | grep -Po 'inet[[:space:]]+\K192.168.42.[0-9]{1,3}')" +locale_ip_addr="192.168.42.58" +port=5232 + +if [ ! -d "$venv" ] || [ -z "$(ls -A "$venv")" ] ; then + virtualvenv "$venv" +fi + +sudo ip a add "$locale_ip_addr" dev usb0 + +echo "populating htpasswd. Enter password :" +htpasswd -c "$htpasswd" dav + +echo "venv" +. venv/bin/activate + +echo "runing on $locale_ip_addr:$port" +python3 -m radicale -H "$locale_ip_addr:$port" --storage-filesystem-folder=~/.contacts --auth-type=htpasswd --auth-htpasswd-encryption md5 --auth-htpasswd-filename "$htpasswd" + +echo "Cleaning" +rm "$htpasswd" diff --git a/redshift.sh b/redshift.sh index 9daa57f..ab025ff 100755 --- a/redshift.sh +++ b/redshift.sh @@ -1,17 +1,118 @@ #!/bin/bash -if [ "$#" -ne 1 ] ; then - echo "Usage : $0 +/-" >&2 +BRIGHTNESS_INCREMENT=.1 +R_INCREMENT=0 +G_INCREMENT=.1 +B_INCREMENT=.2 + +xrandr_settings_of_display () { + if [ "$#" -ne 1 ] ; then + echo "Usage : xrandr_settings_of_display " >&2 + exit 1 + fi + + out="$(xrandr --verbose | sed -e "1,/^$1/d" | sed '/^ /,$d')" + + if [ -z "$out" ] ; then + echo "ERROR, empty output for command: xrandr_settings_of_display $@" >&2 + exit 1 + fi + + echo "$out" +} + + +brigthness_of_display () { + if [ "$#" -ne 1 ] ; then + echo "Usage : brigthness_of_display " >&2 + exit 1 + fi + + xrandr_settings_of_display "$1" | grep -Po 'Brightness: \K.*' +} + + +raw_gamma_of_display () { + if [ "$#" -ne 1 ] ; then + echo "Usage : raw_gamma_of_display " >&2 + exit 1 + fi + + xrandr_settings_of_display "$1" | grep -Po 'Gamma: \K.*' | tr ':' ' ' +} + +gamma_of_display () { + if [ "$#" -ne 1 ] ; then + echo "Usage : gamma_of_display " >&2 + exit 1 + fi + + read r g b <<< "$(raw_gamma_of_display "$1")" + echo "$r $g $b -> $(invert $r) $(invert $g) $(invert $b)" >&2 + echo "$(invert $r) $(invert $g) $(invert $b)" +} + +invert () { + if [ "$#" -ne 1 ] ; then + echo "Usage : invert " >&2 + exit 1 + fi + + echo "1/$1" | bc -l | grep -o '.*\...' +} + + +############### Args + +if [ "$#" -ne 2 ] ; then + echo "Usage : $0 +|-|=" >&2 exit 1 fi -red='--gamma 1:.6:.6 --brightness 0.6' -size='--rate 60 --mode 1920x1080 --fb 1920x1080 --panning 1920x1080*' + +property="$1" +action="$2" + +if [ ! "$action" = - ] && [ ! "$action" = + ] && [ ! "$action" = '=' ] ; then + echo "Bad action '$action'. Expected + - or =." + exit 1 +fi + + i=0 -same='' xrandr --listactivemonitors | tail -n +2 | cut -d ' ' -f 6 | while read monitor ; do - xrandr --output "$monitor" $red $size $same + args='' if [ "$i" -eq 0 ] ; then ((i=i+1)) - same="--same-as $monitor" + case "$property" in + brightness) + if [ "$action" = '=' ] ; then + args="--brightness 1" + else + b="$(brigthness_of_display "$monitor")" + b="$( echo "$b $action $BRIGHTNESS_INCREMENT" | bc -l )" + args="--brightness $b" + fi + ;; + redness) + if [ "$action" = '=' ] ; then + args="--gamma 1:1:1" + else + read r g b <<< "$(gamma_of_display "$monitor")" + + rnew="$( echo "$r $action $R_INCREMENT" | bc -l )" + gnew="$( echo "$g $action $G_INCREMENT" | bc -l )" + bnew="$( echo "$b $action $B_INCREMENT" | bc -l )" + args="--gamma $rnew:$gnew:$bnew" + #echo "from $r:$g:$b to $rnew:$gnew:$bnew" + fi + ;; + *) + echo "Invalid property $property" + exit 1 + esac + else + args="--same-as $monitor" fi + xrandr --output "$monitor" $args + echo xrandr --output "$monitor" $args done