-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy
executable file
·160 lines (125 loc) · 3.66 KB
/
deploy
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
set -e
PROJECT_NAME=apostol
BUILD_TYPE=Release
INSTALL_PATH=/usr/sbin
pop_directory()
{
popd >/dev/null
}
push_directory()
{
local DIRECTORY="$1"
pushd "$DIRECTORY" >/dev/null
}
display_heading_message()
{
echo
echo "********************** $@ **********************"
echo
}
display_message()
{
echo "$@"
}
display_error()
{
>&2 echo "$@"
}
display_help()
{
display_message "Usage: ./deploy [OPTION]..."
display_message "Manage the configure."
display_message "Script options:"
display_message " --help Display usage, overriding script execution."
display_message " --install Install $PROJECT_NAME (run as root)."
display_message " --update Update $PROJECT_NAME (run as root)."
display_message " --release Release build (default)."
display_message " --debug Debug build."
display_message " --build-dir=<path> Location of build files (default: $BUILD_DIR)."
display_message ""
}
display_configuration()
{
display_message "Configuration."
display_message "--------------------------------------------------------------------"
display_message "PROJECT_NAME : $PROJECT_NAME"
display_message "BUILD_TYPE : $BUILD_TYPE"
display_message "BUILD_DIR : $BUILD_DIR"
display_message "--------------------------------------------------------------------"
}
install_project()
{
push_directory "$BUILD_DIR"
display_heading_message "Install: $PROJECT_NAME"
make install
pop_directory
}
make_project()
{
push_directory "$BUILD_DIR"
display_heading_message "Make: $PROJECT_NAME"
make
pop_directory
}
update_project()
{
display_heading_message "Update $PROJECT_NAME"
if [[ -f /usr/bin/systemctl ]]; then
display_heading_message "stop service $PROJECT_NAME"
systemctl stop $PROJECT_NAME.service
fi
display_heading_message "copy $PROJECT_NAME to /usr/bin"
push_directory "$BUILD_DIR"
rm -rf /usr/sbin/$PROJECT_NAME
cp $PROJECT_NAME /usr/sbin
pop_directory
if [[ -d /etc/$PROJECT_NAME/logs ]]; then
display_heading_message "clear log files..."
rm -rf /etc/$PROJECT_NAME/logs/*.log
fi
if [[ -d /var/log/$PROJECT_NAME ]]; then
display_heading_message "clear log files..."
rm -rf /var/log/$PROJECT_NAME/*.log
fi
if [[ -f /usr/bin/systemctl ]]; then
display_heading_message "start service $PROJECT_NAME"
systemctl start ${PROJECT_NAME}.service
fi
}
# Parse command line options that are handled by this script.
#------------------------------------------------------------------------------
for OPTION in "$@"; do
case $OPTION in
# Standard script options.
(--help) DISPLAY_HELP="yes";;
(--install) MAKE_INSTALL="yes";;
(--update) BUILD_UPDATE="yes";;
(--release) BUILD_TYPE="Release";;
(--debug) BUILD_TYPE="Debug";;
# Unique script options.
(--build-dir=*) BUILD_DIR="${OPTION#*=}";;
esac
done
if ! [[ $BUILD_DIR ]]; then
if [[ $BUILD_TYPE == Debug ]]; then
BUILD_DIR=cmake-build-debug
else
BUILD_DIR=cmake-build-release
fi
fi
# Configure.
#==============================================================================
if [[ $DISPLAY_HELP ]]; then
display_help
else
display_configuration
if ! [[ $BUILD_UPDATE ]]; then
if [[ $MAKE_INSTALL ]]; then
install_project
else
make_project
fi
fi
update_project
fi