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, 14 Mar 2005 17:48:43 -0500

CVSROOT:        /cvsroot/administration
Module name:    administration
Branch:         
Changes by:     Sylvain Beucler <address@hidden>        05/03/14 22:48:43

Modified files:
        infra/bin      : sv_cvs_root_etc.pl 

Log message:
        Generated passwd files are now smaller, and the timestamp of the first 
group is checked to see if it worth performing all the script

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/administration/administration/infra/bin/sv_cvs_root_etc.pl.diff?tr1=1.5&tr2=1.6&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.5 
administration/infra/bin/sv_cvs_root_etc.pl:1.6
--- administration/infra/bin/sv_cvs_root_etc.pl:1.5     Thu Feb 24 22:44:42 2005
+++ administration/infra/bin/sv_cvs_root_etc.pl Mon Mar 14 22:48:42 2005
@@ -19,23 +19,13 @@
 # along with Savane; if not, write to the Free Software Foundation,
 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-
-# TODO:
-# - If the first group if already more recent that /etc/group, maybe we can 
stop the script directly. This does not handle the case where this first group 
was manually edited since the last /etc/group change, but that should only 
occur rarely
-# - Create an array of users that belong to each group, and only add these 
users to etc/passwd
-# - Remove users that are not in the group
-# Code to keep meanwhile:
-# @passwd = grep {
-#     my ($user, $uid) = split(":", $_);
-#     ($uid > 1000) 1 : 0;
-# } @passwd;
-
-
 use strict;
 use Savannah;
 
 $ENV{'PATH'} = "/bin:/usr/bin";
 
+umask 0022; # first '0' is for Perl octal mode
+
 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
@@ -49,9 +39,21 @@
                     "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");
 
-umask 0022; # first '0' is for Perl octal mode
+my $passwd_mtime = (stat("/etc/passwd"))[9];
+my $group_mtime = (stat("/etc/group"))[9];
+
+
+# - If the first group if already more recent that /etc/group, we can
+# stop the script directly. This does not handle the case where this
+# first group was manually edited since the last change in /etc/group,
+# but that should only occur rarely.
+
+my $repos_1st_group = "/savannah/cvsroot/$projects[0]/etc/group";
+my $repos_1st_group_mtime = (stat($repos_1st_group))[9];
+if ($repos_1st_group_mtime > $group_mtime) {
+    exit 0;
+}
 
-#my @exclude = qw//;
 
 # Web groups for group types GNU, www.gnu.org and translation teams
 my @www_groups;
@@ -79,20 +81,34 @@
 
 
 ##
-# Filtering
+# Building hashes
 ##
 
+my %passwd_content;
+# Builds the users hash
+foreach my $user_line (@passwd_lines) {
+    my ($name) = split(":", $user_line);
+    $passwd_content{$name} = $user_line;
+}
+
 my %group_content;
+my %group_passwd;
 # Builds the groups hash
 # Add www members to each webgroup
+# Fill in each group's shortened, specific passwd file.
 map {
-    my ($name, $x, $gid, $userlist) = split(":", $_);
-    if (grep { $name eq $_ } @www_groups) {
-       chomp $userlist;
+    my ($group_name, $x, $gid, $userlist) = split(':', $_);
+    chomp $userlist;
+    if (grep { $group_name eq $_ } @www_groups) {
        $userlist = ($userlist) ? "$userlist,$www_members" : $www_members;
-       $_ = join(":", $name, $x, $gid, $userlist) . "\n";
+       $_ = join(":", $group_name, $x, $gid, $userlist) . "\n";
+    }
+    $group_content{$group_name} = $_;
+
+    my @users = split(',', $userlist);
+    foreach my $user (@users) {
+       $group_passwd{$group_name} .= $passwd_content{$user};
     }
-    $group_content{$name} = $_;
 } @group_lines;
 
 # Debug
@@ -103,13 +119,6 @@
 # Copying
 ##
 
-my $passwd_content = join('', @passwd_lines);
-#my $group_content = join('', @group_lines);
-
-my $passwd_mtime = (stat("/etc/passwd"))[9];
-my $group_mtime = (stat("/etc/group"))[9];
-
-
 # Process active public projects
 for my $project_name (sort @projects) {
     chomp($project_name);
@@ -117,7 +126,7 @@
     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) {
-       copy($passwd_content, $repos_passwd);
+       copy($group_passwd{$project_name}, $repos_passwd);
     }
 
     my $repos_group = "/savannah/cvsroot/$project_name/etc/group";




reply via email to

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