Skip to content

Commit

Permalink
Merge pull request RedHatInsights#2472 from loadtheaccumulator/remove…
Browse files Browse the repository at this point in the history
…_firstboot_reg

THEEDGE-3923: remove rhc first boot from edge mgmt
  • Loading branch information
loadtheaccumulator authored Apr 19, 2024
2 parents 07d97ef + c7f939d commit 9f37502
Showing 1 changed file with 1 addition and 95 deletions.
96 changes: 1 addition & 95 deletions templates/templateKickstart.ks
Original file line number Diff line number Diff line change
Expand Up @@ -136,105 +136,11 @@ fi
/usr/sbin/semanage permissive --add insights_client_t
%end


#CUSTOM_POST_HERE
%include /tmp/fleet_kspost.txt


%post --log=/var/log/anaconda/post-autoregister.log
echo POST-AUTOREGISTER

# Automatically register if credentials are provided
[[ -e /root/fleet_env.bash ]] && source /root/fleet_env.bash
RHC_FIRSTBOOT=${RHC_FIRSTBOOT:-false}

# CREATE AUTOREGISTER SCRIPT
# TODO: rhc firstboot registration script should be something installed with RHC (if not already)
cat << '__RHCREGISTER__' >> /usr/local/bin/rhc_autoregister.sh
#!/bin/bash

if [ -e /root/fleet_env.bash ]
then
source /root/fleet_env.bash

[[ -e /root/fleet_tags.yaml ]] && cp /root/fleet_tags.yaml /etc/insights-client/tags.yaml

if [[ -z ${RHC_ORGID+x} ]] && [[ -z ${RHC_USER+x} ]]
then
echo "No credentials provided for registration"
else
# Register with RHSM
[[ -v RHC_ORGID ]] \
&& subscription-manager register --org $RHC_ORGID --activationkey $RHC_ACTIVATION_KEY --force \
|| subscription-manager register --username $RHC_USER --password $RHC_PASS --auto-attach --force

# Register with Insights
insights-client --register > /var/log/anaconda/post-insights-command.log 2>&1

# Enable and start RHCD service
systemctl enable rhcd.service
systemctl restart rhcd.service

# Register with RHC
[[ -v RHC_ORGID ]] \
&& rhc connect --organization $RHC_ORGID --activation-key $RHC_ACTIVATION_KEY \
|| rhc connect --username $RHC_USER --password $RHC_PASS

systemctl status rhcd.service
systemctl status insights-client

# Set specific display name set in custom post
if [ -z ${INSIGHTS_DISPLAY_NAME+x} ]
then
# Replace localhost with Subscription Manager ID and set Insights display name
# Subscription Manager ID was chosen based on availability. Refactor based on feedback
statichostname=$(hostnamectl | grep "Static hostname" | awk -F": " '{print $2}')
transienthostname=$(hostnamectl | grep "Transient hostname" | awk -F": " '{print $2}')
[[ -z ${transienthostname+x} ]] && displayname=${statichostname} || displayname=${transienthostname}
if [ $displayname == "localhost.localdomain" ]
then
displayname=$(subscription-manager identity | grep "system identity" | awk -F": " '{print $2}')
insights-client --display-name "${DISPLAY_NAME_PREFIX}${displayname}"
fi
else
insights-client --display-name "$INSIGHTS_DISPLAY_NAME"
fi
fi
else
echo "INFO: No /root/fleet_env.bash file. Skipping registration"
fi
__RHCREGISTER__

# need to make it executable and restore selinux context
chmod 755 /usr/local/bin/rhc_autoregister.sh
restorecon -rv /usr/local/bin

# CREATE AUTO REGISTRATION FIRSTBOOT SERVICE
cat << '__RHCFIRSTBOOTSERVICE__' >> /etc/systemd/system/rhc_autoregister.service
[Unit]
Before=systemd-user-sessions.service
Wants=network-online.target
After=network-online.target
ConditionPathExists=/root/fleet_env.bash

[Service]
Type=oneshot
ExecStart=/usr/local/bin/rhc_autoregister.sh
ExecStartPost=/usr/bin/rm /root/fleet_env.bash
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

__RHCFIRSTBOOTSERVICE__

# Set up first boot registration or do it now before reboot
[[ $RHC_FIRSTBOOT == "true" ]] \
&& systemctl enable rhc_autoregister.service \
|| /usr/local/bin/rhc_autoregister.sh

%end


%post --log=/var/log/anaconda/post-cleanup.log
# Cleanup fleet-ification
echo POST-CLEANUP
Expand Down

0 comments on commit 9f37502

Please sign in to comment.