You are not logged in.

#1 2020-05-22 15:43:30

LeSnake
Member
Registered: 2020-04-23
Posts: 3

User input in Pacman hooks?

It is possible to get user input in pacman hooks?

I already tried some ways:
read
sh -c read
python -c print(input())

But every time, it just jump over the input..

Anyone know why this happened and how to fix?

Offline

#2 2020-05-22 15:47:55

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,001
Website

Re: User input in Pacman hooks?

I don't think they are meant to be interactive.  Maybe someone from the pacman team will see your message and confirm.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#3 2020-05-22 16:12:19

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 3,426

Re: User input in Pacman hooks?

graysky wrote:

Maybe someone from the pacman team will see your message and confirm.

Stdout and stderr are connected via pipes from the chroot process and don't have direct access to the running terminal.

We explicitly close stdin, (after connecting it, to guarantee that fd 0 exists and it is empty), in order to forbid user input.

This is determinedly intended to not work; don't do it.

References:
https://git.archlinux.org/pacman.git/co … 68f0f8d8a0
https://git.archlinux.org/pacman.git/co … 1087955a7b


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#4 2020-06-30 08:52:54

LeSnake
Member
Registered: 2020-04-23
Posts: 3

Re: User input in Pacman hooks?

eschwartz wrote:
graysky wrote:

Maybe someone from the pacman team will see your message and confirm.

Stdout and stderr are connected via pipes from the chroot process and don't have direct access to the running terminal.

We explicitly close stdin, (after connecting it, to guarantee that fd 0 exists and it is empty), in order to forbid user input.

This is determinedly intended to not work; don't do it.

References:
https://git.archlinux.org/pacman.git/co … 68f0f8d8a0
https://git.archlinux.org/pacman.git/co … 1087955a7b

ok, that explain everything.
Maybe you should consider adding an ask before executing tag and a default answear (that controll if the hook is executed by default and has to be canceled with 'n' or wont run without entering 'Y' ) in the hook file.
The may terminal ask something like "Run "timeshift.hook" hook? [Y/n]"
i would love this option.

Last edited by LeSnake (2020-06-30 09:06:10)

Offline

#5 2020-06-30 09:55:29

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 811
Website

Re: User input in Pacman hooks?

If you want to run some backup prgram before or after a pacman upgrade, just do it.
Pacman is a package manager, not a backup manager.
If you want to automatically create backups before and after an upgrade based on the packages upgraded, you can create a hook with NeedsTargets and let the respective backup script determine whether to backup or not.

Offline

#6 2020-06-30 10:40:15

mpan
Member
Registered: 2012-08-01
Posts: 542
Website

Re: User input in Pacman hooks?

While with makepkg no interaction is an obvious choice, for me it isn’t such with pacman — a program that is interactive by nature and has the official policy of “no unattended upgrades”. So “we don’t want interaction” is not an argument that I myself would accept.

However, there is another one and I wish to share it with you, LeSnake: reliability. Hooks are already moving pacman more away from the declarative towards the imperative domain. This gives more power to package maintainers by removing constraints, but that also implies lower reliability.⁽¹⁾ Letting hooks interact with the user adds yet another point of failure. I doubt anyone has will and resources to deal with that risk for little benefit such features provide.
____
⁽¹⁾ Or at least lower reliability/effort ratio.


Sometimes I seem a bit harsh — don’t get offended too easily! PGP: 7C848198AE93D3BB

Offline

#7 2020-06-30 11:32:39

Allan
Member
From: Brisbane, AU
Registered: 2007-06-09
Posts: 10,939
Website

Re: User input in Pacman hooks?

mpan wrote:

So “we don’t want interaction” is not an argument that I myself would accept.

Would the answer "Allan said no" be acceptable?

Offline

#8 2020-06-30 11:48:53

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 3,426

Re: User input in Pacman hooks?

mpan wrote:

While with makepkg no interaction is an obvious choice, for me it isn’t such with pacman — a program that is interactive by nature and has the official policy of “no unattended upgrades”. So “we don’t want interaction” is not an argument that I myself would accept.

However, there is another one and I wish to share it with you, LeSnake: reliability. Hooks are already moving pacman more away from the declarative towards the imperative domain. This gives more power to package maintainers by removing constraints, but that also implies lower reliability.⁽¹⁾ Letting hooks interact with the user adds yet another point of failure. I doubt anyone has will and resources to deal with that risk for little benefit such features provide.
____
⁽¹⁾ Or at least lower reliability/effort ratio.

Hooks don't do anything that install scripts didn't already do.

LeSnake wrote:

ok, that explain everything.
Maybe you should consider adding an ask before executing tag and a default answear (that controll if the hook is executed by default and has to be canceled with 'n' or wont run without entering 'Y' ) in the hook file.
The may terminal ask something like "Run "timeshift.hook" hook? [Y/n]"
i would love this option.

No.

Why do you think it's okay to just... not run a hook? Should we also add confirmation prompts every time we extract a file from a package? The point of a hook is to always run...


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#9 2020-06-30 11:56:09

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 23,689
Website

Re: User input in Pacman hooks?

A several line pacman wrapper function would get you want you want.  Just grep the output of checkupdates for the package you want to trigger this action on, then offer the user to option to run the action if the triggering package is in that output, then complete the upgrade with `pacman -Syu`.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB