# skleber.de cms 11 > 12
# SOURCE_DB=sklebersql1
# TARGET_DB=sklebersql3
# SOURCE_PW=ycGm2d4Jfp
# TARGET_PW=ep0M6Lgyhv

# nabira.de cms 11 > 12
SOURCE_DB=nabirasql1
TARGET_DB=nabirasql2
SOURCE_PW=36kntiYdsN
TARGET_PW=upeVahgiXs

if [ "$#" -ne 2 ]; then
    echo "Error: You must provide exactly two arguments."
    return 1
fi

echo "Start (smart) copying typo3 instance from $1 to $2."
echo "Press ENTER to continue: "
read
mkdir -p $2
echo "Adjust folder ownership of $2 after running this script."
cd "$1"
cp -ar clear.gif execdir *.ico *.jpg index.php robots.txt typo3 typo3conf typo3_src typo3temp "../$2/"
cp -arl fileadmin uploads "../$2/"
cd "../$2"
# read
echo "Database for this instance:" 
egrep "('dbname'|'user')" typo3conf/LocalConfiguration.php | sed "s/.*'\(.*\)'.*\\s*'\(.*\)'.*/\\1: \\2/"
echo "change database and user to $TARGET_DB"
sed -i "s/$SOURCE_DB/$TARGET_DB/" typo3conf/LocalConfiguration.php
sed -i "s/$SOURCE_PW/$TARGET_PW/" typo3conf/LocalConfiguration.php
diff "../$1/typo3conf/LocalConfiguration.php" typo3conf/LocalConfiguration.php
