Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2012 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4323676 to your computer and use it in GitHub Desktop.
Save anonymous/4323676 to your computer and use it in GitHub Desktop.
MAMP subtool コマンドラインで作業ディレクトリを DocumentRoot にする
#!/bin/sh
# -*- coding: utf_8 -*-
#
# MAMPcwd (start|stop|cwd)
# MAMP のコマンドライン補佐ツール
#
# start: 再起動/起動をします
# stop : 停止します
# cwd : コマンドを実行したディレクトリをDocumentRootにして、再起動をします
#
# 注意
# MAMP 本体を起動してこのコマンドを使い、MAMP 本体を終了した時、httpd は落ちます。
# 正常動作ですが、このことを忘れないでください。
#
# Ex:
#
# [~/Desktop/work/test] $ MAMPcwd cwd
# MAMP の DocumentRoot を'/Users/.../Desktop/work/test' にして再起動します
MAMP="/Applications/MAMP"
if [ ! -d $MAMP ]; then
echo "Not found MAMP"
exit 1
fi
if [ ! -e $MAMP/conf/apache/httpd.conf ]; then
echo "Not Found httpd.conf"
echo "Reinstall at MAMP"
exit 1
fi
function apache () {
case $1 in
start)
$MAMP/bin/startApache.sh
;;
stop)
$MAMP/bin/stopApache.sh
;;
cwd)
echo "MAMP のDocumentRoot を"`pwd`"にして再起動します"
$MAMP/bin/stopApache.sh
cat $MAMP/conf/apache/httpd.conf \
| awk '{gsub(/^DocumentRoot.+/, "DocumentRoot \"'`pwd`'/\"")} {print}' \
| awk '{gsub(/^Listen.+/, "Listen 8888")} {print}' \
| awk '{gsub(/^<Directory "\/U.+">/, "<Directory \"'`pwd`'/\">")}{print}' \
> /tmp/abc.conf
mv /tmp/abc.conf $MAMP/conf/apache/httpd.conf
chown :admin $MAMP/conf/apache/httpd.conf
xattr -w com.apple.TextEncoding utf-8 $MAMP/conf/apache/httpd.conf
$MAMP/bin/startApache.sh
;;
esac
}
function mysql () {
case $1 in
start)
$MAMP/bin/startMysql.sh
;;
stop)
$MAMP/bin/stopMysql.sh
;;
esac
}
for arg in $*; do
case $arg in
start)
apache stop
mysql stop
mysql start
apache start
;;
stop)
apache stop
mysql stop
;;
cwd)
apache cwd
;;
help|*)
echo "MAMPcwd (start|stop|cwd)"
echo " MAMP Command line tool"
echo ""
echo " start: Start up to MAMP"
echo " stop : Stop to MAMP"
echo " cwd : Change DocumentRoot Path at current work directory"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment