[1] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
[901] | 3 | # $Id: label-partitions-as-necessary 3328 2014-12-17 12:38:09Z 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
|
---|
[2066] | 20 | LogIt "Nothing to do on $1"
|
---|
[1295] | 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
|
---|
[2087] | 29 | if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] || [ "$format" = "ext4" ]; then
|
---|
[3008] | 30 | if [ "$format" = "ext4" ] && [ -x "/sbin/tune4fs" ]; then
|
---|
| 31 | command="/sbin/tune4fs $opttun $label $mountpt"
|
---|
| 32 | else
|
---|
| 33 | command="tune2fs $opttun $label $mountpt"
|
---|
| 34 | fi
|
---|
[1295] | 35 | LogIt "Running $command"
|
---|
| 36 | $command
|
---|
[2028] | 37 | elif [ "$format" = "reiserfs" ]; then
|
---|
| 38 | command="reiserfstune $opttun $label $mountpt"
|
---|
| 39 | LogIt "Running $command"
|
---|
| 40 | $command
|
---|
[3328] | 41 | elif [ "$format" = "xfs" ]; then
|
---|
| 42 | command="xfs_admin $opttun $label $mountpt"
|
---|
| 43 | LogIt "Running $command"
|
---|
| 44 | $command
|
---|
[1295] | 45 | elif [ "$format" = "swap" ] ; then
|
---|
| 46 | if [ "$opttun" = "-U" ]; then
|
---|
[1780] | 47 | LogIt "Creating uuid $label on swap partition $mountpt"
|
---|
[3040] | 48 | if [ -x "/sbin/swaplabel" ]; then
|
---|
| 49 | /sbin/swaplabel $opttun $label $mountpt
|
---|
| 50 | else
|
---|
| 51 | echo -n "$label" | perl -ne 's/-//g;chomp;print pack "H*",$_' | dd conv=notrunc "of=$mountpt" obs=1 seek=1036
|
---|
| 52 | fi
|
---|
[1295] | 53 | else
|
---|
[3040] | 54 | if [ -x "/sbin/swaplabel" ]; then
|
---|
| 55 | command="/sbin/swaplabel $opttun $label $mountpt"
|
---|
| 56 | else
|
---|
| 57 | command="mkswap $opttun $label $mountpt"
|
---|
| 58 | fi
|
---|
[1295] | 59 | LogIt "Running $command"
|
---|
| 60 | $command
|
---|
| 61 | fi
|
---|
| 62 | else
|
---|
[3008] | 63 | LogIt "I am NOT going to run tune2|4fs/reiserfstune: the partition is format '$format', which doesn't like tune2|4fs/reiserfstune anyway"
|
---|
[1295] | 64 | fi
|
---|
[1] | 65 | fi
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | # ---------------------------------------------
|
---|
| 70 |
|
---|
[3008] | 71 | LogIt "Identifying your drives with FS tune tool"
|
---|
[1] | 72 | if [ "$#" -ne "1" ] ; then
|
---|
| 73 | LogIt "label-partitions-as-necessary /tmp/mountlist.txt < /tmp/fstab.new" 1
|
---|
| 74 | exit 1
|
---|
| 75 | fi
|
---|
| 76 | mountlist=$1
|
---|
| 77 | noof_blank_lines=0
|
---|
| 78 | read line
|
---|
[2172] | 79 | # We end after 50 empty lines, which hopefully means we reach the end of the file
|
---|
| 80 | while [ "$noof_blank_lines" -le "50" ] ; do
|
---|
[1] | 81 | if [ "$line" = "" ] ; then
|
---|
[691] | 82 | noof_blank_lines=$(($noof_blank_lines+1))
|
---|
[1] | 83 | else
|
---|
[691] | 84 | noof_blank_lines=0
|
---|
| 85 | read_partition_line "$line"
|
---|
[1] | 86 | fi
|
---|
| 87 | read line
|
---|
| 88 | done
|
---|
| 89 | LogIt "Labeling complete."
|
---|
| 90 | exit 0
|
---|