1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # $Id: label-partitions-as-necessary 1297 2007-04-11 23:56:35Z bruno $
|
---|
4 | #
|
---|
5 | ############################################
|
---|
6 |
|
---|
7 |
|
---|
8 | read_partition_line() {
|
---|
9 | local tmp label mountpt command format
|
---|
10 |
|
---|
11 | if [ "`echo "$1" | grep -E 'LABEL='`" != "" ] ; then
|
---|
12 | opttun="-L"
|
---|
13 | elif [ "`echo "$1" | grep -E 'UUID='`" != "" ] ; then
|
---|
14 | opttun="-U"
|
---|
15 | else
|
---|
16 | # Nothing to do
|
---|
17 | return
|
---|
18 | fi
|
---|
19 |
|
---|
20 | tmp=`echo "$1" | tr -s ' ' '\t' | cut -f1`
|
---|
21 | label=`echo "$tmp" | cut -d'=' -f2`
|
---|
22 | format=`echo "$1" | tr -s ' ' '\t' | cut -f3`
|
---|
23 | mountpt=`grep -w " $label" $mountlist | cut -d' ' -f1`
|
---|
24 | if [ ! "$mountpt" ] ; then
|
---|
25 | LogIt "Not labeling anything as $label because $mountpt is not a mountpoint"
|
---|
26 | elif [ ! "$label" ] ; then
|
---|
27 | LogIt "Not labeling $mountpt as anything because $label is not a label"
|
---|
28 | else
|
---|
29 | if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] ; then
|
---|
30 | command="tune2fs $opttun $label $mountpt"
|
---|
31 | LogIt "Running $command"
|
---|
32 | $command
|
---|
33 | elif [ "$format" = "swap" ] ; then
|
---|
34 | if [ "$opttun" = "-U" ]; then
|
---|
35 | echo "Unable yet to identify swap with UUID"
|
---|
36 | else
|
---|
37 | command="mkswap $opttun $label $mountpt"
|
---|
38 | LogIt "Running $command"
|
---|
39 | $command
|
---|
40 | fi
|
---|
41 | else
|
---|
42 | LogIt "I am NOT going to run tune2fs: the partition is format '$format', which doesn't like tune2fs anyway"
|
---|
43 | fi
|
---|
44 | fi
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | # ---------------------------------------------
|
---|
49 |
|
---|
50 | LogIt "Identifying your drives with tune2fs"
|
---|
51 | if [ "$#" -ne "1" ] ; then
|
---|
52 | LogIt "label-partitions-as-necessary /tmp/mountlist.txt < /tmp/fstab.new" 1
|
---|
53 | exit 1
|
---|
54 | fi
|
---|
55 | mountlist=$1
|
---|
56 | noof_blank_lines=0
|
---|
57 | read line
|
---|
58 | while [ "$line" != "" ] && [ "$noof_blank_lines" -le "5" ] ; do
|
---|
59 | if [ "$line" = "" ] ; then
|
---|
60 | noof_blank_lines=$(($noof_blank_lines+1))
|
---|
61 | else
|
---|
62 | noof_blank_lines=0
|
---|
63 | read_partition_line "$line"
|
---|
64 | fi
|
---|
65 | read line
|
---|
66 | done
|
---|
67 | LogIt "Labeling complete."
|
---|
68 | exit 0
|
---|