-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_bootstrap.sh
More file actions
executable file
·158 lines (122 loc) · 4.75 KB
/
Copy path_bootstrap.sh
File metadata and controls
executable file
·158 lines (122 loc) · 4.75 KB
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
#!/usr/bin/env bash
#
# Automatically bootstrap your system with dotfiles, package installation, and system configuration.
#
set -euo pipefail
DOTFILES_LOCATION="${DOTFILES_LOCATION:-$HOME/src/dotfiles}"
DOTFILES_INSTALL="${DOTFILES_INSTALL:-prompt}"
DOTFILES_RESTORE="${DOTFILES_RESTORE:-prompt}"
DOTFILES_CONFIGURE="${DOTFILES_CONFIGURE:-prompt}"
OS_NAME=$(uname -s)
####################################################################################################
# UTILITIES #
####################################################################################################
function print_line_delimiter() {
local width=${COLUMNS:-80}
if [ -z "${COLUMNS:-}" ] && command -v tput >/dev/null 2>&1; then
width=$(tput cols 2>/dev/null || echo 80)
fi
printf '%*s\n' "$width" '' | tr ' ' '='
}
function prompt_yes_no() {
local message=$1
local response
if [ -r /dev/tty ]; then
read -r -e -p "[y/N] ${message}" response </dev/tty
else
read -r -e -p "[y/N] ${message}" response
fi
if [[ "$response" == [Yy]* ]]; then
return 0
else
return 1
fi
}
function should_run_step() {
local value=$1
local message=$2
case "$value" in
1 | true | yes | y) return 0 ;;
0 | false | no | n) return 1 ;;
prompt) prompt_yes_no "$message" ;;
*)
echo "[ERROR] Unsupported value '${value}'. Use 1, 0, or prompt."
exit 1
;;
esac
}
function copy_public_key() {
local public_key=$1
if command -v pbcopy >/dev/null 2>&1; then
pbcopy <"$public_key"
echo "[INFO] ${public_key} has been copied to the clipboard..."
elif command -v xclip >/dev/null 2>&1; then
xclip -selection clipboard <"$public_key"
echo "[INFO] ${public_key} has been copied to the clipboard..."
else
echo "[INFO] Clipboard utility unavailable. Public key:"
cat "$public_key"
fi
}
function ensure_macos_developer_tools() {
if [ "$OS_NAME" != 'Darwin' ] || xcode-select -p >/dev/null 2>&1; then
return
fi
echo "[ERROR] macOS Command Line Tools are required before bootstrapping dotfiles."
echo "[INFO] They provide git and the build tools used by Homebrew."
if prompt_yes_no "Open Apple's Command Line Tools installer now? "; then
xcode-select --install || true
echo "[INFO] After the installation finishes, rerun _bootstrap.sh."
else
echo "[INFO] Install them later with: xcode-select --install"
fi
exit 1
}
####################################################################################################
# ENTRYPOINT #
####################################################################################################
print_line_delimiter
cat <<EOF
USAGE
/bin/bash -c "\$(curl -fsSL https://github.com/cmpadden/dotfiles/raw/refs/heads/main/_bootstrap.sh)"
CONFIGURATION
Environment variables can be overwritten for desired behavior:
DOTFILES_LOCATION - location where dotfiles are to be stored (default: ~/src/dotfiles)
DOTFILES_INSTALL - install applications and packages: 1, 0, or prompt (default: prompt)
DOTFILES_RESTORE - whether to restore dotfiles via \`stow\`: 1, 0, or prompt (default: prompt)
DOTFILES_CONFIGURE - automatically configure system-wide settings: 1, 0, or prompt (default: prompt)
CURRENT CONFIGURATION VALUES
DOTFILES_LOCATION=$DOTFILES_LOCATION
DOTFILES_INSTALL=$DOTFILES_INSTALL
DOTFILES_RESTORE=$DOTFILES_RESTORE
DOTFILES_CONFIGURE=$DOTFILES_CONFIGURE
EOF
ensure_macos_developer_tools
if ! command -v git >/dev/null 2>&1; then
echo "Git is not available on this system. Aborting..."
exit 1
fi
TARGET_SSH_KEY="${TARGET_SSH_KEY:-$HOME/.ssh/id_ed25519}"
if [ -f "$TARGET_SSH_KEY" ]; then
echo "[INFO] SSH key ${TARGET_SSH_KEY} already exists; skipping key generation..."
else
mkdir -p "$(dirname "$TARGET_SSH_KEY")"
read -r -p "Enter e-mail address for \`ssh-keygen\`: " email </dev/tty
ssh-keygen -t ed25519 -C "$email" -f "$TARGET_SSH_KEY"
fi
copy_public_key "${TARGET_SSH_KEY}.pub"
if [ ! -d "$DOTFILES_LOCATION" ]; then
git clone git@github.com:cmpadden/dotfiles.git "$DOTFILES_LOCATION"
else
echo "[INFO] directory $DOTFILES_LOCATION already exists. Skipping Git clone..."
fi
pushd "$DOTFILES_LOCATION" >/dev/null || exit
if should_run_step "$DOTFILES_INSTALL" "Install system packages and applications?"; then
./_install.sh
fi
if should_run_step "$DOTFILES_RESTORE" "Restore configuration files?"; then
./_restore.sh
fi
if should_run_step "$DOTFILES_CONFIGURE" "Set system settings?"; then
./_configure.sh
fi