From 37432a6ac885fa5e6ade44f6845696eaa20deea0 Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Sun, 29 Mar 2026 12:18:34 +0200 Subject: [PATCH] - Base library: - Rename default.bash to base.bash, - 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 functions to isl command, - Add bsh completion. --- COPYING | 1 + COPYING.LESSER | 1 + GNU_LGPL-3.0.txt | 165 ++++++++++ ReadMe.txt | 12 +- ReleaseNotes.txt | 8 +- SPECS/rx3-base.spec | 18 +- etc/bash_completion.d/isl | 53 ++++ sbin/isl | 384 ++++++++++++++++++++++++ usr/lib/rx3/{default.bash => base.bash} | 0 9 files changed, 629 insertions(+), 13 deletions(-) create mode 120000 COPYING create mode 120000 COPYING.LESSER create mode 100644 GNU_LGPL-3.0.txt create mode 100644 etc/bash_completion.d/isl create mode 100755 sbin/isl rename usr/lib/rx3/{default.bash => base.bash} (100%) diff --git a/COPYING b/COPYING new file mode 120000 index 0000000..fe7151e --- /dev/null +++ b/COPYING @@ -0,0 +1 @@ +GNU_GPL-3.0.txt \ No newline at end of file diff --git a/COPYING.LESSER b/COPYING.LESSER new file mode 120000 index 0000000..a88d7bf --- /dev/null +++ b/COPYING.LESSER @@ -0,0 +1 @@ +GNU_LGPL-3.0.txt \ No newline at end of file diff --git a/GNU_LGPL-3.0.txt b/GNU_LGPL-3.0.txt new file mode 100644 index 0000000..0a04128 --- /dev/null +++ b/GNU_LGPL-3.0.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/ReadMe.txt b/ReadMe.txt index 95686f8..c0388c8 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -1,11 +1,7 @@ -Welcome to Rx3 Base 1.0.x ! +Welcome to Rx3 Base 1.1.x ! -Base is licensed under the GPL GNU Licenses. -For more information, please read the corresponding source file headers. -The license details can be found in the GNU-GPL.txt and GNU-FDL.txt files. - This is the base component of an Rx3 system: - Default config files, - Base bash libraries, @@ -13,6 +9,12 @@ This is the base component of an Rx3 system: +Base is licensed under the LGPL/GPL GNU Licenses. +For more information, please read the corresponding source file headers. +The license details can be found in the GNU-GPL.txt, GNU-LGPL.txt and GNU-FDL.txt files. + + + Enjoy it! Your Rx3 Team. diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index b806347..8ec01fc 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,14 +1,16 @@ ------------------------------------------------------------------------------------------------------------------------------------ -Rx3-Base V 1.1.0 - A. GIBERT - 2026/03/28 +Rx3-Base V 1.1.0 - A. GIBERT - 2026/03/29 ------------------------------------------------------------------------------------------------------------------------------------ -- Default library: +- Base library: + - Rename default.bash to base.bash, - 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. + - Move ISL functions to isl command, + - Add bsh completion. diff --git a/SPECS/rx3-base.spec b/SPECS/rx3-base.spec index fca418f..18dde91 100644 --- a/SPECS/rx3-base.spec +++ b/SPECS/rx3-base.spec @@ -94,11 +94,17 @@ This is the base component of an Rx3 system: # Config %{__mkdir_p} %{buildroot}%{_sysconfdir}/profile.d cp etc/profile.d/*.sh %{buildroot}%{_sysconfdir}/profile.d +%{__mkdir_p} %{buildroot}%{_sysconfdir}/bash_completion.d +cp etc/bash_completion.d/* %{buildroot}%{_sysconfdir}/bash_completion.d # Libs %{__mkdir_p} %{buildroot}%{_prefix}/lib/rx3 cp usr/lib/rx3/*.bash %{buildroot}%{_prefix}/lib/rx3 +# Bin +%{__mkdir_p} %{buildroot}%{_sbindir} +cp sbin/!(*~) %{buildroot}%{_sbindir} + @@ -108,11 +114,13 @@ cp usr/lib/rx3/*.bash %{buildroot}%{_prefix}/lib/rx3 #----------------------------------------------------------------------------------------------------------------------------------- %files -%doc ReadMe.txt ReleaseNotes.txt ToDo.txt -%license GNU_GPL-3.0.txt GNU_FDL-1.3.txt +%doc ReadMe.txt ReleaseNotes.txt ToDo.txt +%license GNU_GPL-3.0.txt GNU_FDL-1.3.txt %defattr(644,root,root) -%{_sysconfdir}/profile.d/* -%{_prefix}/lib/rx3/* + %{_sysconfdir}/profile.d/* + %{_sysconfdir}/bash_completion.d/* + %{_prefix}/lib/rx3/* +%attr(0755,root,root) %{_sbindir}/* @@ -123,7 +131,7 @@ cp usr/lib/rx3/*.bash %{buildroot}%{_prefix}/lib/rx3 #----------------------------------------------------------------------------------------------------------------------------------- %changelog -* Sat Mar 28 2026 Arnaud G. GIBERT - 1.1.0-1rx3.mga9 +* Sun Mar 29 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 diff --git a/etc/bash_completion.d/isl b/etc/bash_completion.d/isl new file mode 100644 index 0000000..a9f12ff --- /dev/null +++ b/etc/bash_completion.d/isl @@ -0,0 +1,53 @@ +#!/bin/bash +#!/bin/bash +#----------------------------------------------------------------------------------------------------------------------------------- +# +# ISL: Image Stack Log +# +# 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 +# . +# +#----------------------------------------------------------------------------------------------------------------------------------- +# -*- mode: shell; sh-basic-offset: 4; indent-tabs-mode: nil; -*- + +_isl() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="--help -h --version -V --test -T --verbose -v --add -a --cat -c --dump -d --top -t --reverse -r --inline -i --image -m" + + # Top-level options + case "${prev}" in + --add|-a) + COMPREPLY=( $(compgen -f -- "${cur}") ) # Complete with filenames/URLs + return 0 + ;; + --cat|-c|--dump|-d|--top|-t) + # These options don't take arguments + COMPREPLY=() + return 0 + ;; + *) + # Default completion: show all top-level options + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + esac +} + +complete -F _isl isl diff --git a/sbin/isl b/sbin/isl new file mode 100755 index 0000000..89dbb9c --- /dev/null +++ b/sbin/isl @@ -0,0 +1,384 @@ +#!/bin/bash +#----------------------------------------------------------------------------------------------------------------------------------- +# +# ISL: Image Stack Log +# +# 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 +# . +# +#----------------------------------------------------------------------------------------------------------------------------------- + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# Includes +#----------------------------------------------------------------------------------------------------------------------------------- + +. /usr/lib/rx3/base.bash + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# Global Variables +#----------------------------------------------------------------------------------------------------------------------------------- + +declare -g VERSION="1.1.0" +declare -g NAME="ISL" +declare -g HELP="usage: isl [-a | --add ] | [-c | --cat [-r | --reverse]] | [-d | --dump [-i | --inline] [-r | --reverse]] | [-t | --top [-m | --image]] | [[-h | --help] | [-V | --version] [-T | --test] [-v | --verbose]" + +declare -g ISL_FILE="/etc/img_stack_log" +declare -g EXIT_CODE=0 +declare -g MODE="DEFAULT" +declare -g IMAGE="FALSE" +declare -g INLINE="FALSE" +declare -g REVERSE="FALSE" +declare -g URL="" + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# ISL Arg Parse +#----------------------------------------------------------------------------------------------------------------------------------- + +function isl_args_parse() +{ + tmp_args=$(getopt -o a:cdhtVimrTv --long add:,cat,dump,help,top,version,image,inline,reverse,test,verbose -- "$@") + + if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi + + # Note the quotes around `$tmp_args': they are essential! + eval set -- "${tmp_args}" + + while true ; do + case "$1" in + + # Options + -i|--inline) INLINE="TRUE"; shift;; + -m|--image) IMAGE="TRUE"; shift;; + -r|--reverse) REVERSE="TRUE"; shift;; + + # Mode switches + -a|--add) MODE="ADD"; shift; URL="$1"; shift;; + -c|--cat) MODE="CAT"; shift;; + -d|--dump) MODE="DUMP"; shift;; + -h|--help) MODE="HELP"; shift;; + -t|--top) MODE="TOP"; shift;; + -V|--version) MODE="VERSION"; shift;; + + # Global options + -T|--test) DRY_RUN="TRUE"; shift;; + -v|--verbose) VERBOSE="TRUE"; shift;; + + # + --) shift; break;; + *) echo "args_parse internal error [$1] !"; exit 1;; + esac + done + + if [[ "${MODE}" == "DEFAULT" ]] + then + echo_error "A mode should be selected!" + MODE="HELP" + EXIT_CODE=1 + else + if [[ "${REVERSE}" == "TRUE" ]] + then + if [[ ( "${MODE}" != "CAT") && ( "${MODE}" != "DUMP") ]] + then + echo_error "Reverse option only valid in Cat or Dump mode!" + MODE="HELP" + EXIT_CODE=1 + fi + fi + + if [[ ( "${INLINE}" == "TRUE") && ( "${MODE}" != "DUMP") ]] + then + echo_error "Inline option only valid in Dump mode!" + MODE="HELP" + EXIT_CODE=1 + else + if [[ ( "${IMAGE}" == "TRUE") && ( "${MODE}" != "TOP") ]] + then + echo_error "Image option only valid in Top mode!" + MODE="HELP" + EXIT_CODE=1 + fi + fi + fi +} + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# ISL Version Print +#----------------------------------------------------------------------------------------------------------------------------------- + +isl_version_print() +{ + version_print +} + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# ISL Help Print +#----------------------------------------------------------------------------------------------------------------------------------- + +isl_help_print() +{ + version_print + help_print +} + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# ISL Print +#----------------------------------------------------------------------------------------------------------------------------------- + +isl_print() +{ + local inline="$1" + + + if [[ "${inline}" == "TRUE" ]] + then + shift + + str="%s"'\\n' + else + str="%s"'\n' + fi + + printf "${str}" "$*" +} + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# ISL Add +#----------------------------------------------------------------------------------------------------------------------------------- + +isl_add() +{ + local 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 +} + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# ISL Cat +#----------------------------------------------------------------------------------------------------------------------------------- + +isl_cat() +{ + local reverse="$1" + + + if [[ "${reverse}" == "TRUE" ]] + then + tac ${ISL_FILE} + else + cat ${ISL_FILE} + fi +} + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# ISL HTML Dump +#----------------------------------------------------------------------------------------------------------------------------------- + +isl_html_dump() +{ + local reverse="$1" + local inline="$2" + + local i=1 + local j=1 + + + i=1 + + isl_cat "${reverse}" | while read line + do + set $line + + if [[ $(( $i % 2)) -eq 0 ]] + then + isl_print "${inline}" ' ' + else + isl_print "${inline}" " " + fi + + j=1 + while [[ $j -lt 7 ]] + do + if [[ "$j" == "1" ]] + then + isl_print "${inline}" " ${!j}" + else + isl_print "${inline}" " ${!j}" + fi + + j=$(( $j + 1)) + done + + isl_print "${inline}" " " + i=$(( $i + 1)) + done +} + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# ISL Top +#----------------------------------------------------------------------------------------------------------------------------------- + +isl_top() +{ + local image="$1" + local line="" + + line=$( head -1 ${ISL_FILE}) + + if [[ "$?" != "0" ]] + then + return 1 + else + if [[ "${image}" == "TRUE" ]] + then + set ${line} + + echo "$5:$6" + else + echo "${line}" + fi + fi +} + + + + + +#----------------------------------------------------------------------------------------------------------------------------------- +# Main +#----------------------------------------------------------------------------------------------------------------------------------- + +orig_args=("$@") + +isl_args_parse "$@" + + +case "${MODE}" in + + "EXIT") + exit ${EXIT_CODE} + ;; + + "HELP") + isl_help_print + exit ${EXIT_CODE} + ;; + + "VERSION") + isl_version_print + exit ${EXIT_CODE} + ;; +esac + + + +echo_error "ISL: Mode: [${MODE}] Verbose: [${VERBOSE}] Dry_Run: [${DRY_RUN}] URL: [${URL}] Image: [${IMAGE}] Inline: [${INLINE}] Reverse: [${REVERSE}]" + + + +case "${MODE}" in + "ADD") + isl_add "${URL}" + ;; + + "CAT") + isl_cat "${REVERSE}" + ;; + + "DUMP") + isl_dump "${REVERSE}" "${INLINE}" + ;; + + "TOP") + isl_top "${IMAGE}" + ;; +esac + + +exit ${EXIT_CODE} diff --git a/usr/lib/rx3/default.bash b/usr/lib/rx3/base.bash similarity index 100% rename from usr/lib/rx3/default.bash rename to usr/lib/rx3/base.bash