#!/bin/bash

### https://sourabhbajaj.com/mac-setup/
## Nice overview of mac setup, much better than this one! 

### Don't forget !!!

### cd ~
### chmod a+x macos-settings.sh
### sh macos-settings.sh

##------------- Install XCode Command Line Tools
## Accept license
## use xcode-select -p to check whether Xcode is installed
xcode-select --install
sudo xcodebuild -license


##------------- Installing Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

##------------- Refresh repositories
brew update

##------------- Tapping (Installing 3rd party repositories)
brew tap osgeo/osgeo4mac

##------------- Utilitaries
brew install --cask adobe-acrobat-reader `# Requires pasasword`
brew install --cask cleanmymac
brew install --cask google-chrome
brew install graphicsmagick
brew install ffmpeg
brew install hugo
brew install imagemagick
brew install mplayer
brew install node
brew install --cask the-unarchiver
brew install --cask transmission
brew install vim
brew install --cask vlc
brew install youtube-dl
brew install wget
brew install --cask clickup

##------------- Mail
brew install --cask thunderbird
# [ULaval setup](https://www.dti.ulaval.ca/system/files/offreservices/Courrier_electronique/guide_le_courrier_electronique_ul.pdf)

# UQAR
# - IMAP:
#   - Serveur: corrier.uqar.ca
#   - Port: 143
#   - SSL: STARTTLS
#   - Authentification : Mot de passe normal
# - SMTP
#   - Serveur: smtp-mail.outlook.com
#   - Port : 587
#   - SSL : STARTTLS
#   - Authentification : Mot de passe normal
# - Identifiant : Code usager de l’UQAR
#
# ULaval
# - IMAP:
#   - Serveur: courriel.ulaval.ca
#   - Port: 993
#   - SSL: SSL
#   - Authentification: Mot de passe normal
# - SMTP
#   - Serveur: courriel.ulaval.ca
#   - Port: 587
#   - SSL: TLS
#   - Authentification: Mot de passe normal
# - Identifiant : IDUL de l'ULaval

##------------- Communications app
brew install --cask skype
brew install --cask slack
brew install --cask discord
brew install --cask microsoft-teams
brew install --cask zoom


##------------- Reference manager
brew install --cask mendeley
brew install --cask zotero
# install better bibtex manually: https://retorque.re/zotero-better-bibtex/installation/

##------------- Files Hosting Services
# brew install --cask dropbox
# brew install --cask google-backup-and-sync
# brew install --cask megasync
# brew install --cask owncloud `# Requires pasasword`
brew install --cask onedrive `# For UL, DABEA232@ulaval.ca`
brew install --cask nextcloud `# For inSileco, david.beauchesne@insileco.io`



##------------- Music
brew install --cask spotify

##------------- Password manager
brew install --cask dashlane `# Backup before reset`

##------------- Image editor
brew install --cask xquartz `# Requires pasasword`
brew install --cask inkscape
brew install --cask gimp

##------------- Libre office
## brew install --cask libreoffice

##------------- Atom, Packages, Theme & Keybindings
# Appplication
brew install --cask atom

# Packages
apm install ascii-unicode-escape
apm install atom-beautify
apm install atom-increment
apm install atom-language-r
apm install autocomplete-R
apm install autocomplete-paths
apm install color-picker
apm install dictionary
apm install file-icons
apm install highlight-selected
apm install language-knitr
apm install language-latex
apm install language-markdown
apm install language-sage
apm install latex
apm install latexer
apm install mathjax-wrapper
apm install minimap
apm install minimap-highlight-selected
apm install pdf-view
apm install pigments
apm install platformio-ide-terminal
apm install r-exec
apm install rainbow-csv
apm install tree-view-git-status
apm install wordcount

# Themes
apm install seti-ui
apm install seti-vs-syntax

# Keybindings
echo "'atom-workspace atom-text-editor:not([mini])':
  'cmd-enter': 'r-exec:send-command' `# r execution keybind`
  'shift-cmd-l': 'custom:insert-pipe' `# r pipe`" >> ~/.atom/keymap.cson

echo "atom.commands.add 'atom-text-editor',
  'custom:insert-pipe': ->
    atom.workspace.getActiveTextEditor()?.insertText('%>%')" >> ~/.atom/init.coffee

##------------- R and GIS dependencies
brew install java `# Requires pasasword`
brew install geos
brew install proj
brew install libxml2
brew install openssl
brew install gdal
brew install netcdf
brew install poppler
brew install udunits
brew install r
brew install libgit2
brew install --cask rstudio
# brew install gdal2 --with-armadillo --with-complete --with-libkml --with-unsupported

# -------- weird setup for packages, links don't match (2019-05-13)
# Openblas
# For r, dunno why but I needed to create a link to gcc for openblas
# ln -s /usr/local/Cellar/gcc/9.1.0/lib/gcc/9/libgcc_s.1.dylib /usr/local/lib/gcc/9/
# 
# Netcdf 
# cd /usr/local/opt/
# mkdir netcdf
# mkdir netcdf/lib
# ln -s /usr/local/Cellar/netcdf/4.6.3_1.reinstall/lib/libnetcdf.15.dylib /usr/local/opt/netcdf/lib/
#
# XML2 - for now the path is changes for XCODE
# https://github.com/r-lib/xml2/issues/232
# sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

# Setup R
# Install packages
Rscript -e "download.file('https://gist.githubusercontent.com/david-beauchesne/c43465aa4d3927833c7395f28cd214df/raw/c8c180da3b33c7fe0be7a02da7ec531776cbf7ab/rPackages.R', destfile='~/Desktop/rPackages.R')"
Rscript ~/Desktop/rPackages.R
rm ~/Desktop/rPackages.R

# R Profile
Rscript -e "download.file('https://gist.githubusercontent.com/david-beauchesne/f038ad269d12a872b5b0ce64e9d6d56c/raw/cb2b0d5ba98976fc94b0db5c002b3ade890d69f4/rProfile.R', destfile='~/Desktop/rProfile.R')"
Rscript ~/Desktop/rProfile.R
rm ~/Desktop/rProfile.R

# Configure R java
Rscript -e "download.file('https://gist.githubusercontent.com/david-beauchesne/ca903a7e66fb713071a9907830929b72/raw/0df7672c541443cf813f62819c3d51a745d05685/rJava.R', destfile='~/Desktop/rJava.R')"
Rscript ~/Desktop/rJava.R
sudo R CMD javareconf
rm ~/Desktop/rJava.R


##------------- QGIS
# brew install osgeo/osgeo4mac/qgis2
# ln -s /usr/local/opt/qgis2/QGIS.app/ /Applications/
# pip install psycopg2
# pip install matplotlib
# pip install pyparsing
# pip install requests
# pip install future
# pip install jinja2
# pip install pygments

##------------- Pandoc and Pandoc's filters
brew install pandoc
brew install pandoc-citeproc
pip install pandoc-fignos
pip install pandoc-tablenos
pip install pandoc-eqnos

##------------- Install and setup Git and Github
brew install git
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global user.name "David Beauchesne"
git config --global user.email "david.beauchesne@uqar.ca"
git config --global github.user "david-beauchesne"
brew install git-lfs
git lfs install
# Info on GIT lfs: https://help.github.com/categories/managing-large-files/

##------------- PostgreSQL
brew install postgresql
brew install --cask pgadmin4

##------------- Install jekyll
sudo gem install jekyll jekyll-language-plugin


##------------- Install zsh and prezto (https://codurance.com/2015/03/16/installing-zprezto-a-quick-guide/)
brew install zsh
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
setopt EXTENDED_GLOB
  for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
    ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
  done
# change shell
chsh -s /bin/zsh

##------------- Terminal 
# brew cask install iterm2
# bash -c  "$(curl -sLo- https://git.io/vQgMr)" 

##------------- Load github repositories
# Build structure of GitHub repo on new MAC - 2021-02
mkdir ~/DB

## Personal projects
mkdir ~/DB/Personnel
cd ~/DB/Personnel
git clone https://github.com/david-beauchesne/recettes.git
git clone https://github.com/david-beauchesne/MapArt.git

## Communications
mkdir ~/DB/Comm
cd ~/DB/Comm
git clone https://github.com/david-beauchesne/CurriculumVitae.git

### Presentations
mkdir ~/DB/Comm/Presentations

#### 2019
mkdir ~/DB/Comm/Presentations/2019
cd ~/DB/Comm/Presentations/2019
git clone https://github.com/david-beauchesne/2019_ForumSciencesMarines_Poster.git

#### 2020
mkdir ~/DB/Comm/Presentations/2020
cd ~/DB/Comm/Presentations/2020
git clone https://github.com/david-beauchesne/DFO-BIO_Intro_presentation.git

#### 2021
mkdir ~/DB/Comm/Presentations/2021
cd ~/DB/Comm/Presentations/2021
git clone https://github.com/david-beauchesne/2021-02-04_Webinaire_IDDPNQL_en.git
git clone https://github.com/david-beauchesne/2021-02-04_Webinaire_IDDPNQL.git
git clone https://github.com/david-beauchesne/2021-02-09-UL_CEA_Cours.git
git clone https://github.com/david-beauchesne/2021-02-12-DFO_MSP.git


## Academia 
mkdir ~/DB/Academia

### Projects
mkdir ~/DB/Academia/Projects

#### Cumulative effects St. Lawrence System
mkdir ~/DB/Academia/Projects/NCEA_StLawrence
cd ~/DB/Academia/Projects/NCEA_StLawrence
git clone https://github.com/david-beauchesne/Species_Vulnerability.git
git clone https://github.com/david-beauchesne/Predict_interactions.git
git clone https://github.com/david-beauchesne/MetawebEGSL.git
git clone https://github.com/david-beauchesne/Interaction_catalog.git
git clone https://github.com/david-beauchesne/environmentEGSL.git
git clone https://github.com/david-beauchesne/FoodWeb-MultiStressors.git
git clone https://github.com/david-beauchesne/FoodWeb-CumulativeImpact.git

