Compare commits
31 Commits
567a3ae1a9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb67db2a78 | ||
|
|
71cf1ec44c | ||
|
|
ed19ae5c0d | ||
|
|
c4d9e053ee | ||
|
|
8d88743624 | ||
|
|
2cdab60efb | ||
|
|
c761fe5d93 | ||
|
|
4342f0a5f8 | ||
|
|
be7e5da172 | ||
|
|
4174b3f7e3 | ||
|
|
9d5f5eac9f | ||
|
|
4f2f11bd1a | ||
|
|
d61329011b | ||
|
|
4292b8e4dc | ||
|
|
5c930248eb | ||
|
|
9bc3710c32 | ||
|
|
287a1fd2d3 | ||
|
|
aac91e9a55 | ||
|
|
fd8ad9799b | ||
|
|
3c42aff8f5 | ||
|
|
26460cf7f5 | ||
|
|
8a3654e42b | ||
|
|
855352bdf4 | ||
|
|
f5af07290e | ||
|
|
f0d521b49a | ||
|
|
4d0bf673a5 | ||
|
|
bf5c616f01 | ||
|
|
0f7cddd5a6 | ||
|
|
1e5e310fc8 | ||
|
|
05475361e8 | ||
|
|
ae1379180c |
@@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
. /etc/profile
|
. /etc/profile
|
||||||
|
|
||||||
# export all functions
|
|
||||||
set -a
|
|
||||||
|
|
||||||
|
|
||||||
## Include functions
|
## Include functions
|
||||||
for bashfunc in $(find /etc/bash/gaboshlib -type f -name "g_*.bashfunc" -o -name "g_*.sh")
|
for bashfunc in $(find /etc/bash/gaboshlib -type f -name "g_*.bashfunc" -o -name "g_*.sh")
|
||||||
do
|
do
|
||||||
@@ -34,7 +30,7 @@ g_tmp="$g_tmp/g_$g_scriptname-$$"
|
|||||||
|
|
||||||
# START and EXIT Notification
|
# START and EXIT Notification
|
||||||
g_trap_exit="g_logger EXITING $g_scriptname ; rm -r $g_tmp ; g_kill_all_background_jobs >/dev/null 2>&1"
|
g_trap_exit="g_logger EXITING $g_scriptname ; rm -r $g_tmp ; g_kill_all_background_jobs >/dev/null 2>&1"
|
||||||
trap "$g_trap_exit" EXIT
|
trap "$g_trap_exit" INT TERM EXIT
|
||||||
g_syslogtag="g_bash-script:$g_scriptname[$$]"
|
g_syslogtag="g_bash-script:$g_scriptname[$$]"
|
||||||
[ $g_scriptname = "bash" ] || g_logger STARTING $g_scriptname
|
[ $g_scriptname = "bash" ] || g_logger STARTING $g_scriptname
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ vpn
|
|||||||
.config/Nextcloud/
|
.config/Nextcloud/
|
||||||
nextcloud-test.*/
|
nextcloud-test.*/
|
||||||
.VirtualBox/
|
.VirtualBox/
|
||||||
|
VirtualBox/
|
||||||
DMS/
|
DMS/
|
||||||
tmp
|
tmp
|
||||||
.zoom/
|
.zoom/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
function g_basename {
|
function g_basename {
|
||||||
g_basename_result="${1##*/}"
|
g_basename_result=${1##*/}
|
||||||
g_basename_result="${g_basename_result:-/}"
|
g_basename_result=${g_basename_result:-/}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,66 +1,58 @@
|
|||||||
function g_calc {
|
function g_calc {
|
||||||
|
|
||||||
|
# function for calculating via bc running in the background (much faster then starting bc every time)
|
||||||
|
# $g_fd_bc_in $fd_bc_out have to be global
|
||||||
|
|
||||||
unset g_calc_result
|
unset g_calc_result
|
||||||
|
|
||||||
local g_calc_jobs g_rnd
|
local g_jobs
|
||||||
local g_bc_running=true
|
mapfile -t g_jobs < <(jobs -r)
|
||||||
mapfile -t g_calc_jobs < <(jobs -r)
|
|
||||||
g_calc_jobs_v=${g_calc_jobs[*]}
|
|
||||||
[[ $g_calc_jobs_v =~ bc ]] || unset g_bc_running
|
|
||||||
|
|
||||||
# Use bc in backround for multiple bc's running much faster
|
# check if bc is already running
|
||||||
if [ -z "${g_bc_running}" ]
|
if [[ -z "$g_fd_bc_in" || -z "$g_fd_bc_out" || ${g_jobs[*]} != *bc* ]]
|
||||||
then
|
then
|
||||||
|
local bc_input="$g_tmp/$$-g_bc_input"
|
||||||
g_kill_all_background_jobs bc-ql
|
local bc_output="$g_tmp/$$-g_bc_output"
|
||||||
g_kill_all_background_jobs sed
|
# create fifo pipe
|
||||||
|
[ -p "$bc_input" ] || mkfifo "$bc_input"
|
||||||
g_rnd=$$
|
[ -p "$bc_output" ] || mkfifo "$bc_output"
|
||||||
mkdir -p ${g_tmp}/${g_rnd}
|
# run bc in background und switch i/o to pipes
|
||||||
[ -p ${g_tmp}/${g_rnd}/bc-in ] || mkfifo ${g_tmp}/${g_rnd}/bc-in
|
bc -ql < "$bc_input" > "$bc_output" 2>&1 &
|
||||||
[ -p ${g_tmp}/${g_rnd}/bc-out ] || mkfifo ${g_tmp}/${g_rnd}/bc-out
|
# store in filedescriptiors
|
||||||
[ -p ${g_tmp}/${g_rnd}/bc-sed-in ] || mkfifo ${g_tmp}/${g_rnd}/bc-sed-in
|
exec {g_fd_bc_in}> "$bc_input"
|
||||||
[ -p ${g_tmp}/${g_rnd}/bc-sed-out ] || mkfifo ${g_tmp}/${g_rnd}/bc-sed-out
|
exec {g_fd_bc_out}< "$bc_output"
|
||||||
|
|
||||||
# bc stream channel
|
|
||||||
{ bc -ql <${g_tmp}/${g_rnd}/bc-in 2>&1 >${g_tmp}/${g_rnd}/bc-out & } 2>/dev/null
|
|
||||||
exec 3>${g_tmp}/${g_rnd}/bc-in 4<${g_tmp}/${g_rnd}/bc-out
|
|
||||||
|
|
||||||
# sed stream channel
|
|
||||||
{ sed -su 's/^\./0./; s/^-\./-0./' <${g_tmp}/${g_rnd}/bc-sed-in >${g_tmp}/${g_rnd}/bc-sed-out & } 2>/dev/null
|
|
||||||
exec 5>${g_tmp}/${g_rnd}/bc-sed-in 6<${g_tmp}/${g_rnd}/bc-sed-out
|
|
||||||
|
|
||||||
g_bc_running="true"
|
|
||||||
fi
|
fi
|
||||||
|
# send calculation and read result
|
||||||
|
echo "$1" >&${g_fd_bc_in}
|
||||||
|
read -u ${g_fd_bc_out} g_calc_result
|
||||||
|
|
||||||
# do bc
|
# check if there is a output
|
||||||
echo "scale=8; $@" >&3
|
if [ -z "$g_calc_result" ]
|
||||||
local g_bc_out
|
|
||||||
if ! read -t 0.1 g_bc_out <&4
|
|
||||||
then
|
then
|
||||||
g_traceback "$@"
|
echo "${FUNCNAME} $@" 1>&2
|
||||||
( exec 3<&- ) 2>/dev/null
|
unset g_calc_result
|
||||||
( exec 4<&- ) 2>/dev/null
|
|
||||||
( exec 5<&- ) 2>/dev/null
|
|
||||||
( exec 6<&- ) 2>/dev/null
|
|
||||||
#unset g_bc_running
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# do sed
|
# fix bc output -> change for example .224 to 0.224 and -.224 to -0.224
|
||||||
echo ${g_bc_out} >&5
|
[[ $g_calc_result == "."* ]] && g_calc_result="0$g_calc_result"
|
||||||
local g_sed_out
|
[[ $g_calc_result == "-."* ]] && g_calc_result="-0.${g_calc_result#-.}"
|
||||||
if ! read -t 0.1 g_sed_out <&6
|
|
||||||
|
# remove ending 0 if for exabple 4.54300000
|
||||||
|
while [[ $g_calc_result =~ [.] && ${g_calc_result: -1} == "0" ]]
|
||||||
|
do
|
||||||
|
g_calc_result=${g_calc_result: : -1}
|
||||||
|
done
|
||||||
|
|
||||||
|
# remove ending . for example "100." -> 100
|
||||||
|
[[ $g_calc_result == *"." ]] && g_calc_result=${g_calc_result%?}
|
||||||
|
|
||||||
|
# check output
|
||||||
|
if ! g_num_valid_number "$g_calc_result"
|
||||||
then
|
then
|
||||||
g_traceback "$@"
|
echo "${FUNCNAME} $@" 1>&2
|
||||||
( exec 3<&- ) 2>/dev/null
|
unset g_calc_result
|
||||||
( exec 4<&- ) 2>/dev/null
|
|
||||||
( exec 5<&- ) 2>/dev/null
|
|
||||||
( exec 6<&- ) 2>/dev/null
|
|
||||||
#unset g_bc_running
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# store result
|
|
||||||
g_calc_result=$g_sed_out
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,13 +8,12 @@ function g_kill_all_background_jobs {
|
|||||||
then
|
then
|
||||||
kill -9 ${g_pids[*]} >/dev/null 2>&1
|
kill -9 ${g_pids[*]} >/dev/null 2>&1
|
||||||
else
|
else
|
||||||
local g_cmdline=$1
|
local g_cmdline="$1"
|
||||||
local g_proc
|
local g_proc
|
||||||
local g_pid
|
local g_pid
|
||||||
for g_pid in "${g_pids[@]}"
|
for g_pid in "${g_pids[@]}"
|
||||||
do
|
do
|
||||||
echo $g_pid
|
read g_proc < <(tr "\0" " " < /proc/${g_pid}/cmdline)
|
||||||
readarray g_proc < "/proc/$g_pid/cmdline"
|
|
||||||
[ "$g_proc" = "$g_cmdline" ] && kill -9 $g_pid >/dev/null 2>&1
|
[ "$g_proc" = "$g_cmdline" ] && kill -9 $g_pid >/dev/null 2>&1
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|||||||
26
gaboshlib/g_median.sh
Normal file
26
gaboshlib/g_median.sh
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
function g_median {
|
||||||
|
unset g_median_result
|
||||||
|
|
||||||
|
# Array with numbers
|
||||||
|
local g_numbers=("$@")
|
||||||
|
|
||||||
|
# sort array
|
||||||
|
local g_sorted_numbers=($(printf "%s\n" "${g_numbers[@]}" | sort -n))
|
||||||
|
|
||||||
|
# number of elements
|
||||||
|
local g_num_elements=${#g_sorted_numbers[@]}
|
||||||
|
|
||||||
|
# calculate the middle
|
||||||
|
local g_middle=$(($g_num_elements/2))
|
||||||
|
|
||||||
|
# even/odd number
|
||||||
|
if (($g_num_elements % 2 == 1))
|
||||||
|
then
|
||||||
|
# odd number
|
||||||
|
g_median_result="${g_sorted_numbers[$g_middle]}"
|
||||||
|
else
|
||||||
|
# even number
|
||||||
|
g_calc "(${g_sorted_numbers[$g_middle - 1]} + ${g_sorted_numbers[$g_middle]}) / 2"
|
||||||
|
g_median_result="$g_calc_result"
|
||||||
|
fi
|
||||||
|
}
|
||||||
@@ -5,16 +5,16 @@ function g_num_exponential2normal {
|
|||||||
if [[ "$1" =~ e-[0-9] ]]
|
if [[ "$1" =~ e-[0-9] ]]
|
||||||
then
|
then
|
||||||
# convert
|
# convert
|
||||||
printf -v f_g_num_exponential2normal_result -- "%.12f" "$1"
|
printf -v g_num_exponential2normal_result -- "%.12f" "$1"
|
||||||
# remove ending 0
|
# remove ending 0
|
||||||
if [[ $f_g_num_exponential2normal_result =~ \. ]]
|
if [[ $g_num_exponential2normal_result =~ \. ]]
|
||||||
then
|
then
|
||||||
f_g_num_exponential2normal_result=${f_g_num_exponential2normal_result%%+(0)}
|
g_num_exponential2normal_result=${g_num_exponential2normal_result%%+(0)}
|
||||||
f_g_num_exponential2normal_result=${f_g_num_exponential2normal_result%%.}
|
g_num_exponential2normal_result=${g_num_exponential2normal_result%%.}
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
f_g_num_exponential2normal_result=$1
|
g_num_exponential2normal_result=$1
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
11
gaboshlib/g_num_exponential2normal_file.sh
Normal file
11
gaboshlib/g_num_exponential2normal_file.sh
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
function g_num_exponential2normal_file {
|
||||||
|
# changes expionential numbers in normal notation in given file
|
||||||
|
local g_file=$1
|
||||||
|
local g_substitution g_exnum
|
||||||
|
for g_exnum in $(egrep -o -i "[0-9]+\.[0-9]+e[\+\-][0-9]+" "$g_file" | sort -u)
|
||||||
|
do
|
||||||
|
g_num_exponential2normal $g_exnum && g_substitution="${g_substitution}s/${g_exnum}/${g_num_exponential2normal_result}/g;"
|
||||||
|
done
|
||||||
|
sed -i "${g_substitution}" "$g_file" && return 0
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,62 @@
|
|||||||
function g_python {
|
function g_python {
|
||||||
|
|
||||||
|
# function for running python in the background
|
||||||
|
# $g_fd_python_in $g_fd_python_out have to be global
|
||||||
|
|
||||||
|
unset g_python_result
|
||||||
|
|
||||||
|
local g_jobs
|
||||||
|
mapfile -t g_jobs < <(jobs -r)
|
||||||
|
# check if python is already running
|
||||||
|
if [[ -z $g_fd_python_in || -z $g_fd_python_out || ${g_jobs[*]} != *python3* ]]
|
||||||
|
then
|
||||||
|
local python_input="$g_tmp/$$-g_python_input"
|
||||||
|
local python_output="$g_tmp/$$-g_python_output"
|
||||||
|
local python_error="$g_tmp/$$-g_python_error"
|
||||||
|
# create fifo pipe
|
||||||
|
[ -p "$python_input" ] || mkfifo "$python_input"
|
||||||
|
[ -p "$python_output" ] || mkfifo "$python_output"
|
||||||
|
[ -p "$python_error" ] || mkfifo "$python_error"
|
||||||
|
# run bc in background und switch i/o to pipes
|
||||||
|
python3 -iuq < "$python_input" > "$python_output" 2> "$python_error" &
|
||||||
|
# store in filedescriptiors
|
||||||
|
exec {g_fd_python_in}> "$python_input"
|
||||||
|
exec {g_fd_python_out}< "$python_output"
|
||||||
|
exec {g_fd_python_error}< "$python_error"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# read potential old output
|
||||||
|
read -t 0.001 -u ${g_fd_python_out} g_python_result_old
|
||||||
|
|
||||||
|
# send python command
|
||||||
|
echo "$@
|
||||||
|
print('')" >&${g_fd_python_in}
|
||||||
|
|
||||||
|
# read output
|
||||||
|
read -u ${g_fd_python_out} g_python_result
|
||||||
|
|
||||||
|
local g_errline
|
||||||
|
local g_err_msg
|
||||||
|
|
||||||
|
# look for error
|
||||||
|
while read -t 0.001 -u ${g_fd_python_error} g_errline
|
||||||
|
do
|
||||||
|
[[ "$g_errline" =~ \>\>\>$ ]] && break
|
||||||
|
[ -z "$g_errline" ] && break
|
||||||
|
g_err_msg="$g_err_msg
|
||||||
|
$g_errline"
|
||||||
|
done
|
||||||
|
if [ -n "$g_err_msg" ]
|
||||||
|
then
|
||||||
|
g_echo_error "$g_err_msg"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function g_python_old {
|
||||||
|
|
||||||
local g_python_tmp=${g_tmp}/$$
|
local g_python_tmp=${g_tmp}/$$
|
||||||
g_python_out=${g_python_tmp}/python-out
|
g_python_out=${g_python_tmp}/python-out
|
||||||
local g_python_in=${g_python_tmp}/python-in
|
local g_python_in=${g_python_tmp}/python-in
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ function g_read_csv {
|
|||||||
local g_headline=$3
|
local g_headline=$3
|
||||||
local g_separator=$4
|
local g_separator=$4
|
||||||
|
|
||||||
local g_headline_item i l r
|
local g_headline_item i l r g_csv_headline_array
|
||||||
|
|
||||||
# check for individual separator
|
# check for individual separator
|
||||||
[ -z "$g_separator" ] && g_separator=","
|
[ -z "$g_separator" ] && g_separator=","
|
||||||
@@ -39,14 +39,20 @@ function g_read_csv {
|
|||||||
[ -z "$g_headline" ] && g_headline=$(head -n1 "${g_csvfile}")
|
[ -z "$g_headline" ] && g_headline=$(head -n1 "${g_csvfile}")
|
||||||
|
|
||||||
# read the headline
|
# read the headline
|
||||||
|
unset g_csv_headline_array_ref
|
||||||
g_array "$g_headline" g_csv_headline_array_ref $g_separator
|
g_array "$g_headline" g_csv_headline_array_ref $g_separator
|
||||||
|
|
||||||
# prepare varnames from headline(s)
|
# prepare varnames from headline(s)
|
||||||
for g_headline_item in "${g_csv_headline_array_ref[@]}"
|
for g_headline_item in "${g_csv_headline_array_ref[@]}"
|
||||||
do
|
do
|
||||||
g_csv_headline_array+=("${g_headline_item//[^a-zA-Z0-9]/}")
|
g_csv_headline_array+=("${g_headline_item//[^a-zA-Z0-9_]/}")
|
||||||
done
|
done
|
||||||
|
|
||||||
|
g_basename $g_csvfile
|
||||||
|
local g_csvfile_base=${g_basename_result/\.history*.csv/}
|
||||||
|
g_csvfile_base=${g_csvfile_base//[^a-zA-Z0-9_]/}
|
||||||
|
g_csvfile_base=${g_csvfile_base//ECONOMY*/}
|
||||||
|
|
||||||
# read last lines if defined or complete csv file
|
# read last lines if defined or complete csv file
|
||||||
if [ -n "$g_last_lines" ]
|
if [ -n "$g_last_lines" ]
|
||||||
then
|
then
|
||||||
@@ -54,14 +60,15 @@ function g_read_csv {
|
|||||||
g_csvfile="${g_tmp}/g_csv_tmp.csv"
|
g_csvfile="${g_tmp}/g_csv_tmp.csv"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# read csv file to array
|
# read csv file to array
|
||||||
g_array "$g_csvfile" g_csv_array_ref
|
g_array "$g_csvfile" g_csv_array_ref
|
||||||
g_csv_array=("${g_csv_array_ref[@]}")
|
g_csv_array=("${g_csv_array_ref[@]}")
|
||||||
|
|
||||||
# go reverse through array
|
# create associative arrays forward and reverse and superarray v/vr
|
||||||
declare -Ag v_csv_array_associative
|
declare -Ag v_csv_array_associative
|
||||||
declare -Ag v_csv_array_associative_reverse
|
declare -Ag v_csv_array_associative_reverse
|
||||||
|
declare -Ag v
|
||||||
|
declare -Ag vr
|
||||||
l=0
|
l=0
|
||||||
for (( r=${#g_csv_array[@]}-1 ; r>=0 ; r-- ))
|
for (( r=${#g_csv_array[@]}-1 ; r>=0 ; r-- ))
|
||||||
do
|
do
|
||||||
@@ -75,6 +82,14 @@ function g_read_csv {
|
|||||||
[ "$l" = 0 ] && declare -g v_${g_headline_item}="${g_csv_line_array[i]}"
|
[ "$l" = 0 ] && declare -g v_${g_headline_item}="${g_csv_line_array[i]}"
|
||||||
v_csv_array_associative[${g_headline_item}_${r}]="${g_csv_line_array[i]}"
|
v_csv_array_associative[${g_headline_item}_${r}]="${g_csv_line_array[i]}"
|
||||||
v_csv_array_associative_reverse[${g_headline_item}_${l}]="${g_csv_line_array[i]}"
|
v_csv_array_associative_reverse[${g_headline_item}_${l}]="${g_csv_line_array[i]}"
|
||||||
|
if [ -z "${g_csvfile_base}" ]
|
||||||
|
then
|
||||||
|
v[${g_headline_item}_${r}]=${g_csv_line_array[i]}
|
||||||
|
vr[${g_headline_item}_${l}]=${g_csv_line_array[i]}
|
||||||
|
else
|
||||||
|
v[${g_csvfile_base}_${g_headline_item}_${r}]=${g_csv_line_array[i]}
|
||||||
|
vr[${g_csvfile_base}_${g_headline_item}_${l}]=${g_csv_line_array[i]}
|
||||||
|
fi
|
||||||
((i++))
|
((i++))
|
||||||
done
|
done
|
||||||
((l++))
|
((l++))
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
function g_wget {
|
function g_wget {
|
||||||
wget -T 10 -t 2 -U "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36" $@
|
wget -T 10 -t 2 \
|
||||||
|
--header="User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" \
|
||||||
|
--header="Content-Type: application/json" \
|
||||||
|
--header="Accept-Language: en-US,en," \
|
||||||
|
$@
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user