-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdeploy.sh
executable file
·76 lines (63 loc) · 2.03 KB
/
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
72
73
74
75
76
#!/bin/bash
#=================================================================================================
#
# Deploy API to test or production.
#
#=================================================================================================
# exit script on any error
trap 'exit' ERR
ENV=$1
if [[ "$1" = "test" ]]; then
REMOTE_HOST="super01.supercharge.info"
REMOTE_USER="tomcat_test"
REMOTE_DIR="latest/webapps/"
elif [[ "$1" = "prod" ]]; then
REMOTE_HOST="super01.supercharge.info"
REMOTE_USER="tomcat"
REMOTE_DIR="latest/webapps/"
else
echo "unknown environment: ${ENV}";
printf "usage: deploy <test|prod> <version> \n\n";
exit;
fi
#--------------------------------------------
# check arguments
#--------------------------------------------
if [[ "$#" -ne 2 ]]; then
printf "usage: deploy <test|prod> <version> \n\n";
exit;
fi
#--------------------------------------------
# check for existence of deploy artifact
#--------------------------------------------
VERSION="$2"
LOCAL_WAR="service-war/target/service-war-${VERSION}.war"
if [[ ! -f "${LOCAL_WAR}" ]]; then
printf "ERROR: File not found: ${LOCAL_WAR} \n\n"
exit;
fi
#--------------------------------------------
# prompt, are you sure
#--------------------------------------------
echo "##########################################################";
echo "REMOTE_HOST = ${REMOTE_HOST}"
echo "REMOTE_USER = ${REMOTE_USER}"
echo "REMOTE_DIR = ${REMOTE_DIR}"
echo "##########################################################";
echo ""
printf "Deploy ${LOCAL_WAR} \n\n"
read -p "Are you sure? [y/n]: " -n 1 -r
if [[ $REPLY =~ ^[Nn]$ ]]
then
printf "\n\nExiting\n\n";
exit;
fi
#--------------------------------------------
# deploy
#--------------------------------------------
printf "\n\n"
printf "Copying to ${REMOTE_HOST}\n"
scp ${LOCAL_WAR} ${REMOTE_USER}@${REMOTE_HOST}:service.war
printf "Moving to application server's webapps directory...\n"
ssh "${REMOTE_USER}@${REMOTE_HOST}" "mv service.war ${REMOTE_DIR}"
printf "Finished \n "