- Base library:

- Rename default.bash to base.bash,
    - Normalise 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 bash completion,
- URPMI-Setup:
    - Add urpmi-setup command.
This commit is contained in:
2026-03-28 17:54:27 +01:00
parent 97c05c4606
commit cc7eda3588
13 changed files with 1093 additions and 245 deletions

384
sbin/isl Executable file
View File

@@ -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
# <https://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
# 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 <URL>] | [-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}" ' <tr class="shade">'
else
isl_print "${inline}" " <tr>"
fi
j=1
while [[ $j -lt 7 ]]
do
if [[ "$j" == "1" ]]
then
isl_print "${inline}" " <th>${!j}</th>"
else
isl_print "${inline}" " <td>${!j}</td>"
fi
j=$(( $j + 1))
done
isl_print "${inline}" " </tr>"
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}

197
sbin/urpmi-setup Executable file
View File

@@ -0,0 +1,197 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# URPMI Setup
#
# 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
# <https://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
# Includes
#-----------------------------------------------------------------------------------------------------------------------------------
. /usr/lib/rx3/base.bash
#-----------------------------------------------------------------------------------------------------------------------------------
# Global Variables
#-----------------------------------------------------------------------------------------------------------------------------------
declare -g VERSION="1.0.0"
declare -g NAME="URPMI Setup"
declare -g HELP="usage: urpmi-setup [ [-d | --distrib <Distrib>] [-m | --mirror-mga <Mirror_List>] [-r | --mirror-rx3 <Mirror_List>] ] | [-h | --help] | [-V | --version] [-T | --test] [-u | --update] [-v | --verbose]"
declare -g DISTRIB_DEF="9"
declare -g MIRRORLIST_MGA_DEF='http://mirror.xor.rx3/mageia/distrib/${DISTRIB}/x86_64 https://mirror.rx3.net/mageia/distrib/${DISTRIB}/x86_64 ftp://ftp.proxad.net/mirrors/mageia.org/distrib/${DISTRIB}/x86_64 http://distrib-coffee.ipsl.jussieu.fr/pub/linux/Mageia/distrib/${DISTRIB}/x86_64'
declare -g MIRRORLIST_RX3_DEF='http://mirror.xor.rx3/rx3/distrib/${DISTRIB}/x86_64 https://mirror.rx3.net/rx3/distrib/${DISTRIB}/x86_64'
declare -g EXIT_CODE=0
declare -g MODE="DEFAULT"
declare -g DISTRIB=""
declare -g MIRRORLIST_MGA=""
declare -g MIRRORLIST_RX3=""
declare -g UPDATE="FALSE"
#-----------------------------------------------------------------------------------------------------------------------------------
# US Arg Parse
#-----------------------------------------------------------------------------------------------------------------------------------
function us_args_parse()
{
tmp_args=$(getopt -o d:hm:r:Tuv --long distrib:,help,mirror-mga:,mirror-rx3:,test,update,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
-d|--distrib) shift; DISTRIB="$1"; shift;;
-m|--mirror-mga) shift; MIRRORLIST_MGA="$1"; shift;;
-r|--mirror-rx3) shift; MIRRORLIST_RX3="$1"; shift;;
# Mode switches
-h|--help) MODE="HELP"; shift;;
-V|--version) MODE="VERSION"; shift;;
# Global options
-T|--test) DRY_RUN="TRUE"; shift;;
-u|--update) UPDATE="TRUE"; shift;;
-v|--verbose) VERBOSE="TRUE"; shift;;
#
--) shift; break;;
*) echo "args_parse internal error [$1] !"; exit 1;;
esac
done
if [[ ${DISTRIB} == "" ]]
then
DISTRIB=${DISTRIB_DEF}
fi
if [[ "${MIRRORLIST_MGA}" == "" ]]
then
eval MIRRORLIST_MGA=\"${MIRRORLIST_MGA_DEF}\"
fi
if [[ "${MIRRORLIST_RX3}" == "" ]]
then
eval MIRRORLIST_RX3=\"${MIRRORLIST_RX3_DEF}\"
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------
# US Version Print
#-----------------------------------------------------------------------------------------------------------------------------------
us_version_print()
{
version_print
}
#-----------------------------------------------------------------------------------------------------------------------------------
# US Help Print
#-----------------------------------------------------------------------------------------------------------------------------------
us_help_print()
{
version_print
help_print
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------------------------------------------------------------------
orig_args=("$@")
us_args_parse "$@"
case "${MODE}" in
"EXIT")
exit ${EXIT_CODE}
;;
"HELP")
us_help_print
exit ${EXIT_CODE}
;;
"VERSION")
us_version_print
exit ${EXIT_CODE}
;;
esac
echo_error "${NAME}: Mode: [${MODE}] Verbose: [${VERBOSE}] Dry_Run: [${DRY_RUN}] Distrib: [${DISTRIB}] MirrorList_MGA: [${MIRRORLIST_MGA}] MirrorList_RX3: [${MIRRORLIST_RX3}] Update: [${UPDATE}]"
cmd_exec 'urpmi.removemedia -a'
cmd_exec 'rm -f /var/cache/urpmi/mirrors.cache'
cmd_exec 'urpmi.addmedia --distrib --mirrorlist "'"${MIRRORLIST_MGA}"'"'
cmd_exec 'urpmi.addmedia --distrib --mirrorlist "'"${MIRRORLIST_RX3}"'"'
for arch in "" "32bit "
do
for media in "Core" "Nonfree" "Tainted"
do
for type in "Release" "Updates"
do
cmd_exec 'urpmi.update --no-ignore "'"${media}"' '"${arch}""${type}"'"'
done
done
done
cmd_exec 'urpmi.update -a'
if [[ "${UPDATE}" == "TRUE" ]]
then
cmd_exec 'urpmi --force --auto-update'
fi
exit ${EXIT_CODE}