Files
nexus-vagrant/provision/use-apt-repository.sh
T
2026-08-29 07:18:29 +00:00

62 lines
1.8 KiB
Bash

#!/bin/bash
set -euxo pipefail
nexus_domain=$(hostname --fqdn)
rm -rf tmp/hello-world-debian-package
cp -r /vagrant/hello-world-debian-package tmp
cd tmp/hello-world-debian-package
#
# test the apt repository.
# create the hello-world package.
# see https://www.debian.org/doc/manuals/debmake-doc/ch04.en.html
# see https://www.debian.org/doc/debian-policy/ch-source.html
# see apt-get source dash
apt-get install -y devscripts debmake debhelper dpkg-dev
pushd hello-world
debuild -i -us -uc -b
popd
# upload.
# see https://help.sonatype.com/en/apt-repositories.html
apt-get install -y curl
curl \
--silent \
--fail-with-body \
--show-error \
--config - \
--header 'Content-Type: multipart/form-data' \
--data-binary @hello-world_1.0.0_amd64.deb \
https://$nexus_domain/repository/apt-hosted/ <<'EOF'
user = "alice.doe:password"
EOF
# wait until the Release file exists.
# NB for some reason, after an upload, nexus seems to refresh the repo in
# background, so its unclear when its ready. here we loop and hope for
# the best.
bash -c "while [[ -z \"\$(wget -qO- https://$nexus_domain/repository/apt-hosted/dists/resolute/Release | grep '/Packages$')\" ]]; do sleep 5; done"
# import the apt-hosted repository key.
nexus_apt_hosted_keyring_path="/etc/apt/keyrings/$nexus_domain-apt-hosted.gpg"
gpg --dearmor -o "$nexus_apt_hosted_keyring_path" </vagrant/shared/apt-hosted-public.key
# configure the apt-hosted repository sources.
cat >"/etc/apt/sources.list.d/$nexus_domain-apt-hosted.sources" <<EOF
Types: deb
Architectures: amd64
Signed-By: $nexus_apt_hosted_keyring_path
URIs: https://$nexus_domain/repository/apt-hosted
Suites: resolute
Components: main
EOF
apt-get update
# install the hello-world package.
apt-get install -y hello-world
apt-cache show hello-world
apt-cache policy hello-world
hello-world