-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
executable file
·211 lines (175 loc) · 6.26 KB
/
init
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
export DOTFILES_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
export DOTFILES_GIT_REMOTE="https://github.com/goodguyry/dotfiles"
cd "${DOTFILES_DIRECTORY}";
# Source utils
source var/helpers.sh;
source var/installers.sh;
# Sensible defaults.
export COPY_FILES=false;
export INSTALL_PACKAGES=true;
export CONFIGURE_PREFERENCES=true;
export IS_MACOS=false;
export IS_LINUX=false;
export IS_SERVER=false;
# Additional DRY checks.
[ -z "$(type -P brew)" ] && HAS_BREW=false || HAS_BREW=true;
export HAS_BREW;
[ -z "$(type -P git)" ] && HAS_GIT=false || HAS_GIT=true;
export HAS_GIT;
# Show help text.
if [[ "${1}" == "-h" || "${1}" == "--help" ]]; then
show_help_text;
exit;
fi;
# Test for known flags.
for OPT in "${@}"; do
case "${OPT}" in
--copy) COPY_FILES=true ;; # Copy the files in place instead of linking
--no-sync) SYNC_REPO=false ;; # Suppress syncing with GitHub
--no-packages) INSTALL_PACKAGES=false ;; # Suppress package installations and updates
--no-settings) CONFIGURE_PREFERENCES=false ;; # Suppress configuring OS settings
-*|--*) log_warning "Warning: invalid option ${OPT}" && show_help_text && exit ;;
esac
done;
print_script_details;
# Ask before potentially overwriting files.
printf '\n';
printf 'Continue? [Y/n]';
read CONTINUE;
# Conditionally set the dotfiles in place.
if [[ "${CONTINUE}" == 'n' ]]; then
log_header 'Aborting...';
exit 1;
fi;
# Create a Projects folder.
! $IS_SERVER && mkdirs "${HOME}/Projects";
if $INSTALL_PACKAGES; then
! $HAS_GIT && install_git;
if $SYNC_REPO; then
# Initialize the git repository if it's missing.
if $(git rev-parse --is-inside-work-tree &> /dev/null); then
log_info 'Dotfiles directory is already a Git repo.';
else
log_info 'Syncing dotfiles...';
git init;
git remote add origin "${DOTFILES_GIT_REMOTE}";
git fetch origin master;
# Reset the index and working tree to the fetched HEAD.
git reset --hard FETCH_HEAD;
# Remove any untracked files.
git clean -fd;
# Pull down the latest changes.
git pull --rebase origin master;
fi;
fi;
fi
# Add git config settings.
if [[ $CONFIGURE_PREFERENCES && $HAS_GIT ]]; then
source bin/gitconfig;
fi;
log_info "${WRITE_VERB}ing files to ${HOME}..."
mkdirs '.git-templates/hooks';
set_file 'home/aliases' "${HOME}/.aliases";
set_file 'home/bash_config' "${HOME}/.bash_config";
set_file 'home/bashrc' "${HOME}/.bashrc";
set_file 'home/completions' "${HOME}/.completions";
set_file 'home/functions' "${HOME}/.functions";
set_file 'home/gitignore' "${HOME}/.gitignore";
set_file 'home/hushlogin' "${HOME}/.hushlogin";
set_file 'home/inputrc' "${HOME}/.inputrc";
set_file 'home/paths' "${HOME}/.paths";
set_file 'home/profile' "${HOME}/.profile";
set_file 'home/prompt' "${HOME}/.prompt";
set_file 'home/vimrc' "${HOME}/.vimrc";
set_file 'etc/prepare-commit-msg' "${HOME}/.git-templates/hooks/prepare-commit-msg";
# Always copy editorconfig.
rsync -avz --quiet 'home/editorconfig' "${HOME}/.editorconfig";
# Create dotfiles.local if not present.
if [[ ! -r "${HOME}/.dotfiles.local" ]]; then
log_info "Creating ${HOME}/.dotfiles.local";
printf '#!/bin/bash\n\n' >> "${HOME}/.dotfiles.local";
fi;
# Source bashrc to make sure the environment is set before moving on.
source "${HOME}/.bashrc";
log_success "Done.";
printf "\n";
if $INSTALL_PACKAGES; then
install_homebrew;
install_nvm;
install_rvm;
if $IS_MACOS; then
install_mas;
source var/packages.macos.sh;
fi;
if $IS_LINUX && ! $IS_SERVER; then
set_ppas;
source var/packages.linux-desktop.sh;
install_downloads_debian;
fi;
$IS_SERVER && source var/packages.linux-server.sh;
[ ${#BREW_LIST[@]} -gt 0 ] && brew_install "${BREW_LIST[@]}";
[ ${#BREW_CASK_LIST[@]} -gt 0 ] && brew_cask_install "${BREW_CASK_LIST[@]}";
[ ${#MAS_APPS_LIST[@]} -gt 0 ] && mas_install "${MAS_APPS_LIST[@]}";
[ ${#APT_LIST[@]} -gt 0 ] && apt_install "${APT_LIST[@]}";
[ ${#SNAP_LIST[@]} -gt 0 ] && snap_install "${SNAP_LIST[@]}";
if ! $IS_SERVER; then
npm_install browser-sync git-open;
rvm_install jekyll octopress-autoprefixer rouge sass;
fi;
# List of directories.
declare -a DIRECTORIES=(
.vim/backups
.vim/colors
.vim/swaps
);
# Create directories.
for DIRECTORY in ${DIRECTORIES[*]}; do
mkdirs "${HOME}/${DIRECTORY}";
done;
# Download the Solarized Vim theme.
if [[ -f "${HOME}/.vim/colors/solarized.vim" ]]; then
log_info 'Solarized Vim theme already installed.';
else
# log_info 'Downloading Solarized Vim theme...';
# Extract colors/solarized.vim into .vim (Linux-friendly).
if $IS_LINUX; then
# Linux-friendly.
curl -#L https://github.com/altercation/vim-colors-solarized/tarball/master | \
tar -xzv -C "${HOME}/.vim" --strip-components 1 --wildcards '**/solarized.vim';
else
# macOS-Friendly.
curl -#L https://github.com/altercation/vim-colors-solarized/tarball/master | \
tar -xzv -C "${HOME}/.vim" --strip-components 1 --include='**/solarized.vim';
fi;
[[ $? ]] && log_success 'Solarized Vim theme installed' || log_error 'There was a problem installing the Solarized Vim theme.';
fi;
fi;
if $CONFIGURE_PREFERENCES; then
# Ask before potentially overwriting files.
log_warning "Warning: This step may modify your ${PROVISION_ENV} system defaults.";
printf 'Continue? [Y/n] ';
read DO_PREFERENCES;
printf '\n';
# Conditionally set defaults.
if [[ "${DO_PREFERENCES}" =~ ^[yY]$ ]]; then
$IS_MACOS && source bin/macos;
# $IS_LINUX && source bin/linux-desktop;
# $IS_SERVER && source bin/linux-server;
fi;
fi;
unset DOTFILES_DIRECTORY;
unset DOTFILES_GIT_REMOTE;
unset COPY_FILES;
unset INSTALL_PACKAGES;
unset CONFIGURE_PREFERENCES;
unset IS_MACOS;
unset IS_LINUX;
unset IS_SERVER;
unset HAS_BREW;
unset HAS_GIT;
unset PROVISION_ENV;
unset WRITE_VERB;
[[ $? ]] && log_success 'Done. Restarting the shell to apply changes...';
printf "\n";
exec $SHELL -l;