Difference between revisions of "User talk:Allan/Pacman Hooks - Version 1"

From ArchWiki
Jump to: navigation, search
(Created page with 'Hi, I think it would be really useful to have pacman hooks for a simliar reason: As a zsh user, whenever I update a package, I need to manually run the rehash built-in so that z...')
 
 
(6 intermediate revisions by 4 users not shown)
Line 9: Line 9:
  
 
binaural gmail com
 
binaural gmail com
 +
 +
== Matt's Method ==
 +
 +
-- [[User:Piezoelectric|Piezoelectric]] 13:00, 11 April 2010 (EDT)
 +
 +
Hey, Allan, I like your idea. In fact I came across it after posting a feature request [http://bugs.archlinux.org/task/19044 FS#19044]. I'll outline my ideas here in a similar matter to your own.
 +
 +
=== Directory Layout ===
 +
/etc/pacman.d/
 +
              /hooks.sh
 +
              /local.d/
 +
                      /<pkgname>.install
 +
 +
=== hooks.sh ===
 +
 +
This is the general dispatch file, while the entire functionality of this file ''could'' be built directly into pacman, and the file itself ignored altogether, I think it's best to do it like this, because what we are going for in the first place is maximum per-user flexibility.
 +
 +
{{hc|hooks.sh|2=
 +
#!/bin/sh
 +
 +
# this is just the basic idea, no error checking, etc
 +
 +
#action will be one of: pre_install, post_install, pre_upgrade,
 +
#                      post_upgrade, pre_remove, post_remove
 +
action=$1
 +
 +
# package will be the package name in question
 +
package=$2
 +
 +
# get local install info
 +
source /etc/pacman.d/${package}.install
 +
 +
# execute local action if it exists
 +
$action
 +
 +
}}
 +
 +
=== <pkgname>.install example ===
 +
 +
=== TODO ===
 +
 +
Each {{ic|<pkgname>.install}} should be able to specify when in it will be performed in relation to the install file that comes with the package. Ex: {{ic|<nowiki>TIMING={before|replace|after}</nowiki>}}
 +
 +
I'll integrate this idea in a little bit, I just wanted to make note of it in case someone happens across this in the short time that I step away =)
 +
 +
== Input From a n00b ==
 +
Hi. I was gonna take a crack at implementing shell hooks in pacman a few weeks ago,
 +
but when I looked into it on the mailing lists/wiki/flyspray,
 +
it looked like two or three people had already taken a stab at it,
 +
and that development on the feature was being postponed until after package signing/the new libalpm API was done.
 +
 +
Anyway, I wrote something similar for CentOS so that I didn't have to write yum plugins in python for work anymore,
 +
borrowing heavily from Matt's idea above.
 +
The bulk of the implementation is in this hooks.sh script:
 +
{{hc|/etc/yum/hooks.sh|2=
 +
#!/bin/bash
 +
 +
action="$1"
 +
 +
for file in /etc/yum/hooks.d/*.sh; do
 +
        if [ -r "$file" ]; then
 +
                . "$file"
 +
                if [ "$(type -t $action 2>/dev/null)" = "function" ]; then
 +
                        echo "$file"
 +
                        $action
 +
                        unset "$action"
 +
                fi
 +
        fi
 +
done
 +
 +
}}
 +
 +
This doesn't handle per-package or per-file hooks,
 +
as I don't have any real immediate use for that,
 +
but I just figured I'd share it here in the hopes that it'd useful in some way.
 +
I'd definitely like to see per-transaction shell hooks in pacman,
 +
maybe with a layout something like:
 +
/etc/pacman.d/
 +
              /hooks.sh      <-- controls execution of .install files in directories below
 +
              /hooks.d/      <-- per-transaction .install files
 +
              /hooks.pkg.d/  <-- per-package .install files
 +
 +
...and I guess with this layout, you'd want a hooks.sh
 +
(or equivalent functionality in pacman)
 +
that did what mine does unless it gets a second, optional package argument,
 +
in which case it does what Matt's does.
 +
 +
Anyway, HTH --[[User:Buce|Buce]] 14:59, 30 June 2011 (EDT)

Latest revision as of 11:42, 5 July 2013

Hi, I think it would be really useful to have pacman hooks for a simliar reason:

As a zsh user, whenever I update a package, I need to manually run the rehash built-in so that zsh will recognize new/updated paths.

A pacman PostInstall hook would cut out this step.

Thanks! Noah

binaural gmail com

Matt's Method

-- Piezoelectric 13:00, 11 April 2010 (EDT)

Hey, Allan, I like your idea. In fact I came across it after posting a feature request FS#19044. I'll outline my ideas here in a similar matter to your own.

Directory Layout

/etc/pacman.d/
             /hooks.sh
             /local.d/
                     /<pkgname>.install

hooks.sh

This is the general dispatch file, while the entire functionality of this file could be built directly into pacman, and the file itself ignored altogether, I think it's best to do it like this, because what we are going for in the first place is maximum per-user flexibility.

hooks.sh
#!/bin/sh

# this is just the basic idea, no error checking, etc

#action will be one of: pre_install, post_install, pre_upgrade,
#                       post_upgrade, pre_remove, post_remove
action=$1

# package will be the package name in question
package=$2

# get local install info
source /etc/pacman.d/${package}.install

# execute local action if it exists
$action

<pkgname>.install example

TODO

Each <pkgname>.install should be able to specify when in it will be performed in relation to the install file that comes with the package. Ex: TIMING={before|replace|after}

I'll integrate this idea in a little bit, I just wanted to make note of it in case someone happens across this in the short time that I step away =)

Input From a n00b

Hi. I was gonna take a crack at implementing shell hooks in pacman a few weeks ago, but when I looked into it on the mailing lists/wiki/flyspray, it looked like two or three people had already taken a stab at it, and that development on the feature was being postponed until after package signing/the new libalpm API was done.

Anyway, I wrote something similar for CentOS so that I didn't have to write yum plugins in python for work anymore, borrowing heavily from Matt's idea above. The bulk of the implementation is in this hooks.sh script:

/etc/yum/hooks.sh
#!/bin/bash

action="$1"

for file in /etc/yum/hooks.d/*.sh; do
        if [ -r "$file" ]; then
                . "$file"
                if [ "$(type -t $action 2>/dev/null)" = "function" ]; then
                        echo "$file"
                        $action
                        unset "$action"
                fi
        fi
done

This doesn't handle per-package or per-file hooks, as I don't have any real immediate use for that, but I just figured I'd share it here in the hopes that it'd useful in some way. I'd definitely like to see per-transaction shell hooks in pacman, maybe with a layout something like:

/etc/pacman.d/
             /hooks.sh      <-- controls execution of .install files in directories below
             /hooks.d/      <-- per-transaction .install files
             /hooks.pkg.d/  <-- per-package .install files

...and I guess with this layout, you'd want a hooks.sh (or equivalent functionality in pacman) that did what mine does unless it gets a second, optional package argument, in which case it does what Matt's does.

Anyway, HTH --Buce 14:59, 30 June 2011 (EDT)