Completely revamp installation script
Instead of cluttering the $PREFIX during build (and requiring root to do so), we now install everything into a temporary directrory that is copied in piecemeal to the prefix). Additionally, the installer will now, on a fresh installation only, copy the base config files from /conf to $PREFIX/etc/nginx. A existing installation will not have this performed (unlike the upstream nginx installation rules), so your configuration will be safe.
This commit is contained in:
parent
0435cc9a2c
commit
1be51ac906
5 changed files with 71 additions and 29 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# temporary
|
||||||
|
install_root/
|
|
@ -10,7 +10,7 @@ Essentially, this is OpenResty core (and a few Lua modules we actually use), and
|
||||||
$ git clone --recursive https://git.computernewb.com/nginx-cn
|
$ git clone --recursive https://git.computernewb.com/nginx-cn
|
||||||
$ cd nginx-cn
|
$ cd nginx-cn
|
||||||
$ ./build
|
$ ./build
|
||||||
# ./install
|
# sudo ./install
|
||||||
# ... (copy the base config from conf/ into /opt/nginx/etc/nginx and adjust/add to suit your configuration)
|
# ... (adjust the configuration base to suit your needs)
|
||||||
# profit?
|
# profit?
|
||||||
```
|
```
|
||||||
|
|
34
build
34
build
|
@ -1,11 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# installation prefix. unfortunately we have to vendor
|
. ./config
|
||||||
# certain dependencies (luajit) so this /opt path is
|
|
||||||
# (probably) going to unfortunately stick.
|
|
||||||
PREFIX="/opt/nginx"
|
|
||||||
|
|
||||||
TOP="$(pwd)"
|
|
||||||
|
# make install prefix
|
||||||
|
[[ ! -d "${INSTALL_PREFIX}" ]] && {
|
||||||
|
mkdir -p ${INSTALL_PREFIX}
|
||||||
|
}
|
||||||
|
|
||||||
# clean Nginx sources beforehand.
|
# clean Nginx sources beforehand.
|
||||||
pushd sources/nginx/
|
pushd sources/nginx/
|
||||||
|
@ -13,7 +14,7 @@ pushd sources/nginx/
|
||||||
git clean -dxf
|
git clean -dxf
|
||||||
popd
|
popd
|
||||||
|
|
||||||
local BASE_CONFIGURE_FLAGS=(
|
BASE_CONFIGURE_FLAGS=(
|
||||||
# Build everything with Clang + ThinLTO
|
# Build everything with Clang + ThinLTO
|
||||||
--with-cc="clang"
|
--with-cc="clang"
|
||||||
--with-cc-opt="-pipe -march=native -mtune=native -flto=thin"
|
--with-cc-opt="-pipe -march=native -mtune=native -flto=thin"
|
||||||
|
@ -75,12 +76,12 @@ popd
|
||||||
# build and install luajit and the resty lua libraries into prefix
|
# build and install luajit and the resty lua libraries into prefix
|
||||||
pushd $TOP/sources/luajit2
|
pushd $TOP/sources/luajit2
|
||||||
git clean -dxf
|
git clean -dxf
|
||||||
make PREFIX=$PREFIX -j49
|
make PREFIX=$INSTALL_PREFIX -j49
|
||||||
sudo make PREFIX=$PREFIX install
|
make PREFIX=$INSTALL_PREFIX install
|
||||||
popd
|
popd
|
||||||
|
|
||||||
# resty libs that can be installed
|
# resty libs that can be installed
|
||||||
local RESTY_LIBS=(
|
RESTY_LIBS=(
|
||||||
lua-resty-{core,lrucache,websocket}
|
lua-resty-{core,lrucache,websocket}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -88,15 +89,15 @@ local RESTY_LIBS=(
|
||||||
for lib in ${RESTY_LIBS[@]}; do
|
for lib in ${RESTY_LIBS[@]}; do
|
||||||
echo "installing $lib"
|
echo "installing $lib"
|
||||||
pushd $TOP/sources/$lib
|
pushd $TOP/sources/$lib
|
||||||
sudo make install PREFIX=$PREFIX
|
make install PREFIX=$INSTALL_PREFIX
|
||||||
popd
|
popd
|
||||||
done
|
done
|
||||||
|
|
||||||
pushd $TOP/sources/nginx
|
pushd $TOP/sources/nginx
|
||||||
|
|
||||||
# needed for lua-nginx-module
|
# needed for lua-nginx-module
|
||||||
export LUAJIT_INC="$PREFIX/include/luajit-2.1"
|
export LUAJIT_INC="$INSTALL_PREFIX/include/luajit-2.1"
|
||||||
export LUAJIT_LIB="$PREFIX/lib"
|
export LUAJIT_LIB="$INSTALL_PREFIX/lib"
|
||||||
|
|
||||||
# TODO: see ./install for --sbin-path
|
# TODO: see ./install for --sbin-path
|
||||||
./auto/configure \
|
./auto/configure \
|
||||||
|
@ -118,3 +119,12 @@ export LUAJIT_LIB="$PREFIX/lib"
|
||||||
|
|
||||||
make -j $(($(nproc)+1))
|
make -j $(($(nproc)+1))
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
# Strip nginx and install it into the staging prefix
|
||||||
|
pushd $TOP/sources
|
||||||
|
cp nginx/objs/nginx nginx/objs/nginx.unstripped
|
||||||
|
strip nginx/objs/nginx
|
||||||
|
|
||||||
|
[[ ! -d "${INSTALL_PREFIX}/bin" ]] && mkdir -p ${INSTALL_PREFIX}/bin
|
||||||
|
cp nginx/objs/nginx $INSTALL_PREFIX/bin/nginx
|
||||||
|
popd
|
||||||
|
|
13
config
Normal file
13
config
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Shared configuration for build/install scripts
|
||||||
|
|
||||||
|
# Installation prefix. unfortunately we have to vendor
|
||||||
|
# certain dependencies (luajit) for OpenResty,
|
||||||
|
# so this /opt path is going to unfortunately stick
|
||||||
|
# Change to what you like I suppose, but make sure to update the systemd files..
|
||||||
|
PREFIX="/opt/nginx"
|
||||||
|
|
||||||
|
TOP="$(pwd)"
|
||||||
|
|
||||||
|
# The staging prefix used to install everything before actually installing it to
|
||||||
|
# $PREFIX.
|
||||||
|
INSTALL_PREFIX="${TOP}/install_root"
|
47
install
47
install
|
@ -1,23 +1,40 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Installs nginx-cn
|
# Installs nginx-cn into the configured PREFIX.
|
||||||
|
#
|
||||||
|
# N.B: We do not use nginx's `make install` because it's very very bad
|
||||||
|
# and it overwrites $PREFIX/etc unconditionally. It's bad design choice,
|
||||||
|
# and I personally do not like it.
|
||||||
|
|
||||||
TOP="$(pwd)"
|
. ./config
|
||||||
|
|
||||||
[[ ! -d "$TOP/sources/nginx/objs" ]] && {
|
# Check for the install prefix directory. If it doesn't exist,
|
||||||
|
# then a build likely hasn't been done, so we can't proceed.
|
||||||
|
[[ ! -d "${INSTALL_PREFIX}" ]] && {
|
||||||
echo "You haven't built nginx-cn yet. Do so with ./build"
|
echo "You haven't built nginx-cn yet. Do so with ./build"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# N.B: We do not use nginx's `make install` because it's very very bad
|
# We're replacing an existing installation.
|
||||||
# and it overwrites $PREFIX/etc unconditionally. It's bad. I don't like it.
|
# Make sure not to overwrite a user's existing configuration
|
||||||
pushd $TOP/sources
|
[[ -d "${PREFIX}/etc/nginx" ]] && {
|
||||||
sudo systemctl stop nginx-cn
|
echo "You seem to have a configuration in your PREFIX."
|
||||||
# strip binary of unneeded fluff (saving the original)
|
echo "I will not touch it."
|
||||||
cp nginx/objs/nginx nginx/objs/nginx.unstripped
|
|
||||||
strip nginx/objs/nginx
|
|
||||||
sudo cp nginx/objs/nginx /opt/nginx/bin
|
|
||||||
sudo systemctl start nginx-cn
|
|
||||||
#sudo make install
|
|
||||||
echo "Binary installed. You should probably copy the sample configuration to /opt/nginx/etc/nginx."
|
|
||||||
popd
|
|
||||||
|
|
||||||
|
# Remove old files and replace them with the install prefix versions
|
||||||
|
rm -rf ${PREFIX}/{bin,lib,share}
|
||||||
|
cp -r ${INSTALL_PREFIX}/bin ${PREFIX}/bin
|
||||||
|
cp -r ${INSTALL_PREFIX}/lib ${PREFIX}/lib
|
||||||
|
cp -r ${INSTALL_PREFIX}/share ${PREFIX}/share
|
||||||
|
}
|
||||||
|
|
||||||
|
# A new installation.
|
||||||
|
# We SHOULD copy over the configuration now.
|
||||||
|
[[ ! -d "${PREFIX}" ]] && {
|
||||||
|
mkdir -p ${PREFIX} ${PREFIX}/etc/nginx
|
||||||
|
cp -r ${INSTALL_PREFIX}/bin ${PREFIX}/bin
|
||||||
|
cp -r ${INSTALL_PREFIX}/lib ${PREFIX}/lib
|
||||||
|
cp -r ${INSTALL_PREFIX}/share ${PREFIX}/share
|
||||||
|
cp -r ${TOP}/conf ${PREFIX}/etc/nginx/
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "nginx-cn has been installed/updated."
|
||||||
|
|
Loading…
Reference in a new issue