シェルスクリプトで一括PHP拡張モジュールをインストール

Linux環境でphp拡張モジュールのインストール作業はシェルスクリプトで処理する
テスト環境:
ubuntu 12.04
php 5.3.x

1.インストール
ファイル名:install.sh
サンプルコード:
#!/bin/bash
#Program:
# Accomplish to expand the specified function only one key

test ! -f ./ext_skel && echo “The shell script of 'ext_skel’ doesn’t exist in current directory.\n" && exit 0
[ ! -d “skeleton" ] && echo “The directory of 'skeleton’ doesn’t exist in current directory.\n" && exit 0
#include “./ext_skel"
read -p “拡張モジュール名を入力してください: " ext_name
#echo -e “こんにちは $ext_name"
#スペース名が必要です
#Error:
# like: if[ ! -d “$ext_name" ]; then
if [ ! -d “$ext_name" ]; then
./ext_skel –extname=$ext_name
fi
file="./$ext_name/config.m4″
copy="./$ext_name/config"
if [ ! -f “./$ext_name/configs" ]; then
# 新しいファイルを作成、存在するなら削除
:> “$copy"
cat “$file" | while read line
#for line in $( cat ./zend/config.m4 )
do
string=$( echo $line | grep 'PHP_ARG_ENABLE’ )
if [ “$string" != “" ]; then
echo $line | cut -c5- >> $copy
read line
echo $line | cut -c5- >> $copy
read line
echo $line | cut -c5- >> $copy
read line
fi
echo $line >> $copy
done
mv “$file" “./$ext_name/configs"
mv “$copy" “./$ext_name/config.m4"
fi
cd $ext_name
phpize
./configure

2.コンパイル
ファイル名:compile.sh
サンプルコード:
#!/bin/bash
#Pragram:
# コンパイルとapache再起動
#History:

echo “\033[31mNow, compiling…\033[0m\n"
make
if [ $(( ! $? )) ]; then
echo “\033[32mStart to install the module…\033[0m\n"
sudo make install
echo “\033[32mDon’t forget to add the extension module line to file 'php.ini'( approach the line 945 ) and restart the apache.\033[0m"
sudo /etc/init.d/apache2 restart
fi

Software

Posted by arkgame