]> git.sur5r.net Git - bacula/rescue/blobdiff - rescue/linux/usb/getdiskinfo
Update
[bacula/rescue] / rescue / linux / usb / getdiskinfo
index 4e90cd17ab40b63a9585cf53ec8e45e3118f60d6..75ec6556adfe313925e6816c077df19e387fcedb 100755 (executable)
@@ -7,9 +7,10 @@
 #      This source distributed under the GPL
 #
 export LANG=C
-di=diskinfo
 cwd=`pwd`
 host=`uname -s`
+di=${cwd}/diskinfo
+scr=${cwd}/scripts
 
 case $host in
  Linux)
@@ -35,7 +36,7 @@ fi
 #
 #  First collect information
 #
-rm -rf format.* partition.* $di create-*
+rm -rf format.* partition.* $di create-* $scr
 echo "Begin collecting system info ..."
 mkdir -p $di
 cd $di
@@ -80,9 +81,10 @@ echo "Begin creating scripts ..."
 #
 # First create partitioning script(s)
 #
+mkdir -p $scr
 for i in `cat disks.bsi`; do
   j=`echo $i | cut -c6-`
-  cat >$cwd/partition.$j <<END_OF_DATA
+  cat >$scr/partition.$j <<END_OF_DATA
 
 #!/bin/sh
 #
@@ -116,7 +118,7 @@ echo ""
 END_OF_DATA
 
 
-chmod 755 $cwd/partition.$j
+chmod 755 $scr/partition.$j
 done
 echo "Done making partitioning scripts"
 
@@ -124,7 +126,7 @@ if [ $dolvm -eq 1 ] ; then
 # 
 # LVM phase 1: create the Physical Volumess
 #
-    cat > $cwd/create-pv <<EOF
+    cat > $scr/create-pv <<EOF
 #!/bin/sh
 #
 # Create PVs for LVM -- created by getdiskinfo
@@ -135,10 +137,10 @@ echo "IT WILL DESTROY ALL DATA ON THESE PARTITIONS!!!!"
 echo ""
 EOF
     for pv in `cat lvm-pv.bsi | awk '{print $1}'`; do
-        echo "echo \"    $pv\"" >> $cwd/create-pv
+        echo "echo \"    $pv\"" >> $scr/create-pv
     done
 
-    cat >> $cwd/create-pv <<EOF
+    cat >> $scr/create-pv <<EOF
 echo ""
 echo -n "Are you sure you want to continue? yes/no: "
 read a
@@ -147,17 +149,17 @@ if [ x\$a != xyes ] ; then
 fi 
 EOF
     for pv in `cat lvm-pv.bsi | awk '{print $1}'`; do
-       echo "echo \"Creating PV on $pv\"" >> $cwd/create-pv
-       echo "lvm pvcreate -ff -y -v $pv" >> $cwd/create-pv
+        echo "echo \"Creating PV on $pv\"" >> $scr/create-pv
+        echo "lvm pvcreate -ff -y -v $pv" >> $scr/create-pv
     done
-    echo "echo \"Done.\"" >> $cwd/create-pv
-    echo "echo \"If there were no errors, run create-vg to create the volume groups.\"" >> $cwd/create-pv
-    chmod +x $cwd/create-pv
+    echo "echo \"Done.\"" >> $scr/create-pv
+    echo "echo \"If there were no errors, run create-vg to create the volume groups.\"" >> $scr/create-pv
+    chmod +x $scr/create-pv
 
 #
 # LVM phase 2: create Volume Groups
 #
-    cat > $cwd/create-vg <<EOF
+    cat > $scr/create-vg <<EOF
 #!/bin/sh
 echo ""
 echo "This script will create all volume groups listed in diskinfo/lvm-vg.bsi"
@@ -170,16 +172,16 @@ if [ x\$a != xyes ] ; then
 fi
 EOF
     cat lvm-vg.bsi | awk '{print $1, $2}' | while read vg pesize ; do
