-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
158 lines (134 loc) · 4.7 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
#!/bin/sh -e
RC='\033[0m'
RED='\033[31m'
YELLOW='\033[33m'
GREEN='\033[32m'
# Install required packages using apt (for Debian-based distros)
sudo apt update && sudo apt install -y bash bash-completion tar bat tree multitail wget unzip fontconfig curl git lsb-release
# Check if the home directory and linuxtoolbox folder exist, create them if they don't
LINUXTOOLBOXDIR="$HOME/linuxtoolbox"
if [ ! -d "$LINUXTOOLBOXDIR" ]; then
echo "${YELLOW}Creating linuxtoolbox directory: $LINUXTOOLBOXDIR${RC}"
mkdir -p "$LINUXTOOLBOXDIR"
echo "${GREEN}linuxtoolbox directory created: $LINUXTOOLBOXDIR${RC}"
fi
if [ -d "$LINUXTOOLBOXDIR/bash" ]; then rm -rf "$LINUXTOOLBOXDIR/bash"; fi
echo "${YELLOW}Cloning mybash repository into: $LINUXTOOLBOXDIR/bash${RC}"
git clone https://github.com/mews-se/bash "$LINUXTOOLBOXDIR/bash"
if [ $? -eq 0 ]; then
echo "${GREEN}Successfully cloned bash repository${RC}"
else
echo "${RED}Failed to clone bash repository${RC}"
exit 1
fi
# add variables to top level so can easily be accessed by all functions
PACKAGER="apt"
SUDO_CMD="sudo"
SUGROUP="sudo"
GITPATH="git"
cd "$LINUXTOOLBOXDIR/bash" || exit
command_exists() {
command -v "$1" >/dev/null 2>&1
}
checkEnv() {
## Check Package Handler (only apt for Debian-based distros)
PACKAGER="apt"
## Check if sudo is available
if ! command_exists sudo; then
echo "${RED}To run me, you need 'sudo'${RC}"
exit 1
fi
SUDO_CMD="sudo"
echo "Using $SUDO_CMD as privilege escalation software"
## Check if the current directory is writable.
GITPATH=$(dirname "$(realpath "$0")")
if [ ! -w "$GITPATH" ]; then
echo "${RED}Can't write to $GITPATH${RC}"
exit 1
fi
}
# Check to see if the FiraCode Nerd Font is installed (Change this to whatever font you would like)
FONT_NAME="FiraCode Nerd Font"
if fc-list :family | grep -iq "$FONT_NAME"; then
echo "Font '$FONT_NAME' is installed."
else
echo "Installing font '$FONT_NAME'"
# Change this URL to correspond with the correct font
FONT_URL="https://github.com/ryanoasis/nerd-fonts/releases/download/v2.3.3/FiraCode.zip"
FONT_DIR="$HOME/.local/share/fonts"
wget "$FONT_URL" -O "${FONT_NAME}.zip"
unzip "${FONT_NAME}.zip" -d "$FONT_NAME"
mkdir -p "$FONT_DIR"
mv "$FONT_NAME"/*.ttf "$FONT_DIR/"
# Update the font cache
fc-cache -fv
# delete the files created from this
rm -rf "$FONT_NAME" "${FONT_NAME}.zip"
echo "'$FONT_NAME' installed successfully."
fi
installStarship() {
if command_exists starship; then
echo "Starship already installed"
return
fi
if ! curl -sS https://starship.rs/install.sh | sh; then
echo "${RED}Something went wrong during starship install!${RC}"
exit 1
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 "${RED}Something went wrong during zoxide install!${RC}"
exit 1
fi
}
create_fastfetch_config() {
## Get the correct user home directory.
USER_HOME=$(getent passwd "${SUDO_USER:-$USER}" | cut -d: -f6)
if [ ! -d "$USER_HOME/.config/fastfetch" ]; then
mkdir -p "$USER_HOME/.config/fastfetch"
fi
# Check if the fastfetch config file exists
if [ -e "$USER_HOME/.config/fastfetch/config.jsonc" ]; then
rm -f "$USER_HOME/.config/fastfetch/config.jsonc"
fi
ln -svf "$GITPATH/config.jsonc" "$USER_HOME/.config/fastfetch/config.jsonc" || {
echo "${RED}Failed to create symbolic link for fastfetch config${RC}"
exit 1
}
}
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 "${YELLOW}Moving old bash config file to $USER_HOME/.bashrc.bak${RC}"
if ! mv "$OLD_BASHRC" "$USER_HOME/.bashrc.bak"; then
echo "${RED}Can't move the old bash config file!${RC}"
exit 1
fi
fi
echo "${YELLOW}Linking new bash config file...${RC}"
ln -svf "$GITPATH/.bashrc" "$USER_HOME/.bashrc" || {
echo "${RED}Failed to create symbolic link for .bashrc${RC}"
exit 1
}
ln -svf "$GITPATH/starship.toml" "$USER_HOME/.config/starship.toml" || {
echo "${RED}Failed to create symbolic link for starship.toml${RC}"
exit 1
}
}
checkEnv
installStarship
installZoxide
create_fastfetch_config
if linkConfig; then
echo "${GREEN}Done!\nRestart your shell to see the changes.${RC}"
else
echo "${RED}Something went wrong!${RC}"
fi