2012-04-18 15:35:38 +04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# load config files
|
2014-10-25 21:47:23 +04:00
|
|
|
if [ -f /etc/gitorious_redmine ]; then
|
|
|
|
source /etc/gitorious_redmine
|
|
|
|
elif [ -f ~/etc/gitorious_redmine ]; then
|
|
|
|
source ~/etc/gitorious_redmine
|
2012-04-18 15:35:38 +04:00
|
|
|
else
|
|
|
|
echo "Config file not found ;-("
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
2014-10-25 21:47:23 +04:00
|
|
|
# === REMOVE ALL BROKEN REPOSITORY LINKS IN REDMINE MYSQL DATABASE ===
|
2012-05-07 21:15:41 +04:00
|
|
|
ALL_MYSQL_REPOS=`mysql -h$MYSQL_HOSTNAME -u $MYSQL_USER -e "SELECT url,root_url,id
|
2014-10-25 21:47:23 +04:00
|
|
|
FROM $REDMINE_MYSQL_DBNAME.repositories
|
2012-05-07 21:15:41 +04:00
|
|
|
WHERE type='Git'
|
2012-05-07 21:34:30 +04:00
|
|
|
OR type='Repository::Git'" \
|
2012-05-07 21:15:41 +04:00
|
|
|
| grep -v tables_col|xargs|sed "s/ /\n/g"|tail -n+4`
|
2012-04-18 15:35:38 +04:00
|
|
|
repos_to_remove=
|
|
|
|
current_url=
|
|
|
|
current_root_url=
|
|
|
|
let n=0
|
|
|
|
for v in $ALL_MYSQL_REPOS; do
|
|
|
|
let idx=n/3
|
|
|
|
case $((n%3)) in
|
|
|
|
0) current_url=$v;;
|
|
|
|
1) current_root_url=$v;;
|
|
|
|
2) [ ! -d $current_url -a ! -d $current_root_url ] && repos_to_remove="$repos_to_remove,$v";;
|
|
|
|
esac
|
|
|
|
let n++
|
|
|
|
done;
|
|
|
|
repos_to_remove=${repos_to_remove#,}
|
2014-10-25 21:47:23 +04:00
|
|
|
[ "$repos_to_remove" != "" ] && mysql -h$MYSQL_HOSTNAME -u $MYSQL_USER -e "DELETE FROM $REDMINE_MYSQL_DBNAME.repositories WHERE id IN ($repos_to_remove)"
|
2012-04-18 15:35:38 +04:00
|
|
|
|
2014-05-11 20:01:18 +04:00
|
|
|
# === REMOVE REPOSITORY LINKS WITH DIFFERENT PROJECT NAMES ===
|
2014-10-25 21:47:23 +04:00
|
|
|
REMOVE_IDS=`mysql -h$MYSQL_HOSTNAME -u $MYSQL_USER -e "SELECT $REDMINE_MYSQL_DBNAME.repositories.id
|
|
|
|
FROM $REDMINE_MYSQL_DBNAME.projects,
|
|
|
|
$REDMINE_MYSQL_DBNAME.repositories,
|
2014-05-11 20:01:18 +04:00
|
|
|
$GITORIOUS_MYSQL_DBNAME.repositories
|
2014-10-25 21:47:23 +04:00
|
|
|
WHERE ($REDMINE_MYSQL_DBNAME.repositories.url=CONCAT('$GITORIOUS_REPOS_PATH/',$GITORIOUS_MYSQL_DBNAME.repositories.hashed_path,'.git')
|
|
|
|
OR $REDMINE_MYSQL_DBNAME.repositories.root_url=CONCAT('$GITORIOUS_REPOS_PATH/',$GITORIOUS_MYSQL_DBNAME.repositories.hashed_path,'.git'))
|
|
|
|
AND $REDMINE_MYSQL_DBNAME.projects.name <> $GITORIOUS_MYSQL_DBNAME.repositories.name
|
|
|
|
AND $REDMINE_MYSQL_DBNAME.projects.id = $REDMINE_MYSQL_DBNAME.repositories.project_id
|
2014-05-11 20:01:18 +04:00
|
|
|
;" \
|
|
|
|
| grep -v tables_col|xargs|sed "s/ /\n/g"|tail -n+2`
|
2014-10-25 21:47:23 +04:00
|
|
|
[ "$REMOVE_IDS" != "" ] && mysql -h$MYSQL_HOSTNAME -u $MYSQL_USER -e "DELETE FROM $REDMINE_MYSQL_DBNAME.repositories WHERE id IN ($REMOVE_IDS)"
|
2014-05-11 20:01:18 +04:00
|
|
|
|
2012-04-18 15:35:38 +04:00
|
|
|
# === GET DATA FROM GITORIOUS MYSQL BASE ===
|
2014-10-25 21:47:23 +04:00
|
|
|
roles_mysql_string=`echo $REDMINE_REQUIRED_ROLES | sed "s~\>~'~g ; s~\<~,'~g ; s~^,~~ ; s~ ~~g"`
|
|
|
|
REDMINE_ID_GITORIOUS_REPO=`mysql --default-character-set=utf8 -h$MYSQL_HOSTNAME -u $MYSQL_USER -e \
|
|
|
|
"SELECT DISTINCT $REDMINE_MYSQL_DBNAME.projects.id,$GITORIOUS_MYSQL_DBNAME.repositories.hashed_path
|
|
|
|
FROM $REDMINE_MYSQL_DBNAME.member_roles,
|
|
|
|
$REDMINE_MYSQL_DBNAME.members,
|
|
|
|
$REDMINE_MYSQL_DBNAME.projects,
|
|
|
|
$REDMINE_MYSQL_DBNAME.roles,
|
|
|
|
$REDMINE_MYSQL_DBNAME.users,
|
2015-09-11 21:45:28 +03:00
|
|
|
$REDMINE_MYSQL_DBNAME.email_addresses,
|
2012-05-07 21:15:41 +04:00
|
|
|
$GITORIOUS_MYSQL_DBNAME.repositories,
|
|
|
|
$GITORIOUS_MYSQL_DBNAME.roles,
|
|
|
|
$GITORIOUS_MYSQL_DBNAME.users
|
2014-10-25 21:47:23 +04:00
|
|
|
WHERE $REDMINE_MYSQL_DBNAME.member_roles.member_id=$REDMINE_MYSQL_DBNAME.members.id
|
|
|
|
AND $REDMINE_MYSQL_DBNAME.member_roles.role_id=$REDMINE_MYSQL_DBNAME.roles.id
|
|
|
|
AND $REDMINE_MYSQL_DBNAME.members.user_id=$REDMINE_MYSQL_DBNAME.users.id
|
|
|
|
AND $REDMINE_MYSQL_DBNAME.members.project_id=$REDMINE_MYSQL_DBNAME.projects.id
|
|
|
|
AND $REDMINE_MYSQL_DBNAME.projects.name=$GITORIOUS_MYSQL_DBNAME.repositories.name
|
|
|
|
AND $REDMINE_MYSQL_DBNAME.users.type='User'
|
2015-09-11 21:45:28 +03:00
|
|
|
AND $REDMINE_MYSQL_DBNAME.email_addresses.address=$GITORIOUS_MYSQL_DBNAME.users.email
|
|
|
|
AND $REDMINE_MYSQL_DBNAME.users.id=$REDMINE_MYSQL_DBNAME.email_addresses.user_id
|
|
|
|
AND $REDMINE_MYSQL_DBNAME.email_addresses.is_default='1'
|
2014-10-25 21:47:23 +04:00
|
|
|
AND $REDMINE_MYSQL_DBNAME.roles.name IN ($roles_mysql_string)
|
2012-05-07 21:32:26 +04:00
|
|
|
AND $GITORIOUS_MYSQL_DBNAME.repositories.user_id=$GITORIOUS_MYSQL_DBNAME.users.id;" \
|
2012-05-07 21:15:41 +04:00
|
|
|
| grep -v tables_col|xargs|sed "s/ /\n/g"|tail -n+3`
|
2012-04-18 15:35:38 +04:00
|
|
|
|
2014-10-25 21:47:23 +04:00
|
|
|
# add repositories paths to $REDMINE_MYSQL_DBNAME.repositories
|
|
|
|
redmine_project_id=
|
2012-04-18 15:35:38 +04:00
|
|
|
gitorious_path=
|
|
|
|
let n=0
|
2014-10-25 21:47:23 +04:00
|
|
|
for v in $REDMINE_ID_GITORIOUS_REPO; do
|
2012-04-18 15:35:38 +04:00
|
|
|
let idx=n/2
|
|
|
|
case $((n%2)) in
|
2014-10-25 21:47:23 +04:00
|
|
|
0) redmine_project_id=$v ;;
|
2012-04-18 15:49:45 +04:00
|
|
|
1) gitorious_path=$GITORIOUS_REPOS_PATH/$v.git
|
2012-04-18 16:06:26 +04:00
|
|
|
# Test for already present repo
|
2012-04-18 16:13:38 +04:00
|
|
|
ALREADY_EXIST=`mysql -h$MYSQL_HOSTNAME -u $MYSQL_USER -e "SELECT id
|
2014-10-25 21:47:23 +04:00
|
|
|
FROM $REDMINE_MYSQL_DBNAME.repositories
|
|
|
|
WHERE project_id='$redmine_project_id'
|
2012-05-07 21:15:41 +04:00
|
|
|
OR url='$gitorious_path'
|
|
|
|
OR root_url='$gitorious_path'" \
|
2012-04-18 16:16:35 +04:00
|
|
|
| grep -v tables_col|xargs|sed "s/ /\n/g"|tail -n+2`
|
2012-04-18 16:34:53 +04:00
|
|
|
if [ "" == "$ALREADY_EXIST" ]; then
|
2014-10-25 21:47:23 +04:00
|
|
|
# insert to $REDMINE_MYSQL_DBNAME.repositories
|
|
|
|
echo "insert $redmine_project_id: $gitorious_path"
|
|
|
|
mysql -h$MYSQL_HOSTNAME -u $MYSQL_USER -e "INSERT INTO $REDMINE_MYSQL_DBNAME.repositories(project_id,
|
2012-04-18 16:34:53 +04:00
|
|
|
url,
|
|
|
|
root_url,
|
|
|
|
type,
|
2014-05-09 17:00:03 +04:00
|
|
|
path_encoding,
|
|
|
|
is_default)
|
2014-10-25 21:47:23 +04:00
|
|
|
VALUES('$redmine_project_id',
|
2012-04-18 16:34:53 +04:00
|
|
|
'$gitorious_path',
|
|
|
|
'$gitorious_path',
|
2014-05-09 16:48:04 +04:00
|
|
|
'Repository::Git',
|
2014-05-09 17:00:03 +04:00
|
|
|
'',
|
|
|
|
1)"
|
2012-04-18 16:34:53 +04:00
|
|
|
fi
|
2012-04-18 15:35:38 +04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
let n++
|
|
|
|
done
|