Initial commit : files form /home/$USER/bin

This commit is contained in:
Pieds-Nus 2022-09-16 20:47:15 +00:00
parent c57739fc93
commit 51366fefc8
5 changed files with 383 additions and 0 deletions

87
brightness.sh Normal file
View File

@ -0,0 +1,87 @@
#/bin/bash
usage="\
$0 up|down|min|max|set
Simple binder between screen brightness, hotkeys (via sxhkd) and herbe notifications
"
test $# -eq 0 -o $# -gt 2 && echo "$usage" && "One or two arguments expected" && exit 1 ;
#Run brightnessctl without arguments to get this value (statically stored to avoid multiple calls)
#max=851
#Minimal desired brightness, set to your taste. If 0, the screen will actually blank, set higher if you prefer.
#min=1
case $1 in
"down")
#lvl=`brightnessctl set ${2:-3}%+ | grep Current | cut -d '(' -f 2 | tr -d '%)'`
lvl=`brightnessctl get` #; echo $lvl ;
# let lvl=lvl*9/10 #; echo $lvl ;
if test $lvl -lt 50 ; then
let lvl=lvl-5
else
let lvl=lvl*9/10
fi
brightnessctl -q set $lvl
;;
"up")
#lvl=`brightnessctl set ${2:-3}%- | grep Current | cut -d '(' -f 2 | tr -d '%)'`
lvl=`brightnessctl get` #; echo $lvl ;
# let lvl=lvl*10/9 #; echo $lvl ;
if test $lvl -lt 50 ; then
let lvl=lvl+5
else
let lvl=lvl*10/9
fi
brightnessctl -q set $lvl
;;
"min")
lvl=1
brightnessctl -q set 1 | grep Current | cut -d '(' -f 2 | tr -d '%)'
;;
"max")
lvl=851
brightnessctl -q set 851 | grep Current | cut -d '(' -f 2 | tr -d '%)'
;;
"set")
test $((2*=1)) -eq 0 && echo $usage && echo "Invalid argument: $2 (integer expected in the range 1-100)"
lvl=`brightnessctl set $2%+ | grep Current | cut -d '(' -f 2 | tr -d '%)'`
;;
*)
echo "$usage"
echo "Unrecognized argument: $1"
exit 1
;;
esac
ls /tmp/dsblok.pid &> /dev/null && /home/karsaell/Downloads/dsblocks/sigdsblocks/sigdsblocks 2 $lvl
#echo lvl: $lvl
for i in {1..851..25} ; do
if test $i -lt $lvl ; then
herbe="$herbe*"
else
herbe="$herbe "
fi
done
test -s /tmp/herbe_brightness_pid && kill -s SIGUSR1 `cat /tmp/herbe_brightness_pid` && rm /tmp/herbe_brightness_pid
herbe "$herbe" &
pid=$!
echo $pid >> /tmp/herbe_brightness_pid
wait $pid
test -e /tmp/herbe_brightness_pid && echo -n `cat /tmp/herbe_brightness_pid | grep -v $pid` > /tmp/herbe_brightness_pid

146
pnstatus.sh Normal file
View File

