#!/bin/sh /etc/rc.common
# Copyright(c) 2011-2013 Shenzhen TP-LINK Technologies Co.Ltd.
# file     usbshare.init
# brief    
# author   Zhu Xianfeng<zhuxianfeng@tp-link.net>
# version  1.0.0
# date     27Mar14
# history  arg 1.0.0, 27Mar14, Zhu Xianfeng, Create the file. 

START=70

debug() {
    echo $1 >/dev/console 2>&1
}

gen_random_passwd() {
    openssl rand 5 -hex  -out /tmp/password
    openssl rand 5 -hex  -out /tmp/password1 
    return 0
}

boot() {    
    gen_random_passwd
    local password=`cat /tmp/password`
    local password1=`cat /tmp/password1`
    if [ "$(uci get usbshare.account.password)" == "admin" ]; then
        uci set usbshare.account.password=$password
    fi

    if [ "$(uci_get usbshare.account1.password)" == "visit" ]; then
        uci set usbshare.account1.password=$password1
    fi
    uci commit usbshare
    rm -f /tmp/password
    rm -f /tmp/password1

    debug "usbshare boot start"
    config_load usbshare
    config_get username account username
    config_get password account password
    config_get username1 account1 username
    config_get password1 account1 password

    usbuser $username $password 0
    usbuser $username1 $password1 1
    debug "usbshare boot end"
}

start() {
    return 0
}

stop() {
    return 0
}

reload() {
    return 0
}

