-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMakefile
More file actions
349 lines (289 loc) · 16.4 KB
/
Makefile
File metadata and controls
349 lines (289 loc) · 16.4 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
VERSION := $(shell grep '^version' Cargo.toml | awk -F' = ' '{print $$2}' | tr -d '"')
RELEASE_NUM := 1
ARCH := $(shell uname -m)
# Map x86_64 to amd64 and aarch64 to arm64 for DEB packages
ifeq ($(ARCH),x86_64)
DEB_ARCH := amd64
MUSL_PATH_ARCH := x86-64
else ifeq ($(ARCH),aarch64)
DEB_ARCH := arm64
MUSL_PATH_ARCH := aarch64
else
DEB_ARCH := $(ARCH)
MUSL_PATH_ARCH := $(ARCH)
endif
.PHONE: help
help:
@echo "Read README.md first"
.PHONE: update-template
update-template:
# Generate volume templates using cryptpilot-crypt
cargo run --bin crypt-gen-template --package cryptpilot-crypt -- -t otp > dist/etc/volumes/otp.toml.template
cargo run --bin crypt-gen-template --package cryptpilot-crypt -- -t kbs > dist/etc/volumes/kbs.toml.template
cargo run --bin crypt-gen-template --package cryptpilot-crypt -- -t kms > dist/etc/volumes/kms.toml.template
cargo run --bin crypt-gen-template --package cryptpilot-crypt -- -t oidc > dist/etc/volumes/oidc.toml.template
cargo run --bin crypt-gen-template --package cryptpilot-crypt -- -t exec > dist/etc/volumes/exec.toml.template
# Generate FDE templates using cryptpilot-fde
cargo run --bin fde-gen-template --package cryptpilot-fde -- global > dist/etc/global.toml.template
cargo run --bin fde-gen-template --package cryptpilot-fde -- fde > dist/etc/fde.toml.template
.PHONE: build-static
build-static:
rustup target add $(ARCH)-unknown-linux-musl
cargo build --release --target $(ARCH)-unknown-linux-musl --config target.$(ARCH)-unknown-linux-musl.linker=\"/opt/$(MUSL_PATH_ARCH)--musl--stable-2024.05-1/bin/$(ARCH)-buildroot-linux-musl-gcc\"
.PHONE: build
build:
cargo build --release
.PHONE: create-tarball
create-tarball:
rm -rf /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/ && mkdir -p /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/
mkdir -p /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/.cargo/
cargo vendor --locked --manifest-path ./Cargo.toml --no-delete --versioned-dirs --respect-source-config /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/vendor// | tee /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/.cargo/config.toml
sed -i 's;^.*directory = .*/vendor/.*$$;directory = "vendor";g' /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/.cargo/config.toml
# sanity check on cargo vendor
@grep "source.crates-io" /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/.cargo/config.toml >/dev/null || (echo "cargo vendor failed, please check /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/.cargo/config.toml"; exit 1)
# remove unused files
find /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/vendor/windows*/src/ ! -name 'lib.rs' -type f -exec rm -f {} +
find /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/vendor/winapi*/src/ ! -name 'lib.rs' -type f -exec rm -f {} +
rm -fr /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/vendor/windows*/lib/*.a
rm -fr /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/vendor/winapi*/lib/*.a
rm -fr /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/vendor/winapi*/lib/*.lib
rm -fr /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/vendor/windows*/lib/*.lib
# copy source code to src/
git clone --no-hardlinks . /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/src/
# apply uncommitted changes (staged + unstaged) to the cloned copy
git diff --binary HEAD | git -C /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/src apply --binary --allow-empty
# copy untracked (new) files that are not ignored
if [ -n "$(git ls-files --others --exclude-standard)" ] ; then git ls-files --others --exclude-standard -z | xargs -0 tar -c -f - | tar -x -f - -C /tmp/cryptpilot-tarball/cryptpilot-${VERSION}/src/ ; fi
tar -czf /tmp/cryptpilot-${VERSION}-vendored-source.tar.gz -C /tmp/cryptpilot-tarball/ cryptpilot-${VERSION}
@echo "Tarball generated:" /tmp/cryptpilot-${VERSION}-vendored-source.tar.gz
.PHONE: rpm-build
rpm-build:
# setup build tree
which rpmdev-setuptree || { yum install -y rpmdevtools ; }
rpmdev-setuptree
# copy sources
cp /tmp/cryptpilot-${VERSION}-vendored-source.tar.gz ~/rpmbuild/SOURCES/
# install build dependencies
which yum-builddep || { yum install -y yum-utils ; }
yum-builddep -y --skip-unavailable ./cryptpilot.spec
# build
rpmbuild -ba ./cryptpilot.spec --define 'with_rustup 1'
@echo "RPM packages are:"
@ls -1 ~/rpmbuild/RPMS/*/cryptpilot-[0-9]*.rpm ~/rpmbuild/RPMS/*/cryptpilot-fde-[0-9]*.rpm ~/rpmbuild/RPMS/*/cryptpilot-crypt-[0-9]*.rpm ~/rpmbuild/RPMS/*/cryptpilot-verity-[0-9]*.rpm 2>/dev/null || true
.PHONE: rpm-build-in-al3-docker
rpm-build-in-al3-docker:
# copy sources
mkdir -p ~/rpmbuild/SOURCES/
cp /tmp/cryptpilot-${VERSION}-vendored-source.tar.gz ~/rpmbuild/SOURCES/
docker run --rm -v ~/rpmbuild:/root/rpmbuild -v .:/code --workdir=/code alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest bash -x -c "sed -i -E 's|https?://mirrors.cloud.aliyuncs.com/|https://mirrors.aliyun.com/|g' /etc/yum.repos.d/*.repo ; sed -i 's/^max_parallel_downloads=.*/max_parallel_downloads=20/' /etc/yum.conf ; if ! grep -q '^max_parallel_downloads=' /etc/yum.conf; then sed -i '/^\[main\]$/a max_parallel_downloads=20' /etc/yum.conf; fi ; curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain none ; source \"\$$HOME/.cargo/env\" ; yum install -y rpmdevtools yum-utils; rpmdev-setuptree ; yum-builddep -y --skip-unavailable ./cryptpilot.spec ; rpmbuild -ba ./cryptpilot.spec --define 'with_rustup 1'"
.PHONE: rpm-build-in-an23-docker
rpm-build-in-an23-docker:
# copy sources
mkdir -p ~/rpmbuild/SOURCES/
cp /tmp/cryptpilot-${VERSION}-vendored-source.tar.gz ~/rpmbuild/SOURCES/
docker run --rm -v ~/rpmbuild:/root/rpmbuild -v .:/code --workdir=/code registry.openanolis.cn/openanolis/anolisos:23 bash -x -c "sed -i 's/^max_parallel_downloads=.*/max_parallel_downloads=20/' /etc/yum.conf ; if ! grep -q '^max_parallel_downloads=' /etc/yum.conf; then sed -i '/^\[main\]$/a max_parallel_downloads=20' /etc/yum.conf; fi ; curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain none ; source \"\$$HOME/.cargo/env\" ; yum install -y rpmdevtools yum-utils; rpmdev-setuptree ; yum-builddep -y --skip-unavailable ./cryptpilot.spec ; rpmbuild -ba ./cryptpilot.spec --define 'with_rustup 1'"
.PHONE: rpm-build-in-docker
rpm-build-in-docker: rpm-build-in-al3-docker
.PHONE: rpm-build-in-docker-aarch64
rpm-build-in-docker-aarch64:
# copy sources
mkdir -p ~/rpmbuild/SOURCES/
cp /tmp/cryptpilot-${VERSION}-vendored-source.tar.gz ~/rpmbuild/SOURCES/
docker run --rm --platform linux/arm64 -v ~/rpmbuild:/root/rpmbuild -v .:/code --workdir=/code alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest bash -x -c "sed -i -E 's|https?://mirrors.cloud.aliyuncs.com/|https://mirrors.aliyun.com/|g' /etc/yum.repos.d/*.repo ; sed -i 's/^max_parallel_downloads=.*/max_parallel_downloads=20/' /etc/yum.conf ; if ! grep -q '^max_parallel_downloads=' /etc/yum.conf; then sed -i '/^\[main\]$/a max_parallel_downloads=20' /etc/yum.conf; fi ; curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain none ; source \"\$$HOME/.cargo/env\" ; yum install -y rpmdevtools yum-utils; rpmdev-setuptree ; yum-builddep -y --skip-unavailable ./cryptpilot.spec ; rpmbuild -ba ./cryptpilot.spec --define 'with_rustup 1'"
.PHONE: rpm-install
rpm-install: rpm-build
yum remove cryptpilot cryptpilot-fde cryptpilot-crypt cryptpilot-verity -y || true
ls -t /root/rpmbuild/RPMS/$(ARCH)/cryptpilot-[0-9]*.rpm | head -n 1 | xargs rpm --install
ls -t /root/rpmbuild/RPMS/$(ARCH)/cryptpilot-fde-*.rpm | head -n 1 | xargs rpm --install
ls -t /root/rpmbuild/RPMS/$(ARCH)/cryptpilot-crypt-*.rpm | head -n 1 | xargs rpm --install
ls -t /root/rpmbuild/RPMS/$(ARCH)/cryptpilot-verity-*.rpm | head -n 1 | xargs rpm --install
.PHONE: update-rpm-tree
update-rpm-tree:
# copy sources
rm -f ../rpm-tree-cryptpilot/cryptpilot-*.tar.gz
cp /tmp/cryptpilot-${VERSION}-vendored-source.tar.gz ../rpm-tree-cryptpilot/
cp ./cryptpilot.spec ../rpm-tree-cryptpilot/
.PHONY: deb-build
deb-build:
dpkg-buildpackage -us -uc -b
@echo "DEB packages are in parent directory:"
@ls -lh ../cryptpilot*.deb 2>/dev/null || true
.PHONY: deb-install
deb-install: deb-build
apt-get remove -y cryptpilot cryptpilot-fde cryptpilot-crypt cryptpilot-verity || true
dpkg -i ../cryptpilot-verity_*.deb ../cryptpilot-fde_*.deb ../cryptpilot-crypt_*.deb ../cryptpilot_*.deb
apt-get install -f -y
.PHONE: run-test
run-test: install-test-depend
cargo test -- --nocapture
.PHONE: install-test-depend
install-test-depend:
[[ -e /tmp/pjdfstest/pjdfstest ]] || { cd /tmp/ && git clone https://github.com/pjd/pjdfstest.git && cd /tmp/pjdfstest && autoreconf -ifs && ./configure && make pjdfstest ; }
which prove || { yum install -y perl-Test-Harness ; }
which stress-ng || { yum install -y http://mirrors.openanolis.cn/anolis/8/AppStream/$(ARCH)/os/Packages/stress-ng-0.17.08-2.0.1.an8.$(ARCH).rpm ; }
.PHONY: install-convert-test-depend
install-convert-test-depend:
yum install -y wget qemu-img cryptsetup lvm2 parted e2fsprogs util-linux libguestfs-tools-c
which docker || { yum install -y docker ; }
.PHONY: run-convert-test-case
run-convert-test-case: install-convert-test-depend
bash tests/test-convert.sh --rpm $(CRYPTPILOT_FDE_RPM) --bootloader $(BOOTLOADER) --rootfs-$(ROOTFS_ENC) --delta-location $(DELTA_LOCATION) $(if $(INPUT_IMAGE),--input $(INPUT_IMAGE),)
.PHONE: shellcheck
shellcheck:
@command -v shellcheck >&- || { \
echo "shellcheck not found, please installing it from https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.$(ARCH).tar.xz" ; \
}
find . -name '*.sh' -exec shellcheck {} \;
.PHONE: clippy
clippy:
cargo clippy --all-targets --all-features -- -D warnings
.PHONY: deb-build-in-docker
deb-build-in-docker:
mkdir -p ~/deb-packages/
docker run --rm \
-v ~/deb-packages:/root/deb-packages \
-v .:/code \
--workdir=/code \
ubuntu:24.04 \
bash -x -c "\
export DEBIAN_FRONTEND=noninteractive && apt-get update && \
apt-get install -y build-essential debhelper devscripts curl cmake \
protobuf-compiler libcryptsetup-dev libdevmapper-dev libfuse3-dev \
clang pkg-config && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.82.0 && \
source \"\$$HOME/.cargo/env\" && \
dpkg-buildpackage -us -uc -b && \
cp ../*.deb /root/deb-packages/"
@echo "DEB packages are in ~/deb-packages/"
@ls -lh ~/deb-packages/*.deb 2>/dev/null || true
# Get current version from Cargo.toml
CURRENT_VERSION := $(shell grep '^version' Cargo.toml | awk -F' = ' '{print $$2}' | tr -d '"')
# Parse version components
MAJOR := $(shell echo $(CURRENT_VERSION) | awk -F. '{print $$1}')
MINOR := $(shell echo $(CURRENT_VERSION) | awk -F. '{print $$2}')
PATCH := $(shell echo $(CURRENT_VERSION) | awk -F. '{print $$3}')
# Calculate new versions
NEW_VERSION_MAJOR := $(shell echo $$(( $(MAJOR) + 1 ))).0.0
NEW_VERSION_MINOR := $(MAJOR).$(shell echo $$(( $(MINOR) + 1 ))).0
NEW_VERSION_PATCH := $(MAJOR).$(MINOR).$(shell echo $$(( $(PATCH) + 1 )))
# Function to update Cargo.toml version
define update-cargo-toml
@sed -i 's/^version = "$(CURRENT_VERSION)"/version = "$(1)"/' Cargo.toml
endef
# Function to update Cargo.lock
define update-cargo-lock
@cargo update --workspace --offline 2>/dev/null || cargo update --workspace
endef
# Function to get git info
# $(1) = expected previous version tag (e.g., v0.4.0)
define get-git-info
$(eval EXPECTED_PREV_TAG := v$(shell echo $(1) | awk -F. '{print $$1"."$$2".0"}'))
$(eval AUTHOR := $(shell git log -1 --pretty=format:"%an <%ae>"))
endef
# Function to determine last tag
# $(1) = expected previous version tag (e.g., v0.4.0)
define determine-last-tag
$(eval EXPECTED_TAG := $(1))
$(eval TAG_EXISTS := $(shell git tag -l "$(EXPECTED_TAG)"))
$(eval LAST_TAG := $(if $(TAG_EXISTS),$(EXPECTED_TAG),$(shell git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | head -1)))
endef
# Function to write commits to file for RPM (uses -)
define write-commits-to-file
@git log $(LAST_TAG)..HEAD --pretty=format:"- %s" --no-merges > $(1) 2>/dev/null || echo "- Version bump to $(2)" > $(1)
endef
# Function to write commits to file for Debian (uses *)
define write-commits-to-file-deb
@git log $(LAST_TAG)..HEAD --pretty=format:" * %s" --no-merges > $(1) 2>/dev/null || echo " * Version bump to $(2)" > $(1)
endef
# Function to update RPM spec version and changelog
define update-rpm-spec
@# Update Version field in spec file (matches any version number)
@sed -i 's/^Version: .*/Version: $(1)/' cryptpilot.spec
$(eval RPM_DATE := $(shell env LC_ALL=C date +"%a %b %d %Y"))
@echo "* $(RPM_DATE) $(AUTHOR) - $(1)-1" > /tmp/rpm_changelog_entry.txt
$(call write-commits-to-file,/tmp/rpm_commits.txt,$(1))
@cat /tmp/rpm_commits.txt >> /tmp/rpm_changelog_entry.txt
@echo "" >> /tmp/rpm_changelog_entry.txt
@echo "" >> /tmp/rpm_changelog_entry.txt
@awk '/^%changelog/{print; while((getline line < "/tmp/rpm_changelog_entry.txt") > 0) print line; close("/tmp/rpm_changelog_entry.txt"); next} {print}' cryptpilot.spec > cryptpilot.spec.new && mv cryptpilot.spec.new cryptpilot.spec
@rm -f /tmp/rpm_changelog_entry.txt /tmp/rpm_commits.txt
endef
# Function to update Debian changelog
define update-debian-changelog
$(eval DEB_DATE := $(shell env LC_ALL=C date -R))
@echo "cryptpilot ($(1)) unstable; urgency=medium" > /tmp/deb_changelog_entry.txt
@echo "" >> /tmp/deb_changelog_entry.txt
$(call write-commits-to-file-deb,/tmp/deb_commits.txt,$(1))
@cat /tmp/deb_commits.txt >> /tmp/deb_changelog_entry.txt
@echo "" >> /tmp/deb_changelog_entry.txt
@echo "" >> /tmp/deb_changelog_entry.txt
@echo " -- $(AUTHOR) $(DEB_DATE)" >> /tmp/deb_changelog_entry.txt
@echo "" >> /tmp/deb_changelog_entry.txt
@cat /tmp/deb_changelog_entry.txt debian/changelog > debian/changelog.new && mv debian/changelog.new debian/changelog
@rm -f /tmp/deb_changelog_entry.txt /tmp/deb_commits.txt
endef
# Function to update buildspec.yml version tags
# Updates tags in all three APPLICATION buildspec.yml files
define update-buildspec-yml
@sed -i -E 's/(tags: \[\[)[0-9]+\.[0-9]+\.[0-9]+(, latest\]\])/\1$(1)\2/' APPLICATION/cryptpilot-fde/buildspec.yml
@sed -i -E 's/(tags: \[\[)[0-9]+\.[0-9]+\.[0-9]+(, latest\]\])/\1$(1)\2/' APPLICATION/cryptpilot-crypt/buildspec.yml
@sed -i -E 's/(tags: \[\[)[0-9]+\.[0-9]+\.[0-9]+(, latest\]\])/\1$(1)\2/' APPLICATION/cryptpilot-verity/buildspec.yml
endef
# Main bump version function
# $(1) = version type (major/minor/patch)
# $(2) = new version number
# $(3) = expected previous version tag (e.g., v0.4.0)
define bump-version-internal
@echo "Bumping $(1) version: $(CURRENT_VERSION) -> $(2)"
$(call update-cargo-toml,$(2))
@echo "New version: $(2)"
$(call update-cargo-lock)
$(call get-git-info,$(2))
$(call determine-last-tag,$(3))
@echo "Using last tag: $(LAST_TAG)"
@echo "Updating RPM spec version and changelog..."
$(call update-rpm-spec,$(2))
@echo "Updating Debian changelog..."
$(call update-debian-changelog,$(2))
@echo "Updating buildspec.yml files..."
$(call update-buildspec-yml,$(2))
@echo "Version bump complete. New version: $(2)"
@echo "Changes made:"
@echo " - Updated Cargo.toml"
@echo " - Updated Cargo.lock"
@echo " - Updated RPM spec version and changelog"
@echo " - Updated Debian changelog"
@echo " - Updated APPLICATION buildspec.yml files"
@echo ""
@echo "If it is ok to commit, run the following commands:"
@echo " git add ."
@echo " git commit -m \"Bump $(1) version to $(2)\""
@echo " git tag -a v$(2) -m \"Bump $(1) version to $(2)\""
@echo " git push origin v$(2)"
endef
# Bump major version (0.4.1 -> 1.0.0)
.PHONY: bump-version-major
bump-version-major:
$(call bump-version-internal,major,$(NEW_VERSION_MAJOR),v$(CURRENT_VERSION))
# Bump minor version (0.4.1 -> 0.5.0)
.PHONY: bump-version-minor
bump-version-minor:
$(call bump-version-internal,minor,$(NEW_VERSION_MINOR),v$(CURRENT_VERSION))
# Bump patch version (0.4.1 -> 0.4.2)
.PHONY: bump-version-patch
bump-version-patch:
$(call bump-version-internal,patch,$(NEW_VERSION_PATCH),v$(CURRENT_VERSION))
# Docker build targets
.PHONY: docker-build
docker-build: docker-build-fde docker-build-crypt docker-build-verity
.PHONY: docker-build-fde
docker-build-fde:
docker build -f Dockerfile.fde --target release-fde -t cryptpilot-fde:latest .
.PHONY: docker-build-crypt
docker-build-crypt:
docker build -f Dockerfile.crypt --target release-crypt -t cryptpilot-crypt:latest .
.PHONY: docker-build-verity
docker-build-verity:
docker build -f Dockerfile.verity --target release-verity -t cryptpilot-verity:latest .
.PHONY: docker-build-all
docker-build-all: docker-build