##### eBiotic
mkdir ~/DB/Academia/Projects/NCEA_StLawrence/eBiotic
cd ~/DB/Academia/Projects/NCEA_StLawrence/eBiotic
git clone https://github.com/eBiotic/Traits.git
git clone https://github.com/eBiotic/Biotic.git

##### eDrivers
mkdir ~/DB/Academia/Projects/NCEA_StLawrence/eDrivers
cd ~/DB/Academia/Projects/NCEA_StLawrence/eDrivers
git clone https://github.com/eDrivers/eDrivers.git
git clone https://github.com/eDrivers/eDriversMS.git
git clone https://github.com/eDrivers/eDriversEx.git
git clone https://github.com/eDrivers/eDriversWorkflows.git
git clone https://github.com/eDrivers/eDriversGrids.git
git clone https://github.com/eDrivers/eDriversApp.git

###### Drivers
mkdir ~/DB/Academia/Projects/NCEA_StLawrence/eDrivers/Drivers
cd ~/DB/Academia/Projects/NCEA_StLawrence/eDrivers/Drivers
git clone https://github.com/eDrivers/ToxicAlgae.git
git clone https://github.com/eDrivers/Shipping.git
git clone https://github.com/eDrivers/SeaSurfaceTemperature.git
git clone https://github.com/eDrivers/SeaLevel.git
git clone https://github.com/eDrivers/SeaBottomTemperature.git
git clone https://github.com/eDrivers/OrganicPollution.git
git clone https://github.com/eDrivers/NutrientInput.git
git clone https://github.com/eDrivers/MarinePollution.git
git clone https://github.com/eDrivers/InvasiveSpecies.git
git clone https://github.com/eDrivers/InorganicPollution.git
git clone https://github.com/eDrivers/Hypoxia.git
git clone https://github.com/eDrivers/Fisheries.git
git clone https://github.com/eDrivers/DirectHumanImpact.git
git clone https://github.com/eDrivers/CoastalDevelopment.git



#### Cumulative effects Navigation TC
mkdir ~/DB/Academia/Projects/CEA_Navigation_TC
cd ~/DB/Academia/Projects/CEA_Navigation_TC
git clone https://github.com/EffetsCumulatifsNavigation/ceanav.git
git clone https://github.com/EffetsCumulatifsNavigation/WebinaireMethode
git clone https://github.com/EffetsCumulatifsNavigation/Methode
git clone https://github.com/EffetsCumulatifsNavigation/Methodology
git clone https://github.com/david-beauchesne/Rapport
git clone https://github.com/EffetsCumulatifsNavigation/ZoneEtude

#### Cumulative effects Scotian Shelf
mkdir ~/DB/Academia/Projects/NCEA_ScotianShelf_DFO-BIO
cd ~/DB/Academia/Projects/NCEA_ScotianShelf_DFO-BIO
git clone https://github.com/david-beauchesne/CumulativeEffects-ScotianShelf


### PhD
mkdir ~/DB/Academia/PhD
cd ~/DB/Academia/PhD
git clone https://github.com/david-beauchesne/Soutenance.git
git clone https://github.com/david-beauchesne/ThesePhD.git

### Project ideas
mkdir ~/DB/Academia/Ideas
cd ~/DB/Academia/Ideas
git clone https://github.com/david-beauchesne/KnowledgeManagement.git
git clone https://github.com/david-beauchesne/KnowledgeGraphs.git
git clone https://github.com/david-beauchesne/Global_FoodWeb_CumulativeImpacts.git


## inSilecoInc
mkdir ~/DB/inSilecoInc/

### Administrative
mkdir ~/DB/inSilecoInc/Admin
cd ~/DB/inSilecoInc/Admin
git clone https://github.com/inSilecoInc/admin
git clone https://github.com/inSilecoInc/inSilecoAdmin.git

### Education
mkdir ~/DB/inSilecoInc/Education
cd ~/DB/inSilecoInc/Education
git clone https://github.com/inSilecoInc/workshop_raster.git
git clone https://github.com/inSilecoInc/interactiveRaster.git
git clone https://github.com/inSilecoInc/workshop_reproducibility.git
git clone https://github.com/sci1031/sci1031.git

### Consultation
mkdir ~/DB/inSilecoInc/Consultation
cd ~/DB/inSilecoInc/Consultation
git clone https://github.com/inSilecoInc/shinySpatialApp.git


### Communication
mkdir ~/DB/inSilecoInc/Communication
cd ~/DB/inSilecoInc/Communication
git clone https://github.com/inSilecoInc/inSilecoInc.github.io.git
git clone https://github.com/inSileco/inSileco.github.io.git



##------------- Reboot
sudo reboot