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.

125 lines
3.2 KiB

  1. #!/bin/bash
  2. version_gitloader="1.0.0"
  3. version="master"
  4. dir_root="."
  5. mode="http"
  6. hash curl 2>/dev/null || { echo >&2 "curl is required. Stopped."; exit 1; }
  7. hash jq 2>/dev/null || { echo >&2 "jq is required. Stopped."; exit 1; }
  8. hash git 2>/dev/null || { echo >&2 "git is required. Stopped."; exit 1; }
  9. while getopts "v:d:m:" opt; do
  10. case ${opt} in
  11. v) #version SPIP, par défaut master
  12. version="${OPTARG}"
  13. ;;
  14. d) #répertoire cible
  15. dir_root="${OPTARG}"
  16. ;;
  17. m) #git or http
  18. mode="${OPTARG}"
  19. ;;
  20. \?)
  21. echo "Version: $version_gitloader"
  22. echo "Usage: $0 [-v] [-d] [-m]"
  23. echo "-v : version de SPIP master ou x.y"
  24. echo -e "\\t par défaut master"
  25. echo "-d : répertoire cible où télécharger SPIP et ses plugins"
  26. echo -e "\\t par défaut : répertoire courant"
  27. echo "-m : mode de téléchargement, ssh ou http"
  28. echo -e "\\t par défaut http"
  29. exit;
  30. ;;
  31. esac
  32. done
  33. if [ ! -d "$dir_root" ]; then
  34. mkdir "$dir_root" || exit 1
  35. fi
  36. if [ ! -d "$dir_root/plugins-dist" ]; then
  37. mkdir "$dir_root/plugins-dist" || exit 1
  38. fi
  39. function clone_git() {
  40. local repo_git="$1"
  41. local repo_name="$2"
  42. local version="$3"
  43. if [ ! -d "$repo_name/.git" ]; then
  44. git init "$repo_name"
  45. git -C "$repo_name" remote add origin "$repo_git" >/dev/null 2>&1
  46. fi
  47. if ! git -C "$repo_name" fetch --all -t >/dev/null 2>&1; then
  48. git -C "$repo_name" config --unset-all remote.origin.fetch "\\+refs\\/svn\\/map:refs\\/notes\\/commits"
  49. git -C "$repo_name" fetch --all -t >/dev/null 2>&1
  50. fi
  51. if ! git -C "$repo_name" reset --hard "origin/$version" >/dev/null 2>&1; then
  52. git -C "$repo_name" checkout --orphan orphan
  53. git -C "$repo_name" reset --hard
  54. else
  55. git -C "$repo_name" checkout "$version" >/dev/null 2>&1
  56. git -C "$repo_name" branch -u "origin/$version" >/dev/null 2>&1
  57. fi
  58. #git -C "$repo_name" checkout "$version"
  59. }
  60. # Import SPIP
  61. if [[ "$mode" == "git" ]] || [[ "$mode" == "ssh" ]];then
  62. source_git="git@git.spip.net:spip/spip.git"
  63. fi
  64. if [[ "$mode" == "http" ]];then
  65. source_git="https://git.spip.net/spip/spip.git"
  66. fi
  67. echo "Import SPIP core dans $dir_root à la version $version"
  68. clone_git "$source_git" "$dir_root" "$version"
  69. curl -s -X GET "https://git.spip.net/api/v1/orgs/spip/repos" -H "accept: application/json" -o repos.json
  70. last_index_repo=$(jq -r 'length - 1' repos.json)
  71. if [ "$version" == "master" ]; then
  72. version_repo="master"
  73. else
  74. compteur=$(echo "$version" | tr -cd '.' | wc -c | xargs)
  75. if [ "$compteur" -gt 1 ]; then
  76. version_repo="spip/$version"
  77. else
  78. version_repo="spip-$version"
  79. fi
  80. fi
  81. for i in $(seq 0 "$last_index_repo")
  82. do
  83. repo_name=$(jq -r ".[$i] .name" repos.json)
  84. case "${repo_name}" in
  85. spip|ecrire|prive|dev|themes)
  86. continue
  87. ;;
  88. *)
  89. ;;
  90. esac
  91. if [[ "$mode" == "git" || "$mode" == "ssh" ]];then
  92. source_git=$(jq -r ".[$i] .ssh_url" repos.json)
  93. fi
  94. if [[ "$mode" == "http" ]];then
  95. source_git=$(jq -r ".[$i] .html_url" repos.json)
  96. fi
  97. repo_path="$dir_root/plugins-dist/$repo_name"
  98. #Une exception dans les plugins, le dépot dist n'en ai pas un
  99. if [ "$repo_name" == "dist" ]; then
  100. repo_path="$dir_root/squelettes-$repo_name"
  101. fi
  102. echo "Import de $repo_name à la version $version_repo ("$source_git")"
  103. clone_git "$source_git" "$repo_path" "$version_repo"
  104. done
  105. rm repos.json