std sh til-kron
[sunny256-utils.git] / mklist
blob56225bcc636bcd31b0064984c1fdbe5af2722cf2
1 #!/usr/bin/env perl
3 # mklist
4 # File ID: ff48cd30-5d3f-11df-a4bd-90e6ba3022ac
5 # Made by Øyvind A. Holm <sunny@dataguard.no>
7 use Fcntl ':flock';
9 my $curr_time = time;
10 chomp($host_name = `hostname`);
11 $host_name =~ s!/!!g;
12 my $cvs_comment = "af-$host_name-" . &sec2str($curr_time);
13 my $lock_file = "/home/sunny/MKLIST_LOCK";
14 my $af_dir = "/home/sunny/etc/af/$host_name";
15 my $af_file = "$af_dir/af-$host_name.dat";
16 my $find_path = "/home"; # Evt. flere separeres med space
17 my $stripgz_prog = "/home/sunny/bin/stripgz";
18 my $sort_prog = "/bin/sort -k2";
19 my $cvs_prog = "/usr/bin/cvs";
20 my $sunny_uid = 500;
21 my $sunny_gid = 500;
22 my $cvs_root = "/home/sunny/af-cvsroot";
23 # my $repository_name = "aftest-$host_name"; # Sikkert ikke nødvendig.
24 my $LogName = "sunny";
26 # print "EUID = \"$>\"\n";
28 $> && die("$0: Has to be root\n");
29 die(sprintf("$0: Unknown find(1) version: \"%s\"\n", `find --version`)) unless (`find --version` =~ /GNU find/);
31 # FIXME: Skal flock() brukes? Kommer seinere.
32 die("$0: Lock file $lock_file exists\n") if (-e $lock_file);
34 die("$0: $cvs_root: Directory not found. Run \"cvs -d $cvs_root init\"\n") unless (-d $cvs_root);
36 open(LockFP, ">$lock_file") || die("$0: $lock_file: Can't open lock file: $!\n");
37 flock(LockFP, LOCK_EX);
38 printf(LockFP "%u\n", $curr_time);
39 unless (-d $af_dir) {
40 mkdir($af_dir, 0755) or die("$0: $af_dir: Can't create directory: $!\n");
42 chdir $af_dir || die("$0: $af_dir: Can't chdir to directory: $!\n");
44 $Result = system("(echo \"# $(suuid -t mklist)\"; (find $find_path -xdev -type f -printf \"%TY%Tm%TdT%TH%TM%TS %p\\n\" | $stripgz_prog | $sort_prog)) >$af_file");
45 $> = $sunny_uid;
46 $) = $sunny_gid;
47 $ENV{CVSROOT} = "$cvs_root";
48 $ENV{LOGNAME} = "$LogName";
49 # system("/usr/bin/printenv");
50 system("$cvs_prog -Q -d $cvs_root commit -m \"$cvs_comment\"");
52 close(LockFP);
53 unlink($lock_file) or die("$0: $lock_file: Can't unlink lock file: $!\n");
55 # print "Like før slutten\n";
56 exit;
58 sub sec2str {
59 my @TA = gmtime(shift);
60 my $UtcTime = sprintf("%04u%02u%02uT%02u%02u%02uZ", $TA[5]+1900, $TA[4]+1, $TA[3], $TA[2], $TA[1], $TA[0]);
61 return($UtcTime);
62 } # sec2str()
64 #### End of file mklist ####