Permalink
Browse files

customizepkg: make more robust

- do not require double escaping anymore
- do not require escaping of anything but regex/sed control characters
  • Loading branch information...
1 parent 6631b43 commit 4baa2e2da96ca017545d5106250a1b687d531a68 @AlD committed Sep 3, 2013
Showing with 12 additions and 16 deletions.
  1. +12 −16 customizepkg/customizepkg
View
28 customizepkg/customizepkg
@@ -47,46 +47,41 @@ modify_file()
configfile=$1
originalscriptfile=$2
scriptfile=$3
- grep --invert-match "\(^#\|^$\)" $configfile |
- while read line; do
- unset action context pattern value
- action=`echo $line | awk -F "#" '{print $1}'`
- context=`echo $line | awk -F "#" '{print $2}'`
- pattern=`echo $line | awk -F "#" '{print $3}'`
+ while IFS='#' read -r action context pattern value; do
#echo "action=$action , context=$context , pattern=$pattern"
+ [[ -n "$action" ]] && # filter out comments
case $action in
remove|replace)
- value=`echo $line | awk -F [^#]# '{print $4}'`
echo "=> removes/replaces '$pattern' by '$value' in $context"
if [ "$action" = "replace" -a "$context" != "global" ]; then
value=" '$(echo $value | tr -d "\'")'"
fi
if [ "$context" != "global" ]; then
- pattern="$pattern[<>=]*[a-z0-9.]*"
+ pattern="${pattern}[<>=]*[a-z0-9.]*"
fi
if [ "$context" = "global" ]; then
- sed -i "s/$pattern/$value/g" "$scriptfile"
+ sed -i "s#$pattern#$value#g" "$scriptfile"
else
- sed -i "/^$context=/,/)$/ s/[[:space:]]*[']*$pattern[']*/$value/g" "$scriptfile"
+ sed -i "\#^$context=#,\#)$# s#[[:space:]]*[']*$pattern[']*#$value#g" "$scriptfile"
fi
;;
add)
value=" '$(echo $pattern | tr -d "\'")'"
echo "=> adds $value in $context"
# add the full line if it doesn't exist or just the value
if grep --quiet "^$context=" "$scriptfile"; then
- sed -i "s/^$context=(/&$value /1" "$scriptfile"
+ sed -i "s#^$context=(#&$value #1" "$scriptfile"
else
- sed -i "/^build/i$context=($value)\n" "$scriptfile"
+ sed -i "\#^build#i$context=($value)\n" "$scriptfile"
fi
;;
*)
echo "error: unknow action '$action'"
;;
esac
- done
- [ $VIMDIFF -eq 1 ] && vim -d "$scriptfile" "$originalscriptfile"
- diff -Naur "$originalscriptfile" "$scriptfile"
+ done < $configfile
+ [ $VIMDIFF -eq 1 ] && vim -d "$scriptfile" "$originalscriptfile"
+ diff -Naur "$originalscriptfile" "$scriptfile"
return 0
}
@@ -115,7 +110,8 @@ if [ ! -r ./PKGBUILD ]; then
echo "PKGBUILD not found"
exit 1
fi
-source ./PKGBUILD || exit 1
+
+eval $(egrep '^[[:space:]]*pkgname=' ./PKGBUILD | head -n 1)
if [ ! -r "$CONFIGDIR/$pkgname" ]; then
echo "no configuration found for $pkgname in $CONFIGDIR/"

0 comments on commit 4baa2e2

Please sign in to comment.