From b3d05390d15ca3d351fa53d95aeada7cbaecad0b Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Sat, 28 Mar 2026 17:54:27 +0100 Subject: [PATCH] - Default library: - Normalize some function names: version_print(), help_print(), str_quote(), str_escape(), echo_line(), echo_error() & cmd_exec() - Normalise some global variables: VERBOSE & DRY_RUN, - Add default options: errexit, pipefail & nounset, - Add GPL headers, - ISL: - Move ISL to docker_tools. --- ReleaseNotes.txt | 14 ++++ SPECS/rx3-base.spec | 30 ++++++- etc/profile.d/rx3.sh | 49 ++++++------ usr/lib/rx3/default.bash | 139 +++++++++++++++++++++------------ usr/lib/rx3/isl.bash | 163 --------------------------------------- 5 files changed, 160 insertions(+), 235 deletions(-) delete mode 100644 usr/lib/rx3/isl.bash diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index d1f8c19..b806347 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,3 +1,17 @@ +------------------------------------------------------------------------------------------------------------------------------------ +Rx3-Base V 1.1.0 - A. GIBERT - 2026/03/28 +------------------------------------------------------------------------------------------------------------------------------------ + +- Default library: + - Normalize some function names: version_print(), help_print(), str_quote(), str_escape(), echo_line(), echo_error() & cmd_exec() + - Normalise some global variables: VERBOSE & DRY_RUN, + - Add default options: errexit, pipefail & nounset, + - Add GPL headers, +- ISL: + - Move ISL to docker_tools. + + + ------------------------------------------------------------------------------------------------------------------------------------ Rx3-Base V 1.0.0 - A. GIBERT - 2026/03/17 ------------------------------------------------------------------------------------------------------------------------------------ diff --git a/SPECS/rx3-base.spec b/SPECS/rx3-base.spec index e2b0fbe..fca418f 100644 --- a/SPECS/rx3-base.spec +++ b/SPECS/rx3-base.spec @@ -1,6 +1,31 @@ +#----------------------------------------------------------------------------------------------------------------------------------- +# +# Rx3 Base +# +# Copyright (C) 2026 Arnaud G. GIBERT +# mailto:arnaud@rx3.net +# +# This is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; If not, see +# . +# +#----------------------------------------------------------------------------------------------------------------------------------- + + + %define name rx3-base -%define version 1.0.0 +%define version 1.1.0 %define release %mkrel 1rx3 @@ -98,5 +123,8 @@ cp usr/lib/rx3/*.bash %{buildroot}%{_prefix}/lib/rx3 #----------------------------------------------------------------------------------------------------------------------------------- %changelog +* Sat Mar 28 2026 Arnaud G. GIBERT - 1.1.0-1rx3.mga9 +- Update to 1.1.0 + * Tue Mar 17 2026 Arnaud G. GIBERT - 1.0.0-1rx3.mga9 - Initial release diff --git a/etc/profile.d/rx3.sh b/etc/profile.d/rx3.sh index 0d7947d..48ad496 100644 --- a/etc/profile.d/rx3.sh +++ b/etc/profile.d/rx3.sh @@ -1,5 +1,29 @@ +#!/bin/bash +#----------------------------------------------------------------------------------------------------------------------------------- +# +# Rx3 Base Profile +# +# Copyright (C) 2000-2026 Arnaud G. GIBERT +# mailto:arnaud@rx3.net +# +# This is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; If not, see +# . +# +#----------------------------------------------------------------------------------------------------------------------------------- +#----------------------------------------------------------------------------------------------------------------------------------- # Global Variable #----------------------------------------------------------------------------------------------------------------------------------- @@ -11,6 +35,7 @@ export EDITOR=emacs +#----------------------------------------------------------------------------------------------------------------------------------- # CatVal #----------------------------------------------------------------------------------------------------------------------------------- @@ -29,29 +54,7 @@ export -f cateval -# Print #----------------------------------------------------------------------------------------------------------------------------------- - -print() -{ - if [[ "$1" == "-i" ]] - then - shift - - str="%s"'\\n' - else - str="%s"'\n' - fi - - printf "${str}" "$*" -} - -export -f print - - - - - # File Enable #----------------------------------------------------------------------------------------------------------------------------------- @@ -81,6 +84,7 @@ export -f file_enable +#----------------------------------------------------------------------------------------------------------------------------------- # Include #----------------------------------------------------------------------------------------------------------------------------------- @@ -90,6 +94,7 @@ export -f file_enable +#----------------------------------------------------------------------------------------------------------------------------------- # Aliases #----------------------------------------------------------------------------------------------------------------------------------- diff --git a/usr/lib/rx3/default.bash b/usr/lib/rx3/default.bash index 33fdb22..756b044 100644 --- a/usr/lib/rx3/default.bash +++ b/usr/lib/rx3/default.bash @@ -1,4 +1,26 @@ #!/bin/bash +#----------------------------------------------------------------------------------------------------------------------------------- +# +# Default Library +# +# Copyright (C) 2017-2026 Arnaud G. GIBERT +# mailto:arnaud@rx3.net +# +# This is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; If not, see +# . +# +#----------------------------------------------------------------------------------------------------------------------------------- if [[ "${DEFAULT_BASH}" != "" ]] then @@ -9,69 +31,84 @@ fi -# Global Variable #----------------------------------------------------------------------------------------------------------------------------------- - -declare -g LOG_FILE="" -declare -g LOG_LOCK="" -declare -g LOG_ECHO="" -declare -g LOG_TRACE="DISABLED" - - - - - # Default Options #----------------------------------------------------------------------------------------------------------------------------------- +set -o errexit -o pipefail -o nounset shopt -s extglob -# Print Version +#----------------------------------------------------------------------------------------------------------------------------------- +# Global Variable +#----------------------------------------------------------------------------------------------------------------------------------- + +declare -g VERSION="" +declare -g NAME="" +declare -g HELP="" +declare -g VERBOSE="FALSE" +declare -g DRY_RUN="FALSE" + +declare -g LOG_FILE="" +declare -g LOG_LOCK="" +declare -g LOG_ECHO="" +declare -g LOG_TRACE="DISABLED" + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# Version Print #----------------------------------------------------------------------------------------------------------------------------------- version_print() { - echo "$VERSION" | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//' +# echo "${VERSION}" | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//' + echo "${NAME} ${VERSION}" } -# Prin Help +#----------------------------------------------------------------------------------------------------------------------------------- +# Help Print #----------------------------------------------------------------------------------------------------------------------------------- help_print() { echo "${NAME} ${HELP}" - } -# Quote Str +#----------------------------------------------------------------------------------------------------------------------------------- +# Str Quote #----------------------------------------------------------------------------------------------------------------------------------- -quote_str() +str_quote() { local quoted=${1//\'/\'\\\'\'} - printf "'%s'" "$quoted" + + + printf "'%s'" "${quoted}" } -# Escape Str +#----------------------------------------------------------------------------------------------------------------------------------- +# Str Escape #----------------------------------------------------------------------------------------------------------------------------------- -escape_str() +str_escape() { echo "$*" | sed -e "s/\"/\\\\\"/g" } @@ -80,14 +117,16 @@ escape_str() -# Line Echo +#----------------------------------------------------------------------------------------------------------------------------------- +# Echo Line #----------------------------------------------------------------------------------------------------------------------------------- -line_echo() +echo_line() { - string="$1" - count="$2" + local string="$1" + local count="$2" + echo -en "\e[2K\r" if [[ "${count}" != "" ]] @@ -101,10 +140,11 @@ line_echo() -# Err Echo +#----------------------------------------------------------------------------------------------------------------------------------- +# Echo Error #----------------------------------------------------------------------------------------------------------------------------------- -err_echo() +echo_error() { echo "$@" 1>&2 } @@ -113,20 +153,21 @@ err_echo() -# Exec CMD +#----------------------------------------------------------------------------------------------------------------------------------- +# Cmd Exec #----------------------------------------------------------------------------------------------------------------------------------- -exec_cmd() +cmd_exec() { - cmd="$1" + local cmd="$1" - if [[ "${verbose}" == "true" ]] + if [[ "${VERBOSE}" == "TRUE" ]] then echo "${cmd}" 1>&2 fi - if [[ "${dry_run}" != "true" ]] + if [[ "${DRY_RUN}" != "TRUE" ]] then eval "${cmd}" fi @@ -136,7 +177,7 @@ exec_cmd() #-------------------------------------------------------------------------------------------------------------------------- -# tab_assign +# Tab Assign #-------------------------------------------------------------------------------------------------------------------------- tab_assign() @@ -159,7 +200,7 @@ tab_assign() #-------------------------------------------------------------------------------------------------------------------------- -# var_assign +# Var Assign #-------------------------------------------------------------------------------------------------------------------------- var_assign() @@ -187,7 +228,7 @@ var_assign() #-------------------------------------------------------------------------------------------------------------------------- -# file_dir_init +# File Dir Init #-------------------------------------------------------------------------------------------------------------------------- file_dir_init() @@ -230,7 +271,7 @@ file_dir_init() #-------------------------------------------------------------------------------------------------------------------------- -# file_lock +# File Lock #-------------------------------------------------------------------------------------------------------------------------- file_lock() @@ -267,7 +308,7 @@ file_lock() #-------------------------------------------------------------------------------------------------------------------------- -# file_unlock +# File Unlock #-------------------------------------------------------------------------------------------------------------------------- file_unlock() @@ -290,7 +331,7 @@ file_unlock() #-------------------------------------------------------------------------------------------------------------------------- -# log_set +# Log Set #-------------------------------------------------------------------------------------------------------------------------- log_set() @@ -301,14 +342,14 @@ log_set() local log_trace="$4" - LOG_FILE="${log_file}" - LOG_LOCK="${lock_file}" - LOG_ECHO="${echo_function}" + LOG_FILE="${log_file}" + LOG_LOCK="${lock_file}" + LOG_ECHO="${echo_function}" - if [[ ${log_trace} != "" ]] - then - LOG_TRACE="${log_trace}" - fi + if [[ ${log_trace} != "" ]] + then + LOG_TRACE="${log_trace}" + fi } @@ -316,7 +357,7 @@ log_set() #-------------------------------------------------------------------------------------------------------------------------- -# log_print +# Log Print #-------------------------------------------------------------------------------------------------------------------------- log_print() @@ -356,7 +397,7 @@ log_print() #-------------------------------------------------------------------------------------------------------------------------- -# log_trace +# Log Trace #-------------------------------------------------------------------------------------------------------------------------- log_trace() @@ -369,7 +410,7 @@ log_trace() #-------------------------------------------------------------------------------------------------------------------------- -# log_info +# Log Info #-------------------------------------------------------------------------------------------------------------------------- log_info() @@ -382,7 +423,7 @@ log_info() #-------------------------------------------------------------------------------------------------------------------------- -# log_warning +# Log Warning #-------------------------------------------------------------------------------------------------------------------------- log_warning() @@ -395,7 +436,7 @@ log_warning() #-------------------------------------------------------------------------------------------------------------------------- -# log_error +# Log Error #-------------------------------------------------------------------------------------------------------------------------- log_error() diff --git a/usr/lib/rx3/isl.bash b/usr/lib/rx3/isl.bash deleted file mode 100644 index 26b84af..0000000 --- a/usr/lib/rx3/isl.bash +++ /dev/null @@ -1,163 +0,0 @@ -#----------------------------------------------------------------------------------------------------------------------------------- -# 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}" ' ' - else - print "${i_flag}" " " - fi - - j=1 - while [[ $j -lt 7 ]] - do - if [[ "$j" == "1" ]] - then - print "${i_flag}" " ${!j}" - else - print "${i_flag}" " ${!j}" - fi - - j=$(( $j + 1)) - done - - print "${i_flag}" " " - i=$(( $i + 1)) - done -} - -export -f isl_html_dump