#!/usr/bin/env bash
echo ">>> Pulling inside-factory...";
git pull;
cd ./factory_modules/;

# Pull all module components

if [ -d "inside-administration" ]; then
  cd ./inside-administration/;
  echo ">>> Pulling inside-administration...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-administration...";
  git clone git@bitbucket.org:maecia/inside-administration.git;
fi

if [ -d "inside-core" ]; then
  cd ./inside-core/;
  echo ">>> Pulling inside-core...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-core...";
  git clone git@bitbucket.org:maecia/inside-core.git;
fi

if [ -d "inside-displays" ]; then
  cd ./inside-displays;
  echo ">>> Pulling inside-displays...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-displays...";
  git clone git@bitbucket.org:maecia/inside-displays.git;
fi

if [ -d "inside-edition" ]; then
  cd ./inside-edition;
  echo ">>> Pulling inside-edition...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-edition...";
  git clone git@bitbucket.org:maecia/inside-edition.git;
fi

if [ -d "inside-events" ]; then
  cd ./inside-events;
  echo ">>> Pulling inside-events...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-events...";
  git clone git@bitbucket.org:maecia/inside-events.git;
fi

if [ -d "inside-forms" ]; then
  cd ./inside-forms/;
  echo ">>> Pulling inside-forms...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-forms...";
  git clone git@bitbucket.org:maecia/inside-forms.git;
fi

if [ -d "inside-forum" ]; then
  cd ./inside-forum;
  echo ">>> Pulling inside-forum...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-forum...";
  git clone git@bitbucket.org:maecia/inside-forum.git;
fi

if [ -d "inside-ged" ]; then
  cd ./inside-ged;
  echo ">>> Pulling inside-ged...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-ged...";
  git clone git@bitbucket.org:maecia/inside-ged.git;
fi

if [ -d "inside-layouts" ]; then
  cd ./inside-layouts;
  echo ">>> Pulling inside-layouts...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-layouts...";
  git clone git@bitbucket.org:maecia/inside-layouts.git;
fi

if [ -d "inside-library" ]; then
  cd ./inside-library;
  echo ">>> Pulling inside-library...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-library...";
  git clone git@bitbucket.org:maecia/inside-library.git;
fi

if [ -d "inside-news" ]; then
  cd ./inside-news;
  echo ">>> Pulling inside-news...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-news...";
  git clone git@bitbucket.org:maecia/inside-news.git;
fi

if [ -d "inside-pagebuilder" ]; then
  cd ./inside-pagebuilder;
  echo ">>> Pulling inside-pagebuilder...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-pagebuilder...";
  git clone git@bitbucket.org:maecia/inside-pagebuilder.git;
fi

# if directory inside-poll exists
if [ -d "inside-poll" ]; then
  cd ./inside-poll;
  echo ">>> Pulling inside-poll...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-poll...";
  git clone git@bitbucket.org:maecia/inside-poll.git;
fi

if [ -d "inside-socials" ]; then
  cd ./inside-socials;
  echo ">>> Pulling inside-socials...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-socials...";
  git clone git@bitbucket.org:maecia/inside-socials.git;
fi

if [ -d "inside-tests" ]; then
  cd ./inside-tests;
  echo ">>> Pulling inside-tests...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-tests...";
  git clone git@bitbucket.org:maecia/inside-tests.git;
fi

if [ -d "inside-tools" ]; then
  cd ./inside-tools;
  echo ">>> Pulling inside-tools...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-tools...";
  git clone git@bitbucket.org:maecia/inside-tools.git;
fi

if [ -d "inside-users" ]; then
  cd ./inside-users;
  echo ">>> Pulling inside-users...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-users...";
  git clone git@bitbucket.org:maecia/inside-users.git;
fi

if [ -d "inside-webpack" ]; then
  cd ./inside-webpack;
  echo ">>> Pulling inside-webpack...";
  git pull;
  cd ../;
else
  echo ">>> Cloning inside-webpack...";
  git clone git@bitbucket.org:maecia/inside-webpack.git;
fi

if ! [ -z ${1+x} ]; then
  echo ">>> npm install";
  npm i;
fi
