Debian Codegraph @

pm-prepare

raw
1 #!/bin/sh
2
3 # Public domain notice for all NCBI EDirect scripts is located at:
4 # https://www.ncbi.nlm.nih.gov/books/NBK179288/#chapter6.Public_Domain_Notice
5
6 # pm-prepare
7
8 pth=$( dirname "$0" )
9
10 case "$pth" in
11 /* )
12 ;; # already absolute
13 * )
14 pth=$(cd "$pth" && pwd)
15 ;;
16 esac
17
18 case ":$PATH:" in
19 *:"$pth":* )
20 ;;
21 * )
22 PATH="$PATH:$pth"
23 export PATH
24 ;;
25 esac
26
27 # handle common flags - dot command is equivalent of "source"
28
29 if [ ! -f "$pth"/xcommon.sh ]
30 then
31 echo "ERROR: Unable to find '$pth/xcommon.sh' file" >&2
32 exit 1
33 fi
34
35 . "$pth"/xcommon.sh
36
37 # initialize specific flags
38
39 dbase=""
40 verbose=false
41
42 while [ $# -gt 0 ]
43 do
44 case "$1" in
45 -db )
46 dbase=$2
47 shift
48 shift
49 ;;
50 -* )
51 exec >&2
52 echo "$0: Unrecognized option $1" >&2
53 exit 1
54 ;;
55 * )
56 break
57 ;;
58 esac
59 done
60
61 if [ -z "$dbase" ]
62 then
63 echo "Must supply database in -db argument" >&2
64 exit 1
65 fi
66
67 WriteCacheDirTag() {
68
69 path="$1"
70
71 if [ ! -f "$path/CACHEDIR.TAG" ]
72 then
73 cat >$path/CACHEDIR.TAG <<EOF
74 Signature: 8a477f597d28d172789f06886806bc55
75 # This file is a cache directory tag created by edirect.
76 # For information about cache directory tags, see:
77 # http://www.brynosaurus.com/cachedir/
78 EOF
79 fi
80 }
81
82 for dir in Archive Postings Source Index Invert Merged
83 do
84 target=$( FindLocalArchiveFolder "$dbase" "$dir" "false" )
85 # remove trailing slash
86 target=${target%/}
87 if [ -n "$target" ] && [ -d "$target" ] && [ ! -f "${target}/CACHEDIR.TAG" ]
88 then
89 WriteCacheDirTag "$target"
90 verbose=true
91 fi
92 done
93
94 if [ "$verbose" = false ]
95 then
96 exit 0
97 fi
98
99 HardDriveWarning() {
100
101 path="$1"
102
103 echo "" >&2
104 echo "$path IS ON A HARD DISK DRIVE, NOT THE EXPECTED SOLID-STATE DRIVE." >&2
105 echo "" >&2
106 echo "WOULD YOU LIKE TO PROCEED WITH ARCHIVING EVEN THOUGH IT IS NOT RECOMMENDED? [y/N]" >&2
107 read response
108 case "$response" in
109 [Yy]* ) echo "OK, PROCEEDING." >&2 ;;
110 [Nn]* | '' ) echo "Holding off, then." >&2; exit 1 ;;
111 * ) echo "Conservatively taking that as a no." >&2; exit 1 ;;
112 esac
113 }
114
115 NonAPFSWarning() {
116
117 path="$1"
118 ftyp="$2"
119
120 echo "" >&2
121 echo "$path IS OF TYPE '$ftyp'" >&2
122 echo "" >&2
123 echo "IT NEEDS TO BE REFORMATTED AS APFS BEFORE YOU CAN PROCEED:" >&2
124 echo "" >&2
125 echo " Run Utilities -> Disk Utility" >&2
126 echo "" >&2
127 echo " Switch the View option to 'Show All Devices'." >&2
128 echo "" >&2
129 echo " Select the entry named 'PCIe SSD Media' (not the two entries indented below it)." >&2
130 echo "" >&2
131 echo " Click on 'Erase'." >&2
132 echo "" >&2
133 echo " Change the Scheme to 'GUID Partition Map' (which will expand the Format choices)." >&2
134 echo "" >&2
135 echo " Set the Format to 'APFS'." >&2
136 echo "" >&2
137 echo " Press Erase." >&2
138 echo "" >&2
139 echo "ALSO RUN:" >&2
140 echo "" >&2
141 echo " sudo trimforce enable" >&2
142 echo "" >&2
143 echo "IF NECESSARY TO ENABLE TRIM SUPPORT ON THE SOLID STATE DRIVE." >&2
144 echo "" >&2
145 echo "WOULD YOU LIKE TO PROCEED WITH ARCHIVING ON THE NON-APFS VOLUME ANYWAY? [y/N]" >&2
146 read response
147 case "$response" in
148 [Yy]* ) echo "OK, PROCEEDING." >&2 ;;
149 [Nn]* | '' ) echo "Holding off, then." >&2; exit 1 ;;
150 * ) echo "Conservatively taking that as a no." >&2; exit 1 ;;
151 esac
152 echo "" >&2
153 }
154
155 MacInstructions() {
156
157 path="$1"
158
159 echo "" >&2
160 echo " To prepare the $path disk for an EDirect archive, please disable:" >&2
161 echo "" >&2
162 echo " Antivirus scanning" >&2
163 echo " Spotlight indexing" >&2
164 echo " Time Machine backups" >&2
165 echo "" >&2
166 echo " for the '$path' directory:" >&2
167 echo "" >&2
168 echo " sudo mdutil -i off ${path}" >&2
169 echo " sudo mdutil -E ${path}" >&2
170 echo " sudo touch ${path}/.fseventsd/no_log" >&2
171 }
172
173 LinuxInstructions() {
174
175 path="$1"
176
177 echo "" >&2
178 echo " To prepare the $path disk for an EDirect archive, please disable:" >&2
179 echo "" >&2
180 echo " Antivirus scanning" >&2
181 echo "" >&2
182 echo " for the '$path' directory." >&2
183 echo "" >&2
184 echo " You may also need to run a command like:" >&2
185 echo "" >&2
186 echo " sudo mkfs -t ext4 -b 1024 -I 128 -i 4096 /dev/<device-name>" >&2
187 echo "" >&2
188 echo " to configure the file system for a large number of inodes." >&2
189 }
190
191 PrepareDrive() {
192
193 volume="$1"
194
195 if [ "$osname" = "Darwin" ]
196 then
197 root=$(df $volume | awk 'END { print $NF }')
198 sdst=$(diskutil info -plist $root | plutil -extract SolidState xml1 - -o - | sed -ne 's,<,,pg' | sed -ne 's,/>,,pg')
199 if [ "$sdst" != "true" ]
200 then
201 HardDriveWarning "$volume"
202 fi
203 ftyp=$(diskutil info -plist $root | plutil -extract FilesystemType xml1 - -o - | sed -ne 's,</*string>,,pg')
204 if [ "$ftyp" != "apfs" ]
205 then
206 NonAPFSWarning "$volume" "$ftyp"
207 fi
208 MacInstructions "$volume"
209
210 echo "" >&2
211 fi
212
213 if [ "$osname" = "Linux" ]
214 then
215 dev=$( df $volume | awk '/^\/dev\// { print $1 }' )
216 if [ -z "$dev" ]
217 then
218 echo "Unable to confirm remote file system's underlying storage type" >&2
219 echo "" >&2
220 echo "WOULD YOU LIKE TO PROCEED WITH ARCHIVING ON THIS UNKNOWN STORAGE TYPE? [y/N]" >&2
221 read response
222 case "$response" in
223 [Yy]* ) echo "OK, PROCEEDING." >&2 ;;
224 [Nn]* | '' ) echo "Holding off, then." >&2; exit 1 ;;
225 * ) echo "Conservatively taking that as a no." >&2; exit 1 ;;
226 esac
227 echo "" >&2
228 else
229 basedev=$( realpath "$dev" | sed -e 's,/dev/,,; s/\([a-z]\)[0-9]*$/\1/' )
230 isHDD=$( grep 1 /sys/block/$basedev/queue/rotational )
231 if [ -n "$isHDD" ]
232 then
233 HardDriveWarning "$volume"
234 fi
235 fi
236 LinuxInstructions "$volume"
237
238 echo "" >&2
239 fi
240
241 if [ "$osname" = "CYGWIN_NT" ]
242 then
243 echo "" >&2
244 echo " To prepare the disk for an EDirect archive, please disable:" >&2
245 echo "" >&2
246 echo " Antivirus scanning" >&2
247 echo "" >&2
248 echo " for the '$volume' directory." >&2
249 echo "" >&2
250
251 if reg query 'HKLM\System\CurrentControlSet\Control\FileSystem' \
252 /v NtfsDisable8dot3NameCreation | fgrep -q 0x0
253 then
254 echo " Also ask your administrator to set:" >&2
255 echo "" >&2
256 echo " NtfsDisable8dot3NameCreation" >&2
257 echo "" >&2
258 echo " in the Windows Registry." >&2
259 echo "" >&2
260 fi
261 fi
262 }
263
264 # note that Source is NOT included because it can reside on a rotating hard disk
265
266 for dir in Archive Data Postings Extras Index Invert Merged Scratch
267 do
268 target=$( FindLocalArchiveFolder "$dbase" "$dir" "false" )
269 # remove trailing slash
270 target=${target%/}
271 # remove trailing folder name
272 target=${target%/*}
273 # remove trailing database name
274 volume=${target%/*}
275 echo "$volume"
276 done |
277 sort -f | uniq -i |
278 while read vol
279 do
280 if [ -n "$vol" ] && [ -d "$vol" ]
281 then
282 echo "Preparing $vol" >&2
283 PrepareDrive "$vol"
284 fi
285 done
286
287 exit 0