-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathinstall-wolfprov.sh
More file actions
executable file
·221 lines (192 loc) · 6.85 KB
/
Copy pathinstall-wolfprov.sh
File metadata and controls
executable file
·221 lines (192 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
#
# Copyright (C) 2006-2025 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/>.
set -euo pipefail
PKG_NAME="libwolfprov"
REPO_ROOT=${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel)}
wolfprov_build() {
local WOLFSSL_ISFIPS=${1:-0}
local WOLFPROV_DEBUG=${2:-0}
printf "Running wolfprov_build with WOLFSSL_ISFIPS=$WOLFSSL_ISFIPS and WOLFPROV_DEBUG=$WOLFPROV_DEBUG\n"
export WOLFSSL_ISFIPS
export WOLFPROV_DEBUG
# Step 1: Determine the repo root
REPO_ROOT=${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel)}
cd "$REPO_ROOT"
# Step 2: Determine version from debian/changelog (no tag checks)
if [[ ! -f debian/changelog ]]; then
echo "❌ Error: debian/changelog not found."
echo "👉 Run scripts/debian-changelog-update.sh to create/update the changelog first."
exit 1
fi
VERSION=$(dpkg-parsechangelog --show-field Version)
UPSTREAM_VERSION="${VERSION%%-*}"
current_commit=$(git rev-parse HEAD)
echo "📌 Using version from changelog: $VERSION (upstream: $UPSTREAM_VERSION)"
TARBALL="${PKG_NAME}_${UPSTREAM_VERSION}.orig.tar.gz"
TARBALL_PREFIX="${PKG_NAME}-${UPSTREAM_VERSION}"
# Step 5: Warn if not on master
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$current_branch" != "master" ]]; then
echo "⚠️ Warning: On branch '$current_branch', not 'master'"
fi
# Step 6: Check for uncommitted changes
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "⚠️ Error: Uncommitted changes in working tree:"
git status --short
exit 1
fi
# Step 7: Clean untracked files
echo "🧹 Cleaning untracked files..."
$REPO_ROOT/scripts/build-wolfprovider.sh --distclean
git clean -fdx
# Step 8: Changelog updates handled by scripts/debian-changelog-update.sh
# Step 9: Create tarball
if [[ -f "../$TARBALL" ]]; then
echo "🗑️ Removing existing tarball: $TARBALL"
rm -f "../$TARBALL"
fi
echo "📦 Creating tarball $TARBALL from commit $current_commit..."
git archive --format=tar.gz --prefix="${TARBALL_PREFIX}/" \
-o "../$TARBALL" "$current_commit"
# Step 9.1: Set up ccache if installed
# Optional ccache
if command -v ccache >/dev/null 2>&1; then
export CC="ccache gcc"
export CXX="ccache g++"
else
export CC="gcc"
export CXX="g++"
fi
# Optional tuning (safe if unset)
: "${CCACHE_DIR:=}"
: "${CCACHE_BASEDIR:=}"
: "${CCACHE_NOHASHDIR:=}"
: "${CCACHE_SLOPPINESS:=}"
CCACHE_COMPILERCHECK=${CCACHE_COMPILERCHECK:-content}
# Step 10: Build package with optional ccache (if installed)
echo "⚙️ Building package..."
WOLFSSL_ISFIPS=${WOLFSSL_ISFIPS:-0}
dpkg-buildpackage -us -uc \
-eWOLFSSL_ISFIPS \
-eWOLFPROV_DEBUG \
-eCC -eCXX \
-eCCACHE_DIR -eCCACHE_BASEDIR -eCCACHE_NOHASHDIR -eCCACHE_COMPILERCHECK
echo "✅ Build completed for version $VERSION"
}
wolfprov_install() {
# Install all packages in the parent directory
for file in ../*.deb; do
if [ -f "$file" ]; then
packages+=("$file")
fi
done
if [ ${#packages[@]} -eq 0 ]; then
echo "No packages found in parent directory"
exit 1
fi
printf "Installing packages:\n"
printf "\t%s\n" "${packages[@]}"
dpkg -i --force-overwrite ${packages[@]}
}
# Main execution
main() {
local debug_mode=0
local fips_mode=0
local no_install=0
local output_dir=
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
echo "Usage: $0 [options] [working-directory]"
echo " Installs wolfSSL from git repository by cloning, configuring, and building .deb packages"
echo ""
echo "Options:"
echo " -t, --tag TAG Clone and build specific tag or branch (default: master)"
echo " -d, --debug Enable debug build mode (adds --enable-debug)"
echo " -f, --fips Enable FIPS build mode (adds --enable-fips)"
echo " -n, --no-install Build only, do not install packages"
echo " -h, --help Show this help message"
echo ""
echo "Arguments:"
echo " output-directory Directory to use for build (default: temporary directory)"
exit 0
;;
-d|--debug)
debug_mode=1
shift
;;
-f|--fips)
fips_mode=1
shift
;;
-n|--no-install)
no_install=1
shift
;;
*)
if [ -z "$output_dir" ]; then
output_dir="$1"
else
echo "Too many arguments" >&2
echo "Use --help for usage information" >&2
exit 1
fi
shift
;;
esac
done
# Check for any existing packages in the parent directory.
# These would conflict with the install.
existing_packages=()
for file in $output_dir/libwolfprov*.deb; do
if [ -f "$file" ]; then
existing_packages+=("$file")
fi
done
if [ ${#existing_packages[@]} -gt 0 ]; then
echo "Error: libwolfprov*.deb already exists in output directory, please remove them first"
echo "Existing packages: ${existing_packages[@]}"
exit 1
fi
if [ -n "$output_dir" ]; then
output_dir=$(realpath "$output_dir")
fi
work_dir=$(mktemp -d)
printf "Working directory: $work_dir\n"
pushd $work_dir 2>&1 > /dev/null
cp -r $REPO_ROOT .
cd $(basename $REPO_ROOT)
wolfprov_build $fips_mode $debug_mode
if [ $no_install -eq 0 ]; then
wolfprov_install
fi
if [ -n "$output_dir" ]; then
if [ ! -d "$output_dir" ]; then
printf "Creating output directory: $output_dir\n"
mkdir -p "$output_dir"
fi
cp ../*.* $output_dir || true
else
printf "No output directory specified, packages stored in $work_dir\n"
fi
printf "Done.\n"
}
# Run main function with all arguments
main "$@"