- Initial release: bash profile config & default library included.

This commit is contained in:
2026-03-17 12:25:59 +01:00
commit 97c05c4606
10 changed files with 1920 additions and 0 deletions

404
usr/lib/rx3/default.bash Normal file
View File

@@ -0,0 +1,404 @@
#!/bin/bash
if [[ "${DEFAULT_BASH}" != "" ]]
then
return
else
declare -g DEFAULT_BASH=1
fi
# Global Variable
#-----------------------------------------------------------------------------------------------------------------------------------
declare -g LOG_FILE=""
declare -g LOG_LOCK=""
declare -g LOG_ECHO=""
declare -g LOG_TRACE="DISABLED"
# 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_dir_init
#--------------------------------------------------------------------------------------------------------------------------
file_dir_init()
{
local File="$1"
local Owner="$2"
local Group="$3"
local dir
if [ ! -f ${File} ]
then
if [[ "$( id -u)" != "0" ]]
then
${ECHO} "Can't perform file init of: [${File}] as non root user!"
else
dir="$( dirname ${File})"
if [ ! -d ${dir} ]
then
${ECHO} "Initializing directory: [${dir}]"
mkdir ${dir}
chmod ug+rwx ${dir}
chown ${Owner}:${Group} ${dir}
fi
${ECHO} "Initializing file: [${File}]"
>${File}
chmod ug+rw ${File}
chown ${Owner}:${Group} ${File}
fi
fi
}
#--------------------------------------------------------------------------------------------------------------------------
# file_lock
#--------------------------------------------------------------------------------------------------------------------------
file_lock()
{
local file="$1"
local mode="$2"
local desc="$3"
if [[ ( "${mode}" == "EXCLUSIVE" ) || ( "${mode}" == "WRITE" ) ]]
then
flag="-x"
else
flag="-s"
fi
if [[ "${desc}" == "" ]]
then
desc="9"
fi
eval "exec ${desc}<>\"\${file}\""
if ! flock ${flag} -w 5 ${desc}
then
err_echo "Failed to acquire [${mode}] lock on: [${file}]"
exit 1
fi
}
#--------------------------------------------------------------------------------------------------------------------------
# file_unlock
#--------------------------------------------------------------------------------------------------------------------------
file_unlock()
{
local desc="$1"
if [[ "${desc}" == "" ]]
then
desc="9"
fi
eval "exec ${desc}<&-"
eval "exec ${desc}>&-"
}
#--------------------------------------------------------------------------------------------------------------------------
# log_set
#--------------------------------------------------------------------------------------------------------------------------
log_set()
{
local log_file="$1"
local lock_file="$2"
local echo_function="$3"
local log_trace="$4"
LOG_FILE="${log_file}"
LOG_LOCK="${lock_file}"
LOG_ECHO="${echo_function}"
if [[ ${log_trace} != "" ]]
then
LOG_TRACE="${log_trace}"
fi
}
#--------------------------------------------------------------------------------------------------------------------------
# log_print
#--------------------------------------------------------------------------------------------------------------------------
log_print()
{
local log_file="$1"
local lock_file="$2"
local echo_function="$3"
local log_type="$4"
local log_prefix="$5"
shift; shift; shift; shift; shift
if [[ "${log_type}" != "TRA" ]] || [[ "${LOG_TRACE}" != "DISABLED" ]]
then
${echo_function} "($BASHPID):" "$*"
if [[ "${log_file}" != "" ]]
then
if [[ "${lock_file}" != "" ]]
then
file_lock "${lock_file}" WRITE 8
fi
printf >> "${log_file}" "%s %9s %3s %16s %s\n" "$(date --rfc-3339=seconds -u)" "($BASHPID)" "${log_type}" "${log_prefix}:" "$*"
if [[ "${lock_file}" != "" ]]
then
file_unlock 8
fi
fi
fi
}
#--------------------------------------------------------------------------------------------------------------------------
# log_trace
#--------------------------------------------------------------------------------------------------------------------------
log_trace()
{
log_print "${LOG_FILE}" "${LOG_LOCK}" "${LOG_ECHO}" "TRA" "$@"
}
#--------------------------------------------------------------------------------------------------------------------------
# log_info
#--------------------------------------------------------------------------------------------------------------------------
log_info()
{
log_print "${LOG_FILE}" "${LOG_LOCK}" "${LOG_ECHO}" "INF" "$@"
}
#--------------------------------------------------------------------------------------------------------------------------
# log_warning
#--------------------------------------------------------------------------------------------------------------------------
log_warning()
{
log_print "${LOG_FILE}" "${LOG_LOCK}" "${LOG_ECHO}" "WRN" "$@"
}
#--------------------------------------------------------------------------------------------------------------------------
# log_error
#--------------------------------------------------------------------------------------------------------------------------
log_error()
{
log_print "${LOG_FILE}" "${LOG_LOCK}" "${LOG_ECHO}" "ERR" "$@"
}

