setup-buildenv/setup

63 lines
1.5 KiB
Text
Raw Normal View History

2023-11-02 18:30:24 +00:00
#!/bin/bash
COMPILER=$2
SSL=$3
DISTRO=$(grep -E '^NAME=' /etc/os-release |
cut -d'=' -f2 |
tr -d '"')
# Installs a package using the native OS's package manager.
install_pkg() {
case $DISTRO in
2023-11-02 19:10:00 +00:00
"Ubuntu"|"Debian GNU/Linux")
2023-11-02 18:30:24 +00:00
apt install -y $1
2023-11-02 19:21:31 +00:00
[ $? -eq 0 ] || exit 1
2023-11-02 18:30:24 +00:00
;;
2023-11-02 19:10:00 +00:00
"Arch Linux")
2023-11-02 18:30:24 +00:00
pacman -Syu --noconfirm $1
2023-11-02 19:21:31 +00:00
[ $? -eq 0 ] || exit 1
2023-11-02 18:30:24 +00:00
;;
esac
}
install_compiler() {
echo '::group::Setting up a compiler'
case $DISTRO in
2023-11-02 19:10:00 +00:00
"Ubuntu"|"Debian GNU/Linux")
2023-11-02 18:30:24 +00:00
install_pkg build-essential
[ $COMPILER = 'clang' ] && install_pkg clang
CC=gcc
[ $COMPILER = 'clang' ] && CC=clang
;;
2023-11-02 19:10:00 +00:00
"Arch Linux")
2023-11-02 18:30:24 +00:00
install_pkg $COMPILER make
CC=gcc
[ $COMPILER = 'clang' ] && CC=clang
esac
2023-11-02 19:21:31 +00:00
install_pkg git # Everyone has git!
2023-11-02 18:30:24 +00:00
echo '::endgroup::'
}
install_ssl() {
echo '::group::Setting up SSL'
case $DISTRO in
2023-11-02 19:10:00 +00:00
"Ubuntu"|"Debian GNU/Linux")
2023-11-02 18:30:24 +00:00
# Doesn't seem like Debian got LibreSSL
2023-11-02 19:21:31 +00:00
[ $SSL = 'libressl' ] && echo "::error:: LibreSSL is not on Debian"
[ $SSL = 'libressl' ] && exit 1
2023-11-02 18:30:24 +00:00
install_pkg openssl
2023-11-02 19:30:33 +00:00
install_pkg libssl-dev
2023-11-02 18:30:24 +00:00
;;
2023-11-02 19:10:00 +00:00
"Arch Linux")
2023-11-02 18:30:24 +00:00
install_pkg $SSL
esac
echo '::endgroup::'
}
# Install the compiler and SSL
install_compiler
install_ssl
echo "compiler=$CC" >> "$GITHUB_OUTPUT"