-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_server_installer.rb
148 lines (124 loc) · 4.01 KB
/
update_server_installer.rb
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# @BEGIN_LICENSE
#
# Halyard - Multimedia authoring and playback system
# Copyright 1993-2009 Trustees of Dartmouth College
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
#
# @END_LICENSE
require 'fileutils'
require 'pathname'
require 'time'
require 'buildscript/manifest_parser'
class UpdateServer
include ManifestParser
def UpdateServer.parse_log str
lines = []
str.each_line do |line|
fields = line.split(" ", 5)
lines += [{ :before => fields[0], :after => fields[1], :user => fields[2],
:time => fields[3], :notes => fields[4] && fields[4].chomp }]
end
lines
end
def initialize updater_dir, opts = { }
@root = Pathname.new(updater_dir)
@user = opts[:user] or ENV["USER"]
end
def release_from_staging notes=""
update_spec_file "staging.spec", "release.spec", notes
end
def stage_update build_id, notes=""
update_spec_file "manifests/#{build_id}/release.spec", "staging.spec", notes
end
def canonical_path file
if file.symlink?
file = file.readlink
end
file.expand_path
end
def update_spec_file src, dst, notes=""
src_file = @root + src
src_sig = @root + "#{src}.sig"
dst_file = @root + dst
dst_sig = @root + "#{dst}.sig"
log = @root + "#{dst}.log"
if dst_file.exist?
old_build = parse_spec_file(dst_file.read)["Build"]
else
old_build = "<null>"
end
new_build = parse_spec_file(src_file.read)["Build"]
time = Time.now.xmlschema # Time in YYYY-MM-DDTHH:MM:SS[+-]TZ format
File.open(log, 'a') do |file|
file.puts "#{old_build} #{new_build} #{@user} #{time} #{notes}"
end
rm dst_file if dst_file.exist?
ln_s canonical_path(src_file), dst_file
rm dst_sig if dst_sig.exist?
ln_s canonical_path(src_sig), dst_sig if src_sig.exist?
end
end
class UpdateServerInstaller
include ManifestParser
def initialize source_path, dest_path, opts = { }
@source = Pathname.new(source_path)
@dest = Pathname.new(dest_path)
@spec_file = @source + "release.spec"
@sig_file = @source + "release.spec.sig"
@spec = parse_spec_file(@spec_file.read)
@manifest_files = []
@full_manifest = []
@spec["MANIFEST"].each do |manifest_entry|
manifest_file = @source + manifest_entry.filename
@manifest_files << manifest_file
manifest = parse_manifest(manifest_file.read)
@full_manifest += manifest
end
@user = opts[:user]
end
def build_update_installer
build_manifest_dir
populate_pool
symlink_staging_spec
end
def build_manifest_dir
@manifest_dir = @dest + "manifests" + @spec["Build"]
mkdir_p @manifest_dir
files_to_copy = @manifest_files + [@spec_file, @sig_file]
files_to_copy.each do |file|
cp file, @manifest_dir
chmod 0444, @manifest_dir+file.basename
end
chmod 0555, @manifest_dir
end
def populate_pool
pool_dir = @dest + "pool"
mkdir_p pool_dir
@full_manifest.each do |manifest_entry|
unless (pool_dir + manifest_entry.hash).exist?
dest_file = pool_dir + manifest_entry.hash
cp(@source + manifest_entry.filename, dest_file)
chmod 0444, dest_file
end
end
end
def symlink_staging_spec
server = UpdateServer.new(@dest, :user => @user)
# Path names are relative to @dest
server.stage_update(@spec["Build"], "staging.spec")
end
end