Skip to content

Commit 472fd6b

Browse files
authored
Merge pull request #9 from bazuin-32/main
Added `install_sfml` function to install sfml from package manager wh…
2 parents ae1b5f4 + 2a3b8df commit 472fd6b

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

install.sh

+37-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
11
#!/usr/bin/env bash
22
compile() {
3-
# Compile and clean using Makefile
3+
# determine if sfml is already installed,
4+
# if its not then install it
5+
ldconfig -p | grep -q libsfml
6+
if [ $? -ne 0 ]; then
7+
install_sfml
8+
fi
9+
10+
# Compile; Makefile is not used for now because
11+
# it is not working as intended
412
echo Compiling visualizer...
5-
make
13+
g++ *.cpp -o sorting-visualizer -lsfml-graphics -lsfml-window -lsfml-system
14+
}
15+
16+
install_sfml() {
17+
# detect the package manager and install sfml
18+
# accordingly
19+
20+
# we need to be root to install packages
21+
if [ "$EUID" -ne 0 ]; then
22+
echo "The SFML library needs to be installed to compile the program."
23+
echo "This script can attempt to install SFML using the system package manager if run as root."
24+
echo "Please run it again as root (sudo ./install.sh) or install SFML yourself."
25+
exit
26+
fi
27+
28+
if command -v pacman &>/dev/null; then
29+
pacman -S sfml
30+
elif command -v apt-get &>/dev/null; then
31+
apt-get install libsfml-dev
32+
elif command -v dnf &>/dev/null; then
33+
dnf install SFML
34+
else
35+
# package manager was not found
36+
# maybe compile sfml ourselves?
37+
echo "Could not install SFML using the system package manager."
38+
echo "Please install SFML yourself and run this script again."
39+
exit
40+
fi
641
}
742

843
main() {

0 commit comments

Comments
 (0)