Files
db-middleware/scripts/setup.sh

60 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Directory for the code
APP_DIR="$HOME/.db-middleware"
CODE_DIR="$HOME/.db-middleware/code"
# Git repository URL
REPO_URL="https://gitea.abdulhade.com/abdulhade/db-middleware.git"
# Check if the code directory exists
if [[ ! -d "$CODE_DIR" ]]; then
echo "Creating code directory at $CODE_DIR..."
fi
mkdir -p ~/.db-middleware/{code,configs,scripts,files}
# Navigate to the code directory
cd "$CODE_DIR" || { echo "Failed to navigate to $CODE_DIR"; exit 1; }
# Check if the directory is empty
if [[ -z "$(ls -A $CODE_DIR)" ]]; then
echo "Directory is empty. Cloning repository..."
git clone "$REPO_URL" .
else
# Check if the directory contains a Git repository
if [[ -d ".git" ]]; then
echo "Directory contains a Git repository. Pulling latest changes..."
git pull "$REPO_URL"
else
echo "Directory is not empty and does not contain a Git repository."
echo "Please ensure the directory is empty or contains a valid Git repository."
exit 1
fi
fi
# Check if the operation was successful
if [[ $? -eq 0 ]]; then
echo "Repository setup completed successfully."
else
echo "Failed to set up the repository."
exit 1
fi
# Copy scripts from the code directory to the app directory
cp "$CODE_DIR/scripts/"*.sh "$APP_DIR/scripts/"
cp "$CODE_DIR/scripts/"*.conf "$APP_DIR/configs/"
# Give execution permission to all scripts
chmod +x "$APP_DIR/scripts/"*
mkdir -p "$HOME/.local/bin"
ln -sf "$APP_DIR/scripts/manager.sh" "$HOME/.local/bin/db-middleware"
export PATH="$HOME/.local/bin:$PATH"
source ~/.bashrc
# Run the manager.sh script with the "install" argument
"$APP_DIR/scripts/manager.sh" install