#!/bin/bash
set -e

# Branding
rm -rf public/brand app/views/external
git clone -b master git@github.com:sharelatex/brand-sharelatex public/brand
git clone -b master git@github.com:sharelatex/external-pages-sharelatex app/views/external
mv app/views/external/robots.txt public/robots.txt
mv app/views/external/googlebdb0f8f7f4a17241.html public/googlebdb0f8f7f4a17241.html

# Web Modules
rm -rf modules
BRANCH_NAME=${BRANCH_NAME:="$(git rev-parse --abbrev-ref HEAD)-nope"}
function install_module {
	echo "Cloning $1 from $BRANCH_NAME branch"
	git clone -b $BRANCH_NAME $1 $2 || {
		echo "Cloning from $BRANCH_NAME failed - it likely doesn't exist. Using master";
		git clone -b master $1 $2;
	}
}
install_module git@github.com:sharelatex/web-sharelatex-modules modules
install_module git@github.com:sharelatex/admin-panel modules/admin-panel
install_module git@github.com:sharelatex/tpr-webmodule.git modules/tpr-webmodule
install_module git@github.com:sharelatex/templates-webmodule.git modules/templates
install_module git@github.com:sharelatex/track-changes-web-module.git modules/track-changes
install_module git@github.com:sharelatex/overleaf-integration-web-module.git modules/overleaf-integration
install_module git@github.com:sharelatex/overleaf-account-merge.git modules/overleaf-account-merge
install_module git@github.com:sharelatex/references-search.git modules/references-search
install_module git@github.com:sharelatex/learn-wiki-web-module.git modules/learn-wiki
install_module git@github.com:sharelatex/metrics-web-module.git modules/metrics
