]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Starting with scripts/update-cobbler-distros
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Jul 2022 13:22:38 +0000 (15:22 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Jul 2022 13:22:38 +0000 (15:22 +0200)
scripts/update-cobbler-distros [new file with mode: 0755]

diff --git a/scripts/update-cobbler-distros b/scripts/update-cobbler-distros
new file mode 100755 (executable)
index 0000000..3f5bf6c
--- /dev/null
@@ -0,0 +1,150 @@
+#!/bin/bash
+
+set -e
+set -u
+
+BASE_NAME="$( basename ${0} )"
+MY_REAL_NAME=$( readlink -f $0 )
+BIN_DIR=$( dirname "${MY_REAL_NAME}" )
+BASE_DIR=$( dirname "${BIN_DIR}" )
+LIB_DIR="${BASE_DIR}/lib"
+CONF_DIR="${BASE_DIR}/etc"
+
+if [[ -f "${BIN_DIR}/functions.rc" ]] ; then
+    . "${BIN_DIR}/functions.rc"
+else
+    echo "Bash resource file '${BIN_DIR}/functions.rc' not found" >&2
+    exit 5
+fi
+
+detect_color
+
+declare -a DISTRO_IDS=( 'almalinux-8' 'centos-stream-8' 'centos-stream-9' )
+declare -a DISTRO_ID_UPDATE=()
+
+DESCRIPTION=$( cat <<-EOF
+       Updates the boot environments of cobbler boot environments.
+
+       EOF
+)
+
+#------------------------------------------------------------------------------
+usage() {
+    cat <<-EOF
+       Usage: ${BASE_NAME} [Common Options] [<DISTRO_ID> [<DISTRO_ID> ...]]
+              ${BASE_NAME} [-h|--help]
+              ${BASE_NAME} [-V|--version]
+
+           Optional Parameter(s):
+               DISTRO_ID:  The ID of the Cobbler distribution, which boot environments
+                           should be updated.
+                           (Posix name, mostly in the form 'first_name.last_name'), or
+                           the E-Mail address of the account or group to search.
+
+                           Valid DISTRO_ID's are:
+       EOF
+
+    local distro_id=
+    for distro_id in "${DISTRO_IDS[@]}" ; do
+        echo "                     * '${distro_id}'"
+    done
+
+    echo
+    echo "    Common Options:"
+    echo "${STD_USAGE_MSG}"
+
+}
+
+#------------------------------------------------------------------------------
+get_options() {
+
+    local tmp=
+    local distro_id=
+    local id=
+    local ids_ok='y'=
+
+    set +e
+    tmp=$( getopt -o "${STD_SHORT_OPTIONS}" \
+                    --long "${STD_LONG_OPTIONS}" \
+                    -n "${BASE_NAME}" -- "$@" )
+    # shellcheck disable=SC2181
+    if [[ $? != 0 ]] ; then
+        echo "" >&2
+        usage >&2
+        exit 1
+    fi
+    set -e
+
+    # Note the quotes around `$TEMP': they are essential!
+    eval set -- "${tmp}"
+    eval_common_options "$@"
+    if [[ "${DEBUG}" == 'y' ]] ; then
+        declare -p REMAINING_OPTS
+        declare -p REMAINING_ARGS
+    fi
+
+    debug "Remaining arguments: ${CYAN}${#REMAINING_ARGS[@]}${NORMAL}"
+
+    if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then
+        error "Unknown options: ${REMAINING_OPTS[*]}"
+        echo >&2
+        usage >&2
+        exit 2
+    fi
+
+    if [[ "${#REMAINING_ARGS[@]}" == "0" ]] ; then
+        for distro_id in "${DISTRO_IDS[@]}" ; do
+            DISTRO_ID_UPDATE+=( "${distro_id}" )
+        done
+    else
+        local first="y"
+        for distro_id in "${REMAINING_ARGS[@]}" ; do
+            if [[ "${first}" == 'y' ]] ; then
+                first="n"
+                continue
+            fi
+            DISTRO_ID_UPDATE+=( "${distro_id}" )
+            local distro_found="n"
+            for id in "${DISTRO_IDS[@]}" ; do
+                if [[ "${id}" == "${distro_id}" ]] ; then
+                    distro_found="y"
+                    break
+                fi
+            done
+            if [[ "${distro_found}" == 'n' ]] ; then
+                warn "Wrong Distro-Id '${YELLOW}${distro_id}${NORMAL}' given."
+                ids_ok='n'
+            fi
+        done
+    fi
+
+    if [[ "${ids_ok}" == "n" ]] ; then
+        echo >&2
+        usage >&2
+        exit 1
+    fi
+
+}
+
+#------------------------------------------------------------------------------
+main() {
+
+    local distro_id=
+
+    get_options "$@"
+
+    for distro_id in "${DISTRO_ID_UPDATE[@]}" ; do
+        echo
+        info "Updating Cobbler distribution '${GREEN}${distro_id}${NORMAL}' ..."
+    done
+
+}
+
+main "$@"
+exit 0
+
+
+
+exit 0
+
+# vim: ts=4 et list