* example-hook is a template * checksums computes file checksums after package installation Signed-off-by: Daniel Mendler <mail@daniel-mendler.de> --- etc/pacman.d/hooks/checksums | 51 +++++++++++++++++++++++++++++++++++++++ etc/pacman.d/hooks/example-hook | 41 +++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 0 deletions(-) create mode 100644 etc/pacman.d/hooks/checksums create mode 100644 etc/pacman.d/hooks/example-hook diff --git a/etc/pacman.d/hooks/checksums b/etc/pacman.d/hooks/checksums new file mode 100644 index 0000000..7ad19a1 --- /dev/null +++ b/etc/pacman.d/hooks/checksums @@ -0,0 +1,51 @@ +# +# /etc/pacman.d/hooks/checksums +# +# Example script which computes checksums for each file after package installation. +# It can be used to check system integrity. +# + +post_install() { + name=$1 + ver=$2 + pkg=$name-$ver + pkg_path="/var/lib/pacman/local/$pkg" + echo "computing checksums for $pkg" + files=`sed -e '/^%FILES%$/d;/^$/d;s/.*/\/&/' "$pkg_path/files"` + # Write checksum entries + # filename type mode owner group (link target/sha256 checksum) + for file in $files; do + mode=`stat -c '%a' $file` + owner=`stat -c '%u' $file` + group=`stat -c '%g' $file` + if [ -L "$file" ]; then + link=`readlink $file` + echo "$file s $mode $owner $group $link" + elif [ -f "$file" ]; then + checksum=`sha256sum $file` + echo "$file f $mode $owner $group ${checksum:0:64}" + elif [ -d "$file" ]; then + echo "$file d $mode $owner $group" + fi + done > "$pkg_path/checksums" +} + +pre_remove() { + name=$1 + ver=$2 + rm -f "/var/lib/pacman/local/$name-$ver/checksums" +} + +pre_upgrade() { + name=$1 + ver=$2 + oldver=$3 + pre_remove $name $oldver +} + +post_upgrade() { + name=$1 + ver=$2 + oldver=$3 + post_install $name $ver +} diff --git a/etc/pacman.d/hooks/example-hook b/etc/pacman.d/hooks/example-hook new file mode 100644 index 0000000..e91f935 --- /dev/null +++ b/etc/pacman.d/hooks/example-hook @@ -0,0 +1,41 @@ +# +# /etc/pacman.d/hooks/example-hook +# + +pre_install() { + name=$1 + ver=$2 + echo "example-hook: pre_install $name $ver" +} + +post_install() { + name=$1 + ver=$2 + echo "example-hook: post_install $name $ver" +} + +pre_upgrade() { + name=$1 + ver=$2 + oldver=$3 + echo "example-hook: pre_upgrade $name $ver $oldver" +} + +post_upgrade() { + name=$1 + ver=$2 + oldver=$3 + echo "example-hook: post_upgrade $name $ver $oldver" +} + +pre_remove() { + name=$1 + ver=$2 + echo "example-hook: pre_remove $name $ver" +} + +post_remove() { + name=$1 + ver=$2 + echo "example-hook: post_remove $name $ver" +} -- 1.7.3.5