#!/bin/sh
# copyright (C) 2013 FUJITSU LIMITED All Rights Reserved

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
# 02110-1301, USA.

if [ $# -ne 0 ]; then
        echo "usage lxcf-init"
        exit 1
fi

# create /opt dir
mkdir -p /opt/lxcf
chmod 755 /opt/lxcf

# create /etc dir
mkdir -p /etc/lxcf
chmod 755 /etc/lxcf
mkdir -p /etc/lxcf/rsc
chmod 755 /etc/lxcf/rsc

# create the new .ssh directory
mkdir -p /root/.ssh
chmod 700 /root/.ssh
touch /root/.ssh/known_hosts
chmod 644 /root/.ssh/known_hosts

# generate a ssh key
if ! [ -e /root/.ssh/lxcf_rsa ] ; then
  /usr/lib/lxcf/lxcf-keygen
fi

if ! grep "LXCF283AX" /root/.bashrc >& /dev/null ; then
  echo   >> /root/.bashrc
  echo "# The key to LXCF is registered (LXCF283AX)"  >> /root/.bashrc
  echo "if [ -e /root/.ssh/lxcf_rsa ] ; then"  >> /root/.bashrc
  echo "  eval \`ssh-agent\` >& /dev/null"  >> /root/.bashrc 
  echo "  ssh-add /root/.ssh/lxcf_rsa >& /dev/null"  >> /root/.bashrc
  echo "fi"  >> /root/.bashrc
  echo   >> /root/.bashrc
#  echo "if [ -e /usr/lib/lxcf/sbin/update-alert -a ! -e /etc/lxcf/separate ] ; then" >> /root/.bashrc
#  echo "  alias rpm=\"/usr/lib/lxcf/sbin/update-alert rpm\"" >> /root/.bashrc
#  echo "  alias yum=\"/usr/lib/lxcf/sbin/update-alert yum\"" >> /root/.bashrc
#  echo "fi"  >> /root/.bashrc
#  echo   >> /root/.bashrc
fi

echo

exit 0

