From bcc5aad8b991860b45d84f0b144ecc4a60d2e546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Bertin?= Date: Wed, 27 Nov 2024 14:55:48 +0100 Subject: [PATCH] feat(upgrade-pkg): Upgrade all packages when given the extra parameter 'all' --- usr/local/share/vulture-utils/common.sh | 6 +++--- usr/local/share/vulture-utils/restore.sh | 2 +- usr/local/share/vulture-utils/snapshot.sh | 2 +- usr/local/share/vulture-utils/upgrade-pkg.sh | 10 +++++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/usr/local/share/vulture-utils/common.sh b/usr/local/share/vulture-utils/common.sh index 78d972e..516e749 100644 --- a/usr/local/share/vulture-utils/common.sh +++ b/usr/local/share/vulture-utils/common.sh @@ -107,11 +107,11 @@ sublist() { return $((_index_stop - _index_start + 1)) } -contains() { +contains_word() { _list="$1" - _elem_in_list="$2" + _word_in_list="$2" - if echo "${_list}" | grep -q "${_elem_in_list}"; then + if echo "${_list}" | grep -qw "${_word_in_list}"; then return 0 else return 1 diff --git a/usr/local/share/vulture-utils/restore.sh b/usr/local/share/vulture-utils/restore.sh index d6c6bba..65f63c3 100755 --- a/usr/local/share/vulture-utils/restore.sh +++ b/usr/local/share/vulture-utils/restore.sh @@ -140,7 +140,7 @@ for _type in ${AVAILABLE_DATASET_TYPES}; do fi # Ignore datasets not explicitely selected from here - if ! contains "${_rollback_datasets_list}" "${_type}"; then + if ! contains_word "${_rollback_datasets_list}" "${_type}"; then continue fi diff --git a/usr/local/share/vulture-utils/snapshot.sh b/usr/local/share/vulture-utils/snapshot.sh index b0c353e..c7ba333 100755 --- a/usr/local/share/vulture-utils/snapshot.sh +++ b/usr/local/share/vulture-utils/snapshot.sh @@ -120,7 +120,7 @@ for _type in ${AVAILABLE_DATASET_TYPES}; do # snapshotting datasets else # Ignore datasets not explicitely selected - if ! contains "${_snapshot_datasets_list}" "${_type}"; then + if ! contains_word "${_snapshot_datasets_list}" "${_type}"; then continue fi if [ "${_type}" = "DB" ] && [ "${_mongo_locked}" -eq 0 ]; then diff --git a/usr/local/share/vulture-utils/upgrade-pkg.sh b/usr/local/share/vulture-utils/upgrade-pkg.sh index 0f646e7..d03394b 100755 --- a/usr/local/share/vulture-utils/upgrade-pkg.sh +++ b/usr/local/share/vulture-utils/upgrade-pkg.sh @@ -207,6 +207,10 @@ while [ $# -gt 0 ]; do esac done +if contains_word "$targets" "all"; then + targets="" +fi + if [ $clean_cache -gt 0 ] && [ $download_only -gt 0 ]; then error_and_exit "[!] Cannot activate -c if -D or -T are set" fi @@ -231,7 +235,7 @@ fi # If no argument or jail asked for jail in "haproxy" "redis" "mongodb" "rsyslog" ; do - if [ -z "${targets}" ] || contains "$targets" "$jail" ; then + if [ -z "${targets}" ] || contains_word "$targets" "$jail" ; then /bin/echo "[+] Updating jail $jail packages..." IGNORE_OSVERSION="yes" /usr/sbin/pkg -j "$jail" update -f || finalize 1 "Could not update list of packages for jail ${jail}" @@ -284,7 +288,7 @@ for jail in "haproxy" "redis" "mongodb" "rsyslog" ; do done # No parameter, or gui -if [ -z "${targets}" ] || contains "${targets}" "gui" ; then +if [ -z "${targets}" ] || contains_word "${targets}" "gui" ; then echo "[+] Updating GUI..." _gui_was_up=1 /usr/sbin/jexec apache /usr/sbin/service gunicorn stop @@ -321,7 +325,7 @@ if [ -z "${targets}" ] || contains "${targets}" "gui" ; then echo "[-] GUI updated." fi -if [ -z "${targets}" ] || contains "${targets}" "base" ; then +if [ -z "${targets}" ] || contains_word "${targets}" "base" ; then echo "[+] Updating vulture-base ..." # shellcheck disable=SC2086 IGNORE_OSVERSION="yes" /usr/sbin/pkg upgrade ${_pkg_options} -y vulture-base || finalize 1 "Failed to upgrade vulture-base"