#!/bin/bash

###############################################
## Akmall Apache SRVROOT Change Shell Script ##
###############################################

if [ "$#" -lt 1 ]; then
	echo "####################################"
        echo "Usage: ak-chg-web.sh [target-dir-name]"
	echo "#=================================="
	echo "ex) ak-chg-web.sh akbizmall"
	echo "####################################"
        exit 1
fi

SR_DIR=akmall
CH_DIR=$1
DOWDLOAD_FILE="ak-apache-akmall-making.tar.gz"

echo " ####################################"
echo " 1. FILE Download wget http://opensourcelab.co.kr/download/akmall/$DOWDLOAD_FILE"
echo " #=================================="
wget http://opensourcelab.co.kr/download/akmall/$DOWDLOAD_FILE

echo " ####################################"
echo " 2. tar unpackage -> tar -xvzf $DOWDLOAD_FILE"
echo " #=================================="
tar -xvzf $DOWDLOAD_FILE

echo "wating 2 seconds ...."
sleep 2;

echo " ####################################"
echo " 3. chnage directoy : mv $SR_DIR $CH_DIR"
echo " #=================================="
mv $SR_DIR $CH_DIR

echo " ####################################"
echo " 4. File in DIR_String - find chagne ==> find $CH_DIR -type f -exec sed -i \"s#/$SR_DIR/#/$CH_DIR/#g\" {} \;"
echo " #=================================="
find $CH_DIR -type f -exec sed -i "s#/$SR_DIR/#/$CH_DIR/#g" {} \;

echo " #=================================="
echo " 5. File in DIR_String - find chagne ==> find $CH_DIR -type f -exec sed -i \"s#/$SR_DIR\"#/$CH_DIR\"#g\" {} \;"
echo " #=================================="
find $CH_DIR -type f -exec sed -i "s#/$SR_DIR\"#/$CH_DIR\"#g" {} \;

echo " #=================================="
echo " 6. Make directory docroot ==> mkdir -p /workspace/akapp/web/$CH_DIR"
echo " #=================================="
mkdir -p /workspace/akapp/web/$CH_DIR

echo " #=================================="
echo " 7. Make directory logbase ==> mkdir -p /workspace/aklogs/web/$CH_DIR"
echo " #=================================="
mkdir -p /workspace/aklogs/web/$CH_DIR


rm -f ak-apache-akmall-making.tar.gz
rm -f ak-chg-web.sh
