forked from ChrisTitusTech/mybash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·194 lines (171 loc) · 5.57 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
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
#!/bin/bash
RC='\e[0m'
RED='\e[31m'
YELLOW='\e[33m'
GREEN='\e[32m'
# Check if the home directory and linuxtoolbox folder exist, create them if they don't
CONFIGDIR="$HOME/.config"
if [[ ! -d "$CONFIGDIR" ]]; then
echo -e "${YELLOW}Creating linuxtoolbox directory: $CONFIGDIR${RC}"
mkdir -p "$CONFIGDIR"
echo -e "${GREEN}linuxtoolbox directory created: $CONFIGDIR${RC}"
fi
if [[ ! -d "$CONFIGDIR/mybash" ]]; then
echo -e "${YELLOW}Cloning mybash repository into: $CONFIGDIR/mybash${RC}"
git clone https://github.com/Critlist/critlistbash.git "$CONFIGDIR/mybash"
if [[ $? -eq 0 ]]; then
echo -e "${GREEN}Successfully cloned mybash repository${RC}"
else
echo -e "${RED}Failed to clone mybash repository${RC}"
exit 1
fi
fi
cd "$CONFIGDIR/mybash"
command_exists() {
command -v $1 >/dev/null 2>&1
}
checkEnv() {
## Check for requirements.
REQUIREMENTS='curl groups sudo'
if ! command_exists ${REQUIREMENTS}; then
echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}"
exit 1
fi
## Check Package Handeler
PACKAGEMANAGER='apt yum dnf pacman zypper'
for pgm in ${PACKAGEMANAGER}; do
if command_exists ${pgm}; then
PACKAGER=${pgm}
echo -e "Using ${pgm}"
fi
done
if [ -z "${PACKAGER}" ]; then
echo -e "${RED}Can't find a supported package manager"
exit 1
fi
## Check if the current directory is writable.
GITPATH="$(dirname "$(realpath "$0")")"
if [[ ! -w ${GITPATH} ]]; then
echo -e "${RED}Can't write to ${GITPATH}${RC}"
exit 1
fi
## Check SuperUser Group
SUPERUSERGROUP='wheel sudo root'
for sug in ${SUPERUSERGROUP}; do
if groups | grep ${sug}; then
SUGROUP=${sug}
echo -e "Super user group ${SUGROUP}"
fi
done
## Check if member of the sudo group.
if ! groups | grep ${SUGROUP} >/dev/null; then
echo -e "${RED}You need to be a member of the sudo group to run me!"
exit 1
fi
}
installDepend() {
## Check for dependencies.
DEPENDENCIES='bash bash-completion tar tree multitail fastfetch tldr trash-cli'
echo -e "${YELLOW}Installing dependencies...${RC}"
if [[ $PACKAGER == "pacman" ]]; then
if ! command_exists yay && ! command_exists paru; then
echo "Installing yay as AUR helper..."
sudo ${PACKAGER} --noconfirm -S base-devel
cd /opt && sudo git clone https://aur.archlinux.org/yay-git.git && sudo chown -R ${USER}:${USER} ./yay-git
cd yay-git && makepkg --noconfirm -si
else
echo "Aur helper already installed"
fi
if command_exists yay; then
AUR_HELPER="yay"
elif command_exists paru; then
AUR_HELPER="paru"
else
echo "No AUR helper found. Please install yay or paru."
exit 1
fi
${AUR_HELPER} --noconfirm -S ${DEPENDENCIES}
else
sudo ${PACKAGER} install -yq ${DEPENDENCIES}
fi
}
installStarship() {
if command_exists starship; then
echo "Starship already installed"
return
fi
if ! curl -sS https://starship.rs/install.sh | sh; then
echo -e "${RED}Something went wrong during starship install!${RC}"
exit 1
fi
if command_exists fzf; then
echo "Fzf already installed"
else
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
fi
}
installZoxide() {
if command_exists zoxide; then
echo "Zoxide already installed"
return
fi
if ! curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh; then
echo -e "${RED}Something went wrong during zoxide install!${RC}"
exit 1
fi
}
install_additional_dependencies() {
case $(command -v apt || command -v zypper || command -v dnf || command -v pacman) in
*apt)
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage
chmod u+x nvim.appimage
./nvim.appimage --appimage-extract
sudo mv squashfs-root /opt/neovim
sudo ln -s /opt/neovim/AppRun /usr/bin/nvim
;;
*zypper)
sudo zypper refresh
sudo zypper install -y neovim
;;
*dnf)
sudo dnf check-update
sudo dnf install -y neovim
;;
*pacman)
sudo pacman -Syu
sudo pacman -S --noconfirm neovim
;;
*)
echo "No supported package manager found. Please install neovim manually."
exit 1
;;
esac
}
linkConfig() {
## Get the correct user home directory.
USER_HOME=$(getent passwd ${SUDO_USER:-$USER} | cut -d: -f6)
## Check if a bashrc file is already there.
OLD_BASHRC="${USER_HOME}/.bashrc"
if [[ -e ${OLD_BASHRC} ]]; then
echo -e "${YELLOW}Moving old bash config file to ${USER_HOME}/.bashrc.bak${RC}"
if ! mv ${OLD_BASHRC} ${USER_HOME}/.bashrc.bak; then
echo -e "${RED}Can't move the old bash config file!${RC}"
exit 1
fi
fi
echo -e "${YELLOW}Linking new bash config file...${RC}"
## Make symbolic link.
ln -svf ${GITPATH}/.bashrc ${USER_HOME}/.bashrc
ln -svf ${GITPATH}/starship.toml ${USER_HOME}/.config/starship.toml
}
checkEnv
installDepend
installStarship
installZoxide
install_additional_dependencies
if linkConfig; then
echo -e "${GREEN}Done!\nrestart your shell to see the changes.${RC}"
else
echo -e "${RED}Something went wrong!${RC}"
fi