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.

checkoutSite.sh 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/bash
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing,
  14. # software distributed under the License is distributed on an
  15. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. # KIND, either express or implied. See the License for the
  17. # specific language governing permissions and limitations
  18. # under the License.
  19. #
  20. # Author: Martin Stockhammer <martin_s@apache.org>
  21. # Date: 2018-11-03
  22. #
  23. # This script runs a sparse git clone of a remote repository and
  24. # initializes the git configuration.
  25. #
  26. # It is mainly used for site content creation, because the main archiva-web-content repository
  27. # is rather large and we don't want to checkout the complete data.
  28. #
  29. SITE_DIR=".site-content"
  30. GIT_REMOTE=""
  31. GIT_USER=$(git config user.name)
  32. GIT_EMAIL=$(git config user.email)
  33. GIT_PATTERN_FILE="git-sparse-checkout-pattern"
  34. GIT_PATTERN_DEST=".git/info/sparse-checkout"
  35. MY_PWD=$(pwd)
  36. CLONE=1
  37. FORCE=1
  38. MODULE_DIR="${MY_PWD}"
  39. PATTERN=""
  40. while [ ! -z "$1" ]; do
  41. case "$1" in
  42. -f)
  43. FORCE=0
  44. shift
  45. ;;
  46. -d)
  47. shift
  48. SITE_DIR="$1"
  49. shift
  50. ;;
  51. -p)
  52. shift
  53. if [ -z "${PATTERN}" ]; then
  54. PATTERN="${1}"
  55. else
  56. PATTERN="${PATTERN}\n${1}"
  57. fi
  58. shift
  59. ;;
  60. -m)
  61. shift
  62. MODULE_DIR="$1"
  63. shift
  64. ;;
  65. *)
  66. GIT_REMOTE="$1"
  67. shift
  68. ;;
  69. esac
  70. done
  71. print_usage() {
  72. echo "checkoutRepo [-m MODULE_DIR] [-d SITE_DIR] [-f] GIT_URL"
  73. echo " -m: The module directory where the pattern file can be found and the site dir will be created."
  74. echo " -d SITE_DIR: Use the given directory for checkout"
  75. echo " -f: Force clone, even if directory exists"
  76. }
  77. if [ ! -f "${MODULE_DIR}/pom.xml" ]; then
  78. echo "Looks like the working directory is not a valid dir. No pom.xml found."
  79. exit 1
  80. fi
  81. cd "${MODULE_DIR}" || { echo "Could not change to module directory ${MODULE_DIR}"; exit 1; }
  82. if [ -z "$GIT_REMOTE" ]; then
  83. print_usage
  84. exit 1
  85. fi
  86. if [ "${GIT_REMOTE:0:8}" == "scm:git:" ]; then
  87. GIT_REMOTE="${GIT_REMOTE:8}"
  88. fi
  89. if [ -d "${SITE_DIR}" ]; then
  90. if [ ! -d "${SITE_DIR}/.git" ]; then
  91. echo "Directory ${SITE_DIR} exist already, but is not a git clone. Aborting."
  92. exit 1
  93. elif [ "$FORCE" -eq 0 ]; then
  94. CLONE=0
  95. fi
  96. else
  97. CLONE=0
  98. fi
  99. if [ $CLONE -eq 0 ]; then
  100. git clone "${GIT_REMOTE}" "${SITE_DIR}" --no-checkout
  101. if [ $? -ne 0 ]; then
  102. echo "Git clone failed"
  103. exit 1
  104. fi
  105. fi
  106. cd "${SITE_DIR}" || { echo "Could not change to site dir ${SITE_DIR}"; exit 1; }
  107. git config core.sparsecheckout true
  108. git config user.name "${GIT_USER}"
  109. git config user.email "${GIT_EMAIL}"
  110. if [ ! -z "${PATTERN}" ]; then
  111. echo -e "${PATTERN}" >"${GIT_PATTERN_DEST}"
  112. elif [ -f "../${GIT_PATTERN_FILE}" ]; then
  113. cp "../${GIT_PATTERN_FILE}" "${GIT_PATTERN_DEST}"
  114. fi
  115. git checkout --
  116. cd "${MY_PWD}"