1#!/usr/bin/env bash 2 3###################################################################### 4# 4) configure and build openzfs modules 5###################################################################### 6 7set -eu 8 9function run() { 10 LOG="/var/tmp/build-stderr.txt" 11 echo "****************************************************" 12 echo "$(date) ($*)" 13 echo "****************************************************" 14 ($@ || echo $? > /tmp/rv) 3>&1 1>&2 2>&3 | stdbuf -eL -oL tee -a $LOG 15 if [ -f /tmp/rv ]; then 16 RV=$(cat /tmp/rv) 17 echo "****************************************************" 18 echo "exit with value=$RV ($*)" 19 echo "****************************************************" 20 echo 1 > /var/tmp/build-exitcode.txt 21 exit $RV 22 fi 23} 24 25function freebsd() { 26 export MAKE="gmake" 27 echo "##[group]Autogen.sh" 28 run ./autogen.sh 29 echo "##[endgroup]" 30 31 echo "##[group]Configure" 32 run ./configure \ 33 --prefix=/usr/local \ 34 --with-libintl-prefix=/usr/local \ 35 --enable-pyzfs \ 36 --enable-debug \ 37 --enable-debuginfo 38 echo "##[endgroup]" 39 40 echo "##[group]Build" 41 run gmake -j$(sysctl -n hw.ncpu) 42 echo "##[endgroup]" 43 44 echo "##[group]Install" 45 run sudo gmake install 46 echo "##[endgroup]" 47} 48 49function linux() { 50 echo "##[group]Autogen.sh" 51 run ./autogen.sh 52 echo "##[endgroup]" 53 54 echo "##[group]Configure" 55 run ./configure \ 56 --prefix=/usr \ 57 --enable-pyzfs \ 58 --enable-debug \ 59 --enable-debuginfo 60 echo "##[endgroup]" 61 62 echo "##[group]Build" 63 run make -j$(nproc) 64 echo "##[endgroup]" 65 66 echo "##[group]Install" 67 run sudo make install 68 echo "##[endgroup]" 69} 70 71function rpm_build_and_install() { 72 EXTRA_CONFIG="${1:-}" 73 echo "##[group]Autogen.sh" 74 run ./autogen.sh 75 echo "##[endgroup]" 76 77 echo "##[group]Configure" 78 run ./configure --enable-debug --enable-debuginfo $EXTRA_CONFIG 79 echo "##[endgroup]" 80 81 echo "##[group]Build" 82 run make pkg-kmod pkg-utils 83 echo "##[endgroup]" 84 85 echo "##[group]Install" 86 run sudo dnf -y --skip-broken localinstall $(ls *.rpm | grep -v src.rpm) 87 echo "##[endgroup]" 88 89} 90 91function deb_build_and_install() { 92echo "##[group]Autogen.sh" 93 run ./autogen.sh 94 echo "##[endgroup]" 95 96 echo "##[group]Configure" 97 run ./configure \ 98 --prefix=/usr \ 99 --enable-pyzfs \ 100 --enable-debug \ 101 --enable-debuginfo 102 echo "##[endgroup]" 103 104 echo "##[group]Build" 105 run make native-deb-kmod native-deb-utils 106 echo "##[endgroup]" 107 108 echo "##[group]Install" 109 # Do kmod install. Note that when you build the native debs, the 110 # packages themselves are placed in parent directory '../' rather than 111 # in the source directory like the rpms are. 112 run sudo apt-get -y install $(find ../ | grep -E '\.deb$' \ 113 | grep -Ev 'dkms|dracut') 114 echo "##[endgroup]" 115} 116 117# Debug: show kernel cmdline 118if [ -f /proc/cmdline ] ; then 119 cat /proc/cmdline || true 120fi 121 122# save some sysinfo 123uname -a > /var/tmp/uname.txt 124 125cd $HOME/zfs 126export PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin" 127 128# build 129case "$1" in 130 freebsd*) 131 freebsd 132 ;; 133 alma*|centos*) 134 rpm_build_and_install "--with-spec=redhat" 135 ;; 136 fedora*) 137 rpm_build_and_install 138 ;; 139 debian*|ubuntu*) 140 deb_build_and_install 141 ;; 142 *) 143 linux 144 ;; 145esac 146 147# building the zfs module was ok 148echo 0 > /var/tmp/build-exitcode.txt 149 150# reset cloud-init configuration and poweroff 151sudo cloud-init clean --logs 152sync && sleep 2 && sudo poweroff & 153exit 0 154