anonymous / customizepkg-exec.patch secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Makes customizepkg(1) to run config file instead of parsing it if file has execution permission.

View customizepkg-exec.patch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
--- customizepkg.orig 2013-05-03 19:56:11.394667790 +0300
+++ customizepkg 2013-05-03 19:59:27.206940318 +0300
@@ -47,44 +47,50 @@
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}'`
- #echo "action=$action , context=$context , pattern=$pattern"
- 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.]*"
- fi
- if [ "$context" = "global" ]; then
- sed -i "s/$pattern/$value/g" "$scriptfile"
- else
- 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"
- else
- sed -i "/^build/i$context=($value)\n" "$scriptfile"
- fi
- ;;
- *)
- echo "error: unknow action '$action'"
- ;;
- esac
- done
+
+ if [ -x "$configfile" ]
+ then
+ "$configfile" "$originalscriptfile" "$scriptfile" || return 1
+ else
+ 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}'`
+ #echo "action=$action , context=$context , pattern=$pattern"
+ 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.]*"
+ fi
+ if [ "$context" = "global" ]; then
+ sed -i "s/$pattern/$value/g" "$scriptfile"
+ else
+ 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"
+ else
+ sed -i "/^build/i$context=($value)\n" "$scriptfile"
+ fi
+ ;;
+ *)
+ echo "error: unknow action '$action'"
+ ;;
+ esac
+ done
+ fi
[ $VIMDIFF -eq 1 ] && vim -d "$scriptfile" "$originalscriptfile"
diff -Naur "$originalscriptfile" "$scriptfile"
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.