-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·298 lines (244 loc) · 7.34 KB
/
install
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/sh
#
# install dot files
# Global Variables
: "${XDG_CONFIG_HOME:=${HOME}/.config}"
: "${XDG_CACHE_HOME:=${HOME}/.cache}"
: "${XDG_STATE_HOME:=${HOME}/.local/state}"
: "${XDG_DATA_HOME:=${HOME}/.local/share}"
# Get the full path of the current working directory.
dirname="$(cd "${0%/*}" && printf '%s\n' "${PWD}")"
readonly dirname
symlink_dotfiles() {
# A single operand is used to denote the utility to symlink.
util="${1}"
if [ ! -e "${XDG_CONFIG_HOME}/${util}" ]; then
# TODO: Update the symlink if the location changed.
if [ -d "${dirname}/${util}" ]; then
ln -s "${dirname}/${util}" "${XDG_CONFIG_HOME}/${util}"
fi
fi
}
_zsh() {
# Create the /etc/zshenv file to specify $ZDOTDIR.
printf '%s\n' "Writing to /etc/zshenv using sudo..."
cat <<-'EOF' | sudo tee /etc/zshenv >/dev/null
# /etc/zshenv: system-wide .zshenv file for zsh(1).
#
# This file is sourced on all invocations of the shell.
# If the -f flag is present or if the NO_RCS option is
# set within this file, all other initialization files
# are skipped.
#
# This file should contain commands to set the command
# search path, plus other important environment variables.
# This file should not contain commands that produce
# output or assume the shell is attached to a tty.
#
# Global Order: zshenv, zprofile, zshrc, zlogin
# Use XDG Base Directory Specification
export ZDOTDIR="${XDG_CONFIG_HOME:-${HOME}/.config}/zsh"
EOF
# Setup directories.
mkdir -p "${XDG_CONFIG_HOME}"
mkdir -p "${XDG_CACHE_HOME}/zsh"
mkdir -p "${XDG_STATE_HOME}/zsh"
# Update permissions on existing system files.
if [ -d /usr/local/share/zsh ]; then
chmod 755 /usr/local/share/zsh
chmod 755 /usr/local/share/zsh/site-functions
fi
# Symlink dotfiles to the git repository.
symlink_dotfiles zsh
# Cleanup
# TODO: Preserve existing files and merge/prompt.
# TODO: Set history file to new location before deleting.
rm -f "${HOME}/.zsh_history"
rm -f "${HOME}/.zcompdump"
rm -f "${HOME}/.zprofile"
rm -f "${HOME}/.zshrc"
rm -rf "${HOME}/.zsh_sessions"
rm -rf "${ZDOTDIR}/.zsh_sessions"
}
_vim() {
# Setup directories.
mkdir -p "${XDG_CONFIG_HOME}"
mkdir -p "${XDG_STATE_HOME}/vim"
mkdir -p "${XDG_DATA_HOME}/vim/spell"
mkdir -p "${XDG_DATA_HOME}/vim/view"
mkdir -p "${XDG_CACHE_HOME}/vim/backup"
mkdir -p "${XDG_CACHE_HOME}/vim/swap"
mkdir -p "${XDG_CACHE_HOME}/vim/undo"
# Symlink dotfiles to the git repository.
symlink_dotfiles vim
# Install or update the vim packages.
git submodule update --init --recursive
# Cleanup
rm -f "${HOME}/.viminfo"
}
_nvim() {
# Setup directories.
mkdir -p "${XDG_CONFIG_HOME}"
mkdir -p "${XDG_STATE_HOME}/nvim"
mkdir -p "${XDG_DATA_HOME}/nvim"
mkdir -p "${XDG_CACHE_HOME}/nvim"
# Symlink dotfiles to the git repository.
symlink_dotfiles nvim
}
_git() {
# Setup directories.
mkdir -p "${XDG_CONFIG_HOME}"
# Symlink dotfiles to the git repository.
symlink_dotfiles git
# Migrate existing git configuration.
if [ -f "${HOME}/.gitconfig" ]; then
mv "${HOME}/.gitconfig" "${XDG_CONFIG_HOME}/git/config"
fi
}
_gpg() {
# Migrate existing GnuPG keys, otherwise setup directory.
if [ -d "${HOME}/.gnupg" ]; then
mv "${HOME}/.gnupg" "${XDG_DATA_HOME}/gnupg"
else
mkdir -p "${XDG_DATA_HOME}/gnupg"
chmod 700 "${XDG_DATA_HOME}/gnupg"
fi
# GnuPG requires a special case for symlinking the dotfile.
if [ ! -e "${XDG_DATA_HOME}/gnupg/gpg.conf" ]; then
# TODO: Update the symlink if the location changed.
if [ -f "${dirname}/gnupg/gpg.conf" ]; then
ln -s "${dirname}/gnupg/gpg.conf" \
"${XDG_DATA_HOME}/gnupg/gpg.conf"
fi
fi
}
_go() {
# Setup directories.
mkdir -p "${XDG_CACHE_HOME}/go"
}
_pass() {
# Migrate existing password store, otherwise setup the directory.
if [ -d "${HOME}/.password-store" ]; then
mv "${HOME}/.password-store" "${XDG_DATA_HOME}/pass"
else
mkdir -p "${XDG_DATA_HOME}/pass"
fi
}
_less() {
# Setup directories.
mkdir -p "${XDG_STATE_HOME}/less"
# Preserve existing history file.
if [ -f "${HOME}/.lesshst" ]; then
mv "${HOME}/.lesshst" "${XDG_STATE_HOME}/less/lesshst"
fi
}
_python() {
# Setup directories.
mkdir -p "${XDG_STATE_HOME}/python"
mkdir -p "${XDG_CACHE_HOME}/python"
mkdir -p "${XDG_DATA_HOME}/python"
# Preserve existing history file.
if [ -f "${HOME}/.python_history" ]; then
mv "${HOME}/.python_history" "${XDG_STATE_HOME}/python/history"
fi
}
_tmux() {
# Setup directories.
mkdir -p "${XDG_CONFIG_HOME}"
# Symlink dotfiles to the git repository.
symlink_dotfiles tmux
}
_terraform() {
# Setup directories.
mkdir -p "${XDG_CONFIG_HOME}"
mkdir -p "${XDG_CACHE_HOME}/terraform"
# Symlink dotfiles to the git repository.
symlink_dotfiles terraform
}
_tflint() {
# Setup directories.
mkdir -p "${XDG_CONFIG_HOME}"
# Migrate existing data, otherwise setup the directory.
if [ -d "${HOME}/.tflint.d" ]; then
mv "${HOME}/.tflint.d" "${XDG_DATA_HOME}/tflint"
else
mkdir -p "${XDG_DATA_HOME}/tflint"
fi
# Symlink dotfiles to the git repository.
symlink_dotfiles tflint
}
_yamllint() {
# Setup directories.
mkdir -p "${XDG_CONFIG_HOME}"
# Symlink dotfiles to the git repository.
symlink_dotfiles yamllint
}
_yamlfmt() {
# Setup directories.
mkdir -p "${XDG_CONFIG_HOME}"
# Symlink dotfiles to the git repository.
symlink_dotfiles yamlfmt
}
_ruff() {
# Setup directories.
mkdir -p "${XDG_CACHE_HOME}/ruff"
}
_ghostty() {
# Setup directories.
mkdir -p "${XDG_DATA_HOME}"
# Migrate existing data, otherwise setup the directory.
if [ -d "${HOME}/.terminfo" ]; then
mv "${HOME}/.terminfo" "${XDG_DATA_HOME}/terminfo"
else
mkdir -p "${XDG_DATA_HOME}/terminfo"
fi
}
_bash() {
# Create the /etc/bash.bashrc file to specify Bash
# configuration for interactive shells.
printf '%s\n' "Writing to /etc/bash.bashrc using sudo..."
cat <<-'EOF' | sudo tee /etc/bash.bashrc >/dev/null
# /etc/bash.bashrc: system-wide .bashrc file for the
# Bourne Again shell (bash(1)).
# If not running interactively, don't do anything.
[ -z "$PS1" ] && return
# Use XDG Base Directory Specification
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
if [ -f "${XDG_CONFIG_HOME}/bash/profile" ]; then
. "${XDG_CONFIG_HOME}/bash/profile"
fi
EOF
# Setup directories.
mkdir -p "${XDG_CONFIG_HOME}"
mkdir -p "${XDG_STATE_HOME}/bash"
# Symlink dotfiles to the git repository.
symlink_dotfiles bash
# Preserve existing history file.
if [ -f "${HOME}/.bash_history" ]; then
mv "${HOME}/.bash_history" "${XDG_STATE_HOME}/bash/history"
fi
# Cleanup
# TODO: Preserve existing files and merge/prompt.
# TODO: Set history file to new location before deleting.
rm -f "${HOME}/.bash_logout"
rm -f "${HOME}/.bashrc"
rm -f "${HOME}/.profile"
}
# Specify which dotfiles to install based on the OS.
case "$(uname -s)" in
*Darwin*)
utilities="zsh vim nvim git gpg pass python less tmux terraform tflint yamlfmt yamllint ruff go ghostty"
;;
*)
utilities="bash vim nvim git gpg pass python less tmux terraform tflint yamlfmt yamllint ruff go"
;;
esac
# Configure only the utilities that have been installed.
for util in ${utilities}; do
if command -v "${util}" >/dev/null; then
printf '%s\n' "Installing ${util}..."
"_${util}"
else
printf '%s\n' "Skipping ${util}..."
fi
done