-
Notifications
You must be signed in to change notification settings - Fork 4
/
osx-noatime.sh
executable file
·116 lines (84 loc) · 1.92 KB
/
osx-noatime.sh
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#! /bin/bash
#
# Tweak OS X to not have atime updates on its file systems.
# (c) 2012, 2013 Sudhi Herle <sw at herle.net>
# License: GPLv2
#
# Notes:
# - Running this script once sets the noatime option on /
# - When invoked as "$0 install", it will set itself up
# as a system startup item to set this at every boot
FNAME=net.herle.noatime
me=`id -u`
if [ $me -ne 0 ]; then
echo "$0: Need root privilege to run; switching to dry-run mode .."
e=echo
fi
#set -x
usage() {
cat 1>&2 <<EOF1
Usage: $0 start|install
start: Set noatime on /
install: Creates a system startup file in /Library/LaunchDaemons/$FNAME.plist
EOF1
exit 1
}
# Installs a startup service
install_service() {
local rdir=/Library/LaunchDaemons
if [ $me -ne 0 ]; then
rdir=/tmp
fi
local file=$rdir/${FNAME}.plist
cat > $file <<EOF2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>$FNAME</string>
<key>Disabled</key>
<false/>
<key>UserName</key>
<string>root</string>
<key>GroupName</key>
<string>wheel</string>
<key>Debug</key>
<false/>
<key>KeepAlive</key>
<false/>
<key>RunAtLoad</key>
<true/>
<!-- We only mount / with the noatime option -->
<key>ProgramArguments</key>
<array>
<string>mount</string>
<string>-uvw</string>
<string>-o</string>
<string>noatime</string>
<string>/</string>
</array>
</dict>
</plist>
EOF2
$e chmod 0644 $file
return 0
}
if [ -z "$1" ]; then
usage
exit 1
fi
case $1 in
start)
echo "Setting noatime on /"
$e mount -uvw -o noatime /
;;
install)
install_service
;;
*)
usage
exit 1
;;
esac
# vim: expandtab:sw=4:ts=4:tw=72:notextmode: