#!/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.

APT_GET="`which apt-get 2> /dev/null`"
APT_CONFIG="`which apt-config 2> /dev/null`"

find_apt_sources() {
  APTDIR=$(apt_config_val Dir)
  APTETC=$(apt_config_val 'Dir::Etc')
  APT_SOURCES="$APTDIR$APTETC$(apt_config_val 'Dir::Etc::sourcelist')"
  APT_SOURCESDIR="$APTDIR$APTETC$(apt_config_val 'Dir::Etc::sourceparts')"
}

# Parse apt configuration and return requested variable value.
apt_config_val() {
  APTVAR="$1"
  if [ -x "$APT_CONFIG" ]; then
    "$APT_CONFIG" dump | sed -e "/^$APTVAR /"'!d' -e "s/^$APTVAR \"\(.*\)\".*/\1/"
  fi
}

# Remove our custom sources list file.
# Returns:
# 0 - successfully removed, or not configured
# !0 - failed to remove
clean_sources_lists() {

find_apt_sources

rm -f "$APT_SOURCESDIR/opera.list"
rm -f "$APT_SOURCESDIR/venenux*.list"
rm -f "$APT_SOURCESDIR/google-chrome*.list"
}

find_apt_sources

action="$1"

# Only do complete clean-up on purge.
if [ "$action" != "purge" ] ; then

rm -f $APT_SOURCESDIR/venenux*.list
rm -f /etc/apt/sources.list.d/venenux*.list
  exit 0
fi

clean_sources_lists

exit 0