File
Blob: scripts/package-linux.sh
| 1 | #!/bin/sh |
| 2 | set -eu |
| 3 | |
| 4 | repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) |
| 5 | package_version=${PACKAGE_VERSION:-0.0.0} |
| 6 | package_release=${PACKAGE_RELEASE:-edge.$(git -C "$repo_root" rev-parse --short HEAD)} |
| 7 | arches=${LINUX_PACKAGE_ARCHES:-"amd64 arm64 arm"} |
| 8 | out_root=${OUT_ROOT:-"$repo_root/dist/pkg/linux"} |
| 9 | container_repo_root=/work |
| 10 | |
| 11 | mkdir -p "$out_root" |
| 12 | |
| 13 | if command -v nfpm >/dev/null 2>&1; then |
| 14 | nfpm_mode=native |
| 15 | elif command -v docker >/dev/null 2>&1; then |
| 16 | nfpm_mode=docker |
| 17 | else |
| 18 | echo "nfpm or docker is required" >&2 |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | run_nfpm() { |
| 23 | config_path=$1 |
| 24 | target_path=$2 |
| 25 | packager=$3 |
| 26 | case "$nfpm_mode" in |
| 27 | native) |
| 28 | nfpm package --config "$config_path" --target "$target_path" --packager "$packager" |
| 29 | ;; |
| 30 | docker) |
| 31 | docker run --rm -v "$repo_root:/work" -w /work goreleaser/nfpm:latest \ |
| 32 | package --config "$config_path" --target "$target_path" --packager "$packager" |
| 33 | ;; |
| 34 | esac |
| 35 | } |
| 36 | |
| 37 | for arch in $arches; do |
| 38 | stage_root=$(STAGE_ROOT="$repo_root/dist/stage/linux-$arch" sh "$repo_root/scripts/package-stage.sh" linux "$arch") |
| 39 | work_root="$repo_root/dist/pkg/linux/$arch" |
| 40 | case "$nfpm_mode" in |
| 41 | native) |
| 42 | runtime_repo_root=$repo_root |
| 43 | runtime_stage_root=$stage_root |
| 44 | runtime_work_root=$work_root |
| 45 | ;; |
| 46 | docker) |
| 47 | runtime_repo_root=$container_repo_root |
| 48 | runtime_stage_root="$container_repo_root/dist/stage/linux-$arch" |
| 49 | runtime_work_root="$container_repo_root/dist/pkg/linux/$arch" |
| 50 | ;; |
| 51 | esac |
| 52 | mkdir -p "$work_root" |
| 53 | config_path="$work_root/nfpm.yaml" |
| 54 | cat > "$config_path" <<EOF |
| 55 | name: specter |
| 56 | arch: $arch |
| 57 | platform: linux |
| 58 | version: $package_version |
| 59 | release: $package_release |
| 60 | section: net |
| 61 | priority: optional |
| 62 | maintainer: miragespace <opensource@miragespace.co> |
| 63 | description: Specter edge server, ACME DNS solver, and client tunnel service |
| 64 | vendor: miragespace |
| 65 | homepage: https://github.com/zllovesuki/specter |
| 66 | license: MIT |
| 67 | contents: |
| 68 | - src: $runtime_stage_root/usr/bin/specter |
| 69 | dst: /usr/bin/specter |
| 70 | file_info: |
| 71 | mode: 0755 |
| 72 | - src: $runtime_stage_root/usr/libexec/specter/server-launch |
| 73 | dst: /usr/libexec/specter/server-launch |
| 74 | file_info: |
| 75 | mode: 0755 |
| 76 | - src: $runtime_stage_root/usr/libexec/specter/dns-launch |
| 77 | dst: /usr/libexec/specter/dns-launch |
| 78 | file_info: |
| 79 | mode: 0755 |
| 80 | - src: $runtime_stage_root/usr/libexec/specter/client-launch |
| 81 | dst: /usr/libexec/specter/client-launch |
| 82 | file_info: |
| 83 | mode: 0755 |
| 84 | - src: $runtime_stage_root/usr/share/specter/examples/client.yaml |
| 85 | dst: /usr/share/specter/examples/client.yaml |
| 86 | type: config|noreplace |
| 87 | - src: $runtime_stage_root/etc/specter/server.env |
| 88 | dst: /etc/specter/server.env |
| 89 | type: config|noreplace |
| 90 | - src: $runtime_stage_root/etc/specter/dns.env |
| 91 | dst: /etc/specter/dns.env |
| 92 | type: config|noreplace |
| 93 | - src: $runtime_stage_root/etc/specter/client.env |
| 94 | dst: /etc/specter/client.env |
| 95 | type: config|noreplace |
| 96 | - src: $runtime_stage_root/etc/specter/client.yaml |
| 97 | dst: /etc/specter/client.yaml |
| 98 | type: config|noreplace |
| 99 | - src: $runtime_stage_root/lib/systemd/system/specter-server.service |
| 100 | dst: /lib/systemd/system/specter-server.service |
| 101 | - src: $runtime_stage_root/lib/systemd/system/specter-dns.service |
| 102 | dst: /lib/systemd/system/specter-dns.service |
| 103 | - src: $runtime_stage_root/lib/systemd/system/specter-client.service |
| 104 | dst: /lib/systemd/system/specter-client.service |
| 105 | - dst: /etc/specter/cert |
| 106 | type: dir |
| 107 | - dst: /var/lib/specter |
| 108 | type: dir |
| 109 | - dst: /var/log/specter |
| 110 | type: dir |
| 111 | scripts: |
| 112 | preinstall: $runtime_repo_root/packaging/linux/preinstall.sh |
| 113 | postinstall: $runtime_repo_root/packaging/linux/postinstall.sh |
| 114 | postremove: $runtime_repo_root/packaging/linux/postremove.sh |
| 115 | EOF |
| 116 | case "$nfpm_mode" in |
| 117 | native) |
| 118 | runtime_config_path=$config_path |
| 119 | ;; |
| 120 | docker) |
| 121 | runtime_config_path="$container_repo_root/dist/pkg/linux/$arch/nfpm.yaml" |
| 122 | ;; |
| 123 | esac |
| 124 | run_nfpm "$runtime_config_path" "$runtime_work_root" deb |
| 125 | run_nfpm "$runtime_config_path" "$runtime_work_root" rpm |
| 126 | done |