#!/bin/bash # MyLogin.world: connects this server to your dashboard, then installs the mylogin-unraid 1.0.0 plugin and runs `mylogin-unraid setup`. # Run the command your dashboard shows: --code is valid 24 hours, --address is where you open Unraid. set -euo pipefail usage() { echo "Usage: bash <(curl -fsSL https://mylogin.world.compas.cs.stonybrook.edu/install/unraid) --code --address
. Copy the command from your dashboard." >&2; exit 1; } code= address= while [ $# -gt 0 ]; do [ $# -ge 2 ] || usage case $1 in --code) code=$2 ;; --address) address=$2 ;; *) usage ;; esac shift 2 done [ -n "$code" ] && [ -n "$address" ] || usage [ "$(id -u)" = 0 ] || { echo "Run this as root (Unraid: the terminal icon at the top right of the webGUI)." >&2; exit 1; } [ -f /etc/unraid-version ] || { echo "This is not an Unraid server." >&2; exit 1; } arch=$(uname -m) case $arch in x86_64) file=mylogin-unraid.plg sum=b0a87a2b877e59cd3f63529c9b15a9620315c6a5f6797eb249ae1296e0a34c98 ;; *) echo "Unsupported architecture: $arch" >&2; exit 1 ;; esac res=$(php -r 'echo json_encode(["code" => $argv[1], "address" => $argv[2], "hostname" => $argv[3]]);' -- "$code" "$address" "$(hostname)" | curl -sS -H 'content-type: application/json' --data-binary @- -w '\n%{http_code}' https://mylogin.world.compas.cs.stonybrook.edu/install/unraid) || { echo "Could not reach https://mylogin.world.compas.cs.stonybrook.edu." >&2; exit 1; } status=${res##*$'\n'} body=${res%$'\n'*} field() { printf %s "$body" | php -r '$v = json_decode(stream_get_contents(STDIN), true); foreach (array_slice($argv, 1) as $k) $v = is_array($v) ? ($v[$k] ?? null) : null; echo is_scalar($v) ? $v : "";' -- "$@"; } [ "$status" = 200 ] || { msg=$(field error message); echo "${msg:-Setup failed (HTTP $status). Try again.}" >&2; exit 1; } slug=$(field slug) relay=$(field relay) app_url=$(field appUrl) admin=$(field admin) dir=$(mktemp -d); trap 'rm -rf "$dir"' EXIT curl -fsSL -o "$dir/$file" https://mylogin.world.compas.cs.stonybrook.edu/downloads/unraid/"$file" echo "$sum $dir/$file" | sha256sum -c --quiet - || { echo "Checksum mismatch; nothing installed." >&2; exit 1; } # "forced": a re-run reinstalls the same version (after a failed setup, or to repair) /usr/local/sbin/plugin install "$dir/$file" forced mylogin-unraid setup --slug "$slug" --relay "$relay" --app-url "$app_url" --admin "$admin"