#!/bin/bash
if [ ! -f /usr/src/hbase-0.20.3.tar.gz ]; then
  wget http://ftp.twaren.net/Unix/Web/apache/hadoop/hbase/hbase-0.20.3/hbase-0.20.3.tar.gz -O /usr/src/hbase-0.20.3.tar.gz
fi

tar zxvf /usr/src/hbase-0.20.3.tar.gz -C /opt
ln -s /opt/hbase-* /opt/hbase

cp /opt/hadoop/conf/core-site.xml /opt/hbase/conf
cp /opt/hadoop/conf/hdfs-site.xml /opt/hbase/conf
cp /opt/hadoop/conf/mapred-site.xml /opt/hbase/conf

cat >> /opt/hbase/conf/hbase-env.sh << EOF
  export JAVA_HOME=$JAVA_HOME
  export HADOOP_CONF_DIR=/opt/hadoop/conf
  export HBASE_HOME=/opt/hbase
  export HBASE_MANAGES_ZK=true
EOF

cat > /opt/hbase/conf/hbase-site.xml << EOF
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>hdfs://localhost:9000/hbase</value>
  </property>
  <property>
    <name>hbase.cluster.distributed</name>
    <value>true</value>
  </property>
</configuration>
EOF

echo "export PATH=/opt/hbase/bin/:\$PATH" >> /etc/profile
echo "/bin/stop-hbase" > ~/.bash_logout
echo "/bin/stop-hadoop" >> ~/.bash_logout
echo "/bin/stop-hbase" > /etc/skel/.bash_logout
echo "/bin/stop-hadoop" >> /etc/skel/.bash_logout

cat > ~/hbase-test << EOF
create 'test','data'
put 'test','row1','data:1','v1'
put 'test','row2','data:2','v2'
put 'test','row3','data:3','v3'
scan 'test'
disable 'test'
drop 'test'
list
exit
EOF