#!/bin/sh
export NO_STRIP=1
##############################################################
pkgbase='google_chrome'
release='stable_current'
if [ -x /usr/bin/rpm ]; then
    vers=$(rpm -qpi google-chrome-stable_current_x86_64.rpm 2>/dev/null | egrep '^Version' | awk '{ print $3 }')
else
    vers=$release
fi
src="google-chrome-${vers}"
url="https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm"
verify=""
arch=`uname -m`
build=B1
OPT_CONFIG='--disable-static --enable-shared'
DOCS=''
patchfiles=''
compress=tzst
##############################################################

source /usr/share/plamobuild_functions.sh

# このスクリプトで使う1文字変数の意味
#
# $W : このスクリプトを動かすカレントディレクトリ
# $S : ソースコードのあるディレクトリ(デフォルト: $W/${src})
# $B : ビルド用ディレクトリ(デフォルト: /tmp/build{,32})
# $P : ビルドしたファイルをインストールするディレクトリ(デフォルト: $W/work)

if [ $# -eq 0 ] ; then
  opt_download=0 ; opt_config=1 ; opt_build=1 ; opt_package=1
else
  opt_download=0 ; opt_config=0 ; opt_build=0 ; opt_package=0
  for i in $@ ; do
    case $i in
    download) opt_download=1 ;;
    config) opt_config=1 ;;
    build) opt_build=1 ;;
    package) opt_package=1 ;;
    esac
  done
fi
if [ $opt_download -eq 1 ] ; then
  download_sources
fi

if [ $opt_config -eq 1 ] ; then
  rpm2tar ${url##*/}
  if [ $? != 0 ]; then
    echo "failed to convert rpm to tar."
    exit 255
  fi
fi

if [ $opt_build -eq 1 ] ; then
  echo "There is nothing to do."
fi

if [ $opt_package -eq 1 ] ; then
  check_root
  if [ -d $P ]; then
    rm -rf $P
  fi
  mkdir -p $P
  tar xf $W/${pkgbase/_/-}-${release}_${arch}.tar -C $P

  rm -rf $P/etc
  rm -rf $P/usr/share/gnome-control-center

################################
#      install tweaks
#  strip binaries, delete locale except ja, compress man, 
#  install docs and patches, compress them and  chown root.root
################################
  install_tweak

#############################
#   convert symlink to null file and 
#   add "ln -sf" command into install/doinst.sh
################################
  convert_links

  cd $P
  /sbin/makepkg ../$pkg.$compress <<EOF
y
1
EOF

fi