-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymlink.sh
executable file
·377 lines (298 loc) · 10.9 KB
/
symlink.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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#!/usr/bin/env bash
source "$HOME"/dotfiles/utils.sh
DOTFILES_MAC_DIR=$HOME/dotfiles/mac
function int_signal_handler() {
printf "\nQuitting... You will have to do cleanup manually\n"
exit
}
function setup_int_handler() {
stty -echoctl # hide ^C
trap int_signal_handler INT
}
setup_int_handler
function custom_sudo_password_read_prompt() {
# shellcheck disable=SC2154
echo -en "${colors[BoldGreen]}Enter sudo password:${colors[Reset_Color]}"
sudo --prompt="" --validate
clear
}
custom_sudo_password_read_prompt
sudo_keep_alive
# Create temp directory
mkdir -p "$HOME_DIR"/tmp
# Version of clang-format, should be taken from /usr/bin/clang-format-X.Y,
# same for clang-modernize
printf "${colors[Green]}"
CLANG_VERSION=14.0.0
echo "Clang version symlinked: " $CLANG_VERSION
CLANG_FORMAT_VERSION=$CLANG_VERSION
CLANG_MODERNIZE_VERSION=$CLANG_VERSION
LLDB_VERSION=3.7
echo "LLDB version symlinked: " $LLDB_VERSION
IDEA_VERSION=$(echo "$HOME"/idea-* | awk --field-separator'-' '{print $3}')
echo "IntelliJ version symlinked: " "$IDEA_VERSION"
GOGLAND_VERSION=$(echo "$HOME"/Gogland-* | awk --field-separator'-' '{print $2}')
echo "Gogland version symlinked: " "$GOGLAND_VERSION"
CLION_VERSION=2017.1.1
echo "CLion version symlinked: " $CLION_VERSION
JMETER_VERSION=$(echo "$HOME"/apache-jmeter-* | awk --field-separator'-' '{print $3}')
echo "JMeter version symlinked: " "$JMETER_VERSION"
SWEET_HOME_VERSION=$(echo "$HOME"/SweetHome3D-* | awk --field-separator'-' '{print $2}')
echo "SweetHome3D version symlinked: " "$SWEET_HOME_VERSION"
printf "${colors[Reset_Color]}"
DOTFILES=(profile bashrc zshrc vimrc paths aliases zprofile bash_profile common_profile.sh tmux.conf
gitconfig gitignore gitattributes ghci gvimrc hgrc lldbinit gdbinit xbindkeysrc
fzf.sh psqlrc colordiffrc emacs inputrc agda sudo_as_admin_successful LESS_TERMCAP
jupyter newsboat)
function mac_change_hostname() {
if [ -z "$1" ]; then
echo "Error: Please provide a new hostname."
return 1
fi
# Sanitize input to create a valid LocalHostName.
local sanitized_local_hostname=$(echo "$1" | tr -cd '[:alnum:]-')
# Ensure sanitized LocalHostName is not empty after cleaning
if [ -z "$sanitized_local_hostname" ]; then
echo "Error: The provided hostname contains invalid characters."
return 1
fi
# Fully qualified hostname (e.g., myMac.domain.com)
sudo scutil --set HostName "$1"
# Valid LocalHostName (e.g., myMac.local), sanitize to ensure it's valid.
sudo scutil --set LocalHostName "$sanitized_local_hostname"
# User-friendly computer name (e.g., myMac)
sudo scutil --set ComputerName "$1"
print_success_message "Hostname changed to: $1"
}
function gcc_symlink() {
# these are symlinks, so we can delete these safely
sudo rm --recursive --force /usr/bin/{gcc,g++}
sudo ln -s gcc-12 /usr/bin/gcc
sudo ln -s g++-12 /usr/bin/g++
}
function mac_symlink() {
ln -sf ~/dotfiles/mac/sleep.sh ~/.sleep
ln -sf ~/dotfiles/mac/wakeup.sh ~/.wakeup
function create_symlink_delete_before() {
local to="$1"
local from="$2"
if [[ -L "$from" ]]; then
printf "symlink '%s' exists, removing\n" "$from"
rm --recursive --force "$from"
fi
ln -s "$to" "$from"
}
# create_symlink_delete_before \
# "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format"
# create_symlink_delete_before \
# "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"
# create_symlink_delete_before \
# "$(brew --prefix llvm)/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements"
# iTerm2 config
ln -sf "${DOTFILES_DIR}"/mac/com.googlecode.iterm2.plist \
~/Library/Preferences/com.googlecode.iterm2.plist
# Transmission
"$HOME/dotfiles/mac/transmission.sh"
# ln -sf org.m0k.transmission.plist ~/Library/Preferences/
# Karabiner config
ln -fs "$DOTFILES_MAC_DIR"/karabiner ~/.config/
# TextMate
sudo rm --recursive --force /usr/local/bin/mate
sudo ln -fs /Applications/TextMate.app/Contents/MacOS/mate /usr/local/bin/mate
# VLC
mkdir -p ~/Library/Preferences/org.videolan.vlc
rm --recursive --force ~/Library/Preferences/org.videolan.vlc/vlcrc
cp --recursive --force "$HOME/dotfiles/vlcrc" ~/Library/Preferences/org.videolan.vlc/vlcrc
# echo "NOTE: When updating preferences, VLC doesn't modify the existing vlcrc, instead it deletes the last and creates a new one. Instead of symlinking, the ~/dotfiles/vlcrc has been copied"
[ -d "$HOME/scripts" ] && ln -fs ~/scripts/Chrome\ Debugger.app /Applications/
}
# Fedora regular updates
function fedora_regular_updates() {
sudo dnf install --assumeyes dnf-automatic
sudo systemctl enable dnf-automatic.timer && systemctl start dnf-automatic.timer
}
# Fedora upgrade
function fedora_system_upgrade() {
sudo dnf install --assumeyes python3-dnf-plugin-system-upgrade
sudo dnf system-upgrade download --refresh --releasever=26
sudo dnf system-upgrade reboot
}
function main() {
# Symlink the files in the current directory with corresponding dotfiles in
# the home directory
for f in "${DOTFILES[@]}"; do
rm -f ~/."$f"
ln -sf ~/dotfiles/"$f" ~/."$f" >/dev/null
done
# Terminator
mkdir -p ~/.config/terminator
ln -fs "${DOTFILES_DIR}"/terminator/config ~/.config/terminator/config
# irssi
mkdir -p ~/.irssi
ln -fs "${DOTFILES_DIR}"/irssi.config ~/.irssi/config
# Alacritty
mkdir -p ~/.config/alacritty
ln -fs "${DOTFILES_DIR}"/alacritty.yml ~/.config/alacritty/alacritty.yml
# dunst (notifications)
mkdir -p ~/.config/dunst
ln -fs "${DOTFILES_DIR}"/dunstrc ~/.config/dunst/dunstrc
# pgcli
mkdir -p ~/.config/pgcli
ln -fs "${DOTFILES_DIR}"/pgcli ~/.config/pgcli/config
# htop
mkdir -p ~/.config/htop
ln -fs "${DOTFILES_DIR}"/htoprc ~/.config/htop/
# cabal
mkdir -p ~/.cabal
ln -fs "${DOTFILES_DIR}"/cabal.config ~/.cabal/config
# i3-wm
I3WM_DIR=~/.config/i3/
if ! [[ -f $I3WM_DIR ]]; then
mkdir -p $I3WM_DIR
fi
ln -fs "${DOTFILES_DIR}"/i3/i3.config ~/.config/i3/config
ln -fs "${DOTFILES_DIR}"/i3/i3status.config ~/.config/i3/i3status.config
# Redshift
if [[ ! -e ~/.config/redshift.conf ]]; then
mkdir -p ~/.config
ln -sf "${DOTFILES_DIR}"/redshift.conf ~/.config/redshift.conf
fi
# MIME types
MIME_FILE=$HOME/.config/mimeapps.list
if [ -e ~/.ssh/id_rsa ]; then
rm -f "$MIME_FILE"
fi
ln -fs "${DOTFILES_DIR}"/config/mimeapps.list "$MIME_FILE"
# SSH config
ln -fs "${DOTFILES_DIR}"/sshconfig ~/.ssh/config
# ~/scripts directory
function setup_scripts() {
if [ ! -d "scripts" ]; then
git clone git@github.com:antoni/scripts.git
fi
ln -fs "${DOTFILES_DIR}"/scripts ~/scripts
# Screenshots
sudo_exec ln -fs "$HOME"/scripts/st.sh /bin/st
}
# .ghci access
chmod g-w ~/.ghci
# /usr/local/bin symlinks
# Chrome
sudo_exec ln -fs /usr/bin/google-chrome-stable /usr/local/bin/g
# Firefox
# sudo_exec ln -fs /usr/bin/firefox /usr/local/bin/f
sudo_exec ln -fs "$HOME"/firefox/firefox /usr/local/bin/f
# Eclipse
sudo_exec ln -fs ~"$HOME_DIR"/eclipse/eclipse /usr/local/bin/eclipse
# clang
# sudo_exec ln -fs /usr/bin/clang-$CLANG_VERSION /usr/local/bin/clang
# sudo_exec ln -fs /usr/bin/clang++-$CLANG_VERSION /usr/local/bin/clang++
# clang-format
# sudo_exec ln -fs /usr/bin/clang-format-$CLANG_FORMAT_VERSION /usr/local/bin/clang-format
# clang-modernize
# sudo_exec ln -fs /usr/bin/clang-modernize-$CLANG_MODERNIZE_VERSION /usr/local/bin/clang-modernize
# adb
sudo_exec ln -fs "$HOME_DIR"/Android/Sdk/platform-tools/adb /usr/local/bin/adb
# python
sudo_exec ln -fs "$(which python3)" /usr/local/bin/python
# IDEA
# sudo_exec mkdir -p /etc/sysctl.d
# sudo_exec ln -fs "${DOTFILES_DIR}"/intellij/idea_sysctl.conf /etc/sysctl.d/idea_sysctl.conf
# sudo_exec sysctl -p --system
# Global aliases
case "$(uname -s)" in
Darwin)
mac_symlink
;;
Linux)
sudo_exec mkdir -p /etc/profile.d
sudo_exec ln -fs "${DOTFILES_DIR}"/global_aliases /etc/profile.d/global_aliases.sh
if [[ -n "$IS_WSL" ]]; then
function replace_notepad_plus_plus_settings() {
local -r target_path="/mnt/c/Users/""${WINDOWS_USERNAME}""/AppData/Roaming/Notepad++/config.xml"
printf "Replacing Notepad++ settings at: '%s'\n" "$target_path"
envsubst <windows/notepad_plus_plus_settings.template.xml >"$target_path"
}
replace_notepad_plus_plus_settings
function symlink_wsl_conf() {
sudo ln -sf "${DOTFILES_DIR}"/wsl.conf /etc/wsl.conf
}
symlink_wsl_conf
else
function linux_brightness_settings() {
sudo cp brightness.sh /root/
sudo sh -c 'echo "$USER $(hostname) = NOPASSWD: /root/brightness.sh" >> /etc/sudoers'
}
linux_brightness_settings
function linux_xrdb() {
# Xrdb merge
XRES_FILE=Xresources.solarized
xrdb "${DOTFILES_DIR}"/${XRES_FILE}
ln -sf "${DOTFILES_DIR}"/${XRES_FILE} ~/.Xresources
}
linux_xrdb
fi
;;
CYGWIN* | MINGW32* | MSYS* | MINGW*)
# Note: put only non-WSL things here
;;
*)
# See: https://stackoverflow.com/a/27776822/963881
;;
esac
# lldb
sudo_exec ln -fs /usr/bin/lldb-$LLDB_VERSION /usr/local/bin/lldb
# IDEA
sudo_exec ln -fs "$HOME_DIR"/idea-I?-"$IDEA_VERSION"/bin/idea.sh /usr/local/bin/idea
# Clion
sudo_exec ln -fs "$HOME_DIR"/clion-$CLION_VERSION/bin/clion.sh /usr/local/bin/clion
# Gogland
sudo_exec ln -fs "$HOME_DIR"/Gogland-"$GOGLAND_VERSION"/bin/gogland.sh /usr/local/bin/gogland
# JMeter
sudo_exec ln -fs "$HOME_DIR"/apache-jmeter-"$JMETER_VERSION"/bin/jmeter /usr/local/bin/jmeter
# Robo 3T
sudo_exec ln -fs "$HOME_DIR"/robo3t-*/bin/robo3t /usr/local/bin/robo3t
# SweetHome3D
sudo_exec ln -fs "$HOME_DIR"/SweetHome3D-"$SWEET_HOME_VERSION"/SweetHome3D /usr/local/bin/sweethome
# Sublime 3
if [ -e "$HOME"/sublime_text_3 ]; then
sudo_exec ln -fs "$HOME"/sublime_text_3/sublime_text /usr/local/bin/sublime
fi
if [ -e "$HOME"/android-studio ]; then
sudo_exec ln -fs "$HOME"/android-studio/bin/studio.sh /usr/local//bin/astudio
fi
# Vim
# (Re)install vim-plug
curl -sfLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# Hostname
function setup_hostname() {
if [ "${OSTYPE//[0-9.]/}" == "darwin" ]; then
mac_change_hostname "$HOSTNAME"
else
sudo hostnamectl set-hostname "$HOSTNAME"
print_success_message "Hostname changed to: $HOSTNAME"
fi
}
setup_hostname
# Midnight Commander
rm -f ~/.config/mc/* && mkdir -p ~/.config/mc/
ln -fs "$DOTFILES_DIR"/mc/ini ~/.config/mc/
# Atom
mkdir -p "$HOME"/.atom
pushd atom &>/dev/null || exit 1
for atom in *; do
rm -f "$HOME"/.atom/"$atom"
ln -fs ~/dotfiles/atom/"$atom" "$HOME"/.atom/"$atom"
done
popd &>/dev/null || exit 1
print_success_message "Successfully symlinked all files"
function find_broken_symlinks() {
printf "Looking for broken symlinks\n"
sudo find ~ -maxdepth 3 -type l ! -exec test -e {} \; -print
sudo find /usr/bin -type l ! -exec test -e {} \; -print
sudo find /usr/local/bin -type l ! -exec test -e {} \; -print
}
find_broken_symlinks
}
main