21 lines
538 B

  1. #!/bin/bash
  2. . /etc/apache2/envvars
  3. if [ "$SERVER_NAME" ]; then
  4. FILE=/etc/apache2/apache2.conf
  5. if grep -E "^ServerName\s+.*\$" "$FILE" > /dev/null 2>&1; then
  6. echo "Updated IP."
  7. sed -ri "s/^(ServerName)(\s+[^ ]*)\s*$/\1 $SERVER_NAME/g" "$FILE"
  8. else
  9. #echo "Added IP."
  10. echo "ServerName $SERVER_NAME" >> "$FILE"
  11. fi
  12. fi
  13. ## Using exec replaces the current bash process with the given one.
  14. ## this is necessary if we want that apache2 receives signals correctly.
  15. exec apache2-foreground "$@"