#!/bin/sh /etc/rc.common
# Copyright (C) 2020-2025 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
# Released under GPL 3. See LICENSE for the full terms.

{
	START=99
	STOP=10
	USE_PROCD=1
}

start_service()
{
	if [ -f /etc/backup/installed_packages.txt ]; then
		if [ -e /usr/bin/apk ]; then
			apk update >/dev/null 2>&1
			if [ -z "$(grep '\toverlay' /etc/backup/installed_packages.txt | cut -f1 | xargs -r apk add)" ]; then
				rm /etc/backup/installed_packages.txt
			fi
		else
			opkg -V0 update >/dev/null 2>&1
			if [ -z "$(grep '\toverlay' /etc/backup/installed_packages.txt | cut -f1 | xargs -r opkg -V0 install)" ]; then
				rm /etc/backup/installed_packages.txt
			fi
		fi
	fi
}

