Skip to content
This repository has been archived by the owner on Jun 4, 2018. It is now read-only.

[manjaro-system] pacman 5.0 hooks #29

Open
udeved opened this issue Feb 9, 2016 · 15 comments
Open

[manjaro-system] pacman 5.0 hooks #29

udeved opened this issue Feb 9, 2016 · 15 comments
Labels

Comments

@udeved
Copy link
Contributor

udeved commented Feb 9, 2016

After reading a bit on the new pacman hooks, I think it enables new approach to manjaro-system?

If I understood correctly, the hooks are per transaction.
Could this solve some shortcommings with manjaro-system being upgraded first?
Could manjaro-system become (a) pacman hook(s)?

@philmmanjaro
Copy link
Member

We have to check that. Also how they work. As of now I didn't found examples for it or had no time to check ...

@udeved
Copy link
Contributor Author

udeved commented Feb 9, 2016

I think it support eg like pre or post transaction hooks.

Here are example hooks I found on arch forums.
https://github.com/andrewgregory/pachooks/tree/working

@papajoker
Copy link

hooks are for admin and not for repleace pkgbuild/.install

my tests :

a exemple for no remove manjaro-system:

#/usr/share/libalpm/hooks/mandatory-base.hook
[Trigger]
Operation = Remove
Type = Package
Target = manjaro-system
Target = manjaro-keyring
Target = pacman
[Action]
Description = no remove this package !
When = PreTransaction
Exec = /usr/bin/false
AbortOnFail

or for a real open-rc ?

#/etc/pacman.d/hooks/nosystemd.hook
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = systemd
[Action]
Description = no compliant package !
When = PreTransaction
Exec = /usr/bin/false
AbortOnFail

exemple for write in journald :

#/etc/pacman.d/hooks/journald-remove.hook
[Trigger]
Operation = Remove
Type = Package
Target = *
[Action]
Description = write on journald OPERATION=remove
When = PostTransaction
Exec = /etc/pacman.d/hooks.bin/journald.sh remove
Depends = util-linux
NeedsTargets

#/etc/pacman.d/hooks.bin/journald.sh
#!/bin/bash
[[ "${HTTP_USER_AGENT:0:6}" != 'pacman' ]] && exit 2
declare -r operation="$1"
declare -a packages=()

# journalctl -t pacman OPERATION=remove : script history in journald
function logd(){
   local msg=$1
   local niveau=${2:-6}
   printf "%s\n%s\n%s\n%s" \
          MESSAGE="${operation} : ${msg}"  \
          SYSLOG_IDENTIFIER="pacman" \
          PRIORITY="${niveau}" \
          OPERATION="${operation}" \
          | logger --journald
}

while read -r package; do
    packages=("$package" "${packages[@]}")
done
logd "${packages[*]}" 6

for admin dependences :

#/etc/pacman.d/hooks/filter-dep.hook
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = *
[Action]
Description = filtre dependances
When = PreTransaction
Exec = /etc/pacman.d/hooks.bin/filter-dep.sh " lib " " libtarXX" " gnome"
Depends = yaourt
NeedsTargets
AbortOnFail

#/etc/pacman.d/hooks.bin/filter-dep.sh
#!/bin/bash
[[ "${HTTP_USER_AGENT:0:6}" != 'pacman' ]] && exit 2
while read -r package; do
    deps=$(LANG=C yaourt -Si "${package}" 2>/dev/null | awk -F':' '/^Depend/ {print $2}')
    for d in "${args[@]}"; do
        if [[ "${deps}" =~ "${d}" ]]; then
            echo "[$(date +'%F %H:%I')] [HOOK] Error, deny dependence ${d} for ${package}" >>/var/log/pacman.log
            echo "deny dependence ! ${d} for ${package}"
            exit 9
        fi
    done
done                        

I have 2 manjaro and 2 arch on my pc, for to have a clear grub menu:

#/etc/pacman.d/hooks/lsb-release.hook
[Trigger]
Operation = Install
Operation = Upgrade
Type = File
Target = etc/lsb-release
[Action]
Description = lsb-release change grub description
When = PostTransaction
Exec = /usr/bin/sed -i 's/^DISTRIB_DESCRIPTION.*/DISTRIB_DESCRIPTION="Manjaro Plasma5"/' /etc/lsb-release

