File
Blob: scripts/package-stage.sh
| 1 | #!/bin/sh |
| 2 | set -eu |
| 3 | |
| 4 | if [ "$#" -ne 2 ]; then |
| 5 | echo "usage: $0 <os> <arch>" >&2 |
| 6 | exit 1 |
| 7 | fi |
| 8 | |
| 9 | target_os=$1 |
| 10 | arch=$2 |
| 11 | repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) |
| 12 | stage_root=${STAGE_ROOT:-"$repo_root/dist/stage/$target_os-$arch"} |
| 13 | binary_path=${BINARY_PATH:-"$repo_root/bin/specter-$target_os-$arch"} |
| 14 | |
| 15 | if [ ! -f "$binary_path" ]; then |
| 16 | echo "missing binary: $binary_path" >&2 |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | case "$target_os" in |
| 21 | linux) |
| 22 | sysconfdir=/etc |
| 23 | bindir=/usr/bin |
| 24 | libexecdir=/usr/libexec/specter |
| 25 | sharedir=/usr/share/specter |
| 26 | serviceroot=/lib/systemd/system |
| 27 | packaging_supported=1 |
| 28 | ;; |
| 29 | freebsd) |
| 30 | sysconfdir=/usr/local/etc |
| 31 | bindir=/usr/local/bin |
| 32 | libexecdir=/usr/local/libexec/specter |
| 33 | sharedir=/usr/local/share/specter |
| 34 | serviceroot=/usr/local/etc/rc.d |
| 35 | packaging_supported=0 |
| 36 | ;; |
| 37 | illumos) |
| 38 | sysconfdir=/opt/local/etc |
| 39 | bindir=/opt/local/bin |
| 40 | libexecdir=/opt/local/libexec/specter |
| 41 | sharedir=/opt/local/share/specter |
| 42 | serviceroot=/lib/svc/manifest/site |
| 43 | packaging_supported=0 |
| 44 | ;; |
| 45 | *) |
| 46 | echo "unsupported os: $target_os" >&2 |
| 47 | exit 1 |
| 48 | ;; |
| 49 | esac |
| 50 | |
| 51 | if [ "$packaging_supported" -ne 1 ]; then |
| 52 | echo "packaging for $target_os is currently unsupported" >&2 |
| 53 | exit 1 |
| 54 | fi |
| 55 | |
| 56 | rm -rf "$stage_root" |
| 57 | mkdir -p \ |
| 58 | "$stage_root$bindir" \ |
| 59 | "$stage_root$libexecdir" \ |
| 60 | "$stage_root$sharedir/examples" \ |
| 61 | "$stage_root$sysconfdir/specter/cert" \ |
| 62 | "$stage_root/var/lib/specter" \ |
| 63 | "$stage_root/var/log/specter" |
| 64 | |
| 65 | install -m 0755 "$binary_path" "$stage_root$bindir/specter" |
| 66 | install -m 0644 "$repo_root/tun/client/config.example.yaml" "$stage_root$sharedir/examples/client.yaml" |
| 67 | install -m 0644 "$repo_root/tun/client/config.example.yaml" "$stage_root$sysconfdir/specter/client.yaml" |
| 68 | |
| 69 | cat > "$stage_root$sysconfdir/specter/server.env" <<EOF |
| 70 | SPECTER_GLOBAL_ARGS= |
| 71 | SPECTER_SERVER_ARGS="--data-dir /var/lib/specter --cert-dir $sysconfdir/specter/cert --apex example.com --listen-rpc unix:///run/specter/rpc.sock" |
| 72 | EOF |
| 73 | |
| 74 | cat > "$stage_root$sysconfdir/specter/dns.env" <<EOF |
| 75 | SPECTER_GLOBAL_ARGS= |
| 76 | SPECTER_DNS_ARGS="--rpc unix:///run/specter/rpc.sock --acme acme://ops@example.net@acme-hosted.net --acme-ns ns1.acme-hosted.net/203.0.113.10" |
| 77 | EOF |
| 78 | |
| 79 | cat > "$stage_root$sysconfdir/specter/client.env" <<EOF |
| 80 | SPECTER_GLOBAL_ARGS= |
| 81 | SPECTER_CLIENT_CONFIG=$sysconfdir/specter/client.yaml |
| 82 | SPECTER_CLIENT_ARGS= |
| 83 | EOF |
| 84 | |
| 85 | render_template() { |
| 86 | sed \ |
| 87 | -e "s|__BINDIR__|$bindir|g" \ |
| 88 | -e "s|__SYSCONFDIR__|$sysconfdir|g" \ |
| 89 | "$1" > "$2" |
| 90 | } |
| 91 | |
| 92 | render_template "$repo_root/packaging/templates/server-launch.sh" "$stage_root$libexecdir/server-launch" |
| 93 | render_template "$repo_root/packaging/templates/dns-launch.sh" "$stage_root$libexecdir/dns-launch" |
| 94 | render_template "$repo_root/packaging/templates/client-launch.sh" "$stage_root$libexecdir/client-launch" |
| 95 | chmod 0755 \ |
| 96 | "$stage_root$libexecdir/server-launch" \ |
| 97 | "$stage_root$libexecdir/dns-launch" \ |
| 98 | "$stage_root$libexecdir/client-launch" |
| 99 | |
| 100 | case "$target_os" in |
| 101 | linux) |
| 102 | mkdir -p "$stage_root$serviceroot" |
| 103 | install -m 0644 "$repo_root/packaging/linux/specter-server.service" "$stage_root$serviceroot/specter-server.service" |
| 104 | install -m 0644 "$repo_root/packaging/linux/specter-dns.service" "$stage_root$serviceroot/specter-dns.service" |
| 105 | install -m 0644 "$repo_root/packaging/linux/specter-client.service" "$stage_root$serviceroot/specter-client.service" |
| 106 | ;; |
| 107 | freebsd) |
| 108 | mkdir -p "$stage_root$serviceroot" |
| 109 | install -m 0755 "$repo_root/packaging/freebsd/specter_server" "$stage_root$serviceroot/specter_server" |
| 110 | install -m 0755 "$repo_root/packaging/freebsd/specter_dns" "$stage_root$serviceroot/specter_dns" |
| 111 | install -m 0755 "$repo_root/packaging/freebsd/specter_client" "$stage_root$serviceroot/specter_client" |
| 112 | ;; |
| 113 | illumos) |
| 114 | mkdir -p "$stage_root$serviceroot" |
| 115 | install -m 0644 "$repo_root/packaging/illumos/specter-server.xml" "$stage_root$serviceroot/specter-server.xml" |
| 116 | install -m 0644 "$repo_root/packaging/illumos/specter-dns.xml" "$stage_root$serviceroot/specter-dns.xml" |
| 117 | install -m 0644 "$repo_root/packaging/illumos/specter-client.xml" "$stage_root$serviceroot/specter-client.xml" |
| 118 | ;; |
| 119 | esac |
| 120 | |
| 121 | echo "$stage_root" |