File updatefstab.sh of Package Vj_Latesttar

#!/bin/bash

unset fstab inplace;

# backup_fstab_file()

backup_fstab_file() {
        fstabfile=/etc/fstab;
        fstabfilebackup="";
        i=0;

        fstabfilebackup=/etc/fstab."backup".${i};
	
        while [ -e $fstabfilebackup ]
        do
                
		i=$((i + 1));
        	fstabfilebackup=/etc/fstab."backup".${i};
        done

        cp ${fstabfile} ${fstabfilebackup};
}
  

if [ "x$1" != "x" ]; then
   fstab=$1
else
   echo "You must enter the path to the fstab."
   exit
fi
if [ "x$2" != "x" ]; then
   inplace="-i"
fi
if [ ! -r $fstab ] || [ ! -f $fstab ]; then
   echo "'$fstab' is not readable or no regular file."
   exit
fi

devices="$(cat $fstab 2>/dev/null | awk '{print $1}' 2>/dev/null | grep /dev/ 2>/dev/null)"
sedcommand="sed"

backup_fstab_file;

for device in $devices; do
   uuid=""
   uuid="$(blkid $device 2>/dev/null | grep -oe 'UUID="[0123456789ABCDEFabcdef-]\+"' 2>/dev/null)"
   [ "x$uuid" = "x" ] && continue
   sedcommand+=" -e s,^$device,$uuid,"
done

if [ "$sedcommand" = "sed" ]; then
   echo "No lines to substitute found. Probably everything which can \
be UUID is already UUID."
   exit
fi
eval $sedcommand $inplace $fstab 2>/dev/null


openSUSE Build Service is sponsored by