/
IcculusFinger_planmove.pl
executable file
·91 lines (71 loc) · 2.34 KB
/
IcculusFinger_planmove.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/perl -w
use strict;
my $homebasedir = '/home';
my $fingerspace = '/fingerspace';
sub chown_by_name {
my($user, $file) = @_;
chown((getpwnam($user))[2], (getpwnam('root'))[3], $file) == 1 or
die("chown on $file failed: $!\n");
}
sub check_dir {
my $user = shift;
my $nofingerpath = "$homebasedir/$user/.nofinger";
my $homepath = "$homebasedir/$user/.plan";
my $fingerpath = "$fingerspace/$user";
if (($user eq '.') or ($user eq '..')) {
return;
}
if (not -d "$homebasedir/$user") {
print(" - $homebasedir/$user isn't a directory. Wierd.\n");
return;
}
# ...since the user can WRITE to an existing file, but not create one
# in the fingerspace, we need to create it if it doesn't exist...
if (not -e $fingerpath) {
print(" + Creating $fingerpath ...\n");
# God, I'm lazy. :)
`touch $fingerpath`;
if (not -e $fingerpath) {
print("Failed to create.\n");
return;
}
}
# always fix permissions ...
chmod(0644, $fingerpath) or die("Failed to chmod $fingerpath: $!\n");
chown_by_name($user, $fingerpath);
if (not -e $homepath) {
print(" + symlinking missing file $homepath to $fingerpath ...\n");
symlink($fingerpath, $homepath) or die("symlink failed: $!\n");
return;
}
# (For now, we'll assume that a symlink means we've moved it already.)
if (-l $homepath) {
if (readlink($homepath) ne $fingerpath) {
print(" - There's an UNEXPECTED SYMLINK at $homepath ...\n");
}
return;
}
if (-d $homepath) {
print(" - Uh...there's a DIRECTORY at $homepath ...\n");
return;
}
if (-d $fingerpath) {
print(" - Uh...there's a DIRECTORY at $fingerpath ...\n");
return;
}
if (-e $nofingerpath) {
print(" - $nofingerpath exists. Explicitly skipping ...\n");
return;
}
print(" + Moving $homepath to $fingerpath ... \n");
rename($homepath, $fingerpath) or die("rename failed: $!\n");
symlink($fingerpath, $homepath) or die("symlink failed: $!\n");
}
# the mainline ...
opendir(DIRH, $homebasedir) or die("Can't open $homebasedir: $!\n");
my @homedirs = readdir(DIRH);
closedir(DIRH);
foreach (@homedirs) {
check_dir($_);
}
# end of IcculusFinger_planmove.pl ...