@ -0,0 +1,146 @@
#!/bin/bash
# Dependencies
#acpitools
#nmcli
#awk
#bc
remode() {
echo $((($(tail -n 1 /tmp/pnstatus_mode) $1 1 + 3 ) % 3)) >> /tmp/pnstatus_mode
kill $waitpid
}
trap "remode +" SIGUSR1
trap "remode -" SIGUSR2
echo -e "\
Mode control for pnstatus script\n\
Write the desired mode as last line of this file\n\
\t0|min :\tminimal mode :\t| 23:25\n\
\t1|some :\tintermediate mode :\t| Wifi | CPU:RAM:SWAP | BATTERY | DA/TE TI:ME\n\
\t1|all :\t complete mode :\t| Network | CPU:RAM:SWAP | TEMP | BATTERY | DA/TE TI:ME\n\
0" \
> /tmp/pnstatus_mode
command=echo
if test "$1" = "-x" ; then
# echo "-x"
command="xsetroot -name"
shift 1
fi
if test "$1" = "-c" ; then
# echo "-c"
command="$2"
shift 2
fi
# echo $command
echo ${1:-0} >> /tmp/pnstatus_mode
while true ; do
res=""
case $(tail -n 1 /tmp/pnstatus_mode) in
0|"min")
res="$(date '+%H:%M')"
sleep 30 & waitpid=$!
;;
1|"some")
connect=""
#Check ethernet interface status
grep "up" /sys/class/net/enp0s25/operstate > /dev/null && connect=$connect\E
#Check wifi interface status
grep "up" /sys/class/net/wlp3s0/operstate > /dev/null && connect=$connect\W
# CPU load (divided by 4 cause 4-core i5 cpu.
# Dirty way of dealing with bash and non-integer calculations : )
# | tr -d "." removes the decimal point read in /proc/loadavg
# If it is always written with three significative numbers, should work...
cpu="$(echo "($(acpitool -c | head -n 3 | tail -n 1 | rev | cut -d " " -f 2 | rev)-800)/26" | bc)"
# ram usage
ram=$(free | head -n 2 | tail -n 1 | awk '{printf( "%.0f", $3/$2*100 )}')
# swap usage
swap=$(head -n 16 /proc/meminfo | tail -n 2 | tr -s " " | cut -d " " -f 2 | tr "\n" " " | awk '{printf( "%.0f", ($1-$2)*100/$1)}')
# battery state
bat=$(cat /sys/class/power_supply/BAT1/capacity)
case "$(cat /sys/class/power_supply/BAT1/status)" in
"Full") batstate="" ;;
"Discharging") batstate="-" ;;
"Charging") batstate="+" ;;
"Not charging") batstate="." ;;
*) batstate="?" ;;
esac
res="| $connect | $cpu:$ram:$swap | B:$batstate$bat% | $(date '+%a %d/%m %H:%M')"
sleep 2 & waitpid=$!
;;
2|"all")
# Network
#Should look into iw dev wls3p0 scan dump to get that info quicker
wifi=$(timeout 0.5 nmcli -f IN-USE,SSID,BARS d wifi list | grep ^\* | cut -c 9- | tr -s " ")
grep -q "up" /sys/class/net/enp0s25/operstate && eth=eth
test -n "$wifi" && test -n "$eth" && eth=" - $eth"
res=$res"| $wifi$eth"
#CPU
# cpu1=$(cut -d " " -f 1 /proc/loadavg)
# cpu2=$(cut -d " " -f 2 /proc/loadavg)
# cpu=$(awk '{printf( "%.0f", $cpu1*25 "% - " $cpu2*25 "%" )}')
#cpu=$(cut -d " " -f 1,2 /proc/loadavg | awk '{print $1*25 "%-" $2*25 "%" }')
#cpu freq
res=$res" | C:$(echo "($(acpitool -c | head -n3 | tail -n 1 | rev | cut -d " " -f 2 | rev)-800)/26" | bc)"
#cpu load avg (1 minute) (4 thread-processor)
res=$res" L:$(echo "scale=0 ; $(cut -d " " -f 1 /proc/loadavg) * 25/1" | bc)"
#RAM
mems=($(head -n 3 /proc/meminfo | grep -v MemFree | tr -s " " | cut -d " " -f 2))
res="$res | R:$(((${mems[0]}-${mems[1]})*100/${mems[0]}))"
#SWAP
res="$res S:$(head -n 16 /proc/meminfo | tail -n 2 | tr -s " " | cut -d " " -f 2 | tr "\n" " " | awk '{printf( "%.0f", ($1-$2)*100/$1)}')"
#TEMP °C
#Generic way :
# $(( ( $(cat /sys/class/thermal/thermal_zone*/temp | rev | cut -c 4- | rev | tr "\n" "+") 0 ) / $(ls -d /sys/class/thermal/thermal_zone* | wc -w) ))
#Specific for only 2 thermal_zones :
res="$res | T:$(( ( $(cat /sys/class/thermal/thermal_zone0/temp | rev | cut -c 4- | rev) + $(cat /sys/class/thermal/thermal_zone1/temp | rev | cut -c 4- | rev) ) / 2 ))°C"
#BATTERY
bat=$(cat /sys/class/power_supply/BAT1/capacity)
batstate=$(cat /sys/class/power_supply/BAT1/status)
case "$batstate" in
"Full") batstate="" ;;
"Discharging") batstate="-" ;;
"Charging") batstate="+" ;;
"Not charging") batstate="." ;;
*) batstate="?" ;;
esac
res="$res | B:$bat%$batstate"
#DATE
res="$res | $(date "+%a %d/%m %H:%M")"
sleep 2 & waitpid=$!
;;
*)
echo $usage
exit 1
;;
esac
$command "$res"
wait $waitpid
done

56
progressbar.sh Normal file
View File

