bunkerweb/tests/linux/Linux.sh

85 lines
2.2 KiB
Bash
Raw Normal View History

2023-10-02 10:05:15 +00:00
#!/bin/bash
2023-06-14 13:14:41 +00:00
# Small code to build and run the tests on Linux with docker
# Check if the package already exists in /tmp/$DISTRO/bunkerweb.deb or /tmp/$DISTRO/bunkerweb.rpm
# Always remove the package before building it
function checkPackage() {
2023-10-02 10:05:15 +00:00
if [ -n "$DISTRO" ]; then
2023-06-14 13:14:41 +00:00
if [ -f "/tmp/$DISTRO/bunkerweb.deb" ]; then
2023-10-02 10:05:15 +00:00
sudo rm -rf /tmp/"$DISTRO"/bunkerweb.deb
2023-06-14 13:14:41 +00:00
fi
if [ -f "/tmp/$DISTRO/bunkerweb.rpm" ]; then
2023-10-02 10:05:15 +00:00
sudo rm -rf /tmp/"$DISTRO"/bunkerweb.rpm
2023-06-14 13:14:41 +00:00
fi
fi
}
# Build the package using the dockerfile
function buildPackage() {
2023-10-02 10:05:15 +00:00
if [ -n "$DISTRO" ]; then
2023-06-14 13:14:41 +00:00
if [ "$DISTRO" = "ubuntu" ]; then
sudo docker build -t linux-ubuntu -f src/linux/Dockerfile-ubuntu .
fi
if [ "$DISTRO" = "debian" ]; then
sudo docker build -t linux-debian -f src/linux/Dockerfile-debian .
fi
if [ "$DISTRO" = "centos" ]; then
sudo docker build -t linux-centos -f src/linux/Dockerfile-centos .
fi
if [ "$DISTRO" = "fedora" ]; then
sudo docker build -t linux-fedora -f src/linux/Dockerfile-fedora .
fi
2024-02-05 09:44:38 +00:00
if [ "$DISTRO" = "rhel" ]; then
sudo docker build -t linux-rhel -f src/linux/Dockerfile-rhel .
fi
if [ "$DISTRO" = "rhel9" ]; then
sudo docker build -t linux-rhel9 -f src/linux/Dockerfile-rhel9 .
2024-02-05 09:44:38 +00:00
fi
2023-06-14 13:14:41 +00:00
fi
}
# Create the container and copy the package to the host
function createContainer() {
2023-10-02 10:05:15 +00:00
if [ -n "$DISTRO" ]; then
2023-06-14 13:14:41 +00:00
if [ "$DISTRO" = "ubuntu" ]; then
sudo docker run -v /tmp/ubuntu:/data linux-ubuntu
fi
if [ "$DISTRO" = "debian" ]; then
sudo docker run -v /tmp/debian:/data linux-debian
fi
if [ "$DISTRO" = "centos" ]; then
sudo docker run -v /tmp/centos:/data linux-centos
fi
if [ "$DISTRO" = "fedora" ]; then
sudo docker run -v /tmp/fedora:/data linux-fedora
fi
2024-02-05 09:44:38 +00:00
if [ "$DISTRO" = "rhel" ]; then
sudo docker run -v /tmp/rhel:/data linux-rhel
fi
if [ "$DISTRO" = "rhel9" ]; then
sudo docker run -v /tmp/rhel9:/data linux-rhel9
2024-02-05 09:44:38 +00:00
fi
2023-06-14 13:14:41 +00:00
fi
}
# Retrieve $DISTRO from the user
function retrieveDistro() {
echo "Which distro do you want to use? (ubuntu, debian, centos, fedora, rhel, rhel9)"
2023-10-02 10:05:15 +00:00
read -r DISTRO
2023-06-14 13:14:41 +00:00
}
# Main function
function main() {
retrieveDistro
checkPackage
buildPackage
createContainer
}
main