- First commit of the new version!

This commit is contained in:
2025-06-23 11:34:42 +02:00
parent 218b34a909
commit 7efd2f514c
5 changed files with 1922 additions and 800 deletions

239
usr/local/lib/default.bash Normal file
View File

@@ -0,0 +1,239 @@
#!/bin/bash
if [[ "${DEFAULT_BASH}" != "" ]]
then
return
else
declare -g DEFAULT_BASH=1
fi
# Global Variable
#-----------------------------------------------------------------------------------------------------------------------------------
# Default Options
#-----------------------------------------------------------------------------------------------------------------------------------
shopt -s extglob
# Print Version
#-----------------------------------------------------------------------------------------------------------------------------------
version_print()
{
echo "$VERSION" | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//'
}
# Prin Help
#-----------------------------------------------------------------------------------------------------------------------------------
help_print()
{
echo "${NAME} ${HELP}"
}
# Quote Str
#-----------------------------------------------------------------------------------------------------------------------------------
quote_str()
{
local quoted=${1//\'/\'\\\'\'}
printf "'%s'" "$quoted"
}
# Escape Str
#-----------------------------------------------------------------------------------------------------------------------------------
escape_str()
{
echo "$*" | sed -e "s/\"/\\\\\"/g"
}
# Line Echo
#-----------------------------------------------------------------------------------------------------------------------------------
line_echo()
{
string="$1"
count="$2"
echo -en "\e[2K\r"
if [[ "${count}" != "" ]]
then
printf "%05d: %s" "${count}"
echo -en "${string}"
fi
}
# Err Echo
#-----------------------------------------------------------------------------------------------------------------------------------
err_echo()
{
echo "$@" 1>&2
}
# Exec CMD
#-----------------------------------------------------------------------------------------------------------------------------------
exec_cmd()
{
cmd="$1"
if [[ "${verbose}" == "true" ]]
then
echo "${cmd}" 1>&2
fi
if [[ "${dry_run}" != "true" ]]
then
eval "${cmd}"
fi
}
#--------------------------------------------------------------------------------------------------------------------------
# tab_assign
#--------------------------------------------------------------------------------------------------------------------------
tab_assign()
{
declare -n ta_tab=$1
ta_key=$2
ta_value=$3
if [[ "${ta_value}" == "-" ]]
then
ta_value=""
fi
ta_tab[${ta_key}]="${ta_value}"
}
#--------------------------------------------------------------------------------------------------------------------------
# var_assign
#--------------------------------------------------------------------------------------------------------------------------
var_assign()
{
declare -n va_var=$1
va_value=$2
va_mode=$3
if [[ "${va_value}" == "-" ]]
then
va_value=""
fi
if [[ "${va_mode}" == "INC" ]]
then
va_var="${va_var} ${va_value}"
else
va_var="${va_value}"
fi
}
#--------------------------------------------------------------------------------------------------------------------------
# file_lock
#--------------------------------------------------------------------------------------------------------------------------
file_lock()
{
fl_file="$1"
fl_mode="$2"
fl_desc="$3"
if [[ ( "${fl_mode}" == "EXCLUSIVE" ) || ( "${fl_mode}" == "WRITE" ) ]]
then
fl_flag="-x"
else
fl_flag="-s"
fi
if [[ "${fl_desc}" == "" ]]
then
fl_desc="9"
fi
eval "exec ${fl_desc}<>\"\${fl_file}\""
if ! flock ${fl_flag} -w 5 ${fl_desc}
then
err_echo "Failed to acquire read lock on: [${file}]"
exit 1
fi
}
#--------------------------------------------------------------------------------------------------------------------------
# file_unlock
#--------------------------------------------------------------------------------------------------------------------------
file_unlock()
{
fu_desc="$1"
if [[ "${fu_desc}" == "" ]]
then
fu_desc="9"
fi
eval "exec ${fl_desc}<&-"
eval "exec ${fl_desc}>&-"
}