Files
db-middleware/scripts/manager.sh
2025-03-11 22:01:23 +03:00

124 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
APP_DIR="$HOME/.db-middleware"
CODE_DIR="$APP_DIR/code"
CONFIG_DIR="$APP_DIR/config"
CONFIG_FILE="$CONFIG_DIR/app.conf"
# Function to load the config file
load_config() {
if [[ -f "$CONFIG_FILE" ]]; then
source "$CONFIG_FILE"
else
echo "Config file not found: $CONFIG_FILE"
exit 1
fi
}
show_config() {
echo "Current Config:"
echo "CONTAINER_NAME: $CONTAINER_NAME"
echo "APP_PORT: $APP_PORT"
echo "DBS_PORTS: $DBS_PORTS"
}
install() {
echo
echo "+------------------------------+"
echo "| Installing the Middleware... |"
echo "+------------------------------+"
echo
cd "$CODE_DIR"
# docker build -t db-middleware .
echo
echo "+----------------------------------------+"
echo "| Installed the Middleware Successfully! |"
echo "+----------------------------------------+"
echo
echo "- You can run the middleware simply using the manager:"
echo " >>> db-middleware start"
echo "- Or directly by running the docker container:"
echo " >>> docker run db-middleware -p <port>:<port> -v /path/to/app/directory/"
}
# Function for the "upgrade" command
upgrade() {
echo "Running the 'upgrade' function."
# Add your upgrade logic here
}
# Function for the "status" command
status() {
echo "Running the 'status' function."
docker
# Add your status-checking logic here
}
# Function for the "start" command
start() {
echo "+---------------------------+"
echo "| Starting the Container... |"
echo "+---------------------------+"
echo
docker run db-middleware
}
# Function for the "stop" command
stop() {
echo "Running the 'stop' function."
# Add your stop logic here
}
# Function to display usage instructions
usage() {
echo "Usage: $0 {install|upgrade|status|start|stop}"
exit 1
}
# Main script logic
main() {
# Check if an argument is provided
if [[ $# -eq 0 ]]; then
usage
fi
# Handle the argument
case "$1" in
install)
install
;;
upgrade)
load_config
upgrade
;;
status)
load_config
status
;;
start)
load_config
start
;;
show_config)
load_config
show_config
;;
stop)
load_config
stop
;;
*)
echo "Invalid argument: $1"
usage
;;
esac
}
# Run the script with the provided arguments
main "$@"