From 55fd5c94b15cd3810c3b3b5d2d3cd47820715a11 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 11 Jul 2022 14:09:11 +0200 Subject: [PATCH] Finishing scripts/update-cobbler-distros --- scripts/functions.rc | 27 +++++++++++++++++-- scripts/update-cobbler-distros | 49 +++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/scripts/functions.rc b/scripts/functions.rc index c34613e..9fbbf1d 100644 --- a/scripts/functions.rc +++ b/scripts/functions.rc @@ -8,7 +8,7 @@ BLUE="" CYAN="" NORMAL="" -VERSION="0.2.1" +VERSION="0.2.2" # shellcheck disable=SC2034 STD_SHORT_OPTIONS="sqdvhV" @@ -281,11 +281,17 @@ debug() { if [[ "${VERBOSE}" != "y" ]] ; then return 0 fi + if [[ -n "${LOGFILE}" ]] ; then + echo -e "[$(my_date)] [${BASE_NAME}:${CYAN}DEBUG${NORMAL}]: $@" >>"${LOGFILE}" + fi echo -e " * [$(my_date)] [${BASE_NAME}:${CYAN}DEBUG${NORMAL}]: $*" >&2 } #------------------------------------------------------------------------------ info() { + if [[ -n "${LOGFILE}" ]] ; then + echo -e "[$(my_date)] [${BASE_NAME}:${GREEN}DEBUG${NORMAL}]: $@" >>"${LOGFILE}" + fi if [[ "${QUIET}" != "y" ]] ; then echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $*" >&2 fi @@ -293,11 +299,17 @@ info() { #------------------------------------------------------------------------------ warn() { + if [[ -n "${LOGFILE}" ]] ; then + echo -e "[$(my_date)] [${BASE_NAME}:${YELLOW}DEBUG${NORMAL}]: $@" >>"${LOGFILE}" + fi echo -e " ${YELLOW}*${NORMAL} [$(my_date)] [${BASE_NAME}:${YELLOW}WARN${NORMAL}] : $*" >&2 } #------------------------------------------------------------------------------ error() { + if [[ -n "${LOGFILE}" ]] ; then + echo -e "[$(my_date)] [${BASE_NAME}:${RED}DEBUG${NORMAL}]: $@" >>"${LOGFILE}" + fi echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASE_NAME}:${RED}ERROR${NORMAL}]: $*" >&2 } @@ -341,6 +353,17 @@ MKDIR() { eval ${cmd} } +#------------------------------------------------------------------------------ +MKDIR_forced() { + + local cmd="mkdir $*" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd="mkdir --verbose $*" + fi + debug "Executing: ${cmd}" + eval ${cmd} +} + #------------------------------------------------------------------------------ CHOWN() { @@ -397,7 +420,7 @@ dline() { empty_line() { if [[ -n "${LOGFILE}" ]] ; then - echo >>"${LOGFILE}" + echo >> "${LOGFILE}" fi if [[ "${QUIET}" == "y" ]] ; then diff --git a/scripts/update-cobbler-distros b/scripts/update-cobbler-distros index d23317a..f4c3b60 100755 --- a/scripts/update-cobbler-distros +++ b/scripts/update-cobbler-distros @@ -20,11 +20,12 @@ fi detect_color IMAGE_ROOT="/var/www/cobbler/distro_mirror" +LOG_DIR="/var/log/update-cobbler-distros" DIR_OWNER="apache" DIR_GROUP="apache" -declare -a DISTRO_IDS=( 'almalinux-8' 'centos-stream-8' 'centos-stream-9' ) +declare -a DISTRO_IDS=( 'almalinux-8' 'almalinux-9' 'centos-stream-8' 'centos-stream-9' 'rocky-8' ) declare -a DISTRO_ID_UPDATE=() declare -A SOURCE=() @@ -33,12 +34,18 @@ declare -A TARGET=() SOURCE['almalinux-8']="rsync://ftp.fau.de/almalinux/8/BaseOS/x86_64/os/" TARGET['almalinux-8']="AlmaLinux-8" +SOURCE['almalinux-9']="rsync://ftp.fau.de/almalinux/9/BaseOS/x86_64/os/" +TARGET['almalinux-9']="AlmaLinux-9" + SOURCE['centos-stream-8']="rsync://ftp.fau.de/centos/8-stream/BaseOS/x86_64/os/" TARGET['centos-stream-8']="CentOS-Stream-8" SOURCE['centos-stream-9']="rsync://mirror1.hs-esslingen.de/centos-stream/9-stream/BaseOS/x86_64/os/" TARGET['centos-stream-9']="CentOS-Stream-9" +SOURCE['rocky-8']="rsync://ftp.fau.de/rockylinux/8/BaseOS/x86_64/os/" +TARGET['rocky-8']="Rocky-8" + DESCRIPTION=$( cat <<-EOF Updates the boot environments of cobbler boot environments. @@ -143,6 +150,38 @@ get_options() { } +#------------------------------------------------------------------------------ +check_preferences() { + + info "Checking preferences ..." + local all_ok="y" + + check_for_root + + local -a tools=('rsync') + local tool= + + for tool in "${tools[@]}" ; do + debug "Checking for '${CYAN}${tool}${NORMAL}' ..." + if type -p ${tool} >/dev/null ; then + : + else + all_ok="n" + error "Did not found '${RED}${tool}${NORMAL}'. Maybe not installed?" + fi + done + + if [[ "${all_ok}" != "y" ]] ; then + exit 5 + fi + + if [[ ! -d "${LOG_DIR}" ]] ; then + info "Creating '${GREEN}${LOG_DIR}${NORMAL}' ..." + MKDIR_forced "${LOG_DIR}" + fi + +} + #------------------------------------------------------------------------------ update_distro() { @@ -183,6 +222,7 @@ update_distro() { # info "Chowning '${CYAN}${target_dir}${NORMAL}' to '${CYAN}${DIR_OWNER}:${DIR_GROUP}${CYAN}' ..." # CHOWN --recursive "${DIR_OWNER}:${DIR_GROUP}" "${target_dir}" + info "Finished '${CYAN}${src_url}${NORMAL}'." return 0 @@ -196,13 +236,20 @@ main() { get_options "$@" + check_preferences + for distro_id in "${DISTRO_ID_UPDATE[@]}" ; do + LOGFILE="${LOG_DIR}/${distro_id}.log" empty_line line info "Updating Cobbler distribution '${GREEN}${distro_id}${NORMAL}' ..." update_distro "${distro_id}" done + LOGFILE= + empty_line + info "Finished all." + } main "$@" -- 2.39.5