1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # $Id: label-partitions-as-necessary 1341 2007-04-24 22:27:26Z bruno $
|
---|
4 | #
|
---|
5 | ############################################
|
---|
6 |
|
---|
7 |
|
---|
8 | read_partition_line() {
|
---|
9 | local label mountpt command format
|
---|
10 |
|
---|
11 | label=`echo "$1" | awk '{print $1}' | cut -d'=' -f2`
|
---|
12 | format=`echo "$1" | awk '{print $3}'`
|
---|
13 |
|
---|
14 | if [ "`echo "$1" | grep -E 'LABEL='`" != "" ] ; then
|
---|
15 | opttun="-L"
|
---|
16 | mountpt=`awk '{print $1,$5}' $mountlist | grep " $label$" | awk '{print $1}'`
|
---|
17 | elif [ "`echo "$1" | grep -E 'UUID='`" != "" ] ; then
|
---|
18 | opttun="-U"
|
---|
19 | mountpt=`awk '{print $1,$6}' $mountlist | grep " $label$" | awk '{print $1}'`
|
---|
20 | else
|
---|
21 | # Nothing to do
|
---|
22 | return
|
---|
23 | fi
|
---|
24 |
|
---|
25 | if [ ! "$mountpt" ] ; then
|
---|
26 | LogIt "Not labeling anything as ($label) because ($mountpt) is not a mountpoint"
|
---|
27 | elif [ ! "$label" ] ; then
|
---|
28 | LogIt "Not labeling ($mountpt) as anything because ($label) is not a label"
|
---|
29 | else
|
---|
30 | if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] ; then
|
---|
31 | command="tune2fs $opttun $label $mountpt"
|
---|
32 | LogIt "Running $command"
|
---|
33 | $command
|
---|
34 | elif [ "$format" = "swap" ] ; then
|
---|
35 | if [ "$opttun" = "-U" ]; then
|
---|
36 | echo "Unable yet to identify swap with UUID"
|
---|
37 | else
|
---|
38 | command="mkswap $opttun $label $mountpt"
|
---|
39 | LogIt "Running $command"
|
---|
40 | $command
|
---|
41 | fi
|
---|
42 | else
|
---|
43 | LogIt "I am NOT going to run tune2fs: the partition is format '$format', which doesn't like tune2fs anyway"
|
---|
44 | fi
|
---|
45 | fi
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | # ---------------------------------------------
|
---|
50 |
|
---|
51 | LogIt "Identifying your drives with tune2fs"
|
---|
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
|
---|