mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

commit 1979efba0deaf05f64f88a5b586659e7811f7a74
parent 741ee0606d79dc812ff73307a652506968e690b1
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Fri, 16 Aug 2019 12:50:16 +0200

Merge branch 'master' of a3nm.net:git/mybin

Diffstat:
afk_sway | 5+++++
calendar-backup.sh | 6++++--
dodo_sway | 10++++++++++
electrum | 2+-
fix_pa_bluez_profile | 9++++++---
fix_ux330u | 17+++++++++++++++++
hierarchive | 23+++++++++++++++++++++++
hierarchive_file | 8++++++++
initgit | 2+-
my-mutt | 9++++++---
sandboxed-browser | 28++++++++++++++++++++++++++++
screenshot_sway | 6++++++
startup | 21++++++---------------
startup_i3 | 17+++++++++++++++++
svnsync-myrepos | 26++++++++++++++++++++++++++
upgrades | 2+-
vispell | 7++++++-
xpass | 5++++-
18 files changed, 175 insertions(+), 28 deletions(-)

diff --git a/afk_sway b/afk_sway @@ -0,0 +1,5 @@ +#!/bin/bash + +killall -s HUP gpg-agent + +swaylock -c 00000000 --font Terminus --inside-color ffffffff --inside-clear-color ffff00ff --inside-wrong-color ff000000 --inside-ver-color 00ff00ff --bs-hl-color ff0000ff -r --indicator-thickness 10 --indicator-radius 40 diff --git a/calendar-backup.sh b/calendar-backup.sh @@ -3,10 +3,12 @@ # run with chronic to avoid spam mkdir -p ~/backup/calendar -cd; cd ~/backup/ # required to have the right paths in the archive +cd; cd ~/backup/calendar/ # required to have the right paths in the archive # avoid "file changed as we read it" errors from tar cp -Rv calendar_current calendar_backup -tar zcf calendar/dump-`date +%s`.tgz calendar_backup +FILE="dump-`date +%s`" +tar cf ${FILE}.tar calendar_backup +xz ${FILE}.tar rm -Rvf calendar_backup diff --git a/dodo_sway b/dodo_sway @@ -0,0 +1,10 @@ +#!/bin/bash + +sudo echo + +~/bin/afk_sway & + +sudo pm-suspend + +synclient TapButton2=2 + diff --git a/electrum b/electrum @@ -2,5 +2,5 @@ set -x ARGS="$@" -exec sudo -u bitcoin sh -c "umask 007; QT_X11_NO_MITSHM=1 electrum $ARGS ; chmod -R og+r ~bitcoin/.electrum" +exec sudo -u bitcoin sh -c "umask 007; QT_X11_NO_MITSHM=1 python3 /home/bitcoin/Electrum-3.3.8/run_electrum $ARGS ; chmod -R og+r ~bitcoin/.electrum" diff --git a/fix_pa_bluez_profile b/fix_pa_bluez_profile @@ -2,6 +2,9 @@ # set pulseaudio profile for bluetooth headset to A2DP -CARD=$(pacmd list-cards | grep -A1 index: | grep -B1 bluez | head -1 | cut -d':' -f2) -pacmd set-card-profile "$CARD" a2dp_sink - +pacmd list-cards | grep -A1 index: | grep -B1 bluez | cut -d':' -f2 | + grep -v '<' | while read CARD +do +echo $CARD +#pacmd set-card-profile "$CARD" a2dp_sink +done diff --git a/fix_ux330u b/fix_ux330u @@ -0,0 +1,17 @@ +#!/bin/bash + +# work around some quirks with the Asus Zenbook UX330U hardware + +# previously, needed to load 8723au, NOT r8723au +# and recompile and install ~/apps/rtl8723* +# but it looks like this is no longer true + +if [ `hostname` = gamma -o `hostname` = gamma.a3nm.net ] +then + # somehow the mouse pointer doesn't always work + (sudo modprobe -r psmouse; sudo modprobe psmouse) & + + # somehow wifi is not properly initialized + (sudo ifconfig wlan0 up; sudo iwconfig wlan0 mode managed; sudo service network-manager restart) & +fi + diff --git a/hierarchive b/hierarchive @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +# https://stackoverflow.com/a/246128 +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +cd "$DIR" + +# move old files from $1 to $2 +# expected usage: download/upload folder of a web browser, scratch folder, etc. + +NDAYS="7" + +D=$(date '+%Y-%m-%d') +F="$2/$D" +#mkdir "$F" +cd "$1" +# find all old files and move them away +find -type f -mtime +$NDAYS -print0 | xargs -r -0 -n 1 "$DIR/hierarchive_file" "$F" + +# now, recursively remove all empty directories +find . -type d | xargs rmdir -p 2>/dev/null + diff --git a/hierarchive_file b/hierarchive_file @@ -0,0 +1,8 @@ +#!/bin/bash + +# move $2 to folder $1, creating any missing folders +D=$(dirname "$2") +mkdir -p "$1/$D" +mv "$2" "$1/$D" +#echo "HIERARCHIVE '$1' '$2'" + diff --git a/initgit b/initgit @@ -7,7 +7,7 @@ DESC="$@" HOSTNAME=$(hostname | cut -d. -f1) if [[ $HOSTNAME != "ulminfo" ]] then - exec ssh ulminfo bin/initgit "$NAME" "$DESC" + exec ssh ulminfo bin/initgit "$NAME" \"$DESC\" fi if [ -d "$HOME/git/${NAME}.git" ] diff --git a/my-mutt b/my-mutt @@ -4,15 +4,18 @@ # see https://unix.stackexchange.com/q/90399 echo sleep 0.04 +HOSTNAME=$(hostname | cut -d '.' -f1) +FOLDER="$HOME/config/private/mutt" +FILE="$FOLDER/machines/$HOSTNAME" -if grep "^`hostname | cut -d '.' -f1`$" ~/.mutt/local_email > /dev/null +if [ -f "$FILE" ] then # local email # -e "push '<limit>~(! ~D)<enter>G'" - neomutt "$@" + neomutt -F "$FILE" "$@" else # remote email # -e "push '<limit>~(! ~D)<enter>G'" - neomutt -F ~/.mutt/imap "$@" + neomutt -F "$FOLDER/imap" "$@" fi diff --git a/sandboxed-browser b/sandboxed-browser @@ -0,0 +1,28 @@ +#!/bin/bash + +# need to create browser2 user +# you may also want to add the local user to the browser2 group + +ENDPOINT="$HOME/mnt/browser2" + +mkdir -p "$ENDPOINT" + +# replace by ACLs +grep -qs " $ENDPOINT " /proc/mounts || ( + echo "$ENDPOINT was not mounted, mounting it" + sudo bindfs --create-for-user=$(id -u browser2) \ + --create-for-group=$(id -g browser2) \ + --chown-deny --chgrp-deny --chmod-deny -p '700' \ + -u $(id -u) -g $(id -g) \ + ~browser2 "$ENDPOINT" +) + +# escape all arguments; is there a better way? +ESC="" +for var +do + ESCA=$(printf %q "$var") + ESC="$ESC $ESCA" +done +exec sudo -u browser2 sh -c "umask 007; exec firefox $ESC" + diff --git a/screenshot_sway b/screenshot_sway @@ -0,0 +1,6 @@ +#!/bin/bash + +TIME="$(date -Ins)" + +~/apps/grim/build/grim ~/$TIME.png + diff --git a/startup b/startup @@ -1,6 +1,6 @@ #!/bin/bash -~/bin_private/fix_gamma +~/bin/fix_ux330u #~/bin_private/proxy.sh ~/bin/notmuch-new.sh & @@ -8,22 +8,13 @@ urxvtd & ~/bin_private/myfetchmail ~/bin/rehashpath nm-applet & -#~/bin_private/logkeys rm ~/temp/terminals -~/bin/layout -~/bin/kiwix + +# no longer working: ~/bin_private/logkeys +# no longer working: ~/bin/kiwix + # pulseaudio cannot start by itself due to the uncommon socket folder pulseaudio & -if [ `whoami` = a3nm ] -then - COLOR="#000000" -else - # easy reminder that this is not my real session - COLOR="#400000" -fi -xsetroot -solid "$COLOR" & -# when using compton -hsetroot -solid "$COLOR" & # is there a better way to reset xhost permissions? xhost +si:localuser:`whoami` @@ -32,7 +23,7 @@ xhost | sed 1d | grep -v `whoami` | while read l; do done # for now, browser can access the X server -# TODO: use Xpra +# TODO: use wayland xhost +si:localuser:browser xhost +si:localuser:browser2 xhost +si:localuser:bitcoin diff --git a/startup_i3 b/startup_i3 @@ -0,0 +1,17 @@ +#!/bin/bash + +~/bin/layout +~/bin/startup + +if [ `whoami` = a3nm ] +then + COLOR="#000000" +else + # easy reminder that this is not my real session + COLOR="#400000" +fi + +xsetroot -solid "$COLOR" & +# when using compton +hsetroot -solid "$COLOR" & + diff --git a/svnsync-myrepos b/svnsync-myrepos @@ -0,0 +1,26 @@ +#!/bin/bash + +# synchronizes a local backup of all my svn repositories +# $1 is the destination of the backup +# ASSUMPTION: all the svn repositories live in ~/svn/* + +set -e + +DEST=$(realpath "$1") + +ls ~/svn | while read repos +do + cd "$HOME/svn/$repos" + URL=$(svn info | grep '^URL:' | cut -d' ' -f2) + cd "$DEST" + LDEST="file://$DEST/$repos" + if [ ! -d "$DEST/$repos" ] + then + # https://stackoverflow.com/a/2303862 + svnadmin create "$repos" + echo -ne '#!/bin/sh\nexit 0' > "$repos/hooks/pre-revprop-change" + chmod ugo+x "./$repos/hooks/pre-revprop-change" + svnsync init "$LDEST" "$URL" + fi + svnsync sync "$LDEST" +done diff --git a/upgrades b/upgrades @@ -10,7 +10,7 @@ do "echo \"=== upgrading $m ===\n\n\"; ~/bin/wake $m; sleep 5; - ssh -t $m 'sudo apt-get autoclean && sudo apt-get autoremove && sudo apt-get update && sudo apt-get dist-upgrade'; + ssh -t $m 'sudo apt-get autoclean && sudo apt autoremove && sudo apt update && sudo apt dist-upgrade'; echo \"\n\n=== testing connection to $m ... ===\n\n\"; ssh -t $m 'echo this is fine'; echo \"\n\n=== done upgrading $m ===\n\n\"; diff --git a/vispell b/vispell @@ -3,8 +3,13 @@ # work around the problems induced by wrong LaTeX highlighting missing some # typos +# also close files automatically if there is no typo + +# TODO: use tabs? https://vi.stackexchange.com/a/17267 + FILE="$1" LANG="${2:-en}" -vim -c 'syntax off' -c 'set spell' -c "set spelllang=$LANG" "$FILE" +vim -c 'syntax off' -c 'set spell' -c "set spelllang=$LANG" \ + -S ~/config/vim/spell.vim -c ":call SpellNext()" "$FILE" diff --git a/xpass b/xpass @@ -16,6 +16,9 @@ set -x +# ensure that the layout is correct +~/bin/layout + export PINENTRY_USER_DATA="gtk" cd ~/.password-store @@ -48,7 +51,7 @@ fi # file now exists, retrieve password PASSWORD=$(pass "$FILE" | head -1) -if [[ $USER = "login" || $USER = "user" || $USER = "fill" ]] +if [[ $USER = "login" || $USER = "user" || $USER = "fill" || $USER = "filln" ]] then # user wanted login instead of password USERDAT=$(pass "$FILE" | grep 'login:' | head -1 | grep '^login:' | cut -d ':' -f2 | cut -c 2-)