-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·177 lines (144 loc) · 3.99 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
#!/bin/bash
OS=$(awk -F= '/^ID=/ {gsub(/"/, "", $2); print tolower($2)}' /etc/os-release)
export DOTFILES_DIR="$HOME/dotfiles"
export SCRIPTS_DIR="$DOTFILES_DIR/scripts"
cmd_exist() {
command -v $1 >/dev/null 2>&1
}
mkdir -p $HOME/.tmp
# Arguments
declare -A features=(
[TYPE]=${TYPE:-https}
[CARGO]=${CARGO:-false}
[FDFIND]=${FDFIND:-false}
[FISH]=${FISH:-false}
[FORCE]=${FORCE:-false}
[FZF]=${FZF:-false}
[NODE]=${NODE:-false}
[NODE_VERSION]=${NODE_VERSION:-18.16.1}
[NVIM]=${NVIM:-false}
[OHMYBASH]=${OHMYBASH:-false}
[OHMYFISH]=${OHMYFISH:-false}
[OHMYZSH]=${OHMYZSH:-false}
[UNATTENDED]=${UNATTENDED:-false}
[SYSTEM]=${SYSTEM:-false}
[ZSH]=${ZSH:-false}
[CHANGE_SHELL]=${CHANGE_SHELL:-false}
)
for feature_name in "${!features[@]}"; do
export ${feature_name}=${features[$feature_name]}
done
pushd $HOME >/dev/null
print_color() {
declare -A colors=(
['red']='\033[31m'
['green']='\033[0;32m'
)
echo -e "${colors[$1]}$2\033[0m"
}
setup_locale() {
LOCALE=${1:-en_US.UTF-8}
sudo sed -i "s/# $LOCALE UTF-8/$LOCALE UTF-8/" /etc/locale.gen
sudo locale-gen $LOCALE
sudo update-locale LC_ALL=$LOCALE LANG=$LOCALE
source ~/.bashrc
echo "$LOCALE setup complete!"
}
install_package() {
print_color green "Installing the following packages for ${OS^}:"
for pkg in "$@"; do
print_color blue " - $pkg"
done
case $OS in
ubuntu | debian | linuxmint)
sudo apt install -y "$@"
;;
centos)
sudo yum install -y "$@"
;;
arch)
sudo pacman -S --noconfirm "$@"
;;
esac
}
install_essentials() {
print_color green "INSTALLING ESSENTIALS... \n"
if [ "$OS" = "ubuntu" ]; then
setup_locale
fi
if ! cmd_exist python && ! cmd_exist python3 || ! cmd_exist git; then
install_package python3 git
if [ "$OS" = "alpine" ]; then
sudo ln -sf $(which python3) /usr/bin/python
install_package newt >/dev/null
fi
fi
URL="https://github.com/asolopovas/dotfiles.git"
if [ "${features[TYPE]}" = "ssh" ]; then
URL="[email protected]:asolopovas/dotfiles.git"
fi
if [ ! -d $DOTFILES_DIR ]; then
print_color green "DOWNLOADING DOTFILES..."
git clone $URL $DOTFILES_DIR >/dev/null
fi
}
install_essentials
load_script() {
local script_name=$1
local script_path="$SCRIPTS_DIR/install-$script_name.sh"
print_color green "Sourcing $script_path"
[[ -f $script_path ]] && source $script_path
}
# Serialize and export associative array
export features_string=$(declare -p features)
[[ "$UNATTENDED" = false ]] && source $SCRIPTS_DIR/install-menu.sh
echo -e "FEATURE\t\tSTATUS"
separator="------------\t--------"
echo -e $separator
for feature in "${!features[@]}"; do
if [ "${features[$feature]}" = true ]; then
status="ENABLED"
else
status="DISABLED"
fi
printf "%-15s %s\n" "$feature" "$status"
done
echo -e "$separator\n"
source $DOTFILES_DIR/globals.sh
source $SCRIPTS_DIR/default-dirs.sh
if [ "${features[FISH]}" = true ]; then
load_script 'fish'
fi
if [ "${features[CARGO]}" = true ]; then
curl https://sh.rustup.rs -sSf | sh
fi
if [ "${features[FDFIND]}" = true ] && ! cmd_exist fd; then
load_script "fd"
fi
if [ "${features[FZF]}" = true ]; then
load_script "fzf"
fi
if [ "${features[NODE]}" = true ]; then
load_script "node"
fi
if [ "${features[NVIM]}" = true ]; then
load_script "nvim"
fi
if [ "${features[ZSH]}" = true ]; then
print_color green "INSTALLING ZSH..."
install_package zsh >/dev/null
fi
if [ "${features[OHMYFISH]}" = true ]; then
load_script "ohmyfish"
fi
if [ "${features[OHMYZSH]}" = true ]; then
load_script "ohmyzsh"
fi
if [ "${features[OHMYBASH]}" = true ]; then
load_script "ohmybash"
fi
if [ "${features[CHANGE_SHELL]}" = true ] && [ "$UNATTENDED" = false ]; then
print_color green "CHANGING SHELL TO FISH"
chsh -s $(which fish)
fi
popd >/dev/null