#!/bin/sh

LOCAL_ROMS_DIR=/storage/roms
DATA_LOCAL_DIR=/storage/.config/emulationstation
THEMES_LOCAL_DIR=/storage/roms/themes
DATA_DIR=/usr/share/emulationstation-batocera/resources
ES_SYSTEMS_CFG=/etc/emulationstation-batocera/es_systems.cfg
THEMES_SYS_DIR=/usr/share/emulationstation-batocera/themes

if [ ! -d "$DATA_LOCAL_DIR"/resources ]; then
    mkdir -p "$DATA_LOCAL_DIR"/logs
    cp -r "$DATA_DIR" "$DATA_LOCAL_DIR"
    cp -r "/usr/share/roms" "/storage"
    if [ ! -f /storage/.config/emulationstation/es_systems.cfg ]; then
	cp "$ES_SYSTEMS_CFG" "$DATA_LOCAL_DIR"
    fi
fi

if [[ ! -d "$THEMES_LOCAL_DIR" ]]; then
    cp -r "$THEMES_SYS_DIR" "$LOCAL_ROMS_DIR"/
fi

exec emulationstation --no-splash

