|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +export ARCH="${ARCH-x86-64}" |
| 5 | +SCRIPTFOLDER="$(dirname "$(readlink -f "$0")")" |
| 6 | + |
| 7 | +if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then |
| 8 | + echo "Usage: $0 VERSION SYSEXTNAME" |
| 9 | + echo "The script will download nebula release binaries and create a sysext squashfs image with the name SYSEXTNAME.raw in the current folder." |
| 10 | + echo "A temporary directory named SYSEXTNAME in the current folder will be created and deleted again." |
| 11 | + echo "All files in the sysext image will be owned by root." |
| 12 | + echo "To use arm64 pass 'ARCH=arm64' as environment variable (current value is '${ARCH}')." |
| 13 | + "${SCRIPTFOLDER}"/bake.sh --help |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +VERSION="$1" |
| 18 | +SYSEXTNAME="$2" |
| 19 | + |
| 20 | +if [ "${ARCH}" = "x86_64" ] || [ "${ARCH}" = "x86-64" ]; then |
| 21 | + ARCH="amd64" |
| 22 | +elif [ "${ARCH}" = "aarch64" ]; then |
| 23 | + ARCH="arm64" |
| 24 | +fi |
| 25 | + |
| 26 | +VERSION="v${VERSION#v}" |
| 27 | + |
| 28 | +TARBALL="nebula-linux-${ARCH}.tar.gz" |
| 29 | +SHASUM="SHASUM256.txt" |
| 30 | + |
| 31 | +TARBALL_URL="https://github.com/slackhq/nebula/releases/download/${VERSION}/${TARBALL}" |
| 32 | +SHASUM_URL="https://github.com/slackhq/nebula/releases/download/${VERSION}/${SHASUM}" |
| 33 | + |
| 34 | +rm -rf "${SYSEXTNAME}" |
| 35 | + |
| 36 | +TMP_DIR="${SYSEXTNAME}/tmp" |
| 37 | +mkdir -p "${TMP_DIR}" |
| 38 | + |
| 39 | +curl --parallel --fail --silent --show-error --location \ |
| 40 | + --output "${TMP_DIR}/${TARBALL}" "${TARBALL_URL}" \ |
| 41 | + --output "${TMP_DIR}/${SHASUM}" "${SHASUM_URL}" |
| 42 | + |
| 43 | +pushd "${TMP_DIR}" > /dev/null |
| 44 | +grep "${TARBALL}$" "${SHASUM}" | sha256sum -c - |
| 45 | +popd > /dev/null |
| 46 | + |
| 47 | +mkdir -p "${SYSEXTNAME}/usr/bin" |
| 48 | + |
| 49 | +tar --force-local -xf "${TMP_DIR}/${TARBALL}" -C "${SYSEXTNAME}/usr/bin" |
| 50 | +chmod +x "${SYSEXTNAME}/usr/bin/nebula" |
| 51 | +chmod +x "${SYSEXTNAME}/usr/bin/nebula-cert" |
| 52 | + |
| 53 | +mkdir -p "${SYSEXTNAME}/usr/lib/systemd/system" |
| 54 | +cat > "${SYSEXTNAME}/usr/lib/systemd/system/nebula.service" <<-'EOF' |
| 55 | +[Unit] |
| 56 | +Description=Nebula overlay networking tool |
| 57 | +Wants=basic.target network-online.target nss-lookup.target time-sync.target |
| 58 | +After=basic.target network.target network-online.target |
| 59 | +
|
| 60 | +[Service] |
| 61 | +Type=notify |
| 62 | +NotifyAccess=main |
| 63 | +SyslogIdentifier=nebula |
| 64 | +ExecReload=/bin/kill -HUP $MAINPID |
| 65 | +ExecStart=/usr/bin/nebula -config /etc/nebula/config.yaml |
| 66 | +Restart=always |
| 67 | +
|
| 68 | +[Install] |
| 69 | +WantedBy=multi-user.target |
| 70 | +EOF |
| 71 | + |
| 72 | +mkdir -p "${SYSEXTNAME}"/usr/lib/systemd/system/multi-user.target.d |
| 73 | +{ echo "[Unit]"; echo "Upholds=nebula.service"; } > "${SYSEXTNAME}"/usr/lib/systemd/system/multi-user.target.d/10-nebula.conf |
| 74 | + |
| 75 | +rm -rf "${TMP_DIR}" |
| 76 | + |
| 77 | +RELOAD=1 "${SCRIPTFOLDER}"/bake.sh "${SYSEXTNAME}" |
| 78 | +rm -rf "${SYSEXTNAME}" |
0 commit comments