From 7922bbd4d7548e57ab3661d1edc64383e6e10b8a Mon Sep 17 00:00:00 2001 From: iamdoubz <> Date: Thu, 29 Oct 2026 23:33:42 -0500 Subject: [PATCH] Add --purge to delete build folders after install --- README.md | 1 + freenginx.sh | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index d3659c2..69680a1 100644 --- a/README.md +++ b/README.md @@ -46,3 +46,4 @@ Type `which nginx` and make a copy i.e. `sudo cp /usr/sbin/nginx /usr/sbin/nginx 3. Check nginx `sudo nginx -t` 4. Reload nginx `sudo nginx -s reload` 5. Verify new version `sudo nginx -v` should output `nginx version: freenginx/1.29.4 (w/GeoIP2,Brotli,H3,Headers-More,Quantum,debug,KTLS)` +6. Optionally free up disk space with `./freenginx.sh --purge` (same `-r` and versions as the build). It refuses to run if the built binary doesn't match `/usr/sbin/nginx`. diff --git a/freenginx.sh b/freenginx.sh index 0baae9b..8b78836 100644 --- a/freenginx.sh +++ b/freenginx.sh @@ -39,6 +39,8 @@ Usage: ${0##*/} [options] -q quiet: print only errors and the final summary -v verbose: stream all build output to the terminal (still logged) -c run 'make clean' in the freenginx tree before configuring + --purge don't build; delete this version's source and dependency folders + (run after 'sudo make install'; logs are kept) --no-brotli | --no-zstd | --no-geoip2 | --no-headers | --no-ktls | --no-debug disable an optional feature -h show this help @@ -56,6 +58,7 @@ while [ $# -gt 0 ]; do -q) VERBOSITY=0 ;; -v) VERBOSITY=2 ;; -c) CLEAN=1 ;; + --purge) PURGE=1 ;; --no-brotli) USE_BROTLI=0 ;; --no-zstd) USE_ZSTD=0 ;; --no-geoip2) USE_GEOIP2=0 ;; @@ -141,6 +144,20 @@ install_maxmind() { # system-wide, skipped when pkg-config already reports $V_MA ### Setup case $BUILDROOT in /*) ;; *) BUILDROOT=$PWD/$BUILDROOT ;; esac + +if [ "${PURGE:-0}" = 1 ]; then + built=$BUILDROOT/nginx-release-$V_NGINX/objs/nginx + if [ -f "$built" ] && ! cmp -s "$built" /usr/sbin/nginx; then + echo "!! $built is not the installed /usr/sbin/nginx. Run 'sudo make install' first." >&2 + exit 1 + fi + echo "==> Removing freenginx $V_NGINX build folders from $BUILDROOT" + rm -rf -- "$BUILDROOT/nginx-release-$V_NGINX" "$BUILDROOT/zlib-$V_ZLIB" "$BUILDROOT/pcre2-$V_PCRE" \ + "$BUILDROOT/openssl-$V_QSSL" "$BUILDROOT/libmaxminddb-$V_MAXM" "$BUILDROOT/nginx-geoip2" \ + "$BUILDROOT/ngx-brotli" "$BUILDROOT/ngx-zstd" "$BUILDROOT/headers-more-nginx-module-$V_HEAD" + exit 0 +fi + mkdir -p "$BUILDROOT" : "${LOG:=$BUILDROOT/build-$V_NGINX-$(date +%Y%m%d-%H%M%S).log}" case $LOG in /*) ;; *) LOG=$PWD/$LOG ;; esac