Last active 1725525230

Revision f20d59cedf92c90d991b02ca9e4ee7b62db6e3b3

build.sh Raw
1#!/bin/sh
2routerUser="root"
3version="23.05.1"
4#baseUrl="https://downloads.immortalwrt.org/releases/${version}/targets/x86/64"
5baseUrl="https://immortalwrt.aiursoft.cn/releases/${version}/targets/x86/64" # Use mirror to speed up download
6builderFileName="immortalwrt-imagebuilder-${version}-x86-64.Linux-x86_64.tar.xz"
7pkgConfig="-dnsmasq dnsmasq-full ip-full vim vim-runtime -ethtool ethtool-full \
8kmod-nf-nat kmod-nf-nat6 kmod-tls kmod-nft-arp kmod-nft-compat kmod-nft-connlimit kmod-nft-dup-inet kmod-nft-queue kmod-nft-socket kmod-nft-tproxy kmod-nft-xfrm kmod-nft-offload \
9iptables-nft ip6tables-nft kmod-ipt-nat6 kmod-ipt-nat-extra kmod-ipt-nathelper-rtsp kmod-sched-mqprio kmod-ipt-offload \
10kmod-e1000 kmod-e1000e kmod-igb kmod-ixgbe kmod-ixgbevf kmod-igc \
11pciutils usbutils \
12kmod-usb2 kmod-usb3 usbutils exfat-fsck exfat-mkfs kmod-fs-exfat kmod-usb-storage kmod-usb-storage-extras kmod-usb-storage-uas kmod-usb-serial kmod-usb-hid \
13luci-i18n-opkg-zh-cn luci-i18n-firewall-zh-cn \
14luci-i18n-passwall-zh-cn luci-app-passwall xray-core \
15luci-app-upnp luci-i18n-upnp-zh-cn \
16luci-app-wol luci-i18n-wol-zh-cn \
17luci-app-banip luci-i18n-banip-zh-cn \
18luci-app-watchcat luci-i18n-watchcat-zh-cn \
19luci-app-uhttpd uhttpd \
20luci-theme-bootstrap luci-theme-argon \
21luci-app-statistics luci-i18n-statistics-zh-cn collectd-mod-disk collectd-mod-cpu collectd-mod-cpufreq collectd-mod-df collectd-mod-interface collectd-mod-processes collectd-mod-uptime collectd-mod-vmem collectd-mod-email collectd-mod-ethstat collectd-mod-conntrack collectd-mod-dhcpleases collectd-mod-syslog collectd-mod-write-http collectd-mod-ping collectd-mod-dns collectd-mod-memory collectd-mod-thermal collectd-mod-sensors collectd-mod-smart smartmontools smartmontools-drivedb \
22umdns ca-bundle haveged wget wget-ssl iperf3 telnet-bsd speedtest-cli qrencode lm-sensors-detect lscpu lsblk uhubctl losetup bind-dig httping tcping \
23"
24
25bareMentalPackages="intel-microcode iucode-tool kmod-i2c-i801 kmod-w83627hf-wdt kmod-itco-wdt"
26esxiPackages="kmod-vmxnet3 open-vm-tools open-vm-tools-fuse"
27proxmoxPackages="virtio-console-helper qemu-ga"
28
29echo "# STEP 0. Install prerequisites ..."
30# Needs to run 'make'
31DEBIAN_FRONTEND=noninteractive sudo apt update -y
32DEBIAN_FRONTEND=noninteractive sudo apt install qemu-utils upx-ucl librsync-dev rsync unzip libncurses-dev subversion curl gawk -y
33
34echo "# STEP 1. Gathering information ..."
35echo "What platform are you building for? [Enter 'bare' for bare-metal, 'esxi' for VMware ESXi, 'proxmox' for Proxmox VE]:"
36read platform
37case $platform in
38 bare)
39 pkgConfig="$pkgConfig $bareMentalPackages"
40 ;;
41 esxi)
42 pkgConfig="$pkgConfig $esxiPackages"
43 ;;
44 proxmox)
45 pkgConfig="$pkgConfig $proxmoxPackages"
46 ;;
47 *)
48 echo "Invalid platform. Exiting."
49 exit 1
50 ;;
51esac
52
53echo "# STEP 2. Downloading OpenWrt ${version} Image Builder ..."
54if ! [ -f "./${builderFileName}" ]
55then
56 wget "$baseUrl/$builderFileName" -P .
57fi
58rm -rf ./builder
59mkdir ./builder
60tar xf ./$builderFileName -C ./builder/ --strip-components=1
61cd ./builder
62
63echo "# STEP 3. Preparing to build image ..."
64
65# Change source from https://downloads.immortalwrt.org/ to https://immortalwrt.aiursoft.cn/
66sed -i "s/https:\/\/downloads.immortalwrt.org/https:\/\/immortalwrt.aiursoft.cn/g" ./repositories.conf
67
68# Set grub timeout to 0
69sed -i 's/CONFIG_GRUB_TIMEOUT="[0-9]"/CONFIG_GRUB_TIMEOUT="0"/g' ./.config
70# Image generation config
71#sed -i "s/CONFIG_TARGET_ROOTFS_EXT4FS=y/CONFIG_TARGET_ROOTFS_EXT4FS=n/g" ./.config
72sed -i "s/CONFIG_VHDX_IMAGES=y/CONFIG_VHDX_IMAGES=n/g" ./.config # Disable VHDX because we only need to support bare-metal, ESXi and Proxmox. VHDX is for Hyper-V.
73sed -i "s/CONFIG_QCOW2_IMAGES=y/CONFIG_QCOW2_IMAGES=n/g" ./.config # Disable QCOW2 because we only need to support bare-metal, ESXi and Proxmox. QCOW2 is for KVM.
74sed -i "s/CONFIG_ISO_IMAGES=y/CONFIG_ISO_IMAGES=n/g" ./.config # Disable ISO because we only need to support bare-metal, ESXi and Proxmox. ISO is for CD-ROM.
75#sed -i "s/CONFIG_VMDK_IMAGES=y/CONFIG_VMDK_IMAGES=n/g" ./.config # Enable VMDK because we need to support ESXi and Proxmox. VMDK is for VMware.
76#sed -i "s/CONFIG_VDI_IMAGES=y/CONFIG_VDI_IMAGES=n/g" ./.config # Enable VDI because we need to support VirtualBox. VDI is for VirtualBox.
77
78# Language config
79sed -i "s/# CONFIG_LUCI_LANG_en is not set/CONFIG_LUCI_LANG_en=y/g" ./.config
80
81echo "# STEP 4. Building image ..."
82make image PACKAGES="$pkgConfig" ROOTFS_PARTSIZE=1024 j=32 V=sc
83echo "# DONE. See built images under: ./builder/bin/targets/x86/64/"
84
85if [ "$platform" = "esxi" ]
86then
87 echo "The file you need is with name like 'immortalwrt-${version}-x86-64-generic-ext4-combined-efi.vmdk.gz'."
88 echo "Please unzip it and upload to your ESXi server."
89 echo "You need to create a new virtual machine with the following settings:"
90 echo " - Guest OS: Linux, Version: Other 5.x or later Linux (64-bit)"
91 echo " - Memory: 512MB or more, reserve all guest memory"
92 echo " - Disk: Use existing disk, select the VMDK file you just uploaded, use IDE controller"
93 echo " - Network: Add two new network adapters, pass through to the physical network adapter"
94 echo " - Other settings: Set the boot order to boot from hard disk first"
95 echo " - Other settings: Set the boot mode from BIOS to EFI"
96 echo " - Other settings: Enable IO MMU"
97 echo " - Other settings: Enable Performance counters"
98 echo " - Other settings: Add Precision Clock. (ESXi must synchronize the time with a trusted time source)"
99 echo " - Other settings: Remove the floppy drive & USB controller"
100 echo "And the IP address of the virtual machine will be 192.168.1.1"
101 echo "All interfaces will be bridged as br-lan"
102fi