#!/bin/bash

# Frontend setup
if [ -d "frontend-react" ]; then
  echo "Setting up frontend-react..."
  (
    cd frontend-react
    # npm install
    deno install --allow-scripts
  ) &
else
  echo "frontend-react directory not found, skipping..."
fi

# Dart backend setup
if [ -d "backend-dart" ]; then
  echo "Setting up backend-dart..."
  (
    cd backend-dart
    dart pub get
  ) &
else
  echo "backend-dart directory not found, skipping..."
fi

# Go backend setup
if [ -d "backend-go" ]; then
  echo "Setting up backend-go..."
  (
    cd backend-go
    go mod tidy
  ) &
else
  echo "backend-go directory not found, skipping..."
fi

# Wait for all parallel processes to finish
wait

echo "Copying ssh keys"
sudo bash -c "rsync -a /home/$USER/.ssh-host/* /home/$USER/.ssh/" 
echo "Setting permissions on ssh keys"
sudo chmod 600 /home/$USER/.ssh/* && sudo chown $USER:$USER /home/$USER/.ssh/*
# git config --global user.name 'Jean Avril' && git config --global user.email 'jean@jeanavril.com'

echo "Setup completed!"