yoqw/deploy-static.sh
2020-09-05 13:10:50 +08:00

59 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# get real path of softlink
get_real_path() {
local f="$1"
while [ -h "$f" ]; do
ls=`ls -ld "$f"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
f="$link"
else
f=`dirname "$f"`/"$link"
fi
done
echo "$f"
}
prg_path=$(get_real_path "$0")
echo "Script path [$prg_path]"
# Service Home
pushd $(dirname "$prg_path") > /dev/null
WORK_DIR=$(pwd)
echo "Work dir [$WORK_DIR]"
if [ "$1" == "test" ]; then
echo "Deploy test."
server='xiadou@118.24.251.131'
port=22
elif [ "$1" == "prod" ]; then
echo "Deploy prod."
server='xiandou@localhost'
port=4025
else
echo 'Usage: ./deploy-static.sh test|prod'
exit 1
fi
APP='cms'
buildDir="$APP-static"
buildTgz="$buildDir.tar.gz"
targetPath='/data/program'
prevDir="$targetPath/$buildDir.prev"
# ember build
cd "web/$APP"
rm -rf $buildDir $buildTgz
ember b -prod -o "$APP-static"
tar czvf $buildTgz $buildDir
# mv prev
ssh -p $port $server "rm -rf $prevDir && mv $targetPath/$buildDir $prevDir"
# extract
ssh -p $port $server "tar xzv -C /data/program" < $buildTgz
rm -rf $buildDir $buildTgz
popd > /dev/null