-       echo "echo \"Creating VG $vg PE extent size $pesize kbytes"\" >> $cwd/create-vg
-       pelist=""
-       for pv in `cat lvm-pv.bsi | awk "\\\$2 == \"$vg\" { print \\\$1 }"` ; do
-           pelist="$pelist $pv"
-       done
-       echo "lvm vgcreate $vg -v -s ${pesize}k $pelist" >> $cwd/create-vg
+        echo "echo \"Creating VG $vg PE extent size $pesize kbytes"\" >> $scr/create-vg
+        pelist=""
+        for pv in `cat lvm-pv.bsi | awk "\\\$2 == \"$vg\" { print \\\$1 }"` ; do
+            pelist="$pelist $pv"
+        done
+        echo "lvm vgcreate $vg -v -s ${pesize}k $pelist" >> $scr/create-vg
     done
-    echo "echo \"Done.\"" >> $cwd/create-vg
-    echo "echo \"If there were no errors, run create-lv to create the logical volumes.\"" >> $cwd/create-vg
-    chmod +x $cwd/create-vg
+    echo "echo \"Done.\"" >> $scr/create-vg
+    echo "echo \"If there were no errors, run create-lv to create the logical volumes.\"" >> $scr/create-vg
+    chmod +x $scr/create-vg
 
 
 #
@@ -192,7 +194,7 @@ EOF
 # Using the extent count should allow this script to continue to work
 # even after the bug is fixed.
 
-    cat > $cwd/create-lv <<EOF
+    cat > $scr/create-lv <<EOF
 #!/bin/sh
 echo ""
 echo "This script will create all logical volumes listed in diskinfo/lvm-lv.bsi"
@@ -205,11 +207,11 @@ if [ x\$a != xyes ] ; then
 fi
 EOF
     cat lvm-lv.bsi | awk '{print $1, $2, $3}' | while read lv vg lvsize ; do
-       # lv=`echo $lv | sed -e 's/.*\///'`
-       echo "echo \"Creating LV $lv\"" >> $cwd/create-lv
-       echo "lvm lvcreate -L ${lvsize}k $vg -n $lv" >> $cwd/create-lv
+        # lv=`echo $lv | sed -e 's/.*\///'`
+        echo "echo \"Creating LV $lv\"" >> $scr/create-lv
+        echo "lvm lvcreate -L ${lvsize}k $vg -n $lv" >> $scr/create-lv
     done
-    chmod +x $cwd/create-lv
+    chmod +x $scr/create-lv
 fi
 
 #
@@ -218,7 +220,7 @@ fi
 echo "Begin making formatting script(s) ..."
 for i in `cat disks.bsi`; do
   j=`echo $i | cut -c6-`
-  cat >$cwd/format.$j <<END_OF_DATA
+  cat >$scr/format.$j <<END_OF_DATA
 #!/bin/sh
 #
 #  Format all partitions on disk $i -- created by getdiskinfo
@@ -246,47 +248,47 @@ END_OF_DATA
    # Find swap partitions in output from sfdisk
    k=`grep "^$i.*82  Linux swap" sfdisk.$j.bsi | cut -d ' ' -f 1`
    for disk in $k; do
-      echo "echo \"Formatting $disk -- swap partition\"" >>$cwd/format.$j
-      echo "mkswap $check $disk" >>$cwd/format.$j
-      echo "echo \"\"" >>$cwd/format.$j
+      echo "echo \"Formatting $disk -- swap partition\"" >>$scr/format.$j
+      echo "mkswap $check $disk" >>$scr/format.$j
+      echo "echo \"\"" >>$scr/format.$j
    done
    # Find ext2 partitions in mount output
    k=`grep "^$i" mount.ext2.bsi | cut -d ' ' -f 1`
    for disk in $k; do
