FreeBSD: fix sed inplace usage, use bin/sh as shebang for script, pkg make director dependent of database-postgresql#1961
Conversation
99432e7 to
422cc8e
Compare
5a182cb to
091d00b
Compare
091d00b to
801b37b
Compare
arogge
left a comment
There was a problem hiding this comment.
The change to the "am I running in Windows"-check is not proper. The rest looks great though.
|
|
||
| retval=0 | ||
| if [[ "$(uname -s)" =~ _NT ]]; then | ||
| if [ "$(uname -s)" =~ _NT ]; then |
There was a problem hiding this comment.
ShellCheck says "In POSIX sh, =~ regex matching is undefined.", so chances are this will break sooner or later.
Maybe we could use command -v cygpath to check if cygpath is available instead?
There was a problem hiding this comment.
ShellCheck says "In POSIX sh, =~ regex matching is undefined.", so chances are this will break sooner or later. Maybe we could use
command -v cygpathto check ifcygpathis available instead?
would that work also with the new native build and tests ?
There was a problem hiding this comment.
After a quick check to decide if we want to go for bash require. Actual Next doesn't require bash under FreeBSD.
pkg install bareos.com-director bareos.com-bconsole bareos.com-filedaemon bareos.com-storage
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
Updating Bareos repository catalogue...
pkg: Repository Bareos has a wrong packagesite, need to re-create database
Fetching meta.conf: 100% 163 B 0.2kB/s 00:01
Fetching packagesite.pkg: 100% 3 KiB 2.9kB/s 00:01
Processing entries: 100%
Bareos repository update completed. 12 packages processed.
All repositories are up to date.
The following 9 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
bareos.com-bconsole: 24.0.0.p1181.339.b13 [Bareos]
bareos.com-common: 24.0.0.p1181.339.b13 [Bareos]
bareos.com-database-common: 24.0.0.p1181.339.b13 [Bareos]
bareos.com-database-tools: 24.0.0.p1181.339.b13 [Bareos]
bareos.com-director: 24.0.0.p1181.339.b13 [Bareos]
bareos.com-filedaemon: 24.0.0.p1181.339.b13 [Bareos]
bareos.com-storage: 24.0.0.p1181.339.b13 [Bareos]
jansson: 2.14 [FreeBSD]
lzo2: 2.10_1 [FreeBSD]
Number of packages to be installed: 9
The process will require 9 MiB more space.
2 MiB to be downloaded.
Proceed with this action? [y/N]:
of course on a system that doesn't have bash installed :-)
There was a problem hiding this comment.
@pstorz propose eventually to go that way
https://docs.freebsd.org/en/books/porters-handbook/uses/#uses-shebangfix
There was a problem hiding this comment.
To remove the bashism, we could use the case statement for a substring match, like so:
case $(uname -s) in
*_NT) i_am_running_in_windows=yes
;;
*) i_am_running_in_windows=no
;;
esac
There was a problem hiding this comment.
So to resume, we decided to keep POSIX scripts for the database, so back to /bin/sh and we use the case xxx statement to test the Windows usage.
There was a problem hiding this comment.
should be fixed correctly now with 2cba3da
137e2ac to
283c790
Compare
arogge
left a comment
There was a problem hiding this comment.
I like the idea with the case, that's probably the nicest pattern matching we can have in a posix shell.
However, some of the other small changes you introduced, will not do what you expected.
| fi | ||
| case $(uname -s) in | ||
| *_NT) | ||
| PAGER="" PGOPTIONS="--client-min-messages=warning" psql --no-psqlrc -f "$(cygpath -w \"${temp_sql_grants}\")" -d "${db_name}" || retval=$? |
There was a problem hiding this comment.
Adding the backslashes here is actually harmful: the shell parser treats the contents of $() as a completely separate context with separated quoting.
Thus, echo "$(echo "x y")" will emit x y while echo "$(echo \"x y\")" will emit "x y".
There are not only quotes around the expression, but the second space in the middle was lost. This is because echo gets called with $1 being "x and $2 being y".
| PAGER="" PGOPTIONS="--client-min-messages=warning" psql --no-psqlrc -f "$(cygpath -w \"${temp_sql_grants}\")" -d "${db_name}" || retval=$? | |
| PAGER="" PGOPTIONS="--client-min-messages=warning" psql --no-psqlrc -f "$(cygpath -w "${temp_sql_grants}")" -d "${db_name}" || retval=$? |
There was a problem hiding this comment.
Ok I will complain to shellcheck maintainer :-)
| case $(uname -s) in | ||
| *_NT) | ||
| PAGER="" PGOPTIONS="--client-min-messages=warning" psql --no-psqlrc -f "$(cygpath -w \"${temp_sql_grants}\")" -d "${db_name}" || retval=$? | ||
| rm -f "$(cygpath -w \"${temp_sql_schema}\")" |
There was a problem hiding this comment.
this will not work.
rm needs the cygwin-path (i.e. /cygdrive/c/...) and not the translated windows path (i.e. C:\...).
There was a problem hiding this comment.
That's what you get to try to optimize it too far :-) I will revert this changes.
283c790 to
2cba3da
Compare
afcb458 to
712acfb
Compare
We remove the refactoring, as the expression set in variable will created artifact file with the delimiter like file'' or file"". Add a comment in code to explain the risk of refactoring that part. Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
Reverted changes made in #2204efeef4 for `make_bareos_tables`, `grant_bareos_privileges` and `update_bareos_tables`. We adapt the test detecting Windows to stay posix compatible, which fix FreeBSD catalog management. Sanitize by proper double-quoting variables. Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
- add `#include <signal.h>` for build success on FreeBSD
4c41266 to
b57d131
Compare
Please check
If you have any questions or problems, please give a comment in the PR.
Helpful documentation and best practices
Checklist for the reviewer of the PR (will be processed by the Bareos team)
Make sure you check/merge the PR using
devtools/pr-toolto have some simple automated checks run and a proper changelog record added.General
Source code quality