-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·179 lines (147 loc) · 5.08 KB
/
install.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
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env bash
#
# Description: Installs fresh development environment
#
if [ -n "$DEBUG" ]; then
echo "$0: Setting bash option -x for debug"
PS4='+($(basename ${BASH_SOURCE}):${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -x
fi
# Exit on error
set -e; set -o pipefail
PFX=${PFX:-==>}
HOME=${HOME:?}
OS_TYPE=${OS_TYPE:?}
DOTFILES_ROOT_DIR=${DOTFILES_ROOT_DIR:?}
DOTFILES_REPO_URL=${DOTFILES_REPO_URL:?}
DOTFILES_REPO_BRANCH=${DOTFILES_REPO_BRANCH:-master}
DOTFILES_LOCAL_REPO_URL=${DOTFILES_LOCAL_REPO_URL:?}
DOTFILES_LOCAL_REPO_BRANCH=${DOTFILES_LOCAL_REPO_BRANCH:-master}
DOTFILES_RELATIVE_BASE=${DOTFILES_RELATIVE_BASE:?}
CWD=$(pwd)
HOMEBREW_URL=https://raw.githubusercontent.com/Homebrew/install/master/install
DOTFILES_DIR=$DOTFILES_ROOT_DIR/dotfiles
DOTFILES_LOCAL_DIR=$DOTFILES_ROOT_DIR/dotfiles_local
function printUsage() {
echo "Usage: install.sh"
echo
echo "Environment variables:"
echo
echo " HOME - user home directory"
echo " OS_TYPE - osx (*)"
echo " DOTFILES_ROOT_DIR - path to directory where dotfiles repos will be cloned"
echo " DOTFILES_REPO_URL - dotfiles repo url (e.g git@github.com:mjgs/dotfiles.git)"
echo " DOTFILES_REPO_BRANCH - branch of the dotfiles repo (default: master)"
echo " DOTFILES_LOCAL_REPO_URL - dotfils_local repo url (e.g. git@github.com:mjgs/dotfiles_local.git)"
echo " DOTFILES_LOCAL_REPO_BRANCH - branch of the dotfiles_local repo (default: master)"
echo " DOTFILES_RELATIVE_BASE - path segment used as base for relative symlink creation"
echo " BACKUP_DIR - if set used as the source path in laptop-restore.sh script"
echo " (*) - add other os types scripts to bin/install/<os_type>"
echo
}
function printVariables() {
echo "$PFX Environment variables set:"
echo
echo " OS_TYPE: $OS_TYPE"
echo " HOME: $HOME"
echo " DOTFILS_REPO_DIR: $DOTFILS_REPO_DIR"
echo " DOTFILES_REPO_URL: $DOTFILES_REPO_URL"
echo " DOTFILES_REPO_BRANCH: $DOTFILES_REPO_BRANCH"
echo " DOTFILES_LOCAL_REPO_URL: $DOTFILES_LOCAL_REPO_URL"
echo " DOTFILES_LOCAL_REPO_BRANCH: $DOTFILES_LOCAL_REPO_BRANCH"
echo
}
function getAdminPassword() {
# Ask for the administrator password upfront.
echo "Admin password is required for install..."
sudo -v
# Keep-alive: update existing `sudo` time stamp until the script has finished.
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
}
function getUserInfo() {
read -p "What is your name? " NAME
read -p "What is your email address? " EMAIL
}
function createDirectories() {
echo "$PFX Creating DOTFILES_ROOT_DIR: $DOTFILES_ROOT_DIR"
mkdir -p $DOTFILES_ROOT_DIR
}
function cloneRepo() {
local REPO=$1
local TARGET_DIR=$2
local BRANCH=$3
echo "$PFX Cloning repo: $REPO"
echo "$PFX Target directory: $TARGET_DIR"
echo "$PFX Branch to checkout: $BRANCH"
if [ ! -e "$TARGET_DIR" ]; then
git clone -b $BRANCH "$REPO" "$TARGET_DIR"
else
echo "$PFX Target directory exists, skipping..."
fi
}
function cloneLatestDotfileRepos() {
echo "$PFX Add your public key to your dotfiles code repositories before continuing"
read -p "$PFX Hit enter to continue..." enter
cloneRepo $DOTFILES_LOCAL_REPO_URL $DOTFILES_LOCAL_DIR $DOTFILES_LOCAL_REPO_BRANCH
cloneRepo $DOTFILES_REPO_URL $DOTFILES_DIR $DOTFILES_REPO_BRANCH
}
function exportVariables() {
export PFX
export NAME
export EMAIL
export HOMEBREW_URL
export DOTFILES_DIR
export DOTFILES_REPO
export DOTFILES_LOCAL_REPO
export DOTFILES_LOCAL_DIR
export DOTFILES_RELATIVE_BASE
}
function runInstallScripts() {
echo "$PFX Running install scripts..."
# Configure git, ssh keys and dotfiles here since they are needed during the installation
$DOTFILES_DIR/bin/install/common/configurations/cli/git.sh
$DOTFILES_DIR/bin/install/common/configurations/cli/publicPrivateKeyPair.sh
$DOTFILES_DIR/bin/install/common/installs/openssl.sh
$DOTFILES_DIR/bin/install/common/installs/dotfiles.sh
# Restore files from backup
if [ -d "$BACKUP_DIR" ]; then
$DOTFILES_DIR/bin/restore_laptop.sh
fi
# dotfiles_local install
if [ -d "$DOTFILES_LOCAL_DIR" ]; then
$DOTFILES_LOCAL_DIR/install.sh
fi
# Noe that everyhing has been setup from local dotfiles load bashrc
echo "$PFX Loading $HOME/.bashrc"
source $HOME/.bashrc
# dotfiles install
$DOTFILES_DIR/bin/install/common/install.sh
$DOTFILES_DIR/bin/install/$OS_TYPE/install.sh
}
#
# Main
#
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
printUsage
exit 1
fi
TIMESTAMP_START=$(date)
echo "$PFX dotfiles installation started: $TIMESTAMP_START"
if [ ! -x /usr/bin/git ]; then
echo "ERROR: Apple's version of git must be installed"
exit 1
fi
printVariables
#getAdminPassword
getUserInfo
createDirectories
cloneLatestDotfileRepos
exportVariables
runInstallScripts
TIMESTAMP_END=$(date)
echo "$PFX dotfiles installation started: $TIMESTAMP_START"
echo "$PFX dotfiles installation complete: $TIMESTAMP_END"
echo "TODO: Make sure all nvim plugins got installed, open nvim and run:"
echo ":PluginInstall"
echo ":PluginUpdate"
exit 0