Merge "Force stop a single node pacemaker on yum update"
[apex-tripleo-heat-templates.git] / extraconfig / pre_deploy / rhel-registration / scripts / rhel-registration
1 #!/bin/bash
2
3 # dib-lint: disable=setu sete setpipefail dibdebugtrace
4
5 set -eu
6 set -o pipefail
7
8 OK=/mnt/state/var/lib/rhsm/rhsm.ok
9
10 if [ -e $OK ] ; then
11     exit 0
12 fi
13
14 opts=
15 attach_opts=
16 repos="repos --enable rhel-7-server-rpms"
17 satellite_repo="rhel-7-server-rh-common-rpms"
18 if [ -n "${REG_AUTO_ATTACH:-}" ]; then
19     opts="$opts --auto-attach"
20
21     if [ -n "${REG_SERVICE_LEVEL:-}" ]; then
22         opts="$opts --servicelevel $REG_SERVICE_LEVEL"
23     fi
24
25     if [ -n "${REG_RELEASE:-}" ]; then
26         opts="$opts --release=$REG_RELEASE"
27     fi
28 else
29     if [ -n "${REG_SERVICE_LEVEL:-}" ]; then
30         echo "WARNING: REG_SERVICE_LEVEL set without REG_AUTO_ATTACH."
31     fi
32
33     if [ -n "${REG_RELEASE:-}" ]; then
34         echo "WARNING: REG_RELEASE set without REG_AUTO_ATTACH."
35     fi
36
37     if [ -n "${REG_POOL_ID:-}" ]; then
38         attach_opts="$attach_opts --pool=$REG_POOL_ID"
39     fi
40 fi
41
42 if [ -n "${REG_BASE_URL:-}" ]; then
43     opts="$opts --baseurl=$REG_BASE_URL"
44 fi
45
46 if [ -n "${REG_ENVIRONMENT:-}" ]; then
47     opts="$opts --env=$REG_ENVIRONMENT"
48 fi
49
50 if [ -n "${REG_FORCE:-}" ]; then
51     opts="$opts --force"
52 fi
53
54 if [ -n "${REG_SERVER_URL:-}" ]; then
55     opts="$opts --serverurl=$REG_SERVER_URL"
56 fi
57
58 if [ -n "${REG_ACTIVATION_KEY:-}" ]; then
59     opts="$opts --activationkey=$REG_ACTIVATION_KEY"
60
61     if [ -z "${REG_ORG:-}" ]; then
62         echo "WARNING: REG_ACTIVATION_KEY set without REG_ORG."
63     fi
64 else
65     echo "WARNING: Support for registering with a username and password is deprecated."
66     echo "Please use activation keys instead.  See the README for more information."
67     if [ -n "${REG_PASSWORD:-}" ]; then
68         opts="$opts --password $REG_PASSWORD"
69     fi
70
71     if [ -n "${REG_USER:-}" ]; then
72         opts="$opts --username $REG_USER"
73     fi
74 fi
75
76 if [ -n "${REG_MACHINE_NAME:-}" ]; then
77     opts="$opts --name $REG_MACHINE_NAME"
78 fi
79
80 if [ -n "${REG_ORG:-}" ]; then
81     opts="$opts --org=$REG_ORG"
82 fi
83
84 if [ -n "${REG_REPOS:-}" ]; then
85     for repo in $(echo $REG_REPOS | tr ',' '\n'); do
86         repos="$repos --enable $repo"
87     done
88 fi
89
90 if [ -n "${REG_TYPE:-}" ]; then
91     opts="$opts --type=$REG_TYPE"
92 fi
93
94 case "${REG_METHOD:-}" in
95     portal)
96         subscription-manager register $opts
97         if [ -z "${REG_AUTO_ATTACH:-}" -a -z "${REG_ACTIVATION_KEY:-}" ]; then
98             subscription-manager attach $attach_opts
99         fi
100         subscription-manager $repos
101         ;;
102     satellite)
103         repos="$repos --enable ${satellite_repo}"
104         rpm -Uvh "$REG_SAT_URL/pub/katello-ca-consumer-latest.noarch.rpm" || true
105         subscription-manager register $opts
106         subscription-manager $repos
107         yum install -y katello-agent || true # needed for errata reporting to satellite6
108         katello-package-upload
109         subscription-manager repos --disable ${satellite_repo}
110         ;;
111     disable)
112         echo "Disabling RHEL registration"
113         ;;
114     *)
115         echo "WARNING: only 'portal', 'satellite', and 'disable' are valid values for REG_METHOD."
116         exit 0
117 esac
118
119 mkdir -p $(dirname $OK)
120 touch $OK