#!/usr/local/bin/bash -e
pkg update
pkg upgrade -y
pkg install -y xinit xlibre curl wget bash libical
mkdir -p /usr/local/share/flan/

wget https://www.nonpaged.com/uascripts/uakron.xpm -O /usr/local/share/flan/uakron.xpm

cat << EOF > /usr/local/etc/flan.cfg
[main]
refresh=3600
days=3
logo=/usr/local/share/flan/uakron.xpm
title=College of Business Computer Labs
mode=xml
regex=^(.+)[[:space:]]?--[[:space:]]?(.*)

[fonts]
m=-*-helvetica-medium-r-normal-*-20-*-*-*-*-*-*-*
a=-*-times-bold-r-normal-*-24-*-*-*-*-*-*-*
l=-*-new century schoolbook-bold-r-normal-*-34-*-*-*-*-*-*-*
d=-*-helvetica-medium-r-normal-*-17-*-*-*-*-*-*-*
i=-*-new century schoolbook-medium-r-*-*-17-*-*-*-*-*-*-*

[colors]
t_bgc=#070c72
t_txt=#fffaa0
b_bgc=#e0e7f1
b_txt=#000000
s_bgc=#070c72
s_txt=#fffaa0
c_bgc=#fafafa

[text]
Mo-Th: 8:30AM-8:30PM\\https://uakron.edu/cba/
Fr: 8:30AM-5:30PM\\330-972-7036 | cobtechsupport@uakron.edu

[src]
$(wget -O- https://www.nonpaged.com/uascripts/cob/cal/$(hostname -s).txt)
EOF

cat << EOF > /usr/local/etc/X11/xorg.conf.d/10-ocelot.conf
Section "ServerFlags"
    Option "BlankTime" "0"
    Option "StandbyTime" "0"
    Option "SuspendTime" "0"
    Option "OffTime" "0"
EndSection
Section "Extensions"
    Option "DPMS" "Disable"
EndSection
EOF

cat << EOF > /etc/cron.d/flan
# FLAN helper scripts for at the College of Business
# https://www.nonpaged.com/software/cobutils#cal
#
# Copyright (C) 2025, 2026 Anton McClure <anton@nonpaged.com>
# All rights reserved.
@reboot root sleep 15 && curl https://www.nonpaged.com/uascripts/cob/cal/setup.csh | csh
0,15,30,45 * * * * root curl https://www.nonpaged.com/uascripts/cob/cal/setup.csh | csh
EOF

rm -rvf /tmp/flan/ || true
mkdir /tmp/flan/
cd /tmp/flan/
service flan stop || true
wget -O /tmp/flan.tgz https://release.dl.nonpaged.com/flan/flan_freebsd_x86-64.tgz
cd /tmp/
tar -xzvf flan.tgz
mv flan/flan /usr/local/bin/flan
mv flan/flan.rc /usr/local/etc/rc.d/flan
chmod +x /usr/local/bin/flan /usr/local/etc/rc.d/flan
service flan enable
service flan restart
