0
1

Add make-homes.pl

This commit is contained in:
2025-05-05 13:11:27 +02:00
committed by h7x4
parent 2a513db520
commit 7be1dbfa23

45
make-homes.pl Normal file

@ -0,0 +1,45 @@
#! /usr/bin/perl
# Går gjennom passwd.pvv og oppretter alle hjemmekataloger som mangler.
use strict;
use warnings;
use File::Basename;
sub execute {
if (system(@_) != 0) {
die "Failed to execute " . join(" ", @_);
}
}
my $passwd = "/etc/passwd.pvv";
my $homes_created = 0;
open (my $passwd_fd, $passwd) or die "Unable to open $passwd: $!";
while (<$passwd_fd>) {
chomp;
my ($user, undef, $uid, $gid, undef, $homedir, $shell) = split(":");
# Ignorer brukere som uansett ikke får lvov til å logge inn
next if $shell eq "/bin/sperret" || $shell eq "/bin/msgsh" || $shell eq "/bin/false";
# Prefix med /export, som er lokal path på NFS-serveren
$homedir = "/export" . $homedir;
# Only create homedir if it is missing, and it would have been exported from here
if (-d dirname($homedir) && !-d $homedir) {
print "Oppretter hjemmekatalog for $user: $homedir\n";
$homes_created = 1;
execute("mkdir", "-p", "-m", "711", $homedir);
execute("cp -r /local/skel/usr/.??* $homedir");
execute("chown", "-R", "$uid:$gid", $homedir);
execute("find", $homedir, "-type", "f", "-exec", "chmod", "600", "{}", "+");
execute("find", $homedir, "-type", "d", "-exec", "chmod", "700", "{}", "+");
execute("chmod", "711", $homedir); # Må ha execute, så ~/web-docs virker
}
}
if ($homes_created) {
execute("/local/quota/makeexportsandquota.pl");
}