163
usr/lib/rx3/isl.bash Normal file
View File

@@ -0,0 +1,163 @@
#-----------------------------------------------------------------------------------------------------------------------------------
# ISL: Image Stack Log
#-----------------------------------------------------------------------------------------------------------------------------------
# Global Variable
#-----------------------------------------------------------------------------------------------------------------------------------
export ISL_FILE=/etc/img_stack_log
# ISL Add
#-----------------------------------------------------------------------------------------------------------------------------------
isl_add()
{
url="$1"
reg=${url%%/*}
if [[ "${reg}" == *.* ]]
then
url=${url#*/}
else
reg="-"
fi
tag=${url/*:}
name=${url%:*}
if [[ "${tag}" == "${name}" ]]
then
echo "Bad tag format in URL!"
return 1
fi
ts=$(date -u +"%Y/%m/%d %H:%M:%S")
if [[ ! -e ${ISL_FILE} ]]
then
id=1
else
id=$(( $(wc -l <${ISL_FILE}) + 1))
fi
str="${id} ${ts} ${reg} ${name} ${tag}"
if [[ $id == "1" ]]
then
echo "${str}" >${ISL_FILE}
else
sed -i '1i\'"${str}" ${ISL_FILE}
fi
}
export -f isl_add
# ISL Top
#-----------------------------------------------------------------------------------------------------------------------------------
isl_top()
{
line=$( head -1 ${ISL_FILE})
if [[ "$1" == "-i" ]]
then
set ${line}
echo "$5:$6"
else
echo "${line}"
fi
}
export -f isl_top
# ISL Cat
#-----------------------------------------------------------------------------------------------------------------------------------
isl_cat()
{
if [[ "$1" == "-r" ]]
then
tac ${ISL_FILE}
else
cat ${ISL_FILE}
fi
}
export -f isl_cat
# ISL HTML Dump
#-----------------------------------------------------------------------------------------------------------------------------------
isl_html_dump()
{
r_flag=""
i_flag=""
while [[ $# -gt 0 ]]
do
if [[ "$1" == "-r" ]]
then
r_flag="$1"
else
if [[ "$1" == "-i" ]]
then
i_flag="-i"
fi
fi
shift
done
i=1
isl_cat "${r_flag}" | while read line
do
set $line
if [[ $(( $i % 2)) -eq 0 ]]
then
print "${i_flag}" ' <tr class="shade">'
else
print "${i_flag}" " <tr>"
fi
j=1
while [[ $j -lt 7 ]]
do
if [[ "$j" == "1" ]]
then
print "${i_flag}" " <th>${!j}</th>"
else
print "${i_flag}" " <td>${!j}</td>"
fi
j=$(( $j + 1))
done
print "${i_flag}" " </tr>"
i=$(( $i + 1))
done
}
export -f isl_html_dump