#!/bin/bash

# author: Vasiliy Kleschov <vkleschov@cloudlinux.com>
# created: 2018-03-14
# CloudLinux IP registration tool

SKIP_RHNCHECK=0
SHOW_HELP=0

# simple cycle that does not meant to do
# some completed stuff like positional arguments
# if you need something more -> rewrite this script in python
for opt in "$@"
do
    case "$opt" in
        --force) SKIP_RHNCHECK=1
            ;;
        --help|-h) SHOW_HELP=1
            ;;
    esac
done

# we should show help even if license exists
if [[ ${SHOW_HELP} == 1 ]]; then
    /usr/sbin/rhnreg_ks --help
    exit $?
fi;

# skip rhn_check only with --force option passed
if [[ ${SKIP_RHNCHECK} == 0 ]]; then
    if rhn_check &> /dev/null; then
        echo "Command rhn_check exited with code zero." \
             "That usually means that registration is not needed." \
             "Use --force to override"
        exit 0
    fi;
fi;

/usr/sbin/rhnreg_ks --activationkey=IPL --force $@
