xref: /freebsd/sys/contrib/openzfs/.github/workflows/scripts/qemu-3-deps.sh (revision ac77b2621508c6a50ab01d07fe8d43795d908f05)
1#!/usr/bin/env bash
2
3######################################################################
4# 3) install dependencies for compiling and loading
5######################################################################
6
7set -eu
8
9function archlinux() {
10  echo "##[group]Running pacman -Syu"
11  sudo btrfs filesystem resize max /
12  sudo pacman -Syu --noconfirm
13  echo "##[endgroup]"
14
15  echo "##[group]Install Development Tools"
16  sudo pacman -Sy --noconfirm base-devel bc cpio dhclient dkms fakeroot \
17    fio gdb inetutils jq less linux linux-headers lsscsi nfs-utils parted \
18    pax perf python-packaging python-setuptools qemu-guest-agent ksh samba \
19    sysstat rng-tools rsync wget xxhash
20  echo "##[endgroup]"
21}
22
23function debian() {
24  export DEBIAN_FRONTEND="noninteractive"
25
26  echo "##[group]Running apt-get update+upgrade"
27  sudo apt-get update -y
28  sudo apt-get upgrade -y
29  echo "##[endgroup]"
30
31  echo "##[group]Install Development Tools"
32  sudo apt-get install -y \
33    acl alien attr autoconf bc cpio curl dbench dh-python dkms fakeroot \
34    fio gdb gdebi git ksh lcov isc-dhcp-client jq libacl1-dev libaio-dev \
35    libattr1-dev libblkid-dev libcurl4-openssl-dev libdevmapper-dev libelf-dev \
36    libffi-dev libmount-dev libpam0g-dev libselinux-dev libssl-dev libtool \
37    libtool-bin libudev-dev libunwind-dev linux-headers-$(uname -r) \
38    lsscsi nfs-kernel-server pamtester parted python3 python3-all-dev \
39    python3-cffi python3-dev python3-distlib python3-packaging \
40    python3-setuptools python3-sphinx qemu-guest-agent rng-tools rpm2cpio \
41    rsync samba sysstat uuid-dev watchdog wget xfslibs-dev  xxhash zlib1g-dev
42  echo "##[endgroup]"
43}
44
45function freebsd() {
46  export ASSUME_ALWAYS_YES="YES"
47
48  echo "##[group]Install Development Tools"
49  sudo pkg install -y autoconf automake autotools base64 checkbashisms fio \
50    gdb gettext gettext-runtime git gmake gsed jq ksh93 lcov libtool lscpu \
51    pkgconf python python3 pamtester pamtester qemu-guest-agent rsync xxhash
52  sudo pkg install -xy \
53    '^samba4[[:digit:]]+$' \
54    '^py3[[:digit:]]+-cffi$' \
55    '^py3[[:digit:]]+-sysctl$' \
56    '^py3[[:digit:]]+-packaging$'
57  echo "##[endgroup]"
58}
59
60# common packages for: almalinux, centos, redhat
61function rhel() {
62  echo "##[group]Running dnf update"
63  echo "max_parallel_downloads=10" | sudo -E tee -a /etc/dnf/dnf.conf
64  sudo dnf clean all
65  sudo dnf update -y --setopt=fastestmirror=1 --refresh
66  echo "##[endgroup]"
67
68  echo "##[group]Install Development Tools"
69  sudo dnf group install -y "Development Tools"
70  sudo dnf install -y \
71    acl attr bc bzip2 curl dbench dkms elfutils-libelf-devel fio gdb git \
72    jq kernel-rpm-macros ksh libacl-devel libaio-devel libargon2-devel \
73    libattr-devel libblkid-devel libcurl-devel libffi-devel ncompress \
74    libselinux-devel libtirpc-devel libtool libudev-devel libuuid-devel \
75    lsscsi mdadm nfs-utils openssl-devel pam-devel pamtester parted perf \
76    python3 python3-cffi python3-devel python3-packaging kernel-devel \
77    python3-setuptools qemu-guest-agent rng-tools rpcgen rpm-build rsync \
78    samba sysstat systemd watchdog wget xfsprogs-devel xxhash zlib-devel
79  echo "##[endgroup]"
80}
81
82function tumbleweed() {
83  echo "##[group]Running zypper is TODO!"
84  sleep 23456
85  echo "##[endgroup]"
86}
87
88# Install dependencies
89case "$1" in
90  almalinux8)
91    echo "##[group]Enable epel and powertools repositories"
92    sudo dnf config-manager -y --set-enabled powertools
93    sudo dnf install -y epel-release
94    echo "##[endgroup]"
95    rhel
96    echo "##[group]Install kernel-abi-whitelists"
97    sudo dnf install -y kernel-abi-whitelists
98    echo "##[endgroup]"
99    ;;
100  almalinux9|centos-stream9)
101    echo "##[group]Enable epel and crb repositories"
102    sudo dnf config-manager -y --set-enabled crb
103    sudo dnf install -y epel-release
104    echo "##[endgroup]"
105    rhel
106    echo "##[group]Install kernel-abi-stablelists"
107    sudo dnf install -y kernel-abi-stablelists
108    echo "##[endgroup]"
109    ;;
110  archlinux)
111    archlinux
112    ;;
113  debian*)
114    debian
115    echo "##[group]Install Debian specific"
116    sudo apt-get install -yq linux-perf dh-sequence-dkms
117    echo "##[endgroup]"
118    ;;
119  fedora*)
120    rhel
121    ;;
122  freebsd*)
123    freebsd
124    ;;
125  tumbleweed)
126    tumbleweed
127    ;;
128  ubuntu*)
129    debian
130    echo "##[group]Install Ubuntu specific"
131    sudo apt-get install -yq linux-tools-common libtirpc-dev \
132      linux-modules-extra-$(uname -r)
133    if [ "$1" != "ubuntu20" ]; then
134      sudo apt-get install -yq dh-sequence-dkms
135    fi
136    echo "##[endgroup]"
137    echo "##[group]Delete Ubuntu OpenZFS modules"
138    for i in $(find /lib/modules -name zfs -type d); do sudo rm -rvf $i; done
139    echo "##[endgroup]"
140    ;;
141esac
142
143# This script is used for checkstyle + zloop deps also.
144# Install only the needed packages and exit - when used this way.
145test -z "${ONLY_DEPS:-}" || exit 0
146
147# Start services
148echo "##[group]Enable services"
149case "$1" in
150  freebsd*)
151    # add virtio things
152    echo 'virtio_load="YES"' | sudo -E tee -a /boot/loader.conf
153    for i in balloon blk console random scsi; do
154      echo "virtio_${i}_load=\"YES\"" | sudo -E tee -a /boot/loader.conf
155    done
156    echo "fdescfs /dev/fd fdescfs rw 0 0" | sudo -E tee -a /etc/fstab
157    sudo -E mount /dev/fd
158    sudo -E touch /etc/zfs/exports
159    sudo -E sysrc mountd_flags="/etc/zfs/exports"
160    echo '[global]' | sudo -E tee /usr/local/etc/smb4.conf >/dev/null
161    sudo -E service nfsd enable
162    sudo -E service qemu-guest-agent enable
163    sudo -E service samba_server enable
164    ;;
165  debian*|ubuntu*)
166    sudo -E systemctl enable nfs-kernel-server
167    sudo -E systemctl enable qemu-guest-agent
168    sudo -E systemctl enable smbd
169    ;;
170  *)
171    # All other linux distros
172    sudo -E systemctl enable nfs-server
173    sudo -E systemctl enable qemu-guest-agent
174    sudo -E systemctl enable smb
175    ;;
176esac
177echo "##[endgroup]"
178
179# Setup Kernel cmdline
180CMDLINE="console=tty0 console=ttyS0,115200n8"
181CMDLINE="$CMDLINE selinux=0"
182CMDLINE="$CMDLINE random.trust_cpu=on"
183CMDLINE="$CMDLINE no_timer_check"
184case "$1" in
185  almalinux*|centos*|fedora*)
186    GRUB_CFG="/boot/grub2/grub.cfg"
187    GRUB_MKCONFIG="grub2-mkconfig"
188    CMDLINE="$CMDLINE biosdevname=0 net.ifnames=0"
189    echo 'GRUB_SERIAL_COMMAND="serial --speed=115200"' \
190      | sudo tee -a /etc/default/grub >/dev/null
191    ;;
192  ubuntu24)
193    GRUB_CFG="/boot/grub/grub.cfg"
194    GRUB_MKCONFIG="grub-mkconfig"
195    echo 'GRUB_DISABLE_OS_PROBER="false"' \
196      | sudo tee -a /etc/default/grub >/dev/null
197    ;;
198  *)
199    GRUB_CFG="/boot/grub/grub.cfg"
200    GRUB_MKCONFIG="grub-mkconfig"
201    ;;
202esac
203
204case "$1" in
205  archlinux|freebsd*)
206    true
207    ;;
208  *)
209    echo "##[group]Edit kernel cmdline"
210    sudo sed -i -e '/^GRUB_CMDLINE_LINUX/d' /etc/default/grub || true
211    echo "GRUB_CMDLINE_LINUX=\"$CMDLINE\"" \
212      | sudo tee -a /etc/default/grub >/dev/null
213    sudo $GRUB_MKCONFIG -o $GRUB_CFG
214    echo "##[endgroup]"
215    ;;
216esac
217
218# reset cloud-init configuration and poweroff
219sudo cloud-init clean --logs
220sleep 2 && sudo poweroff &
221exit 0
222