Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

customizepkg: make more robust

- do not require double escaping anymore
- do not require escaping of anything but regex/sed control characters
commit 4baa2e2da96ca017545d5106250a1b687d531a68 1 parent 6631b43
Daniel Albers authored

Showing 1 changed file with 12 additions and 16 deletions. Show diff stats Hide diff stats

  1. +12 16 customizepkg/customizepkg
28 customizepkg/customizepkg
@@ -47,27 +47,22 @@ modify_file()
47 47 configfile=$1
48 48 originalscriptfile=$2
49 49 scriptfile=$3
50   - grep --invert-match "\(^#\|^$\)" $configfile |
51   - while read line; do
52   - unset action context pattern value
53   - action=`echo $line | awk -F "#" '{print $1}'`
54   - context=`echo $line | awk -F "#" '{print $2}'`
55   - pattern=`echo $line | awk -F "#" '{print $3}'`
  50 + while IFS='#' read -r action context pattern value; do
56 51 #echo "action=$action , context=$context , pattern=$pattern"
  52 + [[ -n "$action" ]] && # filter out comments
57 53 case $action in
58 54 remove|replace)
59   - value=`echo $line | awk -F [^#]# '{print $4}'`
60 55 echo "=> removes/replaces '$pattern' by '$value' in $context"
61 56 if [ "$action" = "replace" -a "$context" != "global" ]; then
62 57 value=" '$(echo $value | tr -d "\'")'"
63 58 fi
64 59 if [ "$context" != "global" ]; then
65   - pattern="$pattern[<>=]*[a-z0-9.]*"
  60 + pattern="${pattern}[<>=]*[a-z0-9.]*"
66 61 fi
67 62 if [ "$context" = "global" ]; then
68   - sed -i "s/$pattern/$value/g" "$scriptfile"
  63 + sed -i "s#$pattern#$value#g" "$scriptfile"
69 64 else
70   - sed -i "/^$context=/,/)$/ s/[[:space:]]*[']*$pattern[']*/$value/g" "$scriptfile"
  65 + sed -i "\#^$context=#,\#)$# s#[[:space:]]*[']*$pattern[']*#$value#g" "$scriptfile"
71 66 fi
72 67 ;;
73 68 add)
@@ -75,18 +70,18 @@ modify_file()
75 70 echo "=> adds $value in $context"
76 71 # add the full line if it doesn't exist or just the value
77 72 if grep --quiet "^$context=" "$scriptfile"; then
78   - sed -i "s/^$context=(/&$value /1" "$scriptfile"
  73 + sed -i "s#^$context=(#&$value #1" "$scriptfile"
79 74 else
80   - sed -i "/^build/i$context=($value)\n" "$scriptfile"
  75 + sed -i "\#^build#i$context=($value)\n" "$scriptfile"
81 76 fi
82 77 ;;
83 78 *)
84 79 echo "error: unknow action '$action'"
85 80 ;;
86 81 esac
87   - done
88   - [ $VIMDIFF -eq 1 ] && vim -d "$scriptfile" "$originalscriptfile"
89   - diff -Naur "$originalscriptfile" "$scriptfile"
  82 + done < $configfile
  83 + [ $VIMDIFF -eq 1 ] && vim -d "$scriptfile" "$originalscriptfile"
  84 + diff -Naur "$originalscriptfile" "$scriptfile"
90 85 return 0
91 86 }
92 87
@@ -115,7 +110,8 @@ if [ ! -r ./PKGBUILD ]; then
115 110 echo "PKGBUILD not found"
116 111 exit 1
117 112 fi
118   -source ./PKGBUILD || exit 1
  113 +
  114 +eval $(egrep '^[[:space:]]*pkgname=' ./PKGBUILD | head -n 1)
119 115
120 116 if [ ! -r "$CONFIGDIR/$pkgname" ]; then
121 117 echo "no configuration found for $pkgname in $CONFIGDIR/"

0 comments on commit 4baa2e2

Please sign in to comment.
Something went wrong with that request. Please try again.