#!/bin/bash

UNAME=`uname -r`
STORE_PATH=/lib/modules/$UNAME/kernel/drivers/md/binlogdev/
if [[ ! -d $STORE_PATH ]]; then
    STORE_PATH=/lib/modules/$UNAME/extra/binlogdev/
fi
MOUNT_PATH=/opt/data
LOG_PATH=/usr/local/ucloud/binlog/
RC=/etc/init.d/wiwo

cp -f etc/init.d/binlogdev /etc/init.d/
chmod +x /etc/init.d/binlogdev

[[ -d $STORE_PATH ]] || mkdir -p $STORE_PATH
[[ -d $MOUNT_PATH ]] || mkdir -p $MOUNT_PATH
[[ -d $LOG_PATH ]] || mkdir -p $LOG_PATH
cp -f binlogdev.ko $STORE_PATH
cp -f cachedev.ko $STORE_PATH
depmod -a

sed -i "/binlogdev/d" $RC 
sed -i "/\/root\/wiwo\/bin\/wiwo_watchdog/i\/etc\/init.d\/binlogdev start\n" $RC
/etc/init.d/binlogdev force-format
