1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # $Id: label-partitions-as-necessary 3040 2012-10-06 03:25:43Z 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 | mountpt=`awk '{print $1,$5}' $mountlist | grep " $label$" | awk '{print $1}'`
|
---|
14 |
|
---|
15 | if [ "`echo "$1" | grep -E 'LABEL='`" != "" ] ; then
|
---|
16 | [ "$format" = "reiserfs" ] && opttun="-l" || opttun="-L"
|
---|
17 | elif [ "`echo "$1" | grep -E 'UUID='`" != "" ] ; then
|
---|
18 | [ "$format" = "reiserfs" ] && opttun="-u" || opttun="-U"
|
---|
19 | else
|
---|
20 | LogIt "Nothing to do on $1"
|
---|
21 | return
|
---|
22 | fi
|
---|
23 |
|
---|
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" ] || [ "$format" = "ext4" ]; then
|
---|
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
|
---|
35 | LogIt "Running $command"
|
---|
36 | $command
|
---|
37 | elif [ "$format" = "reiserfs" ]; then
|
---|
38 | command="reiserfstune $opttun $label $mountpt"
|
---|
39 | LogIt "Running $command"
|
---|
40 | $command
|
---|
41 | elif [ "$format" = "swap" ] ; then
|
---|
42 | if [ "$opttun" = "-U" ]; then
|
---|
43 | LogIt "Creating uuid $label on swap partition $mountpt"
|
---|
44 | if [ -x "/sbin/swaplabel" ]; then
|
---|
45 | /sbin/swaplabel $opttun $label $mountpt
|
---|
46 | else
|
---|
47 | echo -n "$label" | perl -ne 's/-//g;chomp;print pack "H*",$_' | dd conv=notrunc "of=$mountpt" obs=1 seek=1036
|
---|
48 | fi
|
---|
49 | else
|
---|
50 | if [ -x "/sbin/swaplabel" ]; then
|
---|
51 | command="/sbin/swaplabel $opttun $label $mountpt"
|
---|
52 | else
|
---|
53 | command="mkswap $opttun $label $mountpt"
|
---|
54 | fi
|
---|
55 | LogIt "Running $command"
|
---|
56 | $command
|
---|
57 | fi
|
---|
58 | else
|
---|
59 | LogIt "I am NOT going to run tune2|4fs/reiserfstune: the partition is format '$format', which doesn't like tune2|4fs/reiserfstune anyway"
|
---|
60 | fi
|
---|
61 | fi
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | # ---------------------------------------------
|
---|
66 |
|
---|
67 | LogIt "Identifying your drives with FS tune tool"
|
---|
68 | if [ "$#" -ne "1" ] ; then
|
---|
69 | LogIt "label-partitions-as-necessary /tmp/mountlist.txt < /tmp/fstab.new" 1
|
---|
70 | exit 1
|
---|
71 | fi
|
---|
72 | mountlist=$1
|
---|
73 | noof_blank_lines=0
|
---|
74 | read line
|
---|
75 | # We end after 50 empty lines, which hopefully means we reach the end of the file
|
---|
76 | while [ "$noof_blank_lines" -le "50" ] ; do
|
---|
77 | if [ "$line" = "" ] ; then
|
---|
78 | noof_blank_lines=$(($noof_blank_lines+1))
|
---|
79 | else
|
---|
80 | noof_blank_lines=0
|
---|
81 | read_partition_line "$line"
|
---|
82 | fi
|
---|
83 | read line
|
---|
84 | done
|
---|
85 | LogIt "Labeling complete."
|
---|
86 | exit 0
|
---|