Files
lodge/backend/internal/server/install.sh
T

43 lines
1.1 KiB
Bash

#!/bin/sh
set -eu
url="{{URL}}"
code="{{CODE}}"
mode="{{MODE}}"
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$arch" in
x86_64 | amd64) arch=amd64 ;;
aarch64 | arm64) arch=arm64 ;;
*) echo "lodge: unsupported architecture $arch" >&2; exit 1 ;;
esac
bin="$HOME/.local/bin"
mkdir -p "$bin"
curl -fsSL "$url/dl/lodge-$os-$arch" -o "$bin/lodge.new"
chmod +x "$bin/lodge.new"
mv "$bin/lodge.new" "$bin/lodge"
if [ "$mode" = login ]; then
"$bin/lodge" login "$url" "$code"
"$bin/lodge" install
else
plist="$HOME/Library/LaunchAgents/com.kotikot.lodge.plist"
unit="$HOME/.config/systemd/user/lodge.service"
restarted=yes
if [ -f "$plist" ]; then
launchctl kickstart -k "gui/$(id -u)/com.kotikot.lodge" || restarted=no
elif [ -f "$unit" ]; then
systemctl --user restart lodge.service || restarted=no
fi
[ "$restarted" = yes ] || echo "lodge: restart the running daemon so it runs the new binary" >&2
(cd / && "$bin/lodge" remote "$url" "$code")
[ -f "$plist" ] || [ -f "$unit" ] || "$bin/lodge" install
fi
case ":$PATH:" in
*":$bin:"*) ;;
*) echo "lodge: add $bin to your PATH to use the lodge command" ;;
esac