Re: Get ${OSREL} at install time

From: Nuno Teixeira <eduardo_at_freebsd.org>
Date: Tue, 18 Apr 2023 10:55:03 UTC
pkg-plist:
@postexec env osrel=$(freebsd-update -u) sed -E -e
s,stable/[0-9]+,stable/${osrel\%\%.*}, -e
s,releng/[0-9]+,releng/${osrel\%\%-*}, %%PREFIX%%/etc/gitup.conf

Result:
/bin/sh: ${osrel\...}: Bad substitution
pkg-static: POST-INSTALL script failed

Other aproach:

pkg-post-install
---
#!/bin/sh -

osrel=$(freebsd-version -u)
releng=${osrel%%-*}
stable=${osrel%%.*}

echo "Configuring gitup.conf for $osrel"

sed -E -e 's|stable\/12|stable\/${stable}|' -e
's|releng\/11.4|releng\/${releng}|' /usr/local/etc/gitup.conf

echo debug:
echo osrel=${osrel}
echo releng=${releng}
echo stable=${stable}
---

Result:
---
debug:
"branch"           : "releng/${releng}",
"branch"           : "stable/${stable}",
osrel=13.2-RELEASE
releng=13.2
stable=13
---

sed doesn't subtitute as it uses literal variables

Eugene Grosbein <eugen@grosbein.net> escreveu no dia terça, 18/04/2023 à(s)
10:40:

> 18.04.2023 16:26, Eugene Grosbein wrote:
>
> > 18.04.2023 15:05, Nuno Teixeira wrote:
> >> Hello all,
> >>
> >> net/gitup uses a reinplace cmd to setup gitup.conf to the correspondent
> RELEASE/STABLE for command `gitup release` and `gitup stable`.
> >> So, if user is using 13.1-RELEASE, reinplace will configure gitup.conf
> to:
> >>
> >> "release" : {
> >>                 "branch"           : "releng/13.1",
> >> "stable" : {
> >>                 "branch"           : "stable/13",
> >>
> >> The problem is that OSREL is taken from build time and at this moment
> 13.2 pkgs are being built on a 13.1 machine.
> >> So the result is wrong by setting releng/13.1 instead of releng/13.2.
> >>
> >> the reinplace cmd is:
> >> ---
> >> ${REINPLACE_CMD} -e 's|stable\/12|stable\/${OSREL:R}| ; \
> >>                 s|releng\/11.4|releng\/${OSREL}|' \
> >>                 ${WRKSRC}/gitup.conf
> >> ---
> >>
> >> Any sugestion or example that permits to get OSREL at install time?
> >
> > # osrel=$(sysctl -n kern.osrelease)
> > # echo $osrel ${osrel%%-*} ${osrel%%.*}
> > 13.2-STABLE 13.2 13
> >
> > And use @postexec command in pkg-plist to run sed instead of
> REINPLACE_CMD in the Makefile.
> > Something like this (untested):
> >
> > @postexec env osrel=$(sysctl -n kern.osrelease) sed -E -e
> s,stable/[0-9]+,stable/${osrel\%\%.*}, -e
> s,releng/[0-9]+,releng/${osrel\%\%-*}, %%PREFIX%%/etc/gitup.conf
>
> Jail-friendly replacement is $(freebsd-version -u) instead of (sysctl -n
> kern.osrelease).
>
> "freebsd-version -u" reports version of userland and in case of full jail
> it may be older than kernel version.
>
>

-- 
Nuno Teixeira
FreeBSD Committer (ports)