-
Notifications
You must be signed in to change notification settings - Fork 4
/
deploy.sh
executable file
·71 lines (54 loc) · 996 Bytes
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
cd $(dirname $BASH_SOURCE)
DIR=./
for i in "$@"
do
case $1 in
--dir=*)
DIR="${i#*=}"
shift # past argument=value
;;
--woc_env=*)
shift # past argument=value
;;
*)
SERVERS="$SERVERS $1"
shift
# unknown option: ignore
;;
esac
done
echo $SERVERS
PROG_NAME=$(awk -F'"' '/^const progname =/ {print $2}' main.go)
cd $DIR
LATEST=$(ls -rt ${PROG_NAME}_*.tar.gz | tail -1)
echo $LATEST
if [[ "$LATEST" == "" ]]; then
exit 1
fi
for var in $SERVERS
do
echo Deploying ${PROG_NAME} to $var
ssh $var mkdir -p ./${PROG_NAME}
if [[ $? -ne 0 ]]; then
exit 1
fi
scp $LATEST $var:./${PROG_NAME}/
if [[ $? -ne 0 ]]; then
exit 1
fi
ssh $var << EOL
cd ${PROG_NAME}
mkdir ${LATEST%.tar.gz}
cd ${LATEST%.tar.gz}
tar xvfz ../$LATEST
cd ../..
mkdir -p public_cdn
rm -f public_cdn/${PROG_NAME}
ln -s ../${PROG_NAME}/${LATEST%.tar.gz} public_cdn/${PROG_NAME}
EOL
done
if [[ $? -ne 0 ]]; then
exit 1
fi
exit 0