3 # dib-lint: disable=setu sete setpipefail dibdebugtrace
8 OK=/mnt/state/var/lib/rhsm/rhsm.ok
18 repos="repos --enable rhel-7-server-rpms"
19 satellite_repo=${REG_SAT_REPO}
20 if [ -n "${REG_AUTO_ATTACH:-}" ]; then
21 opts="$opts --auto-attach"
23 if [ -n "${REG_SERVICE_LEVEL:-}" ]; then
24 opts="$opts --servicelevel $REG_SERVICE_LEVEL"
27 if [ -n "${REG_RELEASE:-}" ]; then
28 opts="$opts --release=$REG_RELEASE"
31 if [ -n "${REG_SERVICE_LEVEL:-}" ]; then
32 echo "WARNING: REG_SERVICE_LEVEL set without REG_AUTO_ATTACH."
35 if [ -n "${REG_RELEASE:-}" ]; then
36 echo "WARNING: REG_RELEASE set without REG_AUTO_ATTACH."
39 if [ -n "${REG_POOL_ID:-}" ]; then
40 attach_opts="$attach_opts --pool=$REG_POOL_ID"
44 if [ -n "${REG_BASE_URL:-}" ]; then
45 opts="$opts --baseurl=$REG_BASE_URL"
48 if [ -n "${REG_ENVIRONMENT:-}" ]; then
49 opts="$opts --env=$REG_ENVIRONMENT"
52 if [ -n "${REG_FORCE:-}" ]; then
54 sat5_opts="$sat5_opts --force"
57 if [ -n "${REG_SERVER_URL:-}" ]; then
58 opts="$opts --serverurl=$REG_SERVER_URL"
61 if [ -n "${REG_ACTIVATION_KEY:-}" ]; then
62 opts="$opts --activationkey=$REG_ACTIVATION_KEY"
63 sat5_opts="$sat5_opts --activationkey=$REG_ACTIVATION_KEY"
65 if [ -z "${REG_ORG:-}" ]; then
66 echo "WARNING: REG_ACTIVATION_KEY set without REG_ORG."
69 echo "WARNING: Support for registering with a username and password is deprecated."
70 echo "Please use activation keys instead. See the README for more information."
71 if [ -n "${REG_PASSWORD:-}" ]; then
72 opts="$opts --password $REG_PASSWORD"
75 if [ -n "${REG_USER:-}" ]; then
76 opts="$opts --username $REG_USER"
80 if [ -n "${REG_MACHINE_NAME:-}" ]; then
81 opts="$opts --name $REG_MACHINE_NAME"
82 sat5_opts="$sat5_opts --profilename=$REG_MACHINE_NAME"
85 if [ -n "${REG_ORG:-}" ]; then
86 opts="$opts --org=$REG_ORG"
87 sat5_opts="$sat5_opts --systemorgid=$REG_ORG"
90 if [ -n "${REG_REPOS:-}" ]; then
91 for repo in $(echo $REG_REPOS | tr ',' '\n'); do
92 repos="$repos --enable $repo"
96 if [ -n "${REG_TYPE:-}" ]; then
97 opts="$opts --type=$REG_TYPE"
101 if [[ $retryCount < 3 ]]; then
103 if ! [[ $? == 0 ]]; then
104 retryCount=$(echo $retryCount + 1 | bc)
105 echo "WARN: Failed to connect when running '$@', retrying..."
111 echo "ERROR: Failed to connect after 3 attempts when running '$@'"
116 function detect_satellite_version {
117 ping_api=$REG_SAT_URL/katello/api/ping
118 if curl --retry 3 --retry-delay 10 --max-time 30 -L -k -s -D - -o /dev/null $ping_api | grep "200 OK"; then
119 echo Satellite 6 detected at $REG_SAT_URL
121 elif curl --retry 3 --retry-delay 10 --max-time 30 -L -k -s -D - -o /dev/null $REG_SAT_URL/rhn/Login.do | grep "200 OK"; then
122 echo Satellite 5 detected at $REG_SAT_URL
125 echo No Satellite detected at $REG_SAT_URL
130 case "${REG_METHOD:-}" in
132 retry subscription-manager register $opts
133 if [ -z "${REG_AUTO_ATTACH:-}" -a -z "${REG_ACTIVATION_KEY:-}" ]; then
134 retry subscription-manager attach $attach_opts
136 retry subscription-manager repos --disable '*'
137 retry subscription-manager $repos
140 detect_satellite_version
141 if [ "$satellite_version" = "6" ]; then
142 repos="$repos --enable ${satellite_repo}"
143 curl --retry 3 --retry-delay 10 --max-time 30 -L -k -O "$REG_SAT_URL/pub/katello-ca-consumer-latest.noarch.rpm"
144 rpm -Uvh katello-ca-consumer-latest.noarch.rpm || true
145 retry subscription-manager register $opts
146 retry subscription-manager $repos
147 retry yum install -y katello-agent || true # needed for errata reporting to satellite6
148 katello-package-upload
149 retry subscription-manager repos --disable ${satellite_repo}
151 pushd /usr/share/rhn/
152 curl --retry 3 --retry-delay 10 --max-time 30 -k -O $REG_SAT_URL/pub/RHN-ORG-TRUSTED-SSL-CERT
154 retry rhnreg_ks --serverUrl=$REG_SAT_URL/XMLRPC $sat5_opts
158 echo "Disabling RHEL registration"
161 echo "WARNING: only 'portal', 'satellite', and 'disable' are valid values for REG_METHOD."
165 mkdir -p $(dirname $OK)