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