and for my archlinux only :

#/etc/pacman.d/hooks/pacman-mirrorlist
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = pacman-mirrorlist
[Action]
Description = run reflector
When = PostTransaction
Depends = reflector
Exec = /etc/pacman.d/hooks.bin/pacman-mirrorlist.sh

#/etc/pacman.d/hooks.bin/pacman-mirrorlist.sh
#!/bin/sh
[[ "${HTTP_USER_AGENT:0:6}" != 'pacman' ]] && exit 2
# add --country XXXXX 
reflector --verbose -l 4 -p http --sort rate --save /etc/pacman.d/mirrorlist 1>/dev/null
if (($?==0)); then
    echo "[$(date +'%F %H:%I')] [HOOK] pacman-mirrorlist" >>/var/log/pacman.log
    if [ -f "/etc/pacman.d/mirrorlist.pacnew" ]; then
        rm -v /etc/pacman.d/mirrorlist.pacnew
    else
        echo "no .pacnew to remove ?"
    fi
fi

@udeved
Copy link
Contributor Author

udeved commented Mar 5, 2016

https://github.com/udeved/manjaro-pacman-hooks

I am about to test it.

@udeved
Copy link
Contributor Author

udeved commented Mar 5, 2016

@udeved
Copy link
Contributor Author

udeved commented Mar 5, 2016

@papajoker
Copy link

Attention, this hook is fired to all install or update (target = *)
So we do 50 "pacman -Qq" every time :(
I proposed another form in the forum with "NeedsTargets" which allows for a swich but the problem remains that it runs every time

# NeedsTargets in .hook
while read -r package; do
    case "$package" in
        gdm):
            if [ "$(vercmp $2 20151019-2)" -lt 0 ]; then
                    pacman -Qq gdm &> /tmp/cmd1
                    if [[ "$(grep 'gdm' /tmp/cmd1)" == "gdm" ]]; then
                        msg "Stop GDM attempting to use Wayland ..."
                        sed -i -e 's/#WaylandEnable=false/WaylandEnable=false/' /etc/gdm/custom.conf
                    fi
            fi
        ;;
        dbus-openrc):
            pacman -Qq dbus-openrc &> /tmp/cmd_dbus_rc
            if [ "$(vercmp $2 20150611)" -eq 0 ] && \
                [ "$(grep 'dbus-openrc' /tmp/cmd_dbus_rc)" == "dbus-openrc" ];then
                msg "Upgrading 'dbus-openrc' ..."
                rm /var/lib/pacman/db.lck &> /dev/null
                pacman --noconfirm -Rdd dbus
                pacman --noconfirm -Syu dbus-openrc netifrc
            fi
        ;;
    esac
done

I'm not sure that we can install a package in pretransaction (pacman --noconfirm -Syu dbus-openrc netifrc), it will not restart even hook indefinitely?

AFTER tests, is ok we can exec pacman -S in a script hook preTransaction :

@udeved
Copy link
Contributor Author

udeved commented Mar 5, 2016

The hook will be split up into package hooks.
This is just an initial version.

@philmmanjaro
Copy link
Member

Before we introduce them, they have to been tested first. Good work so far.

@udeved
Copy link
Contributor Author

udeved commented Mar 7, 2016

@udeved udeved added the todo label Mar 7, 2016
@udeved
Copy link
Contributor Author

udeved commented Mar 7, 2016

I think if we implement the hooks, the syncfirst patch could be dropped from pacman.

@papajoker
Copy link

without syncfirst, old hook are executed and not the new with update

@udeved
Copy link
Contributor Author

udeved commented Mar 7, 2016

Nope, because manjaro-system would be no more.
The hooks package would conflict with it.

@udeved
Copy link
Contributor Author

udeved commented Mar 8, 2016

I have added a mhwd sample hook that triggers mhwd-gpu --setgl

https://github.com/udeved/manjaro-pacman-hooks/commit/451a168144823909e83cfb8ce349843e97672aa9

We could also let it be triggered by multiple package targets.

@udeved
Copy link
Contributor Author

udeved commented Mar 25, 2016

manjaro/release-plan#39

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants