-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_build_environment_edit.sh
204 lines (168 loc) · 7.61 KB
/
init_build_environment_edit.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-only
#
# Copyright (C) ImmortalWrt.org
DEFAULT_COLOR="\033[0m"
BLUE_COLOR="\033[36m"
GREEN_COLOR="\033[32m"
RED_COLOR="\033[31m"
YELLOW_COLOR="\033[33m"
function __error_msg() {
echo -e "${RED_COLOR}[ERROR]${DEFAULT_COLOR} $*"
}
function __info_msg() {
echo -e "${BLUE_COLOR}[INFO]${DEFAULT_COLOR} $*"
}
function __success_msg() {
echo -e "${GREEN_COLOR}[SUCCESS]${DEFAULT_COLOR} $*"
}
function __warning_msg() {
echo -e "${YELLOW_COLOR}[WARNING]${DEFAULT_COLOR} $*"
}
function check_system(){
__info_msg "Checking system info..."
UBUNTU_CODENAME="$(source /etc/os-release; echo "$UBUNTU_CODENAME")"
case "$UBUNTU_CODENAME" in
"bionic"|"focal"|"jammy")
# Nothing to do
;;
*)
__error_msg "Unsupported OS, use Ubuntu 20.04 instead."
exit 1
;;
esac
[ "$(uname -m)" != "x86_64" ] && { __error_msg "Unsupported architecture, use AMD64 instead." && exit 1; }
[ "$(whoami)" != "root" ] && { __error_msg "You must run me as root." && exit 1; }
}
function check_network(){
__info_msg "Checking network..."
curl -s "myip.ipip.net" | grep -qo "中国" && CHN_NET=1
curl --connect-timeout 10 "baidu.com" > "/dev/null" 2>&1 || { __warning_msg "Your network is not suitable for compiling OpenWrt!"; }
curl --connect-timeout 10 "google.com" > "/dev/null" 2>&1 || { __warning_msg "Your network is not suitable for compiling OpenWrt!"; }
}
function update_apt_source(){
__info_msg "Updating apt source lists..."
set -x
apt update -y
apt install -y apt-transport-https gnupg2
[ -n "$CHN_NET" ] && {
mv "/etc/apt/sources.list" "/etc/apt/sources.list.bak"
cat <<-EOF >"/etc/apt/sources.list"
deb http://mirrors.tencent.com/ubuntu/ $UBUNTU_CODENAME main restricted universe multiverse
deb http://mirrors.tencent.com/ubuntu/ $UBUNTU_CODENAME-security main restricted universe multiverse
deb http://mirrors.tencent.com/ubuntu/ $UBUNTU_CODENAME-updates main restricted universe multiverse
# deb http://mirrors.tencent.com/ubuntu/ $UBUNTU_CODENAME-proposed main restricted universe multiverse
deb http://mirrors.tencent.com/ubuntu/ $UBUNTU_CODENAME-backports main restricted universe multiverse
deb-src http://mirrors.tencent.com/ubuntu/ $UBUNTU_CODENAME main restricted universe multiverse
deb-src http://mirrors.tencent.com/ubuntu/ $UBUNTU_CODENAME-security main restricted universe multiverse
deb-src http://mirrors.tencent.com/ubuntu/ $UBUNTU_CODENAME-updates main restricted universe multiverse
deb-src http://mirrors.tencent.com/ubuntu/ $UBUNTU_CODENAME-backports main restricted universe multiverse
# deb-src http://mirrors.tencent.com/ubuntu/ $UBUNTU_CODENAME-proposed main restricted universe multiverse
EOF
}
mkdir -p "/etc/apt/sources.list.d"
cat <<-EOF >"/etc/apt/sources.list.d/nodesource.list"
deb https://deb.nodesource.com/node_16.x $UBUNTU_CODENAME main
deb-src https://deb.nodesource.com/node_16.x $UBUNTU_CODENAME main
EOF
curl -sL "https://deb.nodesource.com/gpgkey/nodesource.gpg.key" -o "/etc/apt/trusted.gpg.d/nodesource.asc"
cat <<-EOF >"/etc/apt/sources.list.d/yarn.list"
deb https://dl.yarnpkg.com/debian/ stable main
EOF
curl -sL "https://dl.yarnpkg.com/debian/pubkey.gpg" -o "/etc/apt/trusted.gpg.d/yarn.asc"
cat <<-EOF >"/etc/apt/sources.list.d/gcc-toolchain.list"
deb http://launchpad.proxy.ustclug.org/ubuntu-toolchain-r/test/ubuntu $UBUNTU_CODENAME main
deb-src http://launchpad.proxy.ustclug.org/ubuntu-toolchain-r/test/ubuntu $UBUNTU_CODENAME main
EOF
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x1e9377a2ba9ef27f" -o "/etc/apt/trusted.gpg.d/gcc-toolchain.asc"
cat <<-EOF >"/etc/apt/sources.list.d/llvm-toolchain.list"
deb http://apt.llvm.org/$UBUNTU_CODENAME/ llvm-toolchain-$UBUNTU_CODENAME-13 main
deb-src http://apt.llvm.org/$UBUNTU_CODENAME/ llvm-toolchain-$UBUNTU_CODENAME-13 main
EOF
curl -sL "https://apt.llvm.org/llvm-snapshot.gpg.key" -o "/etc/apt/trusted.gpg.d/llvm-toolchain.asc"
cat <<-EOF >"/etc/apt/sources.list.d/longsleep-ubuntu-golang-backports-$UBUNTU_CODENAME.list"
deb http://launchpad.proxy.ustclug.org/longsleep/golang-backports/ubuntu $UBUNTU_CODENAME main
deb-src http://launchpad.proxy.ustclug.org/longsleep/golang-backports/ubuntu $UBUNTU_CODENAME main
EOF
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x52b59b1571a79dbc054901c0f6bc817356a3d45e" -o "/etc/apt/trusted.gpg.d/longsleep-ubuntu-golang-backports-$UBUNTU_CODENAME.asc"
[ -n "$CHN_NET" ] && sed -i "s,http://launchpad.proxy.ustclug.org,https://launchpad.proxy.ustclug.org,g" "/etc/apt/sources.list.d"/*
apt update -y
set +x
}
function install_dependencies(){
__info_msg "Installing dependencies..."
set -x
apt full-upgrade -y
case "$UBUNTU_CODENAME" in
"bionic") EXTRA_PKG="python python-pip python-ply lib32gcc1" ;;
"focal") EXTRA_PKG="python2.7 lib32gcc1" ;;
"jammy") EXTRA_PKG="python2.7 lib32gcc-s1" ;;
esac
apt install -y $EXTRA_PKG ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \
bzip2 ccache cmake cpio curl device-tree-compiler ecj fakeroot fastjar flex gawk gettext git gperf \
haveged help2man intltool jq libc6-dev-i386 libelf-dev libglib2.0-dev libgmp3-dev libltdl-dev \
libmpc-dev libmpfr-dev libncurses5-dev libncursesw5 libncursesw5-dev libreadline-dev libssl-dev libtool \
libyaml-dev libz-dev lrzsz mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf libpython3-dev \
python3 python3-pip python3-ply python3-docutils qemu-utils quilt re2c rsync scons squashfs-tools \
subversion swig texinfo uglifyjs unzip vim wget xmlto xxd zlib1g-dev
apt install -y gcc-11 g++-11 gcc-11-multilib g++-11-multilib
ln -svf "/usr/bin/gcc-11" "/usr/bin/gcc"
ln -svf "/usr/bin/g++-11" "/usr/bin/g++"
ln -svf "/usr/bin/gcc-ar-11" "/usr/bin/gcc-ar"
ln -svf "/usr/bin/gcc-nm-11" "/usr/bin/gcc-nm"
ln -svf "/usr/bin/gcc-ranlib-11" "/usr/bin/gcc-ranlib"
ln -svf "/usr/include/asm-generic" "/usr/include/asm"
apt install -y clang-13 lldb-13 lld-13 clangd-13
ln -svf "/usr/bin/clang-13" "/usr/bin/clang"
ln -svf "/usr/bin/clangd-13" "/usr/bin/clangd"
ln -svf "/usr/bin/clang++-13" "/usr/bin/clang++"
ln -svf "/usr/bin/clang-cpp-13" "/usr/bin/clang-cpp"
apt install -y nodejs yarn
[ -n "$CHN_NET" ] && {
npm config set registry "https://mirrors.tencent.com/npm/" --global
yarn config set registry "https://mirrors.tencent.com/npm/" --global
}
apt install -y golang-1.18-go
rm -rf "/usr/bin/go" "/usr/bin/gofmt"
ln -svf "/usr/lib/go-1.18/bin/go" "/usr/bin/go"
ln -svf "/usr/lib/go-1.18/bin/gofmt" "/usr/bin/gofmt"
apt clean -y
if TMP_DIR="$(mktemp -d)"; then
pushd "$TMP_DIR"
else
__error_msg "Failed to create a tmp directory."
exit 1
fi
UPX_REV="3.95"
curl -fLO "https://ghproxy.com/https://github.com/upx/upx/releases/download/v${UPX_REV}/upx-$UPX_REV-amd64_linux.tar.xz"
tar -Jxf "upx-$UPX_REV-amd64_linux.tar.xz"
rm -rf "/usr/bin/upx" "/usr/bin/upx-ucl"
cp -fp "upx-$UPX_REV-amd64_linux/upx" "/usr/bin/upx-ucl"
chmod 0755 "/usr/bin/upx-ucl"
ln -svf "/usr/bin/upx-ucl" "/usr/bin/upx"
svn co -r96154 "https://github.com/openwrt/openwrt/trunk/tools/padjffs2/src" "padjffs2"
pushd "padjffs2"
make
rm -rf "/usr/bin/padjffs2"
cp -fp "padjffs2" "/usr/bin/padjffs2"
popd
svn co -r19250 "https://github.com/openwrt/luci/trunk/modules/luci-base/src" "po2lmo"
pushd "po2lmo"
make po2lmo
rm -rf "/usr/bin/po2lmo"
cp -fp "po2lmo" "/usr/bin/po2lmo"
popd
curl -fL "https://build-scripts.immortalwrt.eu.org/modify-firmware.sh" -o "/usr/bin/modify-firmware"
chmod 0755 "/usr/bin/modify-firmware"
popd
rm -rf "$TMP_DIR"
set +x
__success_msg "All dependencies have been installed."
}
function main(){
check_system
check_network
update_apt_source
install_dependencies
}
main