1 #!/bin/sh2 # Installs the two binaries and the unit. It starts nothing and downloads3 # nothing; the operator writes the deploy file and enables the unit.4 #5 # The script has two layouts. In a checkout it is `ops/install.sh` and the6 # binaries are below `target/release`; in a release directory it sits beside7 # `inf3r-web`, `inf3r`, and `inf3r-web.service`. The version argument selects8 # `releases/build/<version>/` when a checkout has one.9 set -eu10 11 here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)12 13 # Find the pair of files that this script belongs to. A checkout is the parent14 # of `ops/`; a release is the directory that holds the unit beside the script.15 if [ -f "$here/../Cargo.toml" ] && [ -f "$here/../ops/inf3r-web.service" ]; then16 source=$here/..17 checkout=yes18 else19 checkout=no20 fi21 22 if [ "$checkout" = yes ]; then23 checkout_root=$source24 if [ "$#" -gt 0 ] && [ -d "$checkout_root/releases/build/$1" ]; then25 bindir=$checkout_root/releases/build/$126 unit=$bindir/inf3r-web.service27 else28 bindir=${CARGO_TARGET_DIR:-$checkout_root/target}/release29 unit=$checkout_root/ops/inf3r-web.service30 fi31 else32 bindir=$here33 unit=$here/inf3r-web.service34 fi35 if [ "$checkout" = yes ]; then36 docdir=$checkout_root37 else38 docdir=$bindir39 fi40 41 for binary in inf3r-web inf3r inf3r-probe; do42 if [ ! -x "$bindir/$binary" ]; then43 printf 'install.sh: no executable %s in %s\n' "$binary" "$bindir" >&244 exit 145 fi46 done47 if [ ! -f "$unit" ]; then48 printf 'install.sh: no inf3r-web.service beside %s\n' "$bindir" >&249 exit 150 fi51 52 # DESTDIR makes the file placement testable and is the usual package staging53 # root. It does not create the system account; that belongs to a real install.54 root=${DESTDIR:-}55 bindest=$root/usr/local/bin56 unitdest=$root/etc/systemd/system57 statedest=$root/var/lib/inf3r58 59 install -d "$bindest" "$unitdest"60 install -m 0755 "$bindir/inf3r-web" "$bindest/inf3r-web"61 install -m 0755 "$bindir/inf3r" "$bindest/inf3r"62 install -m 0755 "$bindir/inf3r-probe" "$bindest/inf3r-probe"63 install -m 0644 "$unit" "$unitdest/inf3r-web.service"64 if [ -f "$docdir/LICENSE" ]; then65 install -d "$root/usr/share/licenses/inf3r"66 install -m 0644 "$docdir/LICENSE" "$root/usr/share/licenses/inf3r/LICENSE"67 fi68 if [ -f "$docdir/NOTICE" ]; then69 install -d "$root/usr/share/licenses/inf3r"70 install -m 0644 "$docdir/NOTICE" "$root/usr/share/licenses/inf3r/NOTICE"71 fi72 73 if [ -n "$root" ]; then74 install -d "$statedest"75 else76 # The service account exists only for this daemon.77 if ! id -u inf3r >/dev/null 2>&1; then78 useradd --system --home /var/lib/inf3r --shell /usr/sbin/nologin inf3r79 fi80 install -d -o inf3r -g inf3r /var/lib/inf3r81 fi82 83 # A system service account normally cannot reach the interactive user's84 # rootless Docker socket. Point it at the documented setup instead of letting a85 # container bind fail at the first request.86 if [ -z "$root" ] && [ -f /etc/inf3r/deploy.toml ] &&87 grep -Eq '^[[:space:]]*runtime[[:space:]]*=[[:space:]]*"container"' /etc/inf3r/deploy.toml &&88 [ ! -f /etc/inf3r/docker.env ]; then89 printf '%s\n' \90 'install: this deploy has a container bind but inf3r has no Docker setup.' \91 'install: use the compose control, a user unit under the Docker user, or' \92 'install: set DOCKER_HOST in /etc/inf3r/docker.env and grant inf3r socket access.' >&293 fi94 95 # The operator runs these three lines next; this script starts no service.96 printf '%s\n' \97 'systemctl daemon-reload' \98 'install -Dm0600 deploy.toml /etc/inf3r/deploy.toml' \99 'systemctl enable --now inf3r-web'