#!/bin/bash
# Script to register system to Landscape Dedicated Server (LDS)
# Assumes you already have an LDS server

usage() {
   echo "Usage: `basename $0` <landscape-server>"
   exit
}

# Process args
[ $# -lt 1 ] && usage

# Need to run as root or with sudo privileges
if [ `id | sed 's/uid=\([0-9]*\)(.*/\1/'` -ne 0 ] ; then
   echo "You must run this script with root privileges."
   exit
fi

lds=$1

# Check if required package already installed
dpkg -l landscape-client 1> /dev/null 2>&1
if [ $? -ne 0 ] ; then
   apt-get -y install landscape-client
else
   echo "* Package 'landscape-client' already installed!"
fi

# Register your system to LDS
if [ `grep $lds /etc/landscape/client.conf | wc -l` -gt 0 ] ; then
   echo "* Looks like this system is already registered to LDS!"
   echo -n "  Are you sure you want to proceed? [y/N]: "
   read resp
   case $resp in 
      y ) continue ;;
      * ) exit ;;
   esac
fi
 
landscape-config --computer-title `hostname` --account-name standalone \
   --url https://${lds}/message-system --ping-url http://${lds}/ping

# Copy SSL cert from LDS server and add line to configuration file
scp $lds:/etc/ssl/certs/landscape_server.pem /etc/landscape
chown landscape /etc/landscape/landscape_server.pem
echo "ssl_public_key = /etc/landscape/landscape_server.pem" >> /etc/landscape/client.conf
service landscape-client restart

# 2013.03.25 12:48:48 - JD
