Skip to content

Commit 473d3fa

Browse files
committed
patch for gcc-8; run the script as normal user with sudo privilege
2 parents ec4110d + ed91155 commit 473d3fa

File tree

3 files changed

+218
-26
lines changed

3 files changed

+218
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This little script compiles Nginx from source with [Brotli](https://opensource.g
66

77
- Debian 9
88
- Ubuntu 16.04 and Ubuntu 18.04
9+
- Linux Mint 19 Tara
910

1011
## Tested Nginx versions
1112

brotli.sh

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# version 1.1
3+
# version 1.2
44

55
# use it while developing / testing.
66
# you may use it in production as well.
@@ -9,10 +9,12 @@
99

1010
# compile Nginx from the official repo with brotli compression
1111

12-
[ ! -d /root/log ] && mkdir /root/log
12+
[ ! -d ${HOME}/log ] && mkdir ${HOME}/log
13+
14+
G_DIR="$(pwd)"
1315

1416
# logging everything
15-
log_file=/root/log/brotli.log
17+
log_file=${HOME}/log/brotli.log
1618
exec > >(tee -a ${log_file} )
1719
exec 2> >(tee -a ${log_file} >&2)
1820

@@ -27,19 +29,18 @@ check_result() {
2729
export DEBIAN_FRONTEND=noninteractive
2830

2931
printf '%-72s' "Updating apt repos..."
30-
apt-get -qq update
32+
sudo apt-get -qq update
3133
echo done.
3234

3335
printf '%-72s' "Installing pre-requisites..."
34-
apt-get -qq install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev unzip
36+
sudo apt-get -qq install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev unzip
3537
echo done.
3638

3739
codename=$(lsb_release -c -s)
3840

3941
# function to add the official Nginx.org repo
4042
nginx_repo_add() {
4143
distro=$(gawk -F= '/^ID=/{print $2}' /etc/os-release)
42-
codename=$(lsb_release -c -s)
4344
if [ "$codename" == "juno" ] ; then
4445
codename=bionic
4546
fi
@@ -48,10 +49,14 @@ nginx_repo_add() {
4849
distro=ubuntu
4950
fi
5051

52+
if [ "$distro" == "linuxmint" ] ; then
53+
distro=ubuntu
54+
fi
55+
5156
[ -f nginx_signing.key ] && rm nginx_signing.key
5257
curl -LSsO http://nginx.org/keys/nginx_signing.key
5358
check_result $? 'Nginx key could not be downloaded!'
54-
apt-key add nginx_signing.key &> /dev/null
59+
sudo apt-key add nginx_signing.key &> /dev/null
5560
check_result $? 'Nginx key could not be added!'
5661
rm nginx_signing.key
5762

@@ -65,12 +70,12 @@ nginx_repo_add() {
6570
nginx_src_url="https://nginx.org/packages/${distro}/"
6671
fi
6772

68-
[ -f /etc/apt/sources.list.d/nginx.list ] && rm /etc/apt/sources.list.d/nginx.list
69-
echo "deb ${nginx_src_url} ${codename} nginx" > /etc/apt/sources.list.d/nginx.list
70-
echo "deb-src ${nginx_src_url} ${codename} nginx" >> /etc/apt/sources.list.d/nginx.list
73+
[ -f /etc/apt/sources.list.d/nginx.list ] && sudo rm /etc/apt/sources.list.d/nginx.list
74+
echo "deb ${nginx_src_url} ${codename} nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
75+
echo "deb-src ${nginx_src_url} ${codename} nginx" | sudo tee -a /etc/apt/sources.list.d/nginx.list
7176

7277
# finally update the local apt cache
73-
apt-get update -qq
78+
sudo apt-get update -qq
7479
check_result $? 'Something went wrong while updating apt repos.'
7580
}
7681

@@ -88,47 +93,67 @@ case "$codename" in
8893
codename=bionic
8994
nginx_repo_add
9095
;;
96+
"tara")
97+
codename=bionic
98+
nginx_repo_add
99+
;;
91100
*)
92101
echo "Distro: $codename"
93102
echo 'Warning: Could not figure out the distribution codename. Continuing to install Nginx from the OS.'
94103
;;
95104
esac
96105

97-
cd /usr/local/src
106+
sudo install -o ${UID} -g $(id -gn $USER) -d /usr/local/src/${USER}
107+
cd /usr/local/src/${USER}
98108
apt-get source nginx
99-
apt-get build-dep nginx -y
109+
sudo apt-get build-dep nginx -y
100110

101111
git clone --recursive https://github.com/eustas/ngx_brotli
102-
103-
cd /usr/local/src/nginx-*/
112+
sudo ln -s /usr/local/src/${USER}/ngx_brotli /usr/local/src/ngx_brotli
113+
sudo chown ${USER}:$USER:$(id -gn $USER) /usr/local/src/ngx_brotli
114+
cd /usr/local/src/${USER}/nginx-*/
104115

105116
# modify the existing config
106-
grep -wq '--add-module=/usr/local/src/ngx_brotli' debian/rules || sed -i -e '/\.\/configure/ s:$: --add-module=/usr/local/src/ngx_brotli:' debian/rules
117+
sed -i -e '/\.\/configure/ s:$: --add-module=/usr/local/src/ngx_brotli:' debian/rules
118+
119+
# if gcc 8 is installed add patch to nginx
120+
if [ "$(gcc -dumpversion)" == "8" ]; then
121+
mkdir -p debian/patches
122+
cp ${G_DIR}/gcc-8_fix.diff debian/patches/gcc-8_fix
123+
echo "gcc-8_fix" > debian/patches/series
124+
fi
107125

108126
# build the updated pacakge
109127
dpkg-buildpackage -b
110128

111129
# optional
112130
# install the updated package in the current server
113-
cd /usr/local/src
114-
dpkg -i nginx*.deb
131+
cd /usr/local/src/${USER}
115132

116133
# take a backup
117134
[ ! -d ~/backups/ ] && mkdir ~/backups
118135
cp nginx*.deb ~/backups/nginx-$(date +%F)/
119136

120-
# remove all the sources and apt sources file
137+
# sudo apt-mark unhold nginx
138+
sudo dpkg -i nginx_*.deb
139+
140+
# print info about remove all the sources and apt sources file
121141
cd ~/
122-
rm -rf /usr/local/src/nginx*
123-
rm -rf /usr/local/src/ngx_brotli
124-
rm /etc/apt/sources.list.d/nginx.list
125-
apt-get -qq update
126142

143+
printf "
144+
# To clean up after install You can run
145+
rm -rf /usr/local/src/$(echo ${USER})/nginx*
146+
rm -rf /usr/local/src/$(echo ${USER})/ngx_brotli
147+
sudo rm /etc/apt/sources.list.d/nginx.list
148+
sudo apt-get -qq update
149+
"
127150
# hold the package nginx from updating accidentally in the future by someone else!
128-
apt-mark hold nginx
151+
sudo apt-mark hold nginx
129152

130153
# stop the previously running instance, if any
131-
nginx -t && systemctl stop nginx
154+
sudo nginx -t && sudo systemctl stop nginx
132155

133156
# start the new Nginx instance
134-
nginx -t && systemctl start nginx
157+
sudo nginx -t && sudo systemctl start nginx
158+
159+

gcc-8_fix.diff

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
Index: src/http/modules/ngx_http_fastcgi_module.c
2+
===================================================================
3+
--- a/src/http/modules/ngx_http_fastcgi_module.c
4+
+++ b/src/http/modules/ngx_http_fastcgi_module.c
5+
@@ -3265,5 +3265,6 @@
6+
}
7+
8+
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
9+
+ copy->code = (ngx_http_script_code_pt) (void *)
10+
+ ngx_http_script_copy_len_code;
11+
copy->len = src[i].key.len;
12+
13+
@@ -3274,5 +3275,6 @@
14+
}
15+
16+
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
17+
+ copy->code = (ngx_http_script_code_pt) (void *)
18+
+ ngx_http_script_copy_len_code;
19+
copy->len = src[i].skip_empty;
20+
21+
22+
Index: src/http/modules/ngx_http_grpc_module.c
23+
===================================================================
24+
--- a/src/http/modules/ngx_http_grpc_module.c
25+
+++ b/src/http/modules/ngx_http_grpc_module.c
26+
@@ -4390,5 +4390,6 @@
27+
}
28+
29+
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
30+
+ copy->code = (ngx_http_script_code_pt) (void *)
31+
+ ngx_http_script_copy_len_code;
32+
copy->len = src[i].key.len;
33+
34+
35+
Index: src/http/modules/ngx_http_proxy_module.c
36+
===================================================================
37+
--- a/src/http/modules/ngx_http_proxy_module.c
38+
+++ b/src/http/modules/ngx_http_proxy_module.c
39+
@@ -3494,5 +3494,6 @@
40+
}
41+
42+
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
43+
+ copy->code = (ngx_http_script_code_pt) (void *)
44+
+ ngx_http_script_copy_len_code;
45+
copy->len = src[i].key.len;
46+
47+
48+
Index: src/http/modules/ngx_http_scgi_module.c
49+
===================================================================
50+
--- a/src/http/modules/ngx_http_scgi_module.c
51+
+++ b/src/http/modules/ngx_http_scgi_module.c
52+
@@ -1725,5 +1725,6 @@
53+
}
54+
55+
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
56+
+ copy->code = (ngx_http_script_code_pt) (void *)
57+
+ ngx_http_script_copy_len_code;
58+
copy->len = src[i].key.len + 1;
59+
60+
@@ -1734,5 +1735,6 @@
61+
}
62+
63+
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
64+
+ copy->code = (ngx_http_script_code_pt) (void *)
65+
+ ngx_http_script_copy_len_code;
66+
copy->len = src[i].skip_empty;
67+
68+
69+
Index: src/http/modules/ngx_http_uwsgi_module.c
70+
===================================================================
71+
--- a/src/http/modules/ngx_http_uwsgi_module.c
72+
+++ b/src/http/modules/ngx_http_uwsgi_module.c
73+
@@ -1988,5 +1988,6 @@
74+
}
75+
76+
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
77+
+ copy->code = (ngx_http_script_code_pt) (void *)
78+
+ ngx_http_script_copy_len_code;
79+
copy->len = src[i].key.len;
80+
81+
@@ -1997,5 +1998,6 @@
82+
}
83+
84+
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
85+
+ copy->code = (ngx_http_script_code_pt) (void *)
86+
+ ngx_http_script_copy_len_code;
87+
copy->len = src[i].skip_empty;
88+
89+
90+
Index: src/http/ngx_http_script.c
91+
===================================================================
92+
--- a/src/http/ngx_http_script.c
93+
+++ b/src/http/ngx_http_script.c
94+
@@ -696,5 +696,6 @@
95+
}
96+
97+
- code->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
98+
+ code->code = (ngx_http_script_code_pt) (void *)
99+
+ ngx_http_script_copy_len_code;
100+
code->len = len;
101+
102+
@@ -785,5 +786,6 @@
103+
}
104+
105+
- code->code = (ngx_http_script_code_pt) ngx_http_script_copy_var_len_code;
106+
+ code->code = (ngx_http_script_code_pt) (void *)
107+
+ ngx_http_script_copy_var_len_code;
108+
code->index = (uintptr_t) index;
109+
110+
@@ -1179,6 +1181,6 @@
111+
}
112+
113+
- code->code = (ngx_http_script_code_pt)
114+
- ngx_http_script_copy_capture_len_code;
115+
+ code->code = (ngx_http_script_code_pt) (void *)
116+
+ ngx_http_script_copy_capture_len_code;
117+
code->n = 2 * n;
118+
119+
@@ -1294,5 +1296,6 @@
120+
}
121+
122+
- code->code = (ngx_http_script_code_pt) ngx_http_script_full_name_len_code;
123+
+ code->code = (ngx_http_script_code_pt) (void *)
124+
+ ngx_http_script_full_name_len_code;
125+
code->conf_prefix = sc->conf_prefix;
126+
127+
128+
Index: src/stream/ngx_stream_script.c
129+
===================================================================
130+
--- a/src/stream/ngx_stream_script.c
131+
+++ b/src/stream/ngx_stream_script.c
132+
@@ -588,5 +588,6 @@
133+
}
134+
135+
- code->code = (ngx_stream_script_code_pt) ngx_stream_script_copy_len_code;
136+
+ code->code = (ngx_stream_script_code_pt) (void *)
137+
+ ngx_stream_script_copy_len_code;
138+
code->len = len;
139+
140+
@@ -678,6 +679,6 @@
141+
}
142+
143+
- code->code = (ngx_stream_script_code_pt)
144+
- ngx_stream_script_copy_var_len_code;
145+
+ code->code = (ngx_stream_script_code_pt) (void *)
146+
+ ngx_stream_script_copy_var_len_code;
147+
code->index = (uintptr_t) index;
148+
149+
@@ -768,6 +769,6 @@
150+
}
151+
152+
- code->code = (ngx_stream_script_code_pt)
153+
- ngx_stream_script_copy_capture_len_code;
154+
+ code->code = (ngx_stream_script_code_pt) (void *)
155+
+ ngx_stream_script_copy_capture_len_code;
156+
code->n = 2 * n;
157+
158+
@@ -860,5 +861,5 @@
159+
}
160+
161+
- code->code = (ngx_stream_script_code_pt)
162+
+ code->code = (ngx_stream_script_code_pt) (void *)
163+
ngx_stream_script_full_name_len_code;
164+
code->conf_prefix = sc->conf_prefix;
165+
166+

0 commit comments

Comments
 (0)