#!/bin/bash

location="$1"
export DCONF_PROFILE="$location/dconf_profile"
export XDG_DATA_HOME="$location/data"
export XDG_CACHE_HOME="$location/cache"
LIBRARY="$location/library"

echo "Setting up custom environment..."

mkdir -p "$location"
mkdir -p "$XDG_DATA_HOME"
mkdir -p "$XDG_CACHE_HOME"
mkdir -p "$LIBRARY"

echo "user-db:shotwell" > "$DCONF_PROFILE"
old_library=$(gsettings get org.yorba.shotwell.preferences.files import-dir)
if test "x$old_library" = "x''"
then
    gsettings set org.yorba.shotwell.preferences.files import-dir "$LIBRARY"
else
    echo "Not changing library, using $old_library"
fi
./shotwell
