-
Notifications
You must be signed in to change notification settings - Fork 24
/
shipping.sh
96 lines (60 loc) · 1.86 KB
/
shipping.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
ID=$(id -u)
R="\e[31m"
G="\e[32m"
Y="\e[33m"
N="\e[0m"
TIMESTAMP=$(date +%F-%H-%M-%S)
LOGFILE="/tmp/$0-$TIMESTAMP.log"
echo "script stareted executing at $TIMESTAMP" &>> $LOGFILE
VALIDATE(){
if [ $1 -ne 0 ]
then
echo -e "$2 ... $R FAILED $N"
exit 1
else
echo -e "$2 ... $G SUCCESS $N"
fi
}
if [ $ID -ne 0 ]
then
echo -e "$R ERROR:: Please run this script with root access $N"
exit 1 # you can give other than 0
else
echo "You are root user"
fi # fi means reverse of if, indicating condition end
dnf install maven -y &>> $LOGFILE
id roboshop #if roboshop user does not exist, then it is failure
if [ $? -ne 0 ]
then
useradd roboshop
VALIDATE $? "roboshop user creation"
else
echo -e "roboshop user already exist $Y SKIPPING $N"
fi
mkdir -p /app
VALIDATE $? "creating app directory"
curl -L -o /tmp/shipping.zip https://roboshop-builds.s3.amazonaws.com/shipping.zip &>> $LOGFILE
VALIDATE $? "Downloading shipping"
cd /app
VALIDATE $? "moving to app directory"
unzip -o /tmp/shipping.zip &>> $LOGFILE
VALIDATE $? "unzipping shipping"
mvn clean package &>> $LOGFILE
VALIDATE $? "Installing dependencies"
mv target/shipping-1.0.jar shipping.jar &>> $LOGFILE
VALIDATE $? "renaming jar file"
cp /home/centos/roboshop-shell/shipping.service /etc/systemd/system/shipping.service &>> $LOGFILE
VALIDATE $? "copying shipping service"
systemctl daemon-reload &>> $LOGFILE
VALIDATE $? "deamon reload"
systemctl enable shipping &>> $LOGFILE
VALIDATE $? "enable shipping"
systemctl start shipping &>> $LOGFILE
VALIDATE $? "start shipping"
dnf install mysql -y &>> $LOGFILE
VALIDATE $? "install MySQL client"
mysql -h mysql.daws76s.online -uroot -pRoboShop@1 < /app/schema/shipping.sql &>> $LOGFILE
VALIDATE $? "loading shipping data"
systemctl restart shipping &>> $LOGFILE
VALIDATE $? "restart shipping"