-
Notifications
You must be signed in to change notification settings - Fork 2
/
wrt.sh
56 lines (43 loc) · 1.41 KB
/
wrt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Define variables
VM_ID=123
VM_NAME="OpenWRT"
VM_MEMORY=256
VM_CPU=1
VM_DISK_SIZE="512M"
VM_NET="model=virtio,bridge=vmbr0"
STORAGE_NAME="local-lvm"
VM_IP="10.10.27.151"
PROXMOX_NODE="PVE"
# Create new VM
qm create $VM_ID --name $VM_NAME --memory $VM_MEMORY --net0 $VM_NET --cores $VM_CPU --ostype l26 --sockets 1
# Remove default hard drive
qm set $VM_ID --scsi0 none
# Lookup the latest stable version number
regex='<strong>Current Stable Release - OpenWrt ([^/]*)<\/strong>'
response=$(curl -s https://openwrt.org)
[[ $response =~ $regex ]]
stableVersion="${BASH_REMATCH[1]}"
# Download openwrt image
wget -O openwrt.img.gz https://downloads.openwrt.org/releases/$stableVersion/targets/x86/64/openwrt-$stableVersion-x86-64-generic-ext4-combined.img.gz
# Extract the openwrt img
gunzip ./openwrt.img.gz
# Rename the extracted img
mv ./openwrt*.img ./openwrt.raw
# Increase the raw disk to 512 MB
qemu-img resize -f raw ./openwrt.raw $VM_DISK_SIZE
# Import the disk to the openwrt vm
qm importdisk $VM_ID openwrt.raw $STORAGE_NAME
# Attach imported disk to VM
qm set $VM_ID --virtio0 $STORAGE_NAME:vm-$VM_ID-disk-0.raw
# Set boot disk
qm set $VM_ID --bootdisk virtio0
# Start the VM
qm start $VM_ID
# SSH into the VM, change IP address, and install Luci
sshpass -p "" ssh -o StrictHostKeyChecking=no root@$VM_IP << EOF
uci set network.lan.ipaddr='$VM_IP'
service network restart
opkg update
opkg install luci
EOF