Image building tools for OpenStack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
5.4KB

  1. #!/bin/bash
  2. #
  3. # Copyright 2016 SUSE Linux GmbH
  4. # Copyright 2015 Hewlett-Packard Development Company, L.P.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  7. # not use this file except in compliance with the License. You may obtain
  8. # a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. # License for the specific language governing permissions and limitations
  16. # under the License.
  17. #
  18. # dib-lint: disable=safe_sudo
  19. if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
  20. set -x
  21. fi
  22. set -eu
  23. set -o pipefail
  24. source $_LIB/common-functions
  25. function cleanup() {
  26. sudo umount $TARGET_ROOT/proc
  27. sudo umount $TARGET_ROOT/dev/pts
  28. sudo umount $TARGET_ROOT/dev
  29. sudo umount $TARGET_ROOT/sys
  30. sudo umount $TMP_MOUNT_PATH/var/cache/zypp
  31. }
  32. trap cleanup EXIT
  33. ZYPPER_TARGET_OPTS="--non-interactive --gpg-auto-import-keys --root $TARGET_ROOT"
  34. ZYPPER_INSTALL_SYSTEM_PYTHON="python3"
  35. DIB_DISTRIBUTION_MIRROR=${DIB_DISTRIBUTION_MIRROR:-https://download.opensuse.org}
  36. ZYPPER_REPOS=${DIB_ZYPPER_REPOS:-''}
  37. if [ -z "${ZYPPER_REPOS}" ] ; then
  38. case ${DIB_RELEASE} in
  39. # Old Leap releases
  40. 42*)
  41. ZYPPER_REPOS="update=>${DIB_DISTRIBUTION_MIRROR}/update/leap/${DIB_RELEASE}/oss/ "
  42. ZYPPER_REPOS+="oss=>${DIB_DISTRIBUTION_MIRROR}/distribution/leap/${DIB_RELEASE}/repo/oss/"
  43. ZYPPER_INSTALL_SYSTEM_PYTHON="python"
  44. ;;
  45. # New Leap releases
  46. 15*)
  47. ZYPPER_REPOS="update=>${DIB_DISTRIBUTION_MIRROR}/update/leap/${DIB_RELEASE}/oss/ "
  48. ZYPPER_REPOS+="oss=>${DIB_DISTRIBUTION_MIRROR}/distribution/leap/${DIB_RELEASE}/repo/oss/"
  49. ;;
  50. # Tumbleweed
  51. tumbleweed)
  52. ZYPPER_REPOS="update=>${DIB_DISTRIBUTION_MIRROR}/update/${DIB_RELEASE}/ "
  53. ZYPPER_REPOS+="oss=>${DIB_DISTRIBUTION_MIRROR}/${DIB_RELEASE}/repo/oss/"
  54. ;;
  55. *) echo "Unsupported openSUSE release: ${DIB_RELEASE}"; exit 1 ;;
  56. esac
  57. fi
  58. for repo in ${ZYPPER_REPOS}; do
  59. refresh_repo=""
  60. reponame=repo-${repo%%=>*}
  61. repouri=${repo##*=>}
  62. # Refresh all repos in TW and only the update one for the stable ones. This will ensure that
  63. # we always get the latest information from the repo.
  64. [[ ${DIB_RELEASE} == tumbleweed ]] || [[ ${reponame} == "repo-update" ]] && refresh_repo="-f"
  65. sudo zypper ${ZYPPER_TARGET_OPTS} addrepo --name ${reponame} --keep-packages ${refresh_repo} ${repouri} ${reponame}
  66. done
  67. # It appears that zypper will clean up the repo's cache when it (re-)adds the
  68. # repo so we need to add the cache now, once the repos are added. This is
  69. # similar to what the zypper/50-zypper-cache script does
  70. ZYPPER_CACHE_DIR=$DIB_IMAGE_CACHE/zypper
  71. mkdir -p $ZYPPER_CACHE_DIR
  72. sudo mkdir -p $TMP_MOUNT_PATH/var/cache/zypp
  73. sudo mount --bind $ZYPPER_CACHE_DIR $TMP_MOUNT_PATH/var/cache/zypp
  74. # Refresh it so we get updated data in cased we switched DIB_RELEASE
  75. # since last run.
  76. sudo zypper ${ZYPPER_TARGET_OPTS} refresh
  77. # Note this is not usually done for root.d elements (see
  78. # lib/common-functions:mount_proc_dev_sys) but it's important that
  79. # we have things like /dev/urandom around inside the chroot for
  80. # the rpm [pre|post]inst scripts within the packages.
  81. sudo mkdir -p $TARGET_ROOT/proc $TARGET_ROOT/dev $TARGET_ROOT/sys
  82. sudo mount -t proc none $TARGET_ROOT/proc
  83. sudo mount --bind /dev $TARGET_ROOT/dev
  84. sudo mount -t devpts $(mount_dev_pts_options) devpts $TARGET_ROOT/dev/pts
  85. sudo mount -t sysfs none $TARGET_ROOT/sys
  86. # Install filesystem, base and useful tools
  87. sudo zypper ${ZYPPER_TARGET_OPTS} install --no-recommends filesystem
  88. # Install basic components in order
  89. sudo zypper ${ZYPPER_TARGET_OPTS} install \
  90. ${DIB_OPENSUSE_PATTERNS} ${ZYPPER_INSTALL_SYSTEM_PYTHON} \
  91. zypper sudo ca-certificates-mozilla
  92. # Remove the installed symlink, otherwise we wipe the resolv.conf
  93. # outside the target_root (as the link is not relative)
  94. # outside target_root
  95. test -L $TARGET_ROOT/etc/resolv.conf && sudo rm -f $TARGET_ROOT/etc/resolv.conf
  96. # Put in a dummy /etc/resolv.conf over the temporary one we used
  97. # to bootstrap. systemd has a bug/feature [1] that it will assume
  98. # you want systemd-networkd as the network manager and create a
  99. # broken symlink to /run/... if the base image doesn't have one.
  100. # This broken link confuses things like dhclient.
  101. # [1] https://bugzilla.redhat.com/show_bug.cgi?id=1197204
  102. echo -e "# This file intentionally left blank\n" | \
  103. sudo tee $TARGET_ROOT/etc/resolv.conf
  104. # set the most reliable UTF-8 locale
  105. default_lang="C.UTF-8"
  106. sudo sed -i -e "s,^RC_LANG=.*,RC_LANG=\"$default_lang\"," \
  107. $TARGET_ROOT/etc/sysconfig/language
  108. echo -e "LANG=\"$default_lang\"" | \
  109. sudo tee $TARGET_ROOT/etc/locale.conf
  110. # default to UTC
  111. sudo chroot $TARGET_ROOT ln -sf /usr/share/zoneinfo/Etc/UTC \
  112. /etc/localtime
  113. # RPM doesn't know whether files have been changed since install
  114. # At this point though, we know for certain that we have changed no
  115. # config files, so anything marked .rpmnew is just a bug.
  116. for newfile in $(sudo find $TARGET_ROOT -type f -name '*rpmnew') ; do
  117. sudo mv $newfile $(echo $newfile | sed 's/.rpmnew$//')
  118. done
  119. # Unmounting of all the mount points is handled by the cleanup EXIT
  120. # handler so there is nothing else to do here