#!/bin/bash # MyLogin.world: connects this host to your dashboard, then installs mylogin-pihole 1.0.0 and runs `mylogin-pihole setup`. # Run the command your dashboard shows: --code is valid 24 hours, --address is where you open Pi-hole. set -euo pipefail usage() { echo "Usage: bash <(curl -fsSL https://mylogin.world.compas.cs.stonybrook.edu/install/pihole) --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 (sudo -i) on the host that runs Pi-hole (with Docker: the Docker host)." >&2; exit 1; } arch=$(dpkg --print-architecture) case $arch in amd64) file=mylogin-pihole_1.0.0_amd64.deb sum=11ae84c1ffd9d6e9dde4cdb34ef24c1d662820914fcbb5fbf838de4dda0ac4d1 ;; arm64) file=mylogin-pihole_1.0.0_arm64.deb sum=bc868b2e0eae88704881f11ab29d611f1b662c3f5c6ea429aad8e2af8f358151 ;; armhf) file=mylogin-pihole_1.0.0_armhf.deb sum=2d5923f3ff065e3bda08f128017806b417dc8229bd40e58b6cebbd9a16c0b605 ;; *) 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/pihole) || { 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/pihole/"$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-pihole setup --slug "$slug" --relay "$relay" --app-url "$app_url" --admin "$admin"