Solved Upgraded jail to 14.1 then upgraded pkg - now have post install script error

tldr; the file /etc/rc.subr was not properly updated during the upgrade.

OP
Following an upgrade of the host and jail to 14.1 upgrades of pkg itself on the jail produce this error:
Code:
# pkg upgrade -f pkg
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (0 conflicting)
The following 1 package(s) will be affected (of 0 checked):

Installed packages to be REINSTALLED:
        pkg-1.21.3

Number of packages to be reinstalled: 1

Proceed with this action? [y/N]: y
[webdav-1.hamilton.harte-lyne.ca] [1/1] Reinstalling pkg-1.21.3...
[webdav-1.hamilton.harte-lyne.ca] [1/1] Extracting pkg-1.21.3: 100%
/etc/rc.subr: 2323: Syntax error: end of file unexpected (expecting "fi")
pkg: POST-INSTALL script failed
You may need to manually remove /usr/local/etc/pkg.conf if it is no longer needed.

This error does not appear for any other pkg that I have reinstalled.

However, this error prevents iocage from shutting down the jail:

Code:
]# iocage stop webdav-1
* Stopping webdav-1
  + Executing prestop OK
  + Stopping services FAILED
ERROR:
/etc/rc.subr: 2323: Syntax error: end of file unexpected (expecting "fi")
           

Please use --force flag to force stop jail
 
Looks like one of the files (/etc/rc.subr) may have had some merge issues. Have you looked at that specific file?
 
Maybe, pkg.conf had some permissions issue?
Code:
/usr/local/etc
-rw-r--r--  1 root wheel 2392 Jul  4 02:04 pkg.conf
 
Evidently, I did not save the file after editing it. At least the copy that was in the jail did not match the one on the host. I copied the 14.1 host rc.subr to the jail and then the error disappeared.
 
I have run into this problem again when upgrading my desktop to 14.1p3. I ran shellcheck and it reports this:
Code:
In /etc/rc.subr line 587:
                elif [ "$dest_mod" $gt "$curitem_mod" ] \
                                ^-- SC1009 (info): The mentioned syntax error was in this elif clause.
                                     ^-- SC1073 (error): Couldn't parse this test expression. Fix to allow more checks.
                                                   ^-- SC1072 (error): Expected test to end here (don't wrap commands in []/[[]]). Fix any mentioned problems and try again.

SO I looked into this some more and it appears, to me, that there is a coding error in this section of the script:
The elif block has a syntax error. The gt should be used within the test command, i.e., inside [ ... ] or [[ ... ]] Also, I am confused by the $gt operator. Is this a typo or is there some special meaning to this? As far as I recall -gt is the correct operator for comparing integers, and I believe that it should be inside the test operator as in: [ "$dest_mod" -gt "$curitem_mod" ]. Lastly, what is the line continuation character doing following the test operator? Should not the line end ( ; vice \ ) and the thenclause start?
 
If you'll look at some 20 lines before that test, it should be clear that the line is in fact correct. (This is a reminder that syntax/style checkers are just tools with very clear limitations, whose suggestions therfore shouldn't be blindly followed. Other examples are mentioned here:
 
[[..]] doesn't exist in sh, it's from bash.
$gt is a variable defined few lines before like adorno said before.
\ at the end of a line tells the shell that the command line doesn't end here but continue with the next line, it's just aesthetic for better visibility. Instead of having a very long line, it is split in multi lines.

Bash:
root@fbsd >> shellcheck -s sh /etc/rc.subr

In /etc/rc.subr line 397:
    local sort_field=0 sort_strict_fields= sort_numeric=
                                              ^-- SC1007 (warning): Remove space after = if trying to assign a value (for empty string, use var='' ... ).
In /etc/rc.subr line 479:
                curitem_haskey= break
                                               ^-- SC1007 (warning): Remove space after = if trying to assign a value (for empty string, use var='' ... ).
In /etc/rc.subr line 552:
                    dest_haskey= break
                                                    ^-- SC1007 (warning): Remove space after = if trying to assign a value (for empty string, use var='' ... ).
In /etc/rc.subr line 587:
                elif [ "$dest_mod" $gt "$curitem_mod" ] \
                                ^-- SC1009 (info): The mentioned syntax error was in this elif clause.
                                     ^-- SC1073 (error): Couldn't parse this test expression. Fix to allow more checks.
                                                   ^-- SC1072 (error): Expected test to end here (don't wrap commands in []/[[]]). Fix any mentioned problems and try again.

For more information:
  https://www.shellcheck.net/wiki/SC1007 -- Remove space after = if trying to...
  https://www.shellcheck.net/wiki/SC1072 -- Expected test to end here (don't ...
  https://www.shellcheck.net/wiki/SC1073 -- Couldn't parse this test expressi...

All the 4 warnings given by Shellcheck here are wrong, a bit of context is needed to interpret what is written, shellcheck can't do that.
I am under the impression that Shellcheck base some of its analysis on "coding style", so when it faces something coded differently it considers there is an issue which is not always the case, that wouldn't be a problem if everyone could code the exact same way with one unique style but reality is not like that, so sometimes it misses totally how and what it's done, that's why you can't trust totally that tool.

Just so you know I already tried to verify some of the FreeBSD scripts, I've stopped quickly because it never ends well, mostly because shellcheck throw numerous errors.
It just doesn't really understand what is going on, it is not familiar with the syntax and/or the logic used by these old scripts, different time different style.

That being said I don't consider Shellcheck useless at all, I use it for my personal scripts, it helps me to identify my mistakes, syntax errors and things like that, but my code is very simple.
 
Back
Top