Compare commits

...

2 commits

Author SHA1 Message Date
1be51ac906 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.
2024-09-16 00:51:47 -04:00
0435cc9a2c clean up readme and build script 2024-09-16 00:24:22 -04:00
5 changed files with 89 additions and 43 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# temporary
install_root/

View file

@ -1,6 +1,8 @@
# `nginx-cn` # `nginx-cn`
Our build of NGINX we use. Precompiled with OpenResty core and several other useful modules. Our build of NGINX used on computernewb
Essentially, this is OpenResty core (and a few Lua modules we actually use), and several other useful modules.
# Build/installaction instructions # Build/installaction instructions
@ -8,7 +10,7 @@ Our build of NGINX we use. Precompiled with OpenResty core and several other use
$ 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?
``` ```

62
build
View file

@ -1,16 +1,17 @@
#!/bin/bash #!/bin/bash
# installation prefix. unfortunately we have to vendor . ./config
# certains dependencies (luajit) so this /opt path is
# (probably) going to unfortunately stick.
PREFIX="/opt/nginx"
TOP="$(pwd)"
# clean Nginx sources # make install prefix
[[ ! -d "${INSTALL_PREFIX}" ]] && {
mkdir -p ${INSTALL_PREFIX}
}
# clean Nginx sources beforehand.
pushd sources/nginx/ pushd sources/nginx/
echo "cleaning nginx sources" echo "cleaning nginx sources"
git clean -dxf git clean -dxf
popd popd
BASE_CONFIGURE_FLAGS=( BASE_CONFIGURE_FLAGS=(
@ -57,7 +58,7 @@ BASE_CONFIGURE_FLAGS=(
--with-stream_ssl_preread_module --with-stream_ssl_preread_module
--with-threads --with-threads
# Add modules into the build we use # Add modules into the build
--add-module=$TOP/sources/modules/nginx-module-vts --add-module=$TOP/sources/modules/nginx-module-vts
--add-module=$TOP/sources/modules/ngx-fancyindex --add-module=$TOP/sources/modules/ngx-fancyindex
--add-module=$TOP/sources/modules/lua-nginx-module --add-module=$TOP/sources/modules/lua-nginx-module
@ -65,7 +66,8 @@ BASE_CONFIGURE_FLAGS=(
# --add-module=$TOP/modules/nginx-dav-ext-module # --add-module=$TOP/modules/nginx-dav-ext-module
) )
# Do a dummy config of cloudflare zlib so nginx build can actually distclean and do what it wants.. # Do a dummy config of cloudflare zlib so nginx build can actually distclean (which it does for some reason)..
# I wish it didn't try that but oh well.
pushd $TOP/sources/cf-zlib pushd $TOP/sources/cf-zlib
CFLAGS="-O3 -march=native -mtune=native -pipe -flto=thin -pipe" CC="clang" \ CFLAGS="-O3 -march=native -mtune=native -pipe -flto=thin -pipe" CC="clang" \
./configure ./configure
@ -74,33 +76,34 @@ 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
pushd $TOP/sources/lua-resty-core # resty libs that can be installed
sudo make install PREFIX=$PREFIX RESTY_LIBS=(
popd lua-resty-{core,lrucache,websocket}
)
pushd $TOP/sources/lua-resty-lrucache # install resty libs
sudo make install PREFIX=$PREFIX for lib in ${RESTY_LIBS[@]}; do
popd echo "installing $lib"
pushd $TOP/sources/$lib
pushd $TOP/sources/lua-resty-websocket make install PREFIX=$INSTALL_PREFIX
sudo make install PREFIX=$PREFIX popd
popd 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 \
--prefix=$PREFIX/etc/nginx \ --prefix=$PREFIX/etc/nginx \
--conf-path=$PREFIX/etc/nginx/nginx.conf \ --conf-path=$PREFIX/etc/nginx/nginx.conf \
--sbin-path=$PREFIX/usr/bin/nginx \ --sbin-path=$PREFIX/bin/nginx \
--pid-path=/run/nginx.pid \ --pid-path=/run/nginx.pid \
--lock-path=/run/lock/nginx.lock \ --lock-path=/run/lock/nginx.lock \
--user=http \ --user=http \
@ -116,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
View 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
View file

@ -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."