#!/bin/sh

[ -n "$IPKG_INSTROOT" ] && exit 0

chmod 0755 /usr/libexec/emmc-health 2>/dev/null || true

if ! command -v mmc >/dev/null 2>&1 && [ -x /bin/opkg ]; then
	: >/tmp/luci-app-emmc-health-opkg.log
	echo "[luci-app-emmc-health] launcher invoked" >>/tmp/luci-app-emmc-health-opkg.log
	if [ -x /usr/libexec/emmc-health-install-mmc ]; then
		if command -v nohup >/dev/null 2>&1; then
			nohup /usr/libexec/emmc-health-install-mmc >>/tmp/luci-app-emmc-health-opkg.log 2>&1 </dev/null &
		elif command -v setsid >/dev/null 2>&1; then
			setsid /usr/libexec/emmc-health-install-mmc >>/tmp/luci-app-emmc-health-opkg.log 2>&1 </dev/null &
		else
			/usr/libexec/emmc-health-install-mmc >>/tmp/luci-app-emmc-health-opkg.log 2>&1 </dev/null &
		fi
	fi
fi

if [ -x /etc/init.d/rpcd ]; then
	/etc/init.d/rpcd reload 2>/dev/null || /etc/init.d/rpcd restart 2>/dev/null || true
fi

if [ -x /etc/init.d/uhttpd ]; then
	/etc/init.d/uhttpd reload 2>/dev/null || /etc/init.d/uhttpd restart 2>/dev/null || true
fi

exit 0
