Funny and useful scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

158 lines
3.0 KiB

#!/bin/sh
#
_usage() {
cat <<EOF
Usage:
say [-h] -c | -d | -g | -m <message> | -t <dev> [-n] [-o <file>]
-h show this help message
-c say time
-d say date
-g godville.net
-m custom message
-t say device themperature (only cpu dev is supported)
-n show notification
-o save to file
Example:
say -m "Hello, World!" -n -o hello.wav
EOF
exit ${1}
}
_pluralform(){
n=$(( ${1} % 100 ))
n1=$(( ${n} % 10 ))
if [ ${n} -gt 10 -a ${n} -lt 20 ]; then
echo ${4}
elif [ ${n1} -gt 1 -a ${n1} -lt 5 ]; then
echo ${3}
elif [ ${n1} -eq 1 ]; then
echo ${2}
else
echo ${4}
fi
}
_date() {
echo "Сегодня - $( date '+%A' ), $( date2word.lua )."
}
_time() {
H=$(( $( date '+%H' ) + 0 ))
M=$(( $( date '+%M' ) + 0 ))
H="${H} $( _pluralform ${H} час часа часов )"
M="${M} $( _pluralform ${M} минута минуты минут )"
echo "${H}. ${M}"
}
_godville() {
base="https://godville.net/gods/api"
god=""
api_key=""
url="${base}/${god}/${api_key}"
quote="$( ${CURL} "${url}" | jq ".diary_last" )"
echo "${quote}"
}
_temperature() {
D=${1:-none}
M=
case ${D} in
none) M="А куда градусник прикладывать?" ;;
cpu)
t=0
ncpu=$( sysctl -n hw.ncpu )
for C in $( seq 0 $(( ${ncpu} - 1 )) ); do
t1=$( sysctl -n dev.cpu.${C}.temperature 2>/dev/null | \
sed 's/,.*//' )
t1=${t1:-0}
if [ ${t1} -gt ${t} ]; then t=${t1}; fi
done
if [ ${t} -eq 0 ]; then
M="Градусник у процессора сломался или не поддерживается."
else
M="Температура центрального процессора: ${t}"
M="${M} $( _pluralform ${t} градус градуса градусов )"
M="${M} по Цельсию."
fi
;;
esac
echo "${M}"
}
if [ $# -lt 1 ]; then _usage; fi
SAY_CMD="$( which RHVoice-test )"
if [ -z "${SAY_CMD}" ]; then
echo "Speech synthesizer not found"
exit 1
fi
SAY_PARAM="--rate 95 --pitch 120 --volume 30 --profile elena+slt"
CURL="$( which curl )"
if [ -z "${CURL}" ]; then
echo "curl is required, but not found"
exit 1
else
CURL="${CURL} -s"
fi
NOTIFY="$( which notify-send )"
ACTION=
DEV=
MSG=
SEND=0
SUMMARY=
while getopts cdghm:no:t: OPT
do
case ${OPT} in
c|d|g|m|t)
if [ -z "${ACTION}" ]; then
case ${OPT} in
c) ACTION="time" ;;
d) ACTION="date" ;;
g)
ACTION="godville"
SUMMARY="Годвиль - Вести с полей" ;;
m)
ACTION="message"
MSG="${OPTARG}" ;;
t)
ACTION="temperature"
DEV="${OPTARG}" ;;
esac
else
echo "Only one of the options -d, -f, -g, -m, -t is allowed."
exit 2
fi ;;
n) SEND=1 ;;
o) SAY_PARAM="${SAY_PARAM} -o ${OPTARG}" ;;
h) _usage 0 ;;
*) _usage 2 ;;
esac
done
if [ "${ACTION}" != "message" ]; then
MSG="$( _${ACTION} ${DEV} )"
fi
if [ ${SEND} -eq 1 ] && [ -n "${NOTIFY}" ]; then
${NOTIFY} -u low -t 10000 -i dialog-information "${SUMMARY:- }" "${MSG}"
fi
echo "${MSG}" | ${SAY_CMD} ${SAY_PARAM}