Merge branch 'master' of code.ungleich.ch:nico/nsbin

This commit is contained in:
Nico Schottelius 2020-05-12 17:32:19 +02:00
commit fced83c48a
11 changed files with 189 additions and 7 deletions

18
battery-check.sh Executable file
View file

@ -0,0 +1,18 @@
#!/bin/sh
acpi=$(acpi)
# Nothing to be done if we are charging
if echo "$acpi" | grep -q Charging; then
exit 0
fi
percent=$(echo $acpi | cut -d, -f2 | sed 's/%//')
if [ $percent -le 10 ]; then
notify-send -u critical "Battery:${percent}%"
elif [ $percent -le 15 ]; then
notify-send -u normal "Battery:${percent}%"
elif [ $percent -le 20 ]; then
notify-send -u low "Battery:${percent}%"
fi

8
ga.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/sh
for url in \
https://analytics.google.com/analytics/web/#/report-home/a62285904w148949408p153837579 \
https://analytics.google.com/analytics/web/#/report-home/a62285904w148936346p153856341 \
https://analytics.google.com/analytics/web/#/report-home/a62285904w97282594p101425900; do
chromium --new-window ${url}
done

55
install-nicos-notebook Executable file
View file

@ -0,0 +1,55 @@
#!/bin/sh
set -x
set -e
# 1. Create partitions
# 2. install OS
# 3. configure with cdist
# 4. start initial sync (mbsync, nextcloud)
# Things to automate:
# - mbsync call (?)
# - nextcloud sync / config
# - wireguard installation / config
# Things to fix:
# cdist sets hostname of HOST when running in chroot!
if [ $# -ne 1 ]; then
echo "$0 name-of-the-notebook"
exit 1
fi
# Get OS
alpine_version=3.10.2
alpine_url=http://dl-cdn.alpinelinux.org/alpine/v3.10/releases/x86_64/alpine-minirootfs-${alpine_version}-x86_64.tar.gz
hostname=nicos-notebook
tmpdir=$(mktemp -d)
tmpdir=/tmp/tmp.w5LTsMtCDX
root_dir=${tmpdir}/rootfs
dot_cdist=~/vcs/nico-dot-cdist/
cdist_dir=~/vcs/cdist
cdist_copy=${cdist_dir}/other/examples/remote/chroot/copy
cdist_exec=${cdist_dir}/other/examples/remote/chroot/exec
cd ${tmpdir}
# get alpine chroot / extract
wget -c ${alpine_url} -O alpine.tar.gz
mkdir ${root_dir}
chmod 0755 ${root_dir}
cd ${root_dir}
sudo tar xvfz ${tmpdir}/alpine.tar.gz
# enable networking
sudo cp /etc/resolv.conf ${root_dir}/etc/
sudo sudo chroot ${root_dir} apk update
sudo ${cdist_dir}/bin/cdist config -vv -c ${dot_cdist} \
--remote-copy "${cdist_copy} ${root_dir}" \
--remote-exec "${cdist_exec} ${root_dir}" ${hostname}

25
mailer Executable file
View file

@ -0,0 +1,25 @@
#!/bin/sh
if [ $# -ne 4 ]; then
echo "$0 subject from bcc-addr addressfile"
echo "f.i. $0 'How are you?' 'Some Body <from@example.com>' 'another@example.com' ./addresses "
echo "Address file format: | Name | Mail |"
exit 1
fi
subject=$1; shift
from=$1; shift
bcc=$1; shift
addresses_file=$1; shift
while read line; do
name=$(echo $line | awk -F '|' '{ print $2 }' | sed -e 's/^ *//' -e 's/ *$//')
email=$(echo $line | awk -F '|' '{ print $3 }' | sed -e 's/^ *//' -e 's/ *$//')
sed "s/PERSON/$name/" mail | \
mail -s "$subject" \
-r "$from" \
-b "$bcc" \
"$name <$email>"
done < "$addresses_file"

View file

@ -1,2 +1,3 @@
#!/bin/sh
emacs --funcall "mu4e" --name mainemacs
# emacs --funcall "mu4e" --name mainemacs
emacsclient -c -e '(mu4e)'

View file

@ -1 +1 @@
sshfs nutzer@loch:/ ~/.loch
sshfs loch:/ ~/.loch

17
myssh.sh Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh
# SSH for people who did not sleep long enough
# Changes background colour to red for remote and resets to LightYellow2 after
# the session is finished
#
# Inspiration by Stefan Baur
# Coded by Nico Schottelius, 2020-01-19
#
# Copying: GPLv3
printf '\033]10;black\007'
printf '\033]11;red\007'
echo ''
ssh "$@"
printf '\033]11;LightYellow2\007'
printf '\033]10;black\007'
echo ''

View file

@ -3,7 +3,9 @@
exec 2>&1
if [ $# -ge 1 ]; then
printf "Estimated location\n\n$@\n\n"
printf 'Estimated location\n\n'
echo "$@"
printf '\n\n'
fi
printf 'My IP addresses\n\n'

View file

@ -6,9 +6,9 @@ i3-msg 'workspace 2; append_layout ~/.i3/workspace-2.json'
i3-msg 'workspace 10'
# Start programs afterwards and watch matching
#if command -v firefox; then
# firefox &
if command -v chromium; then
if command -v firefox; then
firefox &
elif command -v chromium; then
chromium &
elif command -v chromium-browser; then
chromium-browser &
@ -19,3 +19,6 @@ if [ -f /etc/arch-release ]; then
else
ssh-add </dev/null && mainemacs &
fi
# Dell XPS 13" 2-in-1
xinput map-to-output "WCOM48EC:00 056A:48EC Touchscreen" eDP-1

View file

@ -21,7 +21,9 @@ start=$(date)
rsync -avS --delete --progress \
--exclude /.cache \
--exclude /.cdist/cache \
--exclude ~/temp/ \
--exclude /temp/ \
--exclude /.mu/ \
--exclude /Downloads/ \
"$@" \
~/ "$dst"
end=$(date)

51
wireguard-fix-endpoint.sh Normal file
View file

@ -0,0 +1,51 @@
#!/bin/sh
# 2020-01-19
# Nico Schottelius
# Periodically fix the wireguard endpoint
endpoint=vpn-2a0ae5c1.ungleich.ch
tunnel=wgungleich
config=/etc/wireguard/${tunnel}.conf
endpoint=$(grep -i ^endpoint ${config} | cut -d= -f2)
host=$(echo $endpoint| cut -d: -f1)
port=$(echo $endpoint| cut -d: -f2)
publickey=$(grep -i ^publickey ${config} | cut -d= -f2)
# If wireguard is up, but with the wrong endpoint
# (v4 address in an v6 only network or
# v6 address in an v4 only network) the routing of
# wireguard can break connectivity (i.e. AllowedIPs = ::/0
# breaks IPv6 connectivity)
# Thus we first need to shutdown the wireguard VPN to confirm
# it's not wireguard preventing us to access the endpoint itself.
# It would certainly be better to not needing to shut it down,
# however I don't see a reliable way without skipping the wireguard
# set `ip rule`
wg-quick down ${tunnel}
# Now do the DNS lookups, which should work without a tunnel up
# (they also might have been prevented by wireguard up in the incorrect
# address family)
v6_addr=$(dig +short $endpoint aaaa)
v4_addr=$(dig +short $endpoint a)
v6_ok=""
v4_ok=""
ping -c3 $v6_addr >/dev/null && v6_ok=yes
ping -c3 $v4_addr >/dev/null && v4_ok=yes
# Now verify/check what is reachable
if [ $v6_ok ]; then
wg-quick up ${tunnel}
wg set wgungleich peer ${publickey} endpoint ${v6_addr}:${port}
elif [ $v4_ok ]; then
wg-quick up ${tunnel}
wg set wgungleich peer ${publickey} endpoint ${v4!_addr}:${port}
else
echo "The endpoint ${endpoint} is unreachable, try again later" >&2
exit 1
fi