Skip to content

Commit

Permalink
Fix sed for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed May 16, 2020
1 parent 4a7792a commit d9d53db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"email": "[email protected]"
}
],
"require": {
"php" : ">=5.6"
},
"scripts": {
"post-autoload-dump": [
"cp php-extension.sh /usr/local/bin/php-extension"
Expand Down
18 changes: 14 additions & 4 deletions php-extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@

EXTENSION="$1"
[ "$2" == 'on' ] || [ "$2" == '1' ] || [ "$2" == 'enable' ] && ENABLE=true || ENABLE=false
INI_DIR=$(php --ini | grep 'Configuration File (php.ini) Path:' | sed -E "s/.*: //")
PHP_DIR=$(php --ini | grep 'Configuration File (php.ini) Path:' | sed -E "s~^.*: (.*/php/[^/]*).*$~\1/~")
if [[ "$OSTYPE" == "darwin"* ]]; then
#MAC_OS
SED_ARGS="-i '' -E";
else
#OTHER
SED_ARGS="-i -E";
fi

if [ "$EXTENSION" == '' ]; then
echo 'Error: no extension provided'
exit 1;
fi

#toogle extension line in .ini file:
find "$INI_DIR" -type f -name "*.ini" | while read -r FILE; do
find "$PHP_DIR" -type f -name "*.ini" | while read -r FILE; do
if [ "$ENABLE" == true ]; then
sed -i '' -E "s/^;((zend_extension|extension).+$EXTENSION\.so)$/\1/g" "$FILE"
COMMAND=("sed $SED_ARGS s/^;((zend_extension|extension).+$EXTENSION\.so)$/\1/g $FILE")
else
sed -i '' -E "s/^((zend_extension|extension).+$EXTENSION\.so)$/;\1/g" "$FILE"
COMMAND=("sed $SED_ARGS s/^((zend_extension|extension).+$EXTENSION\.so)$/;\1/g $FILE")
fi

$COMMAND

done

#restart fpm
Expand Down

0 comments on commit d9d53db

Please sign in to comment.