feat: add /bin scripts

This commit is contained in:
Michel 2023-03-24 21:12:45 +01:00
parent b7f66d74c5
commit 93fd73fc16
3 changed files with 158 additions and 0 deletions

20
.Xresources Normal file
View File

@ -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

60
bin/every-hour.zsh Executable file
View File

@ -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

78
bin/once-connected.zsh Executable file
View File

@ -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
}