savannah-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Savannah-cvs] administration/infra/bin sv_cvs_root_etc.pl


From: Sylvain Beucler
Subject: [Savannah-cvs] administration/infra/bin sv_cvs_root_etc.pl
Date: Mon, 10 Jan 2005 14:53:53 -0500

CVSROOT:        /cvsroot/administration
Module name:    administration
Branch:         
Changes by:     Sylvain Beucler <address@hidden>        05/01/10 19:38:44

Modified files:
        infra/bin      : sv_cvs_root_etc.pl 

Log message:
        Handle www group, and use Perl to copy the file (avoid creating 2000 
processes per update)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/administration/administration/infra/bin/sv_cvs_root_etc.pl.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: administration/infra/bin/sv_cvs_root_etc.pl
diff -u administration/infra/bin/sv_cvs_root_etc.pl:1.1 
administration/infra/bin/sv_cvs_root_etc.pl:1.2
--- administration/infra/bin/sv_cvs_root_etc.pl:1.1     Wed Dec 29 20:43:27 2004
+++ administration/infra/bin/sv_cvs_root_etc.pl Mon Jan 10 19:38:44 2005
@@ -22,15 +22,81 @@
 use strict;
 use Savannah;
 
+$ENV{'PATH'} = "/bin:/usr/bin";
+
+my $lockfile = "/var/run/sv_database2system.lock";
+# Locks: There are several sv_db2sys scripts but they should not run
+#        concurrently.  So we add a lock
+if (-e $lockfile) {
+    die "There's a lock ($lockfile), exiting";
+}
+`touch $lockfile`;
+
+
 my @projects = GetDB("groups, group_type",
                     "status='A' and ((use_cvs!='0' and 
group_type.can_use_cvs!='0') OR (use_homepage!='0' and 
group_type.can_use_homepage!='0')) and groups.type = group_type.type_id",
                     "unix_group_name");
 
-# TODO: Handle group 'www'???
-# -> For now, done in sv_users
-
 umask 0022; # first '0' is for Perl octal mode
 
+#my @exclude = qw//;
+
+# Web groups for group types GNU, www.gnu.org and translation teams
+my @www_groups;
+# sv.gnu.org specific, related to the special group www 
+my @type1 = GetGroupList("type='1' AND status='A'", "unix_group_name");
+my @type3 = GetGroupList("type='3' AND status='A'", "unix_group_name");
+my @type5 = GetGroupList("type='5' AND status='A'", "unix_group_name");
address@hidden = map { "web".$_ } (@type1, @type3, @type5);
+
+# Members of group 'www' that will be added to those groups
+my $www_members = join(",", GetDBList("user,user_group", 
"user_group.user_id=user.user_id AND 
user_group.group_id='".GetGroupSettings("www", 
"group_id")."'","user.user_name"));
+
+
+##
+# Getting the original files
+##
+
+open(PASSWD, "< /etc/passwd");
+my @passwd = <PASSWD>;
+close(PASSWD);
+
+open(GROUP, "< /etc/group");
+my @group = <GROUP>;
+close(GROUP);
+
+
+##
+# Filtering
+##
+
+# TODO: Remove users/groups that are not in the database
address@hidden = grep {
+#    my ($user, $uid) = split(":", $_);
+#    ($uid > 1000) 1 : 0;
+#} @passwd;
+
+# Add www members to each webgroup
+map {
+    my ($name, $x, $gid, $userlist) = split(":", $_);
+    if (grep { $name eq $_ } @www_groups) {
+       chomp $userlist;
+       $userlist = ($userlist) ? "$userlist,$www_members" : $www_members;
+       $_ = join(":", $name, $x, $gid, $userlist) . "\n";
+    }
+} @group;
+
+# Debug
+# grep { print $_; } @group;
+
+
+##
+# Copying
+##
+
+my $passwd_content = join('', @passwd);
+my $group_content = join('', @group);
+
 my $passwd_mtime = (stat("/etc/passwd"))[9];
 my $group_mtime = (stat("/etc/group"))[9];
 
@@ -41,12 +107,22 @@
     my $repos_passwd = "/savannah/cvsroot/$project_name/etc/passwd";
     my $repos_passwd_mtime = (stat($repos_passwd))[9];
     if (!$repos_passwd_mtime || $repos_passwd_mtime < $passwd_mtime) {
-       system('/bin/cp', '/etc/passwd', $repos_passwd);
+       copy($passwd_content, $repos_passwd);
     }
 
     my $repos_group = "/savannah/cvsroot/$project_name/etc/group";
     my $repos_group_mtime = (stat($repos_group))[9];
     if (!$repos_group_mtime || $repos_group_mtime < $group_mtime) {
-       system('/bin/cp', '/etc/group', $repos_group);
+       copy($group_content, $repos_group);
     }
 }
+
+unlink($lockfile);
+
+
+sub copy() {
+    my ($content, $file) = @_;
+    open(OUT, "> $file");
+    print OUT $content;
+    close(OUT);
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]