Advertisement
vonschutter

Untitled

Apr 26th, 2023
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.89 KB | None | 0 0
  1. make_kvm_virtual_machine_now_from_redhat_com ()
  2. {
  3.     dependency::virtualization
  4.  
  5.     # Lookup specific binaries: use full path since they may just have been added and not in $PATH yet.
  6.     : ${virt_net="$(system::find_vm_bridge)"}
  7.     : "${BIN_VIRT_INSTALL:=$(type -p virt-install)}"
  8.     : ${_os_version=$( $RTD_GUI --title "Select Release Version of RedHat" --inputbox "Please pick an available OS version by entering it below. \
  9.     If you are not sure just let me choose for you... \n ${fedoralogo} "  25 110 "${_DEFAULT_REDHAT_VER}" 3>&1 1>&2 2>&3)}
  10.     case $? in
  11.         "$DIALOG_CANCEL") return ;;
  12.         "$DIALOG_ESC") return ;;
  13.     esac
  14.     clear
  15.  
  16.     : ${_os_version:="${_DEFAULT_REDHAT_VER}"}
  17.     : ${_mirrorlist_url="https://mirrors.almalinux.org/mirrorlist/${_os_version}/baseos"}
  18.     : ${_source_url="https://repo.almalinux.org/almalinux/${_os_version}/BaseOS/x86_64/kickstart/"}
  19.     : ${_preseed_file="$( mktemp ).cfg"}
  20.     : ${_config="${1:-"workstation"}"}
  21.     system::generate_ks_cfg_file -u "${_mirrorlist_url}" -c "${_config}" -p "${_preseed_file}" -e "@workstation-product-environment"
  22.  
  23.     _summary_message="The virtual machine (VDI_RedHat_"${_config}"_"${RANDOM}") \n
  24.     📋 - Using the instructions in PRESEED: ${_preseed_file} \n
  25.     🔧 - And Using this source for the packages and files to download: \n
  26.     🌎 - ${_source_url} \n
  27.     🌎 - ${_mirrorlist_url} \n
  28.     ✅ - Using the network: ${virt_net:=default} \n
  29.     ✅ - Memory: ${3:-2048} \n
  30.     ✅ - CPU's: ${2:-2} \n
  31.     ✅ - Disk Size: ${4:-40} \n You may attach to this server and see the progress at IP: $(hostname -I)"
  32.  
  33.     "${BIN_VIRT_INSTALL}" --connect qemu:///system --name VDI_RedHat_"${_config}"_"${RANDOM}" \
  34.         --vcpus "${2:-2}" \
  35.         --memory "${3:-2048}" \
  36.         --network "$virt_net" \
  37.         --disk size="${4:-40}" \
  38.         --os-variant="fedora30" \
  39.         --initrd-inject="${_preseed_file}" \
  40.         --location="${_source_url}" \
  41.         --extra-args "inst.ks=file:/$(basename $_preseed_file)" \
  42.         --noautoconsole && dialog::display_summary_message "NOTICE!"  \
  43.     || ( read -p "💥 - An ERROR has occurred. Please press [ENTER] to continue..." && return 1 )
  44.  
  45.     for i in  _preseed_file vm_kernel vm_initrd _source_url _config _mirrorlist_url _os_version ; do unset $i ; done
  46. }
  47.  
  48.  
  49.  
  50. system::generate_ks_cfg_file ()
  51. {
  52. # Description: Function to generate an installation configuration file for Fedora/Red Hat.
  53. # Globals:
  54. # Arguments: [-p <filename> ] [-u URL ] [-c workstation|ssh-server|ansible-server ]
  55. # Outputs: One kick start configuration file.
  56. # Returns: 0/1
  57. # Usage: system::generate_ks_cfg_file [-p <filename> ] [-u URL ] [-c workstation|ssh-server|ansible-server ]
  58. # End of documentation
  59.  
  60.     echo "Function : ${FUNCNAME[0]}"
  61.     echo "Called by: ${FUNCNAME[-1]}"
  62.  
  63.     local OPTIND o a
  64.     while getopts ':u:c:p:e:' OPTION; do
  65.         case "$OPTION" in
  66.         u )
  67.             local _repo_url="${OPTARG}"
  68.             write_host --cyan "${FUNCNAME[0]}: Using URL: ${OPTARG}"
  69.         ;;
  70.         c )
  71.             local _config="${OPTARG}"
  72.             write_host --cyan  "${FUNCNAME[0]}: Using Config for: ${OPTARG}"
  73.         ;;
  74.         p )
  75.             local _ks_file="${OPTARG}"
  76.             write_host --cyan  "${FUNCNAME[0]}: Creating KS.CFG Instructions: ${_ks_file}"
  77.         ;;
  78.         e )
  79.             local _wks_env="${OPTARG}"
  80.             write_host --cyan  "${FUNCNAME[0]}: Received optioinal option: ${_wks_env}"
  81.         ;;
  82.         ? )
  83.             write_host --cyan  "${FUNCNAME[0]}: Usage: $(FUNCNAME[0]) [-p <filename> ] [-u URL ] [-c workstation|ssh-server|ansible-server ]"
  84.             return 1
  85.         ;;
  86.         esac
  87.     done
  88.     unset OPTIND
  89.  
  90.     [[ -v _repo_url && -v _config && -v _ks_file   ]] || ( echo missing mandatory parameters! ; return 1 )
  91.  
  92.     case ${_config} in
  93.     ssh-server )
  94.         write_information "${FUNCNAME[0]}: Selected configuration is ssh-server..."
  95.         cat >> "${_ks_file}" <<-KS_EOF
  96.         # Generated by: system::generate_ks_cfg_file by RTD Power Tools
  97.         # Choosing mode (graphical|text|cmdline [--non-interactive])
  98.         text
  99.         url --mirrorlist="${_repo_url}"
  100.         firstboot --enable
  101.         keyboard --vckeymap=us --xlayouts='us'
  102.         lang en_US.UTF-8
  103.         timezone Europe/London --isUtc --ntpservers=0.pool.ntp.org
  104.         network --onboot=yes --bootproto=dhcp
  105.         rootpw \$6\$Rn5/UTzjIs68MX\$9gz8vmshGlPqse3VoX8dzSfhWxRVoYv1MB6aGRD8xdvztOf.gD.SxxVWkxYrwwbShB9Q14flquK/apbdQJ65t1 --iscrypted
  106.         user --groups=wheel --name=tangarora --password=\$6\$Rn5/UTzjIs68MX\$9gz8vmshGlPqse3VoX8dzSfhWxRVoYv1MB6aGRD8xdvztOf.gD.SxxVWkxYrwwbShB9Q14flquK/apbdQJ65t1 --iscrypted
  107.         zerombr
  108.         clearpart --all
  109.         autopart --nohome
  110.         reboot
  111.  
  112.         %packages --retries 5 --timeout 20
  113.         openssh-server
  114.         spice-vdagent
  115.         git
  116.         curl
  117.         dialog
  118.         %end
  119.         KS_EOF
  120.         return
  121.     ;;
  122.     ansible-server )
  123.         write_information "${FUNCNAME[0]}: Selected configuration is ansible-server..."
  124.         cat >> "${_ks_file}" <<-KS_EOF
  125.         # Generated by: system::generate_ks_cfg_file by RTD Power Tools
  126.         # Choosing mode (graphical|text|cmdline [--non-interactive])
  127.         text
  128.         url --mirrorlist="${_repo_url}"
  129.         firstboot --enable
  130.         keyboard --vckeymap=us --xlayouts='us'
  131.         lang en_US.UTF-8
  132.         timezone Europe/London --isUtc --ntpservers=0.pool.ntp.org
  133.         network --onboot=yes --bootproto=dhcp --hostname=ansible.localdomain
  134.         rootpw \$6\$Rn5/UTzjIs68MX\$9gz8vmshGlPqse3VoX8dzSfhWxRVoYv1MB6aGRD8xdvztOf.gD.SxxVWkxYrwwbShB9Q14flquK/apbdQJ65t1 --iscrypted
  135.         user --groups=wheel --name=tangarora --password=\$6\$Rn5/UTzjIs68MX\$9gz8vmshGlPqse3VoX8dzSfhWxRVoYv1MB6aGRD8xdvztOf.gD.SxxVWkxYrwwbShB9Q14flquK/apbdQJ65t1 --iscrypted
  136.         zerombr
  137.         clearpart --all
  138.         autopart --nohome
  139.         reboot
  140.  
  141.         %packages --retries 5 --timeout 20
  142.         openssh-server
  143.         spice-vdagent
  144.         git
  145.         curl
  146.         dialog
  147.         ansible
  148.         %end
  149.         KS_EOF
  150.         return
  151.     ;;
  152.     workstation )
  153.         write_information "${FUNCNAME[0]}: Selected configuration is workstation..."
  154.         cat >> "${_ks_file}" <<-KS_EOF
  155.         # Generated by: system::generate_ks_cfg_file by RTD Power Tools
  156.         # Choosing mode (graphical|text|cmdline [--non-interactive])
  157.         graphical
  158.         url --mirrorlist="${_repo_url}"
  159.         firstboot --disable
  160.         keyboard --xlayouts='se'
  161.         lang en_US.UTF-8
  162.         timezone Europe/London --isUtc --ntpservers=0.pool.ntp.org
  163.         network --onboot=yes --bootproto=dhcp
  164.         rootpw \$6\$Rn5/UTzjIs68MX\$9gz8vmshGlPqse3VoX8dzSfhWxRVoYv1MB6aGRD8xdvztOf.gD.SxxVWkxYrwwbShB9Q14flquK/apbdQJ65t1 --iscrypted
  165.         user --groups=wheel --name=tangarora --password=\$6\$Rn5/UTzjIs68MX\$9gz8vmshGlPqse3VoX8dzSfhWxRVoYv1MB6aGRD8xdvztOf.gD.SxxVWkxYrwwbShB9Q14flquK/apbdQJ65t1 --iscrypted
  166.         zerombr
  167.         clearpart --all
  168.         autopart --nohome --encrypted --passphrase letmein1234
  169.         reboot
  170.  
  171.         %packages --retries 5 --timeout 20
  172.         ${_wks_env}
  173.         openssh-server
  174.         spice-vdagent
  175.         git
  176.         curl
  177.         dialog
  178.         %end
  179.  
  180.         # Post-installation Script
  181.         %post --interpreter=/bin/bash
  182.         git clone https://github.com/vonschutter/RTD-Setup.git /opt/rtd
  183.         chmod 755 /opt/rtd/core/rtd-oem-enable-config.sh
  184.         bash /opt/rtd/core/rtd-oem-enable-config.sh
  185.         %end
  186.         KS_EOF
  187.         return
  188.     ;;
  189.     * )
  190.         write_information "${FUNCNAME[0]}: No valid OS configuration requested:
  191.         Valid requests are: workstation, ssh-server, ansible-server
  192.         skipping..."
  193.         return 1
  194.     ;;
  195.     esac
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement