source: locker/update-system/bin/build-update @ 446

Last change on this file since 446 was 446, checked in by quentin, 15 years ago
Autoupgrade system, draft 1
  • Property svn:executable set to *
File size: 3.5 KB
Line 
1#!/usr/athena/bin/perl
2
3use File::Spec::Functions qw(:ALL);
4use File::Copy;
5use File::Path;
6use Data::Dumper;
7use Getopt::Long;
8use Cwd;
9use strict;
10use warnings;
11
12my $scriptsdev = "";
13
14GetOptions(
15#"redo-delete" => \$redodelete,
16#          "redo-add" => \$redoadd,
17#          "redo-replace" => \$redoreplace,
18#          "redo-diff" => \$redodiff,
19#          "redo-all" => sub {$redodelete = $redoadd = $redoreplace = $redodiff = 1;},
20           "dev" => sub {$scriptsdev = "dev";},
21                  );
22
23if (@ARGV < 3) {
24  print STDERR "Usage: $0 package oldversion newversion\n";
25  exit(1);
26}
27
28my ($package, $oldversion, $newversion) = @ARGV;
29my ($old, $new, $updatename) = ($package.'-'.$oldversion, $package.'-'.$newversion, $package.'-'.$oldversion.'-to-'.$newversion);
30
31my $proposaldir = $updatename.".proposal";
32my $outdir = catdir("/mit/scripts/deploy$scriptsdev/updates/", $updatename);
33
34(-d $proposaldir) or die "Can't find $proposaldir, did you run propose-update?\n";
35(-d $outdir || mkdir($outdir)) or die "mkdir($outdir) failed: $!";
36
37my $olddir = catdir($proposaldir,$old);
38my $newdir = catdir($proposaldir,$new);
39(-d $olddir && -d $newdir) or die "Packages not unpacked?\n";
40
41sub readFileList($) {
42  my ($list) = @_;
43  open(LIST, $list) or die "Can't read $list: $!\n";
44  my @files = map { chomp; s|$newdir\/?||g; [split(' ', $_, 2)] } <LIST>;
45  close(LIST);
46  return @files;
47}
48
49my @todelete = readFileList(catfile($proposaldir, "files.delete"));
50my @toadd = readFileList(catfile($proposaldir, "files.add"));
51my @toreplace = readFileList(catfile($proposaldir, "files.replace"));
52
53open(CHECKMD5, ">", catfile($outdir, "check.md5")) or die "Can't open check.md5: $!";
54print CHECKMD5 map { join(" ", @{$_})."\n" } @todelete, @toreplace;
55close(CHECKMD5);
56
57open(ABSENT, ">", catfile($outdir, "oldfiles.absent")) or die "Can't open oldfiles.absent: $!";
58print ABSENT map { $_->[1]."\n" } @toadd;
59close(ABSENT);
60
61open(DELETE, ">", catfile($outdir, "files.delete")) or die "Can't open files.delete: $!";
62print DELETE map { $_->[1]."\n" } @todelete, @toreplace;
63close(DELETE);
64
65my $outfiledir = catdir($outdir, "newfiles");
66(-d $outfiledir || mkdir($outfiledir)) or die "Can't mkdir($outfiledir)\n";
67
68foreach my $file (@toadd, @toreplace) {
69  my $filename = $file->[1];
70  my $src = catfile($newdir, $filename);
71  my $dest = catfile($outfiledir, $filename);
72  my (undef, $dir, undef) = splitpath($dest);
73  mkpath($dir);
74  copy($src, $dest) or die "Couldn't copy $filename from $src to $dest: $!";
75}
76
77copy(catfile($proposaldir, "update.diff"), catfile($outdir, "update.diff")) or die "Couldn't copy update.diff: $!";
78
79open (SCRIPT, ">", catfile($outdir, "update")) or die "Couldn't write update: $!";
80printf SCRIPT <<'EOF', $updatename, $new;
81#!/bin/bash
82set -e -o noclobber
83
84die () { echo "$1" >&2; exit 1; }
85
86patchdir=$(dirname "$0")
87
88>.scripts-security-upd-lock || die "error: Unable to obtain update lock."
89
90echo "[$PWD] begin dry run"
91
92xargs -n1 test ! -e <"$patchdir/oldfiles.absent" || die "error: Conflicting files exist."
93md5sum -c "$patchdir/check.md5" || die "error: MD5 check failed."
94patch -stN --dry-run --no-backup-if-mismatch -p1 <"$patchdir/update.diff" || due "error: Patch dry run failed."
95
96echo "[$PWD] dry run OK, applying update"
97
98mv .scripts-version .scripts-version.old
99patch -stN --no-backup-if-mismatch -p1 <"$patchdir/update.diff" || :
100xargs rm -f <"$patchdir/files.delete"
101cp -a "$patchdir/newfiles/." .
102(cat .scripts-version.old; date; echo "%s"; echo "%s") >>.scripts-version
103rm -f .scripts-version.old
104
105rm -f .scripts-security-upd-lock
106
107echo "[$PWD] done"
108
109exit 0
110EOF
111chmod 0755, catfile($outdir, "update");
Note: See TracBrowser for help on using the repository browser.