File: preamble

package info (click to toggle)
nginx 1.18.0-6.1%2Bdeb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 19,344 kB
  • sloc: ansic: 250,653; perl: 7,548; sh: 1,408; ruby: 879; python: 358; makefile: 338; awk: 36; cpp: 18
file content (106 lines) | stat: -rw-r--r-- 2,008 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#! /bin/bash
#
# preamble
# Copyright (C) 2016 Adrian Perez <aperez@igalia.com>
#
# Distributed under terms of the MIT license.
#

function nginx_conf_generate () {
	if ${DYNAMIC} ; then
		echo 'load_module modules/ngx_http_fancyindex_module.so;'
	fi
	cat <<-EOF
	worker_processes 1;
	events { worker_connections 1024; }
	http {
		include mime.types;
		default_type application/octet-stream;
		sendfile on;
		keepalive_timeout 65;
		server {
			server_name localhost;
			listen 127.0.0.1:8888;
			root ${TESTDIR};
			error_page 500 502 503 504 /50x.html;
			location = /50x.html { root html; }
			location / {
				index index.html;
				fancyindex on;
				$*
			}
		}
	}
	EOF
}

readonly NGINX_CONF="${PREFIX}/conf/nginx.conf"
readonly NGINX_PID="${PREFIX}/logs/nginx.pid"
rm -f "${NGINX_CONF}" "${NGINX_PID}"
mkdir -p "${PREFIX}/logs"

function pup () {
	if [[ -x ${TESTDIR}/pup ]] ; then
		"${TESTDIR}/pup" "$@"
	else
		skip 'Test uses "pup", which is not available'
	fi
}

function use () {
	case $1 in
		pup ) [[ -x ${TESTDIR}/pup ]] \
			|| skip 'Test uses "pup", which is unavailable\n' ;;
		* ) warn "Invalid 'use' flag: '%s'\n'" "$1" ;;
	esac
}

function nginx () {
	env - PATH="${PATH}" "${PREFIX}/sbin/nginx" "$@"
}

function nginx_conf () {
	nginx_conf_generate "$@" > "${NGINX_CONF}"
}

function nginx_is_running () {
	[[ -r ${NGINX_PID} ]] && kill -0 $(< "${NGINX_PID}")
}

function nginx_stop () {
	if nginx_is_running ; then nginx -s stop ; fi
	rm -f "${NGINX_PID}"
}
trap nginx_stop EXIT

function nginx_start () {
	if [[ $# -gt 0 || ! -r ${NGINX_CONF} ]] ; then nginx_conf "$@" ; fi
	nginx_stop  # Ensure that it is not running.
	nginx
}

function fetch () {
	local -a opts=( -q )
	if [[ $1 = --with-headers ]] ; then
		opts+=( -S )
		shift
	fi
	wget "${opts[@]}" -O- "http://localhost:8888${1:-/}" 2>&1
}

function skip () {
	printf '(--) '
	printf "$@"
	exit 111
} 1>&2

function fail () {
	printf '(FF) '
	printf "$@"
	exit 1
} 1>&2

function warn () {
	printf '(WW) '
	printf "$@"
} 1>&2