-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
executable file
·130 lines (114 loc) · 3.17 KB
/
setup.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
#!/usr/bin/env bash
trap 'leave_context' INT EXIT
DEFAULT_CONFIGURATION_DIRECTORY="$HOME/src"
DEFAULT_SETUP_DIRECTORY="${DEFAULT_CONFIGURATION_DIRECTORY}/setup"
FORCE="${FORCE:-false}"
clone_dotfiles() {
if test -d "$DEFAULT_SETUP_DIRECTORY" && test "$FORCE" != "true"
then
if $(dirname "$0" | grep -qi -- 'src/setup')
then
return 0
fi
>&2 echo "ERROR: Setup directory already exists at $DEFAULT_SETUP_DIRECTORY. Delete the \
directory and try again."
return 1
fi
if ! test -d "$DEFAULT_SETUP_DIRECTORY"
then
git clone https://github.com/carlosonunez/bash-dotfiles $DEFAULT_SETUP_DIRECTORY
fi
}
set_context() {
pushd $DEFAULT_SETUP_DIRECTORY
}
leave_context() {
if test "${#DIRSTACK[@]}" -gt 1
then
popd &>/dev/null
fi
}
install_homebrew() {
if ! which brew &>/dev/null
then
"$(dirname $0)/install_homebrew.sh"
fi
}
check_for_required_directories() {
for required_directory in "$DEFAULT_CONFIGURATION_DIRECTORY" "$DEFAULT_SETUP_DIRECTORY"
do
if [ ! -d "$required_directory" ]
then
>&2 echo "ERROR: Configuration directory not present: $required_directory"
return 1
fi
done
}
create_symlinks_for_config_files() {
all_bash_files=$(find $(dirname $0) -maxdepth 1 -type f -name ".bash_*" -exec basename {} \;)
for managed_file in $all_bash_files '.vim' '.tmux.conf' '.vimrc'
do
symlink_path="${HOME}/$managed_file"
target_path="${DEFAULT_SETUP_DIRECTORY}/$managed_file"
if test -L "$symlink_path"
then
>&2 echo "INFO: Symlink exists: $symlink_path"
else
/usr/bin/env ln -sf "$target_path" "$symlink_path" || true
fi
done
}
tell_user_what_to_do_next() {
if [ "$?" == "0" ]
then
echo 'Setup complete! Run this to get started: source $HOME/.bash_profile'
fi
}
create_vim_directories() {
for vim_directory in 'swap' 'backup'
do
mkdir -pv "${DEFAULT_SETUP_DIRECTORY}/.vim/$vim_directory"
done
}
create_symlinks_for_tuir() {
mkdir -p ~/.config/tuir &&
ln -sf "${DEFAULT_SETUP_DIRECTORY}/tuir_configs/tuir.cfg" ~/.config/tuir/tuir.cfg || true &&
ln -sf "${DEFAULT_SETUP_DIRECTORY}/tuir_configs/.mailcap" ~/.mailcap || true &&
ln -sf "${DEFAULT_SETUP_DIRECTORY}/.x11run" ~/.x11run || true
}
create_symlinks_for_w3m() {
mkdir -p ~/.w3m &&
ln -sf "${DEFAULT_SETUP_DIRECTORY}/w3m.config" ~/.w3m/config || true
}
create_symlinks_for_rvm() {
ln -sf "${DEFAULT_SETUP_DIRECTORY}/.rvmrc" "$HOME/.rvmrc" || true
}
create_gpg_symlinks() {
test -d "$HOME/.config/gnupg" || mkdir -p "$HOME/.config/gnupg"
ln -sf "${DEFAULT_SETUP_DIRECTORY}/gpg-agent.conf" "$HOME/.config/gnupg/gpg-agent.conf"
}
create_asdf_symlinks() {
ln -sf "${DEFAULT_SETUP_DIRECTORY}/.tool-versions" "$HOME/.tool-versions"
for file in "${DEFAULT_SETUP_DIRECTORY}"/.default-*
do
fname=$(basename "$file")
ln -sf "$file" "${HOME}/$fname"
done
}
if {
clone_dotfiles &&
set_context &&
install_homebrew &&
check_for_required_directories &&
create_symlinks_for_config_files &&
create_vim_directories &&
create_gpg_symlinks &&
create_asdf_symlinks &&
leave_context
}
then
tell_user_what_to_do_next
else
>&2 echo "ERROR: Something went wrong. Fix that thing, then try again."
exit 1
fi