Added deploy file.
This commit is contained in:
132
deploy
Normal file
132
deploy
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
PROJECT_NAME=dm
|
||||||
|
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 " --build-dir=<path> Location of build files (default: $BUILD_DIR)."
|
||||||
|
display_message " --release Release builed (default)."
|
||||||
|
display_message " --debug Debug build."
|
||||||
|
display_message " --help Display usage, overriding script execution."
|
||||||
|
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 "--------------------------------------------------------------------"
|
||||||
|
}
|
||||||
|
|
||||||
|
make_project()
|
||||||
|
{
|
||||||
|
push_directory "$BUILD_DIR"
|
||||||
|
|
||||||
|
display_heading_message "Make: $PROJECT_NAME"
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
pop_directory
|
||||||
|
}
|
||||||
|
|
||||||
|
update_project()
|
||||||
|
{
|
||||||
|
display_heading_message "Update $PROJECT_NAME"
|
||||||
|
|
||||||
|
display_heading_message "stop service $PROJECT_NAME"
|
||||||
|
systemctl stop $PROJECT_NAME.service
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
display_heading_message "clear log files..."
|
||||||
|
rm -rf /etc/$PROJECT_NAME/logs/*.log
|
||||||
|
rm -rf /var/log/$PROJECT_NAME/*.log
|
||||||
|
|
||||||
|
display_heading_message "start service $PROJECT_NAME"
|
||||||
|
systemctl start ${PROJECT_NAME}.service
|
||||||
|
}
|
||||||
|
|
||||||
|
# Parse command line options that are handled by this script.
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
for OPTION in "$@"; do
|
||||||
|
case $OPTION in
|
||||||
|
# Standard script options.
|
||||||
|
(--help) DISPLAY_HELP="yes";;
|
||||||
|
|
||||||
|
(--release) BUILD_TYPE="Release";;
|
||||||
|
(--debug) BUILD_TYPE="Debug";;
|
||||||
|
|
||||||
|
(--update) BUILD_UPDATE="yes";;
|
||||||
|
|
||||||
|
# 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
|
||||||
|
make_project
|
||||||
|
fi
|
||||||
|
|
||||||
|
update_project
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user