#!/bin/bash -e
apt-get update -y
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get install -y xorg xinit build-essential pkg-config libx11-dev libxpm-dev libical-dev xfonts-100dpi
mkdir -p /usr/local/share/flan/

wget ftp://ftp.next.gen.oh.us/uakron/uakron.xpm -O /usr/local/share/flan/uakron.xpm

cat << END > /etc/flan.cfg
[main]
refresh=3600
days=3
logo=/usr/local/share/flan/uakron.xpm
title=College of Business Computer Labs
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

[ics]
$(wget -O- ftp://ftp.next.gen.oh.us/uakron/cob/cal/$(hostname -s).txt)
END

cat << END > /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
END

cat << END > /etc/cron.d/flan
# FLAN helper scripts for at the College of Business
# https://www.next.gen.oh.us/users/asm/cobutils.html#cal
#
# Copyright (C) 2025, 2026 Anton McClure <asm@next.gen.oh.us>
# All rights reserved.
@reboot root sleep 15 && wget -qO- ftp://ftp.next.gen.oh.us/uakron/cob/cal/setup.bash | bash
0 6 * * * root wget -qO- ftp://ftp.next.gen.oh.us/uakron/cob/cal/setup.bash | bash
END

rm -rvf /tmp/flan/ || true
mkdir /tmp/flan/
cd /tmp/flan/
wget -O- "ftp://ftp.next.gen.oh.us/users/asm/flan/" | grep -oE '[^[:space:]]+\.tar\.gz">' | sort -V | tail -n 1 | sed 's/href="//g' | sed 's/">//g' | xargs -I {} wget "{}"
tar -xzvf *.tar.gz
cd flan*/
./configure
make
pkill -5 flan
make install
cp flan.service /etc/systemd/system/flan.service
systemctl daemon-reload
systemctl enable flan
systemctl restart flan
