52 lines
1.4 KiB
Bash
Executable File
52 lines
1.4 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}
|
|
|
|
# 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/"* "$APP_DIR/scripts/"
|
|
|
|
# Give execution permission to all scripts
|
|
chmod +x "$APP_DIR/scripts/"*
|
|
|
|
# Run the manager.sh script with the "install" argument
|
|
"$APP_DIR/scripts/manager.sh" install |