[1] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
[901] | 3 | # $Id: label-partitions-as-necessary 2028 2008-10-02 11:24:10Z bruno $
|
---|
[1] | 4 | #
|
---|
| 5 | ############################################
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | read_partition_line() {
|
---|
[1314] | 9 | local label mountpt command format
|
---|
[1295] | 10 |
|
---|
[1314] | 11 | label=`echo "$1" | awk '{print $1}' | cut -d'=' -f2`
|
---|
| 12 | format=`echo "$1" | awk '{print $3}'`
|
---|
[1755] | 13 | mountpt=`awk '{print $1,$5}' $mountlist | grep " $label$" | awk '{print $1}'`
|
---|
[1314] | 14 |
|
---|
| 15 | if [ "`echo "$1" | grep -E 'LABEL='`" != "" ] ; then
|
---|
[2028] | 16 | [ "$format" = "reiserfs" ] && opttun="-l" || opttun="-L"
|
---|
[1314] | 17 | elif [ "`echo "$1" | grep -E 'UUID='`" != "" ] ; then
|
---|
[2028] | 18 | [ "$format" = "reiserfs" ] && opttun="-u" || opttun="-U"
|
---|
[1295] | 19 | else
|
---|
| 20 | # Nothing to do
|
---|
| 21 | return
|
---|
[1314] | 22 | fi
|
---|
[1295] | 23 |
|
---|
| 24 | if [ ! "$mountpt" ] ; then
|
---|
[1314] | 25 | LogIt "Not labeling anything as ($label) because ($mountpt) is not a mountpoint"
|
---|
[1295] | 26 | elif [ ! "$label" ] ; then
|
---|
[1314] | 27 | LogIt "Not labeling ($mountpt) as anything because ($label) is not a label"
|
---|
[1295] | 28 | else
|
---|
| 29 | if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] ; then
|
---|
| 30 | command="tune2fs $opttun $label $mountpt"
|
---|
| 31 | LogIt "Running $command"
|
---|
| 32 | $command
|
---|
[2028] | 33 | elif [ "$format" = "reiserfs" ]; then
|
---|
| 34 | command="reiserfstune $opttun $label $mountpt"
|
---|
| 35 | LogIt "Running $command"
|
---|
| 36 | $command
|
---|
[1295] | 37 | elif [ "$format" = "swap" ] ; then
|
---|
| 38 | if [ "$opttun" = "-U" ]; then
|
---|
[1780] | 39 | LogIt "Creating uuid $label on swap partition $mountpt"
|
---|
[1766] | 40 | echo -n "$label" | perl -ne 's/-//g;chomp;print pack "H*",$_' | dd conv=notrunc "of=$mountpt" obs=1 seek=1036
|
---|
[1295] | 41 | else
|
---|
| 42 | command="mkswap $opttun $label $mountpt"
|
---|
| 43 | LogIt "Running $command"
|
---|
| 44 | $command
|
---|
| 45 | fi
|
---|
| 46 | else
|
---|
[2028] | 47 | LogIt "I am NOT going to run tune2fs/reiserfstune: the partition is format '$format', which doesn't like tune2fs/reiserfstune anyway"
|
---|
[1295] | 48 | fi
|
---|
[1] | 49 | fi
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | # ---------------------------------------------
|
---|
| 54 |
|
---|
[1295] | 55 | LogIt "Identifying your drives with tune2fs"
|
---|
[1] | 56 | if [ "$#" -ne "1" ] ; then
|
---|
| 57 | LogIt "label-partitions-as-necessary /tmp/mountlist.txt < /tmp/fstab.new" 1
|
---|
| 58 | exit 1
|
---|
| 59 | fi
|
---|
| 60 | mountlist=$1
|
---|
| 61 | noof_blank_lines=0
|
---|
| 62 | read line
|
---|
| 63 | while [ "$line" != "" ] && [ "$noof_blank_lines" -le "5" ] ; do
|
---|
| 64 | if [ "$line" = "" ] ; then
|
---|
[691] | 65 | noof_blank_lines=$(($noof_blank_lines+1))
|
---|
[1] | 66 | else
|
---|
[691] | 67 | noof_blank_lines=0
|
---|
| 68 | read_partition_line "$line"
|
---|
[1] | 69 | fi
|
---|
| 70 | read line
|
---|
| 71 | done
|
---|
| 72 | LogIt "Labeling complete."
|
---|
| 73 | exit 0
|
---|