-      echo "echo \"Formating $disk -- ext2 partition\"" >>$cwd/format.$j
+      echo "echo \"Formating $disk -- ext2 partition\"" >>$scr/format.$j
       label=`grep "^$disk" mount.ext2.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
       if [ x$label = x ] ; then
-         echo "mke2fs -v \$check $disk" >>$cwd/format.$j
+         echo "mke2fs -v \$check $disk" >>$scr/format.$j
       else
-         echo "mke2fs -v \$check -L $label $disk" >>$cwd/format.$j
+         echo "mke2fs -v \$check -L $label $disk" >>$scr/format.$j
       fi
-      echo "echo \"\"" >>$cwd/format.$j
+      echo "echo \"\"" >>$scr/format.$j
    done
    # Find ext3 partitions in mount output
    k=`grep "^$i" mount.ext3.bsi | cut -d ' ' -f 1`
    for disk in $k; do
-      echo "echo \"Formating $disk -- ext3 partition\"" >>$cwd/format.$j
+      echo "echo \"Formating $disk -- ext3 partition\"" >>$scr/format.$j
       label=`grep "^$disk" mount.ext3.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
       if [ x$label = x ] ; then
-         echo "mke2fs -v -j \$check $disk" >>$cwd/format.$j
+         echo "mke2fs -v -j \$check $disk" >>$scr/format.$j
       else
-         echo "mke2fs -v -j \$check -L $label $disk" >>$cwd/format.$j
+         echo "mke2fs -v -j \$check -L $label $disk" >>$scr/format.$j
       fi
-      echo "echo \"\"" >>$cwd/format.$j
+      echo "echo \"\"" >>$scr/format.$j
    done
    # Find reiserfs partitions in mount output
    k=`grep "^$i" mount.rei.bsi | cut -d ' ' -f 1`
    for disk in $k; do
-      echo "echo \"Formating $disk -- reiser partition\"" >>$cwd/format.$j
+      echo "echo \"Formating $disk -- reiser partition\"" >>$scr/format.$j
       label=`grep "^$disk" mount.rei.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
       if [ x$label = x ] ; then
-         echo "mkereiserfs -V \$check $disk" >>$cwd/format.$j
+         echo "mkereiserfs -V \$check $disk" >>$scr/format.$j
       else
-         echo "mkereiserfs -V \$check -L $label $disk" >>$cwd/format.$j
+         echo "mkereiserfs -V \$check -L $label $disk" >>$scr/format.$j
       fi
-      echo "echo \"\"" >>$cwd/format.$j
+      echo "echo \"\"" >>$scr/format.$j
    done
-   chmod 755 $cwd/format.$j
+   chmod 755 $scr/format.$j
 done
 
 #
@@ -298,7 +300,7 @@ done
 if [ $dolvm -eq 1 ] ; then
     echo "Begin making LVM formatting script(s) ..."
     for i in `cat lvm-vg.bsi | awk '{print $1}'`; do
-       cat >$cwd/format.$i <<END_OF_DATA
+        cat >$scr/format.$i <<END_OF_DATA
 #!/bin/sh
 #
 #  Format all partitions on VG $i -- created by getdiskinfo
@@ -327,51 +329,51 @@ END_OF_DATA
    mapper="/dev/mapper/${i}"
    k=`grep "^$mapper" swaps.bsi | awk '{print $1}'`
    for disk in $k; do
-      echo "echo \"Formatting $disk -- swap partition\"" >>$cwd/format.$i
-      echo "mkswap $check $disk" >>$cwd/format.$i
-      echo "echo \"\"" >>$cwd/format.$i
+      echo "echo \"Formatting $disk -- swap partition\"" >>$scr/format.$i
+      echo "mkswap $check $disk" >>$scr/format.$i
+      echo "echo \"\"" >>$scr/format.$i
    done
    # Find ext2 partitions in mount output
    k=`grep "^$mapper" mount.ext2.bsi | cut -d ' ' -f 1`
    for disk in $k; do
-      echo "echo \"Formating $disk -- ext2 partition\"" >>$cwd/format.$i
+      echo "echo \"Formating $disk -- ext2 partition\"" >>$scr/format.$i
       label=`grep "^$disk on" mount.ext2.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
       if [ x$label = x ] ; then
-         echo "mke2fs -v \$check $disk" >>$cwd/format.$i
+         echo "mke2fs -v \$check $disk" >>$scr/format.$i
       else
-         echo "mke2fs -v \$check -L $label $disk" >>$cwd/format.$i
+         echo "mke2fs -v \$check -L $label $disk" >>$scr/format.$i
       fi
