#!/bin/bash set -e vagrant_box='fedora_42' arm_cpu='cortex-a76' vagrant_ssh_port='3333' #set sudo=sudo for # 1. macos systems or # 2. non-root users [[ $EUID != 0 ]] || [[ $(uname -s) == Darwin ]] && sudo='sudo' [[ $(uname -s) == Darwin ]] && system='macos' [[ $(uname -s) == Linux ]] && system='linux' [[ -z $system ]] && echo 'unsupported system....exiting' && exit macos_check_brew_cmd_exists() { brew_cmd=$1 cask_or_form=$2 if ! brew info $brew_cmd >/dev/null 2>&1 then echo -e "\nthe brew $cask_or_form $brew_cmd cannot be found\ninstall it with:\nbrew install $brew_cmd" exit 1 fi } macos_does_brew_exist() { if [[ $(command -v brew) == "" ]]; then echo "homebrew is not installed" echo "install it with:" echo '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"' exit 2 fi } fedora_check_cmd_exists() { cmd=$1 pkg_name=$2 if ! command -v $cmd >/dev/null 2>&1 then echo -e "\nthe $cmd command cannot be found\ninstall it with:\ndnf install $pkg_name" exit 1 fi } does_vagrant_plugin_exist() { plugin=$1 installed=$(vagrant plugin list | grep $plugin || :) [[ -z $installed ]] && echo -e "vagrant plugin $plugin is not installed\ninstall with:\nvagrant plugin install $plugin" && exit || : } # make curl behave like wget curl_cmd () { curl -O --retry 99 --retry-max-time 0 -C - $1 } # if macos if [ $system == 'macos' ]; then macos_does_brew_exist macos_check_brew_cmd_exists vagrant cask macos_check_brew_cmd_exists qemu formulae does_vagrant_plugin_exist vagrant-qemu # if linux elif [ $system == 'linux' ]; then fedora_check_cmd_exists vagrant vagrant fedora_check_cmd_exists nc nmap-ncat does_vagrant_plugin_exist vagrant-qemu fi # download files with curl curl_cmd https://leifliddy.com/vagrant/Vagrantfile curl_cmd https://leifliddy.com/vagrant/fedora_42.json curl_cmd https://leifliddy.com/vagrant/$vagrant_box.box curl_cmd https://leifliddy.com/vagrant/vagrant chmod +x vagrant [[ $(ps -ef | grep "[.]vagrant/machines/fedora/qemu/") ]] && ./vagrant kill is_match=$($sudo vagrant box list | grep $vagrant_box || :) [[ -n $is_match ]] && echo -e '\nbox exists\n' || $sudo vagrant box add $vagrant_box.json $sudo vagrant box prune $sudo ./vagrant up [[ -n $sudo ]] && echo -e '\nssh in with:\nsudo vagrant ssh' [[ -z $sudo ]] && echo -e '\nssh in with:\nvagrant ssh'