add a function in mkTmpfstab.sh for check arguments

This commit is contained in:
zorro
2010-09-21 17:16:04 +08:00
parent 8ee0172cdd
commit 8432cbfbce

View File

@@ -111,7 +111,7 @@ mdfyTmpFstab(){
local UUIDFROMFSTAB=$(awk '/^[ \t]*[^#]/ { if ($1 ~ "^[UUID]") { print $1}}' $1)
for i in $UUIDFROMFSTAB
do
blkid -t$i >/tmp/.blkid.tmp
blkid -t$i >/tmp/.blkid.tmp
local NAMEFROMUUID=`cut -f 1 -d : /tmp/.blkid.tmp`
if [ ! "${NAMEFROMUUID}" ];then
echo "error UUID, can not find devices by blkid" >>$LOGDIR$LOGFILE
@@ -143,7 +143,24 @@ mdfyTmpFstab(){
sed -i s@$i@$LASTNAME@g $1
LASTNAME=''
done
rm /tmp/.blkid.tmp
rm /tmp/.blkid.tmp
}
###########################################################################
# Function Name: checkArgument()
# Input: $PATHFROM $PATHTO
# Return: nothing
# Description: check the arguments
###########################################################################
checkArgument(){
if [ ! -f $1 ];then
echo "Can not find pathfrom $1" >>$LOGDIR$LOGFILE
exit 1
fi
if [ ! $2 ];then
echo "pathto argument is empty!!" >>$LOGDIR$LOGFILE
exit 1
fi
}
###########################################################################
@@ -153,7 +170,7 @@ mdfyTmpFstab(){
# Description: print the helped message
###########################################################################
usage(){
echo "Usage: mkTmpfstab.sh [-h|--help] <-f|--from oldfstab> <-t|--to tmpfstab>"
echo "Usage: mkraid [-h|--help] <-f|--from oldfstab> <-t|--to tmpfstab>"
echo "This shell is just used to modify a false of mkinitrd, when used UUID to specify a raid device in fstab the mkinitrd always analysis false, not only one devices would be found according to the UUID. So I write this shell for makeinitrd. The shell will take the old fstab(usually is /etc/fstab) to a temp place, then change the UUID to right device name in the temp fstab. The makeinitrd shell should use the temp fstab file to make the initrd and stay the old fstab, after make initrd remove the temp fstab."
echo""
echo "ARGUMENT:
@@ -197,6 +214,7 @@ NOWDATE=`date`
echo $NOWDATE >>$LOGDIR$LOGFILE
setArgument $@
checkArgument $PATHFROM $PATHTO
cpTmpfstab $PATHFROM $PATHTO
mdfyTmpFstab $PATHTO
echo "make temp fstab all right" >>$LOGDIR$LOGFILE