diff --git a/scripts/setup.sh b/scripts/setup.sh index 5ef28b2..43a9737 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -2,82 +2,59 @@ set -e -echo "πŸš€ Starting Checkcle Installation..." +REPO_URL="https://github.com/operacle/checkcle.git" +CLONE_DIR="/opt/checkcle" +DATA_DIR="/opt/pb_data" +PORT=8090 -# Check if npm is installed -if ! command -v npm &> /dev/null; then - echo "πŸ“¦ npm is not installed. Installing Node.js and npm..." - - # Install Node.js and npm (Ubuntu/Debian-based systems) - curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - - sudo apt-get install -y nodejs +echo "πŸš€ Installing Checkcle from $REPO_URL" + +# Step 1: Check if port 8090 is already in use +if lsof -i :"$PORT" &>/dev/null; then + echo "❗ ERROR: Port $PORT is already in use. Please free the port or change the Docker Compose configuration." + exit 1 fi -# Clone the repo -if [ ! -d "checkcle" ]; then - echo "πŸ“ Cloning repository..." - git clone https://github.com/operacle/checkcle.git +# Step 2: Ensure Docker is installed +if ! command -v docker &> /dev/null; then + echo "πŸ”§ Docker not found. Installing Docker..." + curl -fsSL https://get.docker.com | sh fi -cd checkcle +# Step 3: Ensure Docker Compose v2 is available +if ! docker compose version &> /dev/null; then + echo "❗ Docker Compose v2 not found. Please install Docker Compose v2 and rerun this script." + exit 1 +fi -# Set up paths -PROJECT_DIR=$(pwd) -APP_DIR="$PROJECT_DIR/application" -PB_DIR="$PROJECT_DIR/server" -PB_BINARY="$PB_DIR/pocketbase" +# Step 4: Clone the repository +if [ -d "$CLONE_DIR" ]; then + echo "πŸ“ Directory $CLONE_DIR already exists. Pulling latest changes..." + git -C "$CLONE_DIR" pull +else + echo "πŸ“₯ Cloning repo to $CLONE_DIR" + git clone "$REPO_URL" "$CLONE_DIR" +fi -# Install web dependencies -echo "πŸ“¦ Installing Web Application dependencies..." -cd "$APP_DIR" -npm install +# Step 5: Create data volume directory if it doesn’t exist +if [ ! -d "$DATA_DIR" ]; then + echo "πŸ“ Creating data volume directory at $DATA_DIR" + sudo mkdir -p "$DATA_DIR" + sudo chown "$(whoami)":"$(whoami)" "$DATA_DIR" +fi -# Create systemd service for frontend -echo "πŸ› οΈ Setting up systemd service for Web Application..." -sudo tee /etc/systemd/system/checkcle-web.service > /dev/null < /dev/null <