Advertisement
Guest User

proxmox-openwrt

a guest
Jun 12th, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.10 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Copyright (c) 2021-2025 tteck
  4. # Author: tteck (tteckster)
  5. # Jon Spriggs (jontheniceguy)
  6. # License: MIT
  7. # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
  8. # Based on work from https://i12bretro.github.io/tutorials/0405.html
  9.  
  10. source /dev/stdin <<<$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func)
  11.  
  12. function header_info {
  13. clear
  14. cat <<"EOF"
  15. ____ _ __ __
  16. / __ \____ ___ ____| | / /____/ /_
  17. / / / / __ \/ _ \/ __ \ | /| / / ___/ __/
  18. / /_/ / /_/ / __/ / / / |/ |/ / / / /_
  19. \____/ .___/\___/_/ /_/|__/|__/_/ \__/
  20. /_/ W I R E L E S S F R E E D O M
  21.  
  22. EOF
  23. }
  24. header_info
  25. echo -e "Loading..."
  26. RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
  27. METHOD=""
  28. NSAPP="openwrt-vm"
  29. var_os="openwrt"
  30. var_version=" "
  31. DISK_SIZE="0.5G"
  32. GEN_MAC=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//')
  33. GEN_MAC_LAN=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//')
  34.  
  35. YW=$(echo "\033[33m")
  36. BL=$(echo "\033[36m")
  37. HA=$(echo "\033[1;34m")
  38. RD=$(echo "\033[01;31m")
  39. BGN=$(echo "\033[4;92m")
  40. GN=$(echo "\033[1;92m")
  41. DGN=$(echo "\033[32m")
  42. CL=$(echo "\033[m")
  43. BFR="\\r\\033[K"
  44. HOLD="-"
  45. CM="${GN}✓${CL}"
  46. CROSS="${RD}✗${CL}"
  47. set -Eeo pipefail
  48. trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
  49. trap cleanup EXIT
  50. trap 'post_update_to_api "failed" "INTERRUPTED"' SIGINT
  51. trap 'post_update_to_api "failed" "TERMINATED"' SIGTERM
  52. function error_handler() {
  53. local exit_code="$?"
  54. local line_number="$1"
  55. local command="$2"
  56. post_update_to_api "failed" "$command"
  57. local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
  58. echo -e "\n$error_message\n"
  59. cleanup_vmid
  60. }
  61.  
  62. function get_valid_nextid() {
  63. local try_id
  64. try_id=$(pvesh get /cluster/nextid)
  65. while true; do
  66. if [ -f "/etc/pve/qemu-server/${try_id}.conf" ] || [ -f "/etc/pve/lxc/${try_id}.conf" ]; then
  67. try_id=$((try_id + 1))
  68. continue
  69. fi
  70. if lvs --noheadings -o lv_name | grep -qE "(^|[-_])${try_id}($|[-_])"; then
  71. try_id=$((try_id + 1))
  72. continue
  73. fi
  74. break
  75. done
  76. echo "$try_id"
  77. }
  78.  
  79. function cleanup_vmid() {
  80. if qm status $VMID &>/dev/null; then
  81. qm stop $VMID &>/dev/null
  82. qm destroy $VMID &>/dev/null
  83. fi
  84. }
  85.  
  86. function cleanup() {
  87. popd >/dev/null
  88. rm -rf $TEMP_DIR
  89. }
  90.  
  91. TEMP_DIR=$(mktemp -d)
  92. pushd $TEMP_DIR >/dev/null
  93. function send_line_to_vm() {
  94. echo -e "${DGN}Sending line: ${YW}$1${CL}"
  95. for ((i = 0; i < ${#1}; i++)); do
  96. character=${1:i:1}
  97. case $character in
  98. " ") character="spc" ;;
  99. "-") character="minus" ;;
  100. "=") character="equal" ;;
  101. ",") character="comma" ;;
  102. ".") character="dot" ;;
  103. "/") character="slash" ;;
  104. "'") character="apostrophe" ;;
  105. ";") character="semicolon" ;;
  106. '\') character="backslash" ;;
  107. '`') character="grave_accent" ;;
  108. "[") character="bracket_left" ;;
  109. "]") character="bracket_right" ;;
  110. "_") character="shift-minus" ;;
  111. "+") character="shift-equal" ;;
  112. "?") character="shift-slash" ;;
  113. "<") character="shift-comma" ;;
  114. ">") character="shift-dot" ;;
  115. '"') character="shift-apostrophe" ;;
  116. ":") character="shift-semicolon" ;;
  117. "|") character="shift-backslash" ;;
  118. "~") character="shift-grave_accent" ;;
  119. "{") character="shift-bracket_left" ;;
  120. "}") character="shift-bracket_right" ;;
  121. "A") character="shift-a" ;;
  122. "B") character="shift-b" ;;
  123. "C") character="shift-c" ;;
  124. "D") character="shift-d" ;;
  125. "E") character="shift-e" ;;
  126. "F") character="shift-f" ;;
  127. "G") character="shift-g" ;;
  128. "H") character="shift-h" ;;
  129. "I") character="shift-i" ;;
  130. "J") character="shift-j" ;;
  131. "K") character="shift-k" ;;
  132. "L") character="shift-l" ;;
  133. "M") character="shift-m" ;;
  134. "N") character="shift-n" ;;
  135. "O") character="shift-o" ;;
  136. "P") character="shift-p" ;;
  137. "Q") character="shift-q" ;;
  138. "R") character="shift-r" ;;
  139. "S") character="shift-s" ;;
  140. "T") character="shift-t" ;;
  141. "U") character="shift-u" ;;
  142. "V") character="shift-v" ;;
  143. "W") character="shift-w" ;;
  144. "X") character="shift=x" ;;
  145. "Y") character="shift-y" ;;
  146. "Z") character="shift-z" ;;
  147. "!") character="shift-1" ;;
  148. "@") character="shift-2" ;;
  149. "#") character="shift-3" ;;
  150. '$') character="shift-4" ;;
  151. "%") character="shift-5" ;;
  152. "^") character="shift-6" ;;
  153. "&") character="shift-7" ;;
  154. "*") character="shift-8" ;;
  155. "(") character="shift-9" ;;
  156. ")") character="shift-0" ;;
  157. esac
  158. qm sendkey $VMID "$character"
  159. done
  160. qm sendkey $VMID ret
  161. }
  162.  
  163. TEMP_DIR=$(mktemp -d)
  164. pushd $TEMP_DIR >/dev/null
  165.  
  166. if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "OpenWrt VM" --yesno "This will create a New OpenWrt VM. Proceed?" 10 58); then
  167. :
  168. else
  169. header_info && echo -e "⚠ User exited script \n" && exit
  170. fi
  171.  
  172. function msg_info() {
  173. local msg="$1"
  174. echo -ne " ${HOLD} ${YW}${msg}..."
  175. }
  176.  
  177. function msg_ok() {
  178. local msg="$1"
  179. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  180. }
  181.  
  182. function msg_error() {
  183. local msg="$1"
  184. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  185. }
  186.  
  187. function pve_check() {
  188. if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then
  189. msg_error "This version of Proxmox Virtual Environment is not supported"
  190. echo -e "Requires Proxmox Virtual Environment Version 8.1 or later."
  191. echo -e "Exiting..."
  192. sleep 2
  193. exit
  194. fi
  195. }
  196.  
  197. function arch_check() {
  198. if [ "$(dpkg --print-architecture)" != "amd64" ]; then
  199. echo -e "\n ${CROSS} This script will not work with PiMox! \n"
  200. echo -e "Exiting..."
  201. sleep 2
  202. exit
  203. fi
  204. }
  205.  
  206. function ssh_check() {
  207. if command -v pveversion >/dev/null 2>&1; then
  208. if [ -n "${SSH_CLIENT:+x}" ]; then
  209. if whiptail --backtitle "Proxmox VE Helper Scripts" --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
  210. echo "you've been warned"
  211. else
  212. clear
  213. exit
  214. fi
  215. fi
  216. fi
  217. }
  218.  
  219. function exit-script() {
  220. clear
  221. echo -e "⚠ User exited script \n"
  222. exit
  223. }
  224.  
  225. function default_settings() {
  226. VMID=$(get_valid_nextid)
  227. HN=openwrt
  228. CORE_COUNT="1"
  229. RAM_SIZE="256"
  230. BRG="vmbr0"
  231. VLAN=""
  232. MAC=$GEN_MAC
  233. LAN_MAC=$GEN_MAC_LAN
  234. LAN_BRG="vmbr0"
  235. LAN_IP_ADDR="192.168.1.1"
  236. LAN_NETMASK="255.255.255.0"
  237. LAN_VLAN=",tag=999"
  238. MTU=""
  239. START_VM="yes"
  240. METHOD="default"
  241. echo -e "${DGN}Using Virtual Machine ID: ${BGN}${VMID}${CL}"
  242. echo -e "${DGN}Using Hostname: ${BGN}${HN}${CL}"
  243. echo -e "${DGN}Allocated Cores: ${BGN}${CORE_COUNT}${CL}"
  244. echo -e "${DGN}Allocated RAM: ${BGN}${RAM_SIZE}${CL}"
  245. echo -e "${DGN}Using WAN Bridge: ${BGN}${BRG}${CL}"
  246. echo -e "${DGN}Using WAN VLAN: ${BGN}Default${CL}"
  247. echo -e "${DGN}Using WAN MAC Address: ${BGN}${MAC}${CL}"
  248. echo -e "${DGN}Using LAN MAC Address: ${BGN}${LAN_MAC}${CL}"
  249. echo -e "${DGN}Using LAN Bridge: ${BGN}${LAN_BRG}${CL}"
  250. echo -e "${DGN}Using LAN VLAN: ${BGN}999${CL}"
  251. echo -e "${DGN}Using LAN IP Address: ${BGN}${LAN_IP_ADDR}${CL}"
  252. echo -e "${DGN}Using LAN NETMASK: ${BGN}${LAN_NETMASK}${CL}"
  253. echo -e "${DGN}Using Interface MTU Size: ${BGN}Default${CL}"
  254. echo -e "${DGN}Start VM when completed: ${BGN}yes${CL}"
  255. echo -e "${BL}Creating a OpenWrt VM using the above default settings${CL}"
  256. }
  257.  
  258. function advanced_settings() {
  259. METHOD="advanced"
  260. [ -z "${VMID:-}" ] && VMID=$(get_valid_nextid)
  261. while true; do
  262. if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $VMID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
  263. if [ -z "$VMID" ]; then
  264. VMID=$(get_valid_nextid)
  265. fi
  266. if pct status "$VMID" &>/dev/null || qm status "$VMID" &>/dev/null; then
  267. echo -e "${CROSS}${RD} ID $VMID is already in use${CL}"
  268. sleep 2
  269. continue
  270. fi
  271. echo -e "${DGN}Virtual Machine ID: ${BGN}$VMID${CL}"
  272. break
  273. else
  274. exit-script
  275. fi
  276. done
  277.  
  278. if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 openwrt --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
  279. if [ -z $VM_NAME ]; then
  280. HN="openwrt"
  281. else
  282. HN=$(echo ${VM_NAME,,} | tr -d ' ')
  283. fi
  284. echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  285. else
  286. exit-script
  287. fi
  288.  
  289. if CORE_COUNT=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate CPU Cores" 8 58 1 --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
  290. if [ -z $CORE_COUNT ]; then
  291. CORE_COUNT="1"
  292. fi
  293. echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
  294. else
  295. exit-script
  296. fi
  297.  
  298. if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 256 --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
  299. if [ -z $RAM_SIZE ]; then
  300. RAM_SIZE="256"
  301. fi
  302. echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
  303. else
  304. exit-script
  305. fi
  306.  
  307. if BRG=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a WAN Bridge" 8 58 vmbr0 --title "WAN BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
  308. if [ -z $BRG ]; then
  309. BRG="vmbr0"
  310. fi
  311. echo -e "${DGN}Using WAN Bridge: ${BGN}$BRG${CL}"
  312. else
  313. exit-script
  314. fi
  315.  
  316. if LAN_BRG=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a LAN Bridge" 8 58 vmbr0 --title "LAN BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
  317. if [ -z $LAN_BRG ]; then
  318. LAN_BRG="vmbr0"
  319. fi
  320. echo -e "${DGN}Using LAN Bridge: ${BGN}$LAN_BRG${CL}"
  321. else
  322. exit-script
  323. fi
  324.  
  325. if LAN_IP_ADDR=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a router IP" 8 58 $LAN_IP_ADDR --title "LAN IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
  326. if [ -z $LAN_IP_ADDR ]; then
  327. LAN_IP_ADDR="192.168.1.1"
  328. fi
  329. echo -e "${DGN}Using LAN IP ADDRESS: ${BGN}$LAN_IP_ADDR${CL}"
  330. else
  331. exit-script
  332. fi
  333.  
  334. if LAN_NETMASK=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a router netmask" 8 58 $LAN_NETMASK --title "LAN NETMASK" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
  335. if [ -z $LAN_NETMASK ]; then
  336. LAN_NETMASK="255.255.255.0"
  337. fi
  338. echo -e "${DGN}Using LAN NETMASK: ${BGN}$LAN_NETMASK${CL}"
  339. else
  340. exit-script
  341. fi
  342.  
  343. if MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --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
  344. if [ -z $MAC1 ]; then
  345. MAC="$GEN_MAC"
  346. else
  347. MAC="$MAC1"
  348. fi
  349. echo -e "${DGN}Using WAN MAC Address: ${BGN}$MAC${CL}"
  350. else
  351. exit-script
  352. fi
  353.  
  354. if MAC2=$(whiptail --backtitle "Proxmox VE Helper Scripts" --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
  355. if [ -z $MAC2 ]; then
  356. LAN_MAC="$GEN_MAC_LAN"
  357. else
  358. LAN_MAC="$MAC2"
  359. fi
  360. echo -e "${DGN}Using LAN MAC Address: ${BGN}$LAN_MAC${CL}"
  361. else
  362. exit-script
  363. fi
  364.  
  365. if VLAN1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a WAN Vlan (leave blank for default)" 8 58 --title "WAN VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
  366. if [ -z $VLAN1 ]; then
  367. VLAN1="Default"
  368. VLAN=""
  369. else
  370. VLAN=",tag=$VLAN1"
  371. fi
  372. echo -e "${DGN}Using WAN Vlan: ${BGN}$VLAN1${CL}"
  373. else
  374. exit-script
  375. fi
  376.  
  377. if VLAN2=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a LAN Vlan" 8 58 999 --title "LAN VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
  378. if [ -z $VLAN2 ]; then
  379. VLAN2="999"
  380. LAN_VLAN=",tag=$VLAN2"
  381. else
  382. LAN_VLAN=",tag=$VLAN2"
  383. fi
  384. echo -e "${DGN}Using LAN Vlan: ${BGN}$VLAN2${CL}"
  385. else
  386. exit-script
  387. fi
  388.  
  389. if MTU1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --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
  390. if [ -z $MTU1 ]; then
  391. MTU1="Default"
  392. MTU=""
  393. else
  394. MTU=",mtu=$MTU1"
  395. fi
  396. echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}"
  397. else
  398. exit-script
  399. fi
  400.  
  401. if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "START VIRTUAL MACHINE" --yesno "Start VM when completed?" 10 58); then
  402. START_VM="yes"
  403. else
  404. START_VM="no"
  405. fi
  406. echo -e "${DGN}Start VM when completed: ${BGN}$START_VM${CL}"
  407.  
  408. if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create OpenWrt VM?" --no-button Do-Over 10 58); then
  409. echo -e "${RD}Creating a OpenWrt VM using the above advanced settings${CL}"
  410. else
  411. header_info
  412. echo -e "${RD}Using Advanced Settings${CL}"
  413. advanced_settings
  414. fi
  415. }
  416.  
  417. function start_script() {
  418. if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
  419. header_info
  420. echo -e "${BL}Using Default Settings${CL}"
  421. default_settings
  422. else
  423. header_info
  424. echo -e "${RD}Using Advanced Settings${CL}"
  425. advanced_settings
  426. fi
  427. }
  428.  
  429. arch_check
  430. pve_check
  431. ssh_check
  432. start_script
  433. post_to_api_vm
  434.  
  435. msg_info "Validating Storage"
  436. while read -r line; do
  437. TAG=$(echo $line | awk '{print $1}')
  438. TYPE=$(echo $line | awk '{printf "%-10s", $2}')
  439. FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}')
  440. ITEM=" Type: $TYPE Free: $FREE "
  441. OFFSET=2
  442. if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
  443. MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET))
  444. fi
  445. STORAGE_MENU+=("$TAG" "$ITEM" "OFF")
  446. done < <(pvesm status -content images | awk 'NR>1')
  447. VALID=$(pvesm status -content images | awk 'NR>1')
  448. if [ -z "$VALID" ]; then
  449. echo -e "\n${RD}⚠ Unable to detect a valid storage location.${CL}"
  450. echo -e "Exiting..."
  451. exit
  452. elif [ $((${#STORAGE_MENU[@]} / 3)) -eq 1 ]; then
  453. STORAGE=${STORAGE_MENU[0]}
  454. else
  455. while [ -z "${STORAGE:+x}" ]; do
  456. STORAGE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Storage Pools" --radiolist \
  457. "Which storage pool would you like to use for the OpenWrt VM?\n\n" \
  458. 16 $(($MSG_MAX_LENGTH + 23)) 6 \
  459. "${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3)
  460. done
  461. fi
  462. msg_ok "Using ${CL}${BL}$STORAGE${CL} ${GN}for Storage Location."
  463. msg_ok "Virtual Machine ID is ${CL}${BL}$VMID${CL}."
  464. msg_info "Getting URL for OpenWrt Disk Image"
  465.  
  466. response=$(curl -fsSL https://openwrt.org)
  467. stableversion=$(echo "$response" | sed -n 's/.*Current stable release - OpenWrt \([0-9.]\+\).*/\1/p' | head -n 1)
  468. URL="https://downloads.openwrt.org/releases/$stableversion/targets/x86/64/openwrt-$stableversion-x86-64-generic-ext4-combined.img.gz"
  469.  
  470. sleep 2
  471. msg_ok "${CL}${BL}${URL}${CL}"
  472. curl -f#SL -o "$(basename "$URL")" "$URL"
  473. echo -en "\e[1A\e[0K"
  474. FILE=$(basename $URL)
  475. msg_ok "Downloaded ${CL}${BL}$FILE${CL}"
  476. gunzip -f $FILE >/dev/null 2>/dev/null || true
  477. NEWFILE="${FILE%.*}"
  478. FILE="$NEWFILE"
  479. mv $FILE ${FILE%.*}
  480. qemu-img resize -f raw ${FILE%.*} 512M >/dev/null 2>/dev/null
  481. msg_ok "Extracted & Resized OpenWrt Disk Image ${CL}${BL}$FILE${CL}"
  482. STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}')
  483. case $STORAGE_TYPE in
  484. nfs | dir)
  485. DISK_EXT=".qcow2"
  486. DISK_REF="$VMID/"
  487. DISK_IMPORT="-format qcow2"
  488. ;;
  489. btrfs)
  490. DISK_EXT=".raw"
  491. DISK_REF="$VMID/"
  492. DISK_IMPORT="-format raw"
  493. ;;
  494. esac
  495. for i in {0,1}; do
  496. disk="DISK$i"
  497. eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-}
  498. eval DISK${i}_REF=${STORAGE}:${DISK_REF:-}${!disk}
  499. done
  500.  
  501. msg_info "Creating OpenWrt VM"
  502. qm create $VMID -cores $CORE_COUNT -memory $RAM_SIZE -name $HN \
  503. -onboot 1 -ostype l26 -scsihw virtio-scsi-pci --tablet 0
  504. pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null
  505. qm importdisk $VMID ${FILE%.*} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null
  506. qm set $VMID \
  507. -efidisk0 ${DISK0_REF},efitype=4m,size=4M \
  508. -scsi0 ${DISK1_REF},size=512M \
  509. -boot order=scsi0 \
  510. -tags community-script \
  511. -description "<div align='center'><a href='https://Helper-Scripts.com'><img src='https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/images/logo-81x112.png'/></a>
  512.  
  513. # OpenWrt
  514.  
  515. <a href='https://ko-fi.com/D1D7EP4GF'><img src='https://img.shields.io/badge/&#x2615;-Buy me a coffee-blue' /></a>
  516. </div>" >/dev/null
  517. msg_ok "Created OpenWrt VM ${CL}${BL}(${HN})"
  518. msg_info "OpenWrt is being started in order to configure the network interfaces."
  519. qm start $VMID
  520. sleep 15
  521. msg_ok "Network interfaces are being configured as OpenWrt initiates."
  522. send_line_to_vm ""
  523. send_line_to_vm "uci delete network.@device[0]"
  524. send_line_to_vm "uci set network.wan=interface"
  525. send_line_to_vm "uci set network.wan.device=eth1"
  526. send_line_to_vm "uci set network.wan.proto=dhcp"
  527. send_line_to_vm "uci delete network.lan"
  528. send_line_to_vm "uci set network.lan=interface"
  529. send_line_to_vm "uci set network.lan.device=eth0"
  530. send_line_to_vm "uci set network.lan.proto=static"
  531. send_line_to_vm "uci set network.lan.ipaddr=${LAN_IP_ADDR}"
  532. send_line_to_vm "uci set network.lan.netmask=${LAN_NETMASK}"
  533. send_line_to_vm "uci commit"
  534. send_line_to_vm "halt"
  535. msg_ok "Network interfaces have been successfully configured."
  536. until qm status $VMID | grep -q "stopped"; do
  537. sleep 2
  538. done
  539. msg_info "Bridge interfaces are being added."
  540. qm set $VMID \
  541. -net0 virtio,bridge=${LAN_BRG},macaddr=${LAN_MAC}${LAN_VLAN}${MTU} \
  542. -net1 virtio,bridge=${BRG},macaddr=${MAC}${VLAN}${MTU} >/dev/null 2>/dev/null
  543. msg_ok "Bridge interfaces have been successfully added."
  544. if [ "$START_VM" == "yes" ]; then
  545. msg_info "Starting OpenWrt VM"
  546. qm start $VMID
  547. msg_ok "Started OpenWrt VM"
  548. fi
  549. VLAN_FINISH=""
  550. if [ "$VLAN" == "" ] && [ "$VLAN2" != "999" ]; then
  551. VLAN_FINISH=" Please remember to adjust the VLAN tags to suit your network."
  552. fi
  553. post_update_to_api "done" "none"
  554. msg_ok "Completed Successfully!\n${VLAN_FINISH}"
  555.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement