1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # 09/05
|
---|
4 | # - replaced 'grep -w' with 'grep " $.. "'
|
---|
5 | #
|
---|
6 | # 06/11
|
---|
7 | # - added support for 5th column, for labels
|
---|
8 | #
|
---|
9 | # 02/02/2003
|
---|
10 | # - something
|
---|
11 | #
|
---|
12 | # mid-2001
|
---|
13 | # - first written
|
---|
14 | ############################################
|
---|
15 |
|
---|
16 |
|
---|
17 | #LogIt() {
|
---|
18 | # echo "$1" >> /dev/stderr
|
---|
19 | #}
|
---|
20 |
|
---|
21 |
|
---|
22 | read_partition_line() {
|
---|
23 | local tmp label mountpt mountline command format
|
---|
24 | if [ "`echo "$1" | grep "LABEL="`" != "" ] ; then
|
---|
25 | tmp=`echo "$1" | tr -s ' ' '\t' | cut -f1`
|
---|
26 | label=`echo "$tmp" | cut -d'=' -f2`
|
---|
27 | format=`echo "$1" | tr -s ' ' '\t' | cut -f3`
|
---|
28 | mountline=`mount | grep " $label "`
|
---|
29 | # mountpt=`echo "$mountline" | cut -d' ' -f1`
|
---|
30 | ! mountpt=`cat $mountlist | grep " $label " | cut -d' ' -f1`
|
---|
31 | if [ ! "$mountpt" ] ; then
|
---|
32 | LogIt "Not labeling anything as $label because $mountpt is not a mountpoint"
|
---|
33 | elif [ ! "$label" ] ; then
|
---|
34 | LogIt "Not labeling $mountpt as anything because $label is not a label"
|
---|
35 | else
|
---|
36 | command="e2label $mountpt $label"
|
---|
37 | if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] ; then
|
---|
38 | LogIt "Running '$command'"
|
---|
39 | $command
|
---|
40 | else
|
---|
41 | LogIt "I am NOT going to run '$command': the partition is format '$format', which doesn't like e2label anyway"
|
---|
42 | fi
|
---|
43 | fi
|
---|
44 | fi
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | # ---------------------------------------------
|
---|
50 |
|
---|
51 | LogIt "Labeling your drives with e2label"
|
---|
52 | if [ "$#" -ne "1" ] ; then
|
---|
53 | LogIt "label-partitions-as-necessary /tmp/mountlist.txt < /tmp/fstab.new" 1
|
---|
54 | exit 1
|
---|
55 | fi
|
---|
56 | mountlist=$1
|
---|
57 | noof_blank_lines=0
|
---|
58 | read line
|
---|
59 | while [ "$line" != "" ] && [ "$noof_blank_lines" -le "5" ] ; do
|
---|
60 | if [ "$line" = "" ] ; then
|
---|
61 | noof_blank_lines=$(($noof_blank_lines+1))
|
---|
62 | else
|
---|
63 | noof_blank_lines=0
|
---|
64 | read_partition_line "$line"
|
---|
65 | fi
|
---|
66 | read line
|
---|
67 | done
|
---|
68 | LogIt "Labeling complete."
|
---|
69 | exit 0
|
---|