Skip to content

FreeBSD: fix sed inplace usage, use bin/sh as shebang for script, pkg make director dependent of database-postgresql#1961

Merged
BareosBot merged 5 commits intobareos:masterfrom
bruno-at-bareos:dev/bruno/master/fix-1960-bsdlike-sed-in-place
Oct 9, 2024
Merged

FreeBSD: fix sed inplace usage, use bin/sh as shebang for script, pkg make director dependent of database-postgresql#1961
BareosBot merged 5 commits intobareos:masterfrom
bruno-at-bareos:dev/bruno/master/fix-1960-bsdlike-sed-in-place

Conversation

@bruno-at-bareos
Copy link
Contributor

@bruno-at-bareos bruno-at-bareos commented Sep 18, 2024

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

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-tool to have some simple automated checks run and a proper changelog record added.

General
  • Is the PR title usable as CHANGELOG entry?
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
  • Required backport PRs have been created
  • Correct milestone is set
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR

@bruno-at-bareos bruno-at-bareos added this to the 24.0.0 milestone Sep 18, 2024
@bruno-at-bareos bruno-at-bareos force-pushed the dev/bruno/master/fix-1960-bsdlike-sed-in-place branch from 99432e7 to 422cc8e Compare September 19, 2024 08:18
@arogge arogge added requires backport to 23 bug This addresses a bug labels Sep 19, 2024
@arogge arogge self-requested a review September 24, 2024 09:48
@bruno-at-bareos bruno-at-bareos force-pushed the dev/bruno/master/fix-1960-bsdlike-sed-in-place branch 6 times, most recently from 5a182cb to 091d00b Compare September 25, 2024 09:16
@bruno-at-bareos bruno-at-bareos changed the title fix sed inplace usage on bsd like OS FreeBSD: fix sed inplace usage, use bin/sh as shebang for script, pkg make director dependent of database-postgresql Sep 25, 2024
@bruno-at-bareos bruno-at-bareos force-pushed the dev/bruno/master/fix-1960-bsdlike-sed-in-place branch from 091d00b to 801b37b Compare September 25, 2024 11:35
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

would that work also with the new native build and tests ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, yes.

Copy link
Contributor Author

@bruno-at-bareos bruno-at-bareos Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fixed correctly now with 2cba3da

@bruno-at-bareos bruno-at-bareos force-pushed the dev/bruno/master/fix-1960-bsdlike-sed-in-place branch 3 times, most recently from 137e2ac to 283c790 Compare October 1, 2024 15:19
@bruno-at-bareos bruno-at-bareos requested a review from arogge October 2, 2024 09:26
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=$?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Suggested change
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=$?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I will complain to shellcheck maintainer :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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}\")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not work.
rm needs the cygwin-path (i.e. /cygdrive/c/...) and not the translated windows path (i.e. C:\...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what you get to try to optimize it too far :-) I will revert this changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 2cba3da

@bruno-at-bareos bruno-at-bareos force-pushed the dev/bruno/master/fix-1960-bsdlike-sed-in-place branch from 283c790 to 2cba3da Compare October 4, 2024 12:27
@bruno-at-bareos bruno-at-bareos requested a review from arogge October 4, 2024 12:28
@bruno-at-bareos bruno-at-bareos force-pushed the dev/bruno/master/fix-1960-bsdlike-sed-in-place branch from afcb458 to 712acfb Compare October 9, 2024 08:43
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

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>
bruno-at-bareos and others added 4 commits October 9, 2024 15:13
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
@BareosBot BareosBot force-pushed the dev/bruno/master/fix-1960-bsdlike-sed-in-place branch from 4c41266 to b57d131 Compare October 9, 2024 15:14
@BareosBot BareosBot merged commit 2939326 into bareos:master Oct 9, 2024
@bruno-at-bareos bruno-at-bareos deleted the dev/bruno/master/fix-1960-bsdlike-sed-in-place branch November 25, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This addresses a bug requires backport to 23

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FreeBSD avoid creating configuration files ending with .conf'' or .conf""

5 participants