#!/bin/sh

NOWSIGNAGE_VERSION=5.3.41
USER_NAME=display

## Install Dependencies
#apt install sway -y # ~69.0MB
#apt install libfuse2 -y # 362.0KB
#apt install libnss3 -y # ~1504.0KB
#apt install libatk1.0-0 -y # ~223.0KB
#apt install libatk1.0-0 -y # ~1335.0KB
#apt install libcups2-dev -y # ~88.0MB
#apt install libgtk-3-dev -y # ~49.8MB
#apt install libasound2 -y # ~510.0KB

## Download NowSignage
wget -O /dos/now_signage.appimage https://cdn.nowsignage.com/linux/NowSignage+Client-$NOWSIGNAGE_VERSION.AppImage
chmod +x /dos/now_signage.appimage

## Sway Setup
cat <<EOF >> /etc/sway/config.d/50-systemd-user.conf
exec /dos/now_signage.appimage --no-sandbox
EOF

## User Setup
useradd --create-home --shell /bin/bash $USER_NAME
passwd -l $USER_NAME
loginctl enable-linger $USER_NAME

mkdir -p /home/$USER_NAME/.config/systemd/user/default.target.wants

cat <<EOF > /home/$USER_NAME/.config/systemd/user/sway.service
[Unit]
Description=Sway compositor

[Service]
ExecStart=/usr/bin/sway
Restart=always
RestartSec=2

[Install]
WantedBy=default.target
EOF

chown $USER_NAME /home/$USER_NAME -R

systemctl --user -M $USER_NAME@ enable sway.service
