Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra/image/system-services: Enhance checks, also fix reverse zone #1282

Merged

Conversation

t-woerner
Copy link
Member

Checks for IPv4 addresses have been added and reverse zone handling for fixipaip.sh

The services are logging StandardOutput and StandardError to journal now.

@t-woerner t-woerner force-pushed the infra_image_enhance_system_services branch from 4d7839a to f3493ab Compare August 2, 2024 15:24
@t-woerner t-woerner changed the title infra/image/system-service: Enhance checks, also fix reverse zone infra/image/system-services: Enhance checks, also fix reverse zone Aug 2, 2024
@t-woerner t-woerner force-pushed the infra_image_enhance_system_services branch from f3493ab to 27b6131 Compare August 2, 2024 16:41
@@ -1,26 +1,82 @@
#!/bin/bash -eu

function validFQDN()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really minor and cosmetic: shell naming conventions lowercase and separate words with underscore, what about

valid_fqdn()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

return 0
}

function validIPv4()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid_ipv4()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

local rematch="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"

[[ "${ip}" =~ ${rematch} ]] || return 1
for i in ${ip//./ }; do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cosmetic:

s/i/octet/g

octet has a meaning

Copy link
Member Author

@t-woerner t-woerner Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bash syntax to replace "." (dot) with " " (space). ${parameter//pattern/string} replaces in the whole string and ${parameter/pattern/string} only the first match.

echo " IP: '${IP}'"
echo

if grep -Pq "[[:space:]]${HOSTNAME}([[:space:]]|$)" /etc/hosts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep -P is not available on all systems by default, what about

grep -qE "\s$HOSTNAME(\s|$)" /etc/hosts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

echo

if grep -Pq "[[:space:]]${HOSTNAME}([[:space:]]|$)" /etc/hosts
then
sed -ie "s/.*${HOSTNAME}/${IP}\t${HOSTNAME}/" /etc/hosts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sed sometimes is risky,

what about

sed -i.bak

it will create a backup before modifying.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Collaborator

@f-trivino f-trivino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! feel free to merge.

@t-woerner I just have cosmetics changes for your consideration, really minor things.

@t-woerner t-woerner force-pushed the infra_image_enhance_system_services branch from 27b6131 to 929ccb1 Compare August 7, 2024 08:23
Checks for IPv4 addresses have been added and reverse zone handling
for fixipaip.sh

The services are logging StandardOutput and StandardError to journal
now.
@t-woerner t-woerner force-pushed the infra_image_enhance_system_services branch from 929ccb1 to e05fbce Compare August 7, 2024 08:50
@f-trivino f-trivino merged commit 88dc4c6 into freeipa:master Aug 7, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants