#!/bin/bash set -e NAME="Mystic BBS" VERSION="A42" INIT=mis function stop { echo "Stopping ${NAME}" kill $(ps -Af|grep ${INIT} |grep -v grep|awk '{ print $2}') } trap 'stop' SIGTERM export PATH=$PATH:/mystic if [ "$1" == "start" ]; then # First time install - expand out our data directory if [ $(find data|wc -l) -le 1 ]; then echo "** First time install, deploying sample setup" tar xzf data.tar.gz echo ${VERSION} > .version # We need to upgrade else OLD_VERSION=$(cat data/.version) echo "** Upgrading [${OLD_VERSION}]" case ${OLD_VERSION} in A39) echo "Processing data/default.txt" set -x [ ! -d data/upgrade/${VERSION}/${OLD_VERSION} ] && mkdir -p data/upgrade/${VERSION}/${OLD_VERSION} cd data/upgrade/${VERSION}/${OLD_VERSION} [ -d data ] && rm -rf data tar xzf /mystic/data.tar.gz cd /mystic/data diff -u data/default.txt upgrade/${VERSION}/${OLD_VERSION}/data/data/default.txt > upgrade/${VERSION}/${OLD_VERSION}/default.txt.patch && echo $? if [ -s upgrade/${VERSION}/${OLD_VERSION}/default.txt.patch ]; then patch -p 0 < upgrade/${VERSION}/${OLD_VERSION}/default.txt.patch echo "! Check upgrade/${VERSION}/${OLD_VERSION}/default.txt.patch for an strings that may have been overwritten..." else rm -f upgrade/${VERSION}/${OLD_VERSION}/default.txt.patch fi for i in msg_index.ini msg_index.ans msg_index_help.ans; do cp upgrade/${VERSION}/${OLD_VERSION}/data/text/$i text/ done cp upgrade/${VERSION}/${OLD_VERSION}/data/data/cfgroot4.ans data/ ../upgrade cd ../scripts ./mplc -all cd ../data rm -rf upgrade/${VERSION}/${OLD_VERSION}/data echo A42 > .version ;; A42) echo "Already up to date!" ;; *) echo "!! Dont know how to upgrade" && exit 1 esac fi # OK, start exec ${INIT} server else exec $@ fi