#!/bin/sh
# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Copyright 2010 Canonical Ltd
# Authors:
#   Michael Terry <michael.terry@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#stampdir="$HOME/.config"
#stamp="$stampdir/.omsk-start-page"
dir="/usr/share/ubuntu-light/home"
page="welcome.xhtml"

#if [ ! -e "$stamp" ]; then
#    page="welcome.xhtml"
#    mkdir -p "$stampdir"
#    touch "$stamp"
#fi

# First try ll_CC
ll="${LANG%%.*}"
ll="${ll%%@*}"
if [ ! -e "$dir/$ll/$page" ]; then
    # Else try ll
    ll="${LANG%%_*}"
    ll="${ll%%.*}"
    ll="${ll%%@*}"

    if [ ! -e "$dir/$ll/$page" ]; then
        ll="en" # final fallback
    fi
fi

# This will tell the page when we're online
netlaunch ln -s "$dir/images/offline.png" "/tmp/omsk-online.png" &

if [ -e "$dir/$ll/$page" ]; then
    chromium-browser "$dir/$ll/$page"
else
    chromium-browser
fi

rm -f "/tmp/omsk-online.png"
