Created
March 17, 2010 17:32
-
-
Save sugamasao/335490 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
############################################## | |
# サーバへアプリケーション等をデプロイします | |
############################################## | |
#------------------------ | |
# ファイルチェック関数 | |
#------------------------ | |
func_file_test () { | |
if [ -d ${SRC_DIR_STATIC_CONTENT} ] ; then | |
echo "found ${SRC_DIR_STATIC_CONTENT}" | |
else | |
return 1 | |
fi | |
if [ -d ${SRC_DIR_DYNAMIC_CONTENT} ] ; then | |
echo "found ${SRC_DIR_DYNAMIC_CONTENT}" | |
else | |
return 1 | |
fi | |
return 0 | |
} | |
#------------------------ | |
# 実行確認 | |
#------------------------ | |
func_is_exec () { | |
INPUT_MESSAGE="exec ok?(-t dry run) [Y/n]"; | |
# OK Cancel のアレ | |
while [ "${READ_KEY}" != "Y" ] && [ "${READ_KEY}" != "n" ]; do | |
echo -n "${INPUT_MESSAGE} :" | |
read READ_KEY; | |
done; | |
# n だったら終了するよ | |
if [ "${READ_KEY}" = "n" ]; then | |
return 1; | |
fi | |
return 0; | |
} | |
######################### | |
# 変数宣言 | |
######################### | |
RSYNC=/usr/bin/rsync | |
SRC_DIR_STATIC_CONTENT=/hogehoge | |
DEST_DIR_STATIC_CONTENT=/fuga | |
SRC_DIR_DYNAMIC_CONTENT=/piyopiyo | |
DEST_DIR_DYNAMIC_CONTENT=/fuga | |
DIR=`dirname ${0}` | |
######################### | |
# 引数チェック | |
######################### | |
while getopts ht opt; do | |
case ${opt} in | |
h) | |
HELP="0";; | |
t) | |
TEST="0";; | |
\?) | |
;; | |
esac | |
done | |
if [ "${HELP}" = "0" ];then | |
echo "this script is rsyc to server. arguments '-t' dry-run."; | |
exit 1; | |
fi | |
if [ "${TEST}" = "0" ];then | |
echo "'-t' dry-run mode."; | |
OPT="n" | |
fi | |
######################### | |
# ローカルファイルチェック | |
######################### | |
func_file_test 1 | |
if [ ${?} = "1" ]; then | |
echo "file no found. ${SRC_DIR_STATIC_CONTENT} or ${SRC_DIR_DYNAMIC_CONTENT}" | |
return 1; | |
fi | |
######################### | |
# 実行確認チェック | |
######################### | |
func_is_exec | |
if [ ${?} = "1" ]; then | |
echo 'execute cancel.'; | |
exit 1; | |
fi | |
######################### | |
# ファイルログ作成 | |
######################### | |
FILE_NAME=deploy_log_`date '+%Y%m%d_%H%M%S'` | |
LOG=${DIR}/${FILE_NAME} | |
######################### | |
# 実行 | |
######################### | |
${RSYNC} -avrz${OPT} --delete --exclude '.svn' ${SRC_DIR_STATIC_CONTENT} user@domain:${DEST_DIR_STATIC_CONTENT} | tee -a ${LOG} | |
${RSYNC} -avrz${OPT} --delete --exclude '.svn' ${SRC_DIR_DYNAMIC_CONTENT} user@domain:${DEST_DIR_DYNAMIC_CONTENT} | tee -a ${LOG} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment