bijna werkende permissie check
This commit is contained in:
parent
118f0b1cab
commit
e5776d052b
1 changed files with 60 additions and 7 deletions
53
mycp/mycp
53
mycp/mycp
|
|
@ -35,6 +35,7 @@ $cpcmd
|
|||
$cvscmd
|
||||
$mkdircmd
|
||||
$sudocmd
|
||||
$permsfile
|
||||
);
|
||||
|
||||
$hostname = hostname();
|
||||
|
|
@ -47,6 +48,10 @@ $sudocmd = "/usr/bin/sudo";
|
|||
|
||||
&readconfig;
|
||||
|
||||
unless ( $permsfile ) {
|
||||
$permsfile = $cvspath ? "$cvspath/PERMS" : "";
|
||||
}
|
||||
|
||||
my %option = ();
|
||||
&cmdline;
|
||||
|
||||
|
|
@ -56,6 +61,7 @@ if ( $cvspath ) {
|
|||
foreach ( @ARGV ) {
|
||||
if ( -f $_ ) {
|
||||
&incvs($_); # check if file exists in cvs else make it so
|
||||
&inperms($_); # check if file perms are registered or make it so
|
||||
unless (&cmptocvs($_)) { # compare file to cvs
|
||||
print "$_ not in sync with cvs version\n";
|
||||
print "please fix this\n";
|
||||
|
|
@ -166,6 +172,45 @@ sub incvs($) {
|
|||
}
|
||||
}
|
||||
|
||||
sub inperms($) {
|
||||
my $file = shift;
|
||||
my $path = &fullpath($file);
|
||||
my $fullname = "$path/" . basename($file);
|
||||
my @stats = stat $fullname;
|
||||
my $user = (getpwuid($stats[4]))[0];
|
||||
my $group = (getgrgid($stats[5]))[0];
|
||||
my $mode = sprintf "%lo", $stats[2];
|
||||
$mode =~ s/.*(\d{4})$/$1/;
|
||||
|
||||
print "$mode:$user:$group:$fullname\n";
|
||||
exit;
|
||||
|
||||
unless ( -f $permsfile ) {
|
||||
print <<EOT;
|
||||
# \$Id\$
|
||||
# \$Source\$
|
||||
|
||||
EOT
|
||||
system("$cvscmd add $permsfile");
|
||||
system("$cvscmd ci -m initial $permsfile");
|
||||
}
|
||||
|
||||
my $perms = &slurp($permsfile);
|
||||
|
||||
if ( $perms =~ /^(\d{4}):([^-:][^:]*):([^:]+?):$fullname$/o ) {
|
||||
# check perms
|
||||
# update als optie -p anders file skippen
|
||||
} else {
|
||||
|
||||
open(FH, ">>$permsfile");
|
||||
print FH "$mode:$user:$group:$fullname\n";
|
||||
close FH;
|
||||
system("$cvscmd ci -m \"adding $fullname\" $permsfile");
|
||||
}
|
||||
print "$path\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
sub edit($) {
|
||||
if ( exists $ENV{'EDITOR'} ) {
|
||||
$editor = $ENV{'EDITOR'};
|
||||
|
|
@ -307,6 +352,14 @@ sub fullpath($) {
|
|||
}
|
||||
}
|
||||
|
||||
sub slurp($) {
|
||||
my $file = shift;
|
||||
open(FH, "<$file") or die "Couldn't open $file: $!\n";
|
||||
my $result = do { local $/; <FH>; };
|
||||
close FH;
|
||||
return $result;
|
||||
}
|
||||
|
||||
sub help {
|
||||
print <<EOT;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue