-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·169 lines (133 loc) · 5.06 KB
/
bootstrap.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#! /usr/bin/env bash
# This is the BOOTSTRAPPER script that installs system programs and dependencies
# required to apply akinizer configurations
set -e # Exit on any error
# ------------------------------------------------------------------------------
# Settings
# ------------------------------------------------------------------------------
# Which ref to checkout after installing Akinizer. Defaults to `master`
AK_GIT_REF=${AK_GIT_REF:-master}
# Where to install Akinizer. Defaults to `$HOME/opt/akinizer`
AK_INSTALL_ROOT=${AK_INSTALL_ROOT:-$HOME/opt/akinizer}
# Optionally skip cloning the Akinizer repo
AK_SKIP_CLONE=${AK_SKIP_CLONE:-no}
# ------------------------------------------------------------------------------
# Constants, helper functions
# ------------------------------------------------------------------------------
PLATFORM=$(uname -s)
AK_REPO_URL="https://github.com/robatron/akinizer.git"
function log() {
echo ">>> $1"
}
function logw() {
echo "!!! $1"
}
function assure_installed_mac() {
log "Looking for $1..."
if ! [ -x "$(command -v $1)" ]; then
log "'$1' not installed. Attempting to install..."
brew install $1
fi
}
function assure_installed_linux() {
log "Looking for $1..."
if ! [ -x "$(command -v $1)" ]; then
log "'$1' not installed. Attempting to install..."
sudo apt install -y $1
fi
}
# ------------------------------------------------------------------------------
# Bootstrap system
# ------------------------------------------------------------------------------
log "Bootstrapping Akinizer w/ these settings:"
log " AK_GIT_REF: $AK_GIT_REF"
log " AK_INSTALL_ROOT: $AK_INSTALL_ROOT"
log " AK_REPO_URL: $AK_REPO_URL"
log " AK_SKIP_CLONE: $AK_SKIP_CLONE"
log " PLATFORM: $PLATFORM"
log "Looking for system target managers and base programs..."
if [ "$PLATFORM" = "Darwin" ]; then
log "Mac OS X detected"
log "Looking for homebrew..."
if ! [ -x "$(command -v brew)" ]; then
log "Homebrew missing. Installing homebrew..."
/usr/bin/ruby -e \
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
log "Looking for Apple Command Line Tools..."
if ! [ -d "/Library/Developer/CommandLineTools" ]; then
APPLE_CMD_LINE_TOOLS_INSTALLING="yes"
log "Apple Command Line Tools missing. Installing..."
xcode-select --install
else
APPLE_CMD_LINE_TOOLS_INSTALLING="no"
fi
assure_installed_mac curl
assure_installed_mac git
elif [ "$PLATFORM" = "Linux" ]; then
log "Linux detected. Looking for apt..."
if ! [ -x "$(command -v apt)" ]; then
logw "apt isn't available and I don't know what to do :-("
exit 1
fi
assure_installed_linux curl
assure_installed_linux git
fi
# ------------------------------------------------------------------------------
# Bootstrap Node.js
# ------------------------------------------------------------------------------
log "Assuring nvm installed..."
export NVM_DIR="$HOME/.nvm"
if [ ! -d $NVM_DIR ]; then
log "Nvm not installed. Installing..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
fi
log "Assuring nvm loaded..."
if ! [ -x "$(command -v nvm)" ]; then
log "Nvm not loaded. Loading..."
. "$NVM_DIR/nvm.sh"
fi
log "Assuring node installed..."
if ! [ -x "$(command -v node)" ]; then
log "Node not installed. Installing latest LTS version and latest npm..."
nvm install --lts --latest-npm
fi
log "Assuring gulp installed globally..."
if ! [ -x "$(command -v gulp)" ]; then
log "Gulp not installed. Installing..."
npm i -g gulp-cli
fi
# ------------------------------------------------------------------------------
# Install / update Akinizer itself
# ------------------------------------------------------------------------------
# TODO: Publish and install via NPM
if ! [ $AK_SKIP_CLONE = yes ]; then
log "Downloading Akinizer..."
mkdir -p $(dirname $AK_INSTALL_ROOT)
cd $(dirname $AK_INSTALL_ROOT)
if ! [ -d $(basename $AK_INSTALL_ROOT) ]; then
log "Akinizer not found at $AK_INSTALL_ROOT. Cloning Akinizer at $AK_GIT_REF..."
git clone $AK_REPO_URL $AK_INSTALL_ROOT
else
log "Akinizer directory exists at $AK_INSTALL_ROOT. Updating repo to $AK_GIT_REF..."
fi
cd $AK_INSTALL_ROOT
git fetch
git checkout $AK_GIT_REF
else
log "Akinizer clone skipped: AK_SKIP_CLONE == yes"
fi
log "Installing Akinizer dependencies..."
if ! [ -d "$AK_INSTALL_ROOT/node_modules" ]; then
cd $AK_INSTALL_ROOT
npm i
else
log "Akinizer deps are already installed"
fi
if [ "$APPLE_CMD_LINE_TOOLS_INSTALLING" = "yes" ]; then
log "WAIT! Akinizer bootstrapping is ALMOST complete. Apple Command Line Tools needs to finish installing, then you can run 'gulp' in the same directory as your Akinizer gulpfile."
else
log "Akinizer bootstraping complete! Run 'gulp' in the same directory as your Akinizer gulpfile:"
log ". $HOME/.nvm/nvm.sh && cd $AK_INSTALL_ROOT/examples/ && gulp"
fi
cd examples/