#!/bin/bash # MyLogin.world: connects this node to your dashboard, then installs mylogin-pve 1.0.0 and runs `mylogin-pve setup`. # Run the command your dashboard shows: --code is valid 24 hours, --address is where you open Proxmox. set -euo pipefail usage() { echo "Usage: bash <(curl -fsSL https://mylogin.world.compas.cs.stonybrook.edu/install/proxmox) --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 (Proxmox: Node > Shell)." >&2; exit 1; } arch=$(dpkg --print-architecture) case $arch in amd64) file=mylogin-pve_1.0.0_amd64.deb sum=c573881e053d81132a794fc40449976cf1e67b76075beddf74211286a3fbe6e3 ;; arm64) file=mylogin-pve_1.0.0_arm64.deb sum=7f561f2027cecfa5378dbdcb204fd15baf027d32b1bb4cd30ac342de0fbd14b1 ;; *) echo "Unsupported architecture: $arch" >&2; exit 1 ;; esac res=$(perl -MJSON::PP -e 'print encode_json({ code => $ARGV[0], address => $ARGV[1], hostname => $ARGV[2] })' -- "$code" "$address" "$(hostname)" | curl -sS -H 'content-type: application/json' --data-binary @- -w '\n%{http_code}' https://mylogin.world.compas.cs.stonybrook.edu/install/proxmox) || { echo "Could not reach https://mylogin.world.compas.cs.stonybrook.edu." >&2; exit 1; } status=${res##*$'\n'} body=${res%$'\n'*} field() { printf %s "$body" | perl -MJSON::PP -e 'my $v = eval { decode_json(join "", ) }; $v = ref $v eq "HASH" ? $v->{$_} : undef for @ARGV; print $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; chmod 755 "$dir" curl -fsSL -o "$dir/$file" https://mylogin.world.compas.cs.stonybrook.edu/downloads/proxmox/"$file" echo "$sum $dir/$file" | sha256sum -c --quiet - || { echo "Checksum mismatch; nothing installed." >&2; exit 1; } chmod 644 "$dir/$file" apt-get install -y "$dir/$file" mylogin-pve setup --slug "$slug" --relay "$relay" --app-url "$app_url" --admin "$admin"