add all little scripts

This commit is contained in:
primardj 2024-07-20 22:10:54 +02:00
parent 417fde9823
commit c161ba4190
12 changed files with 510 additions and 0 deletions

10
dotconfig/bin/allow_screenshare Executable file
View file

@ -0,0 +1,10 @@
#!/bin/sh
sleep 1
killall -e xdg-desktop-portal-hyprland
killall -e xdg-desktop-portal-wlr
killall xdg-desktop-portal
/usr/lib/xdg-desktop-portal-hyprland &
sleep 2
/usr/lib/xdg-desktop-portal &

16
dotconfig/bin/clock-start Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/bash
# Take as $1 the position (eg. bottom-left) as $2 and $3, the y and x pos, in px.
if [ "$1" == "" ]
then
pos="top-left"
else
pos="$1"
fi
# kill all others wlclocks that are still active.
pkill wlclock
wlclock --layer bottom --position "$pos" --margin $2 $3 $2 $3 --background-colour "#ffffff00" --border-colour "#00000000" --clock-colour "#ffa500" --hand-width 4

13
dotconfig/bin/cpu_calcul Executable file
View file

@ -0,0 +1,13 @@
#!/bin/sh
if [ "$1" == "" ]
then
V=" "
else
V="$1"
fi
awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) ; }' <(grep "cpu${V}" /proc/stat) <(sleep 0.5;grep "cpu${V}" /proc/stat)
#awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) "%"; }' <(grep "cpu${V}" /proc/stat) <(sleep 1;grep "cpu${V}" /proc/stat)

103
dotconfig/bin/dmount Executable file
View file

@ -0,0 +1,103 @@
#!/usr/bin/bash
set -e
Version="1.1.1"
Usage="dmount PARAMETER
Script which permit to mount/unmount an LVM on LUKS using dmcrypt, doas and fstab.
Actually works only on cryptdata, my extern SSD.
PARAMETRES
-h, --help Print this help and exit
-v, --version Print the version and exit
-m, --mount Mount cryptdata
-u, --umount Unmount cryptdata
"
Mountpoint_cours=/home/primardj/cours
Mountpoint_doc=/home/primardj/Documents
Mountpoint_virt_machine=/home/primardj/virtual_machine
Mountpoint_data=/home/primardj/data
force_remove_vgdevice() {
echo "force remove vg cryptdata"
#doas dmsetup info --columns
doas dmsetup remove /dev/mapper/cryptdata-*
doas dmsetup remove /dev/mapper/cryptdata
}
mount_lvm_on_luks() {
echo "unlocking device cryptdata"
#doas rc-service dmcrypt restart
doas /etc/rc/sysinit/35-cryptsetup start
#doas vgchange -a y cryptdata
doas mount -a
}
umount_devices() {
echo "umount devices"
doas umount -R $Mountpoint_cours || lsof +D $Mountpoint_cours
doas umount -R $Mountpoint_doc || lsof +D $Mountpoint_doc
doas umount -R $Mountpoint_virt_machine || lsof +D $Mountpoint_virt_machine
doas umount -R $Mountpoint_data || lsof +D $Mountpoint_data
}
error_umount() {
echo "Error, can't umount all devices, need some manual help." >&2
lsblk
exit 1
}
error_deactivate_vg() {
echo "Error, impossible de deactive vg." >&2
echo "Try to force remove vgdisk from memory." >&2
if force_remove_vgdevice
then
echo "could at list remove vgdevice."
exit 0
else
lsblk
doas dmsetup info --columns
echo "couldn't remove vgdevice. need manual intervention." >&2
exit 1
fi
}
umount_lvm_on_luks() {
echo "locking device cryptdata"
umount_devices || error_umount
doas lvchange -a n cryptdata || error_deactivate_vg
doas cryptsetup close --deferred cryptdata
}
for i in "$@"; do
case "$i" in
"-h" | "--help")
echo "${Usage}"
exit 0
;;
"-v" | "--version")
echo "dmount v.${Version}"
exit 0
;;
"-m" | "--mount")
mount_lvm_on_luks
exit 0
;;
"-u" | "--umount")
umount_lvm_on_luks
exit 0
;;
*)
echo "Error, uknown args $i" >&2
exit 1
;;
esac
done

26
dotconfig/bin/newuptime Executable file
View file

