#!/bin/bash
cd $(dirname "$0")
cur_dir=$(pwd)

type -a xhost
if [ $? -ne 0 ];then 
    echo "install xhost..."
    emerge xhost
fi
type -a rpm
if [ $? -ne 0 ];then  
    echo "install rpm..."
    emerge rpm
fi
type -a env
if [ $? -ne 0 ];then  
    echo "install env..."
    emerge coreutils
fi
env-update && source /etc/profile

echo "rpmbuild rpm"
rpm -q rpm
if [ $? -ne 0 ]; then
    rpmbuild -ba rpm.spec
    rpm -ivh /root/rpmbuild/RPMS/noarch/rpm-4.10.0-1.noarch.rpm
fi

echo "rpmbuild gtk2"
rpm -q gtk2
if [ $? -ne 0 ]; then
    rpmbuild -ba gtk2.spec
    rpm -ivh /root/rpmbuild/RPMS/noarch/gtk2-2.24.12-2.noarch.rpm
fi

echo "modify rpm command"
if [ ! -e /usr/bin/rpm.orig ]; then
    mv /usr/bin/rpm /usr/bin/rpm.orig
    cp rpm /usr/bin/rpm
    chmod a+x /usr/bin/rpm
fi
