#!/bin/sh
#
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

set -e

@@include@@../common/postinst.include

# Add to the alternatives system
#
# On Ubuntu 12.04, we have the following priorities
# (which can be obtain be installing browsers and running
# update-alternatives --query x-www-browser):
#
# /usr/bin/epiphany-browser  85
# /usr/bin/firefox           40
# /usr/bin/konqueror         30
#
# While we would expect these values to be keyed off the most popular
# browser (Firefox), in practice, we treat Epiphany as the lower bound,
# resulting in the following scheme:

CHANNEL=@@CHANNEL@@
case $CHANNEL in
  stable )
    # Good enough to be the default.
    PRIORITY=200
    ;;
  beta )
    # Almost good enough to be the default. (Firefox stable should arguably be
    # higher than this, but since that's below the "Epiphany threshold", we're
    # not setting our priority below it. Anyone want to poke Firefox to raise
    # their priority?)
    PRIORITY=150
    ;;
  unstable )
    # Unstable, give it the "lowest" priority.
    PRIORITY=120
    ;;
  * )
    PRIORITY=0
    ;;
esac

update-alternatives --install /usr/bin/x-www-browser x-www-browser \
  /usr/bin/@@USR_BIN_SYMLINK_NAME@@ $PRIORITY
update-alternatives --install /usr/bin/gnome-www-browser gnome-www-browser \
  /usr/bin/@@USR_BIN_SYMLINK_NAME@@ $PRIORITY

update-alternatives --install /usr/bin/google-chrome google-chrome \
  /usr/bin/@@USR_BIN_SYMLINK_NAME@@ $PRIORITY

@@include@@../common/apt.include

@@include@@../common/symlinks.include

remove_udev_symlinks
add_udev_symlinks

## MAIN ##
if [ ! -e "$DEFAULTS_FILE" ]; then
  echo 'repo_add_once="true"' > "$DEFAULTS_FILE"
  echo 'repo_reenable_on_distupgrade="true"' >> "$DEFAULTS_FILE"
fi

# Run the cron job immediately to perform repository configuration.
nohup sh /etc/cron.daily/@@PACKAGE@@ > /dev/null 2>&1 &