@ -0,0 +1,26 @@
#!/bin/sh
# Always print uptime in three columns.
# Two case; case time < 1d, print h m s
# case time > 1d, print d h m
time=$(cat /proc/uptime)
time="${time%%.*}"
if [ ${time} -ge 86400 ]
then
day=$(($time / 86400))
time=$((${time} - day * 86400))
hour=$(($time / 3600))
time=$(($time - hour * 3600))
minutes=$(($time / 60))
time=$((time - minutes * 60))
echo "${day}d ${hour}h ${minutes}m"
else
hour=$(($time / 3600))
time=$(($time - hour * 3600))
minutes=$(($time / 60))
time=$((time - minutes * 60))
echo "${hour}h ${minutes}m ${time}s"
fi

46
dotconfig/bin/nfetch-startup Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/bash
Version=0.1
Usage=" nfetch-startup [ PARAMETTER ]
nfetch-startup is a simple script which execute neofetch and wait until the user press 'q'.
PARAMETTER
-h, --help Print this help and quit
-v, --version Print the version of this script and quit.
"
for i in "$@"; do
case "$i" in
"-h" | "--help")
echo "$Usage"
exit 0
;;
"-v" | "--version")
echo "nfetch-startup $Version"
exit 0
;;
*)
echo "Paramettre $i uknown"
echo "$Usage"
exit 127
;;
esac
done
neofetch
Goout="1"
while [ "$Goout" == "1" ]; do
read -n1 -s value
if echo "$value" | grep -q "q"
then
Goout=0
fi
done

2
dotconfig/bin/nigga Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
echo "POV: Je suis raciste"

5
dotconfig/bin/open_eww Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
eww open system
eww open clock
eww open perf

View file

@ -0,0 +1,56 @@
#!/bin/sh
output="(box :class \"disks_box\" :orientation 'v' "
field="$(ls -l /dev/mapper/cryptdata-* 2> /dev/null| cut -d " " -f 9)
$(ls -l /dev/mapper/cryptlvm-root 2> /dev/null| cut -d " " -f 9)
$(ls -l /dev/mapper/cryptlvm-home 2> /dev/null| cut -d " " -f 9)"
all_values=""
for i in $field
do
if [ ! "${all_values}" == "" ]
then
all_values="${all_values}\n"
fi
result=$(df "$i" -h --output="target,size,used,pcent" | tail -n 1)
all_values="${all_values}${result///home\/primardj/\~}"
#echo $(df "$i" -h --output="source,size,used,pcent" | tail -n 1)
done
echo -e $all_values > /tmp/disk_opens
while read inp
do
v1="$(echo ${inp} | cut -d " " -f 1 )"
v2="$(echo ${inp} | cut -d " " -f 2 )"
v3="$(echo ${inp} | cut -d " " -f 3 )"
v4="$(echo ${inp} | cut -d " " -f 4 )"
v4="${v4/\%/}"
output="${output} (box :orientation \"h\" :halign \"fill\" :space-evenly false "
output="${output} (box :orientation \"h\" :halign \"start\" :hexpand true :space-evenly false "
output="${output} (label :class \"val_disks\" :halign \"start\" :text \"${v1:0:17}\" )"
output="${output} ) (box :orientation \"h\" :halign \"end\" :space-evenly false "
#output="${output} (label :class \"val_disks\" :halign \"end\" :text \"${v3}/${v2}\" )"
output="${output} (progress :valign \"center\" :halign \"end\" :width 25 :class \"disk_bar\" :value \"${v4}\" )"
output="${output} ))"
#output="${output} (box :orientation \"h\" (label :class \"val_label\":halign \"fill\" :text \"${inp}\" ))"
#echo $inp
done < /tmp/disk_opens
output="${output} )"
#echo -e $all_values
echo $output
#output="${output}${field})"
#echo "${output}"

View file

@ -0,0 +1,144 @@
#/bin/bash
#
# little class about bash extension parametters.
#
# ${myvar#pattern} delete shortest occurence from the begining
# ${myvar##pattern} delete longuest occurence from begining
# ${myvar%pattern} delete shortest occurence from the end
# ${myvar%%pattern} delete longuest occurence from the end
#
# conclusion, use of # will delete the pattern at begining
# and % will delete the parameter at the end.
default_user="root"
default_hostname="localhost"
default_ssh_port="22"
default_rsp_port="3389"
default_vnc_port="5900"
Version="2.0.1"
Usage="
$(basename $0) [OPTION] [OPTION=VALUE] PROTOCOL
script which permit to launch a remote connection protocol.
PROTOCOL available
ssh A command line protocol which can be used to connect with tcp
rsp The windows remote server protocol
PROTOCOL #TODO
vnc Virtual Networking Computing, permit to have access to a graphical user interface.
OPTION available
-v, --version print the version and exit
-h, --help print this help and exit
-u <user>,--user=<user> Select the user, by default root
-p <port>,--port=<port> Select the port, by default 10022
-H <hostname>, --hostname=<hostname> Select the hostname to connect
"
start_ssh() {
if [ "${port}" == "" ]
then
port="${default_ssh_port}"
fi
echo "start ssh with user=${user} port=${port} hostname=${hostname}"
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" -p "${port}" "${user}@${hostname}"
}
start_rsp() {
if [ "${port}" == "" ]
then
port="${default_rsp_port}"
fi
hostname="${hostname}:${port}"
echo "start rsp with user=${user} port=${port} hostname=${hostname}"
xfreerdp /v:"${hostname}" /u:"${user}" /dynamic-resolution
}
# Parser
# looking for double parametters.
for (( arg=1; arg<$#; arg++)); do
value="$((arg+1))"
if [ "${!arg}" == "-u" ]
then
user="${!value}"
elif [ "${!arg}" == "-p" ]
then
port="${!value}"
elif [ "${!arg}" == "-H" ]
then
hostname="${!value}"
fi
done
# looking for all parametter alone
for i in "$@"; do
case "$i" in
"ssh")
protocol="ssh"
;;
"rsp")
protocol="rsp"
;;
"--version" | "-v")
echo "$(basename $0) v.${Version}"
exit 0
;;
"--help" | "-h")
echo "${Usage}"
exit 0
;;
esac
done
for i in "$@"; do
case "${i%=*}" in
"--user")
user="${i#*=}"
;;
"--port")
port="${i#*=}"
;;
"--hostname")
hostname="${i#*=}"
;;
esac
done
if [ "${user}" == "" ]
then
user="${default_user}"
fi
if [ "${hostname}" == "" ]
then
hostname="${default_hostname}"
fi
# Last check, if protocol define, launch it, else, exit 0
case "${protocol}" in
"ssh")
start_ssh
;;
"rsp")
start_rsp
;;
*)
echo "protocol ${protocol} uknown" >&2
echo "${Usage}"
exit
;;
esac

24
dotconfig/bin/rotate_screen Executable file
View file

@ -0,0 +1,24 @@
#!/usr/bin/bash
transform_value=$(hyprctl getoption device:wacom-hid-526b-finger:transform | sed '2!d' | cut -d ":" -f 2)
if [ "${transform_value}" == " 0" ]
then
echo ${transform_value}
hyprctl keyword monitor eDP-1,preferred,auto,1.2,transform,1
hyprctl keyword device:wacom-hid-526b-pen:transform 1
hyprctl keyword device:wacom-hid-526b-finger:transform 1
hyprctl keyword device:wacom-hid-526b-finger-1:transform 1
sleep 0.5
eww open keyb
else
echo ${transform_value}
hyprctl keyword device:wacom-hid-526b-pen:transform 0
hyprctl keyword device:wacom-hid-526b-finger:transform 0
hyprctl keyword device:wacom-hid-526b-finger-1:transform 0
hyprctl keyword monitor eDP-1,preferred,auto,1.2,transform,0
fi

65
dotconfig/bin/swaylock-script Executable file
View file

@ -0,0 +1,65 @@
#!/usr/bin/bash
# Definition of constantes.
Version="1.0.1"
Usage="swaylock-script [ PARAMETTER ]
script who lock a computer by my own options.
PARAMETTER
-h, --help Print this help message and quit
-v, --version Print the version and quit
--sleep Launch the script without waiting anytime
--swaylock-only Lauch the locker with swaylock original options.
"
for i in "$@"; do
case "$i" in
"-h" | "--help")
echo "$Usage"
exit 0
;;
"-v" | "--version")
echo "swaylock-script $Version"
exit 0
;;
"--sleep")
sleep_flag="set"
;;
"--swaylock-only")
sw_only="set"
;;
esac
done
option_sw_effects="-f \
--screenshots \
--clock \
--indicator \
--indicator-radius 200 \
--indicator-thickness 10 \
--inside-color 000000BB \
--effect-vignette 0.6:1 \
--effect-blur 3x5 \
--ring-color ff7f50 \
--separator-color 000000ff \
--timestr %I:%M-%p"
option_sw=""
if [ ! "${sleep_flag}" == "set" ]
then
option_sw_effects="${option_sw_effects} \
--fade-in 4"
# no options_sw because I hadden't had time to add them.
fi
if [ "${sw_only}" == "set" ]
then
swaylock ${option_sw}
else
swaylock ${option_sw_effects}
fi