#!/bin/bash

STAMP_DIR="$HOME/.config"
STAMP_FILE="$STAMP_DIR/.oem-first-login.stamp"

mkdir -p "$STAMP_DIR"

if [ -f $STAMP_FILE ]; then
  exit 0
fi


## Create Thunderbird profile, so Import dialog will not be triggered
THUNDER_DIR="$HOME/.mozilla-thunderbird"

if [ ! -d $THUNDER_DIR ]; then
	mkdir -p $THUNDER_DIR

	# Generate a random 8-char profile code (doesn't use full range of
	# alphabet, but not a big deal).
	CODE=`date | md5sum`
	CODE=${CODE:0:8}

	# Write .ini file
echo "[General]
StartWithLastProfile=1

[Profile0]
Name=default
IsRelative=1
Path=${CODE}.default" > "$THUNDER_DIR/profiles.ini"

	PROFILE_DIR="$THUNDER_DIR/${CODE}.default"
	mkdir -p $PROFILE_DIR

	# Now write empty localstore.rdf
	STORE_FILE="$PROFILE_DIR/localstore.rdf"
	touch $STORE_FILE

fi

touch $STAMP_FILE
exit 0
