forked from balena-io-modules/drivelist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.hbs
265 lines (219 loc) · 6.55 KB
/
README.hbs
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!-- Make sure you edit doc/README.hbs rather than README.md because the latter is auto-generated -->
drivelist
=========
> List all connected drives in your computer, in all major operating systems.
[](https://npmjs.com/package/drivelist)
[](https://npmjs.com/package/drivelist)
[](https://npmjs.com/package/drivelist)
[](https://travis-ci.org/resin-io-modules/drivelist/branches)
[](https://ci.appveyor.com/project/resin-io/drivelist/branch/master)
[](https://david-dm.org/resin-io-modules/drivelist)
[](https://gitter.im/resin-io/etcher)
Notice that this module **does not require** admin privileges to get the drives in any supported operating system.
Supports:
- Windows.
- GNU/Linux distributions that include [util-linux](https://github.com/karelzak/util-linux) and [udev](https://wiki.archlinux.org/index.php/udev).
- Mac OS X.
The `drivelist` core consists of a set of scripts built with technologies that
are available by default on the target operating systems (like Bash, VBScript,
etc). Each of these scripts attempts to get information about the available
drives (and metadata related to them), using any methods the target platform
provides, like a combination of `diskutil`, `/proc/mounts`, etc. You can find
these scripts in the `scripts/` directory.
The scripts are then expected to print to `stdout` all the drive information
they have gathered in a predefined way, based on the [YAML][yaml] language. The
scripts are expected to output a set of blocks (separated by blank lines), each
representing a drive with a set of key/value pairs. The exact keys that we
expect are constantly changing while we keep improving this module, but you can
see what the currently expected keys are by running the platform script that
corresponds to your operating system.
This is how the raw output looks on my MacBook Pro at the time of this writing:
```sh
$ ./scripts/darwin.sh
device: /dev/disk0
displayName: /dev/disk0
description: "APPLE SSD SM0256G"
size: 251000193024
mountpoints: []
raw: /dev/rdisk0
protected: False
system: True
device: /dev/disk1
displayName: /dev/disk1
description: "Macintosh HD"
size: 249779191808
mountpoints:
- path: /
raw: /dev/rdisk1
protected: False
system: True
```
Because of the simplicity of this module's design, supporting a new operating
system simply means adding a new script to `scripts/` that gathers drive data
and outputs something similar to the above example. The challenge with this is
that we must ensure all the platform scripts print consistent output.
When the user executes `drivelist.list()`, the module checks the operating
system of the client, and executes the corresponding drive scanning script as a
child process. It then parses the [YAML][yaml] output of the script as an array
of objects, and returns that to the user.
Examples (the output will vary depending on your machine):
```js
const drivelist = require('drivelist');
drivelist.list((error, drives) => {
if (error) {
throw error;
}
console.log(drives);
});
```
***
Mac OS X:
```sh
[
{
device: '/dev/disk0',
displayName: '/dev/disk0',
description: 'GUID_partition_scheme',
size: 68719476736,
mountpoints: [
{
path: '/'
}
],
raw: '/dev/rdisk0',
protected: false,
system: true
},
{
device: '/dev/disk1',
displayName: '/dev/disk1',
description: 'Apple_HFS Macintosh HD',
size: 68719476736,
mountpoints: [],
raw: '/dev/rdisk0',
protected: false,
system: true
}
]
```
***
GNU/Linux
```sh
[
{
device: '/dev/sda',
displayName: '/dev/sda',
description: 'WDC WD10JPVX-75J',
size: 68719476736,
mountpoints: [
{
path: '/'
}
],
raw: '/dev/sda',
protected: false,
system: true
},
{
device: '/dev/sdb',
displayName: '/dev/sdb',
description: 'DataTraveler 2.0',
size: 7823458304,
mountpoints: [
{
path: '/media/UNTITLED'
}
],
raw: '/dev/sdb',
protected: true,
system: false
}
]
```
***
Windows
```sh
[
{
device: '\\\\.\\PHYSICALDRIVE0',
displayName: 'C:',
description: 'WDC WD10JPVX-75JC3T0',
size: 68719476736,
mountpoints: [
{
path: 'C:'
}
],
raw: '\\\\.\\PHYSICALDRIVE0',
protected: false,
system: true
},
{
device: '\\\\.\\PHYSICALDRIVE1',
displayName: 'D:, F:',
description: 'Generic STORAGE DEVICE USB Device',
size: 7823458304,
mountpoints: [
{
path: 'D:'
},
{
path: 'F:'
}
],
raw: '\\\\.\\PHYSICALDRIVE1',
protected: true,
system: false
},
{
device: '\\\\.\\PHYSICALDRIVE2',
displayName: '\\\\.\\PHYSICALDRIVE2',
description: 'Silicon-Power2G',
size: 2014314496,
mountpoints: [],
raw: '\\\\.\\PHYSICALDRIVE2',
protected: false,
system: false
}
]
```
Installation
------------
Install `drivelist` by running:
```sh
$ npm install --save drivelist
```
Documentation
-------------
{{#module name="drivelist"}}
{{>body~}}
{{>member-index~}}
{{>separator~}}
{{>members~}}
{{/module}}
Tests
-----
Run the test suite by doing:
```sh
$ npm test
```
Contribute
----------
We're looking forward to support more operating systems. Please raise an issue or even better, send a PR to increase support!
- Issue Tracker: [github.com/resin-io-modules/drivelist/issues](https://github.com/resin-io-modules/drivelist/issues)
- Source Code: [github.com/resin-io-modules/drivelist](https://github.com/resin-io-modules/drivelist)
Before submitting a PR, please make sure that you include tests, and that the linter runs without any warning:
```sh
$ npm run lint
```
Execute the following command after making any changes to the platform scripts:
```sh
npm run compile-scripts
```
Support
-------
If you're having any problem, please [raise an issue](https://github.com/resin-io-modules/drivelist/issues/new) on GitHub.
License
-------
The project is licensed under the Apache 2.0 license.
[yaml]: http://yaml.org