-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·228 lines (205 loc) · 7.13 KB
/
init.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
#!/bin/bash
# Source common colors, and symbols
source ./utils.sh
function create_symlink {
echo -e "$INFO Creating symlink for ${COL_CYAN}$1${COL_NC}..."
# Check if a file exists and it is not a symlink
if [ -L "$2" ]; then
echo -e "${INFO} Symlink to the target file already exists"
# Ensure that the symlink is correct
if [ "$(readlink -- "$2")" = "$1" ]; then
echo -e "${TICK} Symlink is correct"
return 0
else
echo -e "${INFO} Symlink is incorrect"
echo -e "${INFO} Removing incorrect symlink"
rm -v "$2"
fi
elif [ -f "$2" ]; then
echo -e "${TICK} Created backup of ${COL_LIGHT_CYAN}$2${COL_NC}: $(mv -v "$2" "$2.bak")"
fi
# Create symlink and check if it was successful
if output=$( ln -sv "$1" "$2" 2>&1); then
echo -e "${TICK} Created symlink: ${output}"
else
echo -e "${CROSS} Failed creating symlink: ${output}"
exit 1
fi
}
function prompt_user {
local message=$1
local default_response="y"
if [ "${SKIP_PROMPTS}" = "y" ]; then
response="${default_response}"
else
echo -en "${message}"
read -r response
fi
}
# Enable user to input -y flag to skip all prompts
while getopts ":y" opt; do
case $opt in
y)
echo -e "${INFO} Skipping all prompts..."
SKIP_PROMPTS="y"
;;
\?)
echo -e "${CROSS} Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Check if script is run by root user, this will be important for installing packages
# via package manager
if [ "$(id -u)" -eq 0 ]; then
SUDO=""
echo -e "${INFO} Script is run by ${COL_CYAN}root${COL_NC} user"
else
echo -e "${INFO} Script is run by ${COL_CYAN}uid=$(id -u)${COL_NC} user"
# If we are not root, we will need to use sudo
if command -v sudo &> /dev/null; then
SUDO="sudo"
else
echo -e "${CROSS} This script requires root privileges or sudo."
exit 1
fi
fi
# Symlink all files in config directory
echo -e "${INFO} Starting symlink process..."
echo "----------------------------------"
create_symlink "$DOTFILES/bash/.bashrc" "$HOME/.bashrc"
create_symlink "$DOTFILES/zsh/.zshrc" "$HOME/.zshrc"
create_symlink "$DOTFILES/tmux/.tmux.conf" "$HOME/.tmux.conf"
create_symlink "$DOTFILES/git/.gitconfig" "$HOME/.gitconfig"
create_symlink "$DOTFILES/bash/.profile" "$HOME/.profile"
create_symlink "$DOTFILES/zsh/.zprofile" "$HOME/.zprofile"
echo -e "\n"
# Locales are required by many programes to work properly
echo -e "${INFO} Checking if ${COL_CYAN}locale${COL_NC} are installed..."
# shellcheck disable=SC1091
source ./zsh/init-scripts/locales.sh
echo -e "${INFO} Checking if ${COL_CYAN}curl${COL_NC} is installed..."
# shellcheck disable=SC1091
source ./zsh/init-scripts/curl.sh
echo -e "${INFO} Checking if ${COL_CYAN}tar${COL_NC} is installed..."
# shellcheck disable=SC1091
source ./zsh/init-scripts/tar.sh
echo -e "${INFO} Checking if ${COL_CYAN}zsh${COL_NC} is installed..."
# shellcheck disable=SC1091
source ./zsh/init-scripts/zsh.sh
# Ensure chsh is installed
echo -e "${INFO} Checking if ${COL_CYAN}chsh${COL_NC} is installed..."
if ! command -v chsh &> /dev/null; then
echo -e "${INFO} chsh command not found, will try to install it..."
if [ "$(uname -s)" = "Linux" ]; then
if command -v apt &> /dev/null; then
if ! ${SUDO} apt install -y passwd; then echo -e "${CROSS} Failed installing passwd"; exit 1; fi
elif command -v dnf &> /dev/null; then
if ! ${SUDO} dnf install -y util-linux-user; then echo -e "${CROSS} Failed installing util-linux-user"; exit 1; fi
else
echo -e "${CROSS} Unsupported package manager"
exit 1
fi
elif [ "$(uname -s)" = "Darwin" ]; then
brew install util-linux
else
echo -e "${CROSS} Unsupported OS: $(uname s)"
exit 1
fi
else
echo -e "${TICK} chsh already installed, skipping..."
fi
echo -e "${INFO} Ensuring that ${COL_CYAN}which${COL_NC} is installed..."
# shellcheck disable=SC1091
source ./zsh/init-scripts/which.sh
# Change default shell to zsh
echo -e "${INFO} Checking ${COL_CYAN}default shell${COL_NC}..."
# shellcheck disable=SC1091
source ./zsh/init-scripts/default_shell.sh
# Ensure tmux is installed
echo -e "${INFO} Checking if ${COL_CYAN}tmux${COL_NC} is installed..."
if ! command -v tmux &> /dev/null; then
echo -e "${INFO} Installing tmux..."
if [ "$(uname -s)" = "Linux" ]; then
if command -v apt &> /dev/null; then
if ! ${SUDO} apt install -y tmux; then echo -e "${CROSS} Failed installing tmux"; exit 1; fi
elif command -v dnf &> /dev/null; then
if ! ${SUDO} dnf install -y tmux; then echo -e "${CROSS} Failed installing tmux"; exit 1; fi
else
echo -e "${CROSS} Unsupported package manager"
exit 1
fi
elif [ "$(uname -s)" = "Darwin" ]; then
brew install tmux
else
echo -e "${CROSS} Unsupported OS: $(uname s)"
exit 1
fi
echo -e "${TICK} tmux installed!"
else
echo -e "${TICK} tmux already installed, skipping..."
fi
# Check if $HOME/.local/bin exists, if not create it
echo -e "${INFO} Checking if ${COL_CYAN}$HOME/.local/bin${COL_NC} exists..."
if [ ! -d "$HOME/.local/bin" ]; then
echo -e "${INFO} ${HOME}/.local/bin doesn't exist. Creating it..."
if output=$(mkdir -vp "$HOME/.local/bin"); then
echo "${output}"
echo -e "${TICK} Successfuly created"
else
echo -e "${CROSS} Failed creating: ${output}"
exit 1
fi
else
echo -e "${TICK} ${HOME}/.local/bin already exists, skipping..."
fi
export PATH="$HOME/.local/bin:$PATH"
prompt_user "Do you want to install additional apps? [y/N]"
case "$response" in
([yY][eE][sS]|[yY])
;;
*)
exit 0
;;
esac
prompt_user "Do you want to install ${COL_CYAN}NVM${COL_NC}? [y/N]"
case "$response" in
([yY][eE][sS]|[yY])
source ./zsh/init-scripts/nvm.sh
install_nvm
;;
*)
echo -e "${INFO} Skipping NVM..."
;;
esac
prompt_user "Do you want to install ${COL_CYAN}nvchad${COL_NC}? [y/N] "
case "$response" in
([yY][eE][sS]|[yY])
# Install clipboard support from neovim
echo -e "${INFO} setting up clipboard for neovim"
source ./zsh/init-scripts/clipboard.sh
echo -e "${INFO} Installing ${COL_CYAN}neovim${COL_NC}..."
source ./zsh/init-scripts/neovim.sh
echo -e "${INFO} Installing ${COL_CYAN}nvchad${COL_NC}..."
source ./zsh/init-scripts/nvchad.sh
;;
*)
echo -e "${INFO} Skipping neovim..."
;;
esac
prompt_user "Do you want to install ${COL_CYAN}kubernetes tools${COL_NC}? [y/N]"
case "$response" in
([yY][eE][sS]|[yY])
echo -e "${INFO} Installing ${COL_CYAN}kubectl${COL_NC}..."
source $DOTFILES/zsh/init-scripts/kubectl.sh
echo -e "${INFO} Installing ${COL_CYAN}helm${COL_NC}..."
source $DOTFILES/zsh/init-scripts/helm.sh
echo -e "${INFO} installing ${COL_CYAN}kubecm${COL_NC}..."
source $DOTFILES/zsh/init-scripts/kubecm.sh
echo -e "${INFO} installing ${COL_CYAN}kubectl krew${COL_NC}"
source $DOTFILES/zsh/init-scripts/krew.sh
;;
*)
echo -e "${INFO} Skipping kubectl..."
;;
esac