#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)

. /etc/profile

if [ -d "/storage/cache/.cores" ]
then
  rm -rf /storage/cache/.cores
fi

if [ ! -d "/tmp/cache" ]
then
  mkdir -p /tmp/cache
fi

ln -sf /tmp/cache /storage/cache/.cores

if [ ! -d "/storage/.config/profile.d" ]
then
  mkdir -p /storage/.config/profile.d
fi

### Inspect the system config and revert
### to last known good state if corrupt.
/usr/bin/chksysconfig verify

### Clean up settings
sort_settings

### We do not want to mount the cloud drive on startup
### so we'll reset the mount option to 0.
set_setting clouddrive.mounted 0

### Set up the runtime directory.
if [ ! -d "/var/run/0-runtime-dir" ]
then
  mkdir -p /var/run/0-runtime-dir
fi

chmod 0700 /var/run/0-runtime-dir
