Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2013 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e1ebabbf6527d055ece3 to your computer and use it in GitHub Desktop.
Save anonymous/e1ebabbf6527d055ece3 to your computer and use it in GitHub Desktop.
Makes customizepkg(1) to run config file instead of parsing it if file has execution permission.
--- 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