#!/bin/bash

set -e
set -x


postinstall_download() {
	# pre download some
	share_path=/usr/local/share

	pre_path=$share_path/sk-pre
	decky_path=$pre_path/decky
	decky_service_file=$decky_path/plugin_loader.service

	archive_file=pre-download/sk-pre.tar.gz
	temp_path=/tmp/sk-pre

	if [ -f $archive_file ]; then
		mkdir -p $temp_path
		tar -xzvf $archive_file -C $temp_path
	fi

	cp -av $temp_path/* $share_path

	cp -f $decky_service_file "/etc/systemd/system/plugin_loader.service"
	ln -sf "/etc/systemd/system/plugin_loader.service" "/etc/systemd/system/multi-user.target.wants/plugin_loader.service"

	# enable hhd service
	# ln -sf "/usr/lib/systemd/system/hhd@.service" "/etc/systemd/system/multi-user.target.wants/hhd@${USERNAME}.service"

	rm -rf $temp_path
	rm -rf pre-download
}