-      echo "echo \"\"" >>$cwd/format.$i
+      echo "echo \"\"" >>$scr/format.$i
    done
    # Find ext3 partitions in mount output
    k=`grep "^$mapper" mount.ext3.bsi | cut -d ' ' -f 1`
    for disk in $k; do
-      echo "echo \"Formating $disk -- ext3 partition\"" >>$cwd/format.$i
+      echo "echo \"Formating $disk -- ext3 partition\"" >>$scr/format.$i
       label=`grep "^$disk on" mount.ext3.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
       if [ x$label = x ] ; then
-         echo "mke2fs -v -j \$check $disk" >>$cwd/format.$i
+         echo "mke2fs -v -j \$check $disk" >>$scr/format.$i
       else
-         echo "mke2fs -v -j \$check -L $label $disk" >>$cwd/format.$i
+         echo "mke2fs -v -j \$check -L $label $disk" >>$scr/format.$i
       fi
-      echo "echo \"\"" >>$cwd/format.$i
+      echo "echo \"\"" >>$scr/format.$i
    done
    # Find reiserfs partitions in mount output
    k=`grep "^$mapper" mount.rei.bsi | cut -d ' ' -f 1`
    for disk in $k; do
-      echo "echo \"Formating $disk -- reiser partition\"" >>$cwd/format.$i
+      echo "echo \"Formating $disk -- reiser partition\"" >>$scr/format.$i
       label=`grep "^$disk on" mount.rei.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
       if [ x$label = x ] ; then
-         echo "mkereiserfs -V \$check $disk" >>$cwd/format.$i
+         echo "mkereiserfs -V \$check $disk" >>$scr/format.$i
       else
-         echo "mkereiserfs -V \$check -L $label $disk" >>$cwd/format.$i
+         echo "mkereiserfs -V \$check -L $label $disk" >>$scr/format.$i
       fi
-      echo "echo \"\"" >>$cwd/format.$i
+      echo "echo \"\"" >>$scr/format.$i
    done
-   chmod 755 $cwd/format.$i
+   chmod 755 $scr/format.$i
    done
 fi
 
-cd $cwd
+cd $scr
 
 #
 # Create network start script
@@ -411,7 +413,7 @@ END_OF_DATA
 
 chmod 755 start_network
 
-cat >mount_drives <<END_OF_DATA
+cat >$scr/mount_drives <<END_OF_DATA
 #!/bin/sh
 #
 #  Mount disk drives  -- created by getdiskinfo
@@ -442,22 +444,22 @@ sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/mnt\/disk\2/p' $di/mount.rei.bsi >>$
 sort -k 2 <${TMP1} >${TMP2}
 # output mkdir followed by its mount
 sed -n 's/\(^.*\)\ \(.*$\)/mkdir -p \2\
-mount \1 \2/p' ${TMP2} >>mount_drives
+mount \1 \2/p' ${TMP2} >>$scr/mount_drives
 
 # Now build unmount_drives
-cat >umount_drives <<END_OF_DATA
+cat >$scr/umount_drives <<END_OF_DATA
 #!/bin/sh
 #
 #  Unmount disk drives  -- created by getdiskinfo
 #
 END_OF_DATA
 sort -r -k 2 <${TMP1} >${TMP2}
-sed -n 's/\(^.*\)\ \(.*$\)/umount \2/p' ${TMP2} >>umount_drives
-echo "umount /mnt/cdrom 2>/dev/null >/dev/null" >>umount_drives
-echo "sync" >>umount_drives
-echo "sync" >>umount_drives
+sed -n 's/\(^.*\)\ \(.*$\)/umount \2/p' ${TMP2} >>$scr/umount_drives
+echo "umount /mnt/cdrom 2>/dev/null >/dev/null" >>$scr/umount_drives
+echo "sync" >>$scr/umount_drives
+echo "sync" >>$scr/umount_drives
 
 rm -f ${TMP1} ${TMP2}
 
-chmod 755 mount_drives umount_drives
+chmod 755 $scr/mount_drives $scr/umount_drives
 echo "Done building scripts."