#------------------------------------------------------------------------------
#   chrome.spec
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
#   Prologue information
#------------------------------------------------------------------------------
Summary         : @@MENUNAME
License         : Multiple, see @@PRODUCTURL
Name            : @@rpm_package_filename
Version         : @@version
Release         : @@package_release
Group           : Applications/Internet
Vendor          : @@COMPANY_FULLNAME
Url             : @@PRODUCTURL
Packager        : @@MAINTNAME <@@MAINTMAIL>

Provides        : @@rpm_provides = %{version}
Requires        : @@rpm_depends
Requires(post)  : %{_sbindir}/update-alternatives
Requires(preun) : %{_sbindir}/update-alternatives
Autoreqprov     : No

BuildRoot       : %{_tmppath}/%{name}-%{version}-root

# The prefix is pretty important; RPM uses this to figure out
# how to make a package relocatable
prefix          : /opt

#------------------------------------------------------------------------------
#   Description
#------------------------------------------------------------------------------
%Description
@@SHORTDESC

@@FULLDESC

#------------------------------------------------------------------------------
#   Build rule - How to make the package
#------------------------------------------------------------------------------
%build

#------------------------------------------------------------------------------
#       Installation rule - how to install it (note that it
#   gets installed into a temp directory given by $RPM_BUILD_ROOT)
#------------------------------------------------------------------------------
%install
rm -rf "$RPM_BUILD_ROOT"

if [ -z "@@staging_dir" -o ! -d "@@staging_dir" ] ; then
    echo "@@staging_dir appears to be incorrectly set - aborting"
    exit 1
fi

if [ -z "@@INSTALLDIR" -o ! -d "@@staging_dir/@@INSTALLDIR" ] ; then
    echo "@@INSTALLDIR appears to be incorrectly set - aborting"
    exit 1
fi

install -m 755 -d \
  "$RPM_BUILD_ROOT/etc" \
  "$RPM_BUILD_ROOT/opt" \
  "$RPM_BUILD_ROOT/usr"
# This is hard coded for now
cp -a "@@staging_dir/etc/" "$RPM_BUILD_ROOT/"
cp -a "@@staging_dir/opt/" "$RPM_BUILD_ROOT/"
cp -a "@@staging_dir/usr/" "$RPM_BUILD_ROOT/"

#------------------------------------------------------------------------------
#   Rule to clean up a build
#------------------------------------------------------------------------------
%clean
rm -rf "$RPM_BUILD_ROOT"

#------------------------------------------------------------------------------
#   Files listing.
#------------------------------------------------------------------------------
%files
%defattr(-,root,root)
#%doc README

# We cheat and just let RPM figure it out for us; everything we install
# should go under this prefix anyways.
@@INSTALLDIR

# Be explicit about the files we scatter throughout the system we don't
# accidentally "own" stuff that's not ours (crbug.com/40194046).
/etc/cron.daily/@@PACKAGE
%ghost %attr(755,root,root) /usr/bin/@@package_orig
/usr/bin/@@usr_bin_symlink_name
/usr/share/appdata/@@PACKAGE.appdata.xml
/usr/share/applications/@@PACKAGE.desktop
/usr/share/applications/@@rdn_desktop.desktop
/usr/share/gnome-control-center/default-apps/@@PACKAGE.xml
%docdir /usr/share/man/man1
# These two files will be the same on non-stable channels.
/usr/share/man/man1/@@PACKAGE.1.gz
@@rpm_optional_man_page

#------------------------------------------------------------------------------
#   Pre install script
#------------------------------------------------------------------------------
%pre

exit 0




#------------------------------------------------------------------------------
#   Post install script
#------------------------------------------------------------------------------
%post

@@include@@../common/variables.include

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

@@include@@../common/rpm.include

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

remove_nss_symlinks
add_nss_symlinks

remove_udev_symlinks

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

. "$DEFAULTS_FILE"

if [ "$repo_add_once" = "true" ]; then
  determine_rpm_package_manager

  for PACKAGEMANAGER in ${PACKAGEMANAGERS[*]}
  do
    case $PACKAGEMANAGER in
    "yum")
      install_yum
      ;;
    "zypp")
      install_zypp
      ;;
    esac
  done
fi

CHANNEL=@@channel
case $CHANNEL in
  stable )
    PRIORITY=200
    ;;
  beta )
    PRIORITY=150
    ;;
  unstable )
    PRIORITY=120
    ;;
  * )
    PRIORITY=0
    ;;
esac

%{_sbindir}/update-alternatives --install /usr/bin/@@package_orig \
  @@package_orig /usr/bin/@@usr_bin_symlink_name $PRIORITY

exit 0


#------------------------------------------------------------------------------
#   Pre uninstallation script
#------------------------------------------------------------------------------
%preun

if [ "$1" -eq "0" ]; then
  mode="uninstall"
elif [ "$1" -eq "1" ]; then
  mode="upgrade"
fi

@@include@@../common/rpm.include

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

# Only remove menu items and symlinks on uninstall. When upgrading,
# old_pkg's %preun runs after new_pkg's %post.
if [ "$mode" = "uninstall" ]; then
@@include@@../common/prerm.include
  remove_nss_symlinks
  remove_udev_symlinks

  %{_sbindir}/update-alternatives --remove @@package_orig \
    /usr/bin/@@usr_bin_symlink_name
fi

# On Debian we only remove when we purge. However, RPM has no equivalent to
# dpkg --purge, so this is all disabled.
#
#determine_rpm_package_manager
#
#for PACKAGEMANAGER in ${PACKAGEMANAGERS[*]}
#do
#  case $PACKAGEMANAGER in
#  "yum")
#    remove_yum
#    ;;
#  "zypp")
#    remove_zypp
#    ;;
#  esac
#done

exit 0

#------------------------------------------------------------------------------
#   Post uninstallation script
#------------------------------------------------------------------------------
%postun

exit 0
