-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·217 lines (192 loc) · 6.12 KB
/
build.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
#!/bin/bash
# Define colors and styles
GREEN="\e[32m"
RED="\e[31m"
PINK="\e[35m"
BLUE="\e[34m"
CYAN="\e[36m"
RESET="\e[0m"
BOLD="\e[1m"
UNDERLINE="\e[4m"
# Function to detect the package manager and distribution
detect_distro() {
if command -v dpkg-query &> /dev/null; then
echo "debian"
elif command -v rpm &> /dev/null; then
echo "rpm"
elif command -v pacman &> /dev/null; then
echo "arch"
else
echo "unsupported"
fi
}
detect_nerd_fonts() {
FONT_CHECK=$(fc-list | grep -i "Nerd")
if [ -n "$FONT_CHECK" ]; then
echo -e "${CYAN}Nerd Fonts are installed and available.${RESET}"
else
echo -e "${RED}Nerd Fonts are not installed or not available.${RESET}"
echo -e "\n${RED}${BOLD}Kindly ensure that you have a nerd font installed and enabled in your terminal for LiteFM!${RESET}"
fi
}
# Function to check if a package is installed
check_package_installed() {
local distro="$1"
local package="$2"
case "$distro" in
debian)
dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -c "ok installed"
;;
rpm)
rpm -q "$package" &> /dev/null
;;
arch)
pacman -Q "$package" &> /dev/null
;;
*)
echo -e "${RED}Unsupported package manager.${RESET}"
return 1
;;
esac
}
# Function to install packages based on the distribution
install_packages() {
local distro="$1"
shift
local packages=("$@")
echo -e "${PINK}${BOLD}Installing missing packages:${RESET} ${packages[*]}"
case "$distro" in
debian)
sudo apt-get update
sudo apt-get install -y "${packages[@]}"
;;
rpm)
sudo yum install -y "${packages[@]}"
;;
arch)
sudo pacman -S --needed "${packages[@]}"
;;
*)
echo -e "${RED}Unsupported distribution.${RESET}"
exit 1
;;
esac
}
# Function to detect the display server
detect_display_server() {
if [ -n "$WAYLAND_DISPLAY" ]; then
echo "wayland"
elif [ -n "$DISPLAY" ]; then
echo "x11"
else
echo "unknown"
fi
}
# Title
echo -e "${GREEN}${BOLD}===================="
echo -e " LiteFM "
echo -e "====================${RESET}"
# Detect the distribution
distro=$(detect_distro)
if [ "$distro" == "unsupported" ]; then
echo -e "${RED}${BOLD}Unsupported Linux distribution.${RESET}"
exit 1
fi
echo -e "${PINK}${BOLD}Building for $distro...${RESET}"
# Detect the display server
display_server=$(detect_display_server)
echo -e "${PINK}${BOLD}Detected display server: $display_server${RESET}"
# Define the required packages based on the distribution and display server
required_packages=("libncursesw5-dev" "cmake" "make" "libarchive-dev" "libyaml-dev" "rsync" "pkg-config" "libsdl2-dev" "libsdl2-mixer-dev")
case "$display_server" in
wayland)
required_packages+=("wl-clipboard")
;;
x11)
required_packages+=("xclip")
;;
esac
if [ "$distro" == "rpm" ]; then
required_packages=("ncurses" "cmake" "make" "libarchive" "libyaml" "rsync" "pkg-config" "SDL2-devel" "SDL2_mixer-devel")
elif [ "$distro" == "arch" ]; then
required_packages=("ncurses" "cmake" "make" "libarchive" "libyaml" "rsync" "pkg-config" "sdl2" "sdl2_mixer")
fi
# Check for required packages
missing_packages=()
for package in "${required_packages[@]}"; do
if check_package_installed "$distro" "$package"; then
echo -e "${GREEN}✔ Package $package is already installed.${RESET}"
else
echo -e "${RED}✘ Package $package is missing.${RESET}"
missing_packages+=("$package")
fi
done
if [ ${#missing_packages[@]} -ne 0 ]; then
install_packages "$distro" "${missing_packages[@]}"
else
echo -e "${GREEN}${BOLD}All required packages are already installed.${RESET}"
fi
# Prompt for build type
detect_nerd_fonts
read -p "Enter the type of build (cmake, meson, or make): " build_type
# Set ASan options
export ASAN_OPTIONS=log_path=asan_log.txt
# Build commands
case "$build_type" in
cmake)
echo -e "${CYAN}Running cmake build...${RESET}"
cmake -S . -B build/
cmake --build build/
;;
meson)
echo -e "${CYAN}Running meson build...${RESET}"
meson setup mesbuild
meson compile -C mesbuild
;;
make)
echo -e "${CYAN}Running make build...${RESET}"
make
;;
*)
echo -e "${RED}${BOLD}Invalid build type. Please enter 'cmake', 'meson', or 'make'.${RESET}"
exit 1
;;
esac
# Check if the build was successful
if [ $? -ne 0 ]; then
echo -e "${RED}${BOLD}Build failed.${RESET}"
exit 1
fi
# Copy the man file and gzip it
echo -e "${PINK}${BOLD}============ MAN PAGE =============${RESET}"
read -p "Add manual page? (y/n) " confirm_man
if [ "$confirm_man" == "y" ]; then
sudo cp components/litefm.1 /usr/share/man/man1/
sudo gzip /usr/share/man/man1/litefm.1
fi
# Setup logging
echo -e "${BLUE}${BOLD}=========== LOGGING SETUP =============== ${RESET}"
mkdir -p "$HOME/.cache/litefm/log/"
if [ $? -eq 0 ]; then
echo -e "${BLUE}${BOLD}================ LOGGING DONE ============= ${RESET}"
else
echo -e "${RED}Something went wrong while setting up logging. Exiting with code 1${RESET}"
exit 1
fi
# Create alias in the appropriate shell configuration file
echo -e "${PINK}${BOLD}============= SETTING ALIAS =========${RESET}"
SHELL_NAME=$(basename "$SHELL")
case "$SHELL_NAME" in
bash)
echo "alias lfm='$(pwd)/build/litefm'" >> ~/.bashrc
echo "export ASAN_OPTIONS=log_path=$(pwd)/asan_log.txt " >> ~/.bashrc
;;
zsh)
echo "alias lfm='$(pwd)/build/litefm'" >> ~/.zshrc
echo "export ASAN_OPTIONS=log_path=$(pwd)/memlogs/asan_log.txt " >> ~/.zshrc
;;
*)
echo -e "${RED}Shell $SHELL_NAME not supported for alias creation. Please create the alias manually.${RESET}"
;;
esac
echo -e "${GREEN}${BOLD}Build completed and man page installed. Please restart your terminal or source your rc file to use the litefm command.${RESET}"