]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Finishing scripts/update-cobbler-distros
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 11 Jul 2022 12:09:11 +0000 (14:09 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 11 Jul 2022 12:09:11 +0000 (14:09 +0200)
scripts/functions.rc
scripts/update-cobbler-distros

index c34613e12952cbc512587ddea507cfb63125971f..9fbbf1ddf038c853253d8a5d869ba57f9597b8aa 100644 (file)
@@ -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
index d23317af8173db8ae6082f97d22eacc0333772b0..f4c3b60cc0472de51c36a7738b8a0da057b9ff8b 100755 (executable)
@@ -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 "$@"