From 93fd73fc1648feb07d08e4d7ee644bb7eac2329e Mon Sep 17 00:00:00 2001 From: Michel Date: Fri, 24 Mar 2023 21:12:45 +0100 Subject: [PATCH] feat: add /bin scripts --- .Xresources | 20 +++++++++++ bin/every-hour.zsh | 60 ++++++++++++++++++++++++++++++++ bin/once-connected.zsh | 78 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 .Xresources create mode 100755 bin/every-hour.zsh create mode 100755 bin/once-connected.zsh diff --git a/.Xresources b/.Xresources new file mode 100644 index 0000000..27112b4 --- /dev/null +++ b/.Xresources @@ -0,0 +1,20 @@ +! X(7) manual page, section titled “Resources” +! https://unix.stackexchange.com/questions/216723/xterm-or-xterm-in-configuration-file +! +! Don t forget to run `xrdb -merge ~/.Xresources` after any change. +! +XTerm*termName: xterm-256color +XTerm*background: rgb:00/00/00 +XTerm*foreground: white + +XTerm*geometry: 100x60 + +XTerm*faceName: MesloLGS NF +XTerm*faceSize: 10 + +XTerm*internalBorder: 1 +XTerm*colorInnerBorder: true +XTerm*borderColor: rgb:88/00/19 + +XTerm*scrollBar: false +XTerm*rightScrollBar: true diff --git a/bin/every-hour.zsh b/bin/every-hour.zsh new file mode 100755 index 0000000..62443f3 --- /dev/null +++ b/bin/every-hour.zsh @@ -0,0 +1,60 @@ +#!/bin/zsh +# + +alias xterm='xterm -bg black -fg white -fa Hack -fs 10' + + +## Cloud folder must exist +# +if [ -z "$NC_STORAGE" ]; then + echo "${fg[red]}NC_STORAGE environment variable not set." + exit 1 +fi + +if [ ! -d $NC_STORAGE ]; then + echo "${fg[cyan]}$NC_STORAGE ${fg[red]}is not a folder (in \$NC_STORAGE)." + exit 2 +fi + + +## Save shell history +# +src=${HOME}/.zhistory +tgt=${NC_STORAGE}/history +if [[ ${tgt} -ot ${src} ]]; then + /usr/bin/tac ${src} \ + > ${tgt} +fi + + +## Save manually installed packages +# +src=/var/log/apt +tgt=${NC_STORAGE}/debian_packages.txt +if [[ ${tgt} -ot ${src} ]]; then + /usr/bin/aptitude search '!~M~i !-dev' --display-format '%p' >! ${tgt} + echo >> ${tgt} + /usr/bin/aptitude search '!~M~i -dev' --display-format '%p' >> ${tgt} +fi + + +## Use Systemd to call back in one hour +# + +# Cancel any previous timer +for line in $(systemctl --user show --type=timer --state running,waiting -P Unit,Description); { + if [[ $line = $0 ]]; then + timer=${unit%.*}.timer + echo "Cancel previous timer: $timer\n" + systemctl --user stop $timer + else + unit=$line + fi +} + +# Create new timer +systemd-run --user --on-active=1h $0 + +# To check if timer is running: +# - systemctl --user show --type=timer --state running,waiting -P Unit,Description +# - cat /run/user/${UID}/systemd/transient/run-*.service diff --git a/bin/once-connected.zsh b/bin/once-connected.zsh new file mode 100755 index 0000000..b917a8c --- /dev/null +++ b/bin/once-connected.zsh @@ -0,0 +1,78 @@ +#!/bin/zsh +# vi:spl=en + +alias xterm='xterm -bg black -fg white -fa Hack -fs 10' + + +## Start periodic actions +# +$HOME/bin/every-hour.zsh + + +## Wait for an Internet connection +# +while ! nm-online -t 5 ; do + List=( $(nmcli connection show | grep wifi | cut -d' ' -f1) ) + + Menu=() + for Name in $List; + Menu+=( "$Name" "$Name" ) + + Conn=$(kdialog --menu "Aucune connexion active\nLaquelle choisir?" $Menu) + if [[ $? -eq 0 ]]; then + nmcli radio wifi on + sleep 3 + nmcli connection up $Conn + else + exit 1 + fi +done + + +## Activating services +# +# See: +# - https://software.opensuse.org/download.html?project=home%3Anpreining%3Adebian-ubuntu-onedrive&package=onedrive +# - https://software.opensuse.org/download.html?project=home%3Ajstaf&package=onedriver + +PATH=$PATH:$HOME/bin +PATH=$PATH:$HOME/.asdf/bin + +Services=( + 'firefox -P michel' 'off' '' + 'firefox -P vedecom' 'off' '' + 'firefox -P ''$oft''' 'off' '' + 'onedrive-d1-os4.zsh' 'off' '' + 'onedriver-launcher' 'off' '' + 'asdf update; asdf plugin update --all' 'off' 'xterm' +) + +Menu=() +count=0 +for i in {1..$#Services..3} ; { + (( count+=1 )) + + Command=${Services[$i]} + Enable=${Services[$i+1]} + + Menu+=( ${count} ${Command} ${Enable} ) +} + +Indexes=( $(kdialog --geometry 600x300 --checklist "Applications à démarrer" $Menu) ) +for i in $Indexes ; +{ + i=${i//\"/} + i=$((3*i - 2)) + + Command=${Services[$i]} + Option=${Services[$i+2]} + + case ${Option} in + xterm) + xterm -hold -e ${Command} & + ;; + *) + ${=Command} & + ;; + esac +}