#!/bin/sh
# simple script for setting up PowerGoblin on RPi / DietPi

# openjdk, libhid, liburing - runtime & drivers
# build-essential, unzip - building the application & demo
# dbus - timedatectl
# openssh - remote control
# screen - starting the service remotely

apt update
apt install openjdk-25-jre libhidapi-dev liburing-dev build-essential unzip dbus openssh-server screen

mkdir -p /opt/powergoblin

wget https://tech.utugit.fi/soft/tools/power/powergoblin/powergoblin.jar -O /opt/powergoblin/powergoblin.jar
wget "https://gitlab.utu.fi/tech/soft/tools/power/powergoblin/-/raw/main/stuff/systemd-service/powergoblin.service" -O /etc/systemd/system/powergoblin.service
sed -i 's/User=powergoblin/User=root/g' /etc/systemd/system/powergoblin.service

systemctl daemon-reload
systemctl enable powergoblin.service
systemctl start dbus

timedatectl set-timezone Europe/Helsinki
echo Europe/Helsinki > /etc/timezone

echo 'java --enable-native-access=ALL-UNNAMED -jar /opt/powergoblin/powergoblin.jar $*' > /usr/local/bin/powergoblin
chmod +x /usr/local/bin/powergoblin

mkdir /demo
cd /demo

wget "https://gitlab.utu.fi/tech/education/green/sortdemo/-/archive/main/sortdemo-main.zip?ref_type=heads" -O demo.zip
unzip demo.zip

