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.

118 lines
3.0KB

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