Compare commits

...

5 Commits

Author SHA1 Message Date
root
4c60127786 make local variables local
.. to not interfere with variables in the scripts that source these utils.
2025-02-03 11:12:05 +01:00
204162a747 move mailer to mailer.sh 2024-03-22 07:18:06 +01:00
b852d13475 change sender address of mailer 2024-03-22 07:16:03 +01:00
64d9e38a94 (re)move old files 2024-03-22 07:14:52 +01:00
71539fb906 more robust references to script directory 2024-03-22 07:12:18 +01:00
11 changed files with 37 additions and 28 deletions

View File

@@ -1,6 +1,8 @@
#!/bin/bash
. /home/spezi/Scripts/utils/colors.sh
# https://stackoverflow.com/a/246128
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
. $SCRIPT_DIR/colors.sh
logger () {
echo -e "${NC}$(date) - [$BASHPID] - [${0##*/}] - $@${NC}"
@@ -11,13 +13,13 @@ loggerseparator () {
}
saferun () {
allcommands=""
local allcommands=""
for var in "$@"; do
allcommands="$allcommands$var /// "
done
logger "Enter to run the following command(s): $allcommands"
read ok
ret=0
local ret=0
for var in "$@"; do
if [[ $ret -eq 0 ]]; then
$var

View File

@@ -1,14 +0,0 @@
#!/bin/bash
mailer () {
if ! [[ -z "$3" ]]; then
mailfrom="From: $3 <mad@pogoan.de>"
fi
if ! [[ -z "$4" ]]; then
mailto="$4"
elif [[ -z "$mailto" ]]; then
mailto="christian@betz.cc"
fi
echo -e "$1" | mailx -s "$2" --append="$mailfrom" $mailto &>/dev/null
}

1
madmail.sh Symbolic link
View File

@@ -0,0 +1 @@
mailer.sh

14
mailer.sh Normal file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
mailer () {
if ! [[ -z "$3" ]]; then
local mailfrom="From: $3 <christian@betz.cc>"
fi
if ! [[ -z "$4" ]]; then
local mailto="$4"
elif [[ -z "$mailto" ]]; then
local mailto="christian@betz.cc"
fi
echo -e "$1" | mailx -s "$2" --append="$mailfrom" $mailto &>/dev/null
}

23
math.sh
View File

@@ -1,11 +1,18 @@
#!/bin/bash
DIRECTORY=$(cd `dirname $0` && pwd)
. /home/spezi/Scripts/utils/utils.sh
# https://stackoverflow.com/a/246128
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
. $SCRIPT_DIR/utils.sh
# https://unix.stackexchange.com/questions/66766/float-operation-with-bc
# https://unix.stackexchange.com/questions/89712/how-to-convert-floating-point-number-to-integer
# xargs: https://stackoverflow.com/questions/19148370/piping-seq-to-printf-for-number-formatting
divideint () {
if [ -z $3 ]; then
local scale=2
else
local scale=$3
fi
bc <<< "scale=$scale; $1/$2" | xargs printf "%.0f\n"
}
@@ -15,25 +22,25 @@ multiint () {
divide () {
if [ -z $3 ]; then
scale=2
local scale=2
else
scale=$3
local scale=$3
fi
bc <<< "scale=$scale; $1/$2"
}
multiply () {
if [ -z $3 ]; then
scale=2
local scale=2
else
scale=$3
local scale=$3
fi
bc <<< "scale=$scale; $1*$2"
}
avgoftwo () {
sum=$(bc <<< "$1+$2")
divideint $sum 2
local sum=$(bc <<< "$1+$2")
divide $sum 2
}
max () {

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
#!/bin/bash
isarray() {
var=$1
local var=$1
declare -p $1 2> /dev/null | grep -q '^declare \-a' && return 0
[[ ${var[0]} -eq ${var[0]} ]] && [[ ${var[1]} -eq ${var[1]} ]] && return 0 || return 1
}

View File

@@ -2,7 +2,7 @@
# https://stackoverflow.com/questions/13777387/check-for-ip-validity
function validip () {
ip=$1
local ip=$1
if [ -z $ip ] || ! [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
return 1
else