@ -0,0 +1,56 @@
#!/bin/bash
usage() { echo "Usage: $0 [-c bar|dot|o] [-s str] [-z] VALUE" 1>&2; ${1:+echo $1} ; exit 1; }
while getopts ":c:s:hz:" o; do
case "${o}" in
c)
case ${OPTARG} in
"bar") replace="" ;;
"dot") replace=*\"\' ;;
"o"|"O") replace="Oo.";;
*) usage "-c option only accepts \"bar\", \"dot\" or \"o\"" ;;
esac
;;
s)
if test $(echo -n ${OPTARG} | wc -c ) -eq 3 ; then
replace=${OPTARG}
else
usage "-s option requires a 3-character-long string"
fi
;;
z)
z=-n
;;
*)
usage "Invalid argument: $o $OPTARG"
;;
esac
done
shift $((OPTIND-1))
test $# -ne 1 && usage
value=${value:-$1}
test $value -ge 0 -a $1 -le 100 || usage "VALUE must be an integer between 0 and 100"
for j in {3..100..3} ; do
if [[ j -gt $value ]] ; then
case $(($value%3)) in
0) res=$res"";;
1) res=$res".";;
2) res=$res":";;
esac
break
fi
res=$res"|"
done
res=$res" "
res=[${res:1:32}]
test $replace && res=$(echo "$res" | tr "|:." "$replace")
echo $z "$res"

35
rotatescreen.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
usage="usage: $0 { -cw|-cc } \nRotate the screen clockwise|counter-clockwise using xrandr."
if test ! $# -eq 1 ; then
echo -e $usage
echo "Invalid number of argument"
exit 1
elif test "$1" != "-cw" -a "$1" != "-cc" ; then
echo -e $usage
echo "Unrecognized option : $1"
exit 1
fi
cur=$(xrandr -q | grep "eDP-1" | cut -d '(' -f 1 | rev | cut -d ' ' -f 2 | rev)
case "$cur" in
"left")
test $1 = "-cw" && xrandr -o 0 && echo 1
test $1 = "-cc" && xrandr -o 2 && echo 2
;;
"right")
test $1 = "-cw" && xrandr -o 2 && echo 3
test $1 = "-cc" && xrandr -o 0 && echo 4
;;
"inverted")
test $1 = "-cw" && xrandr -o 1 && echo 5
test $1 = "-cc" && xrandr -o 3 && echo 6
;;
*)
test $1 = "-cw" && xrandr -o 3 && echo 7
test $1 = "-cc" && xrandr -o 1 && echo 8
;;
esac
exit $?

59
swapctl.sh Normal file
View File

@ -0,0 +1,59 @@
#!/bin/bash
usage="$0 -d DIR -n NAME -s SIZE -p PRIO add|remove
Add or remove swapfiles to micro-manage disk usage.
-d DIR : set DIRectory to place swapfile in. Default: /mnt
-n NAME : set filename for the swapfile. Default: swapfileN
-s SIZE : SIZE in MB (only when creating a swapfile). Default: 1024
-p PRIO : Priority to use with swapon. Range from 0 to 1000. Default: 500
-h : Display this help and exit."
test $# -eq 0 && ( echo -e "$usage" ; echo "You must provide either 'add' or 'remove' !" ; exit 1 )
SWAP_FOLDER="/mnt"
SWAP_FILENAME="swapfile"
SWAP_SIZE="12" #in MB
SWAP_PRIO_MAX=500 #range 0..1000
SWAP_PRIO_INC=10
while getopts hp:s:n:d: arg ; do
case $arg in
h) echo -e "$usage" ; exit 0 ;;
d) SWAP_FOLDER="$OPTARG" ;;
n) SWAP_FILENAME="$OPTARG" ;;
s) SWAP_SIZE="$OPTARG" ;;
p) SWAP_PRIO_MAX="$OPTARG" ;;
*) echo -e "$usage" ; echo "Invalid option: $arg"; exit 1 ;;
esac
done
shift $((( $OPTIND - 1 )))
if test "$1" = "add" ; then
N=$(ls $SWAP_FOLDER/$SWAP_FILENAME* | wc -l)
swapfile=$SWAP_FOLDER/$SWAP_FILENAME$N
echo "Creating swapfile: $swapfile"
sudo dd if=/dev/urandom of=$swapfile bs=1M count=$SWAP_SIZE status=progress
sudo chmod 0600 $swapfile
sudo mkswap $swapfile
sudo swapon -p $((($SWAP_PRIO_MAX - $N * $SWAP_PRIO_INC))) $swapfile
echo -e "\n\n\n\n"
sudo swapon
elif test "$1" = "remove" ; then
N=$(ls $SWAP_FOLDER/$SWAP_FILENAME* | wc -l)
swapfile=$SWAP_FOLDER/$SWAP_FILENAME$((($N - 1)))
echo "Removing swapfile: $swapfile"
sudo swapoff $swapfile && sudo rm $swapfile
echo -e "\n\n\n\n"
sudo swapon
fi