forked from wevote/WebApp
-
Notifications
You must be signed in to change notification settings - Fork 3
/
installmac.sh
executable file
·72 lines (51 loc) · 5.24 KB
/
installmac.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#For Mac users only
#!/usr/bin/env zsh
function error() { echo "\x1B[1;31m$1\x1B[0m"; exit 1; }
function success() { echo "\x1B[1;32m$1\x1B[0m"; }
[[ "$1" == "" ]] && error "./installmac.sh <github username>"
gituser=$1
minNodeVersion="v10.12.0"
minNpmVersion="6.4.1"
echo "[*] Installing brew..."
which brew >/dev/null && success "[+] Brew already installed" || (echo "" | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" >/dev/null 2>&1 && success "[+] Installed brew" || error "[-] Failed to install brew")
echo "[*] Installing python..."
which python >/dev/null && success "[+] Python already installed" || (brew install python >/dev/null 2>&1 && success "[+] Installed python" || error "[-] Failed to install python")
echo "[*] Installing pip..."
which pip3 >/dev/null && success "[+] Pip already installed" || (curl -s https://bootstrap.pypa.io/get-pip.py | sudo python >/dev/null 2>&1 && success "[+] Installed pip" || error "[-] Failed to install pip")
echo "[*] Installing nodeenv..."
which nodeenv >/dev/null && success "[+] Nodeenv already installed" || (sudo -H pip install nodeenv >/dev/null 2>&1 && success "[+] Installed nodeenv" || error "[-] Failed to install nodeenv")
echo "[*] Installing node..."
which node >/dev/null && success "[+] Node already installed" || (brew install node >/dev/null 2>&1 && success "[+] Installed node" || error "[-] Failed to install node")
echo "[*] Checking node and npm versions..."
[[ "`echo -e "$(node -v)\n$minNodeVersion" | sort -V | head -n 1`" == "$nodeVersion" && "$nodeVersion" != "$minNodeVersion" ]] && error "node is not up to date"
[[ "`echo -e "$(npm -v)\n$minNpmVersion" | sort -V | head -n 1`" == "$npmVersion" && "$npmVersion" != "$minNpmVersion" ]] && error "npm is not up to date"
success "[+] Node and npm are up to date"
echo "[*] Making node environment..."
[[ -d "$HOME/NodeEnvironments/WebAppEnv" ]] && success "[+] Node environment already created" && cd $HOME/NodeEnvironments/ || (mkdir $HOME/NodeEnvironments/ && cd $HOME/NodeEnvironments/ && nodeenv WebAppEnv && success "[+] Node environment created" || error "[-] Failed to create node environment")
echo "[*] Activating Web App Environment and rebuilding node-sass..."
. $HOME/NodeEnvironments/WebAppEnv/bin/activate && npm rebuild node-sass && success "[+] Activated Web App Environment and rebuilt node-sass" || error "[-] Failed to activate Web App Environment or rebuild node-sass"
echo "[*] Cloning git repository..."
[[ -d "$HOME/MyProjects/WebApp" ]] && success "[+] Git repository already cloned" && cd $HOME/MyProjects/WebApp || (mkdir $HOME/MyProjects/ && cd $HOME/MyProjects/ && git clone https://github.com/$gituser/WebApp.git && cd WebApp && success "[+] Cloned git repository" || error "[-] Failed to clone git repository")
echo "[*] Setting path..."
[[ `echo $PATH | grep /usr/local/bin` != "" ]] && success "[+] Path already set" || (export PATH="/usr/local/bin:$PATH" && success "[+] Added /usr/local/bin to path" || error "[-] Failed to add /usr/local/bin to path")
echo "[*] Adding git remote url..."
[[ "`git remote | grep upstream`" == "upstream" ]] && success "[+] Already added git remote url" || (git remote add upstream [email protected]:wevote/WebApp.git && success "[+] Added git remote url" || error "[-] Failed to add git remote url")
echo "[*] Adding config.js..."
[[ -f "$HOME/MyProjects/WebApp/src/js/config.js" ]] && success "[+] config.js already exists" || (cp src/js/config-template.js src/js/config.js && success "[+] Added config.js" || error "[-] Failed to add config.js")
echo "[*] Adding browserstack.config.js..."
[[ -f "$HOME/MyProjects/WebApp/tests/browserstack/browserstack.config.js" ]] && success "[+] browserstack.config.js already exists" || (cp tests/browserstack/browserstack.config-template.js tests/browserstack/browserstack.config.js && success "[+] Added browserstack.config.js" || error "[-] Failed to add browserstack.config.js")
echo "[*] Installing npm packages..."
{
npm install fsevents
npm install
} >/dev/null 2>&1 && success "[+] Installed npm packages" || error "[-] Failed to install npm packages"
echo "[*] Adding ssh key..."
[[ -f "$HOME/.ssh/id_rsa" ]] && success "[+] ssh key already exists" || (ssh-keygen -q -t rsa -b 4096 -N '' -f "$HOME/.ssh/id_rsa" && success "[+] Created ssh key" || error "[-] Failed to create ssh key")
echo "[*] Adding ssh key to ssh authentication agent..."
ssh-add ~/.ssh/id_rsa 2>/dev/null && success "[+] Added ssh key to ssh authentication agent" || error "[-] Failed to add ssh key to ssh authentication agent"
echo "[*] Copying ssh key to ssh authentication agent..."
pbcopy < ~/.ssh/id_rsa.pub >/dev/null && success "[+] Copied ssh key to clipboard" || error "[-] Failed to copy ssh key to clipboard"
success "[*] Done"
echo "\x1B[33;1mGo to your "Settings" page in GitHub (click on your avatar on the top right). In the left navigation, choose "SSH and GPG keys".
Click the "New SSH key" button on the top right.
Paste the contents of the "~/.ssh/id_rsa.pub" key file (which you alerady copied to your clipboard) into the "Key" text area, and give it any Title you would like. Then go back to the terminal and run the command 'git remote set-url origin [email protected]:$gituser/WebApp.git' followed by 'git config --global user.name "$gituser"'.\x1B[0m"