Voici un script bash que j'ai écrit pour faire exactement cela. Il clone toutes les nouvelles branches, met à jour les branches existantes et supprime les branches qui n'existent plus. Voici les instructions qui "travaillent"; vous pouvez choisir de rendre les choses plus sûres, mais c'est assez bon si votre serveur n'est accessible que sur votre réseau local. J'ai une configuration de travail cron qui l'exécute toutes les 30 minutes sur le serveur. Pour configurer la tâche cron pour exécuter en tant que root, exécutez:
sudo crontab -e
Ensuite, collez dans ces contenus:
*/30 * * * * /usr/local/bin/opengrok_index.sh
ensuite écrire et à proximité:
:wq
Vous devez installer "attend" que le script utilise pour entrer le mot de passe de votre clé ssh. L'un de ces deux commandes ne fonctionnent pas selon ce que linux OS que vous utilisez:
sudo yum install expect
sudo apt-get install expect
Ensuite, créez un fichier à /usr/local/bin/opengrok_index.sh:
sudo vi /usr/local/bin/opengrok_index.sh
Ensuite, la pâte dans le contenu du script (à partir du bas de ce post), et modifier les variables en haut en fonction de votre système. Ensuite, changer les permissions pour seul root peut le lire (il a des mots de passe en elle):
sudo chmod 700 /usr/local/bin/opengrok_index.sh
Vous voulez probablement tester manuellement le script en cours d'exécution et le faire fonctionner, avant d'attendre la tâche cron pour travailler.Ceci est un script particulier que j'ai écrit pour ma configuration particulière, vous devrez peut-être mettre dans certaines déclarations d'écho et faire du débogage pour le faire fonctionner correctement:
sudo /usr/local/bin/opengrok_index.sh
Notes complémentaires:
- Cette script se connecte à GIT via SSH (pas HTTPS). En tant que tel, votre GIT_USER doit exister sur le système et avoir une clé SSH sous /home/user/.ssh/id_rsa qui a accès au dépôt GIT. C'est des trucs de connexion GIT standard donc je ne vais pas le parcourir ici. Le script entrer dans le GIT_USER_SSH_PASSWORD lorsque vous êtes invité
- Le script vérifie tous les fichiers comme GIT_USER, vous devrez peut-être "chown" votre CHECKOUT_LOCATION à cet utilisateur
Script:
#!/bin/bash
SUDO_PASSWORD="password"
CHECKOUT_LOCATION="/var/opengrok/src/"
GIT_PROJECT_NAME="Android"
GIT_USER="username"
GIT_USER_SSH_PASSWORD="password"
GIT_URL="yourgit.domain.com"
OPENGROK_BINARY_FILE="/usr/local/opengrok-0.12.1.6/bin/OpenGrok"
# Run command as GIT_USER which has Git access
function runGitCommand {
git_command="[email protected]"
expect_command="
spawn sudo -u $GIT_USER $git_command
expect {
\"*password for*\" {
send \"$SUDO_PASSWORD\"
send \"\r\"
exp_continue
}
\"*Enter passphrase for key*\" {
send \"$GIT_USER_SSH_PASSWORD\"
send \"\r\"
exp_continue
}
}"
command_result=$(expect -c "$expect_command" || exit 1)
}
# Checkout the specified branch over the network (slow)
function checkoutBranch {
branch=$1
# Check out branch if it does not exist
if [ ! -d "$branch" ]; then
runGitCommand git clone ssh://$GIT_URL/$GIT_PROJECT_NAME
# Rename project to the branch name
mv $GIT_PROJECT_NAME $branch || exit 1
# Otherwise update the existing branch
else
cd $branch || exit 1
runGitCommand git fetch
runGitCommand git pull origin $branch || exit 1
cd ..
fi
}
# If the branch directory does not exist, copy the master
# branch directory then switch to the desired branch.
# This is faster than checkout out over the network.
# Otherwise, update the exisiting branch directory
function updateBranch {
branch=$1
if [ ! -d "$branch" ]; then
mkdir $branch || exit 1
rsync -av master/ $branch || exit 1
cd $branch || exit 1
runGitCommand git checkout -b $branch origin/$branch
cd ..
else
cd $branch || exit 1
runGitCommand git pull origin $branch || exit 1
cd ..
fi
}
# Change to the OpenGrok indexing location to checkout code
cd $CHECKOUT_LOCATION || exit 1
# Check out master branch
checkoutBranch master
# Get a list of all remote branches
cd master || exit 1
old_ifs=$IFS
IFS=$'\n'
origin_branches=($(git branch -r))
IFS=$old_ifs
origin_branches_length=${#origin_branches[@]}
cd .. # Move out of "master" directory
# Loop through and check out all branches
branches=(master)
for origin_branch in "${origin_branches[@]}"
do
# Strip the "origin/" prefix from the branch name
branch=${origin_branch#*/}
# Ignore the "HEAD" branch
# Also skip master since it has already been updated
if [[ $branch == HEAD* ]] || [[ $branch == master* ]]; then
continue
fi
branches+=("$branch")
updateBranch $branch
done
# Get list of branches currently in OpenGrok
old_ifs=$IFS
IFS=$'\n'
local_branches=($(ls -A1))
size=${#local_branches[@]}
IFS=$old_ifs
# Get list of branches that are in OpenGrok, but do not exist
# remotely. These are branches that have been deleted
deleted_branches=()
for local_branch in "${local_branches[@]}"
do
skip=0
for branch in "${branches[@]}"
do
if [[ $local_branch == $branch ]]; then
skip=1;
break;
fi
done
if [[ $skip == "0" ]]; then
deleted_branches+=("$local_branch")
fi
done
# Change to checkout directory again, in case some future code
# change brings us somewhere else. We are deleting recursively
# here and cannot make a mistake!
cd $CHECKOUT_LOCATION
# Delete any branches that no longer exist remotely
for deleted_branch in ${deleted_branches[@]}
do
rm -rf ./$deleted_branch
done
# Reindex OpenGrok
$OPENGROK_BINARY_FILE index
C'est 4 ans. Y a-t-il eu un mod à OpenGrok qui changerait la réponse dans l'intervalle? –
Pour autant que je sache, non. – ebneter