ensure_system_units_have_version.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. set -e
  3. SERVICE_TYPE=$1
  4. DEPLOYMENT_TYPE=$2
  5. VERSION="v${3}"
  6. add_image_version_to_sysconfig () {
  7. unit_name=$2
  8. sysconfig_file=/etc/sysconfig/${unit_name}
  9. if ! grep IMAGE_VERSION ${sysconfig_file}; then
  10. sed -i "/CONFIG_FILE/a IMAGE_VERSION=${1}" ${sysconfig_file}
  11. else
  12. sed -i "s/\(IMAGE_VERSION=\).*/\1${1}/" ${sysconfig_file}
  13. fi
  14. }
  15. add_image_version_to_unit () {
  16. deployment_type=$1
  17. unit_file=$2
  18. if ! grep IMAGE_VERSION $unit_file; then
  19. image_namespace="openshift/"
  20. if [ $deployment_type == "atomic-enterprise" ]; then
  21. image_namespace="aep3/"
  22. elif [ $deployment_type == "openshift-enterprise" ]; then
  23. image_namespace="openshift3/"
  24. fi
  25. sed -i "s|\(${image_namespace}[a-zA-Z0-9]\+\)|\1:\${IMAGE_VERSION}|" $unit_file
  26. fi
  27. }
  28. for unit_file in $(ls /etc/systemd/system/${SERVICE_TYPE}*.service); do
  29. unit_name=$(basename -s .service ${unit_file})
  30. add_image_version_to_sysconfig $VERSION $unit_name
  31. add_image_version_to_unit $DEPLOYMENT_TYPE $unit_file
  32. done
  33. if [ -e /etc/sysconfig/openvswitch ]; then
  34. add_image_version_to_sysconfig $VERSION openvswitch
  35. else
  36. echo IMAGE_VERSION=${VERSION} > /etc/sysconfig/openvswitch
  37. fi
  38. if ! grep EnvironmentFile /etc/systemd/system/openvswitch.service > /dev/null; then
  39. sed -i "/Service/a EnvironmentFile=/etc/sysconfig/openvswitch" /etc/systemd/system/openvswitch.service
  40. fi
  41. add_image_version_to_unit $DEPLOYMENT_TYPE /etc/systemd/system/openvswitch.service
  42. systemctl daemon-reload