File: //proc/self/root/sbin/cln_register
#!/bin/bash
######################################
# This script allows you to get activation key out of your
# partner account, and register the server
# Version: 0.2
# Date: Oct 20, 2010
######################################
progname=$(basename $0)
print_help()
{
cat <<'EOF'
Usage: cln_register --username <username> --password <password> --client <client>
EOF
}
print_version()
{
cat <<EOF
cln_register version 0.2
(c) 2010 CloudLinux Inc.
EOF
}
SHORTOPTS="vp:u:c:"
LONGOPTS="help,version,client:,username:,password:"
if $(getopt -T >/dev/null 2>&1) ; [ $? = 4 ] ; then # New longopts getopt.
OPTS=$(getopt -o $SHORTOPTS --long $LONGOPTS -n "$progname" -- "$@")
else # Old classic getopt.
# Special handling for --help and --version on old getopt.
case $1 in --help) print_help ; exit 0 ;; esac
case $1 in --version) print_version ; exit 0 ;; esac
OPTS=$(getopt $SHORTOPTS "$@")
fi
if [ $? -ne 0 ]; then
echo "'$progname --help' for more information" 1>&2
exit 1
fi
eval set -- "$OPTS"
API_LOGIN=""
API_PASSWORD=""
CLIENT_LOGIN=""
while [ $# -gt 0 ]; do
: debug: $1
case $1 in
--help)
print_help
exit 0
;;
--version)
print_version
exit 0
;;
-p|--password)
API_PASSWORD=$2
shift 2
;;
-u|--username)
API_LOGIN=$2
shift 2
;;
-c|--client)
CLIENT_LOGIN=$2
shift 2
;;
-v|--version)
print_version
exit 0
;;
--)
shift
break
;;
*)
echo "Internal Error: option processing error: $1" 1>&2
exit 1
;;
esac
done
if [ ! -n "$CLIENT_LOGIN" ] || [ ! -n "$API_LOGIN" ] || [ ! -n "$API_PASSWORD" ]; then print_help; exit 1; fi
# Possible key types: x86_64, i386
KEY_TYPE=x86_64
# Set to 1 remove itself
SELF_REMOVE=0
#### END CONFIGURATION
#SCRIPT STARTS
KEY="CloudLinux Subscription $KEY_TYPE"
CALL_ADDRESS="https://cln.cloudlinux.com/clweb/rpc/CREATE_KEY/invoke.do"
AC_KEY=''
get_key() {
POST_DATA="params=$API_LOGIN|$API_PASSWORD|$CLIENT_LOGIN|$KEY"
RESULT_STRING=`wget -q --no-check-certificate --post-data="$POST_DATA" $CALL_ADDRESS -O -`
RESULT=$?
if [ "$RESULT" -ne "0" ]; then
echo
echo "Server response:"
echo
echo $RESULT_STRING
return 1
else
echo $RESULT_STRING |grep ".*LicenseNumber=\([a-f0-9-]\+\).*" > /dev/null
if [ "$?" -ne "0" ]; then
echo $RESULT_STRING
return 1
else
AC_KEY=`echo $RESULT_STRING | sed -e 's/.*LicenseNumber=\([a-f0-9-]\+\).*/\1/'`
return 0
fi
fi
}
get_key
if [ "$?" -eq "0" ]; then
rhnreg_ks --activationkey=$AC_KEY
REG_RESULT=$?
else
REG_RESULT=1
fi
if [ "$SELF_REMOVE" -eq "1" ]; then
rm -f $0
fi
if [ "$REG_RESULT" -eq "0" ]; then
echo "OK"
else
echo "Error getting the key: $REG_RESULT"
exit 1
fi