Files
new_install/operation/functions
lizhi-rocky 220e6bfe40 add Qin Bo's operating shell scripts in
rename directory 'python' to 'interface', for I think it is a better name for its included python scripts function.
2010-09-03 15:59:49 +08:00

148 lines
2.5 KiB
Plaintext

LOG_FILE="/var/log/install.log"
dev_LOG="/dev/tty6"
TARGET="/mnt"
TMP_DIR="/tmp"
# just for debug, also can use in run time
LOG="stdout"
#PKG_SOURCE_DIR="/Rocky/packages"
DATE=$(date "+%Y/%m/%d %T")
log ()
{
case "$LOG" in
true) printf "$DATE $*\n" >>"$LOG_FILE" ;;
stdout) printf "$DATE $*\n" ;;
*) : ;;
esac
}
err ()
{
log "error: $0: $*" >&2
}
warn ()
{
log "warning: $0: $*" >&2
}
info ()
{
log "info: $0: $*"
}
# erv stands for "Evaluate Return Value"
erv ()
{
ret="${?}"
if [ "$ret" -ne 0 ];then
exit $ret
fi
}
cleanup ()
{
rm -f $*
}
#
# check mountpoint whether is duplicate
#
check_duplicate_mountpoint ()
{
if [ -s "$MOUNTPOINT_CONF" ];then
dup=$(awk '{print $2}' "$MOUNTPOINT_CONF" | sort | uniq -d)
if [ -n "$dup" ];then
err "mountpoint: \""$(echo $dup|tr " " "," )"\" is duplicate !"
return 4
fi
return 0
else
err "$MOUNTPOINT_CONF file is empty or doesn't exist !"
return 8
fi
}
#
# check partition whether is duplicate
#
check_duplicate_partition ()
{
if [ -s "$MOUNTPOINT_CONF" ];then
dup=$(awk '{print $1}' "$MOUNTPOINT_CONF" | sort | uniq -d)
if [ -n "$dup" ];then
err "partition: \""$(echo $dup|tr " " "," )"\" is duplicate !"
return 5
fi
return 0
else
err "$MOUNTPOINT_CONF file is empty or doesn't exist !"
return 8
fi
}
#
# check root whether will mounted
#
check_root ()
{
if [ -s "$MOUNTPOINT_CONF" ];then
if ! grep -q "[[:space:]]/[[:space:]]" $MOUNTPOINT_CONF;then
err "\"/\" partition can not be empty!"
return 6
fi
return 0
else
err "$MOUNTPOINT_CONF file is empty or doesn't exist !"
return 8
fi
}
#
# check /boot partition whether exist, if root partition is mounted by raid device
#
check_boot ()
{
if [ -s "$MOUNTPOINT_CONF" ];then
if grep " / " $MOUNTPOINT_CONF|grep -q "md" && ! grep -q " /boot " $MOUNTPOINT_CONF; then
err "boot parition mustn't mount alone, when root partition mount at raid devices !"
return 7
fi
return 0
else
err "$MOUNTPOINT_CONF file is empty or doesn't exist !"
return 8
fi
}
# recursively umount
# arg can is a device node or mountpoint
# ex: 1.reumount /dev/hda5
# 2.reumount /mnt/
reumount ()
{
if [ $# -ne 1 ];then
err "$FUNCNAME function argument error, it must be 1 !"
return 1
fi
local arg="$1"
local mountpoint
# if arg is a device node
if [ ! -d "$arg" ];then
mountpoint=$(dirname `grep "^$arg " /proc/mounts|awk '{print $2}'`)
else
mountpoint="$arg"
fi
for mp in $(grep "$mountpoint" /proc/mounts|sort -k2 -r |awk '{print $2}');do
umount $mp 1>"$dev_LOG" 2>&1
done
}