※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

標準Linuxの/usr/local/bin/内にある。

スクリプト

#!/bin/sh
# KURO-BOX/PRO shell script common routines.
#  Ver 1.00	2007/01/17 : new by Y.H.
#

DEFAULT_IP=192.168.11.150
ENETNAME=eth0

#setup global environment values.
MTD_SHARE=`grep extra /proc/mtd| sed -e "s/:.*//"`
MTD_UIMAGE=`grep uImage /proc/mtd|sed -e "s/:.*//"`
MTD_ROOTFS=`grep rootfs /proc/mtd|sed -e "s/:.*//"`
MTD_UBOOT=mtd0

MTD_SHARE_DEV=/dev/${MTD_SHARE}
MTD_UIMAGE_DEV=/dev/${MTD_UIMAGE}
MTD_ROOTFS_DEV=/dev/${MTD_ROOTFS}
MTD_RBOOT_DEV=/dev/${MTD_UBOOT}

MTD_UIMAGE_CHARDEV_MINORNUM=`echo ${MTD_UIMAGE_DEV}|sed -e "s/.*mtd//"|sed -e "s/.*mtdblock//"`
MTD_UIMAGE_CHARDEV=/dev/mtdchar${MTD_UIMAGE_CHARDEV_MINORNUM}
MTD_ROOTFS_CHARDEV_MINORNUM=`echo ${MTD_ROOTFS_DEV}|sed -e "s/.*mtd//"|sed -e "s/.*mtdblock//"`
MTD_ROOTFS_CHARDEV=/dev/mtdchar${MTD_ROOTFS_CHARDEV_MINORNUM}
MTD_SHARE_CHARDEV_MINORNUM=`echo ${MTD_SHARE_DEV}|sed -e "s/.*mtd//"|sed -e "s/.*mtdblock//"`
MTD_SHARE_CHARDEV=/dev/mtdchar${MTD_SHARE_CHARDEV_MINORNUM}

DISK1_DEV=/dev/sda
DISK2_DEV=/dev/sdb

DISK1_MPT=/mnt/disk1
DISK2_MPT=/mnt/disk2
MTD_MPT=/mnt/mtd

RAMDISK_MPT=/mnt/ram
RAMDISK_DEV=/dev/ram1
RAMDISK_SIZE=8

KERNEL_EVENT_TAIL=/proc/buffalo/kernevnt
FIRST_NAND=/etc/first_boot

MICONAPL=/usr/local/sbin/miconapl
HEXDUMP=/usr/bin/hexdump
CHANGE_TO_DEVHDD_FILE=${MTD_MPT}/ChangeMeDevHDD

SCSI_MAJOR=8
SCSI1_MINOR_BASE=0
SCSI2_MINOR_BASE=16

# $1 : device of check target
# retval
# 1 : device $1 is mounted.
# 0 : device $1 is not mounted.
IsMounted(){
	MOUNTED=`grep $1 /proc/mounts`
	if [ "${MOUNTED}" != "" ] ; then
		return 1
	else
		return 0
	fi
	return 0
}

# $1 : return value of evaluate target.
DispSF(){
	if [ "$1" -eq 0 ] ; then
		echo [Success]
	else
		echo [Failed ]
	fi
}

# $1 : Executing shellscript. (mainly used for rcS)
# $2 : Option(default is start)
exec_sh(){
	if [ ! x"$2" = x"" ] ; then
		EXEC_OPT=$2
	else
		EXEC_OPT=start
	fi
	echo ""
	echo "===== Starting $1 ====="
	/etc/init.d/$1 ${EXEC_OPT}
	DispSF $?
	echo ""
}

# $1 : Check target mount point.
CheckMPT(){
	if [ "$1" != "" ] ; then
		echo "Checking MPT($1) is exist or not."
		if [ ! -e "$1" ] ; then
			echo "$1 not exist. So create a directory, now."
			mkdir $1 -p
			chmod 777 $1
		else
			echo "$1 is exist. So no need to create a directory."
		fi
	else
		echo "Checking MPT target is something wrong."
	fi
}

create_sysfolder(){
	rm -rf ${RAMDISK_MPT}
	mkdir -m 777 -p ${RAMDISK_MPT}
	mount -t tmpfs -o mode=1777,size=${RAMDISK_SIZE}m ${RAMDISK_DEV} ${RAMDISK_MPT}
	if [ $? -ne 0 ] ; then
		echo "*** ERROR! ${RAMDISK_MPT} mount fail!!"
		reboot -f
	fi
	
	mkdir -m 777 -p /mnt/ram/tmp /mnt/ram/var/tmp /mnt/ram/var/run
	rm -rf /tmp /var

	ln -sf /mnt/ram/tmp /tmp
	ln -sf /mnt/ram/var /var
	
	mkdir -m 777 -p /var/lock
	mkdir -m 755 -p /var/empty/sshd
	
	mkdir -m 755 -p /var/lib/dhcp
	mkdir -m 755 -p /var/lib/nfs
	chown rpcuser:rpcuser /var/lib/nfs

	mkdir -m 755 -p /var/lock/subsys
	mkdir -m 755 -p /var/lock/perfmon
	mkdir -m 755 -p /var/lock/printing

	mkdir -m 755 -p /var/log/hotplug
	mkdir -m 755 -p /var/log/samba
	mkdir -m 755 -p /var/log/linkstation

	mkdir -m 755 -p /var/run/usb
	mkdir -m 755 -p /var/spool
	ln -s /etc/cron /var/spool/cron

	MODEL=`grep PRODUCTNAME /proc/buffalo/firmware|sed -e "s/PRODUCTNAME=//"`
	echo "KUROUTOSHIKOU KUROBOX Series ${MODEL}" > /etc/issue
	ln -sf issue /etc/issue.net
	rm -f /var/lock/*
}

# $1 : target device to format
Format_EXT3(){
	echo "***** Starting to format $1 *****"
	mkfs.ext3 $1 
	if [ $? -eq 0 ] ; then
		echo "Format is succeeded without error."
	else
		return 1
		exit 1
	fi
	return 0
}

# $1 : target device to format.
Format_XFS(){
	KEY=`dd if=$1 bs=1 count=3`
	if [ "${KEY}" = "XFS" ] ; then
		. /etc/melco/info
		if [ "${force_format}" = "yes" ] ; then
			echo "Disk (or partition) is looks like already formatted."
			echo "If you stop format, Press Ctrl+C in 10 seconds!!!"
			COUNTER=10
			echo -n "waiting "
			while [ ${COUNTER} -gt 0 ]
			do
				echo -n "."
				sleep 1
				COUNTER=$((${COUNTER} - 1))
			done
			echo ""
			echo "OK, go on formatting."
		else
			return 0
		fi
	fi
	echo "***** Cleaning Disk partition information *****"
	dd if=/dev/zero of=$1 bs=512 count=1
	echo "***** Starting to format $1 *****"
	mkfs.xfs $1 -f
	if [ $? -eq 0 ] ; then
		echo "Format is succeeded without error."
	else
		return 1
		exit 1
	fi
	return 0
}

# $1 : target device to check partition
# ret 0 : this is no partition disk.
# ret 1 : this is nand share type partition
# ret 2 : this is developkit type partition (maybe)
IsHavePartition(){
	if [ -x ${HEXDUMP} ] ; then
		DISK_1_PART_TAIL=`hexdump -s 446 -n 64 -e '8/1 "%02x " 2/4 "%10d " "\n"' $1 | sed -n "1p"|awk '{print $10}'`
		DISK_2_PART_TAIL=`hexdump -s 446 -n 64 -e '8/1 "%02x " 2/4 "%10d " "\n"' $1 | sed -n "2p"|awk '{print $10}'`
		DISK_3_PART_TAIL=`hexdump -s 446 -n 64 -e '8/1 "%02x " 2/4 "%10d " "\n"' $1 | sed -n "3p"|awk '{print $10}'`
		DISK_4_PART_TAIL=`hexdump -s 446 -n 64 -e '8/1 "%02x " 2/4 "%10d " "\n"' $1 | sed -n "4p"|awk '{print $10}'`
		
		if [ "${DISK_1_PART_TAIL}" -ne 0 -a "${DISK_2_PART_TAIL}" -eq 0 -a "${DISK_3_PART_TAIL}" -eq 0 -a "${DISK_4_PART_TAIL}" -eq 0 ] ; then
			return 1
		elif [ "${DISK_1_PART_TAIL}" -ne 0 -a "${DISK_2_PART_TAIL}" -ne 0 -a "${DISK_3_PART_TAIL}" -ne 0 -a "${DISK_4_PART_TAIL}" -ne 0 ] ; then
			return 2
		else
			return 0
		fi
	else
		return 0
	fi
	return 0
}

# $1 : target device to mount.
# $2 : target mountpoint of $1.
# $3 : File system of target device(default is xfs).
# $4 : Mounted device permission(default is 777).
MountShare(){
	# ret 0 : this is no partition disk.
	# ret 1 : this is nand share type partition
	# ret 2 : this is developkit type partition (maybe)

	if [ "$1" = "/dev/sda" -o "$1" = "/dev/sdb" ] ; then
		IsHavePartition $1
		RET=$?
		[ "${RET}" -eq 1 ] && TARGET_DEV=${1}1
		[ "${RET}" -eq 2 ] && TARGET_DEV=${1}4
		[ "${RET}" -eq 0 ] && TARGET_DEV=${1}
	else
		TARGET_DEV=$1
	fi

	IsMounted ${TARGET_DEV}
	if [ $? = 1 ] ; then
		echo "${TARGET_DEV} is already mounted."
		return 1
	fi
	
	if [ "$3" = "" ] ; then
		FS=xfs
	else
		FS=$3
	fi

	if [ "$4" = "" ] ; then
		PERMISSION=777
	else
		PERMISSION=$4
	fi

	echo "Mounting ${TARGET_DEV} on $2 as a ${FS} file system."
	mount -t ${FS} ${TARGET_DEV} $2
	case $? in
	0)
		chmod ${PERMISSION} $2
		echo "Success."
		;;
	*)
		echo "Failed."
		return 1
		;;
	esac
	echo ""
	
	return 0
}

MiconIntEnable(){
	cat /proc/buffalo/miconint_en
}

CreateDevFile(){
	DISK_DEV=$1
	case ${DISK_DEV} in
	${DISK1_DEV})
		SCSI_MINOR_BASE=${SCSI1_MINOR_BASE}
		[ ! -e ${DISK_DEV} ] && mknod ${DISK_DEV} b ${SCSI_MAJOR} ${SCSI_MINOR_BASE}
		;;		
	${DISK2_DEV})
		SCSI_MINOR_BASE=${SCSI2_MINOR_BASE}
		[ ! -e ${DISK_DEV} ] && mknod ${DISK_DEV} b ${SCSI_MAJOR} ${SCSI_MINOR_BASE}
		;;
	*)
		return -1
	esac

	SCSI_MINOR=$((${SCSI_MINOR_BASE} + 1))
	DEV_NO=1

	while [ ${DEV_NO} -lt 8 ]
	do
		[ ! -e ${DISK_DEV}${DEV_NO} ] && mknod ${DISK_DEV}${DEV_NO} b ${SCSI_MAJOR} ${SCSI_MINOR}
		DEV_NO=$((${DEV_NO} + 1))
		SCSI_MINOR=$((${SCSI_MINOR} + 1))
	done


}


lock_file(){

case $1 in
check)
	[ -f "${LOCK}" ] && echo "${THIS_SCRIPT} : already runnign"
	return 1
	;;
create)
	echo "${THIS_SCRIPT}" $2 > ${LOCK}
	;;
delete)
	rm -f ${LOCK}
	;;
delete_log)
	rm -f ${LOCK}.log
	;;
*)
	;;
esac

}