Skip to content

Instantly share code, notes, and snippets.

@astoeckel
Created November 15, 2020 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astoeckel/8ded8670af495c4a0ea137cda67c7af5 to your computer and use it in GitHub Desktop.
Save astoeckel/8ded8670af495c4a0ea137cda67c7af5 to your computer and use it in GitHub Desktop.
Compiling and installing nbdkit on CentOS 7
#!/usr/bin/bash
# Downloads NBDKit and builds a minimal version. This minimal version only
# installs basic plugins and filters, and the SSH plugin.
# For compilation to succeed, you'll need to install
# yum install gcc gcc-c++ libssh-devel openssl-devel autoconf automake libtool
# Also, best create a user nbdkit
# adduser --system --user-group --shell /sbin/nologin --home-dir /opt/nbdkit --create-home nbdkit
set -e
TAR=/opt/nbdkit/
SRC_CMAKE=/opt/nbdkit/cmake-3.19.0-rc3-Linux-x86_64.tar.gz
SRC_NBDKIT=/opt/nbdkit/nbdkit-1.22.3.tar.gz
SRC_LIBSSH=/opt/nbdkit/libssh-0.9.5.tar.xz
TMPDIR=$( mktemp -d )
trap 'rm -rf "$TMPDIR"' EXIT
echo "Changing to \"$TMPDIR\"..."
cd "$TMPDIR"
echo "Extracting cmake tarball..."
tar -xf "$SRC_CMAKE"
DIR_CMAKE=$TMPDIR/$( basename "$SRC_CMAKE" .tar.gz )
echo "Extracting libssh tarball..."
tar -xf "$SRC_LIBSSH"
DIR_LIBSSH=$TMPDIR/$( basename "$SRC_LIBSSH" .tar.xz )
echo "Extracting nbdkit tarball..."
tar -xf "$SRC_NBDKIT"
DIR_NBDKIT=$TMPDIR/$( basename "$SRC_NBDKIT" .tar.gz )
echo "Adding cmake to the path..."
export PATH=$DIR_CMAKE/bin:$PATH
echo "Changing to \"$DIR_LIBSSH\"..."
cd "$DIR_LIBSSH"
echo "Building libssh"
mkdir build
cd build
cmake .. \
"-DCMAKE_INSTALL_PREFIX=$TAR" \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_TYPE=Release \
-Wno-dev
make -j8
make install
echo "Changing to \"$DIR_NBDKIT\"..."
cd "$DIR_NBDKIT"
echo "Patching configure.ac..."
sed -i 's/bash_completion=yes/bash_completion=no/g' configure.ac
sed -i 's/enable_pod=yes/enable_pod=no/g' configure.ac
sed -i '/^PKG_CHECK_MODULES(\[LIBSELINUX\]/,/^\])$/d' configure.ac
sed -i '/^PKG_CHECK_MODULES(\[GNUTLS\]/,/^\])$/d' configure.ac
echo "Running autoreconf"
autoreconf -i
echo "Building..."
export PKG_CONFIG_PATH=$TAR/lib64/pkgconfig
env
./configure \
--without-iconv \
--with-tls-priority \
--without-curl \
--with-ssh \
--without-iso \
--without-libvirt \
--without-zlib \
--without-libnbd \
--without-liblzma \
--without-libzstd \
--without-libguestfs \
--without-ext2 \
--disable-python \
--disable-rust \
--disable-golang \
--disable-vddk \
--disable-linuxdisk \
--disable-static \
"--prefix=$TAR"
make -j 8
make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment