#!/bin/bash input='/usr/share/libalpm/hooks/90-linux.hook' target=$( grep -m1 'Target = ' "${input}" | \ cut -d'=' -f2 | \ sed 's|\s\+||g' ) sed ' /Description =/{ s/=\s*/= Test permissions for / a When = PreTransaction\ Exec = /usr/bin/sh -c '"'"'[ -w /'"${target}"' ]'"'"'\ AbortOnFail q } ' "${input}"