From c161ba4190c16fa0a2fc42d43237d1ba67b26980 Mon Sep 17 00:00:00 2001 From: primardj Date: Sat, 20 Jul 2024 22:10:54 +0200 Subject: [PATCH] add all little scripts --- dotconfig/bin/allow_screenshare | 10 ++ dotconfig/bin/clock-start | 16 +++ dotconfig/bin/cpu_calcul | 13 +++ dotconfig/bin/dmount | 103 ++++++++++++++++++ dotconfig/bin/newuptime | 26 +++++ dotconfig/bin/nfetch-startup | 46 ++++++++ dotconfig/bin/nigga | 2 + dotconfig/bin/open_eww | 5 + dotconfig/bin/print_yuck_disks_mounted | 56 ++++++++++ dotconfig/bin/remote_connection.sh | 144 +++++++++++++++++++++++++ dotconfig/bin/rotate_screen | 24 +++++ dotconfig/bin/swaylock-script | 65 +++++++++++ 12 files changed, 510 insertions(+) create mode 100755 dotconfig/bin/allow_screenshare create mode 100755 dotconfig/bin/clock-start create mode 100755 dotconfig/bin/cpu_calcul create mode 100755 dotconfig/bin/dmount create mode 100755 dotconfig/bin/newuptime create mode 100755 dotconfig/bin/nfetch-startup create mode 100755 dotconfig/bin/nigga create mode 100755 dotconfig/bin/open_eww create mode 100755 dotconfig/bin/print_yuck_disks_mounted create mode 100755 dotconfig/bin/remote_connection.sh create mode 100755 dotconfig/bin/rotate_screen create mode 100755 dotconfig/bin/swaylock-script diff --git a/dotconfig/bin/allow_screenshare b/dotconfig/bin/allow_screenshare new file mode 100755 index 0000000..1d892b9 --- /dev/null +++ b/dotconfig/bin/allow_screenshare @@ -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 & + diff --git a/dotconfig/bin/clock-start b/dotconfig/bin/clock-start new file mode 100755 index 0000000..6614030 --- /dev/null +++ b/dotconfig/bin/clock-start @@ -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 diff --git a/dotconfig/bin/cpu_calcul b/dotconfig/bin/cpu_calcul new file mode 100755 index 0000000..08d7828 --- /dev/null +++ b/dotconfig/bin/cpu_calcul @@ -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) diff --git a/dotconfig/bin/dmount b/dotconfig/bin/dmount new file mode 100755 index 0000000..6aeb5d7 --- /dev/null +++ b/dotconfig/bin/dmount @@ -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 diff --git a/dotconfig/bin/newuptime b/dotconfig/bin/newuptime new file mode 100755 index 0000000..03b9352 --- /dev/null +++ b/dotconfig/bin/newuptime @@ -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 diff --git a/dotconfig/bin/nfetch-startup b/dotconfig/bin/nfetch-startup new file mode 100755 index 0000000..be5387b --- /dev/null +++ b/dotconfig/bin/nfetch-startup @@ -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 + + diff --git a/dotconfig/bin/nigga b/dotconfig/bin/nigga new file mode 100755 index 0000000..f5a145d --- /dev/null +++ b/dotconfig/bin/nigga @@ -0,0 +1,2 @@ +#!/bin/bash +echo "POV: Je suis raciste" diff --git a/dotconfig/bin/open_eww b/dotconfig/bin/open_eww new file mode 100755 index 0000000..1b71cfc --- /dev/null +++ b/dotconfig/bin/open_eww @@ -0,0 +1,5 @@ +#!/bin/sh + +eww open system +eww open clock +eww open perf diff --git a/dotconfig/bin/print_yuck_disks_mounted b/dotconfig/bin/print_yuck_disks_mounted new file mode 100755 index 0000000..4e2186d --- /dev/null +++ b/dotconfig/bin/print_yuck_disks_mounted @@ -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}" diff --git a/dotconfig/bin/remote_connection.sh b/dotconfig/bin/remote_connection.sh new file mode 100755 index 0000000..2c2bbe1 --- /dev/null +++ b/dotconfig/bin/remote_connection.sh @@ -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= Select the user, by default root + -p ,--port= Select the port, by default 10022 + -H , --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 + + + diff --git a/dotconfig/bin/rotate_screen b/dotconfig/bin/rotate_screen new file mode 100755 index 0000000..77bd283 --- /dev/null +++ b/dotconfig/bin/rotate_screen @@ -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 + diff --git a/dotconfig/bin/swaylock-script b/dotconfig/bin/swaylock-script new file mode 100755 index 0000000..d63a3db --- /dev/null +++ b/dotconfig/bin/swaylock-script @@ -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 + +