Browse Source

Mise en place d'un script bash important un projet SPIP depuis git.spip.net

* Ce n'est pas composer certes mais ce n'est pas svn non plus ...
svn/root/trunk
cam.lafit 3 years ago
commit
a2102f6d86
  1. 82
      git_loader.sh

82
git_loader.sh

@ -0,0 +1,82 @@
#!/bin/bash
version="master"
dir_root="."
mode="http"
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: cmd [-r] [-v] [-d]"
;;
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
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/dist/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="$dir_root/plugins-dist/"$(jq -r ".[$i] .name" repos.json)
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_name" "$version_repo"
done
Loading…
Cancel
Save