|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
version="master"
|
|
|
|
dir_root="."
|
|
|
|
mode="http"
|
|
|
|
|
|
|
|
hash curl 2>/dev/null || { echo >&2 "curl is required. Stopped."; exit 1; }
|
|
|
|
hash jq 2>/dev/null || { echo >&2 "jq is required. Stopped."; exit 1; }
|
|
|
|
hash git 2>/dev/null || { echo >&2 "git is required. Stopped."; exit 1; }
|
|
|
|
|
|
|
|
while getopts "v:d:m:" opt; do
|
|
|
|
case ${opt} in
|
|
|
|
v) #version SPIP, par défaut master
|
|
|
|
version="${OPTARG}"
|
|
|
|
;;
|
|
|
|
d) #répertoire cible
|
|
|
|
dir_root="${OPTARG}"
|
|
|
|
;;
|
|
|
|
m) #git or http
|
|
|
|
mode="${OPTARG}"
|
|
|
|
;;
|
|
|
|
\?)
|
|
|
|
echo "Usage: $0 [-v] [-d] [-m]"
|
|
|
|
echo "-v : version de SPIP master ou x.y.z"
|
|
|
|
echo -e "\\t par défaut master"
|
|
|
|
echo "-d : répertoire cible où télécharger SPIP et ses plugins"
|
|
|
|
echo -e "\\t par défaut : répertoire courant"
|
|
|
|
echo "-m : mode de téléchargement (git ou http)"
|
|
|
|
echo -e "\\t par défaut http"
|
|
|
|
exit;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -d "$dir_root/plugins-dist" ]; then
|
|
|
|
mkdir "$dir_root/plugins-dist"
|
|
|
|
fi
|
|
|
|
|
|
|
|
function clone_git() {
|
|
|
|
local repo_git="$1"
|
|
|
|
local repo_name="$2"
|
|
|
|
local version="$3"
|
|
|
|
|
|
|
|
if [ ! -d "$repo_name/.git" ]; then
|
|
|
|
git init "$repo_name"
|
|
|
|
git -C "$repo_name" remote add origin "$repo_git" 2>&1 >/dev/null
|
|
|
|
fi
|
|
|
|
git -C "$repo_name" config --add remote.origin.fetch "+refs/svn/map:refs/notes/commits" 2>&1 >/dev/null
|
|
|
|
git -C "$repo_name" fetch --all -t 2>&1 >/dev/null
|
|
|
|
if [[ "$?" != "0" ]]; then
|
|
|
|
git -C "$repo_name" config --unset-all remote.origin.fetch "\+refs\/svn\/map:refs\/notes\/commits"
|
|
|
|
git -C "$repo_name" fetch --all -t 2>&1 >/dev/null
|
|
|
|
fi
|
|
|
|
git -C "$repo_name" reset --hard "$version" 2>&1 >/dev/null
|
|
|
|
|
|
|
|
#git -C "$repo_name" checkout "$version"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Import SPIP
|
|
|
|
if [[ "$mode" == "git" ]];then
|
|
|
|
source_git="git@git.spip.net:SPIP/spip.git"
|
|
|
|
fi
|
|
|
|
if [[ "$mode" == "http" ]];then
|
|
|
|
source_git="https://git.spip.net/SPIP/spip.git"
|
|
|
|
fi
|
|
|
|
version_core="$version"
|
|
|
|
if [ "$version_core" != "master" ]; then
|
|
|
|
version_core="spip-$version"
|
|
|
|
else
|
|
|
|
version_core="origin/master"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Import SPIP core dans $dir_root à la version $version"
|
|
|
|
clone_git "$source_git" "$dir_root" "$version_core"
|
|
|
|
|
|
|
|
curl -s -X GET "https://git.spip.net/api/v1/orgs/spip/repos" -H "accept: application/json" -o repos.json
|
|
|
|
last_index_repo=$(jq -r 'length - 1' repos.json)
|
|
|
|
|
|
|
|
for i in $(seq 0 "$last_index_repo")
|
|
|
|
do
|
|
|
|
if [[ "$mode" == "git" ]];then
|
|
|
|
source_git=$(jq -r ".[$i] .ssh_url" repos.json)
|
|
|
|
fi
|
|
|
|
if [[ "$mode" == "http" ]];then
|
|
|
|
source_git=$(jq -r ".[$i] .html_url" repos.json)
|
|
|
|
|
|
|
|
fi
|
|
|
|
repo_name=$(jq -r ".[$i] .name" repos.json)
|
|
|
|
repo_path="$dir_root/plugins-dist/$repo_name"
|
|
|
|
|
|
|
|
case "${repo_name}" in
|
|
|
|
spip|ecrire|prive)
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "$version" == "master" ]; then
|
|
|
|
version_repo="origin/master"
|
|
|
|
else
|
|
|
|
version_repo="spip/$version"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Import de $repo_name à la version $version"
|
|
|
|
clone_git "$source_git" "$repo_path" "$version_repo"
|
|
|
|
done
|