|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# exit when any command fails on CI |
| 3 | +# Exit when any command fails on CI |
4 | 4 | if [[ ! -z "$CI" ]]; then |
5 | | - set -e |
| 5 | + set -e |
6 | 6 | fi |
7 | 7 |
|
8 | 8 | if [[ $EUID -ne 0 ]]; then |
9 | | - echo "This script must be run as root" |
10 | | - exit 1 |
| 9 | + echo "This script must be run as root" |
| 10 | + exit 1 |
11 | 11 | fi |
12 | 12 |
|
13 | | -alias apt='apt --option="APT::Acquire::Retries=3"' |
14 | | -apt update |
15 | | -apt install --yes lsb-release g++ make libavcodec-extra libglu1-mesa libegl1 libxkbcommon-x11-dev libxcb-keysyms1 libxcb-image0 libxcb-icccm4 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcomposite-dev libxtst6 libnss3 libxcb-cursor0 |
16 | | -if [[ -z "$DISPLAY" ]]; then |
17 | | - apt install --yes xvfb |
18 | | -fi |
19 | | - |
20 | | -UBUNTU_VERSION=$(lsb_release -rs) |
21 | | -if [[ $UBUNTU_VERSION == "22.04" || $UBUNTU_VERSION == "24.04" ]]; then |
22 | | - apt install --yes ffmpeg |
| 13 | +# Detect the operating system |
| 14 | +if [ -f /etc/os-release ]; then |
| 15 | + . /etc/os-release |
| 16 | + OS=$ID |
| 17 | + VERSION_ID=$VERSION_ID |
23 | 18 | else |
24 | | - echo "Unsupported Linux version: dependencies may not be completely installed. Only the two latest Ubuntu LTS are supported." |
| 19 | + echo "Cannot determine the operating system." |
| 20 | + exit 1 |
25 | 21 | fi |
| 22 | + |
| 23 | +# Function to install runtime dependencies on Ubuntu |
| 24 | +install_ubuntu_runtime_packages() { |
| 25 | + alias apt='apt --option="APT::Acquire::Retries=3"' |
| 26 | + apt update |
| 27 | + apt install --yes g++ make libavcodec-extra libglu1-mesa libegl1 \ |
| 28 | + libxkbcommon-x11-dev libxcb-keysyms1 libxcb-image0 libxcb-icccm4 libxcb-randr0 \ |
| 29 | + libxcb-render-util0 libxcb-xinerama0 libxcomposite-dev libxtst6 libnss3 libxcb-cursor0 |
| 30 | + |
| 31 | + if [[ -z "$DISPLAY" ]]; then |
| 32 | + apt install --yes xvfb |
| 33 | + fi |
| 34 | + |
| 35 | + if [[ $VERSION_ID == "22.04" || $VERSION_ID == "24.04" ]]; then |
| 36 | + apt install --yes ffmpeg |
| 37 | + else |
| 38 | + echo "Unsupported Linux version: dependencies may not be completely installed. Only the two latest Ubuntu LTS are supported." |
| 39 | + fi |
| 40 | +} |
| 41 | + |
| 42 | +# Function to install runtime dependencies on Fedora |
| 43 | +install_fedora_runtime_packages() { |
| 44 | + dnf install -y gcc-c++ make mesa-libGLU libEGL \ |
| 45 | + xkeyboard-config libxcb libXcomposite libXtst nss xcb-util xcb-util-image \ |
| 46 | + xcb-util-keysyms xcb-util-renderutil xcb-util-wm xcb-util-cursor \ |
| 47 | + |
| 48 | + if [[ -z "$DISPLAY" ]]; then |
| 49 | + dnf install -y xorg-x11-server-Xvfb |
| 50 | + fi |
| 51 | + |
| 52 | + # Install ffmpeg (with non-free codecs) |
| 53 | + # Enable RPMFusion |
| 54 | + dnf -y install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm |
| 55 | + if dnf list installed ffmpeg-free &> /dev/null; then |
| 56 | + dnf swap -y ffmpeg-free ffmpeg --allowerasing |
| 57 | + else |
| 58 | + dnf install -y ffmpeg |
| 59 | + fi |
| 60 | + |
| 61 | + echo "WARNING: Fedora is not an officially supported OS! Dependencies may not be completely installed. Only the two latest Ubuntu LTS are supported." |
| 62 | +} |
| 63 | + |
| 64 | +# Determine the operating system and call the appropriate function |
| 65 | +case "$OS" in |
| 66 | + ubuntu) |
| 67 | + install_ubuntu_runtime_packages |
| 68 | + ;; |
| 69 | + fedora) |
| 70 | + install_fedora_runtime_packages |
| 71 | + ;; |
| 72 | + *) |
| 73 | + echo "Unsupported operating system: $OS" |
| 74 | + exit 1 |
| 75 | + ;; |
| 76 | +esac |
0 commit comments