Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib/tasks/mirrorrepos.rake
blob: 5e4ab069918861da0ea784ec7515cdedd705c58e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require File.join(File.dirname(__FILE__), "../gitorious")

namespace :mirror do

  # Creating/synching symlinks to all repos in a separate folder

  # Designate a folder where symlinks to all current repository directories
  # are created. Handy for hosting Gitweb, cgit etc from a separate folder - especially
  # when sharding/hashing the actual repository directories in Gitorious, in which case
  # the folder structure becomes less than human readable when browsing from Gitweb.
  #
  # To keep this updated, schedule regular/frequent runs of this rake task (e.g. cron)

  # EXAMPLE:
  #
  # Run this from the root of your gitorious installation (where you normally run rake tasks)
  # sudo bundle exec rake mirror:symlinkedrepos RAILS_ENV=production
  #

  require 'yaml'

  desc "Create mirror directory with symlinks to all current regular repository paths"
  task :symlinkedrepos => :environment do
    default_mirror_base_path = "#{GitoriousConfig['repository_base_path']}/../mirrored-public-repos"
    mirror_base = GitoriousConfig["symlinked_mirror_repo_base"] || default_mirror_base_path
    mirror_base_new = "#{mirror_base}.new"

    owner = GitoriousConfig["gitorious_user"]

    # create symlink dir if not there already
    `mkdir -p #{mirror_base_new}`
    raise "Failed to create #{mirror_base_new}" unless $?.success?

    # rebuild symlinks for all standard repos (omit private repos, wiki repos etc)
    repo_data = Repository.regular.each do |r|
      if !r.private?
        actual_path = "#{GitoriousConfig["repository_base_path"]}/#{r.real_gitdir}"
        repo_parent_dir = Pathname.new(r.url_path).dirname
        project_dir = "#{mirror_base_new}/#{repo_parent_dir}"
        `mkdir -p #{project_dir}`
        raise "Failed to create #{project_dir}/*" unless $?.success?
        symlink_path = "#{project_dir}/#{r.name}"
        `ln -fs #{actual_path} #{symlink_path}`
        raise "Failed to link #{actual_path} to #{symlink_path}" unless $?.success?
      end
    end

    # make sure gitorious user owns all repo symlinks
    `chown -R #{owner}:#{owner} #{mirror_base_new}`
    raise "Failed to chown #{mirror_base_new}" unless $?.success?

    # remove any current symlinks
    `rm -rf #{mirror_base}.old && mv #{mirror_base} #{mirror_base}.old && mv #{mirror_base_new} #{mirror_base} &&rm -rf #{mirror_base}.old`
    raise "Failed to rename #{mirror_base}" unless $?.success?
  end
end