-
Notifications
You must be signed in to change notification settings - Fork 0
/
fattag.sh
executable file
·40 lines (40 loc) · 965 Bytes
/
fattag.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
#!/bin/sh -e
# Label a vfat device, such as an SD card or USB stick.
# It uses mlabel, from mtools.
# Another way, undocumented, of which I did not know:
# mlabel -i /dev/sdf1 ::DEVICENAME
# mlabel -i /dev/sdf1 -s ::
# fattag may work slightly better, it also:
# - sets mtools_skip_check=1, in case of weird device size
# - does a sync
device="$1"
label="$2"
if [ -z "$device" -o "${device#-}" != "$device" ]; then
prog=`basename "$0"`
echo >&2 "usage: $prog device [label]"
echo >&2 "fat devices:"
blkid | sed -n '/fat/{ s/^/ /; p; }'
exit 2
fi
bak=0
trap '
status=$?
if [ $bak = 1 ]; then
mv ~/.mtoolsrc.bak.$$ ~/.mtoolsrc
else
rm -f ~/.mtoolsrc
fi
exit $status
' INT QUIT TERM PIPE EXIT
if [ -e ~/.mtoolsrc ]; then
bak=1
mv ~/.mtoolsrc ~/.mtoolsrc.bak.$$
fi
echo "mtools_skip_check=1
drive p: file=\"$device\"" >~/.mtoolsrc
if [ -z "$label" ]; then
mlabel -s p: | sed 's/^ Volume label is //; s/ *$//;'
else
mlabel p:"$label"
sync
fi