forked from BigRedS/play
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadonly.monitor
More file actions
executable file
·73 lines (66 loc) · 1.98 KB
/
Copy pathreadonly.monitor
File metadata and controls
executable file
·73 lines (66 loc) · 1.98 KB
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
#! /usr/bin/perl
use strict;
#
# By Avi, aged 25 1/2
#
# Parses fstab, and for each device that looks like it should be writeable,
# attempts to write a file in the root of its mountpoint. Ignores CDs,
# floppy disks and swap. Anything else can be ignored with a comment in fstab so:
#
#readonly.ignore:/dev/sda1 /dev/sda2
#
# which specifies devices to not check.
#
# The 'current' version of this can be found at:
# http://github.com/BigRedS/play/blob/master/readonly.monitor
# click 'raw' for something wgettable.
#
my $fstab = "/etc/fstab";
my $testFile = ".write-test";
# %fstab is a hash of arrays [mountpoint, filesystem, options] using the /dev
# path as a key
my %fstab;
my @ignore;
open(my $f, "<", $fstab);
while(<$f>){
if ( /^#readonly\.ignore:/i ){
@ignore = split(/,\s?/, (split(/:/, $_))[1]);
}
# (( begins with a slash or 'UUID'))
if (( /^\s?\//) || (/^\s?UUID/ )) {
my ($dev,$mountpoint,$fs,$opt)=(split(/\s+/, $_))[0,1,2,3];
$fstab{$dev} = [$mountpoint, $fs, $opt];
}
}
my (@failure);
foreach my $dev (keys(%fstab)){
if ( !grep(/$dev/, @ignore)) {
my $mountpoint = $fstab{$dev}[0];
my $fs = $fstab{$dev}[1];
my @opt = split(/,/ , $fstab{$dev}[2]);
my $file = $mountpoint."/".$testFile;
$file =~ s/\/\//\//;
# neither swap nor cd #mounted auto # not a floppy disk or a cd
if (($fs !~ /(swap|udf)/) && (grep(!/^noauto$/, @opt)) && ($dev !~ /\/dev\/(fd|cdrom)\d/)){
`sudo /usr/bin/touch $file 2>&1 > /dev/null`;
if ($? != 0){
push(@failure, $dev);
}
}
}
}
if ($failure[0]){
foreach(@failure){
chomp $_;
print $_." ";
}
if ($failure[1]){
print "are read-only\n";
}else{
print "is read-only\n";
}
exit 1;
}else{
print "All writeable\n";
exit 0
}