I'm posting it here in case anyone finds it useful.
Code: Select all
#!/bin/dash
########################################################################
# #
# linux_sampler_build.sh #
# #
# A dash shell script to: #
# #
# 1. Download and extract the source code for the related #
# projects 'linuxsampler' and 'libgig' into a temporary #
# working directory. Note that linuxsampler requires this #
# version of libgig. Linuxsampler does not work with the #
# version of libgig provided by the Ubuntu repository #
# (currently 'libgig9' version '4.2.0~ds1-2build1') #
# #
# 2. Install any packages required to build those projects. #
# #
# 3. Install 'qsampler' (and dependency 'liblscp') from Ubuntu #
# repository. Note: A newer version of the qsampler source #
# is available from the Qsampler site at #
# https://qsampler.sourceforge.io/, but I could not get #
# 'checkinstall' to install it without error. Another #
# alternative is the Appimage version of Qsampler at #
# https://sourceforge.net/projects/qsampler/files/. #
# #
# 4. Build 'libgig' and 'linuxsampler', in that order. #
# #
# 5. Use 'checkinstall' to create a dpkg-installable deb package #
# for each project to enable easy uninstall if required. #
# The deb package files are saved in a directory specified by #
# the script variable 'debdir' (/tmp/checkinstall by default). #
# To save the deb package to a different directory, change the #
# debdir variable to point to the preferred location. #
# #
# 6. Install the deb package for each project. #
# #
# 7. Perform a cleanup upon completion or failure of this script #
# by deleting the temporary working directory, and uninstalling #
# any build dependency packages that were installed by this #
# script. #
# #
# Tested on Linux Mint 20 XFCE. #
# #
# #
# Note: this script must be run as root #
# #
# #
########################################################################
# Example: To run this script, save the script's output to a
# time-stamped log file and also display it on the screen,
# open a terminal in the script directory and type
# 'sudo sh linux_sampler_build.sh | tee -a "$(date +"%F_%H-%M-%S")".log'
# Check that the script is being run as 'root' user
if [ "$(id -u)" -ne "0" ]
then
echo 'This script must be run as root'
exit 1
fi
# LinuxSampler home page
ls_home_url='https://www.linuxsampler.org'
# Common URL path to the linuxsampler packages
base_url='https://download.linuxsampler.org/packages'
# libgig variables
libgig_version='4.2.0'
libgig_src="libgig-$libgig_version.tar.bz2"
libgig_dir="libgig-$libgig_version"
libgig_pkg_release='1'
# linuxsampler variables
linuxsampler_version='2.1.1'
linuxsampler_src="linuxsampler-$linuxsampler_version.tar.bz2"
linuxsampler_dir="linuxsampler-$linuxsampler_version"
linuxsampler_pkg_release='1'
# Working directory variable
wdir=''
# Directory to save the deb package files created by checkinstall
debdir='/tmp/checkinstall'
mkdir -p "$debdir"
chmod +r "$debdir"
# List of packages required to build the projects
required_pkgs='build-essential bison checkinstall libjack-jackd2-dev
libsndfile1-dev lv2-dev uuid-dev'
# Variable to hold a list of required packages that need to be
# installed (and subsequently uninstalled)
install_pkgs=''
# Abort on error + trap exit to allow cleanup
set -eE
# Cleanup
trap 'cleanup' EXIT HUP INT TERM QUIT ABRT TSTP
cleanup() {
printf '\n\nCleaning up before exit ...\n'
# Remove any build dependency packages that this script installed
if [ -n "$install_pkgs" ]
then
echo 'Removing build dependency packages that were
installed by this script ...'
apt-get purge --autoremove --assume-yes $install_pkgs
fi
# Remove temporary working directory and contents
if [ -d "$wdir" ]
then
echo "Removing temporary working directory '$wdir' ..."
rm -r "$wdir"
fi
echo 'Exiting now'
}
# Create a temporary working directory
wdir="$(mktemp -d)"
echo "Created temporary working directory: '$wdir'"
# Change current directory to working directory
cd "$wdir"
# Download required source archives from
# https://www.linuxsampler.org/downloads.html
wget "$base_url/$libgig_src" "$base_url/$linuxsampler_src"
# Extract downloaded archives into a subdirectory based on
# the name of the archive file
tar --extract --bzip2 --file="$libgig_src" --one-top-level
tar --extract --bzip2 --file="$linuxsampler_src" --one-top-level
# Check if required packages are already installed
for p in $required_pkgs
do
echo "Checking required package '$p':"
if dpkg -s "$p" 2>/dev/null | grep -q 'Status: install ok installed'
then
echo " '$p' is already installed"
else
echo " '$p' is not installed"
install_pkgs="$install_pkgs $p"
fi
done
# install required packages
if [ -n "$install_pkgs" ]
then
echo 'Installing build dependency packages...'
# shellcheck disable=SC2086
apt-get install --assume-yes --no-install-recommends $install_pkgs \
# word-splitting of variable required
fi
# Install qsampler (and dependency liblscp)
apt-get install --assume-yes --no-install-recommends qsampler
# Get the cpu architecture
arch="$(dpkg --print-architecture)"
# ---------------------- libgig ----------------------------------------
# Build libgig
cd "$libgig_dir"
./configure
make
# Create a libgig package description file for checkinstall
# shellcheck disable=SC2183
printf 'libgig deb package\n\nCompiled from source at %s/%s\n.\n
Licence: GPL\n.\n
For more information refer to The Linux Sampler Project at %s' \
"$base_url" "$libgig_src" "$ls_home_url" > description-pak
# Create a dpkg-installable deb package for libgig
checkinstall -D -y --pkgname='libgig-deb' \
--pkgversion="$libgig_version" --pkgrelease="$libgig_pkg_release" \
--pkgarch="$arch" --pkgsource="$base_url/$libgig_src" \
--pkglicense='GPL' --pakdir="$debdir" --strip=no --install=no
# Install the libgig package
dpkg -i "$debdir"/libgig-deb_"$libgig_version"-"$libgig_pkg_release"_\
"$arch".deb
cd "$wdir"
# ---------------------- linuxsampler ----------------------------------
# Build linuxsampler (both standalone and LV2 plugin)
cd "$linuxsampler_dir"
./configure
make
# Create a linuxsampler package description file for checkinstall
# shellcheck disable=SC2183
printf 'linuxsampler deb package\n\nCompiled from source at %s/%s\n.\n
Licence: LinuxSampler is licensed under the GNU GPL with the exception
that USAGE of the source code, libraries and applications FOR
COMMERCIAL HARDWARE OR SOFTWARE PRODUCTS IS NOT ALLOWED without prior
written permission by the LinuxSampler authors.\n.\n
For more information refer to The Linux Sampler Project at %s' \
"$base_url" "$linuxsampler_src" "$ls_home_url" > description-pak
# Create a dpkg-installable deb package for linuxsampler
checkinstall -D -y --pkgname='linuxsampler-deb' \
--pkgversion="$linuxsampler_version" \
--pkgrelease="$linuxsampler_pkg_release" --pkgarch="$arch" \
--pkgsource="$base_url/$linuxsampler_src" \
--pkglicense='GPL with commercial exception' --pakdir="$debdir" \
--strip=no --install=no
# Install the linuxsampler package
dpkg -i "$debdir"/linuxsampler-deb_"$linuxsampler_version"-\
"$linuxsampler_pkg_release"_"$arch".deb
exit 0