Repository navigation
Expand file tree
/
Copy pathinstall
More file actions
executable file
·222 lines (191 loc) · 5.05 KB
/
Copy pathinstall
File metadata and controls
executable file
·222 lines (191 loc) · 5.05 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
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
#!/bin/bash
#
# bootstrap installs things.
DOTFILES_ROOT="$(pwd)"
LINKS_CONF="$DOTFILES_ROOT/links.conf"
# Default flags
DO_SYMLINK=false
DO_HOMEBREW=false
DO_ALL=true
# Process command line arguments
while [ $# -gt 0 ]; do
case "$1" in
--symlink)
DO_SYMLINK=true
DO_ALL=false
;;
--homebrew)
DO_HOMEBREW=true
DO_ALL=false
;;
--help)
echo "Usage: $0 [options]"
echo "Options:"
echo " --symlink Create symlinks from links.conf"
echo " --homebrew Run homebrew installation/update"
echo " --help Show this help message"
echo ""
echo "If no options are specified, all tasks will be run."
echo "If any options are specified, only those tasks will be run."
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
shift
done
# If no specific flags were set, do everything
if [ "$DO_ALL" = true ]; then
DO_SYMLINK=true
DO_HOMEBREW=true
fi
set -e
echo ''
info () {
printf " [ \033[00;34m..\033[0m ] $1\n"
}
user () {
printf "\r [ \033[0;33m?\033[0m ] $1 "
}
success () {
printf "\r\033[2K [ \033[00;32mOK\033[0m ] $1\n"
}
fail () {
printf "\r\033[2K [\033[0;31mFAIL\033[0m] $1\n"
echo ''
exit 1
}
run_for_destination() {
local destination="$1"
shift
if [ "$destination" = "/etc/codex/config.toml" ] && [ "$EUID" -ne 0 ]; then
sudo "$@"
else
"$@"
fi
}
setup_files () {
if [ "$2" = "$HOME/.codex/config.toml" ]; then
chmod 600 "$1"
fi
run_for_destination "$2" mkdir -p "$(dirname "$2")"
run_for_destination "$2" ln -s "$1" "$2"
success "linked $1 to $2"
}
install_homebrew() {
if [[ $(command -v brew) == "" ]]; then
echo "Installing Homebrew.. "
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "Updating Homebrew.. "
brew update
fi
}
symlink_files() {
info 'creating symlinks from links.conf'
if [ ! -f "$LINKS_CONF" ]; then
fail "links.conf not found at $LINKS_CONF"
return
fi
overwrite_all=false
skip_all=false
# Read each line from links.conf
while IFS= read -r line || [ -n "$line" ]; do
# Skip comments and empty lines
if [[ "$line" =~ ^# ]] || [[ -z "${line// }" ]]; then
continue
fi
# Split the line by the first colon
source_path="${line%%:*}"
dest_path="${line#*:}"
# Trim whitespace
source_path=$(echo "$source_path" | xargs)
dest_path=$(echo "$dest_path" | xargs)
# Strip quotes from dest_path if present
dest_path=$(echo "$dest_path" | sed -e 's/^"//' -e 's/"$//')
# Expand environment variables in destination path
eval "dest_path=$dest_path"
# Resolve source path:
# - Entries starting with $HOME should stay home-anchored.
# - Everything else is resolved relative to the dotfiles root.
if [ "${source_path#\$HOME}" != "$source_path" ]; then
source="$HOME${source_path#\$HOME}"
else
source="$DOTFILES_ROOT/$source_path"
fi
# Skip if source doesn't exist
if [ ! -f "$source" ] && [ ! -d "$source" ]; then
fail "Source not found: $source"
continue
fi
if [ -f "$dest_path" ] || [ -d "$dest_path" ] || [ -L "$dest_path" ]; then
# Handle existing files
overwrite=false
skip=false
if [ "$overwrite_all" = "false" ] && [ "$skip_all" = "false" ]; then
user "Already exists: ${dest_path}, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite all?"
if [ -t 0 ]; then
read -r action
else
read -r action < /dev/tty
fi
case "$action" in
o )
overwrite=true;;
O )
overwrite_all=true;;
s )
skip=true;;
S )
skip_all=true;;
* )
skip=true;; # Default to skip
esac
fi
if [ "$overwrite" = "true" ] || [ "$overwrite_all" = "true" ]; then
run_for_destination "$dest_path" rm -rf "$dest_path"
success "removed $dest_path"
if [ "$overwrite_all" = "false" ]; then
echo ''
fi
setup_files "$source" "$dest_path"
if [ "$overwrite_all" = "false" ]; then
echo ''
fi
elif [ "$skip" = "false" ] && [ "$skip_all" = "false" ]; then
setup_files "$source" "$dest_path"
else
success "skipped $dest_path"
if [ "$skip_all" = "false" ]; then
echo ''
fi
fi
else
setup_files "$source" "$dest_path"
fi
done < "$LINKS_CONF"
}
# Run installations based on flags
if [ "$DO_HOMEBREW" = true ]; then
install_homebrew
brew bundle
fi
if [ "$DO_SYMLINK" = true ]; then
symlink_files
fi
# If we are on a mac, lets install and setup homebrew dependencies
if [ "$(uname -s)" == "Darwin" ] && [ "$DO_HOMEBREW" = true ]
then
info "installing dependencies"
if . bin/dot > /tmp/dotfiles-dot 2>&1
then
success "dependencies installed"
else
fail "error installing dependencies"
fi
fi
echo ''
echo ' All installed!'