#!/bin/bash

# Check if user pijuice exists
if ! id -u pijuice > /dev/null 2>&1; then
	echo "User pijuice does not exist"
	echo "Is pijuice-base (>= 1.4) installed?"
	exit 1
fi

echo "Setting ownership and permissions of pijuice_gui"
chown pijuice.pijuice /usr/bin/pijuice_gui32 /usr/bin/pijuice_gui64
chmod 4755 /usr/bin/pijuice_gui32 /usr/bin/pijuice_gui64
chown pijuice.pijuice /usr/bin/pijuice_gui.py
chmod -x /usr/bin/pijuice_gui.py

# Link to pijuice_gui for current architecture
arch=$(dpkg --print-architecture)
if [ "$arch" == "arm64" ]; then
	ln -sf /usr/bin/pijuice_gui64 /usr/bin/pijuice_gui
else
	ln -sf /usr/bin/pijuice_gui32 /usr/bin/pijuice_gui
fi

# Start pijuice_tray
echo "Starting pijuice_tray"
sudo -u pijuice sh -c '/usr/bin/pijuice_tray.py > /dev/null 2>&1' &

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
