From 3bf9384b46d72072d3e02f9b9931cea0a148b040 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 7 Jun 2021 17:52:49 +0200 Subject: [PATCH] Continue with bin/get-centos8-streams-boot --- bin/get-centos8-streams-boot | 199 ++++++++++++++++++++++++++++++++++- 1 file changed, 198 insertions(+), 1 deletion(-) diff --git a/bin/get-centos8-streams-boot b/bin/get-centos8-streams-boot index 827a19f..ee9e685 100755 --- a/bin/get-centos8-streams-boot +++ b/bin/get-centos8-streams-boot @@ -3,6 +3,15 @@ set -e set -u +VERBOSE="n" +DEBUG="n" +QUIET='n' +SIMULATE="n" + +VERSION="0.2.0" + +BASENAME="$(basename ${0})" +BASE_DIR="$(dirname ${0})" declare -a MIRROR_URLS=( 'https://de.mirrors.clouvider.net/CentOS/' @@ -26,7 +35,195 @@ declare -a MIRROR_URLS=( declare -a URLS=() -LAST_TSTAMP="20210602" +ARCH="x86_64" +HAS_MOUNTED="n" +MOUNTPOINT="/var/tmp/centos8-stream-${ARCH}" +IMAGE_ROOT="/var/www/cobbler/ks_mirror" +IMAGE_DIR="${IMAGE_ROOT}/CentOS-8-Stream-${ARCH}" + +HAS_TTY='y' + +# Defining colors +RED="" +YELLOW="" +GREEN="" +BLUE="" +CYAN="" +NORMAL="" + +#------------------------------------------------------------------------------ +description() { + cat <<-EOF + Tries to get the latest boot environment for CentOS 8 Stream. + EOF + +} + +#------------------------------------------------------------------- +detect_color() { + + local safe_term="${TERM//[^[:alnum:]]/?}" + local match_lhs="" + local use_color="false" + local term= + + if [[ -f ~/.dir_colors ]] ; then + match_lhs="${match_lhs}$( cat ~/.dir_colors | grep '^TERM ' | sed -e 's/^TERM *//' -e 's/ .*//')" + fi + if [[ -f /etc/DIR_COLORS ]] ; then + match_lhs="${match_lhs}$( cat /etc/DIR_COLORS | grep '^TERM ' | sed -e 's/^TERM *//' -e 's/ .*//')" + fi + if [[ -z ${match_lhs} ]] ; then + type -P dircolors >/dev/null && \ + 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 + use_color="true" + break + fi + done + + # console colors: + if [ "${use_color}" = "true" ] ; then + RED="\033[38;5;196m" + YELLOW="\033[38;5;226m" + GREEN="\033[38;5;46m" + BLUE="\033[38;5;27m" + CYAN="\033[38;5;14m" + NORMAL="\033[39m" + else + RED="" + YELLOW="" + GREEN="" + BLUE="" + CYAN="" + NORMAL="" + fi + + local my_tty=$(tty) + if [[ "${my_tty}" =~ 'not a tty' ]] ; then + my_tty='-' + fi + + if [[ "${my_tty}" = '-' || "${safe_term}" = "dump" ]] ; then + HAS_TTY='n' + fi + +} + +#------------------------------------------------------------------------------ +usage() { + cat <<-EOF + Usage: ${BASENAME} [-s|--simulate] [-d|--debug] [[-v|--verbose] | [-q|--quiet]] [--nocolor] + ${BASENAME} [-h|--help] + ${BASENAME} [-V|--version] + + Options: + -s|--simulate Simulation mode - dont apply any changes. + -d|--debug Debug output (bash -x). + -v|--verbose Set verbosity on. Mutually exclusive to --quiet. + -q|--quiet Quiet output, for cronjobs. Mutually exclusive to --verbose. + --nocolor Dont use colors on display. + -h|--help Show this output and exit. + -V|--version prints out version number of the script and exit + EOF +} + +#------------------------------------------------------------------------------ +get_options() { + + local tmp= + local base_dir= + local short_options="sdvqhV" + local long_options="simulate,debug,verbose,quiet,help,version" + + set +e + tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASENAME}" -- "$@" ) + if [[ $? != 0 ]] ; then + echo "" >&2 + usage >&2 + exit 1 + fi + set -e + + # Note the quotes around `$TEMP': they are essential! + eval set -- "${tmp}" + + if [[ "$#" -gt 0 ]] ; then + while true ; do + case "$1" in + -s|--simulate) + SIMULATE="y" + shift + ;; + -d|--debug) + DEBUG="y" + shift + ;; + -v|--verbose) + VERBOSE="y" + shift + ;; + --nocolor) + RED="" + YELLOW="" + GREEN="" + BLUE="" + CYAN="" + NORMAL="" + shift + ;; + -h|--help) + description + echo + usage + exit 0 + ;; + -V|--version) + echo "${BASE_NAME} version: ${VERSION}" + exit 0 + ;; + --) shift + break + ;; + *) REMAINING_OPTS+=($1) + shift + ;; + esac + done + fi + + if [[ "${DEBUG}" = "y" ]] ; then + set -x + fi + + if [[ "$#" -gt "0" ]] ; then + error "Wrong Arguments given: $*" + echo + usage >&2 + echo + exit 1 + 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}" + echo "Nothing is really done." + echo + fi + +} + +LAST_TSTAMP="0" create_urls() { -- 2.39.5