Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FreeBSD] build.sh: line 549: hb:p:d:: command not found #313

Closed
B-Interactive opened this issue Dec 3, 2020 · 2 comments
Closed

[FreeBSD] build.sh: line 549: hb:p:d:: command not found #313

B-Interactive opened this issue Dec 3, 2020 · 2 comments
Assignees
Labels
bug Something isn't working.

Comments

@B-Interactive
Copy link

Describe the bug

On FreeBSD 12.2-RELEASE amd64, when trying to build from source, immediately fails with error:
./build.sh: line 549: hb:p:d:: command not found

Steps to reproduce

  1. Fresh install of FreeBSD 12.1 updated to 12.2-RELEASE.
  2. Build and install Go 1.15.5 from ports.
  3. Build and install Bash shell 5.0.18 from ports.
  4. Downloaded and extracted maddy 0.4.2 release from https://github.com/foxcpp/maddy/releases
  5. In the extracted folder, I run bash ./build.sh
  6. Immediately fails with error ./build.sh: line 549: hb:p:d:: command not found

Environment information

  • FreeBSD version: 12.2-RELEASE amd64
  • maddy version: 0.4.2 Release
  • Go version: 1.15.5 freebsd/amd64
  • Bash shell version: 5.0.18
@B-Interactive B-Interactive added the bug Something isn't working. label Dec 3, 2020
@hugmouse
Copy link
Contributor

hugmouse commented Dec 3, 2020

Can confirm

image

upd

FreeBSD's getopt does not support -o parameter

upd 2

It seems that using getopts should be better option

According to Bash FAQ 35:

Unless it's the version from util-linux, and you use its advanced mode, never use getopt(1). getopt cannot handle empty > arguments strings, or arguments with embedded whitespace. Please forget that it ever existed.

The POSIX shell (and others) offer getopts which is safe to use instead.

Source: https://stackoverflow.com/questions/2721946/cross-platform-getopt-for-a-shell-script/2728625#2728625

@B-Interactive B-Interactive changed the title build.sh: line 549: hb:p:d:: command not found [FreeBSD] build.sh: line 549: hb:p:d:: command not found Dec 3, 2020
@foxcpp foxcpp self-assigned this Dec 3, 2020
@B-Interactive
Copy link
Author

B-Interactive commented Dec 4, 2020

Installing getopt from ports provides the GNU extensions required by build.sh.

To force its use, in build.sh I modified line 3 to point to the specific path of the port version of getopt:

options=$(/usr/local/bin/getopt -o hb:p:d: -l help,builddir:,prefix:,destdir:,systemddir:,configdir:,statedir:,runtimedir:,fail2bandir:,tags:,prefix:,gitversion:,version:,source:,sudo -- "$@")

I'm not out of the woods yet with FreeBSD issues. I now encounter the error below, but I'll research that a little more before following up on it. I'll mark this specific issue closed given the above appropriate fix.

...
--- Preparing integration files...
install: target `vim/ftdetect/maddy-conf.vim' is not a directory
usage: install [-bCcpSsUv] [-f flags] [-g group] [-m mode] [-o owner]
               [-M log] [-D dest] [-h hash] [-T tags]
               [-B suffix] [-l linkflags] [-N dbdir]
               file1 file2
       install [-bCcpSsUv] [-f flags] [-g group] [-m mode] [-o owner]
               [-M log] [-D dest] [-h hash] [-T tags]
               [-B suffix] [-l linkflags] [-N dbdir]
               file1 ... fileN directory
       install -dU [-vU] [-g group] [-m mode] [-N dbdir] [-o owner]
               [-M log] [-D dest] [-h hash] [-T tags]
               directory ...

Update 1

I've yet to produce a happy build.sh on FreeBSD, but the above issue and others that would follow are resolved by converting some commands to a FreeBSD variant.

For example, lines 410-412 are modified to the following:

install -dm 0644 -D "$PKGDIR/$PREFIX/share/vim/vimfiles/ftdetect/" vim/ftdetect/maddy-conf.vim
install -dm 0644 -D "$PKGDIR/$PREFIX/share/vim/vimfiles/ftplugin/" vim/ftplugin/maddy-conf.vim
install -dm 0644 -D "$PKGDIR/$PREFIX/share/vim/vimfiles/syntax/" vim/syntax/maddy-conf.vim

install -dm 0644 -D "$PKGDIR/$FAIL2BANDIR/jail.d/" fail2ban/jail.d/
install -dm 0644 -D "$PKGDIR/$FAIL2BANDIR/filter.d/" fail2ban/filter.d/
    
install -dm 0644 "$PKGDIR/$PREFIX/lib/systemd/system/" systemd/

Line 427 becomes:

install -dm 0644 "$MADDY_SRC/" "$PKGDIR/$CONFDIR/maddy.conf"

Linux useradd is switched to FreeBSD's pw on line 484 and 486:

if [ "$elevate" -eq 1 ]; then
   sudo pw user add maddy -n maddy -s /nonexistent -d /var/lib/maddy/
else
   pw user add maddy -n maddy -s /nonexistent -d /var/lib/maddy/
fi

Where I've become stumped is these sections, I haven't yet been able to resolve (unchanged original quoted here). I'm about ready to throw in the towel and try a Linux option.
Lines 419-423:

sed -Ei "s!/usr/bin!$PREFIX/bin!g;\
   s!/usr/lib/maddy!$PREFIX/lib/maddy!g;\
   s!/etc/maddy!$CONFDIR!g" "$PKGDIR/$SYSTEMDUNITS/system/maddy.service" "$PKGDIR/$SYSTEMDUNITS/system/maddy@.service"

popd >/dev/null

Lines 471-473:

    sudo install -Dm "$(stat -c '%a' "$f")" "$f" "$DESTDIR/$f"
else
    install -Dm "$(stat -c '%a' "$f")" "$f" "$DESTDIR/$f"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

3 participants