Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions scripts/replace-default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash
#
# Copyright (C) 2006-2024 wolfSSL Inc.
#
# This file is part of wolfProvider.
#
# wolfProvider is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# wolfProvider is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
#
# This script builds and installs wolfSSL/OpenSSL/wolfProvider packages to
# replace the default provider to always use wolfProvider.

set -e
set -x

echo "=== Building wolfProvider Debian packages ==="

# Install build dependencies
sudo apt-get update
sudo apt-get install -y \
build-essential \
devscripts \
debhelper \
dh-autoreconf \
libtool \
pkg-config \
git \
wget \
curl \
ca-certificates \
openssl \
dpkg-dev \
lintian \
fakeroot \
dh-exec \
equivs \
expect \
xxd

# Ensure the working directory is safe
git config --global --add safe.directory "$PWD"

# Fetch tags (for Debian versioning)
git fetch --tags --force --prune

# Install wolfSSL Debian packages from repo tarball
mkdir -p "/tmp/wolfssl-pkg"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably clean out this directory if it exists prior to generating the packages. Or just let intstall-wolfssl.sh create a temp dir.

chmod +x debian/install-wolfssl.sh
./debian/install-wolfssl.sh \
--tag v5.8.2-stable \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why hardcode the 5.8.2 tag? That deviates from the default behavior of install-wolfssl.sh

"/tmp/wolfssl-pkg"

# Stage wolfSSL debs into artifacts directory
mkdir -p "/tmp/wolfprov-packages"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here about cleaning out the directory

find /tmp/wolfssl-pkg -name "*wolfssl*" -type f -name "*.deb" -exec cp {} /tmp/wolfprov-packages/ \;

# Build Debian packages (wolfProvider + OpenSSL)
yes Y | ./scripts/build-wolfprovider.sh --debian
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have an option for --debug?


# Collect package artifacts
mv ../*.deb /tmp/wolfprov-packages/ 2>/dev/null || true

echo "=== Installing packages ==="

# Install wolfSSL first
wolfssl_debs=$(ls -1 /tmp/wolfprov-packages/*wolfssl*.deb 2>/dev/null || true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be already completed by install-wolfssl.sh

if [ -n "$wolfssl_debs" ]; then
sudo apt install -y $wolfssl_debs
fi

# Install OpenSSL packages in dependency order with conflict resolution
libssl3_debs=$(ls -1 /tmp/wolfprov-packages/libssl3_[0-9]*.deb 2>/dev/null || true)
openssl_debs=$(ls -1 /tmp/wolfprov-packages/openssl_[0-9]*.deb 2>/dev/null || true)
libssl_dev_debs=$(ls -1 /tmp/wolfprov-packages/libssl-dev_[0-9]*.deb 2>/dev/null || true)

# Install custom OpenSSL packages
echo "Installing custom OpenSSL packages..."
if [ -n "$libssl3_debs" ]; then
echo "Installing custom libssl3 package..."
sudo dpkg -i $libssl3_debs || sudo apt install -f -y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the package is already installed or is a "downgrade" to a lower version number? Does dpkg -i handle this correctly?

fi
if [ -n "$openssl_debs" ]; then
echo "Installing custom openssl package..."
sudo dpkg -i $openssl_debs || sudo apt install -f -y
fi
if [ -n "$libssl_dev_debs" ]; then
echo "Installing custom libssl-dev package..."
sudo dpkg -i $libssl_dev_debs || sudo apt install -f -y
fi

# Install wolfProvider main package
wolfprov_main=$(ls -1 /tmp/wolfprov-packages/libwolfprov_[0-9]*.deb 2>/dev/null | head -n1 || true)
if [ -z "$wolfprov_main" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we print the name of the wolfprov package too for consistency?

echo "ERROR: libwolfprov main package not found"
exit 1
fi
sudo dpkg -i "$wolfprov_main" || sudo apt install -f -y

./scripts/verify-debian.sh

echo "=== Replace Default installed! ==="
Loading