#!/usr/bin/env bash set -e if ! unix2dos -V 2>/dev/null >&2; then fatal "missing command required: unix2dos" fi if ! hg version 2>/dev/null >&2; then fatal "missing command required: hg (mercurial)" fi if ! axel --version 2>/dev/null >&2 && ! wget --version 2>/dev/null >&2; then fatal "missing command required: wget" fi if ! tar --version 2>/dev/null >&2 && ! gzip --version 2>/dev/null >&2; then fatal "missing commands required: tar, gzip" fi abs_path() { if realpath -m -- $1 2>/dev/null >&2; then realpath -m -- $1 else readlink -f -- $1 fi } root_dir=$(dirname $(abs_path $0/..)) . $root_dir/util/base . $root_dir/util/ver name=openresty-$openresty_ver bundle_dir=$root_dir/$name/bundle work_dir=$root_dir/work echo "openresty $openresty_ver" rm -rf $name *.tar.gz mkdir -p $work_dir $bundle_dir cd $bundle_dir download "https://openresty.org/download/nginx-$nginx_ver.tar.gz" \ nginx-$nginx_ver.tar.gz tar -xzf nginx-$nginx_ver.tar.gz apply_nginx_patches \ nginx-$nginx_ver \ $nginx_ver \ "with-prod-patches" # download archives (parallel) for tarball in ${tarballs[@]}; do tarball_name=$(echo $tarball | cut -d'/' -f2) tarball_ver_name="$(sed s/-/_/g <<<$tarball_name)_ver" tarball_ver="${!tarball_ver_name}" if [ -z $tarball_ver ]; then fatal "no version specified for $tarball_name tarball" fi download "https://github.com/$tarball/tarball/$tarball_ver" \ $tarball_name-$tarball_ver.tar.gz & done download "https://people.freebsd.org/~osa/ngx_http_redis-$ngx_http_redis_ver.tar.gz" \ redis-nginx-module-$ngx_http_redis_ver.tar.gz wait # extract archives for tarball in ${tarballs[@]}; do tarball_org=$(echo $tarball | cut -d'/' -f1) tarball_name=$(echo $tarball | cut -d'/' -f2) tarball_ver_name="$(sed s/-/_/g <<<$tarball_name)_ver" tarball_ver="${!tarball_ver_name}" tar -xzf $tarball_name-$tarball_ver.tar.gz mv $tarball_org-$tarball_name-* $tarball_name-${tarball_ver/#v} pushd $tarball_name-${tarball_ver/#v} if [ -f Makefile ]; then sed 's/\$(DESTDIR)\//$(DESTDIR)/g' Makefile > Makefile.tmp mv Makefile.tmp Makefile fi popd done tar -xzf redis-nginx-module-$ngx_http_redis_ver.tar.gz rm -f *.tar.* mv ngx_http_redis-* redis-nginx-module-${ngx_http_redis_ver/#v} mv luajit2-* LuaJIT-${luajit2_ver/#v} mv lua-nginx-module-* ngx_lua-${lua_nginx_module_ver/#v} mv stream-lua-nginx-module-* ngx_stream_lua-${stream_lua_nginx_module_ver/#v} mv lua-upstream-nginx-module-* ngx_lua_upstream-${lua_upstream_nginx_module_ver/#v} pushd LuaJIT-* apply_patch -p1 "luajit-win32-default-paths.patch" popd pushd redis-nginx-module-* apply_patch -p1 "ngx_http_redis-$ngx_http_redis_ver-variables_in_redis_pass.patch" apply_patch -p1 "ngx_http_redis-$ngx_http_redis_ver-default_port_fix.patch" apply_patch -p1 "ngx_http_redis-$ngx_http_redis_ver-without_gzip.patch" popd cd .. resty_cli_dir=$bundle_dir/resty-cli-${resty_cli_ver/#v} mkdir -p util patches # openresty-$ver cp $root_dir/COPYRIGHT . cp $root_dir/util/configure . cp $root_dir/README.markdown . perl $resty_cli_dir/bin/md2pod.pl $root_dir/doc/README-windows.md | pod2text > README-windows.txt unix2dos README-windows.txt # openresty-$ver/bundle cp $root_dir/util/install bundle # openresty-$ver/util cp $root_dir/util/package-win32.sh util cp $root_dir/util/build-win32.sh util # openresty-$ver/patches cp $root_dir/patches/openssl-*.patch patches/ sed $"s/NGINX_VERSION \"\.unknown/NGINX_VERSION \".$minor_ver/" \ $root_dir/patches/nginx-$nginx_ver-no_pool.patch > patches/nginx-no_pool.patch # generate restydoc index from nginx docs # openresty-$ver/bundle/resty.index cp $root_dir/html/index.html $bundle_dir/nginx-$nginx_ver/docs/html/ cp $root_dir/html/50x.html $bundle_dir/nginx-$nginx_ver/docs/html/ restydoc_index=$resty_cli_dir/bin/restydoc-index #restydoc_index=echo #restydoc_index=$HOME/git/resty-cli/bin/restydoc-index nginx_xml2pod=$resty_cli_dir/bin/nginx-xml2pod #nginx_xml2pod=echo #nginx_xml2pod=$HOME/git/resty-cli/bin/nginx-xml2pod pushd $work_dir if [ -d nginx.org ]; then pushd nginx.org hg pull hg update --clean popd else hg clone http://hg.nginx.org/nginx.org fi pushd nginx.org hg purge --config extensions.purge= find xml/en/docs -name 'ngx_http_api_module.xml' -delete rm -f xml/en/docs/njs/* $nginx_xml2pod xml/en/docs popd popd echo "restydoc-index $work_dir/nginx.org" $restydoc_index --outdir bundle $work_dir/nginx.org echo "restydoc-index $root_dir/doc/lua-5.1.5" $restydoc_index --outdir bundle $root_dir/doc/lua-5.1.5 echo "restydoc-index $root_dir/doc/LuaJIT-2.1" $restydoc_index --outdir bundle $root_dir/doc/LuaJIT-2.1 # generate restydoc index from openresty docs for indir in bundle/*/; do #echo "processing directory $indir ..." if [ "$indir" == "bundle/pod/" ]; then continue fi if [ "$indir" == "bundle/nginx-$nginx_ver/" ]; then continue fi echo "restydoc-index --outdir bundle $indir" $restydoc_index --outdir bundle $indir done find bundle -name '*.md' -delete find bundle -name '*.markdown' -delete find bundle -name '*.wiki' -delete find bundle -name '*~' -delete find bundle -name '*.orig' -delete cd $root_dir tar cf $name.tar $name gzip -f --best $name.tar