#!/bin/bash
set -uo pipefail

# Finishes setting a classroom machine up: the things that need the
# network and the apt lock, and so cannot run from the package postinst.
#
# Run from ekklesia-classroom-provision.service at every boot. Each step
# checks whether it is already done and returns immediately if so, so a
# provisioned machine costs nothing, and a machine that was offline the
# first time gets another go at the next boot.
#
# Nothing here is allowed to fail the boot. A classroom with no DVD
# codecs is still a working classroom.

log() {
    echo "[classroom-provision] $1"
}

log "starting"

if /usr/local/bin/classroom-chrome-setup; then
    :
else
    log "WARNING: Google Chrome is not installed. The Browser button will"
    log "WARNING: not work until this succeeds. Retrying at the next boot,"
    log "WARNING: or run: sudo classroom-chrome-setup"
fi

# DVD codecs are only fetched for rooms that actually have a drive.
if /usr/local/bin/classroom-dvd-css-setup --if-enabled; then
    :
else
    log "WARNING: commercial DVD support is not set up. Unencrypted discs"
    log "WARNING: still play. Retrying at the next boot, or run:"
    log "WARNING: sudo classroom-dvd-css-setup"
fi

log "finished"

# Provisioning is best-effort by design.
exit 0
