-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenwrt_auto_install.sh
executable file
·68 lines (48 loc) · 1.77 KB
/
openwrt_auto_install.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
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
pwd_var=$(pwd)
if [ -z "$1" ]; then
echo "Argument 1: Empty router ssh name"
exit 1
fi
if [ -f /usr/bin/apt ]; then
sudo apt update && sudo apt-get install -y make unzip bzip2 build-essential libncurses5-dev libncursesw5-dev
fi
if [ -f /usr/bin/pacman ]; then
sudo pacman -S make wget rsync base-devel unzip python3 python-distutils-extra --noconfirm
fi
ROUTER_NAME=$1
if ! ssh -o StrictHostKeyChecking=no $ROUTER_NAME cat /etc/os-release; then
echo "SSH connection or remote command failed"
exit 1
fi
ROUTER_KERNEL="$(ssh $ROUTER_NAME uname -r)"
ROUTER_OS_RELEASE="$(ssh $ROUTER_NAME cat /etc/os-release)"
VERSION=$(echo "$ROUTER_OS_RELEASE" | grep VERSION | head -n 1 | sed -r 's/.*"([^"]+).*/\1/g')
BOARD=$(echo "$ROUTER_OS_RELEASE" | grep OPENWRT_BOARD | head -n 1 | sed -r 's/.*"([^"]+).*/\1/g')
CONFIGBUILDINFO_URL="https://downloads.openwrt.org/releases/$VERSION/targets/$BOARD/config.buildinfo"
if [ ! -d $pwd_var/openwrt ]; then
git clone https://git.openwrt.org/openwrt/openwrt.git
fi
cd $pwd_var/openwrt
git checkout v$VERSION
wget $CONFIGBUILDINFO_URL -O .config
./scripts/feeds update -a
./scripts/feeds install -a
make defconfig
make -j$(nproc) download
make -j$(nproc) tools/compile
make -j$(nproc) toolchain/compile
make -j$(nproc) target/linux/compile
WIREGUARD_FOLDER=$(find $pwd_var/openwrt -type d | grep "/drivers/net/wireguard" | grep target | head -n 1)
cp $pwd_var/QUICWireGuard.patch $WIREGUARD_FOLDER/QUICWireGuard.patch
cd $WIREGUARD_FOLDER
if [ ! -f QUICWireGuard_tmp ]; then
patch -p1 <QUICWireGuard.patch
touch QUICWireGuard_tmp
fi
cd $pwd_var/openwrt
make -j$(nproc) target/linux/compile
if [ -f $WIREGUARD_FOLDER/wireguard.ko ]; then
scp -O $WIREGUARD_FOLDER/wireguard.ko $ROUTER_NAME:/lib/modules/$ROUTER_KERNEL/
echo "Command succeeded"
fi