#!/bin/sh # vim: set sw=4 ts=4 sts=4 et : memory=2048 vcpus=2 disk_size=16 kickstart=http://rosalina.pyrocufflink.blue/~dustin/kickstart/fedora.ks fedora=$(rpm -E %fedora) network=network=prod dnsdomain=pyrocufflink.blue console=true usage() { printf 'usage: %s [options] name\n' "${0##*/}" } while [ $# -gt 0 ]; do case "$1" in --kickstart) shift kickstart="$1" ;; --kickstart=*) kickstart="${1##*=}" ;; --memory) shift memory="$1" ;; --memory=*) memory="${1#*=}" ;; --vcpus) shift vcpus="$1" ;; --vcpus=*) vcpus="${1#*=}" ;; --location) shift location="$1" ;; --location=*) location="${1#*=}" ;; --disk-size) shift disk_size="$1" ;; --disk=size=*) disk_size="${1#*=}" ;; --fedora) shift fedora="$1" ;; --fedora=*) shift fedora="${1#*=}" ;; --network) shift network="$1" ;; --network=*) network="${1#*=}" ;; --domain) shift dnsdomain=$1 ;; --domain=*) dnsdomain=${1#=*} ;; --no-console|--noconsole) console=false ;; --) shift break ;; *) if [ -z "${name}" ]; then name="$1" else usage >&2 exit 2 fi esac shift done if [ -z "${name}" ]; then usage >&2 exit 2 fi case ${name} in *.*) hostname=${name} name=${name%%.*} ;; *) hostname=${name}.${dnsdomain} ;; esac if [ -z "${LIBVIRT_DEFAULT_URI}" ]; then printf 'LIBVIRT_DEFAULT_URI is not set.\n' >&2 printf 'If you want to create a new VM locally, explicitly set ' printf 'LIBVIRT_DEFAULT_URI=qemu:///session\n' exit 1 fi printf 'Creating %s on %s\n' "${name}" "${LIBVIRT_DEFAULT_URI}" if [ -z "${location}" ]; then location=http://dl.fedoraproject.org/pub/fedora/linux/releases/${fedora}/Everything/x86_64/os fi if [ -z ${http_proxy+on} ]; then export http_proxy=http://proxy.pyrocufflink.blue:3128 printf 'Using default HTTP proxy: %s\n' "${http_proxy}" >&2 elif [ -z "${http_proxy}" ]; then printf 'HTTP proxy disabled\n' "${http_proxy}" >&2 else printf 'Using HTTP proxy: %s\n' "${http_proxy}" >&2 fi extra_args="ip=::::${hostname}::dhcp inst.ks=${kickstart}" if [ -n "${http_proxy}" ]; then extra_args="${extra_args} inst.proxy=${http_proxy}" if [ ${fedora} -lt 40 ]; then extra_args="${extra_args} proxy=${http_proxy}" fi fi extra_args="${extra_args} inst.notmux quiet systemd.show_status=1 console=ttyS0" set -- \ --name ${name} \ --memory ${memory} \ --cpu host \ --location ${location} \ --extra-args "${extra_args}" \ --disk pool=default,size=${disk_size},cache=none \ --network ${network} \ --os-variant fedora$(rpm -E %fedora) \ --console pty,target.type=serial,log.file=/var/log/libvirt/console/${name}.log \ --sound none \ --redirdev none \ --rng /dev/random \ --boot uefi \ "$@" if $console; then set -- "$@" --autoconsole text else set -- "$@" --noautoconsole --wait -1 fi exec virt-install "$@"