Merge pull request #84 from buildplan/fix_config

Fix hostname and disable cloud-init for hostname setting on cloud VPS
This commit is contained in:
buildplan 2025-11-25 20:18:41 +00:00 committed by GitHub
commit 4a35b98ebc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 10 deletions

View File

@ -87,12 +87,12 @@ sha256sum du_setup.sh
Compare the output hash to the one below. They must match exactly.
`d18f20d612eb9d2c8c8faac2cc3bdb6acf7d85860f5a4c93a0953284aa89c820`
`0bb8006d79b07c73e265ef3e88057b9b937e7e2728b7a8e702d0818bdcdee402`
Or echo the hash to check, it should output: `du_setup.sh: OK`
```bash
echo d18f20d612eb9d2c8c8faac2cc3bdb6acf7d85860f5a4c93a0953284aa89c820 du_setup.sh | sha256sum --check
echo 0bb8006d79b07c73e265ef3e88057b9b937e7e2728b7a8e702d0818bdcdee402 du_setup.sh | sha256sum --check
```
### 3. Run the Script

View File

@ -3173,21 +3173,28 @@ configure_system() {
if [[ $(hostnamectl --static) != "$SERVER_NAME" ]]; then
hostnamectl set-hostname "$SERVER_NAME"
hostnamectl set-hostname "$PRETTY_NAME" --pretty
print_success "Hostname configured: $SERVER_NAME"
print_success "Hostname updated to: $SERVER_NAME"
else
print_info "Hostname already set to $SERVER_NAME."
print_info "Hostname is already set to $SERVER_NAME."
fi
if [[ -f /etc/cloud/cloud.cfg ]]; then
if grep -q "manage_etc_hosts: true" /etc/cloud/cloud.cfg; then
print_info "Disabling cloud-init 'manage_etc_hosts' to prevent overwrite..."
sed -i 's/manage_etc_hosts: true/manage_etc_hosts: false/g' /etc/cloud/cloud.cfg
log "Disabled manage_etc_hosts in /etc/cloud/cloud.cfg"
fi
fi
if grep -q "^127.0.1.1" /etc/hosts; then
# Check if the line matches the chosen server name; if not, update it
if ! grep -q "^127.0.1.1.*$SERVER_NAME" /etc/hosts; then
if ! grep -qE "^127.0.1.1[[:space:]]+$SERVER_NAME" /etc/hosts; then
sed -i "s/^127.0.1.1.*/127.0.1.1\t$SERVER_NAME/" /etc/hosts
print_info "Updated /etc/hosts to resolve $SERVER_NAME."
print_success "Fixed /etc/hosts to map 127.0.1.1 to $SERVER_NAME."
else
print_info "/etc/hosts already resolves $SERVER_NAME correctly."
print_info "/etc/hosts is already correct."
fi
else
echo "127.0.1.1 $SERVER_NAME" >> /etc/hosts
print_info "Added entry to /etc/hosts for $SERVER_NAME."
print_success "Added missing 127.0.1.1 entry to /etc/hosts."
fi
log "System configuration completed."

View File

@ -1 +1 @@
d18f20d612eb9d2c8c8faac2cc3bdb6acf7d85860f5a4c93a0953284aa89c820 du_setup.sh
0bb8006d79b07c73e265ef3e88057b9b937e7e2728b7a8e702d0818bdcdee402 du_setup.sh