-
Notifications
You must be signed in to change notification settings - Fork 0
/
smu
executable file
·174 lines (123 loc) · 4.91 KB
/
smu
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
#!/bin/bash
source /dev/stdin <<<"$(curl -s "https://raw.githubusercontent.com/dotbrains/utilities/master/utilities.sh")"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Path to the 'set-me-up' directory
readonly smu_home_dir=${smu_home_dir:-"${HOME}/set-me-up"}
# Get the absolute path of the 'scripts' directory.
# This is only for aesthetic reasons to have an absolute symlink path instead of a relative one
# <path-to-smu>/scripts/somedotfile vs <path-to-smu>/scripts/brew/../somedotfile
readonly installer_scripts_path="${smu_home_dir}/set-me-up-installer/scripts"
# Get the absolute path of the 'utilities' directory.
readonly installer_utilities_path="${smu_home_dir}/set-me-up-installer/utilities"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Dynamically build SMU_BLUEPRINT and SMU_BLUEPRINT_BRANCH
# from the 'set-me-up' directory
if [[ -e "${smu_home_dir}" ]]; then
# Get the current branch of the 'set-me-up' repository
# e.g., 'master' or 'main'
readonly SMU_BLUEPRINT_BRANCH=$(git -C "${smu_home_dir}" rev-parse --abbrev-ref HEAD)
# Get the remote URL of the 'set-me-up' repository
# e.g., 'org/repo' or 'user/repo'
remote_url=$(git -C "${smu_home_dir}" config --get remote.origin.url)
readonly SMU_BLUEPRINT=$(echo "${remote_url}" | sed 's|https://github.com/||' | sed 's/\.git$//')
# Export variables to make them available to the Python script
export SMU_BLUEPRINT_BRANCH
export SMU_BLUEPRINT
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Determine if we're on MacOS or Debian
if [[ "$OSTYPE" == "darwin"* ]]; then
readonly SMU_OS="MacOS"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
readonly SMU_OS="debian"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
create_bash_local() {
declare -r FILE_PATH="$HOME/.bash.local"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [[ ! -e "$FILE_PATH" ]] || [[ -z "$FILE_PATH" ]]; then
printf "%s\n" "#!/bin/bash" >>"$FILE_PATH"
fi
}
install_brew() {
bash "${installer_scripts_path}"/brew/brew.sh
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
main() {
# This is a wrapper script for 'smu.py'.
# It is used to check if the (minimal) required dependencies are installed.
# If they are not installed, then this script will attempt to install them.
bash "${installer_utilities_path}"/header.sh
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check if detected OS is supported
if [[ "${SMU_OS}" != "MacOS" ]] && [[ "${SMU_OS}" != "debian" ]]; then
error "Sorry, '${bold}set-me-up${normal}' is not supported on your OS.\n"
exit 1
fi
success "Detected 'set-me-up' version: ${bold}${SMU_OS}${normal}."
printf "\n"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check if ~/.bash.local exists
if [ ! -f "${HOME}/.bash.local" ]; then
warn "'~/.bash.local' does not exist."
# We must first create the $HOME/.bash.local configuration file
# in order for the brew module to properly install Homebrew.
create_bash_local
fi
# Check if 'brew' is installed
# This step will manually initialize the Homebrew installation
# into the current shell context if it is already installed.
# Otherwise, if 'brew' is not installed, we will install it.
if ! is_brew_installed; then
warn "'brew' is not installed."
install_brew
else
success "'brew' is installed."
fi
if ! cmd_exists "python3"; then
warn "'python3' is not installed."
# Install 'python3' via 'brew' and 'pyenv'
# 'pyenv' is a Python version management tool
# see: https://github.com/pyenv/pyenv
bash "${installer_scripts_path}"/python/pyenv.sh
else
success "'python3' is installed."
fi
# Check if 'rcm' is installed, because it is required for this script to work.
# 'rcm' is a dotfile management tool that is used to symlink files into the home directory.
# see: https://github.com/thoughtbot/rcm
# 'rcm' commands
commands=(
"rcup"
"rcdn"
"lsrc"
)
if ! cmd_exists "${commands[@]}"; then
warn "'rcm' is not installed."
# Install 'rcm' via 'brew'
bash "${installer_scripts_path}"/rcm/rcm.sh
else
success "'rcm' is installed."
fi
# Determine if 'git' is installed
if ! cmd_exists "git"; then
warn "'git' is not installed."
# Install 'git' via 'brew'
brew_install "git"
else
success "'git' is installed."
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check that the 'smu.py' script exists
if [ ! -f "${smu_home_dir}/set-me-up-installer/smu.py" ]; then
error "'smu.py' does not exist."
exit 1
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Pull the latest changes from the 'set-me-up-installer' repository
git -C "${smu_home_dir}"/set-me-up-installer pull origin main --quiet
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
printf "\n"
python3 "${smu_home_dir}"/set-me-up-installer/smu.py "$@"
}
main "$@"