Bug 270911 - net/gitup: Improve gitup.conf auto config
Summary: net/gitup: Improve gitup.conf auto config
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Nuno Teixeira
URL:
Keywords:
Depends on:
Blocks: 255323
  Show dependency treegraph
 
Reported: 2023-04-18 13:27 UTC by Nuno Teixeira
Modified: 2023-06-03 12:08 UTC (History)
3 users (show)

See Also:


Attachments
gitup_config v0 (1.23 KB, patch)
2023-04-18 13:27 UTC, Nuno Teixeira
no flags Details | Diff
gitup_config v1 (1.13 KB, patch)
2023-04-18 13:31 UTC, Nuno Teixeira
no flags Details | Diff
gitup_config v2 (1.28 KB, patch)
2023-04-18 13:33 UTC, Nuno Teixeira
no flags Details | Diff
v3 (1.98 KB, patch)
2023-05-08 09:26 UTC, Nuno Teixeira
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nuno Teixeira freebsd_committer freebsd_triage 2023-04-18 13:27:05 UTC
Created attachment 241559 [details]
gitup_config v0

Current auto config feature detects osrel at build time what leads to an wrong setup if build machine has other version than system where it will be installed.

Find osrel on install time through pkg-post-install.
Comment 1 Nuno Teixeira freebsd_committer freebsd_triage 2023-04-18 13:31:02 UTC
Created attachment 241560 [details]
gitup_config v1

Clean Makefile, delete reinplace comments
Comment 2 Nuno Teixeira freebsd_committer freebsd_triage 2023-04-18 13:33:40 UTC
Created attachment 241561 [details]
gitup_config v2

add PORTREVISION
Comment 3 Nuno Teixeira freebsd_committer freebsd_triage 2023-04-18 13:38:47 UTC
TODO:

- run on CURRENT and STABLE to check if gitup.conf generated values makes sense and if needed some tweaks.
Comment 4 Nuno Teixeira freebsd_committer freebsd_triage 2023-04-18 13:47:27 UTC
(In reply to Nuno Teixeira from comment #3)
(...)

- should we use lua instead? pkg-script(5) pkg-lua-script(5)
Comment 5 Felix Palmen freebsd_committer freebsd_triage 2023-04-18 16:02:19 UTC
(In reply to Nuno Teixeira from comment #4)
> - should we use lua instead? pkg-script(5) pkg-lua-script(5)
IMHO doesn't matter much here. It works fine in shell and isn't too complex either. I would certainly go for lua when more complex things must be accomplished...

I'd probably remove all output, but that's just personal taste.

But then, thinking about it for a while: What happens on updates? Will it automatically change an already installed config file? If so, this would be a POLA violation.

Maybe doing the replacement on the .sample would be the better idea? I don't know whether this works before it is initially copied on first install though.
Comment 6 Nuno Teixeira freebsd_committer freebsd_triage 2023-04-19 10:18:44 UTC
(In reply to Felix Palmen from comment #5)

osrel detection:

* old version: detection at build stage

- reinplace is done in WRKSRC/gitup.conf
- changed config is installed in PREFIX/etc/gitup.conf.sample
  and to PREFIX/etc/gitup.conf if it don't exist (@sample macro)

* new version: detection at post-install stage

-- reinplace is done in PREFIX/etc/gitup.conf (POLA)
-+ reinplace should be done in PREFIX/etc/gitup.conf.sample

It was nice that we have a PRE-INSTALL to check if there is a 
PREFIX/etc/gitup.conf present and if not, both .config and .config.sample could be changed to updated osrel. If it is present, then update only .config.sample. Do what @sample macro do.

The problem that I found is that pkg-install runs 2 times: PRE-INSTALL and POST-INSTALL and I cannot send variables from one state to the other.

So I'm still playing with pkg-post-install and I will try again @postexec in pkg-plist.

I'm completly lost on how to find the best way to implement a osrel detection at install stage like an addon, without changing port, but I will need to think in other solutions.
Comment 7 Nuno Teixeira freebsd_committer freebsd_triage 2023-04-19 10:24:55 UTC
(In reply to Nuno Teixeira from comment #6)
(...)

Also, it must exist a mechanism to check STABLE and CURRENT and do reinplace accordingly. To be done when I have a working setup.

Resuming, I'd like to preserve what @sample macro do nicely by installing a fresh and updated gitup.conf and .sample for a fresh install/new user or only update .sample if gitup.conf is changed by user.

Easy :)
Comment 8 Nuno Teixeira freebsd_committer freebsd_triage 2023-04-19 11:39:05 UTC
(In reply to Nuno Teixeira from comment #7)

(...)

Found a way to have a working @postexec

pkg-plist:

bin/gitup
share/man/man1/gitup.1.gz
share/man/man5/gitup.conf.5.gz
@sample etc/gitup.conf.sample
@postexec sed -E -e "s,stable/[0-9]+,stable/$(freebsd-version -u|cut -c 1-2)," -e "s,releng/[0-9]+.[0-9]+,releng/$(freebsd-version -u|cut -c 1-4)," %%PREFIX%%/etc/gitup.conf.sample

"branch"           : "releng/13.2",
"branch"           : "stable/13",

Same issue on how to interact with @preexec and with @sample macro.
Comment 9 Felix Palmen freebsd_committer freebsd_triage 2023-04-19 12:12:52 UTC
(In reply to Nuno Teixeira from comment #8)
> @postexec sed -E -e [...]
TBH, I don't like this. IMHO, it's much too complex for a "command" in pkg-plist, this is just unreadable and should really better be handled by explicit scripts instead.

On the general topic, kudos to your efforts! I see and understand the problem of course. And if there's a "good" solution (not violating POLA, but assisting the user by installing a sample matching their system), that would be great! But as soon as it gets just too complex and unreadable, I'd probably qualify it as "bikeshed" and rather opt for the users to fix their configuration themselves...

Still, interesting issue. Maybe I'll find the time to experiment a bit myself!
Comment 10 Nuno Teixeira freebsd_committer freebsd_triage 2023-04-19 12:41:45 UTC
(In reply to Felix Palmen from comment #9)

Yes, I confess it's a big uggly cmd to put in pkg-plist :)

But the fun is all mine! I did great and powerfull POLA violations in my testings lol

Cheers
Comment 11 Graham Perrin freebsd_committer freebsd_triage 2023-05-07 13:01:26 UTC
(In reply to Nuno Teixeira from comment #3)

> TODO:
> 
> - run on CURRENT and STABLE to check if gitup.conf generated values 
>   makes sense and if needed some tweaks.

Should I use the patch from comment 2? 

I'd like to test and feedback ASAP before releng/14.0 is created. 

Thanks
Comment 12 Nuno Teixeira freebsd_committer freebsd_triage 2023-05-08 09:26:13 UTC
Created attachment 242051 [details]
v3

- Find osrel on install time through pkg-post-install to get an updated match on gitup.conf.sample
- Only install gitup.conf.sample
- Add message on install with information about gitup.conf(5) and gitup.sample.
Comment 13 Nuno Teixeira freebsd_committer freebsd_triage 2023-05-08 09:28:29 UTC
(In reply to Nuno Teixeira from comment #12)
(...)

While I'm here, move pkg-plist to PLIST_FILES
Comment 14 commit-hook freebsd_committer freebsd_triage 2023-06-03 12:06:54 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=574c5c9142f39aea9da2ffccce25bbd8401242f9

commit 574c5c9142f39aea9da2ffccce25bbd8401242f9
Author:     Nuno Teixeira <eduardo@FreeBSD.org>
AuthorDate: 2023-06-03 12:02:06 +0000
Commit:     Nuno Teixeira <eduardo@FreeBSD.org>
CommitDate: 2023-06-03 12:06:38 +0000

    net/gitup: Improve gitup.conf auto config

    - Find osrel on install time through pkg-post-install to get an updated
      match on gitup.conf.sample
    - Only install gitup.conf.sample
    - Add message on install with information about gitup.conf(5) and
      gitup.sample
    - Move pkg-plist to PLIST_FILES

    PR:             270911

 net/gitup/Makefile                   | 12 ++++++------
 net/gitup/files/pkg-message.in (new) | 12 ++++++++++++
 net/gitup/pkg-plist (gone)           |  4 ----
 net/gitup/pkg-post-install (new)     |  5 +++++
 4 files changed, 23 insertions(+), 10 deletions(-)
Comment 15 Nuno Teixeira freebsd_committer freebsd_triage 2023-06-03 12:08:59 UTC
Committed.