move ganerated stuff to local_data
[spider.git] / perl / update_sysop.pl
1 #!/usr/bin/env perl
2 #
3 # remove all records with the sysop/cluster callsign and recreate
4 # it from the information contained in DXVars
5 #
6 # WARNING - this must be run when the cluster.pl is down!
7 #
8 # This WILL NOT delete an old sysop call if you are simply
9 # changing the callsign.
10 #
11 # Copyright (c) 1998 Dirk Koopman G1TLH
12 #
13 #
14
15
16 # make sure that modules are searched in the order local then perl
17 BEGIN {
18         # root of directory tree for this system
19         $root = "/spider"; 
20         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
21
22         unshift @INC, "$root/local";
23 }
24
25 use SysVar;
26 use DXUser;
27 use DXUtil;
28
29 sub create_it
30 {
31         my $ref;
32         
33         while ($ref = DXUser::get(uc $mycall)) {
34                 print "old call $mycall deleted\n";
35                 $ref->del();
36         }
37         
38         my $self = DXUser->new(uc $mycall);
39         $self->{alias} = uc $myalias;
40         $self->{name} = $myname;
41         $self->{qth} = $myqth;
42         $self->{qra} = uc $mylocator;
43         $self->{lat} = $mylatitude;
44         $self->{long} = $mylongitude;
45         $self->{email} = $myemail;
46         $self->{bbsaddr} = $mybbsaddr;
47         $self->{homenode} = uc $mycall;
48         $self->{sort} = 'S';            # C - Console user, S - Spider cluster, A - AK1A, U - User, B - BBS
49         $self->{priv} = 9;                      # 0 - 9 - with 9 being the highest
50         $self->{lastin} = 0;
51         $self->{dxok} = 1;
52         $self->{annok} = 1;
53
54         # write it away
55         $self->close();
56         print "new call $mycall added\n";
57
58         # now do one for the alias
59         while ($ref = DXUser::get($myalias)) {
60                 print "old call $myalias deleted\n";
61                 $ref->del();
62         }
63
64         $self = DXUser->new(uc $myalias);
65         $self->{name} = $myname;
66         $self->{qth} = $myqth;
67         $self->{qra} = uc $mylocator;
68         $self->{lat} = $mylatitude;
69         $self->{long} = $mylongitude;
70         $self->{email} = $myemail;
71         $self->{bbsaddr} = $mybbsaddr;
72         $self->{homenode} = uc $mycall;
73         $self->{sort} = 'U';            # C - Console user, S - Spider cluster, A - AK1A, U - User, B - BBS
74         $self->{priv} = 9;                      # 0 - 9 - with 9 being the highest
75         $self->{lastin} = 0;
76         $self->{dxok} = 1;
77         $self->{annok} = 1;
78         $self->{lang} = 'en';
79         $self->{group} = [qw(local #9000)];
80   
81         # write it away
82         $self->close();
83         print "new call $myalias added\n";
84
85 }
86
87 die "\$myalias \& \$mycall are the same ($mycall)!, they must be different (hint: make \$mycall = '${mycall}-2';).\n" if $mycall eq $myalias;
88
89 $lockfn = localdata("cluster.lck");       # lock file name
90 if (-e $lockfn) {
91         open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!";
92         my $pid = <CLLOCK>;
93         chomp $pid;
94         die "Sorry, Lockfile ($lockfn) and process $pid exist, a cluster is running\n" if kill 0, $pid;
95         close CLLOCK;
96 }
97
98 DXUser::init(1);
99 create_it();
100 DXUser:finish();
101 print "Update of $myalias on cluster $mycall successful\n";
102 exit(0);
103