-
Notifications
You must be signed in to change notification settings - Fork 0
/
startup
executable file
·283 lines (249 loc) · 7.74 KB
/
startup
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/bin/bash
# _ _
# ___| |_ __ _ _ __| |_ _ _ _ __
# / __| __/ _` | '__| __| | | | '_ \
# \__ \ || (_| | | | |_| |_| | |_) |
# |___/\__\__,_|_| \__|\__,_| .__/
# |_|
#
# Script : startup
# Location : /usr/local/bin
# Author : Jens Ochmann
# Date : 2024-06-02
# License : MIT
# Description : Install specified applications and run the dispatch script to dispatch files from GitHub repository
# Requires root : Yes
# Colors
NC='\033[0m' # No Color
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[0;37m'
# Ensure root
root() {
if [ "$(id -u)" != "0" ]; then
echo -e "${RED}This script must be run as root${NC}" >&2
exit 1
fi
}
root
# Prompt the user to enter their username
echo
read -p "Please enter your username: " USERNAME
# Define HOME directory based on the entered username
HOME="/home/$USERNAME"
# Check if the entered username exists
if [ ! -d "$HOME" ]; then
echo -e "${RED}Error: User '$USERNAME' does not exist or home directory not found.${NC}"
exit 1
fi
check_command() {
if [ "$?" -ne 0 ]; then
echo -e "${RED}Error: $1 failed.${NC}" >&2
exit 1
fi
}
# Check if the GitHub directory exists
OCHILINUX_DIR="$HOME/github/ochilinux84"
if [ ! -d "$OCHILINUX_DIR" ]; then
echo -e "${BLUE}$OCHILINUX_DIR ${YELLOW}does not exist.${NC}"
echo -e "${YELLOW}Cloning repository from Github...${NC}"
mkdir $HOME/github
cd $HOME/github
sudo apt install git -y
check_command "Installation of git"
sudo -u $USERNAME git clone https://github.com/ochi84/ochilinux84.git
check_command "Clone git repository"
else
echo
echo -e "${YELLOW}Check for GitHub directory | ${GREEN}ok${NC}"
fi
# Load config file
CONFIG_FILE="$OCHILINUX_DIR/sc.conf"
if [[ -f "$CONFIG_FILE" ]]; then
source "$CONFIG_FILE"
else
echo -e "${RED}Error: Configuration file not found.${NC}"
echo -e "${RED}Please ensure the configuration file 'sc.conf' exists at $HOME/.config/${NC}"
exit 1
fi
echo
echo -e "${YELLOW}Starting the installation of applications...${NC}"
# Function to install packages
install_packages() {
local packages=("${@}")
local installed=()
for app in "${packages[@]}"; do
if sudo apt install -y "$app"; then
check_command "Installing package"
echo -e "${GREEN}Installed $app successfully.${NC}"
echo
installed+=("$app") # Add app to the list of successfully installed packages
else
echo -e "${RED}Failed to install $app. Check if the package exists or if there are network issues.${NC}"
echo
fi
done
echo -e "${YELLOW}Successfully installed the following packages:${NC}"
printf '%s\n' "${installed[@]}" # List successfully installed packages
}
# Display installation options with descriptions
echo -e "Select the installation type:"
echo -e "1 - Minimal Install : ${BLUE}Basic utilities like 'mc', 'vim', 'micro', 'ranger'.${NC}"
echo -e "2 - Minimal Plus Install : ${BLUE}Adds more advanced VIM plugins and tools on top of the Minimal Install.${NC}"
echo -e "3 - Expand Install : ${BLUE}Includes all packages from Minimal Plus and additional tools like 'git', 'fzf', 'exa'.${NC}"
echo -e "4 - Full Install : ${BLUE}The most comprehensive installation, including window managers and advanced applications.${NC}"
read -p "Enter your choice (1-4): " choice
# Prepare installation array based on user choice
all_packages=()
case $choice in
1)
all_packages+=("${minimal[@]}")
;;
2)
all_packages+=("${minimal[@]}")
all_packages+=("${minimal_plus[@]}")
;;
3)
all_packages+=("${minimal[@]}")
all_packages+=("${minimal_plus[@]}")
all_packages+=("${expand[@]}")
;;
4)
all_packages+=("${minimal[@]}")
all_packages+=("${minimal_plus[@]}")
all_packages+=("${expand[@]}")
all_packages+=("${full[@]}")
;;
*)
echo "${RED}Invalid choice. Exiting.${NC}"
exit 1
;;
esac
# Install selected packages
install_packages "${all_packages[@]}"
# Install Dispatch-Script
if sudo cp $OCHILINUX_DIR/dispatch /usr/local/bin/ && sudo chmod +x /usr/local/bin/dispatch; then
echo
echo -e "${GREEN}Dispatch successfully installed and made executable.${NC}"
else
echo
echo -e "${RED}Failed to install and set execute permission on dispatch.${NC}"
exit 1
fi
echo
echo -e "${YELLOW}Running dispatch...${NC}"
echo
# Ensure dispatch is executable and available
if /usr/local/bin/dispatch; then
check_command "Execution of dispatch"
echo
echo -e "${GREEN}Dispatch executed successfully.${NC}"
else
echo
echo -e "${RED}Failed to execute dispatch.${NC}"
exit 1
fi
# Install Nerd Fonts
echo
echo -e "${YELLOW}Installing Nerd Fonts...${NC}"
# Define the font directory
FONT_DIR="/usr/share/fonts"
# Source directory for Nerd Fonts
NERDFONTS_DIR="$OCHILINUX_DIR/nerdfonts"
if [ -d "$NERDFONTS_DIR" ]; then
sudo cp -r "$NERDFONTS_DIR" "$FONT_DIR/"
echo -e "${GREEN}Nerd Fonts installed successfully.${NC}"
else
echo -e "${RED}Nerd Fonts directory not found in the repository.${NC}"
exit 1
fi
## Clear and regenerate font cache
#echo "Clearing font cache..."
#rm -rf ~/.cache/fontconfig/*
#
#echo "Rebuilding font cache..."
#fc-cache -fv
#
## Verify the installation
#echo "Verifying installed Nerd Fonts..."
#if fc-list | grep -iq "Nerd Font"; then
# echo -e "${GREEN}Nerd Fonts verification completed successfully.${NC}"
#else
# echo -e "${RED}Nerd Fonts verification failed.${NC}"
# exit 1
#fi
# Install Tilix Schemes
echo
echo -e "${YELLOW}Installing Tilix Schemes...${NC}"
# Define Tilix Schemes directory
TILIX_DIR="$HOME/.config/tilix/"
# Source directory for Tilix Schemes
TILIX_OCHILINUX_DIR="$OCHILINUX_DIR/tilix"
if [ -d "$TILIX_OCHILINUX_DIR" ]; then
cp -r "$TILIX_DIR/schemes" "$TILIX_OCHILINUX_DIR/"
echo -e "${GREEN}Tilix Schemes installed successfully.${NC}"
else
echo -e "${RED}Tilix Schemes directory not found in the repository.${NC}"
exit 1
fi
# Install and activate "Uncomplicated Firewall"
# Check if ufw is installed
if ! dpkg -l | grep -qw ufw; then
echo
echo -e "${YELLOW}Installing ufw (Firewall)...${NC}"
apt update
apt install -y ufw
check_command "Installation of ufw"
else
echo
echo -e "${GREEN}ufw (Firewall) is already installed.${NC}"
fi
# Check if SSH is allowed
if ! ufw status | grep -qw '22/tcp'; then
echo
echo -e "${YELLOW}Allowing SSH connections (port 22)...${NC}"
ufw allow ssh
check_command "Allowing SSH connections"
else
echo
echo -e "${GREEN}SSH connections are already allowed.${NC}"
fi
# Enable ufw if not already enabled
if ! ufw status | grep -qw 'Status: active'; then
echo
echo -e "${YELLOW}Enabling ufw...${NC}"
ufw enable
check_command "Enabling ufw"
else
echo
echo -e "${GREEN}ufw is already enabled.${NC}"
fi
# Ensure ufw is enabled at startup
if ! systemctl is-enabled ufw | grep -qw 'enabled'; then
echo
echo -e "${YELLOW}Enabling ufw to start at boot...${NC}"
echo
systemctl enable ufw
check_command "Enabling ufw to start at boot"
else
echo
fi
# Check ufw status
echo -e "${YELLOW}Checking ufw status...${NC}"
ufw_status=$(ufw status verbose)
echo -e "${GREEN}${ufw_status}${NC}"
# Check systemd service status
echo
echo -e "${YELLOW}Checking systemd service status of ufw...${NC}"
service_status=$(systemctl status ufw)
echo -e "${GREEN}${service_status}${NC}"
echo
echo -e "${GREEN}ufw has been successfully installed and enabled.${NC}"
echo
echo -e "${GREEN}All desired applications have been installed.${NC}"
echo