VERSION="0.2.1"
# shellcheck disable=SC2034
-STD_SHORT_OPTIONS="sdvhV"
+STD_SHORT_OPTIONS="sqdvhV"
# shellcheck disable=SC2034
-STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version"
+STD_LONG_OPTIONS="simulate,quiet,debug,verbose,nocolor,help,version"
# shellcheck disable=SC2034
STD_USAGE_MSG=$( cat <<-EOF
-s|--simulate Simulation mode - dont apply any changes.
-d|--debug Debug output (bash -x).
- -v|--verbose Set verbosity on.
+ -q|--quiet Quiet execution (e.g. as a cronjob). Mutually exclusive to --verbose.
+ -v|--verbose Set verbosity on. Mutually exclusive to --quiet.
--nocolor Dont use colors on display.
-h|--help Show this output and exit.
-V|--version prints out version number of the script and exit
# Standard global variables
VERBOSE="n"
DEBUG="n"
+QUIET="n"
# shellcheck disable=SC2034
DO_ASK="n"
SIMULATE="n"
+LOGFILE=
declare -a REMAINING_ARGS=()
declare -a REMAINING_OPTS=()
match_lhs=$(dircolors --print-database | grep '^TERM ' | sed -e 's/^TERM *//' -e 's/ .*//')
fi
for term in ${match_lhs} ; do
- if [[ "${safe_term}" == "${term}" || "${TERM}" == "${term}" ]] ; then
+ if [[ "${safe_term}" == "${term}" || "${TERM}" == "${term}" || "${TERM}" =~ .*color ]] ; then
use_color="true"
break
fi
DEBUG="y"
shift
;;
+ -q|--quiet)
+ QUIET="y"
+ shift
+ ;;
-v|--verbose)
VERBOSE="y"
shift
done
fi
+ if [[ "${VERBOSE}" == "y" && "${QUIET}" == "y" ]] ; then
+ error "Parameters '${RED}--verbose${NORMAL}' and '${RED}--quiet${NORMAL}' are mutually exclusive."
+ echo
+ usage >&2
+ echo
+ exit 1
+ fi
+
if [[ "${SIMULATE}" == "y" ]] ; then
echo
echo -e "${CYAN}Simulation mode!${NORMAL}"
#------------------------------------------------------------------------------
info() {
- echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $*" >&2
+ if [[ "${QUIET}" != "y" ]] ; then
+ echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $*" >&2
+ fi
}
#------------------------------------------------------------------------------
echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASE_NAME}:${RED}ERROR${NORMAL}]: $*" >&2
}
+#------------------------------------------------------------------------------
+check_for_root() {
+ local my_id=$( id -u )
+ if [[ "${my_id}" != "0" ]] ; then
+ error "You must be ${RED}root${NORMAL} to execute this script."
+ echo >&2
+ exit 1
+ fi
+}
+
#------------------------------------------------------------------------------
RM() {
}
+#------------------------------------------------------------------------------
+MKDIR() {
+
+ local cmd="mkdir $*"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd="mkdir --verbose $*"
+ fi
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Executing: ${cmd}"
+ return
+ fi
+ debug "Executing: ${cmd}"
+ eval ${cmd}
+}
+
+#------------------------------------------------------------------------------
+CHOWN() {
+
+ local cmd="chown $*"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd="chown --verbose $*"
+ fi
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Executing: ${cmd}"
+ return
+ fi
+ debug "Executing: ${cmd}"
+ eval ${cmd}
+}
+
+#------------------------------------------------------------------------------
+line() {
+
+ local lchar='-'
+ if [[ "$#" -ge 1 ]] ; then
+ lchar=$( echo "$1" | sed -e 's/^\(.\).*/\1/' )
+ fi
+
+ local count=79
+ if [[ "$#" -ge 2 ]] ; then
+ count="$2"
+ fi
+
+ local i=0
+ local l=''
+
+ while [[ "$i" -lt "${count}" ]] ; do
+ l+="${lchar}"
+ i=$(( $i + 1 ))
+ done
+
+ if [[ -n "${LOGFILE}" ]] ; then
+ echo "${l}" >>"${LOGFILE}"
+ fi
+
+ if [[ "${QUIET}" == "y" ]] ; then
+ return
+ fi
+ echo "${l}"
+
+}
+
+#------------------------------------------------------------------------------
+dline() {
+ line '=' "$@"
+}
+
+#------------------------------------------------------------------------------
+empty_line() {
+
+ if [[ -n "${LOGFILE}" ]] ; then
+ echo >>"${LOGFILE}"
+ fi
+
+ if [[ "${QUIET}" == "y" ]] ; then
+ return
+ fi
+ echo
+
+}
+
#------------------------------------------------------------------------------
set_locale() {
detect_color
+IMAGE_ROOT="/var/www/cobbler/distro_mirror"
+
+DIR_OWNER="apache"
+DIR_GROUP="apache"
+
declare -a DISTRO_IDS=( 'almalinux-8' 'centos-stream-8' 'centos-stream-9' )
declare -a DISTRO_ID_UPDATE=()
+declare -A SOURCE=()
+declare -A TARGET=()
+
+SOURCE['almalinux-8']="rsync://ftp.fau.de/almalinux/8/BaseOS/x86_64/os/"
+TARGET['almalinux-8']="AlmaLinux-8"
+
+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"
+
DESCRIPTION=$( cat <<-EOF
Updates the boot environments of cobbler boot environments.
exit 1
fi
+}
+
+#------------------------------------------------------------------------------
+update_distro() {
+
+ distro_id="$1"
+
+ local src_url="${SOURCE[${distro_id}]}"
+ if [[ -z "${src_url}" ]] ; then
+ error "Cobbler distribution '${RED}${distro_id}${NORMAL}' has no source URL defined."
+ exit 8
+ fi
+
+ local target_dir_rel="${TARGET[${distro_id}]}"
+ if [[ -z "${target_dir_rel}" ]] ; then
+ error "Cobbler distribution '${RED}${distro_id}${NORMAL}' has no target directory defined."
+ exit 8
+ fi
+ local target_dir="${IMAGE_ROOT}/${target_dir_rel}"
+
+ info "Syncing from '${CYAN}${src_url}${NORMAL}' ==> '${CYAN}${target_dir}${NORMAL}' ..."
+
+ local cmd="rsync --recursive --links --perms --times --specials --hard-links --compress"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" --verbose"
+ elif [[ "${QUIET}" == "y" ]] ; then
+ cmd+=" --quiet"
+ fi
+ cmd+=" --compress --stats --delete --delete-after --delete-excluded --delay-updates"
+ if [[ -n "${LOGFILE}" ]] ; then
+ cmd+=" --log-file \"${LOGFILE}\""
+ fi
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ cmd+=" --dry-run"
+ fi
+ cmd+=" \"${src_url}\" \"${target_dir}/\""
+ debug "Executing: ${cmd}"
+ eval ${cmd}
+
+ # info "Chowning '${CYAN}${target_dir}${NORMAL}' to '${CYAN}${DIR_OWNER}:${DIR_GROUP}${CYAN}' ..."
+ # CHOWN --recursive "${DIR_OWNER}:${DIR_GROUP}" "${target_dir}"
+
+ return 0
+
+
+
}
#------------------------------------------------------------------------------
get_options "$@"
for distro_id in "${DISTRO_ID_UPDATE[@]}" ; do
- echo
+ empty_line
+ line
info "Updating Cobbler distribution '${GREEN}${distro_id}${NORMAL}' ..."
+ update_distro "${distro_id}"
done
}