forked from OpenGG/docker-aria2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_aria2.sh
232 lines (209 loc) · 6.13 KB
/
build_aria2.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/env bash
#===========================================================
# https://github.com/P3TERX/aria2-builder
# File name: aria2-gnu-linux-build.sh
# Description: Build aria2 on the target architecture
# System Required: Debian & Ubuntu & Fedora & Arch Linux
# Lisence: GPLv3
# Version: 1.3
# Author: P3TERX
# Blog: https://p3terx.com (chinese)
#===========================================================
set -e
[ $EUID != 0 ] && SUDO=sudo
$SUDO echo
## DEPENDENCES ##
ZLIB='https://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz'
EXPAT='https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.bz2'
C_ARES='https://c-ares.haxx.se/download/c-ares-1.16.0.tar.gz'
OPENSSL='https://www.openssl.org/source/openssl-1.1.1f.tar.gz'
SQLITE3='https://www.sqlite.org/2020/sqlite-autoconf-3310100.tar.gz'
LIBSSH2='https://www.libssh2.org/download/libssh2-1.9.0.tar.gz'
## CONFIG ##
ARCH="$(uname -m)"
OPENSSL_ARCH="linux-x86_64"
BUILD_DIR="/tmp"
OUTPUT_DIR="$HOME/output"
PREFIX="$BUILD_DIR/aria2-build-libs"
ARIA2_PREFIX="/usr/local"
export CURL_CA_BUNDLE="/etc/ssl/certs/ca-certificates.crt"
export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig"
export LD_LIBRARY_PATH="$PREFIX/lib"
export CC="gcc"
export CXX="g++"
export STRIP="strip"
export RANLIB="ranlib"
export AR="ar"
export LD="ld"
DEBIAN_INSTALL() {
$SUDO apt-get update
$SUDO apt-get -y install build-essential git curl ca-certificates \
libxml2-dev libcppunit-dev autoconf automake autotools-dev autopoint libtool pkg-config
}
FEDORA_INSTALL() {
$SUDO dnf install -y make gcc gcc-c++ kernel-devel libgcrypt-devel git curl ca-certificates bzip2 xz findutils \
libxml2-devel cppunit autoconf automake gettext-devel libtool pkg-config dpkg
}
ARCH_INSTALL() {
$SUDO pacman -Syu --noconfirm base-devel git dpkg
}
TOOLCHAIN() {
if [ -x "$(command -v apt-get)" ]; then
DEBIAN_INSTALL
elif [ -x "$(command -v dnf)" ]; then
FEDORA_INSTALL
elif [ -x "$(command -v pacman)" ]; then
ARCH_INSTALL
else
echo -e "This operating system is not supported !"
exit 1
fi
}
ZLIB_BUILD() {
mkdir -p $BUILD_DIR/zlib && cd $BUILD_DIR/zlib
curl -Ls -o - "$ZLIB" | tar zxvf - --strip-components=1
./configure \
--prefix=$PREFIX \
--static
make install -j$(nproc)
}
EXPAT_BUILD() {
mkdir -p $BUILD_DIR/expat && cd $BUILD_DIR/expat
curl -Ls -o - "$EXPAT" | tar jxvf - --strip-components=1
./configure \
--prefix=$PREFIX \
--enable-static \
--enable-shared
make install -j$(nproc)
}
C_ARES_BUILD() {
mkdir -p $BUILD_DIR/c-ares && cd $BUILD_DIR/c-ares
curl -Ls -o - "$C_ARES" | tar zxvf - --strip-components=1
./configure \
--prefix=$PREFIX \
--enable-static \
--disable-shared
make install -j$(nproc)
}
OPENSSL_BUILD() {
mkdir -p $BUILD_DIR/openssl && cd $BUILD_DIR/openssl
curl -Ls -o - "$OPENSSL" | tar zxvf - --strip-components=1
./Configure \
--prefix=$PREFIX \
--openssldir=ssl \
$OPENSSL_ARCH \
no-asm \
shared
make install
}
SQLITE3_BUILD() {
mkdir -p $BUILD_DIR/sqlite3 && cd $BUILD_DIR/sqlite3
curl -Ls -o - "$SQLITE3" | tar zxvf - --strip-components=1
./configure \
--prefix=$PREFIX \
--enable-static \
--enable-shared
make install -j$(nproc)
}
LIBSSH2_BUILD() {
mkdir -p $BUILD_DIR/libssh2 && cd $BUILD_DIR/libssh2
curl -Ls -o - "$LIBSSH2" | tar zxvf - --strip-components=1
rm -rf $PREFIX/lib/pkgconfig/libssh2.pc
./configure \
--prefix=$PREFIX \
--enable-static \
--disable-shared \
CPPFLAGS="-I$PREFIX/include" \
LDFLAGS="-L$PREFIX/lib"
make install -j$(nproc)
}
ARIA2_SRC() {
[ -e $BUILD_DIR/aria2 ] && {
cd $BUILD_DIR/aria2
git reset --hard origin || git reset --hard
git pull
} || {
git clone https://github.com/aria2/aria2 $BUILD_DIR/aria2
cd $BUILD_DIR/aria2
}
sed -i 's#"1", 1, 16, #"1", 1, 4096, #g' ./src/OptionHandlerFactory.cc
sed -i 's#TEXT_MIN_SPLIT_SIZE, "20M", 1_m, 1_g,#TEXT_MIN_SPLIT_SIZE, "20M", 256_k, 1_g,#g' ./src/OptionHandlerFactory.cc
autoreconf -i
$ARIA2_VER=master
}
ARIA2_RELEASE() {
mkdir -p $BUILD_DIR/aria2 && cd $BUILD_DIR/aria2
curl -s 'https://api.github.com/repos/aria2/aria2/releases/latest' |
grep 'browser_download_url.*[0-9]\.tar\.xz' | sed -e 's/^[[:space:]]*//' |
cut -d ' ' -f 2 | xargs -I % curl -Ls -o - '%' | tar Jxvf - --strip-components=1
sed -i 's#"1", 1, 16, #"1", 1, 4096, #g' ./src/OptionHandlerFactory.cc
sed -i 's#TEXT_MIN_SPLIT_SIZE, "20M", 1_m, 1_g,#TEXT_MIN_SPLIT_SIZE, "20M", 256_k, 1_g,#g' ./src/OptionHandlerFactory.cc
}
ARIA2_BUILD() {
ARIA2_RELEASE || ARIA2_SOURCE
./configure \
--prefix=${ARIA2_PREFIX:-'/usr/loacl'} \
--without-libxml2 \
--without-libgcrypt \
--with-openssl \
--without-libnettle \
--without-gnutls \
--without-libgmp \
--with-libssh2 \
--with-sqlite3 \
--with-ca-bundle='/etc/ssl/certs/ca-certificates.crt' \
ARIA2_STATIC=yes \
--enable-shared=no
make -j$(nproc)
}
ARIA2_BIN() {
cd $BUILD_DIR/aria2/src
strip aria2c
mkdir -p $OUTPUT_DIR
cp aria2c $OUTPUT_DIR
}
ARIA2_PACKAGE() {
ARIA2_VER=$($BUILD_DIR/aria2/src/aria2c -v | grep 'aria2 version' | cut -f 3 -d ' ')
dpkgARCH=$(dpkg --print-architecture | awk -F- '{ print $NF }')
cd $BUILD_DIR/aria2/src
strip aria2c
mkdir -p $OUTPUT_DIR
cp aria2c /aria2c
tar zcvf $OUTPUT_DIR/aria2-$ARIA2_VER-static-linux-$dpkgARCH.tar.gz aria2c
}
ARIA2_INSTALL() {
cd $BUILD_DIR/aria2
make install-strip
}
CLEANUP_SRC() {
cd $BUILD_DIR
rm -rf \
zlib \
expat \
c-ares \
openssl \
sqlite3 \
libssh2 \
aria2
}
CLEANUP_LIB() {
rm -rf $PREFIX
}
CLEANUP_ALL() {
CLEANUP_SRC
CLEANUP_LIB
}
## BUILD ##
TOOLCHAIN
ZLIB_BUILD
EXPAT_BUILD
C_ARES_BUILD
OPENSSL_BUILD
SQLITE3_BUILD
LIBSSH2_BUILD
ARIA2_BUILD
#ARIA2_BIN
ARIA2_PACKAGE
#ARIA2_INSTALL
CLEANUP_ALL
echo "finished!"