Compare commits

..

No commits in common. "1c3e107f4aa9e9460ea52de7bc00aa856de42564" and "d37bbe628db7892857a9b5b749fa4f3654971ecf" have entirely different histories.

2 changed files with 144 additions and 236 deletions

View File

@ -4,13 +4,6 @@
- All LXC instances created using this repository come pre-installed with Midnight Commander, which is a command-line tool (`mc`) that offers a user-friendly file and directory management interface for the terminal environment. - All LXC instances created using this repository come pre-installed with Midnight Commander, which is a command-line tool (`mc`) that offers a user-friendly file and directory management interface for the terminal environment.
## 2023-05-23
### Changed
- **OpenWrt VM**
- NEW Script
## 2023-05-17 ## 2023-05-17
### Changed ### Changed

View File

@ -8,21 +8,21 @@
# Based on work from https://i12bretro.github.io/tutorials/0405.html # Based on work from https://i12bretro.github.io/tutorials/0405.html
function header_info { function header_info {
clear
cat <<"EOF" cat <<"EOF"
____ _ __ __ _______ ________ __
/ __ \____ ___ ____| | / /____/ /_ | |.-----.-----.-----.| | | |.----.| |_
/ / / / __ \/ _ \/ __ \ | /| / / ___/ __/ | - || _ | -__| || | | || _|| _|
/ /_/ / /_/ / __/ / / / |/ |/ / / / /_ |_______|| __|_____|__|__||________||__| |____|
\____/ .___/\___/_/ /_/|__/|__/_/ \__/ |__| W I R E L E S S F R E E D O M
/_/ W I R E L E S S F R E E D O M -----------------------------------------------------
EOF EOF
} }
clear
header_info header_info
echo -e "Loading..." echo -e "Loading..."
GEN_MAC=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//') GEN_MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]')
GEN_MAC_LAN=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//') GEN_MAC_LAN=$(echo '00 60 2e'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]')
NEXTID=$(pvesh get /cluster/nextid) NEXTID=$(pvesh get /cluster/nextid)
YW=$(echo "\033[33m") YW=$(echo "\033[33m")
BL=$(echo "\033[36m") BL=$(echo "\033[36m")
@ -35,33 +35,35 @@ CL=$(echo "\033[m")
BFR="\\r\\033[K" BFR="\\r\\033[K"
HOLD="-" HOLD="-"
CM="${GN}${CL}" CM="${GN}${CL}"
CROSS="${RD}${CL}" set -o errexit
set -Eeuo pipefail set -o errtrace
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR set -o nounset
set -o pipefail
shopt -s expand_aliases
alias die='EXIT=$? LINE=$LINENO error_exit'
trap die ERR
trap cleanup EXIT trap cleanup EXIT
function error_handler() { function error_exit() {
local exit_code="$?" trap - ERR
local line_number="$1" local reason="Unknown failure occurred."
local command="$2" local msg="${1:-$reason}"
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
echo -e "\n$error_message\n" echo -e "$flag $msg" 1>&2
cleanup_vmid [ ! -z ${VMID-} ] && cleanup_vmid
exit $EXIT
} }
function cleanup_vmid() { function cleanup_vmid() {
if qm status $VMID &>/dev/null; then if $(qm status $VMID &>/dev/null); then
qm stop $VMID &>/dev/null if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then
qm destroy $VMID &>/dev/null qm stop $VMID
fi
qm destroy $VMID
fi fi
} }
function cleanup() { function cleanup() {
popd >/dev/null popd >/dev/null
rm -rf $TEMP_DIR rm -rf $TEMP_DIR
} }
TEMP_DIR=$(mktemp -d)
pushd $TEMP_DIR >/dev/null
function send_line_to_vm() { function send_line_to_vm() {
echo -e "${DGN}Sending line: ${YW}$1${CL}" echo -e "${DGN}Sending line: ${YW}$1${CL}"
for ((i = 0; i < ${#1}; i++)); do for ((i = 0; i < ${#1}; i++)); do
@ -134,265 +136,179 @@ function send_line_to_vm() {
TEMP_DIR=$(mktemp -d) TEMP_DIR=$(mktemp -d)
pushd $TEMP_DIR >/dev/null pushd $TEMP_DIR >/dev/null
if [ $(pveversion | grep "pve-manager/7" | wc -l) -ne 1 ]; then
if (whiptail --title "OpenWrt VM" --yesno "This will create a New OpenWrt VM. Proceed?" 10 58); then echo "⚠ This version of Proxmox Virtual Environment is not supported"
: echo "Requires PVE Version: 7.XX"
echo "Exiting..."
sleep 3
exit
fi
if (whiptail --title "OpenWRT VM" --yesno "This will create a New OpenWRT VM. Proceed?" 10 58); then
echo "User selected Yes"
else else
header_info && echo -e "⚠ User exited script \n" && exit clear
echo -e "⚠ User exited script \n"
exit
fi fi
function msg_info() { function msg_info() {
local msg="$1" local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..." echo -ne " ${HOLD} ${YW}${msg}..."
} }
function msg_ok() { function msg_ok() {
local msg="$1" local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}" echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
} }
function msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}
function pve_check() {
if [ $(pveversion | grep -c "pve-manager/7\.[2-9]") -eq 0 ]; then
echo -e "${CROSS} This version of Proxmox Virtual Environment is not supported"
echo -e "Requires PVE Version 7.2 or higher"
echo -e "Exiting..."
sleep 2
exit
fi
}
function arch_check() {
if [ "$(dpkg --print-architecture)" != "amd64" ]; then
echo -e "\n ${CROSS} This script will not work with PiMox! \n"
echo -e "Exiting..."
sleep 2
exit
fi
}
function ssh_check() {
if command -v pveversion >/dev/null 2>&1; then
if [ -n "${SSH_CLIENT:+x}" ]; then
if whiptail --defaultno --title "SSH DETECTED" --yesno "It's suggested to use the Proxmox shell instead of SSH, since SSH can create issues while gathering variables. Would you like to proceed with using SSH?" 10 62; then
echo "you've been warned"
else
clear
exit
fi
fi
fi
}
function exit-script() {
clear
echo -e "⚠ User exited script \n"
exit
}
function default_settings() { function default_settings() {
echo -e "${DGN}Using Virtual Machine ID: ${BGN}$NEXTID${CL}"
VMID=$NEXTID VMID=$NEXTID
echo -e "${DGN}Using Hostname: ${BGN}openwrt${CL}"
HN=openwrt HN=openwrt
echo -e "${DGN}Allocated Cores: ${BGN}1${CL}"
CORE_COUNT="1" CORE_COUNT="1"
echo -e "${DGN}Allocated RAM: ${BGN}256${CL}"
RAM_SIZE="256" RAM_SIZE="256"
echo -e "${DGN}Using WAN Bridge: ${BGN}vmbr0${CL}"
BRG="vmbr0" BRG="vmbr0"
VLAN=""
MAC=$GEN_MAC
LAN_MAC=$GEN_MAC_LAN
LAN_BRG="vmbr0"
LAN_VLAN=",tag=999"
MTU=""
START_VM="yes"
echo -e "${DGN}Using Virtual Machine ID: ${BGN}${VMID}${CL}"
echo -e "${DGN}Using Hostname: ${BGN}${HN}${CL}"
echo -e "${DGN}Allocated Cores: ${BGN}${CORE_COUNT}${CL}"
echo -e "${DGN}Allocated RAM: ${BGN}${RAM_SIZE}${CL}"
echo -e "${DGN}Using WAN Bridge: ${BGN}${BRG}${CL}"
echo -e "${DGN}Using WAN VLAN: ${BGN}Default${CL}" echo -e "${DGN}Using WAN VLAN: ${BGN}Default${CL}"
echo -e "${DGN}Using WAN MAC Address: ${BGN}${MAC}${CL}" VLAN=""
echo -e "${DGN}Using LAN MAC Address: ${BGN}${LAN_MAC}${CL}" echo -e "${DGN}Using WAN MAC Address: ${BGN}$GEN_MAC${CL}"
echo -e "${DGN}Using LAN Bridge: ${BGN}${LAN_BRG}${CL}" MAC=$GEN_MAC
echo -e "${DGN}Using LAN MAC Address: ${BGN}$GEN_MAC_LAN${CL}"
LAN_MAC=$GEN_MAC_LAN
echo -e "${DGN}Using LAN Bridge: ${BGN}vmbr0${CL}"
LAN_BRG="vmbr0"
echo -e "${DGN}Using LAN VLAN: ${BGN}999${CL}" echo -e "${DGN}Using LAN VLAN: ${BGN}999${CL}"
LAN_VLAN=",tag=999"
echo -e "${DGN}Using Interface MTU Size: ${BGN}Default${CL}" echo -e "${DGN}Using Interface MTU Size: ${BGN}Default${CL}"
MTU=""
echo -e "${DGN}Start VM when completed: ${BGN}yes${CL}" echo -e "${DGN}Start VM when completed: ${BGN}yes${CL}"
START_VM="yes"
echo -e "${BL}Creating a OpenWRT VM using the above default settings${CL}" echo -e "${BL}Creating a OpenWRT VM using the above default settings${CL}"
} }
function advanced_settings() { function advanced_settings() {
while true; do VMID=$(whiptail --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" 3>&1 1>&2 2>&3)
if VMID=$(whiptail --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then exitstatus=$?
if [ -z "$VMID" ]; then if [ $exitstatus = 0 ]; then
VMID="$NEXTID" echo -e "${DGN}Using Virtual Machine ID: ${BGN}$VMID${CL}"
fi
if pct status "$VMID" &>/dev/null || qm status "$VMID" &>/dev/null; then
echo -e "${CROSS}${RD} ID $VMID is already in use${CL}"
sleep 2
continue
fi
echo -e "${DGN}Virtual Machine ID: ${BGN}$VMID${CL}"
break
else
exit-script
fi
done
if VM_NAME=$(whiptail --inputbox "Set Hostname" 8 58 openwrt --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
if [ -z $VM_NAME ]; then
HN="openwrt"
echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
else
HN=$(echo ${VM_NAME,,} | tr -d ' ')
echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
fi
else else
exit-script exit
fi fi
VM_NAME=$(whiptail --inputbox "Set Hostname" 8 58 openwrt --title "HOSTNAME" 3>&1 1>&2 2>&3)
if CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 1 --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then exitstatus=$?
if [ -z $CORE_COUNT ]; then if [ $exitstatus = 0 ]; then
CORE_COUNT="1" HN=$(echo ${VM_NAME,,} | tr -d ' ')
echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
else
echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
fi
else else
exit-script exit
fi fi
CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 1 --title "CORE COUNT" 3>&1 1>&2 2>&3)
if RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 256 --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then exitstatus=$?
if [ -z $RAM_SIZE ]; then if [ $exitstatus = 0 ]; then
RAM_SIZE="256" echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
else
echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
fi
else else
exit-script exit
fi fi
RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 256 --title "RAM" 3>&1 1>&2 2>&3)
if BRG=$(whiptail --inputbox "Set a WAN Bridge" 8 58 vmbr0 --title "WAN BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then exitstatus=$?
if [ -z $BRG ]; then if [ $exitstatus = 0 ]; then
BRG="vmbr0" echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
echo -e "${DGN}Using WAN Bridge: ${BGN}$BRG${CL}"
else
echo -e "${DGN}Using WAN Bridge: ${BGN}$BRG${CL}"
fi
else else
exit-script exit
fi fi
BRG=$(whiptail --inputbox "Set a WAN Bridge" 8 58 vmbr0 --title "BRIDGE" 3>&1 1>&2 2>&3)
if LAN_BRG=$(whiptail --inputbox "Set a LAN Bridge" 8 58 vmbr0 --title "LAN BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then exitstatus=$?
if [ -z $LAN_BRG ]; then if [ $exitstatus = 0 ]; then
LAN_BRG="vmbr0" echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
echo -e "${DGN}Using LAN Bridge: ${BGN}$LAN_BRG${CL}"
else
echo -e "${DGN}Using LAN Bridge: ${BGN}$LAN_BRG${CL}"
fi
else else
exit-script exit
fi fi
LAN_BRG=$(whiptail --inputbox "Set a LAN Bridge" 8 58 vmbr0 --title "BRIDGE" 3>&1 1>&2 2>&3)
if MAC1=$(whiptail --inputbox "Set a WAN MAC Address" 8 58 $GEN_MAC --title "WAN MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then exitstatus=$?
if [ -z $MAC1 ]; then if [ $exitstatus = 0 ]; then
MAC="$GEN_MAC" echo -e "${DGN}Using Bridge: ${BGN}$LAN_BRG${CL}"
echo -e "${DGN}Using WAN MAC Address: ${BGN}$MAC${CL}"
else
MAC="$MAC1"
echo -e "${DGN}Using WAN MAC Address: ${BGN}$MAC1${CL}"
fi
else else
exit-script exit
fi fi
MAC1=$(whiptail --inputbox "Set a WAN MAC Address" 8 58 $GEN_MAC --title "MAC ADDRESS" 3>&1 1>&2 2>&3)
if MAC2=$(whiptail --inputbox "Set a LAN MAC Address" 8 58 $GEN_MAC_LAN --title "LAN MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then exitstatus=$?
if [ -z $MAC2 ]; then if [ $exitstatus = 0 ]; then
LAN_MAC="$GEN_MAC_LAN" MAC="$MAC1"
echo -e "${DGN}Using LAN MAC Address: ${BGN}$LAN_MAC${CL}" echo -e "${DGN}Using WAN MAC Address: ${BGN}$MAC1${CL}"
else
LAN_MAC="$MAC2"
echo -e "${DGN}Using LAN MAC Address: ${BGN}$MAC2${CL}"
fi
else else
exit-script exit
fi fi
MAC2=$(whiptail --inputbox "Set a LAN MAC Address" 8 58 $GEN_MAC --title "MAC ADDRESS" 3>&1 1>&2 2>&3)
if VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "WAN VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then exitstatus=$?
if [ $exitstatus = 0 ]; then
LAN_MAC="$MAC2"
echo -e "${DGN}Using LAN MAC Address: ${BGN}$MAC2${CL}"
else
exit
fi
VLAN1=$(whiptail --inputbox "Set a WAN VLAN tag(leave blank for default)" 8 58 --title "VLAN" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
if [ -z $VLAN1 ]; then if [ -z $VLAN1 ]; then
VLAN1="Default" VLAN1="Default" VLAN=""
VLAN="" echo -e "${DGN}Using WAN VLAN tag: ${BGN}$VLAN1${CL}"
echo -e "${DGN}Using WAN Vlan: ${BGN}$VLAN1${CL}"
else else
VLAN=",tag=$VLAN1" VLAN=",tag=$VLAN1"
echo -e "${DGN}Using WAN Vlan: ${BGN}$VLAN1${CL}" echo -e "${DGN}Using WAN VLAN tag: ${BGN}$VLAN1${CL}"
fi fi
else
exit-script
fi fi
VLAN2=$(whiptail --inputbox "Set a LAN VLAN tag(leave blank for default)" 8 58 --title "VLAN" 3>&1 1>&2 2>&3)
if VLAN2=$(whiptail --inputbox "Set a LAN Vlan" 8 58 999 --title "LAN VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then exitstatus=$?
if [ $exitstatus = 0 ]; then
if [ -z $VLAN2 ]; then if [ -z $VLAN2 ]; then
VLAN2="999" VLAN2="Default" LAN_VLAN=""
LAN_VLAN=",tag=$VLAN2" echo -e "${DGN}Using LAN VLAN tag: ${BGN}$VLAN2${CL}"
echo -e "${DGN}Using LAN Vlan: ${BGN}$VLAN2${CL}"
else else
LAN_VLAN=",tag=$VLAN2" LAN_VLAN=",tag=$VLAN2"
echo -e "${DGN}Using LAN Vlan: ${BGN}$VLAN2${CL}" echo -e "${DGN}Using LAN VLAN tag: ${BGN}$VLAN2${CL}"
fi fi
else
exit-script
fi fi
MTU1=$(whiptail --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
if MTU1=$(whiptail --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then exitstatus=$?
if [ $exitstatus = 0 ]; then
if [ -z $MTU1 ]; then if [ -z $MTU1 ]; then
MTU1="Default" MTU1="Default" MTU=""
MTU=""
echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}"
else else
MTU=",mtu=$MTU1" MTU=",mtu=$MTU1"
echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}"
fi fi
else
exit-script
fi fi
if (whiptail --title "START VIRTUAL MACHINE" --yesno "Start OpenWRT VM when completed?" 10 58); then
if (whiptail --title "START VIRTUAL MACHINE" --yesno "Start VM when completed?" 10 58); then echo -e "${DGN}Start OpenWRT VM when completed: ${BGN}yes${CL}"
echo -e "${DGN}Start VM when completed: ${BGN}yes${CL}"
START_VM="yes" START_VM="yes"
else else
echo -e "${DGN}Start VM when completed: ${BGN}no${CL}" echo -e "${DGN}Start OpenWRT VM when completed: ${BGN}no${CL}"
START_VM="no" START_VM="no"
fi fi
if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create OpenWRT VM?" 10 58); then
if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create OpenWrt VM?" --no-button Do-Over 10 58); then echo -e "${RD}Creating OpenWRT VM using the above advanced settings${CL}"
echo -e "${RD}Creating a OpenWrt VM using the above advanced settings${CL}"
else else
clear
header_info header_info
echo -e "${RD}Using Advanced Settings${CL}" echo -e "${RD}Using Advanced Settings${CL}"
advanced_settings advanced_settings
fi fi
} }
function start_script() { function start_script() {
if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" 10 58); then
clear
header_info header_info
echo -e "${BL}Using Default Settings${CL}" echo -e "${BL}Using Default Settings${CL}"
default_settings default_settings
else else
clear
header_info header_info
echo -e "${RD}Using Advanced Settings${CL}" echo -e "${RD}Using Advanced Settings${CL}"
advanced_settings advanced_settings
fi fi
} }
arch_check
pve_check
ssh_check
start_script start_script
msg_info "Validating Storage" msg_info "Validating Storage"
while read -r line; do while read -r line; do
TAG=$(echo $line | awk '{print $1}') TAG=$(echo $line | awk '{print $1}')
@ -415,14 +331,14 @@ elif [ $((${#STORAGE_MENU[@]} / 3)) -eq 1 ]; then
else else
while [ -z "${STORAGE:+x}" ]; do while [ -z "${STORAGE:+x}" ]; do
STORAGE=$(whiptail --title "Storage Pools" --radiolist \ STORAGE=$(whiptail --title "Storage Pools" --radiolist \
"Which storage pool you would like to use for the OpenWrt VM?\n\n" \ "Which storage pool you would like to use for the OpenWRT VM?\n\n" \
16 $(($MSG_MAX_LENGTH + 23)) 6 \ 16 $(($MSG_MAX_LENGTH + 23)) 6 \
"${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3) || exit "${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3) || exit
done done
fi fi
msg_ok "Using ${CL}${BL}$STORAGE${CL} ${GN}for Storage Location." msg_ok "Using ${CL}${BL}$STORAGE${CL} ${GN}for Storage Location."
msg_ok "Virtual Machine ID is ${CL}${BL}$VMID${CL}." msg_ok "Virtual Machine ID is ${CL}${BL}$VMID${CL}."
msg_info "Getting URL for OpenWrt Disk Image" msg_info "Getting URL for OpenWRT Disk Image"
regex='<strong>Current Stable Release - OpenWrt ([^/]*)<\/strong>' && response=$(curl -s https://openwrt.org) && [[ $response =~ $regex ]] && stableVersion="${BASH_REMATCH[1]}" regex='<strong>Current Stable Release - OpenWrt ([^/]*)<\/strong>' && response=$(curl -s https://openwrt.org) && [[ $response =~ $regex ]] && stableVersion="${BASH_REMATCH[1]}"
URL=https://downloads.openwrt.org/releases/$stableVersion/targets/x86/64/openwrt-$stableVersion-x86-64-generic-ext4-combined.img.gz URL=https://downloads.openwrt.org/releases/$stableVersion/targets/x86/64/openwrt-$stableVersion-x86-64-generic-ext4-combined.img.gz
@ -438,7 +354,7 @@ NEWFILE="${FILE%.*}"
FILE="$NEWFILE" FILE="$NEWFILE"
mv $FILE ${FILE%.*} mv $FILE ${FILE%.*}
qemu-img resize -f raw ${FILE%.*} 512M >/dev/null 2>/dev/null qemu-img resize -f raw ${FILE%.*} 512M >/dev/null 2>/dev/null
msg_ok "Extracted & Resized OpenWrt Disk Image ${CL}${BL}$FILE${CL}" msg_ok "Resized ${CL}${BL}$FILE${CL}"
STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}')
case $STORAGE_TYPE in case $STORAGE_TYPE in
nfs | dir) nfs | dir)
@ -449,6 +365,7 @@ nfs | dir)
btrfs) btrfs)
DISK_EXT=".raw" DISK_EXT=".raw"
DISK_REF="$VMID/" DISK_REF="$VMID/"
DISK_FORMAT="subvol"
DISK_IMPORT="-format raw" DISK_IMPORT="-format raw"
;; ;;
esac esac
@ -457,24 +374,22 @@ for i in {0,1}; do
eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-} eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-}
eval DISK${i}_REF=${STORAGE}:${DISK_REF:-}${!disk} eval DISK${i}_REF=${STORAGE}:${DISK_REF:-}${!disk}
done done
msg_ok "Extracted OpenWRT Disk Image"
msg_info "Creating OpenWrt VM" msg_info "Creating OpenWRT VM"
qm create $VMID -cores $CORE_COUNT -memory $RAM_SIZE -name $HN \ qm create $VMID -cores $CORE_COUNT -memory $RAM_SIZE -name $HN \
-onboot 1 -ostype l26 -scsihw virtio-scsi-pci --tablet 0 -onboot 1 -ostype l26 -scsihw virtio-scsi-pci --tablet 0
pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null
qm importdisk $VMID ${FILE%.*} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null qm importdisk $VMID ${FILE%.*} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null
qm set $VMID \ qm set $VMID \
-efidisk0 ${DISK0_REF},efitype=4m,size=4M \
-scsi0 ${DISK1_REF},size=512M \ -scsi0 ${DISK1_REF},size=512M \
-boot order=scsi0 \ -boot order=scsi0 \
-description "# OpenWrt VM -description "# OpenWRT VM
### https://github.com/tteck/Proxmox ### https://github.com/tteck/Proxmox
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/D1D7EP4GF)" >/dev/null [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/D1D7EP4GF)" >/dev/null
msg_ok "OpenWrt VM ${CL}${BL}(${HN})" msg_ok "OpenWRT VM ${CL}${BL}(${HN})"
msg_info "OpenWrt is being started in order to configure the network interfaces." msg_info "Pre-configuring network interfaces"
qm start $VMID qm start $VMID
sleep 15 sleep 15
msg_ok "Network interfaces are being configured as OpenWrt initiates."
send_line_to_vm "" send_line_to_vm ""
send_line_to_vm "uci delete network.@device[0]" send_line_to_vm "uci delete network.@device[0]"
send_line_to_vm "uci set network.wan=interface" send_line_to_vm "uci set network.wan=interface"
@ -490,22 +405,22 @@ send_line_to_vm "uci set firewall.@zone[1].input='ACCEPT'"
send_line_to_vm "uci set firewall.@zone[1].forward='ACCEPT'" send_line_to_vm "uci set firewall.@zone[1].forward='ACCEPT'"
send_line_to_vm "uci commit" send_line_to_vm "uci commit"
send_line_to_vm "halt" send_line_to_vm "halt"
msg_ok "Network interfaces have been successfully configured." msg_ok "Pre-configured network interfaces"
until qm status $VMID | grep -q "stopped"; do until qm status $VMID | grep -q "stopped"; do
sleep 2 sleep 2
done done
msg_info "Bridge interfaces are being added." msg_info "Adding bridge interface"
qm set $VMID \ qm set $VMID \
-net0 virtio,bridge=${BRG},macaddr=${MAC}${VLAN}${MTU} \ -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU \
-net1 virtio,bridge=${LAN_BRG},macaddr=${LAN_MAC}${LAN_VLAN}${MTU} >/dev/null 2>/dev/null -net1 virtio,bridge=${LAN_BRG},macaddr=${LAN_MAC}${LAN_VLAN}$MTU >/dev/null 2>/dev/null
msg_ok "Bridge interfaces have been successfully added." msg_ok "Added bridge interface"
if [ "$START_VM" == "yes" ]; then if [ "$START_VM" == "yes" ]; then
msg_info "Starting OpenWrt VM" msg_info "Starting OpenWRT VM"
qm start $VMID qm start $VMID
msg_ok "Started OpenWrt VM" msg_ok "Started OpenWRT VM"
fi fi
VLAN_FINISH="" VLAN_FINISH=""
if [ "$VLAN" == "" ] && [ "$VLAN2" != "999" ]; then if [ "$VLAN" == "" ] && [ "$LAN_VLAN" != "999" ]; then
VLAN_FINISH=" Please remember to adjust the VLAN tags to suit your network." VLAN_FINISH=" Please remember to adjust the VLAN tags to suit your network."
fi fi
msg_ok "Completed Successfully!\n${VLAN_FINISH}" msg_ok "Completed Successfully!\n${VLAN_FINISH:-}"