From e2dd3610f372f8e803a841271a31b54e43a63dfb Mon Sep 17 00:00:00 2001 From: Liam Crilly Date: Fri, 16 Dec 2022 12:46:35 +0000 Subject: Tools: fixed quoting for apostrophe in setup-unit. --- tools/setup-unit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/setup-unit') diff --git a/tools/setup-unit b/tools/setup-unit index 79dab850..6c1aec63 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -9,7 +9,7 @@ if test -n ${BASH_VERSION} && test "${BASH_VERSINFO[0]}" -eq 3; then - >&2 echo 'Your version of bash(1) isn't supported by this script.'; + >&2 echo "Your version of bash(1) isn't supported by this script."; >&2 echo "You're probably running on macOS. We recommend that you either"; >&2 echo 'install a newer version of bash(1) or run this script with'; >&2 echo 'another shell, such as zsh(1):'; -- cgit From 99a7fa783917fac7fa38aa619d8e02b61dd1d816 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Fri, 16 Dec 2022 15:02:20 +0100 Subject: Tools: Using HereDoc instead of echo(1). This prevents accidents, which are likely to happen especially with quotes. Signed-off-by: Alejandro Colomar --- tools/setup-unit | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'tools/setup-unit') diff --git a/tools/setup-unit b/tools/setup-unit index 6c1aec63..52ed6ede 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -9,11 +9,13 @@ if test -n ${BASH_VERSION} && test "${BASH_VERSINFO[0]}" -eq 3; then - >&2 echo "Your version of bash(1) isn't supported by this script."; - >&2 echo "You're probably running on macOS. We recommend that you either"; - >&2 echo 'install a newer version of bash(1) or run this script with'; - >&2 echo 'another shell, such as zsh(1):'; - >&2 echo " $ zsh ${SUDO_USER:+sudo }$0 ..."; + >&2 cat <<__EOF__ ; +Your version of bash(1) isn't supported by this script. You're probably +running on macOS. We recommend that you either install a newer version +of bash(1) or run this script with another shell, such as zsh(1): + + $ zsh ${SUDO_USER:+sudo }$0 ... +__EOF__ exit 1; fi; -- cgit From 9c94cfccd58bbd78e5eac9d861dceb7c5fa9a6b7 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Fri, 16 Dec 2022 15:14:35 +0100 Subject: Tools: Fixed bug in help message. 'sudo' was misplaced. Signed-off-by: Alejandro Colomar --- tools/setup-unit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/setup-unit') diff --git a/tools/setup-unit b/tools/setup-unit index 52ed6ede..f96bd499 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -14,7 +14,7 @@ Your version of bash(1) isn't supported by this script. You're probably running on macOS. We recommend that you either install a newer version of bash(1) or run this script with another shell, such as zsh(1): - $ zsh ${SUDO_USER:+sudo }$0 ... + $ ${SUDO_USER:+sudo }zsh $0 ... __EOF__ exit 1; fi; -- cgit From 6861c25e4e46a9ee34f2f80ce468f846403046a1 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Fri, 16 Dec 2022 20:47:50 +0100 Subject: Tools: setup-unit: removed root checks. Reported-by: Liam Crilly Signed-off-by: Alejandro Colomar --- tools/setup-unit | 8 -------- 1 file changed, 8 deletions(-) (limited to 'tools/setup-unit') diff --git a/tools/setup-unit b/tools/setup-unit index f96bd499..a41b7f81 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -557,10 +557,6 @@ unit_ctl_welcome() shift; done; - id -u \ - | xargs test 0 -ne \ - && err 'welcome: This script requires root privileges to run.'; - command -v curl >/dev/null \ || err 'welcome: curl(1) not found in PATH. It must be installed to run this script.'; @@ -1179,10 +1175,6 @@ __EOF__"; command -v curl >/dev/null \ || err 'repo-config: curl(1) not found in PATH. It must be installed to run this script.'; - id -u \ - | xargs test 0 -ne \ - && err 'repo-config: This script requires root privileges to run.'; - echo 'This script sets up the NGINX Unit repository'; if ! test $# -ge 3; then -- cgit From 2435bd1c3a55cad4d9bcacf5389a38c7cb0b154e Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Fri, 16 Dec 2022 21:39:28 +0100 Subject: Tools: setup-unit: workarounded macOS tmp file permissions. mktemp(1) in macOS uses a weird directory where only the running user has permissions. If we use that for the welcome website, unitd(8) won't be able to read the page. Use a directory at $HOME before trying a tmpdir. Reported-by: Liam Crilly Signed-off-by: Alejandro Colomar --- tools/setup-unit | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tools/setup-unit') diff --git a/tools/setup-unit b/tools/setup-unit index a41b7f81..d16fe1a3 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -562,6 +562,9 @@ unit_ctl_welcome() www='/srv/www/unit/index.html'; if test -e "$www" && ! test -v force || ! test -w /srv; then + www="$HOME/srv/www/unit/index.html"; + fi; + if test -e "$www" && ! test -v force; then www="$(mktemp)"; mv "$www" "$www.html"; www="$www.html" @@ -624,7 +627,7 @@ unit_ctl_welcome() dry_run_echo 'Create a file to serve:'; dry_run_eval "mkdir -p $(dirname $www);"; - dry_run_eval "cat >'$www'"' <<__EOF__; + dry_run_eval "tee '$www' >/dev/null"' <<__EOF__; -- cgit From 88b04f3e7cc100caf74623165ebe102115a9e304 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Thu, 22 Dec 2022 16:36:29 +0100 Subject: Tools: setup-unit: disabled buggy behavior of zsh(1). Reported-by: Liam Crilly Signed-off-by: Alejandro Colomar --- tools/setup-unit | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/setup-unit') diff --git a/tools/setup-unit b/tools/setup-unit index d16fe1a3..3db2d38b 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -25,6 +25,9 @@ set -Eefuo pipefail; test -v BASH_VERSION \ && shopt -s lastpipe; +test -v ZSH_VERSION \ +&& setopt sh_word_split; + export LC_ALL=C program_name="$0"; -- cgit From 5a37171f733fa8c7326161cc49af3df0be5dfae4 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Thu, 14 Jul 2022 13:25:57 +0200 Subject: Added default values for pathnames. This allows one to simply run `./configure` and expect it to produce sane defaults for an install. Previously, without specifying `--prefix=...`, `make install` would simply fail, recommending to set `--prefix` or `DESTDIR`, but that recommendation was incomplete at best, since it didn't set many of the subdirs needed for a good organization. Setting `DESTDIR` was even worse, since that shouldn't even affect an installation (it is required to be transparent to the installation). /usr/local is the historic Unix standard path to use for installations from source made manually by the admin of the system. Some package managers (Homebrew, I'm looking specifically at you) have abused that path to install their things, but 1) it's not our fault that someone else incorrectly abuses that path (and they seem to be fixing it for newer archs; e.g., they started using /opt/homebrew for Apple Silicon), 2) there's no better path than /usr/local, 3) we still allow changing it for systems where this might not be the desired path (MacOS Intel with hombrew), and 4) it's _the standard_. See a related conversation with Ingo (OpenBSD maintainer): On 7/27/22 16:16, Ingo Schwarze wrote: > Hi Alejandro, [...] > > Alejandro Colomar wrote on Sun, Jul 24, 2022 at 07:07:18PM +0200: >> On 7/24/22 16:57, Ingo Schwarze wrote: >>> Alejandro Colomar wrote on Sun, Jul 24, 2022 at 01:20:46PM +0200: > >>>> /usr/local is for sysadmins to build from source; > >>> Doing that is *very* strongly discouraged on OpenBSD. > >> I guess that's why the directory was reused in the BSDs to install ports >> (probably ports were installed by the sysadmin there, and by extension, >> ports are now always installed there, but that's just a guess). > > Maybe. In any case, the practice of using /usr/local for packages > created from ports is significantly older than the recommendation > to refrain from using upstream "make install" outside the ports > framework. > > * The FreeBSD ports framework was started by Jordan Hubbard in 1993. > * The ports framework was ported from FreeBSD to OpenBSD > by Niklas Hallqvist in 1996. > * NetBSD pkgsrc was forked from FreeBSD ports by Alistair G. Crooks > and Hubert Feyrer in 1997. > > I failed to quickly find Jordan's original version, but rev. 1.1 > of /usr/ports/infrastructure/mk/bsd.port.mk in OpenBSD (dated Jun 3 > 22:47:10 1996 UTC) already said > > LOCALBASE ?= /usr/local > PREFIX ?= ${LOCALBASE} > [...] >> I had a discussion in NGINX Unit about it, and >> the decission for now has been: "support prefix=/usr/local for default >> manual installation through the Makefile, and let BSD users adjust to >> their preferred path". > > That's an *excellent* solution for the task, thanks for doing it > the right way. By setting PREFIX=/usr/local by default in the > upstream Makefile, you are minimizing the work for *BSD porters. > > The BSD ports frameworks will typically run the upstreak "make install" > with the variable DESTDIR set to a custom value, for example > > DESTDIR=/usr/ports/pobj/groff-1.23.0/fake-amd64 > > so if the upstream Makefile sets PREFIX=/usr/local , > that's perfect, everything gets installed to the right place > without an intervention by the person doing the porting. > > Of course, if the upstream Makefile would use some other PREFIX, > that would not be a huge obstacle. All we have to do in that case > is pass the option --prefix=/usr/local to the ./configure script, > or something equivalent if the software isn't using GNU configure. > >> We were concerned that we might get collisions >> with the BSD port also installing in /usr/local, but that's the least >> evil (and considering BSD users don't typically run `make install`, it's >> not so bad). > > It's not bad at all. It's perfect. > > Of course, if a user wants to install *without* the ports framework, > they have to provide their own --prefix. But that's not an issue > because it is easy to do, and installing without a port is discouraged > anyway. === Directory variables should never contain a trailing slash (I've learned that the hard way, where some things would break unexpectedly). Especially, make(1) is likely to have problems when things have double slashes or a trailing slash, since it treats filenames as text strings. I've removed the trailing slash from the prefix, and added it to the derivate variables just after the prefix. pkg-config(1) also expects directory variables to have no trailing slash. === I also removed the code that would set variables as depending on the prefix if they didn't start with a slash, because that is a rather non-obvious behavior, and things should not always depend on prefix, but other dirs such as $(runstatedir), so if we keep a similar behavior it would be very unreliable. Better keep variables intact if set, or use the default if unset. === Print the real defaults for ./configure --help, rather than the actual values. === I used a subdirectory under the standard /var/lib for NXT_STATE, instead of a homemade "state" dir that does the same thing. === Modified the Makefile to create some dirs that weren't being created, and also remove those that weren't being removed in uninstall, probably because someone forgot to add them. === Add new options for setting the new variables, and rename some to be consistent with the standard names. Keep the old ones at configuration time for compatibility, but mark them as deprecated. Don't keep the old ones at exec time. === A summary of the default config is: Unit configuration summary: bin directory: ............. "/usr/local/bin" sbin directory: ............ "/usr/local/sbin" lib directory: ............. "/usr/local/lib" include directory: ......... "/usr/local/include" man pages directory: ....... "/usr/local/share/man" modules directory: ......... "/usr/local/lib/unit/modules" state directory: ........... "/usr/local/var/lib/unit" tmp directory: ............. "/tmp" pid file: .................. "/usr/local/var/run/unit/unit.pid" log file: .................. "/usr/local/var/log/unit/unit.log" control API socket: ........ "unix:/usr/local/var/run/unit/control.unit.sock" Link: Link: Reviewed-by: Artem Konev Reviewed-by: Andrew Clayton Tested-by: Andrew Clayton Reviewed-by: Konstantin Pavlov Signed-off-by: Alejandro Colomar --- tools/setup-unit | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/setup-unit') diff --git a/tools/setup-unit b/tools/setup-unit index 3db2d38b..ca7635db 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -598,14 +598,14 @@ unit_ctl_welcome() # Check unitd is not configured already. echo "$cmd" \ - | if grep '\--state' >/dev/null; then + | if grep '\--libstatedir' >/dev/null; then echo "$cmd" \ | sed 's/ --/\n--/g' \ - | grep '\--state' \ + | grep '\--libstatedir' \ | cut -d' ' -f2; else $cmd --help \ - | sed -n '/\--state/,+1p' \ + | sed -n '/\--libstatedir/,+1p' \ | grep 'default:' \ | sed 's/ *default: "\(.*\)"/\1/'; fi \ -- cgit From e249dd4727c8ca1cb6387ee983c131abc672b84e Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 11 Jan 2023 15:25:25 +0100 Subject: Tools: using nicer characters for showing a tree. Especially in small trees, ASCII characters are confusing. Use nicer UTF-8 characters, which are more readable to the audience of this script. We don't expect the audience of this script to have limited environments where these characters will not be shown, but if that happens, we could improve the script to select the caracters based on the locale. Suggested-by: Liam Crilly Reviewed-by: Andrew Clayton Signed-off-by: Alejandro Colomar --- tools/setup-unit | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'tools/setup-unit') diff --git a/tools/setup-unit b/tools/setup-unit index ca7635db..67f89394 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -42,8 +42,8 @@ SYNOPSIS $program_name [-h] COMMAND [ARGS] Subcommands - +-- repo-config [-hn] [PKG-MANAGER OS-NAME OS-VERSION] - +-- welcome [-hn] + ├── repo-config [-hn] [PKG-MANAGER OS-NAME OS-VERSION] + └── welcome [-hn] DESCRIPTION This script simplifies installing and configuring an NGINX Unit server @@ -78,19 +78,19 @@ SYNOPSIS $program_name [-h] COMMAND [ARGS] Subcommands - +-- cmd [-h] - +-- ctl [-h] [-s SOCK] SUBCOMMAND [ARGS] - | +-- http [-h] [-c CURLOPT] METHOD PATH - | +-- insert [-h] PATH INDEX - +-- freeport [-h] - +-- json-ins [-hn] JSON INDEX - +-- os-probe [-h] - +-- ps [-h] [-t TYPE] - +-- repo-config [-hn] [PKG-MANAGER OS-NAME OS-VERSION] - +-- sock [-h] SUBCOMMAND [ARGS] - | +-- filter [-chs] - | +-- find [-h] - +-- welcome [-hn] + ├── cmd [-h] + ├── ctl [-h] [-s SOCK] SUBCOMMAND [ARGS] + │   ├── http [-h] [-c CURLOPT] METHOD PATH + │   └── insert [-h] PATH INDEX + ├── freeport [-h] + ├── json-ins [-hn] JSON INDEX + ├── os-probe [-h] + ├── ps [-h] [-t TYPE] + ├── repo-config [-hn] [PKG-MANAGER OS-NAME OS-VERSION] + ├── sock [-h] SUBCOMMAND [ARGS] + │   ├── filter [-chs] + │   └── find [-h] + └── welcome [-hn] DESCRIPTION This script simplifies installing and configuring @@ -210,8 +210,8 @@ SYNOPSIS $program_name ctl [-h] [-s SOCK] SUBCOMMAND [ARGS] Subcommands - +-- http [-h] [-c CURLOPT] METHOD PATH - +-- insert [-h] PATH INDEX + ├── http [-h] [-c CURLOPT] METHOD PATH + └── insert [-h] PATH INDEX DESCRIPTION Control a running unitd(8) instance through its control API socket. @@ -1231,8 +1231,8 @@ SYNOPSIS $program_name sock [-h] SUBCOMMAND [ARGS] Subcommands - +-- filter [-ch] - +-- find [-h] + ├── filter [-ch] + └── find [-h] DESCRIPTION Print the control API socket address of running unitd(8) -- cgit From 5ba79b9b524ef746bc3269520c3f6b893f39275c Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 27 Mar 2023 13:43:37 +0200 Subject: Renamed --libstatedir to --statedir. In BSD systems, it's usually or some other dir under that is not , so $statedir is a more generic name. See hier(7). Reported-by: Andrei Zeliankou Reported-by: Zhidao Hong Reviewed-by: Konstantin Pavlov Reviewed-by: Andrew Clayton Cc: Liam Crilly Signed-off-by: Alejandro Colomar --- tools/setup-unit | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/setup-unit') diff --git a/tools/setup-unit b/tools/setup-unit index 67f89394..da276448 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -598,14 +598,14 @@ unit_ctl_welcome() # Check unitd is not configured already. echo "$cmd" \ - | if grep '\--libstatedir' >/dev/null; then + | if grep '\--statedir' >/dev/null; then echo "$cmd" \ | sed 's/ --/\n--/g' \ - | grep '\--libstatedir' \ + | grep '\--statedir' \ | cut -d' ' -f2; else $cmd --help \ - | sed -n '/\--libstatedir/,+1p' \ + | sed -n '/\--statedir/,+1p' \ | grep 'default:' \ | sed 's/ *default: "\(.*\)"/\1/'; fi \ -- cgit From 6f36a67fc37004511299133e39d9a6fbb9d55a0c Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 3 Apr 2023 18:16:28 +0200 Subject: Tools: setup-unit: unified repeated code. Instead of doing the same operation in each subcommand, do it once in the parent. Reviewed-by: Andrew Clayton Signed-off-by: Alejandro Colomar --- tools/setup-unit | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'tools/setup-unit') diff --git a/tools/setup-unit b/tools/setup-unit index da276448..de1d4f5f 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -290,7 +290,11 @@ unit_ctl() err 'ctl: Missing subcommand.'; fi; - if test -v sock && echo $sock | grep '^ssh://' >/dev/null; then + if ! test -v sock; then + local sock="$(unit_sock_find)"; + fi; + + if echo $sock | grep '^ssh://' >/dev/null; then local remote="$(echo $sock | sed 's,\(ssh://[^/]*\).*,\1,')"; local sock="$(echo $sock | sed 's,ssh://[^/]*\(.*\),unix:\1,')"; fi; @@ -298,11 +302,11 @@ unit_ctl() case $1 in http) shift; - unit_ctl_http ${remote:+ ---r $remote} ${sock:+ ---s $sock} $@; + unit_ctl_http ${remote:+ ---r $remote} ---s "$sock" $@; ;; insert) shift; - unit_ctl_insert ${remote:+ ---r $remote} ${sock:+ ---s $sock} $@; + unit_ctl_insert ${remote:+ ---r $remote} ---s "$sock" $@; ;; *) err "ctl: $1: Unknown argument."; @@ -403,9 +407,6 @@ unit_ctl_http() -L "$local_sock:$remote_sock" "$remote"; sock="unix:$local_sock"; - - elif ! test -v sock; then - local sock="$(unit_sock_find)"; fi; curl $curl_options -X $method -d@- \ @@ -490,9 +491,6 @@ unit_ctl_insert() -L "$local_sock:$remote_sock" "$remote"; sock="unix:$local_sock"; - - elif ! test -v sock; then - local sock="$(unit_sock_find)"; fi; local old="$(mktemp ||:)"; -- cgit