Commit 7646592a authored by Claude's avatar Claude 🌴

Merge branch 'QA' into 'master'

QA

See merge request !8
parents 7bde2117 c85793fd
Pipeline #8537 passed with stage
in 5 seconds
......@@ -4,11 +4,11 @@
#
if [ "$( type -t echofatal )" != 'function' ] ; then
echo 'https://git.cclaude.rocks/bash-apis/bash-common-api is required: Function echofatal not found.' >&2
exit 1
exit 100
fi
if [ "$( type -t exit_if_variable_not_define_or_empty )" != 'function' ] ; then
echofatal 'https://git.cclaude.rocks/bash-apis/bash-common-api is required Function exit_if_variable_not_define_or_empty not found.' >&2
exit 1
exit 100
fi
function _get_package_manager_ {
......@@ -20,28 +20,26 @@ function _get_package_manager_ {
if [ -z "${pkg_manager}" ] ; then
echofatal 'Package manager not found.' >&2
exit 1
exit 100
fi
echo "${pkg_manager}"
}
function install_update {
local pkg_manager=
pkg_manager="$( _get_package_manager_ "$1" )"
if [ -z "${pkg_manager}" ] ; then
exit 1
exit 101
fi
"${pkg_manager}" update || exit 1
"${pkg_manager}" update || exit $?
}
function install_install_if_needed {
local pkg_manager=
pkg_manager="$( _get_package_manager_ "$1" )"
if [ -z "${pkg_manager}" ] ; then
exit 1
exit 101
fi
shift
......@@ -57,7 +55,7 @@ function install_install_if_needed {
fi
if ! command -v "${command_name}" >/dev/null ; then
"${pkg_manager}" install -y "${package_name}" || exit 1
"${pkg_manager}" install -y "${package_name}" || exit $?
fi
done
}
......@@ -80,7 +78,7 @@ function install_if_needed { # DEPRECATED
fi
if [ "${skip_update}" != 'skip_update' ] ; then
"${pkg_manager}" update || exit 1
"${pkg_manager}" update || exit $?
fi
local command_name=
......@@ -95,7 +93,7 @@ function install_if_needed { # DEPRECATED
fi
if ! command -v "${command_name}" >/dev/null ; then
"${pkg_manager}" install -y "${package_name}" || exit 1
"${pkg_manager}" install -y "${package_name}" || exit $?
fi
done
}
......@@ -103,21 +101,21 @@ function install_if_needed { # DEPRECATED
function install_set_chmod_for_list {
local -r mode="$1"
local -r files="$2"
local file=
local file=
while read -r file ; do
if [ -n "${file}" ] ; then
chmod -v "${mode}" "${INSTALL_DATA_DIR}/${file}" || exit 1
chmod -v "${mode}" "${INSTALL_DATA_DIR}/${file}" || exit $?
fi
done <<<"${files}"
}
function install_links {
local -r files="$1"
local file=
local realfile=
local linkfile=
local file=
local realfile=
local linkfile=
while read -r file ; do
if [ -n "${file}" ] ; then
realfile="${INSTALL_DATA_DIR}/bin/${file}.sh"
......@@ -125,7 +123,7 @@ function install_links {
if [ ! -f "${realfile}" ] ; then
echofatal "'${realfile}' not found." >&2
exit 1
exit 101
fi
if [ -L "${linkfile}" ] ; then
......@@ -133,27 +131,27 @@ function install_links {
rm -v "${linkfile}"
fi
fi
ln -sv "${realfile}" "${linkfile}" || exit 1
ln -sv "${realfile}" "${linkfile}" || exit $?
fi
done <<<"${files}"
}
function install_main {
mkdir -pv "${INSTALL_DATA_DIR}" || exit 1
mkdir -pv "${INSTALL_DATA_DIR}" || exit $?
rsync -av \
--exclude='package' \
--exclude='.git' \
--exclude='.gitignore' \
--exclude='.gitlab-ci.yml' \
--exclude='samples' \
"${PROJECT_HOME}/"* "${INSTALL_DATA_DIR}" || exit 1
chown -Rv root:root "${INSTALL_DATA_DIR}" || exit 1
"${PROJECT_HOME}/"* "${INSTALL_DATA_DIR}" || exit $?
chown -Rv root:root "${INSTALL_DATA_DIR}" || exit $?
find "${INSTALL_DATA_DIR}" -type f -exec chmod -v 444 {} \; || exit 1
find "${INSTALL_DATA_DIR}" -type d -exec chmod -v 755 {} \; || exit 1
find "${INSTALL_DATA_DIR}" -type f -exec chmod -v 444 {} \; || exit $?
find "${INSTALL_DATA_DIR}" -type d -exec chmod -v 755 {} \; || exit $?
install_set_chmod_for_list 555 "${INSTALL_EXE}"
install_links "${INSTALL_LINKS}"
install_set_chmod_for_list 555 "${INSTALL_EXE}" || return $?
install_links "${INSTALL_LINKS}" || return $?
echoinfo "$( realpath "$0" ) done." >&2
}
......@@ -161,7 +159,7 @@ function install_main {
function exit_if_not_root {
if [ "${EUID}" -ne 0 ] ; then
echo 'This script must be run as root.' >&2
exit 1
exit 100
fi
}
......@@ -187,10 +185,10 @@ function remove_previous_version_before_install {
function remove_links {
local -r files="$1"
local file=
local realfile=
local linkfile=
local file=
local realfile=
local linkfile=
while read -r file ; do
if [ -n "${file}" ] ; then
realfile="${INSTALL_DATA_DIR}/bin/${file}.sh"
......@@ -207,13 +205,13 @@ function remove_links {
function _remove_main_ {
local -r force_remove="${0:-false}"
local remove='false'
exit_if_not_root
local scriptpath=
scriptpath="$( realpath "$0" )" || return $?
local remove='false'
if [ "${force_remove}" = 'false' ] ; then
if [ "${REMOVE_EXE}" != "${scriptpath}" ] && [ -f "${REMOVE_EXE}" ] ; then
echoinfo "Using: '${REMOVE_EXE}' --force-remove"
......@@ -231,7 +229,7 @@ function _remove_main_ {
if [ "${remove}" = 'false' ] ; then
remove_links "${INSTALL_LINKS}"
rm -fvr "${INSTALL_DATA_DIR}" || exit 1
rm -fvr "${INSTALL_DATA_DIR}" || return $?
fi
echoinfo "${scriptpath} done." >&2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment