forked from Edditoria/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·157 lines (132 loc) · 4.21 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
#!/usr/bin/env bash
# Require: User account, machine name and localhost are set.
# Require: bash, XCode (macOS), git and Homebrew are properly installed.
# NOTE: Suppose Github Codespaces will run this file at first priority.
# Simple Health Check
# ===================
echo '[dotfiles:install] Start...'
# Do what Homebrew does:
if [ -z "${BASH_VERSION:-}" ]; then
echo '[dotfiles:install] Require Bash to run this script.'
return 1 2> /dev/null || exit 1
fi
if [[ -n "${CI-}" && -n "${INTERACTIVE-}" ]]; then
echo '[dotfiles:install] Cannot run force-interactive mode in CI.'
return 1 2> /dev/null || exit 1
fi
if [[ -n "${INTERACTIVE-}" && -n "${NONINTERACTIVE-}" ]]; then
echo '[dotfiles:install] Both `$INTERACTIVE` and `$NONINTERACTIVE` are set. Please unset at least one variable and try again.'
return 1 2> /dev/null || exit 1
fi
# Thanks Homebrew team!
if ! command -v git > /dev/null; then
echo '[dotfiles:install] Cannot find git.'
return 1 2> /dev/null || exit 1
fi
if [[ "$CODESPACES" == true ]]; then
echo ''
# TODO: More health check...
elif [[ "$(uname -s)" == 'Darwin' ]]; then
if ! command -v brew > /dev/null; then
echo '[dotfiles:install] Cannot find Homebrew.'
return 1 2> /dev/null || exit 1
fi
# TODO: More health check...
elif [[ "$(uname -s)" == 'Linux' ]]; then
if ! command -v brew > /dev/null; then
echo '[dotfiles:install] Cannot find Homebrew.'
return 1 2> /dev/null || exit 1
fi
# TODO: More health check...
fi
# Let's Get It Started
# ====================
( # Subshell start
this_file_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
dotfiles_profile='not_supported'
if [[ "$CODESPACES" == true ]]; then
dotfiles_profile='CodeSpaces'
elif [[ "$(uname -s)" == 'Darwin' ]]; then
dotfiles_profile='macOS'
elif [[ "$(uname -s)" == 'Linux' ]]; then
dotfiles_profile='Linux'
else
echo "[dotfiles:install] Machine type not supported: $(uname -s)"
return 1 2> /dev/null || exit 1
fi
# Setup git
echo '[setup:git] Start...'
# CodeSpaces already set user in `--system`.
if [[ "$dotfiles_profile" != 'CodeSpaces' ]]; then
source $this_file_dir/functions/setup_git_user.sh
setup_git_user
fi
source $this_file_dir/functions/setup_git_configs.sh
setup_git_configs
echo '[setup:git] Done.'
# Setup shells: bash
echo '[setup:shells] Start...'
source "$this_file_dir/functions/setup_shells.sh"
setup_shells $dotfiles_profile
echo '[setup:shells] Done.'
# Install apps and cli-tools via Homebrew
if [[ "$dotfiles_profile" != 'CodeSpaces' ]]; then
echo '[install:apps] Start...'
source $this_file_dir/functions/setup_homebrew.sh
setup_homebrew $dotfiles_profile
echo '[install:apps] Done.'
fi
# Setup asdf
if [[ "$dotfiles_profile" != 'CodeSpaces' ]]; then
echo '[setup:asdf] Start...'
source $this_file_dir/functions/setup_asdf.sh
setup_asdf $dotfiles_profile
echo '[setup:asdf] Done.'
fi
# Setup Node env
# - CodeSpaces: nvm via its own nvc.
# - macOS: asdf, somtimes nvm.
# - Linux(_mini): asdf, sometimes nvm.
echo '[setup:node] Start...'
if [[ "$dotfiles_profile" == 'CodeSpaces' ]]; then
source "$this_file_dir/functions/setup_nvm.sh"
setup_nvm
else
echo '[setup:node] Setup asdf nodejs...'
source $this_file_dir/functions/setup_asdf_nodejs.sh
setup_asdf_nodejs
echo '[setup:node] Skipped setup_nvm. Please manually run functions/setup_nvm.sh'
fi
echo '[setup:node] Done.'
# Setup Ruby env
echo '[setup:ruby] Start...'
source $this_file_dir/functions/setup_ruby.sh
setup_ruby
if [[ "$dotfiles_profile" != 'CodeSpaces' ]]; then
source $this_file_dir/functions/setup_chruby.sh
setup_chruby
fi
echo '[setup:ruby] Done.'
# Setup tmux
if [[ "$dotfiles_profile" != 'CodeSpaces' ]]; then
echo '[setup:tmux] Start...'
source "$this_file_dir/functions/setup_tmux.sh"
setup_tmux
echo '[setup:tmux] Done.'
fi
# Setup micro-editor
if [[ "$dotfiles_profile" != 'CodeSpaces' ]]; then
echo '[setup:micro] Start...'
source "$this_file_dir/functions/setup_micro.sh"
setup_micro
echo '[setup:micro] Done.'
fi
# Setup Vim
if [[ "$dotfiles_profile" != 'CodeSpaces' ]]; then
echo '[setup:vim] Start...'
source "$this_file_dir/functions/setup_vim.sh"
setup_vim
echo '[setup:vim] Done.'
fi
) # Subshell end
echo '[dotfiles:install] Done.'