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`
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
@ -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
$ cd nginx-cn
$ ./build
# ./install
# ... (copy the base config from conf/ into /opt/nginx/etc/nginx and adjust/add to suit your configuration)
# sudo ./install
# ... (adjust the configuration base to suit your needs)
# profit?
```

62
build
View file

@ -1,16 +1,17 @@
#!/bin/bash
# installation prefix. unfortunately we have to vendor
# certains dependencies (luajit) so this /opt path is
# (probably) going to unfortunately stick.
PREFIX="/opt/nginx"
. ./config
TOP="$(pwd)"
# clean Nginx sources
# make install prefix
[[ ! -d "${INSTALL_PREFIX}" ]] && {
mkdir -p ${INSTALL_PREFIX}
}
# clean Nginx sources beforehand.
pushd sources/nginx/
echo "cleaning nginx sources"
git clean -dxf
echo "cleaning nginx sources"
git clean -dxf
popd
BASE_CONFIGURE_FLAGS=(
@ -57,7 +58,7 @@ BASE_CONFIGURE_FLAGS=(
--with-stream_ssl_preread_module
--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/ngx-fancyindex
--add-module=$TOP/sources/modules/lua-nginx-module
@ -65,7 +66,8 @@ BASE_CONFIGURE_FLAGS=(
# --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
CFLAGS="-O3 -march=native -mtune=native -pipe -flto=thin -pipe" CC="clang" \
./configure
@ -74,33 +76,34 @@ popd
# build and install luajit and the resty lua libraries into prefix
pushd $TOP/sources/luajit2
git clean -dxf
make PREFIX=$PREFIX -j49
sudo make PREFIX=$PREFIX install
make PREFIX=$INSTALL_PREFIX -j49
make PREFIX=$INSTALL_PREFIX install
popd
pushd $TOP/sources/lua-resty-core
sudo make install PREFIX=$PREFIX
popd
# resty libs that can be installed
RESTY_LIBS=(
lua-resty-{core,lrucache,websocket}
)
pushd $TOP/sources/lua-resty-lrucache
sudo make install PREFIX=$PREFIX
popd
pushd $TOP/sources/lua-resty-websocket
sudo make install PREFIX=$PREFIX
popd
# install resty libs
for lib in ${RESTY_LIBS[@]}; do
echo "installing $lib"
pushd $TOP/sources/$lib
make install PREFIX=$INSTALL_PREFIX
popd
done
pushd $TOP/sources/nginx
# needed for lua-nginx-module
export LUAJIT_INC="$PREFIX/include/luajit-2.1"
export LUAJIT_LIB="$PREFIX/lib"
export LUAJIT_INC="$INSTALL_PREFIX/include/luajit-2.1"
export LUAJIT_LIB="$INSTALL_PREFIX/lib"
# TODO: see ./install for --sbin-path
./auto/configure \
--prefix=$PREFIX/etc/nginx \
--conf-path=$PREFIX/etc/nginx/nginx.conf \
--sbin-path=$PREFIX/usr/bin/nginx \
--sbin-path=$PREFIX/bin/nginx \
--pid-path=/run/nginx.pid \
--lock-path=/run/lock/nginx.lock \
--user=http \
@ -116,3 +119,12 @@ export LUAJIT_LIB="$PREFIX/lib"
make -j $(($(nproc)+1))
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
# 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"
exit 1
}
# 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. I don't like it.
pushd $TOP/sources
sudo systemctl stop nginx-cn
# strip binary of unneeded fluff (saving the original)
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
# We're replacing an existing installation.
# Make sure not to overwrite a user's existing configuration
[[ -d "${PREFIX}/etc/nginx" ]] && {
echo "You seem to have a configuration in your PREFIX."
echo "I will not touch it."
# 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."