Enviado em 11/01/2024 - 16:00h
Este é um esboço de um menu checklist sem dialog ou similares.#!/bin/sh
: '
Two read functions for Bourne Shell (ueliton@disroot.org 28/07/23)
usage;
mini_read -t 3 -n 3 myVar
-n nchars return after reading NCHARS characters rather than waiting for a newline.
Just work with -s arg.
-t time out and return failure if a complete line of input is not read within TIMEOUT seconds.
-s do not echo input coming from a terminal
'
mini_read () {
#enquanto total args maior que 0
while [ $# -gt 0 ]; do
# caso primeiro arg
case "$1" in
-t)
MRTIME=$2 shift 2
;;
-n)
MRCOUNT=$2 shift 2
;;
-s)
MRSUPRE=$1 shift
;;
*)
if [ $# -eq 1 ]; then
MRVAR_NAME=$1
shift
else
echo "Invalid parameter: $1"
exit 1
fi
;;
esac
done
MRLAST_ARG=${!#}
eval "MRVAR=\$$MRLAST_ARG"
eval "${MRVAR_NAME}=\$MRVAR"
if [ -z "$MRTIME" ]; then
MRTIME=300
elif [ -z "$MRCOUNT" ]; then
MRCOUNT=300
fi
mrback_ground () {
(
sleep 1s
for MRLOOP in $(seq $MRTIME -1 0); do
MRPIDF=$(ps ax -o pid=,args=|grep "dd bs=1 count=$MRCOUNT"|grep -v 'grep'|head -n 1|grep -o -E '([0-9]{2,6})')
if [ -z "$MRPIDF" ]; then
MRLOOP=0
elif [ "$MRLOOP" -eq 0 ]; then
kill -s PIPE $MRPIDF >/dev/null 2>&1
kill -15 $MRPIDF >/dev/null 2>&1
fi
sleep 1s
done
)
}
mrback_ground </dev/null &>/dev/null &
MRFPID=$(echo "$!"|grep -o -E '([0-9]{2,6})')
unset MRINPUT_READ
if [ ! -z "$MRSUPRE" ]; then
stty -echo
fi
stty raw
MRINPUT_READ=$(dd bs=1 count="$MRCOUNT" 2>/dev/null)
stty -raw
stty echo
eval ${MRVAR_NAME}=$MRINPUT_READ
MRRPID=$(ps ax -o pid=|grep -o "$MRFPID")
if [ -z "$MRINPUT_READ" ] && [ ! -z "$MRRPID" ]; then
kill -s PIPE $MRFPID >/dev/null 2>&1
kill -15 $MRFPID >/dev/null 2>&1
printf "\n"
exit 1
else
printf "\n"
fi
}
#mini_read -n 2 -t 30 test
check_list(){
options(){
case $key in
A|a|1) case $Acheck in
A|a|1) Acheck="";;
*) Acheck="A";;
esac;;
B|b|2) case $Bcheck in
B|b|2) Bcheck="";;
*) Bcheck="B";;
esac;;
C|c|3) case $Ccheck in
C|c|3) Ccheck="";;
*) Ccheck="C";;
esac;;
D|d|4) case $Dcheck in
D|d|4) Dcheck="";;
*) Dcheck="D";;
esac;;
E|e|5) case $Echeck in
E|e|5) Echeck="";;
*) Echeck="E";;
esac;;
x|X) key="fim";;
esac
}
options
}
menu_list(){
a_check(){
if [ -z $Acheck ];then echo "( )";else echo "(x)";fi
}
b_check(){
if [ -z $Bcheck ];then echo "( )";else echo "(x)";fi
}
c_check(){
if [ -z $Ccheck ];then echo "( )";else echo "(x)";fi
}
d_check(){
if [ -z $Dcheck ];then echo "( )";else echo "(x)";fi
}
e_check(){
if [ -z $Echeck ];then echo "( )";else echo "(x)";fi
}
printf "\n Marque o que deseja digitando as letras referentes:
$(a_check) A. opt1
$(b_check) B. opt2
$(c_check) C. opt3
$(d_check) D. opt4
$(e_check) E. opt5
Digite X para sair\n"
}
until [ "$key" = fim ];do
clear
menu_list
mini_read -s -n 1 key
check_list
if [ "$key" = fim ]; then
break
fi
done
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Visualizar câmeras IP ONVIF no Linux sem necessidade de instalar aplicativos
Atualizar Debian Online de uma Versão para outra
Instalando Discord no Debian 13
Instalar driver Nvidia no Debian 13
Redimensionando, espelhando, convertendo e rotacionando imagens com script
Software livre - será que eu estou tão errado assim? (6)
A escola é altamente ineficiente e ineficaz! (10)