1

Add original scripts

This commit is contained in:
eleksir
2016-09-04 22:20:40 +03:00
commit 8e3af042d2
128 changed files with 19003 additions and 0 deletions

578
ImRd.sh Executable file
View File

@@ -0,0 +1,578 @@
#!/bin/sh
MNT_POINT="/mnt/ext"
ROOT_PART="/mnt/HDA_ROOT"
UPDATEPKG_DIR="${ROOT_PART}/update_pkg"
PHP_INI="/etc/config/php.ini"
APP_RUNTIME_CONF="/var/.application.conf"
QPKG_CONF="/etc/config/qpkg.conf"
DEF_QPKG_CONF="/etc/default_config/qpkg.conf"
MultimediaShare=`/sbin/getcfg SHARE_DEF defMultimedia -d Qmultimedia -f /etc/config/def_share.info`
MSV2_SUPPORT=`/sbin/getcfg "QPHOTO" "MSV2_SUPPORT" -d FALSE -f /etc/default_config/uLinux.conf`
ThumbnailGenerator="/mnt/ext/opt/MSV2/api/background_conversion.php"
RUNTIME_ALARM_INFO="/tmp/.alarm_info.conf"
BACKUP_ALARM_INFO="/share/${MultimediaShare}/.@__thumb/.alarm_info.conf"
UPNP_ROOT="/mnt/QUPNP"
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
QPHOTO_Hide=`/sbin/getcfg DISABLE qmultimedia -d 0 -f $APP_RUNTIME_CONF`
MS_Hide=`/sbin/getcfg DISABLE musics -d 0 -f $APP_RUNTIME_CONF`
PS_Hide=`/sbin/getcfg DISABLE photos -d 0 -f $APP_RUNTIME_CONF`
MMSHARE_PATH=`/sbin/getcfg ${MultimediaShare} path -d /ERROR -f /etc/config/smb.conf`
DEMO_SITE_SUPPORT=`/sbin/getcfg DEMO_SITE_SUPPORT Enable -u -d FALSE -f $APP_RUNTIME_CONF`
MEDIALIB_DBCMD="/usr/local/medialibrary/bin/mymediadbcmd"
MEDIALIB_CONF="/etc/config/medialibrary.conf"
PHOTO_SCAND=photo_scand
. /etc/init.d/functions
make_qpkg_base(){
FindDefVol
_ret=$?
if [ $_ret != 0 ]; then
echo "Default volume not found."
[ "x$1" = "xstop" ] || exit 1
fi
QPKG_ROOT="${DEF_VOLMP}/.qpkg"
[ -d "${QPKG_ROOT}" ] || /bin/mkdir -p "${QPKG_ROOT}"
/bin/chmod 777 "${QPKG_ROOT}"
}
function check_audio_dev()
{
for (( i=0; i<5; i=i+1 ))
do
if [ -f /proc/asound/card${i}/pcm0p/sub0/info ]; then
/bin/grep PLAYBACK /proc/asound/card${i}/pcm0p/sub0/info 1>>/dev/null 2>>/dev/null
if [ $? -eq 0 ]; then
/bin/ln -sf audio${i} /dev/audio
/bin/ln -sf mixer${i} /dev/mixer
/bin/ln -sf dsp${i} /dev/dsp
break;
fi
fi
done
}
function set_def_qpkg_info()
{
[ "x$1" != x ] || return 1
MY_QPKG_Name=`/sbin/getcfg "$1" Name -u -d X -f $QPKG_CONF`
if [ xX != x"$MY_QPKG_Name" ]; then
if [ x`/sbin/getcfg "$1" Enable -u -d TRUE -f $QPKG_CONF` = xFALSE ]; then
MY_QPKG_Enable="FALSE"
else
MY_QPKG_Enable="TRUE"
fi
else
MY_QPKG_Enable="`/sbin/getcfg "$1" Enable -u -d FALSE -f $DEF_QPKG_CONF`"
fi
if [ -f $DEF_QPKG_CONF ] && [ xX != x`/sbin/getcfg "$1" Name -u -d X -f $DEF_QPKG_CONF` ]; then
[ -f $QPKG_CONF ] || /bin/touch $QPKG_CONF
/sbin/setcfg -f $QPKG_CONF "$1" Name "`/sbin/getcfg -f $DEF_QPKG_CONF "$1" Name`"
/sbin/setcfg -f $QPKG_CONF "$1" Version "`/sbin/getcfg -f $DEF_QPKG_CONF "$1" Version`"
if [ "$1" = "MusicStation" ] && [ "x$MS_Hide" = "x1" ]; then
/sbin/setcfg -f $QPKG_CONF "$1" Enable FALSE
elif [ "$1" = "PhotoStation" ] && [ "x$PS_Hide" = "x1" ]; then
/sbin/setcfg -f $QPKG_CONF "$1" Enable FALSE
else
/sbin/setcfg -f $QPKG_CONF "$1" Enable "$MY_QPKG_Enable"
fi
/sbin/setcfg -f $QPKG_CONF "$1" QPKG_File "`/sbin/getcfg -f $DEF_QPKG_CONF "$1" QPKG_File`"
/sbin/setcfg -f $QPKG_CONF "$1" Date "`/sbin/getcfg -f $DEF_QPKG_CONF "$1" Date`"
/sbin/setcfg -f $QPKG_CONF "$1" Shell "`/sbin/getcfg -f $DEF_QPKG_CONF "$1" Shell`"
/sbin/setcfg -f $QPKG_CONF "$1" Install_Path "`/sbin/getcfg -f $DEF_QPKG_CONF "$1" Install_Path`"
/sbin/setcfg -f $QPKG_CONF "$1" WebUI "`/sbin/getcfg -f $DEF_QPKG_CONF "$1" WebUI`"
/sbin/setcfg -f $QPKG_CONF "$1" Author "`/sbin/getcfg -f $DEF_QPKG_CONF "$1" Author`"
/sbin/setcfg -f $QPKG_CONF "$1" Sys_App "`/sbin/getcfg -f $DEF_QPKG_CONF "$1" Sys_App -d 0`"
fi
/bin/touch "/tmp/.${1}.updated"
return 0
}
function mmscan_schedule()
{
BG_HOUR=`/sbin/getcfg "QPHOTO" "BG_HOUR" -d 3`
BG_MINUTE=`/sbin/getcfg "QPHOTO" "BG_MINUTE" -u -d 0`
/bin/grep ImR_all /etc/config/crontab 1>>/dev/null 2>>/dev/null
ret=$?
if [ $ret -eq 0 ]; then
/bin/sed -i '/ImR_all/d' /etc/config/crontab
fi
/bin/grep "ImRd" /etc/config/crontab 1>>/dev/null 2>>/dev/null
if [ $? -ne 0 ]; then
if [ $BG_HOUR -ge 0 ]; then
/bin/echo "$BG_MINUTE $BG_HOUR * * * /etc/init.d/ImRd.sh bgThGen" >> /etc/config/crontab
fi
else
if [ $BG_HOUR -ge 0 ]; then
/bin/sed -i 's/^.*.ImRd.*$/'"$BG_MINUTE $BG_HOUR * * * \/etc\/init.d\/ImRd.sh bgThGen"'/g' /etc/config/crontab
else
/bin/sed -i '/ImRd.sh/d' /etc/config/crontab
fi
fi
/bin/pidof crond 1>>/dev/null 2>>/dev/null
[ $? -ne 0 ] || /usr/bin/crontab /etc/config/crontab
}
function enable_medialib()
{
if [ "x$1" = "xstop" ]; then
/etc/init.d/StartMediaService.sh stop 1>/dev/null 2>/dev/null
return 0
fi
/bin/pidof mymediadbserver >/dev/null 2>&1
if [ $? != 0 ] && [ -x /etc/init.d/StartMediaService.sh ]; then
if [ ! -f $PACKAGE_PATH/bin/mymediadbserver ] && [ -f /mnt/HDA_ROOT/update_pkg/MusicStation/medialibrary.tgz ]; then
/bin/rm -rf ${MNT_POINT}/opt/medialibrary 2>/dev/null
/bin/tar zxf /mnt/HDA_ROOT/update_pkg/MusicStation/medialibrary.tgz -C ${MNT_POINT}/opt/ 2>/dev/null
/bin/rm -rf /usr/local/medialibrary 2>/dev/null
/bin/ln -sf ${MNT_POINT}/opt/medialibrary /usr/local/medialibrary
fi
/etc/init.d/StartMediaService.sh start 1>/dev/null 2>/dev/null
fi
ln -sf ../init.d/StartMediaService.sh /etc/rcK.d/K03MediaService
}
function musicstation()
{
MS_QPKG_Ver=`/sbin/getcfg MusicStation Version -d 2.0 -f $QPKG_CONF`
UseSysAccount=`/sbin/getcfg MUSICSTATION UseSysAccount -u -d x -f /etc/config/uLinux.conf`
if [ "$MS_QPKG_Ver" \< "2.1" ] && [ ! -f ${UPDATEPKG_DIR}/musicstation.tgz ]; then
/sbin/rmcfg MusicStation -f $QPKG_CONF 2>/dev/null
/sbin/setcfg MUSICSTATION Enable FALSE
[ $1 != "start" ] || return 1
fi
MS_Enable=`/sbin/getcfg MUSICSTATION Enable -u -d TRUE`
if [ "x$MS_Hide" = "x1" ] && [ x"$MS_Enable" = x"TRUE" ]; then
/sbin/setcfg MUSICSTATION Enable FALSE
MS_Enable="FALSE"
fi
MS_QPKG=`/sbin/getcfg MusicStation QPKG -u -d FALSE -f $APP_RUNTIME_CONF`
MS_QPKG_Name=`/sbin/getcfg MusicStation Name -u -d X -f $QPKG_CONF`
if [ ! -f ${UPDATEPKG_DIR}/.MusicStation_removed ] && [ x"$MS_QPKG" = xTRUE ] && [ x"$MS_QPKG_Name" = xX ]; then
set_def_qpkg_info MusicStation
elif [ ! -f ${UPDATEPKG_DIR}/.MusicStation_removed ] && [ ! -f "/tmp/.MusicStation.updated" ] && [ ! -d ${UPDATEPKG_DIR}/MusicStation ] && [ x"$MS_QPKG" = xTRUE ]; then
set_def_qpkg_info MusicStation
fi
if [ x"$MS_QPKG" = xTRUE ] && [ x"$MS_QPKG_Name" != xX ]; then
#use QPKG
MS_QPKG_Enable=`/sbin/getcfg MusicStation Enable -u -d FALSE -f $QPKG_CONF`
if [ "x$MS_Hide" = "x1" ] && [ x"$MS_QPKG_Enable" = x"TRUE" ]; then
[ -f ${UPDATEPKG_DIR}/.MusicStation_removed ] || /sbin/setcfg MusicStation Enable FALSE -f $QPKG_CONF
MS_QPKG_Enable="FALSE"
fi
if [ ! -z "$MS_QPKG_Enable" ] && [ x"$MS_Enable" != x"$MS_QPKG_Enable" ]; then
MS_Enable=$MS_QPKG_Enable
/sbin/setcfg MUSICSTATION Enable "$MS_QPKG_Enable"
fi
fi
if [ $1 = "start" ]; then
if [ x"$MS_QPKG" = xTRUE ] && [ -f ${UPDATEPKG_DIR}/.MusicStation_removed ]; then
[ ! -f ${UPDATEPKG_DIR}/musicstation.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/musicstation.tgz
return 1
fi
if [ -f ${UPDATEPKG_DIR}/musicstation.tgz ]; then
/bin/tar zxf ${UPDATEPKG_DIR}/musicstation.tgz -C "${QPKG_ROOT}"
/bin/rm -rf ${MNT_POINT}/opt/musicstation 2>/dev/null
/bin/ln -sf "${QPKG_ROOT}/musicstation" ${MNT_POINT}/opt/
fi
if [ ! -f ${UPDATEPKG_DIR}/musicstation.tgz ] && [ ! -d /mnt/ext/opt/musicstation/api ]; then
/sbin/rmcfg MusicStation -f $QPKG_CONF 2>/dev/null
/sbin/setcfg MUSICSTATION Enable FALSE
return 1
fi
/bin/sed -i 's/QRINFOVAL_USESYSACCOUNT/'"${UseSysAccount}"'/g' /mnt/ext/opt/musicstation/api/libs/inc_common.php
if [ -f ${MNT_POINT}/opt/musicstation/api/radioclass.php ] && [ -d /mnt/ext/opt/MSV2/api ]; then
/bin/cp ${MNT_POINT}/opt/musicstation/api/radioclass.php /mnt/ext/opt/MSV2/api/
fi
[ -d /share/${MultimediaShare}/.@__thumb ] || /bin/mkdir /share/${MultimediaShare}/.@__thumb
[ -d /share/${MultimediaShare}/.@__thumb ] && /bin/chmod 777 /share/${MultimediaShare}/.@__thumb
[ -d ${MNT_POINT}/opt/musicstation/sound ] && /bin/cp -af ${MNT_POINT}/opt/musicstation/sound /share/${MultimediaShare}/.@__thumb/
[ -f /share/${MultimediaShare}/.@__thumb/MS.db ] && /bin/chmod 666 /share/${MultimediaShare}/.@__thumb/MS.db
if [ $MS_Enable = TRUE ]; then
enable_medialib start
/sbin/setcfg MultimediaStation USBSound TRUE -f $APP_RUNTIME_CONF
/sbin/setcfg MusicStation Enable TRUE -f $APP_RUNTIME_CONF
[ -d $UPNP_ROOT ] || /bin/mkdir -m 777 $UPNP_ROOT
/bin/grep "$UPNP_ROOT" /proc/mounts 1>/dev/null 2>/dev/null
[ $? = 0 ] || _djmounted=FALSE
if [ o${_djmounted} = oFALSE ]; then
for i in `/bin/pidof djmount`
do
/bin/kill -9 $i
sleep 1
done
if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
[ -f /usr/local/bin/djmount ] && /usr/local/bin/djmount -o "allow_other,max_item=256,iocharset=UTF-8" $UPNP_ROOT
else
[ -f /usr/local/bin/djmount ] && /usr/local/bin/djmount -o "allow_other,max_item=512,iocharset=UTF-8" $UPNP_ROOT
fi
fi
[ -f /usr/local/sbin/speaker.sh ] || /bin/ln -sf ${MNT_POINT}/opt/musicstation/speaker.sh /usr/local/sbin/
[ -f /usr/bin/aumix ] || /bin/ln -sf /usr/local/sbin/aumix /usr/bin/
IMPORTFLAG=`/sbin/getcfg OPTIONS IMPORTFLAG -d 0 -f ${MEDIALIB_CONF}`
if [ "$IMPORTFLAG" = "0" ] && [ -x /usr/local/apache/bin/php ] && [ -f /mnt/ext/opt/musicstation/api/playlist_upgrade.php ]; then
/usr/local/apache/bin/php /mnt/ext/opt/musicstation/api/playlist_upgrade.php
/sbin/setcfg OPTIONS IMPORTFLAG 1 -f ${MEDIALIB_CONF}
fi
[ x0 = x`/sbin/getcfg OPTIONS INOTIFY -d 0 -f ${MEDIALIB_CONF}` ] || ${MEDIALIB_DBCMD} inotifyStart 1>>/dev/null 2>>/dev/null
if [ x1 = x`/sbin/getcfg OPTIONS DAILYBUILD -d 0 -f ${MEDIALIB_CONF}` ]; then
${MEDIALIB_DBCMD} SchedulBuild `/sbin/getcfg OPTIONS DAILYBUILD_MM -d 0 -f ${MEDIALIB_CONF}` `/sbin/getcfg OPTIONS DAILYBUILD_HH -d 0 -f ${MEDIALIB_CONF}`
fi
else
[ -d ${MNT_POINT}/opt/musicstation ] || /bin/mkdir ${MNT_POINT}/opt/musicstation
#/bin/rm -rf ${MNT_POINT}/opt/musicstation/* 2>>/dev/null
/bin/echo "The service is not enabled." > ${MNT_POINT}/opt/musicstation/index.php
[ ! -f ${MNT_POINT}/opt/musicstation/error.htm ] || /bin/cp ${MNT_POINT}/opt/musicstation/error.htm ${MNT_POINT}/opt/musicstation/index.php
enable_medialib stop
fi
fi
if [ $1 = "stop" ]; then
/bin/umount "$UPNP_ROOT" 1>>/dev/null 2>>/dev/null
sleep 1
for i in `/bin/pidof djmount`
do
/bin/kill -9 $i
sleep 1
done
/sbin/setcfg MultimediaStation USBSound TRUE -f $APP_RUNTIME_CONF
/sbin/setcfg MusicStation Enable FALSE -f $APP_RUNTIME_CONF
[ -d ${MNT_POINT}/opt/musicstation ] || /bin/mkdir ${MNT_POINT}/opt/musicstation
if [ $MS_Enable = TRUE ]; then
/bin/echo "The service is not activated." > ${MNT_POINT}/opt/musicstation/index.php
[ ! -f ${MNT_POINT}/opt/musicstation/error.htm ] || /bin/cp ${MNT_POINT}/opt/musicstation/error.htm ${MNT_POINT}/opt/musicstation/index.php
else
/bin/echo "The service is not enabled." > ${MNT_POINT}/opt/musicstation/index.php
[ ! -f ${MNT_POINT}/opt/musicstation/error.htm ] || /bin/cp ${MNT_POINT}/opt/musicstation/error.htm ${MNT_POINT}/opt/musicstation/index.php
fi
[ ! -f ${MNT_POINT}/opt/musicstation/api/libs/inc_common.php ] || /bin/rm -f ${MNT_POINT}/opt/musicstation/api/libs/inc_common.php
[ ! -f ${MNT_POINT}/opt/musicstation/api/libs/inc_common.php.disabled ] || /bin/cp ${MNT_POINT}/opt/musicstation/api/libs/inc_common.php.disabled ${MNT_POINT}/opt/musicstation/api/libs/inc_common.php
#${MEDIALIB_DBCMD} DelSchedulBuild 1>>/dev/null 2>>/dev/null
/bin/sed -i "/^.*mymediadbcmd.*buildall/d" /etc/config/crontab
/bin/sed -i "/^.*mymediadbcmd.*stopbuild/d" /etc/config/crontab
/bin/pidof crond 1>>/dev/null 2>>/dev/null
[ $? -ne 0 ] || /usr/bin/crontab /etc/config/crontab
${MEDIALIB_DBCMD} inotifyStop 1>>/dev/null 2>>/dev/null
${MEDIALIB_DBCMD} stopbuildall 1>>/dev/null 2>>/dev/null
enable_medialib stop
fi
}
function photo_scan()
{
case "$1" in
start)
/bin/kill `pidof photo_scand.sh` 2>/dev/null
/etc/init.d/photo_scand.sh 2>/dev/null &
;;
stop)
/sbin/daemon_mgr $PHOTO_SCAND stop "/sbin/photo_scand"
/bin/kill `pidof photo_scand.sh` 2>/dev/null
sleep 1
;;
*)
echo "do nothing"
;;
esac
}
function photostation2()
{
PS_Enable=`/sbin/getcfg PHOTOSTATION Enable -u -d TRUE`
UseSysAccount=`/sbin/getcfg PHOTOSTATION UseSysAccount -u -d x -f /etc/config/uLinux.conf`
if [ "x$PS_Hide" = "x1" ] && [ x"$PS_Enable" = x"TRUE" ]; then
/sbin/setcfg PHOTOSTATION Enable FALSE
PS_Enable="FALSE"
fi
PS_QPKG=`/sbin/getcfg PhotoStation QPKG -u -d FALSE -f $APP_RUNTIME_CONF`
PS_QPKG_Name=`/sbin/getcfg PhotoStation Name -u -d X -f $QPKG_CONF`
if [ ! -f ${UPDATEPKG_DIR}/.PhotoStation_removed ] && [ x"$PS_QPKG" = xTRUE ] && [ x"$PS_QPKG_Name" = xX ]; then
set_def_qpkg_info PhotoStation
elif [ ! -f ${UPDATEPKG_DIR}/.PhotoStation_removed ] && [ ! -f "/tmp/.PhotoStation.updated" ] && [ ! -d ${UPDATEPKG_DIR}/PhotoStation ] && [ x"$PS_QPKG" = xTRUE ]; then
set_def_qpkg_info PhotoStation
fi
if [ x"$PS_QPKG" = xTRUE ] && [ x"$PS_QPKG_Name" != xX ]; then
#use QPKG
PS_QPKG_Enable=`/sbin/getcfg PhotoStation Enable -u -d FALSE -f $QPKG_CONF`
if [ "x$PS_Hide" = "x1" ] && [ x"$PS_QPKG_Enable" = x"TRUE" ]; then
[ -f ${UPDATEPKG_DIR}/.PhotoStation_removed ] || /sbin/setcfg PhotoStation Enable FALSE -f $QPKG_CONF
PS_QPKG_Enable="FALSE"
fi
if [ ! -z "$PS_QPKG_Enable" ] && [ x"$PS_Enable" != x"$PS_QPKG_Enable" ]; then
PS_Enable=$PS_QPKG_Enable
/sbin/setcfg PHOTOSTATION Enable "$PS_QPKG_Enable"
fi
fi
if [ $1 = "start" ]; then
if [ ! -d "${MMSHARE_PATH}" ]; then
echo "${MultimediaShare} directory is not ready."
exit 1
fi
if [ x"$PS_QPKG" = xTRUE ] && [ -f ${UPDATEPKG_DIR}/.PhotoStation_removed ]; then
[ ! -f ${UPDATEPKG_DIR}/photostation2.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/photostation2.tgz
return 1
fi
if [ -f ${UPDATEPKG_DIR}/photostation2.tgz ]; then
/bin/tar zxf ${UPDATEPKG_DIR}/photostation2.tgz -C "${QPKG_ROOT}" 2>>/dev/null
/bin/rm -rf ${MNT_POINT}/opt/photostation2 2>/dev/null
/bin/ln -sf "${QPKG_ROOT}/photostation2" ${MNT_POINT}/opt/
fi
if [ ! -f ${UPDATEPKG_DIR}/photostation2.tgz ] && [ ! -d /mnt/ext/opt/photostation2/api ]; then
/sbin/rmcfg PhotoStation -f $QPKG_CONF 2>/dev/null
/sbin/setcfg PHOTOSTATION Enable FALSE
return 1
fi
[ -d ${MNT_POINT}/opt/photostation2/Samples ] || /bin/ln -sf ${MNT_POINT}/opt/MSV2/Samples ${MNT_POINT}/opt/photostation2/Samples
[ ! -f /mnt/ext/opt/photostation2/api/fileclass.php ] || /bin/cp /mnt/ext/opt/photostation2/api/fileclass.php /mnt/ext/opt/MSV2/api/fileclass.php
if [ -d /share/${MultimediaShare}/.@__thumb ]; then
if [ ! -f "/share/${MultimediaShare}/.@__thumb/PS_data.db" ]; then
/bin/cp /mnt/ext/opt/photostation2/api/libs/PS_data_basic.db "/share/${MultimediaShare}/.@__thumb/PS_data.db"
chown httpdusr "/share/${MultimediaShare}/.@__thumb/PS_data.db"
fi
chmod 666 "/share/${MultimediaShare}/.@__thumb/PS_data.db"
[ ! -f "/share/${MultimediaShare}/.@__thumb/MS_data.db" ] || chmod 666 "/share/${MultimediaShare}/.@__thumb/MS_data.db"
fi
/bin/sed -i 's/QINFOVAL_PLATFORM/'"${BOOT_CONF}"'/g' ${MNT_POINT}/opt/photostation2/api/libs/inc_common.php
/bin/sed -i 's/QINFOVAL_DEMO_SITE/'"${DEMO_SITE_SUPPORT}"'/g' ${MNT_POINT}/opt/photostation2/api/libs/inc_common.php
FFmpegExtra=`/sbin/getcfg MultimediaStation FFmpegExtra -u -d FALSE -f $APP_RUNTIME_CONF`
/bin/sed -i 's/QINFOVAL_MS_EXTRA/'"${FFmpegExtra}"'/g' ${MNT_POINT}/opt/photostation2/api/libs/inc_common.php
/bin/sed -i 's/QINFOVAL_MS_FILE_ROOT/'"\/share\/${MultimediaShare}"'/g' ${MNT_POINT}/opt/photostation2/api/libs/inc_common.php
/bin/sed -i 's/QRINFOVAL_USESYSACCOUNT/'"${UseSysAccount}"'/g' /mnt/ext/opt/photostation2/api/libs/inc_common.php
if [ $PS_Enable != TRUE ]; then
[ -d ${MNT_POINT}/opt/photostation2 ] || /bin/mkdir ${MNT_POINT}/opt/photostation2
/bin/echo "Photo Station is not enabled." > ${MNT_POINT}/opt/photostation2/index.php
[ ! -f ${MNT_POINT}/opt/photostation2/disabled_page.html ] || /bin/cp ${MNT_POINT}/opt/photostation2/disabled_page.html ${MNT_POINT}/opt/photostation2/index.php
else
photo_scan start
/sbin/setcfg PhotoStation Enable TRUE -f $APP_RUNTIME_CONF
fi
[ -f /tmp/geoip.xml ] && /bin/ln -sf /tmp/geoip.xml ${MNT_POINT}/opt/photostation2/geoip.xml
fi
if [ $1 = "stop" ]; then
photo_scan stop
/sbin/setcfg PhotoStation Enable FALSE -f $APP_RUNTIME_CONF
[ -d ${MNT_POINT}/opt/photostation2 ] || /bin/mkdir ${MNT_POINT}/opt/photostation2
if [ $PS_Enable = TRUE ]; then
/bin/echo "The service is not activated." > ${MNT_POINT}/opt/photostation2/index.php
[ ! -f ${MNT_POINT}/opt/photostation2/disabled_page.html ] || /bin/cp ${MNT_POINT}/opt/photostation2/disabled_page.html ${MNT_POINT}/opt/photostation2/index.php
else
/bin/echo "The service is not enabled." > ${MNT_POINT}/opt/photostation2/index.php
[ ! -f ${MNT_POINT}/opt/photostation2/disabled_page.html ] || /bin/cp ${MNT_POINT}/opt/photostation2/disabled_page.html ${MNT_POINT}/opt/photostation2/index.php
fi
[ ! -f ${MNT_POINT}/opt/photostation2/api/libs/inc_common.php ] || /bin/rm -f ${MNT_POINT}/opt/photostation2/api/libs/inc_common.php
[ ! -f ${MNT_POINT}/opt/photostation2/api/libs/inc_common.php.disabled ] || /bin/cp ${MNT_POINT}/opt/photostation2/api/libs/inc_common.php.disabled ${MNT_POINT}/opt/photostation2/api/libs/inc_common.php
fi
}
function mmstation(){
QPHOTO_Enable=`/sbin/getcfg QPHOTO Enable -u -d TRUE` #MSV2
if [ "x$QPHOTO_Hide" = "x1" ] && [ x"$QPHOTO_Enable" = x"TRUE" ]; then
/sbin/setcfg QPHOTO Enable FALSE
QPHOTO_Enable="FALSE"
fi
if [ $1 = "start" ]; then
if [ $QPHOTO_Enable = TRUE ]; then
if [ x${MSV2_SUPPORT} = xTRUE ]; then
if [ x${MSV2_SUPPORT} = xTRUE ] && [ -f ${UPDATEPKG_DIR}/MSV2.tgz ]; then
cd ${MNT_POINT}/opt/
/bin/tar zxf ${UPDATEPKG_DIR}/MSV2.tgz MSV2/index.php
fi
[ -f /sbin/flv_convertd ] && /sbin/daemon_mgr flv_convertd start "/sbin/flv_convertd -d"
index_file=index`/sbin/getcfg System "Build Number" -f /etc/default_config/uLinux.conf`
if [ -f ${MNT_POINT}/opt/MSV2/index.swf ] || [ -f "${MNT_POINT}/opt/MSV2/${index_file}.swf" ]; then
/bin/grep INDEXSWFFILENAME ${MNT_POINT}/opt/MSV2/index.php 1>>/dev/null 2>>/dev/null
if [ $? -eq 0 ]; then
/bin/sed -i 's/INDEXSWFFILENAME/'"${index_file}"'/g' ${MNT_POINT}/opt/MSV2/index.php
[ -f ${MNT_POINT}/opt/MSV2/index.swf ] && /bin/rm -f ${MNT_POINT}/opt/MSV2/index20*.swf
/bin/mv ${MNT_POINT}/opt/MSV2/index.swf "${MNT_POINT}/opt/MSV2/${index_file}.swf" 2>/dev/null
fi
fi
/bin/rm -rf /home/httpd/cgi-bin/Qmultimedia/* 2>>/dev/null
/bin/rm -rf /home/httpd/Qmultimedia/* 2>>/dev/null
[ -d /home/httpd/Qmultimedia/ ] && /bin/echo "Page not found." > /home/httpd/Qmultimedia/index.html
fi
echo "."
else
if [ x${MSV2_SUPPORT} = xTRUE ]; then
[ -d ${MNT_POINT}/opt/MSV2 ] || /bin/mkdir ${MNT_POINT}/opt/MSV2
# /bin/rm -rf ${MNT_POINT}/opt/MSV2/* 2>>/dev/null
/bin/echo "Multimedia Station is not enabled." > ${MNT_POINT}/opt/MSV2/index.php
fi
fi
fi #end of start
if [ $1 = "stop" ]; then
if [ -f /sbin/flv_convertd ]; then
/sbin/daemon_mgr flv_convertd stop "/sbin/flv_convertd -d"
[ ! -f /var/lock/flv_convertd ] || /bin/kill -9 `/bin/cat /var/lock/flv_convertd` 2>/dev/null
[ ! -f /var/lock/flv_convertd ] || /bin/rm -f /var/lock/flv_convertd
fi
/bin/echo "The service is not enabled." > ${MNT_POINT}/opt/MSV2/index.php
fi
}
make_qpkg_base "$1"
case "$1" in
start)
echo -n "Starting media stations: "
check_audio_dev
if [ ! -f /tmp/geoip.xml ]; then
/bin/touch /tmp/geoip.xml
[ -f /mnt/ext/opt/photostation2/geoip.xml ] && /bin/cp /mnt/ext/opt/photostation2/geoip.xml /tmp/geoip.xml
/sbin/curl -4 --retry 2 --connect-timeout 30 -m 30 http://www.mycloudnas.com/geoip/getMyGeoIP.php -o /tmp/geoip.xml 2>/dev/null &
fi
if [ ! -d "${MMSHARE_PATH}" ]; then
echo "${MultimediaShare} directory is not ready."
exit 1
else
/bin/chmod 777 "${MMSHARE_PATH}"
fi
mmscan_schedule
if [ x${MSV2_SUPPORT} = xTRUE ] && [ -f ${UPDATEPKG_DIR}/MSV2.tgz ]; then
/bin/tar zxf ${UPDATEPKG_DIR}/MSV2.tgz -C "${QPKG_ROOT}"
/bin/rm -rf ${MNT_POINT}/opt/MSV2 2>/dev/null
/bin/ln -sf "${QPKG_ROOT}/MSV2" ${MNT_POINT}/opt/
fi
if [ -d "${MNT_POINT}/opt/MSV2" ]; then
[ -d /share/${MultimediaShare}/.@__thumb/image_frame ] || /bin/mkdir -p /share/${MultimediaShare}/.@__thumb/image_frame
/bin/chmod 777 /share/${MultimediaShare}/.@__thumb
/bin/chmod 777 /share/${MultimediaShare}/.@__thumb/image_frame
[ -f /share/${MultimediaShare}/.@__thumb/MS.db ] && /bin/chmod 666 /share/${MultimediaShare}/.@__thumb/MS.db
[ ! -f "/share/${MultimediaShare}/.@__thumb/MS_data.db" ] || chmod 666 "/share/${MultimediaShare}/.@__thumb/MS_data.db"
[ ! -f "/share/${MultimediaShare}/.@__thumb/PS_data.db" ] || chmod 666 "/share/${MultimediaShare}/.@__thumb/PS_data.db"
[ -d ${MNT_POINT}/opt/MSV2/image_frame ] && /bin/cp -a ${MNT_POINT}/opt/MSV2/image_frame/*.png /share/${MultimediaShare}/.@__thumb/image_frame/
/bin/chmod 666 /share/${MultimediaShare}/.@__thumb/image_frame/*.png
if [ ! -f /share/${MultimediaShare}/.@__thumb/install.lock ]; then
content=`/bin/ls "/share/${MultimediaShare}/"`
if [ -z "${content}" ] && [ -d ${MNT_POINT}/opt/MSV2/Samples ]; then
/bin/cp -a ${MNT_POINT}/opt/MSV2/Samples /share/${MultimediaShare}/
[ ! -d /share/${MultimediaShare}/Samples/thumb ] || /bin/rm -rf /share/${MultimediaShare}/Samples/thumb
/bin/chmod 777 /share/${MultimediaShare}/Samples
/bin/chmod 666 /share/${MultimediaShare}/Samples/*.jpg
if [ -x /usr/local/apache/bin/php ]; then
[ -f ${MNT_POINT}/opt/MSV2/init_samples.php ] && /usr/local/apache/bin/php -c $PHP_INI ${MNT_POINT}/opt/MSV2/init_samples.php
[ $? = 0 ] && /bin/touch /share/${MultimediaShare}/.@__thumb/install.lock
fi
else
/bin/touch /share/${MultimediaShare}/.@__thumb/install.lock
fi
fi
[ ! -f /share/${MultimediaShare}/.@__thumb/install.lock ] || /bin/rm -f ${MNT_POINT}/opt/MSV2/init_samples.php
fi
[ ! -f ${MNT_POINT}/opt/MSV2/speaker.sh ] || /bin/ln -sf ${MNT_POINT}/opt/MSV2/speaker.sh /usr/local/sbin/
[ -f /usr/bin/aumix ] || /bin/ln -sf /usr/local/sbin/aumix /usr/bin/
[ -f "${BACKUP_ALARM_INFO}" ] && /bin/cp -af "${BACKUP_ALARM_INFO}" "${RUNTIME_ALARM_INFO}"
[ -f /sbin/lpb_scheduler ] && /sbin/daemon_mgr lpb_scheduler start "/sbin/lpb_scheduler -d"
[ ! -f /tmp/.2genth.ing ] || /bin/rm -f /tmp/.2genth.ing 2>/dev/null
[ -f /sbin/genthd ] && /sbin/daemon_mgr genthd start "/sbin/genthd&"
if [ -x ${MNT_POINT}/opt/MSV2/bin/dcraw ] && [ ! -x /usr/local/sbin/dcraw ]; then
/bin/ln -sf ${MNT_POINT}/opt/MSV2/bin/dcraw /usr/local/sbin/
fi
echo -n "Multimedia Station, "
mmstation start
echo -n "Music Station, "
musicstation start
echo -n "Photo Station. "
photostation2 start
echo
;;
stop)
echo -n "Shutting down media stations: "
if [ x${MSV2_SUPPORT} = xTRUE ] && [ -f /sbin/flv_convertd ]; then
[ -f /sbin/lpb_scheduler ] && /sbin/daemon_mgr lpb_scheduler stop "/sbin/lpb_scheduler -d"
[ ! -f /var/lock/flv_convertd.lpb_scheduler ] || /bin/kill -9 `/bin/cat /var/lock/flv_convertd.lpb_scheduler` 2>/dev/null
[ ! -f /var/lock/flv_convertd.lpb_scheduler ] || /bin/rm -f /var/lock/flv_convertd.lpb_scheduler
[ -f /sbin/genthd ] && /sbin/daemon_mgr genthd stop "/sbin/genthd"
[ -f "${RUNTIME_ALARM_INFO}" ] && /bin/cp -af "${RUNTIME_ALARM_INFO}" "${BACKUP_ALARM_INFO}"
#/bin/sed -i '/ImRd.sh/d' /etc/config/crontab
#/bin/pidof crond 1>>/dev/null 2>>/dev/null
#[ $? -ne 0 ] || /usr/bin/crontab /etc/config/crontab
fi
if [ -d "/share/${MultimediaShare}/.@__thumb/magick_tmpdir" ]; then
/bin/chmod 777 "/share/${MultimediaShare}/.@__thumb/magick_tmpdir"
/bin/rm -rf /share/${MultimediaShare}/.@__thumb/magick_tmpdir/*
fi
echo -n "Multimedia Station, "
mmstation stop
echo -n "Music Station, "
musicstation stop
echo -n "Photo Station. "
photostation2 stop
/bin/kill `pidof inotifywait` 2>/dev/null
echo
;;
restart)
$0 stop
$0 start
;;
notify)
# notify daemon that a new job is the queue
#/bin/kill -USR1 `pidof ImRd`
;;
bgThGen)
trgtFolder="/share/${MultimediaShare}"
if [ ! -z "${2}" ]; then
[ -d "${2}" ] || exit 1
trgtFolder="${2}"
fi
QPHOTO_Enable=`/sbin/getcfg QPHOTO Enable -u -d TRUE`
[ x"$QPHOTO_Enable" = x"TRUE" ] || ThumbnailGenerator="/mnt/ext/opt/photostation2/api/background_conversion.php"
if [ x${MSV2_SUPPORT} = xTRUE ]; then
[ -f $ThumbnailGenerator ] || exit 1
ret=1
for i in `/bin/pidof php`
do
/bin/cat /proc/$i/cmdline | /bin/grep "$ThumbnailGenerator" 1>>/dev/null 2>>/dev/null
[ $? -eq 0 ] && ret=0 && break
done
else
/bin/ps | /bin/grep "ImR_all" | /bin/grep "soft" 1>>/dev/null 2>>/dev/null
ret=$?
fi
if [ $ret -eq 0 ]; then
/bin/echo "bgThGen is running."
exit 1
fi
/bin/echo "ImRd bgThGen start."
[ ! -f "/tmp/.bgThGen.last" ] || /bin/rm -f "/tmp/.bgThGen.last"
if [ x${MSV2_SUPPORT} = xTRUE ]; then
j=1
while [ $j -le 10 ] ; do
ret=1
for i in `/bin/pidof php`
do
/bin/cat /proc/$i/cmdline | /bin/grep "$ThumbnailGenerator" 1>>/dev/null 2>>/dev/null
[ $? -eq 0 ] && ret=0 && break
done
[ $ret = 0 ] || /usr/local/apache/bin/php -c $PHP_INI -d memory_limit=128M $ThumbnailGenerator "${trgtFolder}" 1000
j=$(($j+1))
[ -f "/tmp/.bgThGen.last" ] || break
done
else
/usr/local/sbin/ImR_all -soft /Qmultimedia 1>>/dev/null 2>>/dev/null
fi
/bin/echo "bgThGen finished."
;;
musicstation)
musicstation $2
;;
photostation2)
photostation2 $2
;;
mmstation)
mmstation $2
;;
mmscan_schedule)
mmscan_schedule
;;
*)
echo "Usage: /etc/init.d/$0 {start|stop|restart}"
exit 1
esac
[ -d /home/httpd/cgi-bin/apps ] && /sbin/user_cmd -1 /etc/qos.ui.sm.conf > /home/httpd/cgi-bin/apps/start.json
exit 0

488
Qthttpd.sh Executable file
View File

@@ -0,0 +1,488 @@
#!/bin/sh
# For Qweb and Qphoto
# default port: 80
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
ROOT_PART="/mnt/HDA_ROOT"
QWEB_DEFAULT_INDEX_HTML="/home/httpd/help/eng/help_qweb.html"
QWEB_DEFAULT_INDEX_PHP="/home/httpd/help/eng/help_qweb.php"
WebShare=`/sbin/getcfg SHARE_DEF defWeb -d Qweb -f /etc/config/def_share.info`
QWEB_SLINK="/home/Qhttpd/${WebShare}"
QWEB_FOLDER="/share/${WebShare}"
QWEB_INDEX_HTML="$QWEB_SLINK/index.html"
QWEB_INDEX_HTM="$QWEB_SLINK/index.htm"
QWEB_INDEX_PHP="$QWEB_SLINK/index.php"
QEACCELERATOR_TMPLINK="/tmp/.eaccelerator.tmp"
QEACCELERATOR_TMPDIR="/.eaccelerator.tmp"
MNT_POINT="/mnt/ext"
APACHE_SOURCE="${MNT_POINT}/opt/source/apache_php5.tgz"
APACHE_DIR="/usr/local/apache"
APACHE_CONF_DIR="/etc/config/apache"
UPDATEPKG_DIR="${ROOT_PART}/update_pkg"
PHP_INI="/etc/config/php.ini"
APACHE_CONF="/etc/config/apache/apache.conf"
APP_RUNTIME_CONF="/var/.application.conf"
QPKG_CONF="/etc/config/qpkg.conf"
SSMTP_CONF_DIR=/etc/config/ssmtp
SSMTP_CONF_DEFAULT=/etc/default_config/ssmtp
CMS_ENABLE=`/sbin/getcfg CMS Enable -d FALSE -f /etc/config/uLinux.conf`
PGSQL_ENABLE=`/sbin/getcfg PgSQL Enable -d FALSE -f /etc/config/uLinux.conf`
ZEND_SOURCE="${UPDATEPKG_DIR}/Zend.tgz"
DEF_MEMORY_LIMIT=256
[ "x${BOOT_CONF}" = "xTS-NASX86" ] || DEF_MEMORY_LIMIT=128
DEF_POST_MAX_SIZE=2047
DEF_UPLOAD_MAX_FILESIZE=2047
MSV2_SUPPORT=`/sbin/getcfg "QPHOTO" "MSV2_SUPPORT" -d "FALSE" -f /etc/default_config/uLinux.conf`
PHP_SESSION_PATH=""
CustomLog=`/sbin/getcfg QWEB CustomLog -u -d FALSE`
ramUse=`/bin/df | grep "/dev/ram" | /bin/awk '{print $5}'`
. /etc/init.d/functions
make_php_sess_base(){
FindDefVol
_ret=$?
if [ $_ret != 0 ]; then
return 1
fi
[ -d "${DEF_VOLMP}/.php_session" ] || /bin/mkdir -p "${DEF_VOLMP}/.php_session"
/bin/chmod 777 "${DEF_VOLMP}/.php_session"
PHP_SESSION_PATH="${DEF_VOLMP}/.php_session"
[ -d "${DEF_VOLMP}/${WebShare}" ] && /bin/chmod 777 "${DEF_VOLMP}/${WebShare}"
}
init_qweb()
{
if [ ! -f $QWEB_INDEX_HTML ] && [ ! -f $QWEB_INDEX_HTM ] && [ ! -f $QWEB_INDEX_PHP ]; then
/bin/cp "$QWEB_DEFAULT_INDEX_PHP" "$QWEB_INDEX_PHP"
fi
}
check_qweb_link()
{
if [ `/sbin/getcfg "QWEB" "Enable" -d 1` = 1 ]; then
if [ -d $QWEB_FOLDER ]; then
if [ ! -e $QWEB_SLINK ]; then
ln -s $QWEB_FOLDER $QWEB_SLINK
elif [ ! -L $QWEB_SLINK ]; then
#shouldn't come to this place
rm -rf $QWEB_SLINK
ln -s $QWEB_FOLDER $QWEB_SLINK
fi
init_qweb
fi
fi
}
clean_apache_log()
{
/bin/rm -f ${APACHE_DIR}/logs/* 1>>/dev/null 2>>/dev/null
/bin/rm -rf ${APACHE_DIR}/logs/ssl_scache 1>>/dev/null 2>>/dev/null
/bin/mkdir ${APACHE_DIR}/logs/ssl_scache
[ $? = 0 ] && echo "Apache logs have been cleaned."
/bin/grep "Qthttpd.sh" /etc/config/crontab 1>/dev/null 2>/dev/null
if [ $? = 0 ]; then
/bin/sed -i '/Qthttpd/d' /etc/config/crontab
/usr/bin/crontab /etc/config/crontab
fi
/bin/sync
return 0
}
set_config()
{
MEMORY_LIMIT=`/sbin/getcfg PHP memory_limit -d 0 -f $PHP_INI | /bin/cut -d 'M' -f 1`
POST_MAX_SIZE=`/sbin/getcfg PHP post_max_size -d 0 -f $PHP_INI | /bin/cut -d 'M' -f 1`
UPLOAD_MAX_FILESIZE=`/sbin/getcfg PHP upload_max_filesize -d 0 -f $PHP_INI | /bin/cut -d 'M' -f 1`
sendmailp=`/sbin/getcfg "mail function" "sendmail_path" -f $PHP_INI`
[ "x${sendmailp}" != x ] || /sbin/setcfg "mail function" sendmail_path "/usr/sbin/sendmail -t -i" -f $PHP_INI
[ x`/sbin/getcfg MySQL "mysql.default_socket" -f $PHP_INI` != x ] || /sbin/setcfg MySQL "mysql.default_socket" \"/tmp/mysql.sock\" -f $PHP_INI
[ x`/sbin/getcfg eaccelerator "eaccelerator.shm_size" -f $PHP_INI -d 16` = x32 ] || /sbin/setcfg eaccelerator eaccelerator.shm_size 32 -f $PHP_INI
[ x`/sbin/getcfg "PHP" "include_path" -f $PHP_INI` != "\".:/etc/config/php\"" ] || /sbin/setcfg PHP include_path "\".:/etc/config/php\"" -f $PHP_INI
[ x`/sbin/getcfg "PHP" "upload_tmp_dir" -f $PHP_INI` = "x${QWEB_FOLDER}" ] || /sbin/setcfg "PHP" "upload_tmp_dir" "${QWEB_FOLDER}" -f $PHP_INI
[ x`/sbin/getcfg "Session" "session.save_path" -f $PHP_INI` = "x${PHP_SESSION_PATH}" ] || /sbin/setcfg "Session" "session.save_path" "${PHP_SESSION_PATH}" -f $PHP_INI
if [ "x${MSV2_SUPPORT}" = xTRUE ] && [ -f /usr/bin/ffmpeg ]; then
/bin/grep ffmpeg.so ${PHP_INI} 1>>/dev/null 2>>/dev/null
[ $? != 0 ] || /bin/sed -i "/extension = ffmpeg.so/d" ${PHP_INI} 2>/dev/null 1>/dev/null
/bin/grep "^Include" ${APACHE_CONF} | /bin/grep "apache-msv2.conf" 1>>/dev/null 2>>/dev/null
if [ $? != 0 ] && [ -f /etc/config/apache/extra/apache-msv2.conf ]; then
/bin/echo "" >> ${APACHE_CONF}
/bin/echo "Include /etc/config/apache/extra/apache-msv2.conf" >> ${APACHE_CONF}
fi
[ -f /etc/config/apache/extra/apache-msv2.conf ] || /bin/sed -i "/^Include.*apache-msv2.conf/d" ${APACHE_CONF} 2>/dev/null 1>/dev/null
/bin/grep "^Include" ${APACHE_CONF} | /bin/grep "apache-musicstation.conf" 1>>/dev/null 2>>/dev/null
if [ $? != 0 ] && [ -f /etc/config/apache/extra/apache-musicstation.conf ]; then
/bin/echo "Include /etc/config/apache/extra/apache-musicstation.conf" >> ${APACHE_CONF}
fi
/bin/grep "^Include" ${APACHE_CONF} | /bin/grep "apache-photo.conf" 1>>/dev/null 2>>/dev/null
if [ $? != 0 ] && [ -f /etc/config/apache/extra/apache-photo.conf ]; then
/bin/echo "Include /etc/config/apache/extra/apache-photo.conf" >> ${APACHE_CONF}
fi
if [ -f /usr/local/apache/modules/imagick.so ]; then
[ x`/sbin/getcfg Imagick extension -f ${PHP_INI}` = "ximagick.so" ] || /sbin/setcfg Imagick extension "imagick.so" -f ${PHP_INI}
else
/bin/grep "\[Imagick\]" ${PHP_INI} 1>>/dev/null 2>>/dev/null
[ $? != 0 ] || /sbin/setcfg -e Imagick extension -f ${PHP_INI}
fi
#[ x`/sbin/getcfg eaccelerator extension -f ${PHP_INI}` = x ] || /sbin/setcfg -e eaccelerator extension -f ${PHP_INI}
[ $MEMORY_LIMIT -le $DEF_MEMORY_LIMIT ] || /sbin/setcfg PHP memory_limit "$DEF_MEMORY_LIMIT"M -f $PHP_INI
[ $POST_MAX_SIZE -le $DEF_POST_MAX_SIZE ] || /sbin/setcfg PHP post_max_size "$DEF_POST_MAX_SIZE"M -f $PHP_INI
[ $UPLOAD_MAX_FILESIZE -le $DEF_UPLOAD_MAX_FILESIZE ] || /sbin/setcfg PHP upload_max_filesize "$DEF_UPLOAD_MAX_FILESIZE"M -f $PHP_INI
else
/sbin/setcfg -e Imagick extension -f ${PHP_INI}
/bin/sed -i "/extension = ffmpeg.so/d" ${PHP_INI} 2>/dev/null 1>/dev/null
/bin/sed -i "/^Include.*apache-msv2.conf/d" ${APACHE_CONF} 2>/dev/null 1>/dev/null
/bin/sed -i "/^Include.*apache-musicstation.conf/d" ${APACHE_CONF} 2>/dev/null 1>/dev/null
/bin/sed -i "/^Include.*apache-photo.conf/d" ${APACHE_CONF} 2>/dev/null 1>/dev/null
[ x`/sbin/getcfg eaccelerator extension -f ${PHP_INI}` = x"eaccelerator.so" ] || /sbin/setcfg eaccelerator extension "eaccelerator.so" -f ${PHP_INI}
fi
VS_QPKG=`/sbin/getcfg VideoStation QPKG -u -d FALSE -f $APP_RUNTIME_CONF`
VS_QPKG_Name=`/sbin/getcfg VideoStation Name -u -d X -f $QPKG_CONF`
if [ x"$VS_QPKG" = xTRUE ]; then
/bin/grep "^Include" ${APACHE_CONF} | /bin/grep "apache-video.conf" 1>>/dev/null 2>>/dev/null
if [ $? != 0 ] && [ -f /etc/config/apache/extra/apache-video.conf ]; then
/bin/echo "" >> ${APACHE_CONF}
/bin/echo "Include /etc/config/apache/extra/apache-video.conf" >> ${APACHE_CONF}
fi
else
/bin/sed -i "/^Include.*apache-video.conf/d" ${APACHE_CONF} 2>/dev/null 1>/dev/null
fi
if [ "x${PHP_ZEND_SUPPORT}" = "xTRUE" ]; then
/bin/grep Zend ${PHP_INI} 2>/dev/null 1>/dev/null
if [ $? != 0 ]; then
/sbin/setcfg Zend zend_extension_manager.optimizer /usr/local/apache/modules/Zend/lib/Optimizer-3.3.0 -f ${PHP_INI}
/sbin/setcfg Zend zend_extension_manager.optimizer_ts /usr/local/apache/modules/Zend/lib/Optimizer_TS-3.3.0 -f ${PHP_INI}
/sbin/setcfg Zend zend_optimizer.version 3.3.0a -f ${PHP_INI}
/sbin/setcfg Zend zend_extension /usr/local/apache/modules/Zend/lib/ZendExtensionManager.so -f ${PHP_INI}
/sbin/setcfg Zend zend_extension_ts /usr/local/apache/modules/Zend/lib/ZendExtensionManager_TS.so -f ${PHP_INI}
fi
else
/bin/grep Zend ${PHP_INI} 2>/dev/null 1>/dev/null
if [ $? = 0 ]; then
[ -x /sbin/rmcfg ] && /sbin/rmcfg Zend -f ${PHP_INI}
fi
fi
if [ -f ${APACHE_CONF} ]; then
/bin/grep "^DocumentRoot \"/share/${WebShare}\"" ${APACHE_CONF} 1>/dev/null 2>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^DocumentRoot.*$/'"DocumentRoot \"\/share\/${WebShare}\""'/g' ${APACHE_CONF}
/bin/grep "^<Directory \"/share/${WebShare}\">" ${APACHE_CONF} 1>/dev/null 2>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^<Directory \"\/share\/Qweb.*$/'"<Directory \"\/share\/${WebShare}\">"'/' ${APACHE_CONF}
if [ "x${CMS_ENABLE}" != xTRUE ]; then
if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
/bin/grep "^MinSpareServers 2" ${APACHE_CONF} 1>/dev/null 2>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^MinSpareServers.*$/'"MinSpareServers 2"'/g' ${APACHE_CONF}
/bin/grep "^MaxSpareServers 5" ${APACHE_CONF} 1>/dev/null 2>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^MaxSpareServers.*$/'"MaxSpareServers 5"'/g' ${APACHE_CONF}
/bin/grep "^StartServers 2" ${APACHE_CONF} 1>/dev/null 2>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^StartServers.*$/'"StartServers 2"'/g' ${APACHE_CONF}
/bin/grep "^MaxClients 10" ${APACHE_CONF} 1>/dev/null 2>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^MaxClients.*$/'"MaxClients 10"'/g' ${APACHE_CONF}
/bin/grep "^MaxRequestsPerChild 30" ${APACHE_CONF} 1>/dev/null 2>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^MaxRequestsPerChild.*$/'"MaxRequestsPerChild 30"'/g' ${APACHE_CONF}
else
maxClient=`/bin/grep MaxClients ${APACHE_CONF} | /bin/cut -d ' ' -f 2`
if [ ! -z "$maxClient" ] && [ $maxClient -gt 50 ]; then
/bin/sed -i 's/^MaxClients.*$/'"MaxClients 50"'/g' ${APACHE_CONF}
fi
fi
if [ "x${CustomLog}" != xTRUE ]; then
/bin/grep "^LogLevel" ${APACHE_CONF} | /bin/grep crit 1>>/dev/null 2>>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^LogLevel.*$/'"LogLevel crit"'/g' ${APACHE_CONF}
/bin/grep "CustomLog" ${APACHE_CONF} 1>>/dev/null 2>>/dev/null
[ $? != 0 ] || /bin/sed -i '/CustomLog/d' ${APACHE_CONF}
/bin/grep "ErrorLog" ${APACHE_CONF} | /bin/grep "/dev/null" 1>>/dev/null 2>>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^ErrorLog.*$/'"ErrorLog \/dev\/null"'/g' ${APACHE_CONF}
fi
fi
fi
/bin/grep TraceEnable ${APACHE_CONF} 1>>/dev/null 2>>/dev/null
if [ $? != 0 ]; then
/bin/sed -i 's/^DocumentRoot/ServerTokens Prod\nTraceEnable off\nDocumentRoot/' ${APACHE_CONF}
/bin/sed -i '/^.*UserDir public_html/d' ${APACHE_CONF}
fi
if [ -f ${APACHE_CONF_DIR}/extra/apache-ssl.conf ]; then
/bin/grep "^DocumentRoot \"/share/${WebShare}\"" ${APACHE_CONF_DIR}/extra/apache-ssl.conf 1>/dev/null 2>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^DocumentRoot.*$/'"DocumentRoot \"\/share\/${WebShare}\""'/g' ${APACHE_CONF_DIR}/extra/apache-ssl.conf
/bin/grep "^SSLCipherSuite ALL:\!SSLv2:\!LOW:\!EXPORT40:@STRENGTH" ${APACHE_CONF_DIR}/extra/apache-ssl.conf 1>/dev/null 2>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^SSLCipherSuite.*$/SSLCipherSuite ALL:!SSLv2:!LOW:!EXPORT40:@STRENGTH/' ${APACHE_CONF_DIR}/extra/apache-ssl.conf
if [ x`/sbin/getcfg QWEB Enable_SSL -d 1` = x1 ]; then
ssl_port=`/sbin/getcfg QWEB SSL_Port -d 8081`
/bin/grep "^Listen ${ssl_port}$" ${APACHE_CONF_DIR}/extra/apache-ssl.conf 1>>/dev/null 2>>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^Listen .*$/'"Listen ${ssl_port}"'/g' ${APACHE_CONF_DIR}/extra/apache-ssl.conf
/bin/grep "^<VirtualHost _default_:${ssl_port}>" ${APACHE_CONF_DIR}/extra/apache-ssl.conf 1>>/dev/null 2>>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^<VirtualHost _default_:.*$/'"<VirtualHost _default_:${ssl_port}>"'/g' ${APACHE_CONF_DIR}/extra/apache-ssl.conf
/bin/grep "^Include" ${APACHE_CONF} | /bin/grep "apache-ssl.conf" 1>>/dev/null 2>>/dev/null
if [ $? != 0 ]; then
/bin/echo "" >> ${APACHE_CONF}
/bin/echo "Include ${APACHE_CONF_DIR}/extra/apache-ssl.conf" >> ${APACHE_CONF}
fi
else
/bin/grep "^Include" ${APACHE_CONF} | /bin/grep "apache-ssl.conf" 1>>/dev/null 2>>/dev/null
[ $? != 0 ] || /bin/sed -i "/^Include.*apache-ssl.conf/d" ${APACHE_CONF} 2>/dev/null 1>/dev/null
fi
fi
if [ -f ${APACHE_CONF_DIR}/extra/apache-dav.conf ]; then
if [ x`/sbin/getcfg QWEB "Enable_WebDAV" -d 0` = x1 ]; then
/bin/grep "^Include" ${APACHE_CONF} | /bin/grep "apache-dav.conf" 1>>/dev/null 2>>/dev/null
if [ $? != 0 ]; then
/bin/echo "" >> ${APACHE_CONF}
/bin/echo "Include ${APACHE_CONF_DIR}/extra/apache-dav.conf" >> ${APACHE_CONF}
fi
else
/bin/grep "^Include" ${APACHE_CONF} | /bin/grep "apache-dav.conf" 1>>/dev/null 2>>/dev/null
[ $? != 0 ] || /bin/sed -i "/^Include.*apache-dav.conf/d" ${APACHE_CONF} 2>/dev/null 1>/dev/null
fi
fi
}
prepare_apache(){
[ -d ${QEACCELERATOR_TMPDIR} ] || /bin/mkdir ${QEACCELERATOR_TMPDIR}
#if [ "x${MSV2_SUPPORT}" != xTRUE ]; then
/bin/mount | /bin/grep "${QEACCELERATOR_TMPDIR}"
[ $? = 0 ] || /bin/mount -t tmpfs tmpfs ${QEACCELERATOR_TMPDIR} -o size=32M
#fi
/bin/chmod 777 ${QEACCELERATOR_TMPDIR}
/bin/rm -rf ${QEACCELERATOR_TMPLINK} 1>>/dev/null 2>>/dev/null
/bin/ln -sf ${QEACCELERATOR_TMPDIR} ${QEACCELERATOR_TMPLINK}
if [ -f ${UPDATEPKG_DIR}/apache_php5.tgz ];then
[ ! -f $APACHE_SOURCE ] || /bin/rm -f $APACHE_SOURCE
APACHE_SOURCE="${UPDATEPKG_DIR}/apache_php5.tgz"
fi
if [ ! -f ${APACHE_DIR}/bin/apachectl ] && [ -f $APACHE_SOURCE ]; then
/bin/rm ${APACHE_DIR}/conf 1>>/dev/null 2>>/dev/null
/bin/tar xzf $APACHE_SOURCE -C ${MNT_POINT}/opt
/bin/ln -sf ${MNT_POINT}/opt/apache ${APACHE_DIR}
/bin/sync
fi
if [ ! -d ${APACHE_CONF_DIR} ];then
/bin/rm -rf ${APACHE_CONF_DIR} 2>/dev/null
[ -d ${APACHE_DIR}/conf ] && /bin/cp -a ${APACHE_DIR}/conf ${APACHE_CONF_DIR}
fi
if [ "x${PHP_ZEND_SUPPORT}" = "xTRUE" ]; then
if [ ! -d /usr/local/apache/modules/Zend ]; then
/bin/tar xzf ${ZEND_SOURCE} -C ${MNT_POINT}/opt/apache/modules
fi
fi
if [ -d ${APACHE_CONF_DIR} ] && [ -f ${APACHE_DIR}/bin/apachectl ]; then
/usr/bin/readlink ${APACHE_DIR}/conf | grep config 1>>/dev/null 2>>/dev/null
if [ $? != 0 ] && [ -d ${APACHE_CONF_DIR} ];then
/bin/rm -rf ${APACHE_DIR}/conf
/bin/ln -sf ${APACHE_CONF_DIR} ${APACHE_DIR}/conf
fi
#remove alias of Qmultimedia
/bin/grep "Alias /Qmultimedia/" ${APACHE_CONF} 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]; then
/bin/grep -v "Alias /Qmultimedia/" ${APACHE_CONF} > ${APACHE_CONF}.tmp
/bin/cp ${APACHE_CONF}.tmp ${APACHE_CONF}
fi
#copy extra apache conf files
[ -d ${APACHE_CONF_DIR}/extra ] || /bin/mkdir ${APACHE_CONF_DIR}/extra
[ -f ${APACHE_CONF_DIR}/extra/apache-dav.conf ] || /bin/cp /etc/default_config/apache-dav.conf ${APACHE_CONF_DIR}/extra/
[ -f ${APACHE_CONF_DIR}/extra/apache-ssl.conf ] || /bin/cp /etc/default_config/apache-ssl.conf ${APACHE_CONF_DIR}/extra/
#use default apache-xxx.conf
[ -f /etc/default_config/apache-msv2.conf ] && /bin/cp /etc/default_config/apache-msv2.conf ${APACHE_CONF_DIR}/extra/
[ -f /etc/default_config/apache-musicstation.conf ] && /bin/cp /etc/default_config/apache-musicstation.conf ${APACHE_CONF_DIR}/extra/
[ -f /etc/default_config/apache-photo.conf ] && /bin/cp /etc/default_config/apache-photo.conf ${APACHE_CONF_DIR}/extra/
[ -f /etc/default_config/apache-video.conf ] && /bin/cp /etc/default_config/apache-video.conf ${APACHE_CONF_DIR}/extra/
make_php_sess_base
set_config
fi
if [ -f $APACHE_SOURCE ] && [ -d ${APACHE_CONF_DIR} ];then
if [ ! -f ${APACHE_CONF_DIR}/magic ]; then
/bin/tar xzf $APACHE_SOURCE -C /tmp apache/conf/magic
/bin/cp /tmp/apache/conf/magic ${APACHE_CONF_DIR}
/bin/rm -rf /tmp/apache
fi
/bin/grep "x-chrome-extension" ${APACHE_CONF_DIR}/mime.types 1>>/dev/null 2>>/dev/null
if [ $? != 0 ] || [ ! -f ${APACHE_CONF_DIR}/mime.types ]; then
/bin/tar xzf $APACHE_SOURCE -C /tmp apache/conf/mime.types
/bin/cp /tmp/apache/conf/mime.types ${APACHE_CONF_DIR}
/bin/rm -rf /tmp/apache
fi
fi
/sbin/httpd_init
if [ "x${CMS_ENABLE}" = xTRUE ]; then
if [ ! -d "/hd" ]; then
volume="HDA_DATA"
/usr/bin/readlink "/share/Public" 1>>/dev/null 2>>/dev/null;
if [ $? = 0 ] && [ -d "/share/Public" ]; then
volume_test=`/sbin/getcfg Public path -f /etc/smb.conf | cut -d '/' -f 3`
[ "x${volume_test}" = "x" ] || volume=${volume_test}
fi
/bin/ln -sf /share/${volume} /hd
fi
[ -d "/hd/data" ] || /bin/mkdir -p -m 700 "/hd/data"
[ -d "/hd/logs" ] || /bin/mkdir -p -m 700 "/hd/logs"
[ -d "/hd/fcgi" ] || /bin/mkdir -p -m 700 "/hd/fcgi"
/bin/chown httpdusr "/hd/fcgi"
if [ ! -d /fcgi ]; then
/bin/ln -s /hd/fcgi /fcgi
fi
[ -d "/hd/notify" ] || /bin/mkdir -p -m 700 "/hd/notify"
[ -d "/hd/backup" ] || /bin/mkdir -p -m 700 "/hd/backup"
[ -d "/hd/data/interval" ] || /bin/mkdir -p -m 700 "/hd/data/interval"
[ -d "/hd/data/profile" ] || /bin/mkdir -p -m 700 "/hd/data/profile"
[ -d "/hd/data/rule" ] || /bin/mkdir -p -m 700 "/hd/data/rule"
[ -d "/hd/data/emap" ] || /bin/mkdir -p -m 700 "/hd/data/emap"
[ -d "/hd/data/bookmark" ] || /bin/mkdir -p -m 700 "/hd/data/bookmark"
[ -d "/hd/logs/system" ] || /bin/mkdir -p -m 700 "/hd/logs/system"
[ -d "/hd/logs/event" ] || /bin/mkdir -p -m 700 "/hd/logs/event"
[ -d "/hd/logs/service" ] || /bin/mkdir -p -m 700 "/hd/logs/service"
[ -d "/hd/logs/applica" ] || /bin/mkdir -p -m 700 "/hd/logs/applica"
/bin/echo " " > /hd/logs/debug
fi
}
test -f /usr/local/sbin/Qthttpd || exit 0
[ -f ${ZEND_SOURCE} ] || /sbin/setcfg QWEB PHP_ZEND_SUPPORT FALSE -f /etc/default_config/uLinux.conf
PHP_ZEND_SUPPORT=`/sbin/getcfg QWEB PHP_ZEND_SUPPORT -d FALSE -f /etc/default_config/uLinux.conf`
[ "x${CMS_ENABLE}" = xTRUE ] && export LD_LIBRARY_PATH="/usr/local/apache/lib/apr-util-1"
case "$1" in
start)
if [ ! -z "$ramUse" ] && [ "$ramUse" = "100%" ]; then
/bin/echo "Out-of-disk-space on ramdisk"
/sbin/write_log "Out-of-disk-space on ramdisk. If restarting the server does not solve the problem please contact support for further assistance." 1
exit 1
fi
prepare_apache
echo -n "Starting Qthttpd services:"
Web_Access_Port=`/sbin/getcfg System "Web Access Port" -d 8080`
if [ `/sbin/getcfg "QWEB" "Enable" -d 1` = 0 ] && [ ${Web_Access_Port} != 80 ]; then
[ -d "/home/Qhttpd/RSS" ] || /bin/ln -sf /home/httpd/RSS /home/Qhttpd/RSS
[ -d "/home/Qhttpd/ajax_obj" ] || /bin/ln -sf /home/httpd/ajax_obj /home/Qhttpd/ajax_obj
[ ! -f /home/Qhttpd/index.html ] || /bin/sed -i 's/+\":\"+.*+/'"+\":\"+${Web_Access_Port}+"'/' /home/Qhttpd/index.html
/sbin/daemon_mgr Qthttpd start \
"/usr/local/sbin/Qthttpd -p 80 -nor -nos -u admin -d /home/Qhttpd -c '**.*'"
echo -n " Qthttpd"
touch /var/lock/subsys/Qthttpd
echo "."
else
check_qweb_link
if [ ! -d ${SSMTP_CONF_DIR} ]; then
[ ! -f ${SSMTP_CONF_DIR} ] || /bin/rm ${SSMTP_CONF_DIR}
/bin/mkdir ${SSMTP_CONF_DIR}
[ -d ${SSMTP_CONF_DEFAULT} ] && /bin/cp ${SSMTP_CONF_DEFAULT}/* ${SSMTP_CONF_DIR}
fi
# Start Apache
if [ ! -d $QWEB_FOLDER ]; then
#/sbin/write_log "Default share ${WebShare} is not found. Apache httpd start failed." 2
/bin/echo "Default share ${WebShare} is not found. Apache httpd start failed."
exit 1
fi
if [ -d ${APACHE_CONF_DIR} ] && [ -f ${APACHE_DIR}/bin/apachectl ]; then
clean_apache_log
[ $? = 0 ] || echo "Some error occurred in clean_apache_log."
if [ "x${CMS_ENABLE}" != xTRUE ]; then
/sbin/daemon_mgr Qthttpd stop /usr/local/sbin/Qthttpd
/sbin/daemon_mgr apache start "${APACHE_DIR}/bin/apachectl start 1>/dev/null 2>/dev/null </dev/null"
#${APACHE_DIR}/bin/apachectl start 1>/dev/null 2>/dev/null </dev/null
else
if [ -f /usr/local/cmsbin/cmsmsghandler ]; then
/bin/pidof cmsmsghandler 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]; then
/sbin/daemon_mgr cmsmsghandler stop "/usr/local/cmsbin/cmsmsghandler"
/bin/sleep 10
/bin/pidof cmsmsghandler 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]; then
/bin/kill -9 `/bin/pidof cmsmsghandler` >& /dev/null
/bin/sleep 10
fi
fi
fi
[ "x${PGSQL_ENABLE}" = xTRUE ] && [ -f /etc/init.d/pgsqld.sh ] && /etc/init.d/pgsqld.sh start 1>/dev/null 2>/dev/null
/bin/sleep 5
[ -f /usr/local/cmsbin/dbgtrm ] && /usr/local/cmsbin/dbgtrm 1>/dev/null 2>/dev/null &
[ -f /usr/local/cmsbin/initlog ] && /usr/local/cmsbin/initlog 1>/dev/null 2>/dev/null
[ -f /usr/local/cmsbin/configapacheldap.sh ] && /usr/local/cmsbin/configapacheldap.sh 1>/dev/null 2>/dev/null
/bin/sleep 3
/sbin/daemon_mgr apache start "${APACHE_DIR}/bin/apachectl start >& /tmp/apalog </dev/null"
/bin/sleep 3
[ -f /usr/local/cmsbin/cmsmsghandler ] && /sbin/daemon_mgr cmsmsghandler start "/usr/local/cmsbin/cmsmsghandler 1>/dev/null 2>/dev/null &"
fi
j=0
while [ $j -le 10 ]; do
/bin/pidof apache 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]; then
/bin/renice -2 `/bin/pidof apache` 1>>/dev/null 2>>/dev/null
break
fi
sleep 1
j=$(($j+1))
done
fi
fi
;;
stop)
echo -n "Shutting down Qthttpd services:"
/sbin/daemon_mgr Qthttpd stop /usr/local/sbin/Qthttpd
rm -f /var/lock/subsys/Qthttpd
echo -n " Qthttpd"
echo "."
# Stop Apache
# due to daemon_mgr only kill one process of apache.....
${APACHE_DIR}/bin/apachectl stop
/bin/sleep 1
/sbin/daemon_mgr apache stop "${APACHE_DIR}/bin/apachectl stop"
[ $? = 0 ] && echo "Apache httpd is stopped."
sleep 3
/bin/pidof apache 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]; then
/bin/kill `/bin/pidof apache`
/bin/sleep 3
/bin/pidof apache 1>>/dev/null 2>>/dev/null
[ $? != 0 ] || /bin/kill -9 `/bin/pidof apache`
fi
if [ "x${CMS_ENABLE}" = xTRUE ]; then
/bin/pidof cmsmsghandler 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]; then
/sbin/daemon_mgr cmsmsghandler stop "/usr/local/cmsbin/cmsmsghandler"
/bin/sleep 3
/bin/pidof cmsmsghandler 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]; then
/bin/kill -9 `/bin/pidof cmsmsghandler` >& /dev/null
/bin/sleep 3
fi
fi
/bin/pidof dbgtrm 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]; then
/bin/kill -9 `/bin/pidof dbgtrm` >& /dev/null
/bin/sleep 3
fi
[ "x${PGSQL_ENABLE}" = xTRUE ] && [ -f /etc/init.d/pgsqld.sh ] && /etc/init.d/pgsqld.sh stop 1>/dev/null 2>/dev/null
fi
/bin/umount ${QEACCELERATOR_TMPDIR} 1>>/dev/null 2>>/dev/null
make_php_sess_base
[ ! -d "${PHP_SESSION_PATH}" ] || /bin/rm -rf "${PHP_SESSION_PATH}"/*
#ms/ps might not exist after downgrade
if [ ! -z "$ramUse" ] && [ "$ramUse" = "100%" ]; then
/bin/echo "Out-of-disk-space on ramdisk"
/sbin/write_log "Out-of-disk-space on ramdisk. If restarting the server does not solve the problem please contact support for further assistance." 1
exit 1
fi
/bin/cp "${APACHE_CONF}" "${APACHE_CONF}.tmp"
/bin/sed -i "/^Include.*apache-msv2.conf/d" "${APACHE_CONF}.tmp" 2>/dev/null 1>/dev/null
/bin/sed -i "/^Include.*apache-musicstation.conf/d" "${APACHE_CONF}.tmp" 2>/dev/null 1>/dev/null
/bin/sed -i "/^Include.*apache-photo.conf/d" "${APACHE_CONF}.tmp" 2>/dev/null 1>/dev/null
/bin/sed -i "/^Include.*apache-video.conf/d" "${APACHE_CONF}.tmp" 2>/dev/null 1>/dev/null
[ -f /bin/awk ] && /bin/awk -F"xxxxxx" -v OFS="\n" ' $1=$1 ' ${APACHE_CONF}.tmp > ${APACHE_CONF}
;;
restart)
$0 stop
/bin/sleep 3
$0 start
;;
reload)
check_qweb_link
/bin/kill -HUP `pidof Qthttpd`
;;
*)
echo "Usage: /etc/init.d/$0 {start|stop|restart}"
exit 1
esac
exit 0

67
StartMediaService.sh Executable file
View File

@@ -0,0 +1,67 @@
#!/bin/sh
PACKAGE_PATH=/usr/local/medialibrary
export MYMEDIADB_PATH=$PACKAGE_PATH/bin
export LD_LIBRARY_PATH=$PACKAGE_PATH/lib:$LD_LIBRARY_PATH
MULTIMEDIA_PATH=`/sbin/getcfg -f /etc/config/smb.conf "Multimedia" "path"`
if [ "x${MULTIMEDIA_PATH}" = "x" ]; then
MULTIMEDIA_PATH=`/sbin/getcfg -f /etc/config/smb.conf "Qmultimedia" "path"`
fi
[ -f /etc/config/medialibrary.conf ] || /bin/touch /etc/config/medialibrary.conf
[ x`/sbin/getcfg OPTIONS INOTIFY -d x -f /etc/config/medialibrary.conf` != xx ] || /sbin/setcfg OPTIONS INOTIFY 1 -f /etc/config/medialibrary.conf
case "$1" in
start)
if [ "x${MULTIMEDIA_PATH}" = "x" ]; then
echo "I cannot find multimedia folder"
exit 0
fi
MOUNT_PATH=`dirname $MULTIMEDIA_PATH`
MULTIMEDIA_NAME=`basename $MULTIMEDIA_PATH`
[ -x $PACKAGE_PATH/bin/mymediadbserver ] || exit 1
/bin/pidof mymediadbserver >/dev/null 2>&1
[ $? != 0 ] || exit 1
if [ -f $PACKAGE_PATH/bin/PriMyDB ]; then
[ -d /tmp/.system ] || /bin/mkdir /tmp/.system
[ -f /tmp/.system/PriMyDB ] || /usr/bin/install -m 777 $PACKAGE_PATH/bin/PriMyDB /tmp/.system/
fi
$PACKAGE_PATH/bin/mymediadbserver -d >/dev/null 2>&1
sleep 2
$PACKAGE_PATH/bin/mymediadbcmd adddisk $MOUNT_PATH >/dev/null 2>&1
$PACKAGE_PATH/bin/mymediadbcmd addfolder $MOUNT_PATH $MULTIMEDIA_NAME 1 >/dev/null 2>&1
[ -f $PACKAGE_PATH/bin/InstallMusicSamples.sh ] && $PACKAGE_PATH/bin/InstallMusicSamples.sh
INOTIFY=`/sbin/getcfg OPTIONS INOTIFY -d 0 -f /etc/config/medialibrary.conf`
if [ "$INOTIFY" = "1" ]; then
$PACKAGE_PATH/bin/mymediadbcmd buildfolder $MOUNT_PATH $MULTIMEDIA_NAME >/dev/null 2>&1
fi
sleep 2
$PACKAGE_PATH/bin/myidbserver -d >/dev/null 2>&1
INOTIFY=`/sbin/getcfg OPTIONS INOTIFY -d 0 -f /etc/config/medialibrary.conf`
if [ "$INOTIFY" = "1" ]; then
$PACKAGE_PATH/bin/mymediadbcmd inotifyStart >/dev/null 2>&1
fi
CODEPAGE=`/sbin/getcfg OPTIONS CODEPAGE -d -1 -f /etc/config/medialibrary.conf`
if [ ! "$CODEPAGE" = "-1" ]; then
$PACKAGE_PATH/bin/mymediadbcmd codepage $CODEPAGE >/dev/null 2>&1
fi
;;
stop)
killall myidbserver
killall mymediadbserver
sleep 1
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/StrarMediaService.sh {start|stop|restart}"
exit 1
esac
exit 0

4
_check_nss2 Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
_NSS2_SUPPORT=yes

29
ads_register_dns.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/sh
GETCFG="/sbin/getcfg"
NET="/usr/local/samba/bin/net"
quiet="$1"
ads_register_dns() {
_ads=`${GETCFG} global security -d USER -f /etc/config/smb.conf`
if [ "x${_ads}" = "xADS" ]; then
_reg_dns=`${GETCFG} Samba "register dns" -d FALSE`
if [ "x${_reg_dns}" = "xTRUE" ]; then
try=0
while [ $try -lt 3 ]; do
${NET} ads dns register -P
if [ $? = 0 ]; then
[ "$quiet" == "" ] && /sbin/write_log "[Microsoft Networking] The NAS has been registered successfully in DNS" 4
break
fi
/bin/sleep 1
let "try++"
done
if [ $try -ge 3 ]; then
/sbin/write_log "[Microsoft Networking] The NAS registration in DNS failed" 2
fi
fi
fi
}
ads_register_dns

699
antivirus.sh Executable file
View File

@@ -0,0 +1,699 @@
#/bin/sh
ANTIVIRUS_SCRIPT="/etc/init.d/antivirus.sh"
ANTIVIRUS_CONFIG="/etc/config/antivirus.global"
ANTIVIRUS_JOBS="/etc/config/antivirus.jobs"
CLAMSCAN="/usr/local/bin/clamscan"
FRESHCLAM="/usr/local/bin/freshclam"
FRESHCLAM_CONFIG="/etc/config/freshclam.conf"
CRONTAB="/etc/config/crontab"
TEMP_CRONTAB="/tmp/crontab"
VOLUME=`/sbin/getcfg Public path -f /etc/smb.conf | cut -d '/' -f 3`
ANTIVIRUS_FOLDER="/share/$VOLUME/.antivirus"
LOG_FOLDER="$ANTIVIRUS_FOLDER/log"
QUARANTINE_CONFIG="/etc/config/antivirus.quarantine"
QUARANTINE_FOLDER="$ANTIVIRUS_FOLDER/quarantine"
UPDATE_PKG="/mnt/HDA_ROOT/update_pkg/antivirus.tgz"
TEMP="$ANTIVIRUS_FOLDER/tmp"
TMPDIR="${ANTIVIRUS_FOLDER}/.temp"
[ -d "${TMPDIR}" ] && export "TMPDIR=${TMPDIR}"
ANTIVIRUS_LIB="$ANTIVIRUS_FOLDER/usr/lib"
ANTIVIRUS_CLAMAV="$ANTIVIRUS_FOLDER/usr/share/clamav"
usage()
{
/bin/echo "Usage: $0 {start|stop|scan|stop_scan|update_db}"
}
check_config()
{
if [ ! -f $ANTIVIRUS_CONFIG ]; then
/bin/echo "[Antivirus]" > $ANTIVIRUS_CONFIG
/bin/echo " AntivirusEnable = FALSE" >> $ANTIVIRUS_CONFIG
/bin/echo " AntivirusStatus =" >> $ANTIVIRUS_CONFIG
/bin/echo " LastScan =" >> $ANTIVIRUS_CONFIG
/bin/echo " LastInfected =" >> $ANTIVIRUS_CONFIG
/bin/echo " AutoUpdateDBEnable = FALSE" >> $ANTIVIRUS_CONFIG
/bin/echo " AutoUpdateDBCheckTimes = 1" >> $ANTIVIRUS_CONFIG
/bin/echo " AutoUpdateDBTime = 0" >> $ANTIVIRUS_CONFIG
/bin/echo " ArchiveLogEnable = FALSE" >> $ANTIVIRUS_CONFIG
if [ -d "/share/$VOLUME/Qdownload" ]; then
/bin/echo " ArchiveLogPath = /Qdownload" >> $ANTIVIRUS_CONFIG
else
/bin/echo " ArchiveLogPath = /Download" >> $ANTIVIRUS_CONFIG
fi
/bin/echo " KeepLogLive = 10" >> $ANTIVIRUS_CONFIG
/bin/echo " TGZChecksum =" >> $ANTIVIRUS_CONFIG
fi
[ -f $ANTIVIRUS_JOBS ] || /bin/echo "" > $ANTIVIRUS_JOBS
}
check_env()
{
/bin/echo "DatabaseMirror database.clamav.net" > $FRESHCLAM_CONFIG
[ -f "$QUARANTINE_CONFIG" ] || /bin/echo "" > $QUARANTINE_CONFIG
/bin/mount | /bin/grep $VOLUME &> /dev/null
if [ $? -eq 0 ]; then
[ -d "$ANTIVIRUS_FOLDER" ] || /bin/mkdir -p $ANTIVIRUS_FOLDER
[ -d "$LOG_FOLDER" ] || /bin/mkdir -p $LOG_FOLDER
[ -d "$QUARANTINE_FOLDER" ] || /bin/mkdir -p $QUARANTINE_FOLDER
[ -d "${TMPDIR}" ] || /bin/mkdir -p "${TMPDIR}"
[ -d "${TMPDIR}" ] && export "TMPDIR=${TMPDIR}"
[ -d "$ANTIVIRUS_CLAMAV" ] || /bin/mkdir -p $ANTIVIRUS_CLAMAV
if [ -f $UPDATE_PKG ]; then
local tgzchecksum=`/sbin/getcfg "Antivirus" "TGZChecksum" -d "sum" -f "$ANTIVIRUS_CONFIG"`
local checksum=`/bin/md5sum $UPDATE_PKG |/bin/cut -d' ' -f 1`
if [ "$checksum" != "$tgzchecksum" ] || [ ! -d "$ANTIVIRUS_FOLDER/usr/" ] || [ ! -f /usr/lib/libclamav.so ]; then
[ ! -d "${ANTIVIRUS_LIB}" ] || /bin/rm $ANTIVIRUS_LIB/*
/bin/tar xf $UPDATE_PKG -C $ANTIVIRUS_FOLDER
/sbin/setcfg "Antivirus" "TGZChecksum" "$checksum" -f "$ANTIVIRUS_CONFIG"
fi
fi
cd ${ANTIVIRUS_LIB}
SUB_VER=`ls libclamav.so* | head -1 |tr -d '@*' | cut -d '.' -f 3-5`
/bin/rm -f /usr/share/clamav/clamav 2>/dev/null
/bin/ln -sf $ANTIVIRUS_FOLDER/usr/share/clamav /usr/share/
/bin/ln -sf $ANTIVIRUS_FOLDER/usr/lib/libclamav.so.$SUB_VER /usr/lib/libclamav.so.$SUB_VER
/bin/ln -sf /usr/lib/libclamav.so.$SUB_VER /usr/lib/libclamav.so.6
/bin/ln -sf /usr/lib/libclamav.so.$SUB_VER /usr/lib/libclamav.so
fi
/bin/touch /tmp/antivirus.lock
/bin/touch /tmp/antivirus.jobs
}
log_rename()
{
local type="$1"
local log_folder="$2"
[ "x$log_folder" = "x" -o "${log_folder:0:1}" != "/" ] && exit 1
if [ "x$type" = "xall" ]; then
/usr/bin/find "$log_folder" -type f > $TEMP
elif [ "x$type" = "xmtime" ]; then
local keep=`/sbin/getcfg "Antivirus" "KeepLogLive" -f "$ANTIVIRUS_CONFIG"`
/usr/bin/find "$log_folder" -type f -mtime +$keep > $TEMP
else
exit 1
fi
while read LINE
do
local job_name=`/sbin/getcfg "" "JobName" -f "$LINE"`
local execution_time=`/bin/echo $LINE|/bin/cut -d'/' -f 6|/bin/cut -d'-' -f 2`
local job_scan_time=`/sbin/getcfg "" "LogLastScanTime" -f "$LINE"`
local year=`/bin/echo $job_scan_time|/bin/cut -d'/' -f 1`
local month=`/bin/echo $job_scan_time|/bin/cut -d'/' -f 2`
local day=`/bin/echo $job_scan_time|/bin/cut -d'/' -f 3|/bin/cut -d' ' -f 1`
/bin/sed 's/^\/share\//\//g' "$LINE" > "$log_folder"/Antivirus_"$job_name"_"$execution_time"_"$year"_"$month"_"$day".log
done < $TEMP
/bin/rm -f $TEMP
}
archive_log()
{
local enable="$1"
if [ "x$enable" != "x" ]; then
/bin/cat $CRONTAB | /bin/grep -v "archive_log" > "$TEMP_CRONTAB"
/bin/mv $TEMP_CRONTAB $CRONTAB
if [ $(($enable)) -eq 1 ]; then
/bin/echo "0 0 * * * $ANTIVIRUS_SCRIPT archive_log" >> $CRONTAB
fi
/usr/bin/crontab $CRONTAB
else
local share=`/sbin/getcfg "Antivirus" "ArchiveLogPath" -f "$ANTIVIRUS_CONFIG"`
local keep=`/sbin/getcfg "Antivirus" "KeepLogLive" -f "$ANTIVIRUS_CONFIG"`
for i in `/bin/mount |/bin/grep _DATA |/bin/cut -d ' ' -f 3|/usr/bin/xargs /bin/echo -n`
do
if [ -d "$i$share" ]; then
local enable=`/sbin/getcfg "Antivirus" "ArchiveLogEnable" -f "$ANTIVIRUS_CONFIG"`
if [ "$enable" = "TRUE" ]; then
log_rename "mtime" "$LOG_FOLDER" &> /dev/null
cd $LOG_FOLDER && /usr/local/sbin/zip "$i$share/Antivirus_logs_`date +"%Y_%m_%d"`.zip" Antivirus_* 2> /dev/null && cd -
fi
cd $LOG_FOLDER && /bin/rm -f Antivirus_* && /usr/bin/find . -type f -mtime +$keep | /usr/bin/xargs /bin/rm -f 2> /dev/null && cd -
break
fi
done
fi
}
restart_crond()
{
[ ! -f "$CRONTAB" ] && /bin/echo "$CRONTAB is not exit." && exit 0
/bin/cat $CRONTAB | /bin/grep -v "antivirus.sh scan" > "$TEMP_CRONTAB"
/bin/mv $TEMP_CRONTAB $CRONTAB
local i=0
while read LINE
do
local session_id=`/bin/echo $LINE |/bin/grep '\['|/bin/cut -d'[' -f2|/bin/cut -d']' -f1`
[ "x$session_id" = "x" ] && continue
local job_id=`/bin/echo $session_id |/bin/cut -d' ' -f2`
# initial LogLastScanTime
/sbin/setcfg "Antivirus" "AntivirusStatus" "" -f "$ANTIVIRUS_CONFIG"
local scan_time=`/sbin/getcfg "Job $job_id" "LogLastScanTime" -d "" -f "$ANTIVIRUS_JOBS"`
if [ "x$scan_time" = "xIn progress" ]; then
/sbin/setcfg "Job $job_id" "JobStatus" "2" -f "$ANTIVIRUS_JOBS"
/sbin/setcfg "Job $job_id" "LogLastScanTime" "" -f "$ANTIVIRUS_JOBS"
fi
local schedule=`/sbin/getcfg "$session_id" "JobSchedule" -f "$ANTIVIRUS_JOBS"`
if [ "$schedule" = "now" ]; then
/bin/echo ""
elif [ "$schedule" = "interval" ]; then
local interval=`/sbin/getcfg "$session_id" "JobScheduleInterval" -f "$ANTIVIRUS_JOBS"`
local num=`/bin/echo $interval|/bin/cut -d',' -f 1`
local unit=`/bin/echo $interval|/bin/cut -d',' -f 2`
if [ "$unit" = "m" ]; then
/bin/echo "*/$num * * * * $ANTIVIRUS_SCRIPT scan $job_id" >> $CRONTAB
elif [ "$unit" = "h" ]; then
/bin/echo "0 */$num * * * $ANTIVIRUS_SCRIPT scan $job_id" >> $CRONTAB
elif [ "$unit" = "d" ]; then
/bin/echo "0 0 */$num * * $ANTIVIRUS_SCRIPT scan $job_id" >> $CRONTAB
else
/bin/echo "No such interval." && exit 1
fi
elif [ "$schedule" = "daily" ]; then
local daily=`/sbin/getcfg "$session_id" "JobScheduleDaily" -f "$ANTIVIRUS_JOBS"`
local hour=`/bin/echo $daily|/bin/cut -d',' -f 1`
local minute=`/bin/echo $daily|/bin/cut -d',' -f 2`
/bin/echo "$minute $hour * * * $ANTIVIRUS_SCRIPT scan $job_id" >> $CRONTAB
elif [ "$schedule" = "weekly" ]; then
local weekly=`/sbin/getcfg "$session_id" "JobScheduleWeekly" -f "$ANTIVIRUS_JOBS"`
local hour=`/bin/echo $weekly|/bin/cut -d',' -f 1`
local minute=`/bin/echo $weekly|/bin/cut -d',' -f 2`
local week=`/bin/echo $weekly|/bin/cut -d',' -f 3`
/bin/echo "$minute $hour * * $week $ANTIVIRUS_SCRIPT scan $job_id" >> $CRONTAB
else
/bin/echo "No such schedule type." && return
fi
i=$(($i + 1))
done < $ANTIVIRUS_JOBS
[ $i -ge 0 ] && /usr/bin/crontab $CRONTAB
}
stop_crond()
{
[ ! -f "$CRONTAB" ] && /bin/echo "$CRONTAB is not exit." && exit 0
/bin/cat $CRONTAB | /bin/grep -v "antivirus.sh" > "$TEMP_CRONTAB"
/bin/mv $TEMP_CRONTAB $CRONTAB
/usr/bin/crontab $CRONTAB
}
start()
{
check_config
check_env
local enable=`/sbin/getcfg "Antivirus" "AntivirusEnable" -d "FALSE" -f "$ANTIVIRUS_CONFIG"`
[ "x$enable" != "xTRUE" ] && exit 0
restart_crond
archive_log 1
local in_days=`/sbin/getcfg "Antivirus" "AutoUpdateDBCheckTimes" -f "$ANTIVIRUS_CONFIG"`
update_db $in_days &> /dev/null
#20411 check auto update DB after reboot
local last_update=`/sbin/getcfg "Antivirus" "AutoUpdateDBTime" -f "$ANTIVIRUS_CONFIG"`
[ "x$last_update" = "x" ] && last_update=0
local now_time=`date +%s`
local _enable=`/sbin/getcfg "Antivirus" "AutoUpdateDBEnable" -f "$ANTIVIRUS_CONFIG"`
if [ ! -f ${ANTIVIRUS_CLAMAV}/main.cld ] || [ o"$_enable" = oTRUE ]; then
[ $(($now_time-$last_update)) -ge $(($in_days*24*60*60)) ] && update_db &> /dev/null
fi
}
stop()
{
archive_log 0
stop_crond
i=1
while [ $i -le 64 ]; do
stop_scan $i
i=$(($i+1))
[ x`pidof clamscan` != x ] || break
done
/sbin/setcfg "Antivirus" "AntivirusStatus" "" -f "$ANTIVIRUS_CONFIG"
}
set_quarantine_conf()
{
local job_id="$1"
local job_execution_times="$2"
local logfile="$LOG_FOLDER/log.$job_id-$job_execution_times"
local action=`/sbin/getcfg "Job $job_id" "JobAction" -f "$ANTIVIRUS_JOBS"`
[ ! -f $logfile ] && /bin/echo "No such file \"$1\"." && exit 1
local job_name=`/sbin/getcfg "" "JobName" -d "" -f "$logfile"`
/sbin/setcfg "Infected-$job_id.$job_execution_times" "JobName" "$job_name" -f "$QUARANTINE_CONFIG"
local i=1
while read LINE
do
[ "x$LINE" = "x" ] && continue
#echo "LINE [$LINE]"
local file=`/bin/echo -n $LINE|/bin/grep FOUND|/bin/cut -d':' -f 1`
local virus=`/bin/echo -n $LINE|/bin/grep FOUND|/bin/cut -d':' -f 2|/bin/cut -d' ' -f 2`
#echo "logfile [$logfile] LINE [$LINE] file [$file] virus [$virus] i [$i]"
[ ! -f "$file" ] && continue
[ "x$virus" = "x" ] && continue
if [ $(($action)) -eq 1 ]; then
local volume=`/bin/echo $file|/bin/cut -d '/' -f 3`
local folder="/share/$volume"
#check iso mount and ignore
/bin/df|/bin/grep "/dev/loop"|/bin/grep "/share/$VOLUME/$volume" &> /dev/null
[ $? -eq 0 ] && continue
local path=`/usr/bin/readlink "/share/$volume"`
if [ $? -ne 0 ]; then
#FIXME:quarantined into default volume
local quarantine_folder="/share/$VOLUME/.antivirus/quarantine"
elif [ "${file:0:14}" = "/share/USBDisk" -o "${file:0:16}" = "/share/eSATADisk" ]; then
local quarantine_folder="/share/$path/.antivirus/quarantine"
else
local quarantine_folder="/share/${path:0:$((${#path}-${#volume}-1))}/.antivirus/quarantine"
fi
# bug [19603]: It should be renamed if there is the same path and filename in quarantine
local ofile="$file"
local num=1
while [ 1 ]; do
[ ! -f "$quarantine_folder/$ofile" ] && break
ofile="$file($num)"
num=$(($num+1))
done
mv $file $ofile &> /dev/null
file="$ofile"
[ ! -d $quarantine_folder ] && /bin/mkdir -p $quarantine_folder
/bin/tar cf - "$file" | /bin/tar xf - -C "$quarantine_folder" &> /dev/null
/bin/rm -f "$file"
/sbin/setcfg "Infected-$job_id.$job_execution_times" "InfectedFile$i" "$file" -f "$QUARANTINE_CONFIG"
/sbin/setcfg "Infected-$job_id.$job_execution_times" "InfectedVirus$i" "$virus" -f "$QUARANTINE_CONFIG"
fi
i=$(($i+1))
done < $logfile
[ $(($i-1)) -ne 0 ] && /sbin/write_log "[Antivirus] Virus Found by the scan job $job_name." 2
/sbin/setcfg "Infected-$job_id.$job_execution_times" "InfectedFileNum" "$(($i-1))" -f "$QUARANTINE_CONFIG"
}
send_antivirus_alert_mail()
{
local type="$1"
local job_id="$2"
local job_execution_times="$3"
local logfile="$LOG_FOLDER/log.$job_id-$job_execution_times"
local hostname=`/bin/hostname`
local ip=`/bin/ls /sys/class/net/|/bin/sed -e 's/\//g' 2>/dev/null|/usr/bin/xargs /sbin/ifconfig |/bin/grep "inet addr"|/bin/cut -d: -f 2|/bin/cut -d ' ' -f 1|/bin/grep -v 127.0.0.1|/usr/bin/xargs echo -n`
local job_name=`/sbin/getcfg "Job $job_id" "JobName" -f "$ANTIVIRUS_JOBS"`
local start_time=`/sbin/getcfg "Job $job_id" "LogLastScanTime" -f "$ANTIVIRUS_JOBS"`
local duration=`/bin/cat $logfile|/bin/grep "Time:"|/bin/cut -d '(' -f 2|/bin/cut -d ')' -f 1`
local virus=`/bin/cat $logfile|/bin/grep "Infected files:"|/bin/cut -d ' ' -f 3`
local action=`/sbin/getcfg "Job $job_id" "JobAction" -f "$ANTIVIRUS_JOBS"`
local http_port=`/sbin/getcfg "System" "Web Access Port" -d "8080"`
local https_port=`/sbin/getcfg "Stunnel" "Port" -d "443"`
[ $(($action)) -eq 0 ] && action="nothing"
[ $(($action)) -eq 1 ] && action="quarantine"
[ $(($action)) -eq 2 ] && action="delete"
local message="NAS hostname :$hostname \nNAS IP : $ip \nScan Job : $job_name \nStart Date: $start_time\nDuration : $duration \nVirus found : $virus \nDefault action : $action \n\nAdminstration interface:"
for i in $ip
do
message="$message \nNormal:http://$i:$http_port"
done
for i in $ip
do
if [ "$https_port" = "443" ]; then
message="$message \nSecure:https://$i"
else
message="$message \nSecure:https://$i:$https_port"
fi
done
if [ "$type" = "alert" ]; then
local object="Antivirus report from $hostname for $job_name"
message=`/bin/echo -e $message`
elif [ "$type" = "virus" ]; then
local object="Antivirus report from $hostname for $job_name - $virus virus found"
local files=`/bin/cat $logfile|/bin/grep FOUND|/bin/cut -d':' -f 1|sed -e 's/^\/share//g'|sed -e 's/_DATA/#/g'|cut -d# -f2`
# if message is bigger than 128Kb, alert mail can't send
if [ ${#files} -gt 131072 ]; then
files="`/bin/cat $logfile|/bin/grep FOUND|/bin/cut -d':' -f 1|sed -e 's/_DATA/#/g'|cut -d# -f2|/usr/bin/head -n 10` `/bin/echo -e "\n...\n\nPlease check the report for the complete file list.\n"`"
fi
message="$message \n\nInfected files:\n"
message="`/bin/echo -e $message` $files"
fi
local level="Warning"
/sbin/send_antivirus_alert_mail "$object" "$message" "$level"
}
scan()
{
#check antivirus jobs exist
[ ! -f "$ANTIVIRUS_JOBS" ] && /bin/echo "$ANTIVIRUS_JOBS is not exit." && exit 0
local job_id="$1"
[ "$job_id" = "" ] && usage && exit 0
local status=`/sbin/getcfg "Job $job_id" "JobStatus" -f "$ANTIVIRUS_JOBS"`
[ "$status" != "0" -a "$status" != "2" ] && /bin/echo "Job $job_id is running." && exit 1
/sbin/setcfg "Job $job_id" "LogLastScanTime" "In progress" -f "$ANTIVIRUS_JOBS"
/sbin/setcfg "Job $job_id" "LogLastSpendTime" "" -f "$ANTIVIRUS_JOBS"
/sbin/setcfg "Job $job_id" "LogLastInfected" "0" -f "$ANTIVIRUS_JOBS"
#only show infected file info and scan recursive
local OPTIONS="-i -r"
local scan_all_dirs=`/sbin/getcfg "Job $job_id" "JobScanAllDirs" -f "$ANTIVIRUS_JOBS"`
if [ "$scan_all_dirs" = "1" ]; then
/usr/bin/find /share/ -type l > $TEMP
while read LINE
do
local tmp=`/bin/echo $LINE|/bin/cut -d '/' -f 4`
[ ${#tmp} -gt 0 ] && continue
[ -L "$LINE" ] && OPTIONS="$OPTIONS \"$LINE/\""
done < $TEMP
/bin/rm -f $TEMP
elif [ "$scan_all_dirs" = "0" ]; then
local scan_dirs=`/sbin/getcfg "Job $job_id" "JobScanDirs" -f "$ANTIVIRUS_JOBS"`
if [ "x$scan_dirs" != "x" ]; then
local i=1
while [ 1 ]; do
local dirs=`/bin/echo $scan_dirs|/bin/cut -d ';' -f $i`
[ "x$dirs" = "x" ] && break
[ $i -ge 2 -a "$dirs" = "$scan_dirs" ] && break
[ -d "/share$dirs" ] && OPTIONS="$OPTIONS \"/share$dirs\""
i=$(($i+1))
done
fi
fi
local include_all_files=`/sbin/getcfg "Job $job_id" "JobIncludeAllFiles" -f "$ANTIVIRUS_JOBS"`
local get_session=0
local include_files=""
while read LINE
do
[ "$LINE" = "[Job $job_id]" ] && get_session=1
if [ $get_session -eq 1 ]; then
include_files=`/bin/echo $LINE |/bin/cut -d ' ' -f 1`
[ "$include_files" = "JobIncludeFiles" ] && include_files=`/bin/echo $LINE |/bin/cut -d ' ' -f 3` && break
fi
done < $ANTIVIRUS_JOBS
include_files="$include_files;"
if [ "$include_all_files" = "0" -a "x$include_files" != "x" ]; then
local i=1
while [ 1 ]; do
local files=`/bin/echo $include_files|/bin/cut -d ';' -f $i`
[ "x$files" = "x" ] && break
[ $i -ge 2 -a "$files" = "$include_files" ] && break
if [ "${files:0:1}" = "*" -o "${files:0:1}" = "?" ]; then
OPTIONS="$OPTIONS --include=.$files"
else
OPTIONS="$OPTIONS --include=$files"
fi
i=$(($i+1))
done
fi
#exclude quarantined directory
[ -d $ANTIVIRUS_FOLDER ] && OPTIONS="$OPTIONS --exclude=\".antivirus\""
local enable_exclude=`/sbin/getcfg "Job $job_id" "JobExcludeEnable" -f "$ANTIVIRUS_JOBS"`
if [ "$enable_exclude" = "1" ]; then
get_session=0
local exclude_files=""
while read LINE
do
[ "$LINE" = "[Job $job_id]" ] && get_session=1
if [ $get_session -eq 1 ]; then
exclude_files=`/bin/echo $LINE |/bin/cut -d ' ' -f 1`
[ "$exclude_files" = "JobExcludeFilesDirs" ] && exclude_files=`/bin/echo $LINE |/bin/cut -c 23-` && break
fi
done < $ANTIVIRUS_JOBS
exclude_files="$exclude_files;"
if [ "x$exclude_files" != "x" ]; then
i=1
while [ 1 ]; do
local files=`/bin/echo $exclude_files|/bin/cut -d ';' -f $i`
[ "x$files" = "x" ] && break
files="/share$files"
if [ -d "$files" ]; then
files=$(/bin/echo $files|/bin/sed 's/+/\\+/g')
OPTIONS="$OPTIONS --exclude-dir=\"$files\""
else
files=$(/bin/echo $files|/bin/sed 's/+/\\+/g')
files=$(/bin/echo $files|/bin/sed 's/*/.*/g')
files=$(/bin/echo $files|/bin/sed 's/?/.?/g')
OPTIONS="$OPTIONS --exclude=\"$files\""
fi
i=$(($i+1))
done
fi
fi
local max_file_size_enable=`/sbin/getcfg "Job $job_id" "JobMaxFileSizeEnable" -f "$ANTIVIRUS_JOBS"`
if [ $(($max_file_size_enable)) -eq 1 ]; then
local max_file_size=`/sbin/getcfg "Job $job_id" "JobMaxFileSize" -f "$ANTIVIRUS_JOBS"`
[ $(($max_file_size)) -ge 1 -a $(($max_file_size)) -le 4096 ] && OPTIONS="$OPTIONS --max-filesize=$(($max_file_size))M"
else
OPTIONS="$OPTIONS --max-filesize=0"
fi
local max_scan_size_enable=`/sbin/getcfg "Job $job_id" "JobMaxScanSizeEnable" -f "$ANTIVIRUS_JOBS"`
if [ $(($max_scan_size_enable)) -eq 1 ]; then
local max_scan_size=`/sbin/getcfg "Job $job_id" "JobMaxScanSize" -f "$ANTIVIRUS_JOBS"`
[ $(($max_scan_size)) -ge 1 -a $(($max_scan_size)) -le 4096 ] && OPTIONS="$OPTIONS --max-scansize=$(($max_scan_size))M"
else
OPTIONS="$OPTIONS --max-scansize=0"
fi
local scan_compress_file=`/sbin/getcfg "Job $job_id" "JobScanCompressFile" -f "$ANTIVIRUS_JOBS"`
[ "$scan_compress_file" = "0" ] && OPTIONS="$OPTIONS --scan-archive=no --scan-elf=no --scan-pe=no"
local scan_document_file=`/sbin/getcfg "Job $job_id" "JobScanDocumentFile" -f "$ANTIVIRUS_JOBS"`
[ "$scan_document_file" = "0" ] && OPTIONS="$OPTIONS --scan-ole2=no --scan-html=no --scan-pdf=no"
local scan_mail_file=`/sbin/getcfg "Job $job_id" "JobScanMailFile" -f "$ANTIVIRUS_JOBS"`
[ "$scan_mail_file" = "0" ] && OPTIONS="$OPTIONS --scan-mail=no"
local action=`/sbin/getcfg "Job $job_id" "JobAction" -f "$ANTIVIRUS_JOBS"`
#if [ $(($action)) -eq 1 ]; then
# OPTIONS="$OPTIONS --move=$QUARANTINE_FOLDER"
#elif [ $(($action)) -eq 2 ]; then
if [ $(($action)) -eq 2 ]; then
OPTIONS="$OPTIONS --remove"
fi
#log file and execution times
local job_execution_times=`/sbin/getcfg "Job $job_id" "JobExecutionTimes" -f "$ANTIVIRUS_JOBS"`
job_execution_times=$(($job_execution_times + 1))
/sbin/setcfg "Job $job_id" "JobExecutionTimes" "$job_execution_times" -f "$ANTIVIRUS_JOBS"
[ -f "$LOG_FOLDER/log.$job_id-$job_execution_times" ] && rm -f $LOG_FOLDER/log.$job_id-$job_execution_times
[ $(($job_execution_times)) -gt 0 ] && OPTIONS="$OPTIONS --log=$LOG_FOLDER/log.$job_id-$job_execution_times"
#set job status "run"
/sbin/setcfg "Job $job_id" "JobStatus" "1" -f "$ANTIVIRUS_JOBS"
[ $? -ne 0 ] && /bin/echo "set job status \"run\" fail." && exit 0
# set antivirus status scanning
/sbin/setcfg "Antivirus" "AntivirusStatus" "0" -f "$ANTIVIRUS_CONFIG"
local job_name=`/sbin/getcfg "Job $job_id" "JobName" -f "$ANTIVIRUS_JOBS"`
/sbin/write_log "[Antivirus] Scan job $job_name started." 4
/bin/echo "JobName = $job_name" >> $LOG_FOLDER/log.$job_id-$job_execution_times
local finish_time=`date +"%Y/%m/%d %H:%M:%S"`
/bin/echo "LogLastScanTime = $finish_time" >> $LOG_FOLDER/log.$job_id-$job_execution_times
#echo "$CLAMSCAN $OPTIONS"
/bin/sh -c "$CLAMSCAN $OPTIONS &> /dev/null"
#[ $(($action)) -eq 1 ] && set_quarantine_conf $job_id $job_execution_times
set_quarantine_conf $job_id $job_execution_times
# convert into doc format
/sbin/unix2dos -d $LOG_FOLDER/log.$job_id-$job_execution_times
/sbin/setcfg "Job $job_id" "JobStatus" "0" -f "$ANTIVIRUS_JOBS"
# set antivirus status scan complete
[ "`/bin/pidof clamscan`" = "" ] && /sbin/setcfg "Antivirus" "AntivirusStatus" "1" -f "$ANTIVIRUS_CONFIG"
/sbin/setcfg "Antivirus" "LastScan" "$finish_time" -f "$ANTIVIRUS_CONFIG"
/sbin/setcfg "Job $job_id" "LogLastScanTime" "$finish_time" -f "$ANTIVIRUS_JOBS"
local last_spend_time=`/bin/cat $LOG_FOLDER/log.$job_id-$job_execution_times | /bin/grep "Time: "|/bin/cut -d':' -f 2|/bin/cut -d'.' -f 1`
/sbin/setcfg "Job $job_id" "LogLastSpendTime" "$last_spend_time" -f "$ANTIVIRUS_JOBS"
local last_infected=`/bin/cat $LOG_FOLDER/log.$job_id-$job_execution_times | /bin/grep "Infected files: "|/bin/cut -d':' -f 2`
/sbin/setcfg "Job $job_id" "LogLastInfected" "$last_infected" -f "$ANTIVIRUS_JOBS"
/bin/cat $LOG_FOLDER/log.$job_id-$job_execution_times | /bin/grep FOUND &> /dev/null
if [ $? -eq 0 ]; then
/sbin/setcfg "Antivirus" "LastInfected" "$finish_time" -f "$ANTIVIRUS_CONFIG"
local infected_mail=`/sbin/getcfg "Job $job_id" "JobInfectedMailEnable" -f "$ANTIVIRUS_JOBS"`
[ $(($infected_mail)) -eq 1 ] && send_antivirus_alert_mail virus "$job_id" "$job_execution_times"
fi
local everytime_mail=`/sbin/getcfg "Job $job_id" "JobEndScanMailEnable" -f "$ANTIVIRUS_JOBS"`
[ $(($everytime_mail)) -eq 1 ] && send_antivirus_alert_mail alert "$job_id" "$job_execution_times"
/sbin/write_log "[Antivirus] Scan job $job_name completed." 4
}
stop_scan()
{
#check antivirus jobs exist
[ ! -f "$ANTIVIRUS_JOBS" ] && /bin/echo "$ANTIVIRUS_JOBS is not exit." && return 0
local job_id="$1"
local status=`/sbin/getcfg "Job $job_id" "JobStatus" -f "$ANTIVIRUS_JOBS"`
[ "$status" != "1" ] && /bin/echo "Job $job_id is not running." && return 1
local job_execution_times=`/sbin/getcfg "Job $job_id" "JobExecutionTimes" -f "$ANTIVIRUS_JOBS"`
/bin/echo "Time: stopped" >> $LOG_FOLDER/log.$job_id-$job_execution_times
/bin/ps | /bin/grep "$ANTIVIRUS_SCRIPT scan $job_id"| /bin/cut -d'a' -f 1| /bin/sed 's/\ //g'| /usr/bin/xargs kill
for i in `/bin/pidof clamscan`
do
/bin/cat /proc/$i/cmdline | /bin/grep "log.$job_id-$job_execution_times"
[ $? -eq 0 ] && /bin/kill -9 $i &> /dev/null
done
#set job status "stop"
/sbin/setcfg "Job $job_id" "JobStatus" "2" -f "$ANTIVIRUS_JOBS"
# set antivirus status scan stopped
[ "`/bin/pidof clamscan`" = "" ] && /sbin/setcfg "Antivirus" "AntivirusStatus" "2" -f "$ANTIVIRUS_CONFIG"
/sbin/setcfg "Antivirus" "LastScan" "`date +%Y/%m/%d\" \"%k:%M:%S`" -f "$ANTIVIRUS_CONFIG"
/sbin/setcfg "Job $job_id" "LogLastScanTime" "`date +%Y/%m/%d\" \"%k:%M:%S`" -f "$ANTIVIRUS_JOBS"
/sbin/setcfg "Job $job_id" "LogLastSpendTime" "stopped" -f "$ANTIVIRUS_JOBS"
local job_name=`/sbin/getcfg "Job $job_id" "JobName" -f "$ANTIVIRUS_JOBS"`
/sbin/write_log "[Antivirus] Scan job $job_name stopped by user." 4
}
update_db()
{
[ ! -f "$FRESHCLAM_CONFIG" ] && /bin/echo "$FRESHCLAM_CONFIG is not exit." && exit 0
local update_lock="/tmp/FRESHCLAM_CONFIG.lock"
local TMP_FRESHCLAM_CONFIG="/tmp/FRESHCLAM_CONFIG.tmp"
if [ -f $update_lock ]; then
/bin/rm -f $update_lock
/bin/echo "$FRESHCLAM_CONFIG is locked"
exit 0
else
/bin/touch $update_lock
fi
/bin/sed -e "s/HTTPProxyServer.*//g" -e "s/HTTPProxyPort.*//g" -e "s/HTTPProxyUsername.*//g" -e "s/HTTPProxyPassword.*//g" -e "/^$/d" $FRESHCLAM_CONFIG > $TMP_FRESHCLAM_CONFIG
# check proxy setting
local proxy_server=`/sbin/getcfg "System" "proxy server" -d ""`
if [ "$proxy_server" != "" ]; then
local HTTPProxyServer=${proxy_server%:*}
local HTTPProxyPort=${proxy_server##*:}
/bin/echo "HTTPProxyServer $HTTPProxyServer" >> $TMP_FRESHCLAM_CONFIG
/bin/echo "HTTPProxyPort $HTTPProxyPort" >> $TMP_FRESHCLAM_CONFIG
local proxy_user=`/sbin/getcfg "System" "proxy username" -d ""`
local proxy_password=`/sbin/getcfg "System" "proxy password" -d ""`
if [ "$proxy_user" != "" ]; then
/bin/echo "HTTPProxyUsername \"$proxy_user\"" >> $TMP_FRESHCLAM_CONFIG
/bin/echo "HTTPProxyPassword \"$proxy_password\"" >> $TMP_FRESHCLAM_CONFIG
fi
fi
/bin/cp $TMP_FRESHCLAM_CONFIG $FRESHCLAM_CONFIG
/bin/rm -f $TMP_FRESHCLAM_CONFIG
/bin/rm -f $update_lock
/bin/chmod 700 $FRESHCLAM_CONFIG
local in_days="$1"
if [ "x$in_days" != "x" ]; then
/bin/cat $CRONTAB | /bin/grep -v "update_db" > "$TEMP_CRONTAB"
/bin/mv $TEMP_CRONTAB $CRONTAB
local enable=`/sbin/getcfg "Antivirus" "AutoUpdateDBEnable" -f "$ANTIVIRUS_CONFIG"`
if [ "$enable" = "TRUE" -a $(($in_days)) -ge 1 -a $(($in_days)) -le 999 ]; then
/bin/echo "0 0 */$in_days * * $ANTIVIRUS_SCRIPT update_db" >> $CRONTAB
fi
/usr/bin/crontab $CRONTAB
else
#check clamav.net
/sbin/curl --connect-timeout 10 -I clamav.net 1>>/dev/null 2>>/dev/null
if [ $? != 0 ]; then
/sbin/setcfg "Antivirus" "AntivirusStatus" "5" -f "$ANTIVIRUS_CONFIG"
/sbin/write_log "[Antivirus] Failed to update virus definition." 2
return 1
fi
# set antivirus status updating
/sbin/setcfg "Antivirus" "AntivirusStatus" "3" -f "$ANTIVIRUS_CONFIG"
$FRESHCLAM -u admin -l /tmp/.freshclam.log 2>/dev/null
if [ $? = "0" ]; then
# set antivirus status update complete
/sbin/setcfg "Antivirus" "AntivirusStatus" "4" -f "$ANTIVIRUS_CONFIG"
/bin/grep "Database updated" /tmp/.freshclam.log 1>>/dev/null 2>>/dev/null
[ $? = 0 ] && /sbin/write_log "[Antivirus] Virus definition updated." 4
[ ! -f /tmp/.freshclam.log ] || /bin/rm -f /tmp/.freshclam.log
local now_time=`date +%s`
/sbin/setcfg "Antivirus" "AutoUpdateDBTime" "$now_time" -f "$ANTIVIRUS_CONFIG"
return 0
else
# set antivirus status update fail
/sbin/setcfg "Antivirus" "AntivirusStatus" "5" -f "$ANTIVIRUS_CONFIG"
/sbin/write_log "[Antivirus] Failed to update virus definition." 2
return 1
fi
fi
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
scan)
scan $2
;;
stop_scan)
stop_scan $2
;;
update_db)
update_db $2
[ $? = 0 ] || exit 1
;;
set_q)
set_quarantine_conf $2 $3
;;
restart_crond)
restart_crond
;;
archive_log)
archive_log $2
;;
send_mail)
send_antivirus_alert_mail $2 $3 $4
;;
init)
check_config
;;
log_rename)
log_rename $2 $3
;;
*)
usage
exit 1
esac
exit 0

99
atalk.sh Executable file
View File

@@ -0,0 +1,99 @@
#!/bin/sh
# chkconfig: - 91 35
# description: This package enables Linux to talk to Macintosh computers via the \
# AppleTalk networking protocol. It includes a daemon to allow Linux \
# to act as a file server over EtherTalk or IP for Mac's.
# processname: atalkd
# pidfile: /var/run/atalkd.pid
# config: /usr/local/etc/metatalk/*
ATALK_PATH=/usr/local/etc/netatalk
ZONE=`/sbin/getcfg Appletalk "Default Zone" -d "*"`
BOND_SUP=`/sbin/getcfg "Network" "BONDING Support" -d "FALSE"`
if [ "$BOND_SUP" = "TRUE" ]; then
DEV="bond0"
else
DEV="eth0"
fi
/bin/echo $DEV -zone "$ZONE" > $ATALK_PATH/atalkd.conf
# Source function library.
#. /etc/init.d/functions
# Source networking configuration.
#. /etc/sysconfig/network
# Source Appletalk configuration
. ${ATALK_PATH}/netatalk.conf
# Check that networking is up.
#[ ${NETWORKING} = "no" ] && exit 0
start() {
if [ `/sbin/getcfg Appletalk Enable -u -d TRUE` = FALSE ]
then
echo "Starting AppleTalk Services: disabled."
exit 0
fi
#if [ `/sbin/getcfg Appletalk Version -d 0` != 2.1 ]
#then
# /sbin/_remove
# /sbin/setcfg Appletalk Version "2.1"
#fi
quota=`/sbin/getcfg TimeMachine Size -d 0 -f /etc/config/usr_quota.conf 2>/dev/null`
if [ "$quota" != "0" ]; then
/sbin/setcfg TimeMachine Size 0 -f /etc/config/usr_quota.conf > /dev/null 2>&1
TMUID=`/bin/grep ^TimeMachine: /etc/passwd | /bin/awk -F ':' '{printf $3}'`
QFMT=`/sbin/getcfg System "Quota Type" -d vfsold`
if [ "$TMUID" != "" ]; then
/sbin/setquota -u -F $QFMT $TMUID 0 0 0 0 -a > /dev/null 2>&1
fi
fi
/sbin/mkafpconf > /dev/null 2>&1
echo -n "Starting AppleTalk services: "
/sbin/daemon_mgr afpd start "/usr/local/sbin/afpd -F /etc/afp.conf -p /var/afpd3.pid"
}
stop() {
echo -n "Shutting down AppleTalk services: "
/sbin/daemon_mgr afpd stop /usr/local/sbin/afpd
/bin/sleep 1
/bin/pidof afpd 1>>/dev/null 2>>/dev/null
[ $? != 0 ] || /bin/kill -TERM `/bin/pidof afpd`
echo ""
}
restart() {
stop
start
}
reload()
{
[ -f /var/afpd3.pid ] && kill -HUP `cat /var/afpd3.pid 2>/dev/null`
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
[ -f /var/afpd3.pid ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart}"
exit 1
esac
exit 0

525
avahi.sh Executable file
View File

@@ -0,0 +1,525 @@
#!/bin/sh
AVAHI_SRC=/mnt/ext/opt/avahi0630
DBUS_DAEMON=/usr/sbin/dbus-daemon
AVAHI_DAEMON=/usr/sbin/avahi-daemon
AVAHI_CONF_DIR=/etc/avahi/services
AVAHI_TM_CONF_FILE=${AVAHI_CONF_DIR}/timemachine.service
MYCLOUDNAS_CONF="/etc/config/qnapddns.conf"
Project_Name=`/sbin/getcfg Project Name -f /var/default`
/sbin/test -f ${AVAHI_DAEMON} || exit 0
set_avahi_conf()
{
/bin/rm -rf ${AVAHI_CONF_DIR}/web.service \
${AVAHI_CONF_DIR}/samba.service \
${AVAHI_CONF_DIR}/afp.service \
${AVAHI_CONF_DIR}/ssh.service \
${AVAHI_CONF_DIR}/sftp-ssh.service \
${AVAHI_CONF_DIR}/https.service \
${AVAHI_CONF_DIR}/upnp.service \
${AVAHI_CONF_DIR}/itunes.service \
${AVAHI_CONF_DIR}/printer.service \
${AVAHI_CONF_DIR}/qmobile.service \
${AVAHI_CONF_DIR}/qdiscover.service \
${AVAHI_CONF_DIR}/csco.service \
${AVAHI_CONF_DIR}/ftp.service >&/dev/null
MAC_ADDR=`/sbin/getcfg "MAC" "eth0" -f "/var/MacAddress" | /bin/tr '[a-z]' '[A-Z]'`
WEB_PORT=`/sbin/getcfg System "Web Access Port" -d 8080`
HTTPS_PORT=`/sbin/getcfg "Stunnel" "Port" -d "443"`
HOSTNAME=`/sbin/getcfg System "Server Name"`
MYCLOUDNAS_NAME=`/sbin/getcfg "QNAP DDNS Service" "Host Name" -f "${MYCLOUDNAS_CONF}"`
MYCLOUDNAS_DN=`/sbin/getcfg "QNAP DDNS Service" "Domain Name Server" -f "${MYCLOUDNAS_CONF}"`
FW_VER=`/sbin/getcfg "System" "Version" -d --`
FW_BN=`/sbin/getcfg System "Build Number" -d --`
SN=`/sbin/get_hwsn`
DISPLAY_MODEL=`/sbin/get_display_name`
MODEL=`/sbin/getcfg "System" "Model" -d NAS`
if [ "x$HOSTNAME" = "x" ]; then
/sbin/gen_hostname
/bin/sync
HOSTNAME=`/sbin/getcfg System "Server Name"`
fi
if [ `/sbin/getcfg "Bonjour Service" Web -u -d 1` = 1 ]; then
BROWSENAME=`/sbin/getcfg "Bonjour Service" "Web Service Name" -d "$HOSTNAME"`
/bin/cat > ${AVAHI_CONF_DIR}/web.service <<__EOF__
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">$BROWSENAME</name>
<service>
<type>_http._tcp</type>
<port>${WEB_PORT}</port>
<txt-record>path=/</txt-record>
</service>
</service-group>
__EOF__
fi
if [ `/sbin/getcfg "Bonjour Service" SAMBA -u -d 1` = 1 ]; then
BROWSENAME=`/sbin/getcfg "Bonjour Service" "SAMBA Service Name" -d "$HOSTNAME(SMB)"`
/bin/cat > ${AVAHI_CONF_DIR}/samba.service <<__EOF__
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">$BROWSENAME</name>
<service>
<type>_smb._tcp</type>
<port>445</port>
</service>
</service-group>
__EOF__
fi
if [ `/sbin/getcfg "Bonjour Service" AFP -u -d 0` = 1 ]; then
BROWSENAME=`/sbin/getcfg "Bonjour Service" "AFP Service Name" -d "$HOSTNAME(AFP)"`
/bin/cat > ${AVAHI_CONF_DIR}/afp.service <<__EOF__
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">$BROWSENAME</name>
<service>
<type>_afpovertcp._tcp</type>
<port>548</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=Mac</txt-record>
</service>
</service-group>
__EOF__
fi
if [ `/sbin/getcfg "Bonjour Service" SSH -u -d 0` = 1 ]; then
BROWSENAME=`/sbin/getcfg "Bonjour Service" "SSH Service Name"`
SSH_PORT=`/sbin/getcfg LOGIN "SSH Port"`
/bin/cat > ${AVAHI_CONF_DIR}/ssh.service <<__EOF__
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">$BROWSENAME</name>
<service>
<type>_ssh._tcp</type>
<port>${SSH_PORT}</port>
</service>
</service-group>
__EOF__
fi
if [ `/sbin/getcfg "Bonjour Service" FTP -u -d 0` = 1 ]; then
BROWSENAME=`/sbin/getcfg "Bonjour Service" "FTP Service Name"`
FTP_PORT=`/sbin/getcfg FTP Port`
/bin/cat > ${AVAHI_CONF_DIR}/ftp.service <<__EOF__
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">$BROWSENAME</name>
<service>
<type>_ftp._tcp</type>
<port>${FTP_PORT}</port>
<txt-record>model=path=/</txt-record>
</service>
</service-group>
__EOF__
fi
if [ `/sbin/getcfg "Bonjour Service" HTTPS -u -d 0` = 1 ]; then
BROWSENAME=`/sbin/getcfg "Bonjour Service" "HTTPS Service Name"`
/bin/cat > ${AVAHI_CONF_DIR}/https.service <<__EOF__
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">$BROWSENAME</name>
<service>
<type>_https._tcp</type>
<port>${HTTPS_PORT}</port>
<txt-record>model=path=/</txt-record>
</service>
</service-group>
__EOF__
fi
if [ `/sbin/getcfg "Bonjour Service" UPNP -u -d 0` = 1 ]; then
BROWSENAME=`/sbin/getcfg "Bonjour Service" "UPNP Service Name" -d "$HOSTNAME(DLNA)"`
UPNP_PORT=`/sbin/getcfg "TwonkyMedia" "Port" -d 9000`
/bin/cat > ${AVAHI_CONF_DIR}/upnp.service <<__EOF__
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">$BROWSENAME</name>
<service>
<type>_upnp._tcp</type>
<port>${UPNP_PORT}</port>
</service>
</service-group>
__EOF__
fi
if [ `/sbin/getcfg "Bonjour Service" "QMobile" -u -d 1` = 1 ]; then
BROWSENAME=`/sbin/getcfg "Bonjour Service" "QMobile Service Name" -d "$HOSTNAME(Apps)"`
QMOBILE_PORT=`/sbin/getcfg "QMobile" "Port" -d 3986`
/bin/cat > ${AVAHI_CONF_DIR}/qmobile.service <<__EOF__
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">$BROWSENAME</name>
<service>
<type>_qmobile._tcp</type>
<port>${QMOBILE_PORT}</port>
</service>
</service-group>
__EOF__
fi
if [ `/sbin/getcfg "Bonjour Service" QNAP -u -d 1` = 1 ]; then
BROWSENAME=`/sbin/getcfg "Bonjour Service" QNAP -d "$HOSTNAME"`
atype="http";
aport=${WEB_PORT};
if [ `/sbin/getcfg "Stunnel" "Enable" -u -d 1` = 1 -a `/sbin/getcfg "System" "Force SSL" -u -d 0` = 1 ]; then
atype="https"
aport=${HTTPS_PORT}
fi
qTXT="accessType=${atype},accessPort=${aport},model=${MODEL},displayModel=${DISPLAY_MODEL},fwVer=${FW_VER},fwBuildNum=${FW_BN}"
if [ x != x"$SN" ]; then
qTXT="${qTXT},serialNum=${SN}"
fi
if [ x != x"$MYCLOUDNAS_NAME" -a x != x"$MYCLOUDNAS_DN" ]; then
qTXT="${qTXT},myCloudNASName=${MYCLOUDNAS_NAME},myCloudNASDomain=${MYCLOUDNAS_DN}"
fi
/bin/cat > ${AVAHI_CONF_DIR}/qdiscover.service <<__EOF__
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">$BROWSENAME</name>
<service>
<type>_qdiscover._tcp</type>
<port>${WEB_PORT}</port>
<txt-record>$qTXT</txt-record>
</service>
</service-group>
__EOF__
fi
if [ `/sbin/getcfg iTune Enable -u -d FALSE` = TRUE ]; then
_iTunes_ID=`/sbin/get_hwsn`
if [ $? != 0 ]; then
_iTunes_ID=`/sbin/uuidgen | /bin/cut -c 1-8`
fi
if [ "x`/sbin/getcfg iTune "Password Enabled" -u -d 0`" = "x1" ]; then
export _Passowrd=true
else
export _Passowrd=false
fi
/bin/cat > ${AVAHI_CONF_DIR}/itunes.service <<__EOF__
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">$HOSTNAME(iTunes)</name>
<service>
<type>_daap._tcp</type>
<port>3689</port>
<txt-record>txtvers=1</txt-record>
<txt-record>Machine Name=$HOSTNAME(iTunes)</txt-record>
<txt-record>Database ID=${_iTunes_ID}</txt-record>
<txt-record>iTSh Version=131073</txt-record>
<txt-record>Version=196610</txt-record>
<txt-record>Passowrd=${_Passowrd}</txt-record>
</service>
</service-group>
__EOF__
fi
if [ `/sbin/getcfg "Bonjour Service" CSCO -u -d 0` = 1 ]; then
service_name=`/sbin/getcfg "Bonjour Service" "Web Service Name" -d $HOSTNAME`"(csco-sb)"
/sbin/setcfg "Bonjour Service" "CSCO Service Name" $service_name
model_name=`/sbin/getcfg "System" "Model"`
devicedescr=`/bin/echo "$model_name" | /bin/tr -d '[a-z][A-Z]'`
[ ${model_name} = "NSS324R" ] && devicedescr="324R"
fmVersion=`/sbin/getcfg "System" "Version"`
hdVersion=`/sbin/get_hwver`
[ ${model_name} = "NSS324R" ] && hdVersion="1.0"
vid=`/bin/echo "${hdVersion} 10" | awk '{ printf("%g", $1 * $2);}'`
vid=$(($vid - 10 + 1 ))
if [ ${vid} -lt 10 ]; then
vid="0$vid"
fi
MACAddress=`/sbin/getcfg "MAC" "eth0" -f "/var/MacAddress" | /bin/tr '[a-z]' '[A-Z]' | /bin/tr -d ':'`
serialNo=`/sbin/get_hwsn`
hostname=`/bin/hostname`
mdf_id=""
if [ ${model_name} = "NSS322" ]; then
mdf_id="282984440"
elif [ ${model_name} = "NSS324" ]; then
mdf_id="282984441"
elif [ ${model_name} = "NSS326" ]; then
mdf_id="282984448"
elif [ ${model_name} = "NSS324R" ]; then
mdf_id="282984441"
fi
accesstype="noaccess";
if [ `/sbin/getcfg "Stunnel" "Enable" -u -d 1` = 1 ]; then
if [ "x$accesstype" = "xnoaccess" ]; then
accesstype="https"
else
accesstype="$accesstype, https"
fi
fi
if [ `/sbin/getcfg "System" "Force SSL" -u -d 0` = 0 ]; then
if [ "x$accesstype" = "xnoaccess" ]; then
accesstype="http"
else
accesstype="$accesstype, http"
fi
else
if [ "x$accesstype" = "xnoaccess" ]; then
accesstype="http"
fi
fi
if [ `/sbin/getcfg "LOGIN" "SSH Enable" -u -d TRUE` = TRUE ]; then
if [ "x$accesstype" = "xnoaccess" ]; then
accesstype="ssh"
else
accesstype="$accesstype, ssh"
fi
fi
if [ `/sbin/getcfg "LOGIN" "TELNET Enable" -u -d FALSE` = TRUE ]; then
if [ "x$accesstype" = "xnoaccess" ]; then
accesstype="telnet"
else
accesstype="$accesstype, telnet"
fi
fi
/bin/cat > ${AVAHI_CONF_DIR}/csco.service <<__EOF__
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h(csco)</name>
<service>
<type>_csco-sb._tcp</type>
<port>${WEB_PORT}</port>
<txt-record>version=1.0</txt-record>
<txt-record>model=${model_name}</txt-record>
<txt-record>deviceType=NAS</txt-record>
<txt-record>deviceDescr=Cisco NSS ${devicedescr} Smart Storage</txt-record>
<txt-record>fmVersion=$fmVersion</txt-record>
<txt-record>PIDVID=${model_name} V${vid}</txt-record>
<txt-record>MACAddress=${MACAddress}</txt-record>
<txt-record>serialNo=${serialNo}</txt-record>
<txt-record>hostname=${hostname}</txt-record>
<txt-record>MDFID=${mdf_id}</txt-record>
<txt-record>accessType=${accesstype}</txt-record>
</service>
</service-group>
__EOF__
fi
for i in 1 2 3 4 5 6 7; do
[ $i -eq 1 ] && i=""
if [ `/sbin/getcfg "Bonjour Service" "PRINTER$i" -u -d 0` = 1 ]; then
local phy_exist=`/sbin/getcfg "Printers" "Phy exist$i"`
[ "x$phy_exist" = "x" ] || [ $phy_exist -eq 0 ] && continue
local status=`/sbin/getcfg "Printers" "Status$i"`
[ $status -eq 4 ] && continue
local service_name=`/sbin/getcfg "Bonjour Service" "PRINTER Service Name$i"`
local printer_port=`/bin/cat /etc/config/cups/cupsd.conf|/bin/grep "Listen"|/bin/cut -d':' -f 2|/usr/bin/head -n 1`
local printer_name=`/sbin/getcfg "Printers" "Name$i"`
local manufacture=`/sbin/getcfg "Printers" "Manufacture$i"`
local model=`/sbin/getcfg "Printers" "Model$i"`
/bin/cat > ${AVAHI_CONF_DIR}/printer.service <<__EOF__
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h(Airprint)</name>
<service>
<type>_ipp._tcp</type>
<subtype>_universal._sub._ipp._tcp</subtype>
<port>$printer_port</port>
<txt-record>txtvers=1</txt-record>
<txt-record>qtotal=1</txt-record>
<txt-record>priority=0</txt-record>
<txt-record>rp=printers/$printer_name</txt-record>
<txt-record>ty=$manufacture $model</txt-record>
<txt-record>note=$manufacture $model</txt-record>
<txt-record>product=(GPL Ghostscript)</txt-record>
<txt-record>pdl=application/pdf,application/postscript,application/vnd.cups-raster,application/octet-stream,image/png</txt-record>
<txt-record>URF=none</txt-record>
</service>
</service-group>
__EOF__
fi
done
}
dbus_start()
{
if [ -L /var/run/dbus ] || [ -d ${AVAHI_SRC}/var/run/dbus ]; then
/bin/rm -rf /var/run/dbus
/bin/rm -rf ${AVAHI_SRC}/var/run/dbus
fi
DBUS_PID=`/bin/ps | /bin/grep dbus | /bin/grep -v grep | /bin/awk '{print $1}'`
if [ ! -z "$DBUS_PID" ]; then
/bin/echo "Dbus is still running ... restart dbus ..."
kill -9 $DBUS_PID
fi
/bin/mkdir -p ${AVAHI_SRC}/var/run/dbus
/bin/ln -sf ${AVAHI_SRC}/var/run/dbus /var/run/dbus
/bin/echo -n "Starting Dbus ... "
${DBUS_DAEMON} --system
/bin/sleep 1
/bin/kill -HUP `/bin/cat /var/run/dbus/pid`
/bin/sleep 1
/bin/echo "Dbus Started"
}
dbus_stop()
{
DBUS_PID=`/bin/ps | /bin/grep dbus | /bin/grep -v grep | /bin/awk '{print $1}'`
if [ -z "$DBUS_PID" ]; then
/bin/echo "Dbus is not running ..."
else
/bin/echo -n "Stopping Dbus ... "
/bin/kill -9 $DBUS_PID
/bin/sleep 1
/bin/echo "Stopped."
fi
/bin/rm -rf /var/run/dbus
/bin/rm -rf $AVAHI_SRC/var/run/dbus
}
PUBLIC_SHARE=`/sbin/getcfg SHARE_DEF defPublic -d Public -f /etc/config/def_share.info`
#Determine BASE installation location according to smb.conf
BASE=
publicdir=`/sbin/getcfg $PUBLIC_SHARE path -f /etc/config/smb.conf`
if [ ! -z $publicdir ] && [ -d $publicdir ];then
publicdirp1=`/bin/echo $publicdir | /bin/cut -d "/" -f 2`
publicdirp2=`/bin/echo $publicdir | /bin/cut -d "/" -f 3`
publicdirp3=`/bin/echo $publicdir | /bin/cut -d "/" -f 4`
if [ ! -z $publicdirp1 ] && [ ! -z $publicdirp2 ] && [ ! -z $publicdirp3 ]; then
[ -d "/${publicdirp1}/${publicdirp2}/${PUBLIC_SHARE}" ] && BASE="/${publicdirp1}/${publicdirp2}"
fi
fi
#Determine BASE installation location by checking where the Public folder is.
if [ -z $BASE ]; then
for datadirtest in /share/HDA_DATA /share/HDB_DATA /share/HDC_DATA /share/HDD_DATA /share/MD0_DATA; do
[ -d $datadirtest/$PUBLIC_SHARE ] && BASE="/${publicdirp1}/${publicdirp2}"
done
fi
if [ -z $BASE ] ; then
echo "The Public share not found."
exit 1
fi
case "$1" in
start)
if [ -f /tmp/avahi0630.lock ]; then
/bin/kill -INT `/bin/ps | /bin/grep avahi-daemon | /bin/grep -v grep | /bin/grep running | /bin/awk '{print $1}'` 2>/dev/null 1>/dev/null
/bin/rm -rf /tmp/avahi0630.lock
fi
if [ -f /etc/config/timemachine.conf ]; then
cp /etc/config/timemachine.conf /etc/config/timemachine.conf-pre_avahi
fi
[ -f ${AVAHI_DAEMON} ] || exit 1
#/etc/init.d/bonjour.sh stop
/bin/echo "Try to shutting down AVAHI services first"
/bin/kill -INT `/bin/ps | /bin/grep avahi-daemon | /bin/grep -v grep | /bin/grep running | /bin/awk '{print $1}'` 2>/dev/null 1>/dev/null
/bin/rm -rf /var/run/avahi-daemon
/bin/rm -rf ${AVAHI_SRC}/var/run/avahi-daemon
mkdir -p ${AVAHI_SRC}/var/run/avahi-daemon
ln -sf ${AVAHI_SRC}/var/run/avahi-daemon /var/run/avahi-daemon
/etc/init.d/timemachine.sh stop
/bin/sleep 3
# create the lock file
touch /tmp/avahi0630.lock
# starting Dbus
dbus_start
/sbin/ldconfig
#starting AVAHI
set_avahi_conf
if [ "x"`/sbin/getcfg TimeMachine Enabled -d FALSE` = "xTRUE" ]; then
/etc/init.d/timemachine.sh start
fi
/bin/sleep 2
#${AVAHI_DAEMON} --debug
${AVAHI_DAEMON} -D
#/bin/sleep 3
#CURRENT_AVAHI_PID=`/bin/ps | /bin/grep avahi-daemon | /bin/grep -v grep | /bin/grep running | /bin/awk '{print $1}'`
#if [ -z "$CURRENT_AVAHI_PID" ] ; then
#/bin/echo "Error: Avahi failed to start."
#/sbin/write_log "Error: Avahi failed to start." 1
#fi
;;
stop)
/bin/echo "Stop Avahi"
if [ ! -f /tmp/avahi0630.lock ]; then
/bin/echo "Avahi hasn't been enabled or started ..."
exit 0
fi
/bin/echo -n "Shutting down services: "
/bin/kill -INT `/bin/ps | /bin/grep avahi-daemon | /bin/grep -v grep | /bin/grep running | /bin/awk '{print $1}'` 2>/dev/null 1>/dev/null
/bin/rm -rf /var/run/avahi-daemon/pid
/bin/rm -rf /var/run/avahi-daemon/socket
/etc/init.d/timemachine.sh stop
#Stopping Dbus
dbus_stop
/bin/sleep 1
/bin/rm -rf /etc/config/timemachine.conf-pre_avahi
/bin/rm -rf /tmp/avahi0630.lock
;;
restart)
$0 stop
$0 start
;;
reload)
CURRENT_AVAHI_PID=`/bin/ps | /bin/grep avahi-daemon | /bin/grep "local]" | /bin/awk '{print $1}'`
if [ ! -z "$CURRENT_AVAHI_PID" ]; then
if [ -f /var/lock/avahi_set_conf.lock ]; then
exit 0;
fi
touch /var/lock/avahi_set_conf.lock
set_avahi_conf
/bin/kill -HUP $CURRENT_AVAHI_PID
rm /var/lock/avahi_set_conf.lock
fi
;;
*)
/bin/echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

26
backup2nas.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/sh
RETVAL=0
case "$1" in
start)
echo "Starting backup2nas services: "
/sbin/daemon_mgr backup2nas start "/sbin/backup2nas -D"
RETVAL=$?
;;
stop)
echo "Shutting down backup2nas services: "
/sbin/daemon_mgr backup2nas stop "/sbin/backup2nas -D"
RETVAL=$?
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $RETVAL

70
backup_conf.sh Executable file
View File

@@ -0,0 +1,70 @@
#!/bin/sh
func="$1"
opt="$2"
MIN_FSIZE=200 #minimum config file size required
. /etc/init.d/functions
#1. Check conifg in uLinux
backup_en=`/sbin/getcfg BackupConfig Enable -d null`
backup_files=`/sbin/getcfg BackupConfig Files -d "/etc/config/*"`
backup_max=`/sbin/getcfg BackupConfig "Max config" -d 10`
if [ "x$backup_en" = "xFALSE" ] && [ -z "$func" ]; then
echo "Backup func is Disabled"
exit 0
fi
#2. Determine BASE installation location according to smb.conf
FindDefVol
_ret=$?
if [ $_ret != 0 ]; then
echo "Default volume not found."
exit 1
fi
CONFIG_DIR="$DEF_VOLMP/.@backup_config"
[ -d "$CONFIG_DIR" ]|| /bin/mkdir "$CONFIG_DIR"
if [ "x$func" = "xrestore" ] && [ ! -z "$opt" ]; then
ret=0
[ ! -z "$opt" ] || exit 1
cd $CONFIG_DIR
/bin/ls -r | grep "^0_" | while read archive
do
[ -f $archive ] || continue
restore_f=`tar -tf "$archive" 2>>/dev/null | grep "$opt"`
if [ $? = 0 ]; then
[ ! -f "/$restore_f" ] || /bin/cp "/$restore_f" "/$restore_f".replaced
/bin/tar -f $archive -x "$restore_f"
f_size=`/usr/bin/du -b "$restore_f" | /bin/awk '{print $1}'`
if [ -z "$f_size" ] || [ "$f_size" -lt $MIN_FSIZE ]; then
/bin/rm -rf "$restore_f" 2>>/dev/null
continue
fi
/bin/tar -f $archive -C / -x "$restore_f"
ret=$?
break
fi
done
exit $ret
fi
#3. file rotate
/bin/ls -r $CONFIG_DIR | while read config_name
do
echo "$config_name" | grep -q "_*\.tar\.gz"
[ "$?" = "1" ]&& continue
index=${config_name%%_*}
postfix_name=${config_name#*_}
let "index++"
if [ $index -ge $backup_max ]; then
#echo "remove $CONFIG_DIR/$config_name"
/bin/rm -f "$CONFIG_DIR/$config_name"
continue
fi
let "index%=backup_max"
/bin/mv "$CONFIG_DIR/$config_name" "$CONFIG_DIR/${index}_${postfix_name}"
done
#4. Backup config
tar_name=`date +%Y%m%d_%H%M`
[ "x$backup_files" != "x" ]&& /bin/tar --no-recursion -czpf $CONFIG_DIR/0_$tar_name.tar.gz $backup_files > /dev/null 2>&1

6
boot_done.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/sh
/bin/sleep 20
/bin/touch /tmp/.boot_done
exit 0

27
bt_scheduler.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
if [ `/sbin/getcfg BTDownload Version -u -d 1.0 -f /etc/default_config/uLinux.conf` = 1.0 ]; then
exit 1
fi
case "$1" in
start)
if [ -f /sbin/bt_scheduler ] && [ `/sbin/getcfg BTDownload Enable -u -d FALSE` = TRUE ]; then
echo -n "Starting DS scheduler: "
/bin/pidof bt_scheduler 1>>/dev/null 2>>/dev/null
if [ $? != 0 ]; then
/sbin/bt_scheduler
fi
fi
;;
stop)
echo -n "Stop DS scheduler: "
killall bt_scheduler
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

232
btd.sh Executable file
View File

@@ -0,0 +1,232 @@
#!/bin/sh
ROOT_PART="/mnt/HDA_ROOT"
UPDATEPKG_DIR="${ROOT_PART}/update_pkg"
RETVAL=0
APP_RUNTIME_CONF="/var/.application.conf"
QGET_TMP_DIR=/tmp/qget
QGET_INFO_DIR=/etc/config/qget
DownloadShare=`/sbin/getcfg SHARE_DEF defDownload -d Qdownload -f /etc/config/def_share.info`
REAL_PATH=`/sbin/getcfg ${DownloadShare} path -f /etc/smb.conf -d /ERROR`
BTDownloadFolder=`/sbin/getcfg BTDownload "BT Download Folder"`
#BTCompleteFolder=`/sbin/getcfg BTDownload "BT Move Completed Task Folder"`
HTTPDownloadFolder=`/sbin/getcfg BTDownload "HTTP_FTP Download Folder"`
#HTTPCompleteFolder=`/sbin/getcfg BTDownload "HTTP_FTP Move Completed Task Folder"`
TORRENT_FOLDER=`/sbin/getcfg BTDownload "Torrent Folder"`
Volume_Str=`/sbin/getcfg Public path -f /etc/smb.conf | cut -d '/' -f 3`
DB_FILE="/mnt/HDA_ROOT/ds.db"
BTD_PID="/var/lock/btd.pid"
DS_Enable=`/sbin/getcfg BTDownload Enable -u -d TRUE`
check_share()
{
local share="$1"
local conf_name="$2"
if [ "$share" = "" ]; then
/bin/echo "set $2 to default"
/sbin/setcfg BTDownload "$2" "${DownloadShare}"
return 0
fi
if [ ! -d "/share/$share" ]; then
/bin/echo "Share folder $share does not exist. Failed to start btd."
/sbin/write_log "[Download Station] Share folder $share does not exist. Failed to start btd." 1
exit 1
fi
return 0
}
DS_Hide=`/sbin/getcfg DISABLE qdownload -d 0 -f $APP_RUNTIME_CONF`
if [ "x$DS_Hide" = "x1" ]; then
/sbin/setcfg BTDownload Enable FALSE
DS_Enable="FALSE"
fi
if [ x`/sbin/getcfg BTDownload addonEnable -u -d X` = xX ]; then
/bin/echo "default Enable addonEnable."
/sbin/setcfg BTDownload addonEnable TRUE
fi
_debug="0"
case "$2" in
debug)
_debug="1"
;;
DEBUG)
_debug="1"
;;
*)
_debug="0"
esac
case "$1" in
start)
if [ ! -f /tmp/.boot_done ] && [ `/bin/pidof btd | /usr/bin/wc -w` == "0" ]; then
[ ! -f ${UPDATEPKG_DIR}/DSv3.tgz ] || /etc/init.d/installtgz.sh DSv3 ${UPDATEPKG_DIR}/DSv3.tgz
else
_MNT_POINT="/mnt/ext"
if [ -f ${_MNT_POINT}/opt/DSv3/gt/gt_run.sh ]; then
/bin/ln -sf ${_MNT_POINT}/opt/DSv3/gt/gt_run.sh /etc/init.d/gt_run.sh
/bin/chmod 755 ${_MNT_POINT}/opt/DSv3/gt/gt_run.sh
fi
fi
if [ ! -d $REAL_PATH ]; then
/bin/echo "Volume is not ready for btd."
exit 1
fi
if [ ! -f $DB_FILE ]; then
/sbin/bt_tool -cv
else
if [ `/sbin/getcfg "BTDownload" "Version" -u -d 1.0 -f /etc/config/uLinux.conf` != 3.0 ]; then
/sbin/setcfg "BTDownload" "Version" "3.0" -f /etc/config/uLinux.conf
/sbin/bt_tool -cv
fi
fi
if [ ! -s $DB_FILE ]; then
/bin/rm "$DB_FILE"
/sbin/bt_tool -cv
fi
if [ ! -f /sbin/btd ]; then
/bin/echo "Failed to locate the daemon."
# /sbin/write_log "[Download Station] Failed to locate the daemon." 1
exit 1
fi
if [ ! -d "/share/$Volume_Str/.torrent" ]; then
/bin/mkdir "/share/$Volume_Str/.torrent"
fi
if [ ! -d "/share/$Volume_Str/.torrent/.temp" ]; then
/bin/mkdir "/share/$Volume_Str/.torrent/.temp"
else
/bin/rm -f "/share/$Volume_Str/.torrent/.temp/*"
fi
if [ -d /etc/config/torrent/torrent ] && [ `ls "/etc/config/torrent/torrent/" | /usr/bin/wc -l` != 0 ]; then
/bin/rm -rf /etc/config/torrent/torrent/*
fi
# if [ ! -d "/mnt/HDA_ROOT/.ds/engines" ]; then
# /bin/mkdir -p "/mnt/HDA_ROOT/.ds/engines"
# /bin/cp -rf "/home/httpd/cgi-bin/Qdownload/engines" "/mnt/HDA_ROOT/.ds/"
# fi
# if [ -d "/home/httpd/cgi-bin/Qdownload/engines" ]; then
# [ -f "/mnt/HDA_ROOT/.ds/engines/isohunt.php" ] || /bin/cp -rf "/home/httpd/cgi-bin/Qdownload/engines" "/mnt/HDA_ROOT/.ds/"
# /bin/rm -rf "/home/httpd/cgi-bin/Qdownload/engines"
# /bin/ln -sf "/mnt/HDA_ROOT/.ds/engines" "/home/httpd/cgi-bin/Qdownload/engines"
# fi
if [ x"$TORRENT_FOLDER" = x ]; then
/sbin/setcfg BTDownload "Torrent Folder" "/share/$Volume_Str/.torrent"
TORRENT_FOLDER="/share/$Volume_Str/.torrent"
fi
if [ x"$TORRENT_FOLDER" != x"/share/$Volume_Str/.torrent" ]; then
/sbin/setcfg BTDownload "Torrent Folder" "/share/$Volume_Str/.torrent"
TORRENT_FOLDER="/share/$Volume_Str/.torrent"
fi
if [ -f /sbin/btd ] && [ "x$DS_Enable" = "xTRUE" ]; then
/bin/echo "Starting BT management services: "
check_share "$BTDownloadFolder" "BT Download Folder"
[ x"$BTDownloadFolder" != x ] || BTDownloadFolder=${DownloadShare}
# check_share "$BTCompleteFolder" "BT Move Completed Task Folder"
# [ x"$BTCompleteFolder" != x ] || BTCompleteFolder=${DownloadShare}
# check_share "$HTTPDownloadFolder" "HTTP_FTP Download Folder"
# [ x"$HTTPDownloadFolder" != x ] || HTTPDownloadFolder=${DownloadShare}
# check_share "$HTTPCompleteFolder" "HTTP_FTP Move Completed Task Folder"
# [ x"$HTTPCompleteFolder" != x ] || HTTPCompleteFolder=${DownloadShare}
[ x"$BTDownloadFolder" = x"HTTPDownloadFolder" ] || `/sbin/setcfg BTDownload "HTTP_FTP Download Folder" "$BTDownloadFolder"`
if [ `/bin/pidof btd | /usr/bin/wc -w` != "0" ]; then
/bin/echo "bt daemon is running, exit."
exit 1
fi
#add column(s)
if [ -f /usr/local/apache/bin/php ] && [ -f /home/httpd/cgi-bin/Qdownload/db_alter.php ]; then
/usr/local/apache/bin/php /home/httpd/cgi-bin/Qdownload/db_alter.php BT_TASK task_queue_position 1 2>>/dev/null
/usr/local/apache/bin/php /home/httpd/cgi-bin/Qdownload/db_alter.php BT_TASK task_move_folder 0 2>>/dev/null
/usr/local/apache/bin/php /home/httpd/cgi-bin/Qdownload/db_alter.php HTTP_FTP_TASK task_move_folder 0 2>>/dev/null
/usr/local/apache/bin/php /home/httpd/cgi-bin/Qdownload/db_alter.php BT_TASK task_hash 0 2>>/dev/null
/usr/local/apache/bin/php /home/httpd/cgi-bin/Qdownload/db_alter.php BT_TASK task_type 1 2>>/dev/null
/usr/local/apache/bin/php /home/httpd/cgi-bin/Qdownload/db_alter.php BT_TASK task_magnet_link 0 2>>/dev/null
/usr/local/apache/bin/php /home/httpd/cgi-bin/Qdownload/db_alter.php BT_SESSION pause_all_time 1 2>>/dev/null
/usr/local/apache/bin/php /home/httpd/cgi-bin/Qdownload/db_alter.php HTTP_FTP_TASK task_savename 0 2>>/dev/null
/usr/local/apache/bin/php /home/httpd/cgi-bin/Qdownload/db_alter.php HTTP_FTP_TASK task_queue_position 1 2>>/dev/null
fi
if [ ! -d $QGET_TMP_DIR ]; then
/bin/mkdir $QGET_TMP_DIR
fi
if [ ! -d $QGET_INFO_DIR ]; then
/bin/mkdir $QGET_INFO_DIR
fi
[ -f libtorrent-rasterbar.so.6 ] || /bin/ln -sf libtorrent.so /usr/lib/libtorrent-rasterbar.so.6
if [ `/sbin/getcfg BTDownload Encrypt -u -d 0` = 1 ]; then
cd /usr/lib; /bin/rm libtorrent-0.15.9.so; /bin/ln -sf libtorrent-0.15.9.so.enc libtorrent-0.15.9.so
else
cd /usr/lib; /bin/rm libtorrent-0.15.9.so; /bin/ln -sf libtorrent-0.15.9.so.nonenc libtorrent-0.15.9.so
fi
#scan torrent and check DB
/sbin/bt_tool -s -v
if [ ${_debug} == "0" ]; then
/sbin/btd -m "/share/$Volume_Str/.torrent" -s "/share/${BTDownloadFolder}" 1>/dev/null 2>/dev/null &
else
/sbin/btd -m "/share/$Volume_Str/.torrent" -s "/share/${BTDownloadFolder}" --log-file "/share/${BTDownloadFolder}/btd.log" 1>/dev/null 2>/dev/null &
fi
#/sbin/daemon_mgr btd start "/sbin/btd"
Addon_Enable=`/sbin/getcfg BTDownload addonEnable -u -d FALSE`
if [ "x$Addon_Enable" = "xTRUE" ]; then
[ ! -f /etc/init.d/gt_run.sh ] || /etc/init.d/gt_run.sh start
fi
fi
RETVAL=$?
;;
reset)
/bin/rm "$DB_FILE"
/sbin/bt_tool -cv
/bin/rm /etc/config/torrent/torrent/*
/bin/rm /share/$Volume_Str/.torrent/*
;;
stop)
/bin/echo -n "Shutting down BT management services: "
#/sbin/daemon_mgr btd stop "/sbin/btd"
/bin/echo "btd."
/bin/chmod -R +rw /share/${DownloadShare}/
/usr/bin/killall curl
/usr/bin/killall btd
/usr/bin/killall curl_download
[ ! -f /etc/init.d/gt_run.sh ] || /etc/init.d/gt_run.sh stop
/bin/echo -n "Killing BT processes. Please wait...."
count=15
btdP=1
while [ $btdP = 1 ] && [ $count -gt 0 ]; do
/bin/echo -n "."
count=$(($count-1));
/bin/pidof btd 1>>/dev/null 2>>/dev/null
if [ $? -ne 0 ]; then
btdP=0
else
/bin/sleep 1
fi
done
/bin/echo
/usr/bin/killall -9 curl
/usr/bin/killall -9 curl_download
/usr/bin/killall -9 btd
[ ! -d $QGET_TMP_DIR ] || /bin/rm ${QGET_TMP_DIR}/* 1>/dev/null 2>/dev/null
[ ! -f $BTD_PID ] || /bin/rm ${BTD_PID} 1>/dev/null 2>/dev/null
/bin/sleep 1
RETVAL=$?
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
*)
/bin/echo "Usage: $0 {start|stop|restart|reset}"
exit 1
esac
exit $RETVAL

28
cacd.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/sh
# For Administration
test -f /usr/bin/cacd || exit 0
case "$1" in
start)
echo -n "Start cacd:"
/sbin/daemon_mgr cacd start "/usr/bin/cacd &" 2>/dev/null > /dev/null
echo -n " cacd"
echo "."
;;
stop)
echo -n "Shutting down cacd:"
/sbin/daemon_mgr cacd stop /usr/bin/cacd 2>/dev/null > /dev/null
echo -n " cacd"
echo "."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/cacd.sh {start|stop|restart}"
exit 1
esac
exit 0

31
check_bootcmd.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/sh
model_name=`/bin/cat /etc/config/BOOT.conf`
if [ "x$model_name" == "xTS-NASARM" ]; then
partition="U-Boot Config"
proc_mtd="/proc/mtd"
base=0
mtdno=`/bin/cat $proc_mtd | /bin/grep "$partition" | /bin/cut -d':' -f 1 | /bin/sed 's/mtd//g'`
ubootcfg_r="/sbin/ubootcfg -b 0 -o - -f /dev/mtdblock${mtdno}"
ubootcfg_w="/sbin/ubootcfg -b 0 -i - -f /dev/mtdblock${mtdno}"
getucfg="/sbin/getmtd_ubootcfg.sh"
setucfg="/sbin/setmtd_ubootcfg.sh"
delucfg="/sbin/delmtd_ubootcfg.sh"
chgbootcmd="cp.l 0xf8200000 0x800000 0x80000;cp.l 0xf8400000 0xa00000 0x240000;bootm 0x800000"
cmd=`$ubootcfg_r | /bin/grep ^bootcmd= | /bin/cut -d '=' -f 2 | /bin/cut -d ' ' -f 1`
if [ "x$cmd" == "xcp.b" ]; then
$ubootcfg_r | sed "/^bootcmd=/ c bootcmd=$chgbootcmd" | $ubootcfg_w
echo "bootcmd change ok"
else
echo "bootcmd check ok"
fi
# add pic watch dog timer 5 min, time out reboot
chgbootcmd="uart1 0x68;cp.l 0xf8200000 0x800000 0x80000;cp.l 0xf8400000 0xa00000 0x240000;bootm 0x800000"
cmd=`$ubootcfg_r | /bin/grep ^bootcmd= | /bin/cut -d '=' -f 2 | /bin/cut -d ' ' -f 1`
if [ "x$cmd" == "xcp.l" ]; then
$ubootcfg_r | sed "/^bootcmd=/ c bootcmd=$chgbootcmd" | $ubootcfg_w
echo "bootcmd change ok"
fi
fi

54
check_ddns_external_ip.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/ash
#
# check ddns external ip change or not
DDNS_TMP_FILE="/var/ddns_tmp.conf"
DDNS_EX_IP_FILE="/var/ddns_extranl_ip"
check_ddns_temp_file()
{
if [ ! -f ${DDNS_TMP_FILE} ]; then
/bin/echo "${DDNS_TMP_FILE} is not exist"
/bin/echo "[DDNS]" > ${DDNS_TMP_FILE}
/bin/echo "Support = "`/sbin/getcfg "DDNS" "Support" -u -d "TRUE"` >> ${DDNS_TMP_FILE}
/bin/echo "Enable = "`/sbin/getcfg "DDNS" "Enable" -u -d "FALSE"` >> ${DDNS_TMP_FILE}
/bin/echo "Server Type = "`/sbin/getcfg "DDNS" "Server Type" -u -d "0"` >> ${DDNS_TMP_FILE}
/bin/echo "Config File = "`/sbin/getcfg "DDNS" "Config File" -d "/etc/ddns_update.conf"` >> ${DDNS_TMP_FILE}
/bin/echo "Check External IP = "`/sbin/getcfg "DDNS" "Check External IP" -d "0"` >> ${DDNS_TMP_FILE}
/bin/echo "User Name = "`/sbin/getcfg "DDNS" "User Name" -d ""` >> ${DDNS_TMP_FILE}
/bin/echo "Password = "`/sbin/getcfg "DDNS" "Password" -d ""` >> ${DDNS_TMP_FILE}
/bin/echo "Host Name = "`/sbin/getcfg "DDNS" "Host Name" -d ""` >> ${DDNS_TMP_FILE}
/bin/echo "DDNS Type = "`/sbin/getcfg "DDNS" "DDNS Type" -d "0"` >> ${DDNS_TMP_FILE}
fi
[ ! -f ${DDNS_EX_IP_FILE} ] && /bin/echo `/sbin/getcfg "DDNS" "IP Address" -f ${DDNS_TMP_FILE}` > ${DDNS_EX_IP_FILE}
}
SEVER_TYPE=`grep "Server Type" ${DDNS_TMP_FILE} | /bin/tr -cs '[0-9\.]' '\012'`
if [ ${SEVER_TYPE} = 5 ]; then
/bin/echo "no-ip don't need use this functin"
exit 0
fi
NEW_IP=`/etc/init.d/get_external_ip.sh`
result=$?
#[ -f /sbin/set_ipupatetime ] && /sbin/set_ipupatetime "%T"
[ -f /sbin/set_ipupatetime ] && /sbin/set_ipupatetime "0"
if [ $result -eq 0 ] && [ "x${NEW_IP}" != "x" ]; then
check_ddns_temp_file
OLD_IP=`/bin/cat ${DDNS_EX_IP_FILE}`
if [ "x${OLD_IP}" = "x${NEW_IP}" ]; then
/bin/echo "external ip is not change"
exit 0;
else
/bin/echo "external ip is change ,update ddns [${OLD_IP}]=>[${NEW_IP}]"
/sbin/setcfg "DDNS" "IP Address" ${NEW_IP} -f ${DDNS_TMP_FILE}
/bin/echo ${NEW_IP} > ${DDNS_EX_IP_FILE}
/etc/init.d/ddns_update.sh
/sbin/write_log "external ip is change ,update ddns." 2
exit 1;
fi
else
/bin/echo "can not get external ip"
fi
exit 0

113
check_lan_port.sh Executable file
View File

@@ -0,0 +1,113 @@
#!/bin/sh
GETCFG="/sbin/getcfg"
SETCFG="/sbin/setcfg"
DEFAULT_NIC_NUM=`$GETCFG "Network" "Interface Number" -f /etc/default_config/uLinux.conf`
CONFIG_NIC_NUM=`$GETCFG "Network" "Interface Number"`
ADV_BOND_SUPPORT=`$GETCFG "Network" "Advanced Bonding Support" -u -d "FALSE"`
LAN_CARD_10G=(808610fb 8086151c 19a20710 80861528)
LAN_CARD_1G=(808610c9 808610a7)
no_extra_lan_card="TRUE"
LAN_CARD_10G_V2=(8086:10FB 8086:151C 19A2:0710 8086:1528)
LAN_CARD_1G_V2=(8086:10C9 8086:10A7)
EXTRA_LAN_CARD_PORT_NUM=0
have_10G_extra_lan_card="FALSE"
have_1G_extra_lan_card="FALSE"
MAX_EXTRA_LAN_CARD_PORT_NUM=8
# Patch for build-in 4Lan TS-879U(Ivy Bridge)
Model_NameX=`/bin/cat /etc/default_config/uLinux.conf | grep "^Model =" | cut -d ' ' -f3 2>/dev/null`
if [ "x${Model_NameX}" = "xTS-1279" ] || [ "x${Model_NameX}" = "xTS-879U" ] || [ "x${Model_NameX}" = "xTS-1279U" ] || [ "x${Model_NameX}" = "xTS-1279-G" ] || [ "x${Model_NameX}" = "xTS-879U-G" ] || [ "x${Model_NameX}" = "xTS-1279U-G" ]; then
if [ -e /proc/tsinfo/hw_version ];then
Board=$(cat /proc/tsinfo/hw_version | cut -d ' ' -f2)
if [ $((Board & 2)) -eq 2 ];then
NIC_NUM=4
`$SETCFG "Network" "Interface Number" "$NIC_NUM"
`$SETCFG "Network" "Interface Number" "$NIC_NUM" -f /etc/default_config/uLinux.conf
fi
fi
fi
DEFAULT_NIC_NUM=`$GETCFG "Network" "Interface Number" -f /etc/default_config/uLinux.conf`
CONFIG_NIC_NUM=`$GETCFG "Network" "Interface Number"`
for (( i=0; i<${#LAN_CARD_10G[@]}; i=i+1 ))
do
/bin/cat /proc/bus/pci/devices | grep ${LAN_CARD_10G[$i]} 2>/dev/null 1>/dev/null
if [ $? = 0 ]; then
have_10G_extra_lan_card="TRUE"
pic_raw 99
break;
else
pic_raw 100
fi
done
for (( i=0; i<${#LAN_CARD_1G[@]}; i=i+1 ))
do
/bin/cat /proc/bus/pci/devices | grep ${LAN_CARD_1G[$i]} 2>/dev/null 1>/dev/null
if [ $? = 0 ]; then
have_1G_extra_lan_card="TRUE"
break;
fi
done
if [ $have_10G_extra_lan_card = "TRUE" ]; then
[ ! -f /lib/modules/misc/mdio.ko ] || /sbin/insmod /lib/modules/misc/mdio.ko
[ ! -f /lib/modules/misc/ixgbe.ko ] || /sbin/insmod /lib/modules/misc/ixgbe.ko
[ ! -f /lib/modules/misc/be2net.ko ] || /sbin/insmod /lib/modules/misc/be2net.ko
/sbin/setcfg Samba SO_SNDBUF 2621440 -f /etc/default_config/uLinux.conf
/sbin/setcfg Samba SO_RCVBUF 2621440 -f /etc/default_config/uLinux.conf
no_extra_lan_card="FALSE"
/bin/touch /tmp/option_10G
pic_raw 99
else
pic_raw 100
fi
if [ $have_1G_extra_lan_card = "TRUE" ]; then
[ ! -f /lib/modules/misc/igb.ko ] || /sbin/insmod /lib/modules/misc/igb.ko
no_extra_lan_card="FALSE"
/bin/touch /tmp/option_1G
fi
for (( i=$DEFAULT_NIC_NUM; i<$MAX_EXTRA_LAN_CARD_PORT_NUM; i=i+1 ))
do
if [ -d /sys/class/net/eth$i ]; then
for (( j=0; j<${#LAN_CARD_10G_V2[@]}; j=j+1 ))
do
/bin/cat /sys/class/net/eth$i/device/uevent | grep ${LAN_CARD_10G_V2[$j]} 2>/dev/null 1>/dev/null
if [ $? = 0 ]; then
/bin/touch /var/option_extra_lan
$SETCFG "eth$i" "max speed" "10000" -f "/var/option_extra_lan"
EXTRA_LAN_CARD_PORT_NUM=$EXTRA_LAN_CARD_PORT_NUM+1
break;
fi
done
for (( j=0; j<${#LAN_CARD_1G_V2[@]}; j=j+1 ))
do
/bin/cat /sys/class/net/eth$i/device/uevent | grep ${LAN_CARD_1G_V2[$j]} 2>/dev/null 1>/dev/null
if [ $? = 0 ]; then
/bin/touch /var/option_extra_lan
$SETCFG "eth$i" "max speed" "1000" -f "/var/option_extra_lan"
EXTRA_LAN_CARD_PORT_NUM=$EXTRA_LAN_CARD_PORT_NUM+1
break;
fi
done
fi
done
if [ $no_extra_lan_card = "TRUE" ]; then
if [ $DEFAULT_NIC_NUM != $CONFIG_NIC_NUM ]; then
/bin/rm /var/option_extra_lan
/bin/rm /tmp/option_1G
/bin/rm /tmp/option_10G
fi
else
lan_port_num=$[$DEFAULT_NIC_NUM + $EXTRA_LAN_CARD_PORT_NUM]
$SETCFG "Network" "Interface Number" "$lan_port_num"
$SETCFG -f /etc/default_config/uLinux.conf "Network" "Interface Number" "$lan_port_num"
fi
$SETCFG -f /etc/default_config/uLinux.conf "Network" "Advanced Bonding Support" "TRUE"
[ -f /etc/init.d/network.sh_adv_bonding ] && /bin/cp /etc/init.d/network.sh_adv_bonding /etc/init.d/network.sh

21
check_nss2 Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/sh
_NSS2_SUPPORT=no
if [ -f /mnt/HDA_ROOT/update_pkg/SurveillanceStation/nvr_app2.tar.gz ] && [ ! -f /mnt/HDA_ROOT/update_pkg/nvr_app2.tar.gz ]; then
/bin/rm -f /mnt/HDA_ROOT/update_pkg/nvr_app2.tar.gz 2>/dev/null
/bin/ln -sf /mnt/HDA_ROOT/update_pkg/SurveillanceStation/nvr_app2.tar.gz /mnt/HDA_ROOT/update_pkg/
fi
_tmp=`/sbin/getcfg "NVR" "NSS Enabled" -d "no"`
if [ "x$_tmp" = "xyes" ]; then
_NSS2_SUPPORT=yes
else
if [ -f /mnt/HDA_ROOT/update_pkg/nvr_app2.tar.gz ] || [ -f /mnt/ext/opt/source/nvr_app2.tar.gz ]; then
/sbin/setcfg NVR "NSS Enabled" yes
_NSS2_SUPPORT=yes;
fi
_Internal_Model=`/sbin/getcfg System "Internal Model"`
if [ "x$_Internal_Model" = "xTS-269" ] || [ "x$_Internal_Model" = "xTS-469" ] || [ "x$_Internal_Model" = "xTS-669" ] || [ "x$_Internal_Model" = "xTS-869" ]; then
_NSS2_SUPPORT=yes
fi
fi

47
chkcfgpart.sh Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/sh
TMP_MP=/tmp/mp6
# check if the HAL subsystem exist
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
if [ -x /sbin/hal_app ]; then
BOOT_DEV=$(/sbin/hal_app --get_boot_pd port_id=0)
elif [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
BOOT_DEV="/dev/mtdblock"
else
BOOT_DEV="/dev/sdx"
fi
if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
NAS_CONFIG=${BOOT_DEV}5
NAS_CONFIG_SIZE=1024
else
NAS_CONFIG=${BOOT_DEV}6
NAS_CONFIG_SIZE=4096
fi
NAS_CONFIG_BAK=/tmp/nas_config.tgz
NAS_CONFIG_IMG=/tmp/nas_config.img
[ -d $TMP_MP ] || mkdir $TMP_MP
mount $NAS_CONFIG $TMP_MP
CFG_SIZE=`/bin/df -k | /bin/grep "$NAS_CONFIG" | /bin/awk '{print $2}'`
if [ $CFG_SIZE -ge $NAS_CONFIG_SIZE ]; then
#Backup /tmp/mp6
cd $TMP_MP
/bin/tar czf $NAS_CONFIG_BAK *
RET=$?
cd /
umount $TMP_MP
if [ $RET = 0 ]; then
/bin/dd if=/dev/zero of=$NAS_CONFIG_IMG bs=1k count=$NAS_CONFIG_SIZE
if [ $? = 0 ]; then
/sbin/mke2fs -F -v -m0 -b 1024 -I 128 $NAS_CONFIG_IMG
/bin/dd if=$NAS_CONFIG_IMG of=$NAS_CONFIG bs=1k count=$NAS_CONFIG_SIZE
mount $NAS_CONFIG $TMP_MP
/bin/tar xzf $NAS_CONFIG_BAK -C $TMP_MP
umount $TMP_MP
rm $NAS_CONFIG_IMG
fi
fi
rm $NAS_CONFIG_BAK
fi
umount $TMP_MP

49
cloud3p.sh Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/sh
EXE_CLOUD3P=/usr/sbin/cloud3p
DIR_VAULT_CONF=/etc/config/vaultServices
SZF_VAULT_CONF=vaultServices.config
SZP_VAULT_CONF_DEF=/etc/default_config/vaultServices/vaultServices.config
start()
{
if [ -f $EXE_CLOUD3P ]; then
echo "Startup all cloud related services..."
[ -d $DIR_VAULT_CONF ] || /usr/bin/install -d $DIR_VAULT_CONF
if [ ! -f $DIR_VAULT_CONF/$SZF_VAULT_CONF ] && [ -f $SZP_VAULT_CONF_DEF ]; then
/bin/cp -p $SZP_VAULT_CONF_DEF $DIR_VAULT_CONF/$SZF_VAULT_CONF
fi
$EXE_CLOUD3P --start
fi
}
stop()
{
if [ -f $EXE_CLOUD3P ]; then
echo "Shutting down all cloud related services..."
$EXE_CLOUD3P --stop
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
*)
echo "Usage: /etc/init.d/cloud3p.sh {start|stop|restart}"
exit 1
esac
exit 0

96
crond.sh Executable file
View File

@@ -0,0 +1,96 @@
#!/bin/sh
DAEMON_MGR="/sbin/daemon_mgr"
CROND="/usr/sbin/crond"
smart_entry_convert() {
hd=16
while [ $hd -gt 0 ]
do
old_str="qsmart -t short -d $hd"
index=$(printf "%02x" $hd)
new_str="hal_event --pd_self_test dev_id=0x000000${index},action=1"
/bin/sed -i "s/${old_str}/${new_str}/" /etc/config/crontab
hd=$(($hd - 1))
done
hd=16
while [ $hd -gt 0 ]
do
old_str="qsmart -t extend -d $hd"
index=$(printf "%02x" $hd)
new_str="hal_event --pd_self_test dev_id=0x000000${index},action=2"
/bin/sed -i "s/${old_str}/${new_str}/" /etc/config/crontab
hd=$(($hd - 1))
done
}
test -f $CROND || exit 0 # check if crond exists...
_crontab_path=/tmp/cron/crontabs
[ -d ${_crontab_path} ] || mkdir -p ${_crontab_path}
[ -f ${_crontab_path}/admin ] || ln -sf /etc/config/crontab ${_crontab_path}/admin
case "$1" in
start)
if [ x"`/bin/cat /etc/config/crontab | /bin/grep "hwclock"`" = x ]; then
echo "0 4 * * * /sbin/hwclock -s" >> /etc/config/crontab
fi
if [ x"`/bin/cat /etc/config/crontab | /bin/grep "vs_refresh"`" = x ]; then
echo "0 3 * * * /sbin/vs_refresh" >> /etc/config/crontab
fi
/bin/sed -i 's/0 \* \* \* \* \/sbin\/hwclock/0 4 \* \* \* \/sbin\/hwclock/' /etc/config/crontab
/bin/sed -i '/hdusb_copy/d' /etc/config/crontab
/bin/cat /etc/config/crontab | /bin/grep -v "backup_conf.sh" > /tmp/crontab
/bin/mv /tmp/crontab /etc/config/crontab
backup_en=`/sbin/getcfg BackupConfig Enable -d null`
if [ "x$backup_en" != "xFALSE" -a -x "/etc/init.d/backup_conf.sh" ]; then
backup_period=`/sbin/getcfg BackupConfig "period" -d 7`
case "$backup_period" in
1) #once a day
echo "4 3 * * * /etc/init.d/backup_conf.sh" >> /etc/config/crontab
;;
30) #once a month
echo "4 3 3 * * /etc/init.d/backup_conf.sh" >> /etc/config/crontab
;;
7) #once a week
echo "4 3 * * 3 /etc/init.d/backup_conf.sh" >> /etc/config/crontab
;;
*) #for testing
echo "*/3 * * * * /etc/init.d/backup_conf.sh" >> /etc/config/crontab
;;
esac
fi
if [ x"`/bin/cat /etc/config/crontab | /bin/grep "clean_reset_pwd"`" = x ]; then
/bin/echo "0 3 * * * /sbin/clean_reset_pwd" >> /etc/config/crontab
fi
if [ x"`/bin/cat /etc/config/crontab | /bin/grep "nss2_dusg"`" = x ]; then
echo "0-59/15 * * * * /etc/init.d/nss2_dusg.sh" >> /etc/config/crontab
fi
if [ -x /sbin/hal_app ]; then
smart_entry_convert
fi
/bin/sync
echo -n "Starting periodic command scheduler: "
$DAEMON_MGR crond start "$CROND -l 9 -c ${_crontab_path}"
echo "crond."
;;
stop)
echo -n "Stopping periodic command scheduler: "
$DAEMON_MGR crond stop "$CROND"
echo "crond."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $1 start|stop|restart"
exit 1
;;
esac
exit 0

264
cupsd.sh Executable file
View File

@@ -0,0 +1,264 @@
#/bin/sh
CUPS_CONF="/etc/config/cups/cupsd.conf"
TEMP="/tmp/cupsd.conf"
LPADMIN="/usr/local/sbin/lpadmin"
BACKEND_USB="/usr/lib/cups/backend/usb"
#LPADMIN="./systemv/lpadmin"
#BACKEND_USB="./backend/usb"
set_config()
{
[ ! -d /var/spool/cups ] && /bin/mkdir -p /var/spool/cups
[ ! -d /var/run/cups ] && /bin/mkdir -p /var/run/cups
if [ -f $CUPS_CONF ]; then
/bin/cat $CUPS_CONF|/bin/grep "BrowseRemoteProtocols" &> /dev/null
[ $? = 0 ] && return
fi
/bin/mkdir -p /etc/config/cups
echo "#" > /etc/config/cups/cupsd.conf
echo "# \"$Id: cupsd.sh,v 1.24 2011-11-23 04:52:13 aixchou Exp $\"" >> /etc/config/cups/cupsd.conf
echo "#" >> /etc/config/cups/cupsd.conf
echo "# Sample configuration file for the CUPS scheduler. See \"man cupsd.conf\" for a" >> /etc/config/cups/cupsd.conf
echo "# complete description of this file." >> /etc/config/cups/cupsd.conf
echo "#" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "# Log general information in error_log - change \"warn\" to \"debug\"" >> /etc/config/cups/cupsd.conf
echo "# for troubleshooting..." >> /etc/config/cups/cupsd.conf
echo "LogLevel warn" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "# Administrator user group..." >> /etc/config/cups/cupsd.conf
echo "SystemGroup administrators" >> /etc/config/cups/cupsd.conf
echo "ServerAlias *" >> /etc/config/cups/cupsd.conf
echo "PreserveJobHistory Yes" >> /etc/config/cups/cupsd.conf
echo "Include /etc/config/cups/cupsd.conf.maxjobs" >> /etc/config/cups/cupsd.conf
echo "Include /etc/config/cups/cupsd.conf.allowip" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "# Only listen for connections from the local machine." >> /etc/config/cups/cupsd.conf
echo "Listen *:631" >> /etc/config/cups/cupsd.conf
echo "Listen /var/run/cups/cups.sock" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "# Show shared printers on the local network." >> /etc/config/cups/cupsd.conf
echo "Browsing On" >> /etc/config/cups/cupsd.conf
echo "BrowseOrder allow,deny" >> /etc/config/cups/cupsd.conf
echo "BrowseAllow all" >> /etc/config/cups/cupsd.conf
echo "BrowseLocalProtocols CUPS" >> /etc/config/cups/cupsd.conf
echo "BrowseRemoteProtocols none" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "# Default authentication type, when authentication is required..." >> /etc/config/cups/cupsd.conf
echo "DefaultAuthType Basic" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "# Restrict access to the server..." >> /etc/config/cups/cupsd.conf
echo "#<Location />" >> /etc/config/cups/cupsd.conf
echo "# Order allow,deny" >> /etc/config/cups/cupsd.conf
echo "# allow all" >> /etc/config/cups/cupsd.conf
echo "#</Location>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "# Restrict access to the admin pages..." >> /etc/config/cups/cupsd.conf
echo "<Location /admin>" >> /etc/config/cups/cupsd.conf
echo " Order allow,deny" >> /etc/config/cups/cupsd.conf
echo "</Location>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "# Restrict access to configuration files..." >> /etc/config/cups/cupsd.conf
echo "<Location /admin/conf>" >> /etc/config/cups/cupsd.conf
echo " AuthType Default" >> /etc/config/cups/cupsd.conf
echo " Require user @SYSTEM" >> /etc/config/cups/cupsd.conf
echo " Order allow,deny" >> /etc/config/cups/cupsd.conf
echo "</Location>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "# Set the default printer/job policies..." >> /etc/config/cups/cupsd.conf
echo "<Policy default>" >> /etc/config/cups/cupsd.conf
echo " # Job-related operations must be done by the owner or an administrator..." >> /etc/config/cups/cupsd.conf
echo " <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job CUPS-Get-Document>" >> /etc/config/cups/cupsd.conf
echo " Require user @OWNER @SYSTEM" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo " # All administration operations require an administrator to authenticate..." >> /etc/config/cups/cupsd.conf
echo " <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default CUPS-Get-Devices>" >> /etc/config/cups/cupsd.conf
echo " AuthType Default" >> /etc/config/cups/cupsd.conf
echo " Require user @SYSTEM" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo " # All printer operations require a printer operator to authenticate..." >> /etc/config/cups/cupsd.conf
echo " <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After CUPS-Accept-Jobs CUPS-Reject-Jobs>" >> /etc/config/cups/cupsd.conf
echo " AuthType Default" >> /etc/config/cups/cupsd.conf
echo " Require user @SYSTEM" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo " # Only the owner or an administrator can cancel or authenticate a job..." >> /etc/config/cups/cupsd.conf
echo " <Limit Cancel-Job CUPS-Authenticate-Job>" >> /etc/config/cups/cupsd.conf
echo " Require user @OWNER @SYSTEM" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo " <Limit All>" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "</Policy>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "# Set the authenticated printer/job policies..." >> /etc/config/cups/cupsd.conf
echo "<Policy authenticated>" >> /etc/config/cups/cupsd.conf
echo " # Job-related operations must be done by the owner or an administrator..." >> /etc/config/cups/cupsd.conf
echo " <Limit Create-Job Print-Job Print-URI>" >> /etc/config/cups/cupsd.conf
echo " AuthType Default" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo " <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job CUPS-Get-Document>" >> /etc/config/cups/cupsd.conf
echo " AuthType Default" >> /etc/config/cups/cupsd.conf
echo " Require user @OWNER @SYSTEM" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo " # All administration operations require an administrator to authenticate..." >> /etc/config/cups/cupsd.conf
echo " <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>" >> /etc/config/cups/cupsd.conf
echo " AuthType Default" >> /etc/config/cups/cupsd.conf
echo " Require user @SYSTEM" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo " # All printer operations require a printer operator to authenticate..." >> /etc/config/cups/cupsd.conf
echo " <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After CUPS-Accept-Jobs CUPS-Reject-Jobs>" >> /etc/config/cups/cupsd.conf
echo " AuthType Default" >> /etc/config/cups/cupsd.conf
echo " Require user @SYSTEM" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo " # Only the owner or an administrator can cancel or authenticate a job..." >> /etc/config/cups/cupsd.conf
echo " <Limit Cancel-Job CUPS-Authenticate-Job>" >> /etc/config/cups/cupsd.conf
echo " AuthType Default" >> /etc/config/cups/cupsd.conf
echo " Require user @OWNER @SYSTEM" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo " <Limit All>" >> /etc/config/cups/cupsd.conf
echo " Order deny,allow" >> /etc/config/cups/cupsd.conf
echo " </Limit>" >> /etc/config/cups/cupsd.conf
echo "</Policy>" >> /etc/config/cups/cupsd.conf
echo "" >> /etc/config/cups/cupsd.conf
echo "#" >> /etc/config/cups/cupsd.conf
echo "# End of \"$Id: cupsd.sh,v 1.24 2011-11-23 04:52:13 aixchou Exp $\"." >> /etc/config/cups/cupsd.conf
echo "#" >> /etc/config/cups/cupsd.conf
echo "MaxJobsPerPrinter 500" > /etc/config/cups/cupsd.conf.maxjobs
echo "<Location />" > /etc/config/cups/cupsd.conf.allowip
echo " Order allow,deny" >> /etc/config/cups/cupsd.conf.allowip
echo " allow all" >> /etc/config/cups/cupsd.conf.allowip
echo "</Location>" >> /etc/config/cups/cupsd.conf.allowip
}
cups_del_all_printers()
{
for i in 1 2 3 4 5 6 7; do
/usr/local/sbin/lpstat -t|/bin/grep printer|/bin/cut -d' ' -f2|xargs /usr/local/sbin/lpadmin -x > /dev/null 2>&1
done
/bin/rm -f /var/log/cups/* 2> /dev/null
}
cups_del_printer()
{
index="$1"
[ "$index" = "1" ] && index=""
local printer=`/sbin/getcfg "Printers" "Name$index"`
$LPADMIN -x $printer 2> /dev/null
}
add_bonjour_printer()
{
index="$1"
[ "$index" = "1" ] && index=""
/sbin/getcfg "Bonjour Service" "PRINTER$index" > /dev/null 2>&1
if [ $? != 0 ]; then
/sbin/setcfg "Bonjour Service" "PRINTER$index" "1"
local name=`/sbin/getcfg "Printers" "Name$index" -d "printer$index"`
/sbin/setcfg "Bonjour Service" "PRINTER Service Name$index" "$name"
fi
}
cups_add_printer()
{
index="$1"
[ "$index" = "1" ] && index=""
local phy_exist=`/sbin/getcfg "Printers" "Phy exist$index"`
#echo "index = $index, phy_exit = $phy_exist"
[ "x$phy_exist" = "x" ] || [ "$phy_exist" = "0" ] && return
local printer=`/sbin/getcfg "Printers" "Name$index" -d "printer$index"`
local printer_model=`/sbin/getcfg "Printers" "Model$index"`
local printer_sn=`/sbin/getcfg "Printers" "SN$index" -d "unknow"`
if [ "$printer_sn" != "unknow" ]; then
local printer_uri=`$BACKEND_USB 2> /dev/null|/bin/grep "$printer_model"|/bin/grep "$printer_sn"|/bin/grep -v FAX|/bin/cut -d ' ' -f 2`
else
local printer_uri=`$BACKEND_USB 2> /dev/null|/bin/grep "$printer_model"|/bin/grep -v FAX|/bin/cut -d ' ' -f 2`
fi
if [ "$printer_uri" = "" ]; then
sleep 2
if [ "$printer_sn" != "unknow" ]; then
printer_uri=`$BACKEND_USB 2> /dev/null|/bin/grep "$printer_model"|/bin/grep "$printer_sn"|/bin/cut -d ' ' -f 2`
else
printer_uri=`$BACKEND_USB 2> /dev/null|/bin/grep "$printer_model"|/bin/cut -d ' ' -f 2`
fi
[ "$printer_uri" = "" ] && echo "can't get printer uri!" && exit 1
fi
#echo "printer = $printer uri = $printer_uri"
$LPADMIN -p $printer -v $printer_uri -o printer-error-policy=retry-job -E
add_bonjour_printer $index
}
start()
{
set_config
/usr/sbin/cupsd -c /etc/config/cups/cupsd.conf
#add or delete printers
for i in 1 2 3 4 5 6 7; do
index="$i"
[ "$index" = "1" ] && index=""
local phy_exist=`/sbin/getcfg "Printers" "Phy exist$index"`
if [ "x$phy_exist" = "x" ] || [ "$phy_exist" = "0" ]; then
cups_del_printer $i
elif [ "$phy_exist" = "1" ]; then
cups_add_printer $i
fi
done
}
stop()
{
/usr/bin/killall cupsd 2> /dev/null
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
add_printer)
cups_add_printer $2
;;
del_printer)
cups_del_printer $2
;;
del_all_printers)
cups_del_all_printers
;;
*)
/bin/echo $"Usage: $0 {start|stop|restart|add_printer|del_printer|del_all_printers}"
exit 1
esac
exit 0

16
ddns_update.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/sh
# ddns_update.sh This shell script takes care of ddns updating
#
# description: ez_ipupdate provide register domain name from special server.
result=0
exec /etc/init.d/ddns_update_for_cgi.sh &
result=$?
#if [ $result -eq 0 ]; then
# /sbin/write_log "DDNS was updated successfully." 4
#else [ $result -eq 1 ]
# /sbin/write_log "Failed to update DDNS." 2
#fi
exit $result

105
ddns_update_for_cgi.sh Executable file
View File

@@ -0,0 +1,105 @@
#!/bin/sh
# ddns_update.sh This shell script takes care of ddns updating
#
# description: ez_ipupdate provide register domain name from special server.
echo -n "Starting ddns update: "
rm /tmp/ddns.result -f
DDNS_TMP_FILE="/var/ddns_tmp.conf"
check_ddns_temp_file()
{
if [ ! -f ${DDNS_TMP_FILE} ]; then
/bin/echo "${DDNS_TMP_FILE} is not exist"
/bin/echo "[DDNS]" > ${DDNS_TMP_FILE}
/bin/echo "Support = "`/sbin/getcfg "DDNS" "Support" -u -d "TRUE"` >> ${DDNS_TMP_FILE}
/bin/echo "Enable = "`/sbin/getcfg "DDNS" "Enable" -u -d "FALSE"` >> ${DDNS_TMP_FILE}
/bin/echo "Server Type = "`/sbin/getcfg "DDNS" "Server Type" -u -d "0"` >> ${DDNS_TMP_FILE}
/bin/echo "Config File = "`/sbin/getcfg "DDNS" "Config File" -d "/etc/ddns_update.conf"` >> ${DDNS_TMP_FILE}
/bin/echo "Check External IP = "`/sbin/getcfg "DDNS" "Check External IP" -d "0"` >> ${DDNS_TMP_FILE}
/bin/echo "User Name = "`/sbin/getcfg "DDNS" "User Name" -d ""` >> ${DDNS_TMP_FILE}
/bin/echo "Password = "`/sbin/getcfg "DDNS" "Password" -d ""` >> ${DDNS_TMP_FILE}
/bin/echo "Host Name = "`/sbin/getcfg "DDNS" "Host Name" -d ""` >> ${DDNS_TMP_FILE}
/bin/echo "DDNS Type = "`/sbin/getcfg "DDNS" "DDNS Type" -d "0"` >> ${DDNS_TMP_FILE}
fi
}
check_ddns_temp_file
[ -f /usr/sbin/noip2c ] || ln -sf /usr/sbin/noip2 /usr/sbin/noip2c
if [ `/sbin/getcfg "DDNS" "Support" -u -d "TRUE" -f ${DDNS_TMP_FILE}` = TRUE ]
then
if [ `/sbin/getcfg "DDNS" "Enable" -u -d "FALSE" -f ${DDNS_TMP_FILE}` = FALSE ]
then
echo "disabled."
exit 0
fi
if [ `/sbin/getcfg "DDNS" "Server Type" -u -d "0" -f ${DDNS_TMP_FILE}` != 5 ]
then
/usr/sbin/create_ddns_conf > /dev/null
result=$?
if [ $result -ne 0 ]
then
echo "ERROR."
exit 1
fi
config_file=`/sbin/getcfg "DDNS" "Config File" -d "/etc/ddns_update.conf" -f ${DDNS_TMP_FILE}`
/usr/sbin/ez-ipupdate -c $config_file 2>/dev/null
result=$?
else
if [ ! -f /etc/config/no-ip2.conf ]; then
username=`/sbin/getcfg "DDNS" "User Name" -d "" -f ${DDNS_TMP_FILE}`
password=`/sbin/getcfg "DDNS" "Password" -d "" -f ${DDNS_TMP_FILE}`
hostname=`/sbin/getcfg "DDNS" "Host Name" -d "" -f ${DDNS_TMP_FILE}`
externalIP=`/sbin/getcfg "DDNS" "Check External IP" -d "5" -f ${DDNS_TMP_FILE}`
if [ $externalIP = 0 ]; then
externalIP=5
fi
/usr/sbin/noip2c -C -u ${username} -p ${password} -n ${hostname} -U ${externalIP}
fi
if [ -f /etc/config/no-ip2.conf ]; then
/sbin/daemon_mgr noip2 start /usr/sbin/noip2 1>/dev/null 2>/dev/null
result=0
echo "DDNS was updated successfully"
else
/sbin/setcfg "DDNS" "Enable" "FALSE"
/sbin/setcfg "DDNS" "Enable" "FALSE" -f ${DDNS_TMP_FILE}
/sbin/write_log "Enabling Dynamic DNS Service failed due to noip2 execution failure." 2
result=1
fi
if [ $result -ne 0 ];then
echo $result > /tmp/ddns.result
else
echo "DDNS was updated successfully"
fi
echo -n "noip2"
echo "."
touch /var/lock/subsys/noip2
exit $result
fi
if [ $result -ne 0 ]
then
echo $result > /tmp/ddns.result
# /sbin/write_log "Failed to update DDNS." 2
else
echo "DDNS was updated successfully"
# /sbin/write_log "DDNS was updated successfully." 4
fi
#update record
/sbin/setcfg "DDNS" "Update Server Response" ${result} -f ${DDNS_TMP_FILE}
[ -f /sbin/set_ipupatetime ] && /sbin/set_ipupatetime "1"
echo -n "ez-ipupdate"
echo "."
touch /var/lock/subsys/ez-ipupdate
exit $result
else
echo "Un-support"
fi
exit 1

73
dhcpd.sh Executable file
View File

@@ -0,0 +1,73 @@
#!/bin/sh
# dhcpd This shell script takes care of starting and stopping
# dhcpd.
#
# description: dhcpd provide access to Dynamic Host Control Protocol.
BOND_NIC=`/sbin/getcfg "Network" "BONDING NICs" -d "0"`
NIC_NUM=`/sbin/getcfg "Network" "Interface Number" -d "2"`
# See how we were called.
case "$1" in
start)
# Stop daemons
/bin/kill -HUP `/bin/pidof dhcpd`
# Start daemons
/usr/sbin/create_dhcpd_conf > /dev/null
echo -n "Starting dhcpd: "
if [ `/sbin/getcfg "DHCP Server" "Enable" -u -d "FALSE"` = FALSE ]
then
echo disabled
exit 0
fi
DEV=`/sbin/getcfg "DHCP Server" "Interface" -d "eth0"`
vlan_enable=`/sbin/getcfg $DEV vlan_enable -d "FALSE"`
if [ "$vlan_enable" = "TRUE" ]; then
vlan_id=`/sbin/getcfg $DEV vlan_id -d ""`
if [ "x$vlan_id" != "x" ]; then
DEV="$DEV.$vlan_id"
fi
fi
[ -d /etc/config/dhcp ] || /bin/mkdir /etc/config/dhcp;
[ -d /var/state ] || /bin/mkdir /var/state
if [ ! -L /var/state/dhcp ]; then
/bin/ln -sf /etc/config/dhcp /var/state/dhcp
/bin/touch /var/state/dhcp/dhcpd.leases
fi
/sbin/daemon_mgr dhcpd start "/usr/local/sbin/dhcpd -q $DEV 2>/dev/null 1>/dev/null"
echo -n "dhcpd on $DEV"
echo "."
touch /var/lock/subsys/dhcpd
# echo -n "ddns update"
# /etc/init.d/ddns_update.sh > /dev/null
# echo "."
;;
stop)
# Stop daemons.
echo -n "Shutting down dhcpd: "
/sbin/daemon_mgr dhcpd stop /usr/local/sbin/dhcpd
#kill -HUP `/bin/pidof dhcpd`
# local pid
pid=`/bin/pidof dhcpd`
if [ ! -z $pid ]; then
kill $pid
fi
echo -n "dhcpd"
echo "."
rm -f /var/lock/subsys/dhcpd
;;
restart)
$0 start
RETVAL=$?
;;
*)
echo "Usage: dhcpd { [start]|stop|[restart] }"
exit 1
esac
exit 0

61
fbdisk.sh Executable file
View File

@@ -0,0 +1,61 @@
#!/bin/sh
FBDISK_MODULE=/lib/modules/misc/fbdisk.ko
module_fbdisk="fbdisk"
device_fbdisk="fbdisk"
module_fbsnap="fbsnap"
device_fbsnap="fbsnap"
max_device=256
start_fbdisk()
{
/sbin/insmod $FBDISK_MODULE
major_fbdisk=`/bin/awk "\\$2==\"$module_fbdisk\" {print \\$1}" /proc/devices`
major_fbdisk=$(($major_fbdisk+0))
major_fbsnap=`/bin/awk "\\$2==\"$module_fbsnap\" {print \\$1}" /proc/devices`
major_fbsnap=$(($major_fbsnap+0))
if [ $major_fbdisk -gt 0 ];
then
i=0
while [ "$i" -ne ${max_device} ]; do
/bin/mknod /dev/${device_fbdisk}${i} b $major_fbdisk $i
/bin/mknod /dev/${device_fbsnap}${i} b $major_fbsnap $i
/bin/chmod 444 /dev/${device_fbsnap}${i}
i=$(($i+1))
done
fi
}
stop_fbdisk()
{
/sbin/rmmod $FBDISK_MODULE
i=0
while [ "$i" -ne ${max_device} ]; do
/bin/rm -f /dev/${device_fbdisk}${i}
/bin/rm -f /dev/${device_fbsnap}${i}
i=$(($i+1))
done
}
# check if fbdisk.ko exist
[ -f $FBDISK_MODULE ] || exit 0
case "$1" in
start)
start_fbdisk;
;;
stop)
stop_fbdisk;
;;
restart)
stop_fbdisk;
sleep 1
start_fbdisk;
;;
*)
echo "Usage: %0 (start|stop|restart)"
exit 1
esac
exit 0

78
ftp.sh Executable file
View File

@@ -0,0 +1,78 @@
#!/bin/sh
RETVAL=0
STUNNEL_KEY=/etc/config/stunnel/backup.key
STUNNEL_CERT=/etc/config/stunnel/backup.cert
STUNNEL_KEY_DEFAULT=/etc/default_config/stunnel/backup.key
STUNNEL_CERT_DEFAULT=/etc/default_config/stunnel/backup.cert
prepare_cert_key()
{
if [ ! -f $STUNNEL_CERT ] && [ -f $STUNNEL_CERT_DEFAULT ]; then
/bin/cp $STUNNEL_CERT_DEFAULT $STUNNEL_CERT 2>>/dev/null
fi
if [ ! -f $STUNNEL_KEY ] && [ -f $STUNNEL_KEY_DEFAULT ]; then
/bin/cp $STUNNEL_KEY_DEFAULT $STUNNEL_KEY 2>>/dev/null
fi
}
case "$1" in
start)
echo -n "Starting FTP services: "
prepare_cert_key
if [ -f /etc/init.d/rcv_port.sh ]; then
/etc/init.d/rcv_port.sh start
fi
if [ -f /usr/local/sbin/proftpd ] && [ `/sbin/getcfg FTP Enable -u -d FALSE` = TRUE ]; then
/sbin/daemon_mgr proftpd start "TZ=/etc/localtime /usr/local/sbin/proftpd -n > /dev/null 2>&1 &"
# /sbin/daemon_mgr proftpd start "/usr/local/sbin/proftpd"
fi
RETVAL=$?
echo "proftpd."
;;
stop)
echo "Shutting down FTP services: "
/sbin/daemon_mgr proftpd stop "/usr/local/sbin/proftpd"
/bin/kill -INT `pidof proftpd` 1>/dev/null 2>/dev/null
/usr/bin/killall proftpd 1>/dev/null 2>/dev/null
RETVAL=$?
count=5
while [ $count -gt 0 ]; do
/bin/echo -n "."
/bin/pidof proftpd >/dev/null 2>&1
if [ $? -ne 0 ]; then
#no any proftpd process.
#count=0
break
else
/bin/sleep 1
fi
count=$(($count-1));
done
if [ $count == 0 ]; then
/bin/kill -9 `/bin/pidof proftpd`
RETVAL=$?
fi
/bin/echo
;;
restart)
$0 stop
$0 start
RETVAL=$?
echo "stopped."
;;
reconfig)
echo "Reconfigure FTP services: "
pid=`/bin/pidof proftpd`
if [ "$pid" != "" ]; then
echo "reconfig ftp success"
/bin/kill -HUP $pid
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reconfig}"
exit 1
esac
exit $RETVAL

78
functions Executable file
View File

@@ -0,0 +1,78 @@
#!/bin/sh
local_check_sum()
{
if [ ! -f $1 ] || [ ! -f $2 ];then
return 1
fi
local file_cksum=`/sbin/cksum $1`
local file_crc=`echo $file_cksum | cut -d ' ' -f 1`
local file_size=`echo $file_cksum | cut -d ' ' -f 2`
local cksum_cksum=`cat $2`
local cksum_crc=`echo $cksum_cksum | cut -d ' ' -f 1`
local cksum_size=`echo $cksum_cksum | cut -d ' ' -f 2`
if [ $file_crc = $cksum_crc ] && [ $file_size = $cksum_size ]; then
return 0
fi
return 1
}
install_PKGs()
{
local FLASH_TMP="/flashfs_tmp"
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
local BOOT_DEV=$(/sbin/hal_app --get_boot_pd port_id=0)
else
local BOOT_DEV="/dev/sdx"
fi
local FLASH_RFS1=${BOOT_DEV}2
local FLASH_RFS2=${BOOT_DEV}3
local _INSTALL_PATH=$1
local BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf`
[ "x${BOOT_CONF}" = "xTS-NASX86" ] || return 0
[ -d $FLASH_TMP ] || /bin/mkdir $FLASH_TMP
/bin/mount $FLASH_RFS1 $FLASH_TMP -o ro
[ -d ${_INSTALL_PATH} ] || /bin/mkdir ${_INSTALL_PATH}
[ -d ${_INSTALL_PATH} ] || return 1
local_check_sum "$FLASH_TMP/boot/qpkg.tar" "$FLASH_TMP/boot/qpkg.tar.cksum"
if [ $? = 0 ]; then
/bin/tar xf $FLASH_TMP/boot/qpkg.tar -C ${_INSTALL_PATH}
/bin/umount $FLASH_RFS1
else
/bin/umount $FLASH_RFS1
/bin/mount $FLASH_RFS2 $FLASH_TMP -o ro
local_check_sum "$FLASH_TMP/boot/qpkg.tar" "$FLASH_TMP/boot/qpkg.tar.cksum"
[ $? = 0 ] && /bin/tar xf $FLASH_TMP/boot/qpkg.tar -C ${_INSTALL_PATH}
/bin/umount $FLASH_RFS2
fi
/bin/rmdir $FLASH_TMP
}
FindDefVol()
{
VOLMPS="HDA_DATA HDB_DATA HDC_DATA HDD_DATA HDE_DATA HDF_DATA HDG_DATA HDH_DATA HDI_DATA HDJ_DATA HDK_DATA HDL_DATA HDM_DATA HDN_DATA HDO_DATA HDP_DATA MD0_DATA MD1_DATA MD2_DATA MD3_DATA MD4_DATA MD5_DATA"
[ -x /usr/bin/dirname ] || /bin/ln -sf /bin/busybox /usr/bin/dirname
_pdir=`/sbin/getcfg Public path -f /etc/config/smb.conf`
if [ ! -z $_pdir ] && [ -d $_pdir ];then
DEF_VOLMP=$(/usr/bin/dirname "$_pdir")
else
DEF_VOLMP=
fi
if [ -z $DEF_VOLMP ]; then
PubShare=`/sbin/getcfg SHARE_DEF defPublic -d Public -f /etc/config/def_share.info`
for _vn in $VOLMPS; do
[ -d "/share/$_vn/${PubShare}" ] && DEF_VOLMP="/share/$_vn"
done
fi
if [ ! -z "$DEF_VOLMP" ] && [ -d "$DEF_VOLMP" ]; then
/bin/grep "$DEF_VOLMP" /proc/mounts 1>/dev/null 2>/dev/null
return $?
fi
return 1
}

50
genLanglist.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/sh
#This shell script will creat support language list accroding the language file's exist.
_LANG_FOLDER=(/home/httpd/cgi-bin/inc/)
_LANG_FILE=(/home/httpd/cgi-bin/inc/lang_eng.js /home/httpd/cgi-bin/inc/lang_chs.js /home/httpd/cgi-bin/inc/lang_cht.js /home/httpd/cgi-bin/inc/lang_cze.js /home/httpd/cgi-bin/inc/lang_dan.js /home/httpd/cgi-bin/inc/lang_ger.js /home/httpd/cgi-bin/inc/lang_spa.js /home/httpd/cgi-bin/inc/lang_fre.js /home/httpd/cgi-bin/inc/lang_ita.js /home/httpd/cgi-bin/inc/lang_jpn.js /home/httpd/cgi-bin/inc/lang_kor.js /home/httpd/cgi-bin/inc/lang_nor.js /home/httpd/cgi-bin/inc/lang_pol.js /home/httpd/cgi-bin/inc/lang_rus.js /home/httpd/cgi-bin/inc/lang_fin.js /home/httpd/cgi-bin/inc/lang_swe.js /home/httpd/cgi-bin/inc/lang_dut.js /home/httpd/cgi-bin/inc/lang_es-mex.js /home/httpd/cgi-bin/inc/lang_tur.js /home/httpd/cgi-bin/inc/lang_tha.js /home/httpd/cgi-bin/inc/lang_por.js /home/httpd/cgi-bin/inc/lang_hun.js /home/httpd/cgi-bin/inc/lang_grk.js /home/httpd/cgi-bin/inc/lang_rom.js)
_QUICK_LANG_FILE=(/home/httpd/cgi-bin/quick/inc/lang_eng.js /home/httpd/cgi-bin/quick/inc/lang_chs.js /home/httpd/cgi-bin/quick/inc/lang_cht.js /home/httpd/cgi-bin/quick/inc/lang_cze.js /home/httpd/cgi-bin/quick/inc/lang_dan.js /home/httpd/cgi-bin/quick/inc/lang_ger.js /home/httpd/cgi-bin/quick/inc/lang_spa.js /home/httpd/cgi-bin/quick/inc/lang_fre.js /home/httpd/cgi-bin/quick/inc/lang_ita.js /home/httpd/cgi-bin/quick/inc/lang_jpn.js /home/httpd/cgi-bin/quick/inc/lang_kor.js /home/httpd/cgi-bin/quick/inc/lang_nor.js /home/httpd/cgi-bin/quick/inc/lang_pol.js /home/httpd/cgi-bin/quick/inc/lang_rus.js /home/httpd/cgi-bin/quick/inc/lang_fin.js /home/httpd/cgi-bin/quick/inc/lang_swe.js /home/httpd/cgi-bin/quick/inc/lang_dut.js /home/httpd/cgi-bin/quick/inc/lang_tha.js /home/httpd/cgi-bin/quick/inc/lang_por.js /home/httpd/cgi-bin/quick/inc/lang_hun.js /home/httpd/cgi-bin/quick/inc/lang_grk.js /home/httpd/cgi-bin/quick/inc/lang_rom.js)
_code=(\'en\' \'zh_CN\' \'zh_TW\' \'cz\' \'da\' \'de\' \'es\' \'fr\' \'it\' \'ja\' \'ko\' \'no\' \'pl\' \'ru\' \'fi\' \'sv_SE\' \'dut\' \'es\' \'tur\' \'tha\' \'por\' \'hun\' \'grk\' \'rom\' )
_display_name=("'English'" "'简体中文'" "'繁體中文'" "'Czech'" "'Dansk'" "'Deutsch'" "'Español'" "'Français'" "'Italiano'" "'日本語'" "'한글'" "'Norsk'" "'Polski'" "'Русский'" "'Suomi'" "'Svenska'" "'Nederlands'" "'Español mexicano'" "'Turk dili'" "'ไทย'" "'Português'" "'Magyar'" "'Ελληνικά'" "'Român'")
_charset=(\'ascii\' \'utf-8\' \'UTF-8\' \'UTF-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\' \'utf-8\')
_cookie_name=(\'ENG\' \'SCH\' \'TCH\' \'CZE\' \'DAN\' \'GER\' \'SPA\' \'FRE\' \'ITA\' \'JPN\' \'KOR\' \'NOR\' \'POL\' \'RUS\' \'FIN\' \'SWE\' \'DUT\' \'ESM\' \'TUR\' \'THA\' \'POR\' \'HUN\' \'GRK\' \'ROM\')
_file_name=(\'eng\' \'chs\' \'cht\' \'cze\' \'dan\' \'ger\' \'spa\' \'fre\' \'ita\' \'jpn\' \'kor\' \'nor\' \'pol\' \'rus\' \'fin\' \'swe\' \'dut\' \'es-mex\' \'tur\' \'tha\' \'por\' \'hun\' \'grk\' \'rom\')
_output_file=/home/httpd/ajax_obj/extjs/languages.js
str=""
element_count=${#_LANG_FILE[@]}
index=0
#lang_folder=1 : /home/httpd/cgi-bin/inc/ exist
#lang_folder=0 : /home/httpd/cgi-bin/inc/ do not exist
test -e ${_LANG_FILE[0]} && lang_folder=1 || lang_folder=0
if [ ${lang_folder} -eq 1 ]; then
while [ "$index" -lt "$element_count" ]; do
if [ -f ${_LANG_FILE[$index]} ]; then
firstline="["${_code[$index]}","${_display_name[$index]}","${_charset[$index]}","${_cookie_name[$index]}","${_file_name[$index]}"],"
str=${str}${firstline}
fi
index=`/usr/bin/expr $index + 1`
done
else
while [ "$index" -lt "${#_QUICK_LANG_FILE[@]}" ]; do
if [ -f ${_QUICK_LANG_FILE[$index]} ]; then
firstline="["${_code[$index]}","${_display_name[$index]}","${_charset[$index]}","${_cookie_name[$index]}","${_file_name[$index]}"],"
str=${str}${firstline}
fi
index=`/usr/bin/expr $index + 1`
done
fi
count_str=${#str}
restult=''
#echo ${str}
if [ "$count_str" -gt 0 ]; then
result=${str::$count_str -1 }
fi
#Display and output to $_output_file
echo "Ext.namespace('Ext.exampledata');" > $_output_file
echo "Ext.exampledata.languages = ["$result"];" >> $_output_file

23
gen_issue.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/sh
BOND_SUP=`/sbin/getcfg "Network" "BONDING Support" -d "FALSE"`
if [ "$BOND_SUP" = "TRUE" ]; then
IP=`/sbin/ifconfig bond0 | grep "inet addr" | cut -f 2 -d ':' | cut -f 1 -d ' '`
else
IP=`/sbin/ifconfig eth0 | grep "inet addr" | cut -f 2 -d ':' | cut -f 1 -d ' '`
fi
if [ "`/sbin/getcfg "Project" "Name" -d "null" -f /var/default`" != "null" ]; then
echo "" > /etc/issue
echo -n "Welcome to `/sbin/getcfg System Model -d NAS`, " >> /etc/issue
echo "`/sbin/getcfg System Manufacturer -f /etc/default_config/uLinux.conf`." >> /etc/issue
echo "" >> /etc/issue
elif [ -f /etc/IS_G ]; then
echo "" > /etc/issue
echo -n "Welcome to NAS Server" >> /etc/issue
echo "" >> /etc/issue
else
echo "" > /etc/issue
echo "Welcome to `/sbin/getcfg System Model -d NAS`($IP), QNAP Systems, Inc." >> /etc/issue
echo "" >> /etc/issue
fi

258
genpowerfail.sh Executable file
View File

@@ -0,0 +1,258 @@
#!/bin/sh
#
# genpowerfail.sh This script is run when the UPS tells the system
# the power has gone. Tell everybody, ans start the
# shutdown based on the failure type.
# This script is also being run when the power comes
# up again (if it does in time!)
#
# Version: /etc/genpowerfail 1.0.1
# /etc/init.d/genpowerfail.sh 1.0.2
#
# Author: Tom Webster <webster@kaiwan.com>
#
#
# Modification:
# 2002/03/28 by Tiger Fu <tigerfu@iei.com.tw
# Set the path.
PATH=/sbin:/etc:/bin:/usr/bin
# Set location of upsstatus file
statpath="/etc/upsstatus"
# Set location of file containing PID of running shutdowns
spidpath="/etc/shutdownpid"
restart_time=0
POWER_MODE=`/sbin/getcfg UPS "Power Loss Mode" -d Standby`
# See what happened.
case "$1" in
start)
# Called with a powerfail event, check to see if a shutdown is running, and stop it if it is.
if [ -f $spidpath ]
then
# Shutdown is running, kill it to process the new event
# shutdown -c "Halting running shutdown to process power event...." &
# kill `pidof halt`
if [ $POWER_MODE = Shutdown ]
then
/bin/kill `/bin/pidof poweroff`
else
if [ -e "/tmp/ups_stop_service" ]; then
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
/sbin/setcfg UPS "AC Power" OK
else
/sbin/config_util 1
/sbin/storage_boot_init 1
/sbin/setcfg UPS "AC Power" OK
/bin/umount /mnt/HDA_ROOT
fi
/sbin/reboot
else
/bin/kill `/bin/pidof ups_stop_service`
fi
fi
fi
if [ $POWER_MODE = Shutdown ]
then
restart_time=`/sbin/getcfg UPS "Shutdown System In" -d 5`
else
restart_time=`/sbin/getcfg UPS "Standby System In" -d 5`
fi
echo $restart_time
# Get power problem and act on it
if [ -r $statpath ]
then
stats=`head $statpath`
echo $stats
case "$stats" in
FAIL) # Power is down
if [ -f /var/run/shutdown.pid ]
then
# kill `pidof shutdown`
# kill `pidof halt`
if [ $POWER_MODE = Shutdown ]
then
/bin/kill `/bin/pidof poweroff`
else
if [ -e "/tmp/ups_stop_service" ]; then
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
/sbin/setcfg UPS "AC Power" OK
else
/sbin/config_util 1
/sbin/storage_boot_init 1
/sbin/setcfg UPS "AC Power" OK
/bin/umount /mnt/HDA_ROOT
fi
/sbin/reboot
else
/bin/kill `/bin/pidof ups_stop_service`
fi
fi
fi
# shutdown -h +$restart_time &
time=$restart_time
time=`expr ${time} \* 60`
# /sbin/halt -d +${time} &
if [ $POWER_MODE = Shutdown ]
then
/sbin/poweroff -d +${time} &
else
/usr/sbin/ups_stop_service ${time} &
fi
#"THE POWER IS DOWN! SHUTTING DOWN SYSTEM! PLEASE LOG OFF NOW!" < /dev/console &
;;
SCRAM) # Battery is low
if [ -f /var/run/shutdown.pid ]
then
# kill `pidof shutdown`
# kill `pidof halt`
if [ $POWER_MODE = Shutdown ]
then
/bin/kill `/bin/pidof poweroff`
else
if [ -e "/tmp/ups_stop_service" ]; then
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
/sbin/setcfg UPS "AC Power" OK
else
/sbin/config_util 1
/sbin/storage_boot_init 1
/sbin/setcfg UPS "AC Power" OK
/bin/umount /mnt/HDA_ROOT
fi
/sbin/reboot
else
/bin/kill `/bin/pidof ups_stop_service`
fi
fi
fi
# sutdown -h now &
time=$restart_time
time=`expr ${time} \* 60`
# /sbin/halt -d +${time} &
if [ $POWER_MODE = Shutdown ]
then
/sbin/poweroff -d +${time} &
else
/usr/sbin/ups_stop_service ${time} &
fi
#"THE POWER IS DOWN! BATTERY POWER IS LOW! EMERGENCY SHUTDOWN!" < /dev/console &
;;
CABLE) # Possible bad cable
# shutdown -c "Connectation Lose"
# kill `pidof halt`
if [ $POWER_MODE = Shutdown ]
then
/bin/kill `/bin/pidof poweroff`
else
if [ -e "/tmp/ups_stop_service" ]; then
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
/sbin/setcfg UPS "AC Power" OK
else
/sbin/config_util 1
/sbin/storage_boot_init 1
/sbin/setcfg UPS "AC Power" OK
/bin/umount /mnt/HDA_ROOT
fi
/sbin/reboot
else
/bin/kill `/bin/pidof ups_stop_service`
fi
fi
;;
*) # Unknown message, assume power is down
if [ -f /var/run/shutdown.pid ]
then
# kill `pidof shutdown`
# kill `pidof halt`
if [ $POWER_MODE = Shutdown ]
then
/bin/kill `/bin/pidof poweroff`
else
if [ -e "/tmp/ups_stop_service" ]; then
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
/sbin/setcfg UPS "AC Power" OK
else
/sbin/config_util 1
/sbin/storage_boot_init 1
/sbin/setcfg UPS "AC Power" OK
/bin/umount /mnt/HDA_ROOT
fi
/sbin/reboot
else
/bin/kill `/bin/pidof ups_stop_service`
fi
fi
fi
# shutdown -h +$restart_time &
time=$restart_time
time=`expr ${time} \* 60`
# /sbin/halt -d +${time} &
if [ $POWER_MODE = Shutdown ]
then
/sbin/poweroff -d +${time} &
else
/usr/sbin/ups_stop_service ${time} &
fi
#"THE POWER IS DOWN! SHUTTING DOWN SYSTEM! PLEASE LOG OFF NOW!" < /dev/console &
;;
esac
else
# genowerfail called, and upsstatus dosen't exist.
# Assume user is using powerd, and shutdown.
# shutdown -h +$restart_time &
time=$restart_time
time=`expr ${time} \* 60`
# sbin/halt -d +${time} &
if [ $POWER_MODE = Shutdown ]
then
/sbin/poweroff -d +${time} &
else
/usr/sbin/ups_stop_service ${time} &
fi
#"THE POWER IS DOWN! SHUTTING DOWN SYSTEM! PLEASE LOG OFF NOW!" < /dev/console &
fi
;;
stop)
# Ok, power is good again. Say so on the console.
#echo "THE POWER IS BACK, GOING MULTI USER"
# shutdown -c "THE POWER IS BACK"
# kill `pidof halt`
if [ $POWER_MODE = Shutdown ]
then
/bin/kill `/bin/pidof poweroff`
else
if [ -e "/tmp/ups_stop_service" ]; then
if [ -x /sbin/hal_app ]; then
/sbin/setcfg UPS "AC Power" OK
else
/sbin/config_util 1
/sbin/storage_boot_init 1
/sbin/setcfg UPS "AC Power" OK
/bin/umount /mnt/HDA_ROOT
fi
/sbin/reboot
else
/bin/kill `/bin/pidof ups_stop_service`
fi
fi
;;
*)
echo "Usage: /etc/init.d/genpowerfail.sh {start|stop}"
exit 1
;;
esac
exit 0

32
get_external_ip.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/ash
#
# Script for getting an external WAN IP
# in my test, can't use below URL "http://www.whatismyipaddress.com" "http://ipid.shat.net" "http://www.showmyip.com"
#URLS="http://checkip.dyndns.org http://whatismyip.com http://www.edpsciences.com/htbin/ipaddress"
URLS="http://checkip.dyndns.org http://monip.net/ http://forum.qnap.com/mywanip.php"
Project_Name=`/sbin/getcfg Project Name -d null -f /var/default`
WGET=/bin/wget-s
TMP_FILE=/tmp/get_external_ip
[ -f ${WGET} ] || /bin/ln -sf /usr/bin/wget-s ${WGET} 1>/dev/null 2>/dev/null
#To prevent wget will not work
#${WGET} -T 1 -t 1 ftp://127.0.0.1 1>/dev/null 2>/dev/null
i=1;
for URL in $URLS
do
${WGET} -4 -O ${TMP_FILE} -o /dev/null -T 19 -t 1 "${URL}" 2>/dev/null 1>/dev/null
RET1=$?
IP=`/bin/cat ${TMP_FILE} | /bin/tr -cs '[0-9\.]' '\012' | /bin/awk -F'.' 'NF==4 && $1>0 && $1<256 && $2<256 && $3<256 && $4<256 && !/\.\./' | /bin/uniq`
RET2=$?
if [ "x${IP}" != "x" ]; then
if [ ${RET1} = 0 ] && [ ${RET2} = 0 ]; then
echo $IP
rm ${TMP_FILE}
exit 0
fi
fi
done
exit 1

26
getmac.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/sh
if [ "x$1" = "x" ]; then
echo "getmac.sh [dev]"
exit 1
fi
MACFILE=/var/MacAddress
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
/sbin/getcfg MAC $1 -f ${MACFILE}
else
Model_Name=`/bin/cat /etc/default_config/Model_Name.conf 2>/dev/null`
Model_NameX=`/bin/cat /etc/default_config/uLinux.conf | grep "^Model =" | cut -d ' ' -f3 2>/dev/null`
if [ "x${Model_Name}" = "xTS-509" ] || [ "x${Model_Name}" = "xTS-419" ] || [ "x${Model_Name}" = "xTS-809" ] || [ "x${Model_Name}" = "xTS-259" ] || [ "x${Model_Name}" = "xTS-459" ] || [ "x${Model_Name}" = "xTS-559" ] || [ "x${Model_Name}" = "xTS-659" ] || [ "x${Model_Name}" = "xTS-859" ] || [ "x${Model_NameX}" = "xTS-1279" ] || [ "x${Model_NameX}" = "xTS-879U" ] || [ "x${Model_NameX}" = "xTS-1279U" ] || [ "x${Model_NameX}" = "xTS-1279-G" ] || [ "x${Model_NameX}" = "xTS-879U-G" ] || [ "x${Model_NameX}" = "xTS-1279U-G" ]; then
# change eth0/eth1
if [ "x$1" = "xeth0" ]; then
/sbin/getcfg MAC eth1 -f ${MACFILE}
elif [ "x$1" = "xeth1" ]; then
/sbin/getcfg MAC eth0 -f ${MACFILE}
fi
else
/sbin/getcfg MAC $1 -f ${MACFILE}
fi
fi

67
hostname.sh Executable file
View File

@@ -0,0 +1,67 @@
#!/bin/sh
GETCFG="/sbin/getcfg"
/bin/touch /etc/hosts
[ $? = 0 ] || echo "/etc/hosts cannot be touched."
echo "127.0.0.1 localhost localhost" > /etc/hosts
write_hosts()
{
local ip
local hostname
local domainname
ip=`/sbin/ifconfig $1 | grep "inet addr" | cut -f 2 -d ':' | cut -f 1 -d ' '`
domainname=`/sbin/getcfg global realm -f /etc/config/smb.conf`
if [ "x$ip" != "x" ]; then
hostname=`/bin/hostname`
if [ "x$domainname" != "x" ]; then
echo "$ip ${hostname}.${domainname} $hostname" >> /etc/hosts
else
echo "$ip $hostname $hostname" >> /etc/hosts
fi
fi
}
name=`/sbin/getcfg System "Server Name"`
if /sbin/test $? != 0
then
/sbin/gen_hostname
/bin/sync
name=`/sbin/getcfg System "Server Name"`
fi
hostname $name
/bin/echo $name > /etc/hostname
NIC_NUM=`/sbin/getcfg "Network" "Interface Number" -d 2`
BOND_SUP=`/sbin/getcfg "Network" "BONDING Support" -d "FALSE"`
ADV_BOND_SUPPORT=`$GETCFG "Network" "Advanced Bonding Support" -d "FALSE"`
ULINUX_UPGRADE=`$GETCFG "Network" "uLinux Upgrade" -d "FALSE"`
if [ "x$ADV_BOND_SUPPORT" = "xTRUE" ] && [ "x$ULINUX_UPGRADE" = "xTRUE" ]; then
GROUP_NUM=`$GETCFG "Network Group" "Group Count" -d $NIC_NUM`
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
write_hosts ${net_interface}
fi
done
else
if [ "$BOND_SUP" = "TRUE" ]; then
write_hosts bond0
else
if [ "x${NIC_NUM}" = "x1" ] ;then
write_hosts eth0
else
write_hosts eth0
write_hosts eth1
fi
fi
fi
/etc/init.d/smb.sh nmbdrestart &
SNMPD_CONF_TMP=`/bin/mktemp /tmp/snmpd.conf.XXXXXX`
echo "sysName $name" > $SNMPD_CONF_TMP
/bin/sed -e '/^sysName/d' -e '/^sysDescr/d' /etc/config/snmpd.conf >> $SNMPD_CONF_TMP
/bin/mv $SNMPD_CONF_TMP /etc/config/snmpd.conf
if [ "x$1" != "xreset" ]; then
/usr/bin/killall -HUP snmpd
fi

66
idmap.sh Executable file
View File

@@ -0,0 +1,66 @@
#!/bin/sh
IDMAP_MAX=4
NET=/usr/local/samba/bin/net
IDMAP_TDB=/usr/local/samba/var/locks/winbindd_idmap.tdb
volume_test=`/sbin/getcfg Public path -f /etc/smb.conf | cut -d '/' -f 3`
[ "x${volume_test}" = "x" ] || volume=${volume_test}
LOCATION=/share/${volume}/.idmap
if [ ! -d ${LOCATION} ]; then
/bin/mkdir ${LOCATION}
fi
PREFIX1=$LOCATION/.idmap.dump
PREFIX2=$LOCATION/.idmap.leave
check_ADS()
{
/bin/grep "security = ADS" /etc/config/smb.conf 2>/dev/null 1>/dev/null
if [ $? != 0 ]; then
echo "ADS off"
exit 1
fi
}
case "$1" in
leave_dump)
check_ADS
_latest_no=`/sbin/getcfg Samba "idmap leave" -d 0`
if [ "x$_latest_no" = "x$IDMAP_MAX" ]; then
_latest_no=1
else
_latest_no=`/usr/bin/expr $_latest_no + 1`
fi
/sbin/setcfg Samba "idmap leave" $_latest_no
$NET idmap dump $IDMAP_TDB > $PREFIX2$_latest_no
;;
dump)
check_ADS
_latest_no=`/sbin/getcfg Samba "idmap dump" -d 0`
if [ "x$_latest_no" = "x$IDMAP_MAX" ]; then
_latest_no=1
else
_latest_no=`/usr/bin/expr $_latest_no + 1`
fi
/sbin/setcfg Samba "idmap dump" $_latest_no
$NET idmap dump $IDMAP_TDB > $PREFIX1$_latest_no
;;
restore)
if [ "x$2" = "x" ]; then
echo $0 restore [idmap_file]
exit 1
fi
$NET idmap restore < $2
/bin/rm -f /usr/local/samba/var/locks/gencache.tdb 2>/dev/null 1>/dev/null
/etc/init.d/winbind restart 2>/dev/null 1>/dev/null
;;
list)
echo PATH = [$LOCATION]
/bin/ls -al $LOCATION
;;
*)
echo "Usage: $0 {leave_dump|dump|restore|list}"
exit 1
esac
exit 0

7
init_acl.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
if [ `/sbin/getcfg System "Init ACL" -d 0` == 1 ] && [ `/sbin/getcfg System "ACL Enable" -d FALSE` == TRUE ]; then
/sbin/init_acl 1>/dev/null 2>/dev/null
/sbin/setcfg System "Init ACL" 0
fi

374
init_check.sh Executable file
View File

@@ -0,0 +1,374 @@
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
MNT_POINT="/mnt/ext"
FLASH_RFS1="/dev/sdx2"
FLASH_RFS2="/dev/sdx3"
FLASH_RFS5="/dev/sdx5"
FLASH_RFS6="/dev/sdx6"
FLASH_TMP="/flashfs_tmp"
CONFIG_Dev="/dev/md9"
MNT_HD_ROOT_TMP="/hd_root_tmp"
TS_LOG_DIR=/etc/logs
ISCSI_CONFIG="/etc/config/iscsi.conf"
ISCSI_DEFAULT_CONFIG="/etc/default_config/iscsi.conf"
DEV_NAS_CONFIG="/dev/sdx6"
function run_burntest()
{
mnt_burntest="/mnt/burntest"
[ ! -d $mnt_burntest ] && mkdir $mnt_burntest
mount -t ext3 /dev/sda1 $mnt_burntest
if [ $? -eq 0 ]; then
# Check the special symbol
SYM="`cat /etc/burntest.sym 2> /dev/null`"
BURNSYM="$mnt_burntest/burntest/$SYM/QNAP-burning-test"
if [ -f $BURNSYM ]; then
[ "x$1" = "xstart" ] && [ -x $mnt_burntest/burntest/burntest-init ] && {
$mnt_burntest/burntest/burntest-init
[ $? -eq 0 ] && return 0
}
[ "x$1" = "xstop" ] && [ -x $mnt_burntest/burntest/burntest-fini ] && {
$mnt_burntest/burntest/burntest-fini
[ $? -eq 0 ] && return 0
}
fi
umount $mnt_burntest > /dev/null 2>&1
rm -rf $mnt_burntest > /dev/null 2>&1
return 1
fi
return 1
}
create_iscsi_conf()
{
/bin/echo '[iSCSISetting]' > $ISCSI_CONFIG
/bin/echo 'Enable = FALSE' >> $ISCSI_CONFIG
/bin/echo 'iSCSIPort = 3260' >> $ISCSI_CONFIG
/bin/echo '[iSCSISetting]' > $ISCSI_DEFAULT_CONFIG
/bin/echo 'Enable = FALSE' >> $ISCSI_DEFAULT_CONFIG
/bin/echo 'iSCSIPort = 3260' >> $ISCSI_DEFAULT_CONFIG
}
remove_S30_S45()
{
/bin/rm /etc/rcS.d/S[3-4]* 1>/dev/null 2>&1
}
mount -t proc /proc /proc
# Mount local file systems in /etc/fstab
mount -o remount,rw /
mount -a
mkdir /sys
mount -t sysfs sysfs /sys
[ -d /tmp ] || mkdir /tmp
mount -t tmpfs tmpfs /tmp -o size=32M
if [ ! -z $_memsize ] && [ $_memsize -gt 1500000 ]; then
mount -t tmpfs tmpfs /tmp -o remount,size=64M
echo 131072 > /proc/sys/fs/inotify/max_user_watches
elif [ ! -z $_memsize ] && [ $_memsize -gt 1000000 ]; then
mount -t tmpfs tmpfs /tmp -o remount,size=64M
echo 65536 > /proc/sys/fs/inotify/max_user_watches
else
echo 32768 > /proc/sys/fs/inotify/max_user_watches
fi
chmod 777 /tmp
[ -d /tmp/config ] || mkdir /tmp/config
[ -d /tmp/qget ] || mkdir /tmp/qget
#set HDD LED
for i in 0 1 2 3 4 5; do
[ ! -f /sys/class/scsi_host/host$i/em_message ] || /bin/echo 0x80000 > /sys/class/scsi_host/host$i/em_message && sync
done
#insmod
[ ! -f /lib/modules/misc/jbd.ko ] || /sbin/insmod /lib/modules/misc/jbd.ko
[ ! -f /lib/modules/misc/ext3.ko ] || /sbin/insmod /lib/modules/misc/ext3.ko
[ ! -f /lib/modules/misc/hid.ko ] || /sbin/insmod /lib/modules/misc/hid.ko &
[ ! -f /lib/modules/misc/gcu.ko ] || /sbin/insmod /lib/modules/misc/gcu.ko &
[ ! -f /lib/modules/misc/iegbe.ko ] || /sbin/insmod /lib/modules/misc/iegbe.ko &
[ ! -f /lib/modules/misc/mv61xx.ko ] || /sbin/insmod /lib/modules/misc/mv61xx.ko
[ ! -f /lib/modules/misc/mv_sata.ko ] || /sbin/insmod /lib/modules/misc/mv_sata.ko
if [ -f /lib/modules/misc/mv_sata.ko ] || [ -f /lib/modules/misc/mv61xx.ko ]; then
/bin/sleep 10
fi
[ ! -f /lib/modules/misc/libata.ko ] || /sbin/insmod /lib/modules/misc/libata.ko &
[ ! -f /lib/modules/misc/usb-common.ko ] || /sbin/insmod /lib/modules/misc/usb-common.ko
[ ! -f /lib/modules/misc/usbcore.ko ] || /sbin/insmod /lib/modules/misc/usbcore.ko
[ ! -f /lib/modules/misc/ehci-hcd.ko ] || /sbin/insmod /lib/modules/misc/ehci-hcd.ko
[ ! -f /lib/modules/misc/uhci-hcd.ko ] || /sbin/insmod /lib/modules/misc/uhci-hcd.ko
if [ -f /lib/modules/misc/usb-storage.ko ]; then
/sbin/insmod /lib/modules/misc/usb-storage.ko
sleep 10
fi
/bin/mount -t usbfs none /proc/bus/usb
[ $? = 0 ] || /bin/echo "mount usbfs failed."
#insmod hal module
[ ! -f /lib/modules/misc/hal_netlink.ko ] || /sbin/insmod /lib/modules/misc/hal_netlink.ko 2>>/dev/null
Model_Name=`cat /etc/default_config/Model_Name.conf 2>/dev/null`
[ "x$Model_Name" != "x" ] || Model_Name="TS-509"
if [ "x${Model_Name}" = "xTS-101" ]; then
/bin/echo -n "Recover device node...."
/bin/mv /dev/sdareal4 /dev/sda4
[ $? = 0 ] && /bin/echo "OK."
/bin/echo "Wait for 1 seconds."
/bin/sleep 1
fi
/bin/echo
if [ -f /etc/lcd_disable_install ]; then
export COMPRT4LCD=yes
[ -x /sbin/lcd_tool ] || COMPRT4LCD=no
# Turn on sysklog ... because I will be blind
[ "x$COMPRT4LCD" = "xyes" ] && {
# /sbin/syslogd -O /tmp/messages -s 1000
# /sbin/klogd -c 7
#Check if generic version
if [ -f /etc/IS_G ]; then
lcd_tool -1 " NAS" -2 " Welcome! "
else
lcd_tool -1 " QNAP Turbo NAS" -2 " Welcome! "
fi
}
fi
/bin/echo "Start config_util..."
/sbin/config_util 1
/sbin/config_util 4
[ $? != 0 ] && /bin/echo "Some errors occurred while running config_util."
/bin/echo "config_util finished."
/bin/echo 500 > /proc/sys/vm/dirty_expire_centisecs &
/bin/echo 100 > /proc/sys/vm/dirty_writeback_centisecs &
/bin/echo 5 > /proc/sys/vm/dirty_ratio &
/bin/echo 10 > /proc/sys/vm/dirty_background_ratio &
/bin/echo 0x4000000 > /proc/sys/kernel/shmmax &
/bin/echo 16384 > /proc/sys/vm/min_free_kbytes &
echo "mount HDD root device"
/bin/mkdir $MNT_HD_ROOT_TMP
/bin/mount $CONFIG_Dev $MNT_HD_ROOT_TMP 1>>/dev/null 2>>/dev/null
if [ $? != 0 ]; then
/bin/echo "mount $CONFIG_Dev failed."
else
/bin/echo "mount $CONFIG_Dev successful."
[ -f $MNT_HD_ROOT_TMP/.config/Model_Name.conf ] || echo "$Model_Name" > $MNT_HD_ROOT_TMP/.config/Model_Name.conf
HD_Model_Name=`cat $MNT_HD_ROOT_TMP/.config/Model_Name.conf 2>/dev/null`
#try to fix model name here.
if [ "x$HD_Model_Name" != "x$Model_Name" ]; then
/bin/ln -sf config_util /sbin/ch_model
/sbin/ch_model "$Model_Name"
. /etc/init.d/functions
install_PKGs "${MNT_HD_ROOT_TMP}/update_pkg"
fi
HD_Model_Name=`cat $MNT_HD_ROOT_TMP/.config/Model_Name.conf 2>/dev/null`
echo $HD_Model_Name > /tmp/Internal_Model
HD_BOOT_CONF=`cat ${MNT_HD_ROOT_TMP}/.config/BOOT.conf`
/bin/echo "$HD_BOOT_CONF" > /tmp/BOOT_CONF
/bin/umount $CONFIG_Dev
[ $? = 0 ] || /bin/echo "umount $CONFIG_Dev failed."
if [ "x$HDD_INTERNAL_MODEL" != "x$SYS_INTERNAL_MODEL" ]; then
/sbin/write_log "HDD cannot be mounted because the Internal Model is not matched" 2
fi
fi
[ -f /etc/init.d/check_bootcmd.sh ] && /etc/init.d/check_bootcmd.sh
[ -f /bin/md5sum ] || /bin/ln -sf busybox /bin/md5sum
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
/sbin/create_hwtype
if [ "x${HD_BOOT_CONF}" = "xTS-NASX86" -a "x$HD_Model_Name" = "x$Model_Name" ] || \
[ "x${HD_BOOT_CONF}" = "xTS-NASARM" -a "x$HD_Model_Name" = "x$Model_Name" ] || \
[ "x${HD_BOOT_CONF}" = "xTS-NASPPC" -a "x$HD_Model_Name" = "x$Model_Name" ]; then
/bin/echo "Update Extended rcX_init.d...(1)"
BOOT_NORMAL=1
remove_S30_S45
# /bin/echo "------ /etc/init.d/mountall --------"
/etc/init.d/mountall
# /bin/echo "------ /etc/init.d/init_hardware.sh --------"
/etc/init.d/init_hardware.sh start
# /bin/echo "------ /etc/init.d/init_mac_addr.sh --------"
/etc/init.d/init_mac_addr.sh start
# /bin/echo "------ /etc/init.d/sysinit.sh --------"
/etc/init.d/sysinit.sh start
# /bin/echo "------ /etc/init.d/shutdown_check.sh --------"
/etc/init.d/shutdown_check.sh start
# /bin/echo "------ /etc/init.d/init_disk.sh --------"
/etc/init.d/init_disk.sh start
# /bin/echo "------ /etc/init.d/init_network.sh --------"
/etc/init.d/init_network.sh start
# /bin/echo "------ /etc/init.d/hostname.sh --------"
/etc/init.d/hostname.sh start
# /bin/echo "------ /etc/init.d/network.sh --------"
CNT=0
while [ $CNT -lt 10 ]; do
if [ -f /tmp/init.1 ]; then
break
else
sleep 1
CNT=`expr $CNT + 1`
fi
done
/etc/init.d/network.sh start
/etc/init.d/rcS_normal_fast
if [ -f /mnt/HDA_ROOT/update_pkg/.Squid_required ]; then
[ -x /mnt/HDA_ROOT/update_pkg/Squid.bin ] && ( /mnt/HDA_ROOT/update_pkg/Squid.bin 2>/dev/null 1>/dev/null & ) && sleep 3
/bin/rm -f /mnt/HDA_ROOT/update_pkg/.Squid_required 2>/dev/null
fi
#/bin/mv /etc/rcS.d/* /etc/rcS_init.d/
#/bin/mv /etc/rcK.d/* /etc/rcK_init.d/
else
/bin/echo "Update Extended rcX_init.d...(2)"
BOOT_NORMAL=0
/etc/rcS.d/S30mountall start
/sbin/setcfg System Booting 1
/sbin/daemon_mgr picd start "/sbin/picd &"
/sbin/daemon_mgr gpiod start "/sbin/gpiod &"
CPU_MODEL=""
[ ! -f /proc/tsinfo/cpu_model ] || CPU_MODEL=`/bin/cat /proc/tsinfo/cpu_model 2>/dev/null`
MODEL_NAME=`/sbin/getcfg "System" "Model"`
if [ "x${CPU_MODEL}" = "x88F6281 A0" ] && [ "x${MODEL_NAME}" = "xTS-119" ];then
/bin/rm /sbin/hwmond
fi
[ -f /sbin/hwmond ] && /sbin/daemon_mgr hwmond start "/sbin/hwmond &"
[ -f /sbin/acpid ] && /sbin/daemon_mgr acpid start "/sbin/acpid"
[ -f /usr/sbin/upsutil ] && /sbin/daemon_mgr upsutil start "/usr/sbin/upsutil &"
/etc/rcS.d/S31init_hardware start
#/etc/init.d/check_lan_port.sh
/etc/rcS.d/S32init_mac_addr start
#/etc/rcS.d/S33sysinit start
/sbin/hwclock --hctosys
/sbin/daemon_mgr bcclient start "/sbin/bcclient"
run_burntest start
[ $? -eq 0 ] && exit 0
/bin/echo log hidden config directory not exist, initial log file...
/bin/mkdir $TS_LOG_DIR
/sbin/log_tool -c -v
/sbin/log_tool -b 50 -v
/sbin/conn_log_tool -c -v
/sbin/conn_log_tool -b 50 -v
/etc/rcS.d/S34shutdown_check start
/sbin/storage_boot_init 3
/sbin/storage_boot_init 4
#/etc/rcS.d/S35init_disk start
/etc/rcS.d/S42hostname start
/etc/rcS.d/S45network start
/etc/rcS.d/S60thttpd start
#/usr/local/sbin/Qthttp -p 80 -nor -nos -u admin -d /home/httpd -c '**.*'
/etc/rcS.d/S61Qthttpd start
# create default index html file (replace "SERVER_NAME" string)
#/bin/sed s/SERVER_NAME/`/sbin/getcfg system "server name"`/ /root/index_default.html > /home/httpd/index.html
#/bin/mv /etc/rcK.d/K24thttpd /etc/rcK_init.d/
#/bin/mv /etc/rcK.d/K40network /etc/rcK_init.d/
#/bin/mv /etc/rcK.d/K66shutdown_check /etc/rcK_init.d/
#/bin/mv /etc/rcK.d/K80init_disk /etc/rcK_init.d/
if [ "x${BOOT_CONF}" = "xTS-NASARM" ] || [ "x${BOOT_CONF}" = "xTS-NASPPC" ]; then
DEV_NAS_CONFIG=/dev/mtdblock5
fi
/bin/mount $DEV_NAS_CONFIG -t ext2 /tmp/config -o ro 2>/dev/null 1>/dev/null
if [ -f /tmp/config/.write_cache ]; then
/sbin/setcfg Misc "Enable Write Cache" 1
/sbin/setcfg Misc "Enable Write Cache" 1 -f /etc/default_config/uLinux.conf
fi
if [ -f /tmp/config/.case_sensitive ]; then
/sbin/setcfg Samba "Case Sensitive" yes
/sbin/setcfg Samba "Case Sensitive" yes -f /etc/default_config/uLinux.conf
fi
/bin/umount /tmp/config 2>/dev/null 1>/dev/null
/bin/touch /tmp/format.status
Internal_Model=`/sbin/getcfg System "Internal Model"`
/sbin/config_util 0
if [ $? != 0 ]; then
/bin/echo "init_check.sh: No HD existed."
/sbin/set_status_led 1 1
# /sbin/burning &
fi
#Set power LED on
if [ "x$Internal_Model" = "xTS-609" ] || [ "x$Internal_Model" = "xTS-239" ] || [ "x$Internal_Model" = "xTS-439" ] || [ "x$Internal_Model" = "xTS-639" ] || [ "x$Internal_Model" = "xTS-839" ] || [ "x$Internal_Model" = "xTS-259" ] || [ "x$Internal_Model" = "xTS-459" ] || [ "x$Internal_Model" = "xTS-559" ]|| [ "x$Internal_Model" = "xTS-659" ] || [ "x$Internal_Model" = "xTS-859" ] || [ "x$Internal_Model" = "xTS-1279" ] || [ "x$Internal_Model" = "xTS-879" ] || [ "x$Internal_Model" = "xTS-1079" ] || [ "x$Internal_Model" = "xTS-469" ] || [ "x$Internal_Model" = "xTS-569" ] || [ "x$Internal_Model" = "xTS-669" ] || [ "x$Internal_Model" = "xTS-869" ]; then
/sbin/pic_raw 77
fi
[ -f /sbin/qLogEngined ] && /sbin/daemon_mgr qLogEngined start /sbin/qLogEngined
[ -f /sbin/qsyslogd ] && /sbin/daemon_mgr qsyslogd start /sbin/qsyslogd
[ -f /sbin/qShield ] && /sbin/daemon_mgr qShield start /sbin/qShield
# For utelnetd
cd /bin; ln -sf busybox readlink;
/bin/readlink /etc/inittab | /bin/grep enable > /dev/null
/etc/init.d/login.sh start
/etc/init.d/stunnel.sh start
/etc/init.d/bonjour.sh restart
# For localtime
readlink /usr/share/zoneinfo 1>>/dev/null 2>>/dev/null
if [ $? != 0 ]; then
[ -d /usr/share ] || /bin/mkdir /usr/share -p
[ -d /usr/share/zoneinfo ] || /bin/ln -sf /etc/zoneinfo /usr/share/zoneinfo
fi
# For passwd
if [ ! -d /usr/bin ]; then
echo "create /usr/bin/passwd"
/bin/mkdir /usr/bin -p
/bin/ln -sf /bin/busybox /usr/bin/passwd
fi
/sbin/pidof upnpd
[ $? = 0 ] || /etc/init.d/upnpd.sh restart
[ -f /sbin/lcdmond ] && /sbin/daemon_mgr lcdmond start /sbin/lcdmond
if [ x`/sbin/getcfg Misc "Buzzer Quiet Enable"` != "xTRUE" ]; then
/sbin/pic_raw 81
fi
/etc/init.d/update_def_share.sh
/bin/touch /etc/config/usb_share_mapping
/bin/touch /etc/default_config/usb_share_mapping
/bin/touch /var/lock/add_ext_dev
/bin/touch /etc/config/usb_share_setting
/bin/touch /etc/default_config/usb_share_setting
/bin/touch /etc/config/esata_share_mapping
/bin/touch /etc/default_config/esata_share_mapping
/bin/touch /etc/config/smart.conf
[ ! -f /home/httpd/cgi-bin/inc/lang_es-mex.js ] || /bin/rm /home/httpd/cgi-bin/inc/lang_es-mex.js
[ ! -f /home/httpd/cgi-bin/inc/s_lang_es-mex.js ] || /bin/rm /home/httpd/cgi-bin/inc/s_lang_es-mex.js
[ ! -f /etc/init.d/genLanglist.sh ] || /etc/init.d/genLanglist.sh
fi
# scan network card on PCIE bus
#/etc/init.d/check_lan_port.sh
[ -f /bin/ts_init ] && /bin/ts_init
/sbin/set_home_directory
/sbin/sss_convert
/etc/init.d/network.sh write_hosts
/bin/umount $FLASH_RFS1 1>>/dev/null 2>>/dev/null
/bin/umount $FLASH_RFS2 1>>/dev/null 2>>/dev/null
/bin/e2fsck -pf $FLASH_RFS5 1>>/dev/null 2>>/dev/null
/bin/e2fsck -pf $FLASH_RFS6 1>>/dev/null 2>>/dev/null
[ ! -d $FLASH_TMP ] || /bin/rmdir $FLASH_TMP 1>>/dev/null 2>>/dev/null
[ -f /etc/init.d/upnpd.sh ] && /bin/ln -sf ../init.d/upnpd.sh /etc/rcK.d/K15upnp
[ -f /etc/init.d/iscsiinit.sh ] && /bin/ln -sf ../init.d/iscsiinit.sh /etc/rcK.d/K59iscsiinit
#[ -f /etc/init.d/upnpd.sh ] && /etc/init.d/upnpd.sh restart
[ -f $ISCSI_CONFIG ] || create_iscsi_conf
if [ -f /sbin/upnpcd ]; then
[ -f /etc/config/upnpc.conf ] || /bin/touch /etc/config/upnpc.conf
/sbin/daemon_mgr upnpcd start "/sbin/upnpcd -i 300 &"
fi
# Send alert mail
[ -f /tmp/send_alert_mail ] && \
/sbin/send_alert_mail "The system was not shut down properly last time." && \
/bin/rm -f /tmp/send_alert_mail
[ $BOOT_NORMAL == 1 ] && /etc/init.d/boot_done.sh &
/etc/init.d/usb_device_check.sh
/bin/grep "${MNT_HD_ROOT_TMP}" "/proc/mounts" 1>>/dev/null 2>>/dev/null
[ $? != 0 ] || /bin/umount "${MNT_HD_ROOT_TMP}" 1>>/dev/null 2>>/dev/null
[ ! -d $MNT_HD_ROOT_TMP ] || /bin/rmdir $MNT_HD_ROOT_TMP 1>>/dev/null 2>>/dev/null

478
init_disk.sh Executable file
View File

@@ -0,0 +1,478 @@
#!/bin/sh
#. /etc/init.d/check_nss2
ROOT_PART="/mnt/HDA_ROOT"
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
BOOT_DEV=$(/sbin/hal_app --get_boot_pd port_id=0)
EXT_ROOT="/dev/md13"
elif [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
BOOT_DEV="/dev/mtdblock"
EXT_ROOT="/dev/sda4"
else
BOOT_DEV="/dev/sdx"
EXT_ROOT="/dev/sda4"
fi
if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
DEV_NAS_CONFIG=${BOOT_DEV}5
else
DEV_NAS_CONFIG=${BOOT_DEV}6
fi
TMP_CONFIG="/tmp/nasconfig_tmp"
DEFAULT_CFG_FILE="/etc/config/uLinux.conf"
NASCONFIG_FS="/opt/nasconfig_fs.img.tgz"
SWAP_DEVICE=/dev/md`/sbin/getcfg Storage "Disk Drive Number"`
restore_flag1=0
FLASH_UBOOT="/dev/mtdblock0"
FLASH_KERNEL="/dev/mtdblock1"
DEV_NAS_CONFIG_SIZE_MIN=32
NSS_ENABLED=`/sbin/getcfg "NVR" "NSS Enabled" -d "no"`
_init_spool()
{
local volume=`/sbin/getcfg Public path -f /etc/smb.conf | cut -d '/' -f 3`
local spool_dir="/share/$volume/.spool"
/bin/mount | /bin/grep $volume
if [ $? != 0 ]; then
spool_dir="/mnt/HDA_ROOT/.cups"
fi
[ -d $spool_dir ] || /bin/mkdir "$spool_dir" && /bin/chmod 777 $spool_dir
/bin/rm -f "/var/spool"
/bin/ln -s "$spool_dir" "/var/spool"
# init cups spool
if [ -f /usr/sbin/cupsd ]; then
[ -d "$spool_dir/cups" ] && /bin/rm -fr "$spool_dir/cups"
fi
}
check_sum()
{
local file_cksum=`/sbin/cksum $1`
local file_crc=`echo $file_cksum | cut -d ' ' -f 1`
local file_size=`echo $file_cksum | cut -d ' ' -f 2`
local cksum_cksum=`cat $2`
local cksum_crc=`echo $cksum_cksum | cut -d ' ' -f 1`
local cksum_size=`echo $cksum_cksum | cut -d ' ' -f 2`
if [ ! -f $1 ] || [ ! -f $2 ]; then
[ ! -f $1 ] && echo "$1 not found."
[ ! -f $2 ] && echo "$2 not found."
return 1
fi
if [ $file_crc = $cksum_crc ] && [ $file_size = $cksum_size ]; then
return 0
fi
return 1
}
update_flash_config(){
[ -f ${ROOT_PART}/.config/Model_Name.conf ] || return 1
echo "Update config files"
[ -d $TMP_CONFIG ] || /bin/mkdir $TMP_CONFIG
/bin/mount $DEV_NAS_CONFIG -t ext2 $TMP_CONFIG
if [ $? = 0 ]; then
DEV_NAS_CONFIG_FREE_SIZE=`/bin/df -k | /bin/grep "$DEV_NAS_CONFIG" | /bin/awk '{print $4}'`
if [ ${DEV_NAS_CONFIG_FREE_SIZE} -le ${DEV_NAS_CONFIG_SIZE_MIN} ]; then
/bin/umount $DEV_NAS_CONFIG
/bin/echo "The available space in flash rom is not enough."
return 1
fi
/bin/grep "\[END_FLAG\]" $DEFAULT_CFG_FILE 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]; then
DEFAULT_CFG_FILE_SIZE=`/usr/bin/du -k $DEFAULT_CFG_FILE | /bin/awk '{print $1}'`
[ ${DEV_NAS_CONFIG_FREE_SIZE} -gt ${DEFAULT_CFG_FILE_SIZE} ] && /bin/cp $DEFAULT_CFG_FILE $TMP_CONFIG
fi
if [ ! -f ${TMP_CONFIG}/system.map.key ]; then
/sbin/uuidgen > ${TMP_CONFIG}/system.map.key
/bin/cp ${TMP_CONFIG}/system.map.key /etc/config/system.map.key
fi
smbconf_cksum_val=0
flash_smbconf_cksum_val=1
if [ -f /etc/config/smb.conf ]; then
DEV_NAS_CONFIG_FREE_SIZE=`/bin/df -k | /bin/grep "$DEV_NAS_CONFIG" | /bin/awk '{print $4}'`
SMBCONF_SIZE=`/usr/bin/du -k /etc/config/smb.conf | /bin/awk '{print $1}'`
if [ -z $DEV_NAS_CONFIG_FREE_SIZE ] || [ -z $SMBCONF_SIZE ] || [ $SMBCONF_SIZE -le 0 ] || [ ${DEV_NAS_CONFIG_FREE_SIZE} -le ${SMBCONF_SIZE} ]; then
/bin/umount $DEV_NAS_CONFIG
/bin/echo "The available space in flash rom is not enough."
return 1
fi
smbconf_cksum_val=`/sbin/cksum /etc/config/smb.conf | /bin/cut -d ' ' -f 1`
[ -f ${TMP_CONFIG}/smb.conf ] && flash_smbconf_cksum_val=`/sbin/cksum ${TMP_CONFIG}/smb.conf | /bin/cut -d ' ' -f 1`
if [ $smbconf_cksum_val != $flash_smbconf_cksum_val ]; then
/bin/cp /etc/config/smb.conf ${TMP_CONFIG}/smb.conf
flash_smbconf_cksum_val=`/sbin/cksum ${TMP_CONFIG}/smb.conf | /bin/cut -d ' ' -f 1`
/bin/echo $flash_smbconf_cksum_val > ${TMP_CONFIG}/smb.conf.cksum
/bin/echo $flash_smbconf_cksum_val > /etc/config/smb.conf.cksum
/bin/echo "Configuration files in the flash rom is updated."
fi
fi
system_map_uuid=`/bin/cat ${TMP_CONFIG}/system.map.key`
system_map_uuid_hd=`/bin/cat /etc/config/system.map.key`
if [ "x$system_map_uuid" != x ] && [ "x$system_map_uuid" != "x$system_map_uuid_hd" ]; then
DEV_NAS_CONFIG_FREE_SIZE=`/bin/df -k | /bin/grep "$DEV_NAS_CONFIG" | /bin/awk '{print $4}'`
[ ${DEV_NAS_CONFIG_FREE_SIZE} -gt ${DEV_NAS_CONFIG_SIZE_MIN} ] && /bin/cp ${TMP_CONFIG}/system.map.key /etc/config/system.map.key
fi
/bin/sync
/bin/umount $DEV_NAS_CONFIG
fi
}
check_config(){
echo "Check config files...start"
[ -d $TMP_CONFIG ] || /bin/mkdir $TMP_CONFIG
/bin/mount -t ext2 $DEV_NAS_CONFIG $TMP_CONFIG
if [ $? = 0 ]; then
# /bin/grep "\[END_FLAG\]" $DEFAULT_CFG_FILE 1>>/dev/null 2>>/dev/null
# if [ $? != 0 ]; then
# echo "Restore uLinux.conf..."
# restore_flag1=1
# /bin/grep "\[END_FLAG\]" $TMP_CONFIG/uLinux.conf 1>>/dev/null 2>>/dev/null
# if [ $? = 0 ];then
# /bin/cp $TMP_CONFIG/uLinux.conf $DEFAULT_CFG_FILE
# else
# /bin/cp $DEGAULT_CFG_DIR/uLinux.conf $DEFAULT_CFG_FILE
# fi
# fi
if [ -f ${ROOT_PART}/.config/Model_Name.conf ]; then
smbconf_cksum_val=0
flash_smbconf_cksum_val=1
flash_smbconf_cksum_ver=2
system_map_uuid=`/bin/cat ${TMP_CONFIG}/system.map.key`
system_map_uuid_hd=`/bin/cat /etc/config/system.map.key`
SMBCONF_SIZE=`/usr/bin/du -k /etc/config/smb.conf | /bin/awk '{print $1}'`
ROOT_PART_FREE_SIZE=`/bin/df -k | /bin/grep "$ROOT_PART" | /bin/awk '{print $4}'`
if [ -z $SMBCONF_SIZE ] || [ -z $ROOT_PART_FREE_SIZE ] || [ $SMBCONF_SIZE -le 0 ] || [ $ROOT_PART_FREE_SIZE -le $SMBCONF_SIZE ]; then
/bin/umount $DEV_NAS_CONFIG
/bin/echo "Configuration file recovery failed."
return 1
fi
if [ "x$system_map_uuid" != x ] && [ "x$system_map_uuid" = "x$system_map_uuid_hd" ]; then
if [ -f /etc/config/smb.conf ] && [ -f /etc/config/smb.conf.cksum ]; then
smbconf_cksum_val=`/sbin/cksum /etc/config/smb.conf | /bin/cut -d ' ' -f 1`
smbconf_cksum_ver=`/bin/cat ${TMP_CONFIG}/smb.conf.cksum`
if [ -n $smbconf_cksum_ver ] && [ $smbconf_cksum_ver = $smbconf_cksum_val ]; then
/bin/umount $DEV_NAS_CONFIG
/bin/echo "No need to do recovery."
return 0
fi
fi
if [ -f ${TMP_CONFIG}/smb.conf ] && [ -f ${TMP_CONFIG}/smb.conf.cksum ]; then
flash_smbconf_cksum_val=`/sbin/cksum ${TMP_CONFIG}/smb.conf | /bin/cut -d ' ' -f 1`
[ -f /etc/config/smb.conf ] && smbconf_cksum_val=`/sbin/cksum /etc/config/smb.conf | /bin/cut -d ' ' -f 1`
flash_smbconf_cksum_ver=`/bin/cat ${TMP_CONFIG}/smb.conf.cksum`
if [ $smbconf_cksum_val != $flash_smbconf_cksum_val ] && [ $flash_smbconf_cksum_ver = $flash_smbconf_cksum_val ]; then
#/bin/cp ${TMP_CONFIG}/smb.conf /etc/config/smb.conf
#/bin/cp ${TMP_CONFIG}/smb.conf.cksum /etc/config/smb.conf.cksum
restore_flag1=1
fi
fi
fi
if [ ! -f ${TMP_CONFIG}/smb.conf ] && [ ! -f ${TMP_CONFIG}/smb.conf.cksum ] && [ -f /etc/config/smb.conf ]; then
DEV_NAS_CONFIG_FREE_SIZE=`/bin/df -k | /bin/grep "$DEV_NAS_CONFIG" | /bin/awk '{print $4}'`
freesize_need=$(($SMBCONF_SIZE+$DEV_NAS_CONFIG_SIZE_MIN))
if [ ! -z $DEV_NAS_CONFIG_FREE_SIZE ] && [ $DEV_NAS_CONFIG_FREE_SIZE -gt $freesize_need ]; then
smbconf_cksum_val=`/sbin/cksum /etc/config/smb.conf | /bin/cut -d ' ' -f 1`
/bin/cp /etc/config/smb.conf ${TMP_CONFIG}/smb.conf
/bin/echo $smbconf_cksum_val > ${TMP_CONFIG}/smb.conf.cksum
if [ -f ${TMP_CONFIG}/system.map.key ]; then
/bin/cp ${TMP_CONFIG}/system.map.key /etc/config/system.map.key
else
/sbin/uuidgen > ${TMP_CONFIG}/system.map.key
/bin/cp ${TMP_CONFIG}/system.map.key /etc/config/system.map.key
fi
fi
fi
if [ ! -f /etc/config/smb.conf.cksum ]; then
smbconf_cksum_val=`/sbin/cksum /etc/config/smb.conf | /bin/cut -d ' ' -f 1`
/bin/echo $smbconf_cksum_val > /etc/config/smb.conf.cksum
fi
fi #end of Model_Name.conf
/bin/sync
/bin/umount $DEV_NAS_CONFIG
echo "Check config files...end"
else
echo "Mount $DEV_NAS_CONFIG failed...try to recover it..."
[ -f ${NASCONFIG_FS} ] && echo "${NASCONFIG_FS} is found."
[ -f ${NASCONFIG_FS} ] && /bin/tar xzf ${NASCONFIG_FS} -O > $DEV_NAS_CONFIG
fi
#Restore config logs
if [ $restore_flag1 = 1 ]; then
echo
#/sbin/write_log "System configuration file(s) recovered." 2
fi
}
stop_all_dev(){
MD_DEVICES="md0 md1 md2 md3 md4 md5"
HD_DEVICES="sda3 sdb3 sdc3 sdd3 sde3 sdf3 sdg3 sdh3 sdi3 sdj3 sdk3 sdkl3 sdz3"
/sbin/qwatchdogd -d
if [ -f /tmp/ups_stop_service ]; then
/bin/ps | grep "/etc/rcK.d/" | grep -v grep >/dev/null
[ $? != 0 ] || /usr/sbin/killall5
else
/usr/sbin/killall5
fi
/sbin/qwatchdogd &
echo "umount and stop encrypt devices."
for i in $MD_DEVICES
do
if [ `/sbin/getcfg Storage "Encrypt_${i}" -d "FALSE"` = "TRUE" ]; then
/bin/umount /dev/mapper/${i} 1>>/dev/null 2>>/dev/null
if [ "$?" = "0" ] && [ -f /sbin/cryptsetup ]; then
/sbin/cryptsetup luksClose ${i} 1>>/dev/null 2>>/dev/null
[ "$?" = "0" ] && /sbin/mdadm -S /dev/${i}
fi
else
/bin/cat /proc/mounts | /bin/grep ${i} | /bin/grep "ro,"
if [ $? = 0 ]; then
readonly_flag=1
else
readonly_flag=0
fi
/bin/umount /dev/${i} 1>>/dev/null 2>>/dev/null
if [ "$?" = "0" ]; then
/bin/sleep 1
if [ $readonly_flag = 0 ]; then
/sbin/mdadm -S /dev/${i}
[ "$?" = "0" ] || echo "Cannot stop raid device /dev/${i}."
else
echo "/dev/${i} is set read-only."
fi
fi
fi
done
for i in $HD_DEVICES
do
if [ `/sbin/getcfg Storage "Encrypt_${i}" -d "FALSE"` = "TRUE" ]; then
/bin/umount /dev/mapper/${i} 1>>/dev/null 2>>/dev/null
if [ "$?" = "0" ] && [ -f /sbin/cryptsetup ]; then
/sbin/cryptsetup luksClose ${i} 1>>/dev/null 2>>/dev/null
fi
else
/bin/umount /dev/${i} 1>>/dev/null 2>>/dev/null
fi
done
}
PUBLIC_SHARE=Public
# Use around 5TB (5000000M)
USE_THRESHOLD=5000000
# Free around 5G (5000M)
AVAIL_THRESHOLD=5000
preload_group_block_bitmap()
{
/bin/echo "group block bitmap usage checking..."
public_dir=$(/sbin/getcfg $PUBLIC_SHARE path -f /etc/config/smb.conf)
if [ ! -z $public_dir ] && [ -d $public_dir ]; then
public_mnt_path=$(/usr/bin/dirname $public_dir)
/bin/echo "find default mount path $public_mnt_path"
if [ ! -z $public_mnt_path ] && [ -d $public_mnt_path ]; then
use_size="$(/bin/df -m | /bin/awk -v mnt_path=$public_mnt_path '{if ($6 == mnt_path) print $3}')"
avail_size="$(/bin/df -m | /bin/awk -v mnt_path=$public_mnt_path '{if ($6 == mnt_path) print $4}')"
if [ X != X$use_size ] && [ X != X$avail_size ]; then
if [ $use_size -gt $USE_THRESHOLD ] && [ $avail_size -gt $AVAIL_THRESHOLD ]; then
/bin/echo "$USE_THRESHOLD/$AVAIL_THRESHOLD exceeds threshold, try to preload them."
/bin/dd if=/dev/zero of=$public_mnt_path/.group_bitmap_preload bs=1M count=1024
/bin/rm -f $public_mnt_path/.group_bitmap_preload
fi
fi
fi
fi
}
case "$1" in
start)
echo "Starting Disk initialized:"
[ -f /sbin/lcd_tool ] && /sbin/lcd_tool -1 "Mount Volume" -2 "Please Wait..."
check_config
/bin/rm /etc/config/usb_share_mapping -f
/bin/touch /etc/config/usb_share_mapping
/bin/touch /etc/default_config/usb_share_mapping
/bin/touch /var/lock/add_ext_dev
/bin/rm /etc/config/esata_share_mapping -f
/bin/touch /etc/config/esata_share_mapping
/bin/touch /etc/default_config/esata_share_mapping
/bin/touch /etc/config/usb_share_setting
/bin/touch /etc/default_config/usb_share_setting
# Clear QRAID1 status to avoid system shutdown abnormal.
/sbin/setcfg QRAID1 "device name" ""
if [ -f /sbin/storage_boot_init ]; then
/sbin/storage_boot_init 2
fi
# preload FS group block bitmap
preload_group_block_bitmap
/bin/touch /tmp/init.1
# Check external disks.
if [ -f /sbin/storage_boot_init ]; then
/sbin/storage_boot_init 6 &
fi
[ -f /sbin/hotswap ] && /sbin/daemon_mgr hotswap stop "/sbin/hotswap &"
/bin/sleep 1
[ -f /sbin/hotswap ] && /sbin/daemon_mgr hotswap start "/sbin/hotswap &" &
/bin/touch /var/ledvalue
/bin/touch /tmp/check.status
/bin/touch /tmp/format.status
#---u-boot & uImage_bak update---
if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
if [ -f $ROOT_PART/update_pkg/uImage_bak ]; then
echo "Update Kernel..."
check_sum "$ROOT_PART/update_pkg/uImage_bak" "$ROOT_PART/update_pkg/uImage_bak.cksum"
if [ $? = 0 ]; then
/bin/dd if=$ROOT_PART/update_pkg/uImage_bak of=${FLASH_KERNEL}
echo "Kernel is updated."
else
echo "Kernel update error."
fi
/bin/rm -f $ROOT_PART/update_pkg/uImage_bak*
fi
#Reboot after u-boot is updated.
if [ -f $ROOT_PART/update_pkg/u-boot.bin ]; then
echo "Update U-boot..."
check_sum "$ROOT_PART/update_pkg/u-boot.bin" "$ROOT_PART/update_pkg/u-boot.bin.cksum"
if [ $? = 0 ]; then
/bin/dd if=$ROOT_PART/update_pkg/u-boot.bin of=${FLASH_UBOOT}
echo "u-boot is updated."
else
echo "u-boot update error."
fi
/bin/rm -f $ROOT_PART/update_pkg/u-boot.bin*
echo "Reboot..."
/sbin/reboot
fi
fi
[ -f /sbin/qsmartd ] && ( /sbin/daemon_mgr qsmartd start "/sbin/qsmartd -d" & ) && sleep 1
# for TS119 TS219 TS419
if [ -f /etc/config/quick_update.flag ]; then
/sbin/setcfg "Misc" "Configured" "TRUE"
rm -f /etc/config/quick_update.flag
fi
if [ "x${NSS_ENABLED}" = "xyes" ]; then
cp -v /etc/init.d/nvr_svc.sh /etc/init.d/nvrd.sh
else
touch /home/httpd/cgi-bin/data/lang_tools.js
if [ ! -e /home/httpd/cgi-bin/surv/lang ]; then
mkdir -p /home/httpd/cgi-bin/surv/lang
fi
touch /home/httpd/cgi-bin/surv/lang/lang_tools.js
fi
_init_spool
standby_enable=`/sbin/getcfg Misc "Disk StandBy Timeout Enable" -d FALSE`
[ "x${standby_enable}" = "xFALSE" ] && /sbin/hdsuspend -a -t 0
/sbin/gen_next_alarm
#Write BOOT to crontab for RR postpone.
/sbin/gen_next_alarm 2 -c
;;
stop)
[ -f /tmp/donotrecover ] || update_flash_config
echo "Unmount ISO shares"
/etc/init.d/iso_mount.sh stop
/sbin/daemon_mgr klogd.sh stop "/etc/init.d/klogd.sh stop" &
/etc/init.d/klogd.sh stop
if [ -f /sbin/storage_boot_init ]; then
/sbin/storage_boot_init 7
fi
[ -f /sbin/hotswap ] && /sbin/daemon_mgr hotswap stop "/sbin/hotswap -d" &
/sbin/daemon_mgr bcclient stop "/sbin/bcclient"
/sbin/daemon_mgr rsync stop "/sbin/rsync --daemon" &
[ -f /sbin/hd_util ] && /sbin/daemon_mgr hd_util stop "/sbin/hd_util -d" &
[ -f /sbin/qsmartd ] && /bin/kill -HUP `/bin/pidof qsmartd`
[ -f /sbin/qsmartd ] && /sbin/daemon_mgr qsmartd stop "/sbin/qsmartd -d" &
[ -f /sbin/qsmart ] && /sbin/qsmart -c -d 1 1>/dev/null 2>/dev/null
[ -f /sbin/qsmart ] && /sbin/qsmart -c -d 2 1>/dev/null 2>/dev/null
[ -f /sbin/qsmart ] && /sbin/qsmart -c -d 3 1>/dev/null 2>/dev/null
[ -f /sbin/qsmart ] && /sbin/qsmart -c -d 4 1>/dev/null 2>/dev/null
#set power recovery mode to power off if mode is last state
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
/sbin/hal_event --se_shutdown
else
Internal_Model=`/sbin/getcfg System "Internal Model"`
if [ "x$Internal_Model" != "xTS-879" ] && [ "x$Internal_Model" != "xTS-1079" ] && [ "x$Internal_Model" != "xTS-1279" ] && [ "x$Internal_Model" != "xTS-1679" ] ;then
Power_Recovery_Mode=`/sbin/getcfg Misc Power_Recovery_Mode -d 0`;
case "$Power_Recovery_Mode" in
0)
#LAST STATE
/sbin/pic_raw 68
echo "last state mode"
;;
esac
fi
fi
/bin/kill -9 `/bin/pidof daemon_mgr`
/bin/kill -9 `/bin/pidof utelnetd`
/bin/kill -9 `/bin/pidof proftpd`
/bin/kill -9 `/bin/pidof rsyncd`
/bin/kill -9 `/bin/pidof cupsd`
if [ -f /tmp/ups_stop_service ]; then
/sbin/daemon_mgr lcdmond stop /sbin/lcdmond 1>>/dev/null 2>>/dev/null
/bin/sleep 1
[ -f /sbin/lcd_tool ] && /sbin/lcd_tool -f 1>>/dev/null 2>>/dev/null
fi
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
/sbin/hal_event --clear_ipc
/sbin/storage_util --data_umount
else
stop_all_dev
fi
[ -f /sbin/umount_all_extdev ] && /sbin/umount_all_extdev
/bin/umount /dev/md9
if [ "$?" = "0" ]; then
/bin/sleep 1
/sbin/mdadm -S /dev/md9
[ "$?" = "0" ] || echo "Cannot stop raid device /dev/md9."
fi
/sbin/swapoff ${SWAP_DEVICE}
[ "$?" = "0" ] && /sbin/mdadm -S ${SWAP_DEVICE}
/bin/sleep 3
/bin/umount $EXT_ROOT
[ "$?" = "0" ] || /bin/echo "init_disk.sh: Umount $EXT_ROOT failed."
/sbin/mdadm -S $EXT_ROOT
[ "$?" = "0" ] || /bin/echo "Cannot stop raid device $EXT_ROOT."
#Turn off HDD LED
# check if the HAL subsystem exist
if [ ! -x /sbin/hal_app ]; then
for i in 0 1 2 3 4 5; do
[ ! -f /sys/class/scsi_host/host$i/em_message ] || /bin/echo 0x0 > /sys/class/scsi_host/host$i/em_message && sync
done
else
# reboot all SAS enclosure if enclosure fw has been upgrade
if [ -f /etc/enclosure_upgrade.info ]; then
/sbin/hal_app --se_reboot enc_id=-1
fi
fi
;;
restart)
echo "Restarting Disk services:"
$0 stop
$0 start
echo "done."
;;
update_flash_config)
#update_flash_config
echo
;;
check_config)
check_config
;;
init_spool)
_init_spool
;;
*)
echo "Usage: init_disk {start|stop|restart}"
exit 1
esac

53
init_dns_type.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/bin/sh
#This shell script was used to get DNS type value from /etc/config/uLinux.conf
#If DNS type was empty, then we will set default value.
GETCFG="/sbin/getcfg"
SETCFG="/sbin/setcfg"
DNS_type=`$GETCFG "Network" "DNS type" -d "NoValue"`
Interface_number=`$GETCFG "Network" "Interface Number" -d "No_eth"`
BOND_SUP=`$GETCFG "Network" "BONDING Support" -d "FALSE"|tr a-z A-Z`
DEFAULT_GW_DEV=`$GETCFG "Network" "Default GW Device" -d eth0`
check_dns_type()
{
if [ "x$DNS_type" = "xNoValue" ]; then
_local_dns1=`$GETCFG "Network" "Domain Name Server 1" -d "0.0.0.0"`
_local_dns2=`$GETCFG "Network" "Domain Name Server 2" -d "0.0.0.0"`
if [ "x${_local_dns1}" != "x0.0.0.0" ] || [ "x${_local_dns2}" != "x0.0.0.0" ]; then
$SETCFG "Network" "DNS type" manual
else
if [ "x$Interface_number" = "x1" ]; then
if [ "x`$GETCFG eth0 "Use DHCP" -u -d TRUE`" = "xTRUE" ]; then
$SETCFG "Network" "DNS type" auto
else
$SETCFG "Network" "DNS type" manual
fi
elif [ "x$Interface_number" = "x2" ] && [ "x$BOND_SUP" = "xTRUE" ]; then
if [ "x`$GETCFG bond0 "Use DHCP" -u -d TRUE`" = "xTRUE" ]; then
$SETCFG "Network" "DNS type" auto
else
$SETCFG "Network" "DNS type" manual
fi
elif [ "x$Interface_number" = "x2" ] && [ "x$BOND_SUP" = "xFALSE" ]; then
if [ "x`$GETCFG $DEFAULT_GW_DEV "Use DHCP" -u -d TRUE`" = "xTRUE" ]; then
$SETCFG "Network" "DNS type" auto
else
$SETCFG "Network" "DNS type" manual
fi
elif [ $Interface_number -ge 4 ]; then
if [ "x`$GETCFG $DEFAULT_GW_DEV "Use DHCP" -u -d TRUE`" = "xTRUE" ]; then
$SETCFG "Network" "DNS type" auto
else
$SETCFG "Network" "DNS type" manual
fi
else
echo Please check your setting
fi
fi
fi
}
check_dns_type;

198
init_final.sh Executable file
View File

@@ -0,0 +1,198 @@
#!/bin/sh
. /etc/init.d/functions
ROOT_PART="/mnt/HDA_ROOT"
UPDATEPKG_DIR="${ROOT_PART}/update_pkg"
FLASH_TMP="/flashfs_tmp"
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
BOOT_DEV=$(/sbin/hal_app --get_boot_pd port_id=0)
else
BOOT_DEV="/dev/sdx"
fi
FLASH_RFS1=${BOOT_DEV}2
FLASH_RFS2=${BOOT_DEV}3
BOOT_CONF=`/bin/cat /etc/config/BOOT.conf`
_init_spool()
{
local volume=`/sbin/getcfg Public path -f /etc/smb.conf | cut -d '/' -f 3`
local spool_dir="/share/$volume/.spool"
[ -d $spool_dir ] || /bin/mkdir "$spool_dir" && /bin/chmod 777 $spool_dir
[ -L "/var/spool" ] && /bin/rm -f "/var/spool" && /bin/ln -s "$spool_dir" "/var/spool"
# init cups spool
if [ -f /usr/sbin/cupsd ]; then
[ -d "$spool_dir/cups" ] && /bin/rm -fr "$spool_dir/cups"
fi
}
check_sum()
{
if [ ! -f $1 ] || [ ! -f $2 ];then
echo "${1} or ${2} not found."
return 1
fi
local file_cksum=`/sbin/cksum $1`
local file_crc=`echo $file_cksum | cut -d ' ' -f 1`
local file_size=`echo $file_cksum | cut -d ' ' -f 2`
local cksum_cksum=`cat $2`
local cksum_crc=`echo $cksum_cksum | cut -d ' ' -f 1`
local cksum_size=`echo $cksum_cksum | cut -d ' ' -f 2`
if [ $file_crc = $cksum_crc ] && [ $file_size = $cksum_size ]; then
return 0
fi
return 1
}
rsync_startup() {
rsync_support=`/sbin/getcfg System "Rsync Support" -u`
if [ "x${rsync_support}" = "x" ]; then
/sbin/setcfg System "Rsync Support" TRUE
fi
# [ -f /etc/config/rsyncd.conf ] || /etc/init.d/rsyncd_srv.sh
# [ -f /etc/config/rsync_schedule.conf ] || echo "" > /etc/config/rsync_schedule.conf
#
# if [ `/sbin/getcfg System "Rsync Support" -u -d FALSE` = TRUE ]; then
# echo "Starting rsync services: rsync."
# /sbin/daemon_mgr rsync stop "/sbin/rsync --daemon"
# if [ `/sbin/getcfg "System" "Rsync Model" -u -d QNAP` = NORMAL ]; then
# #/sbin/daemon_mgr rsync start "/usr/bin/rsync --daemon --sever-mode=0"
# /usr/bin/rsyncd --daemon --sever-mode=0
# else
# #/sbin/daemon_mgr rsync start "/usr/bin/rsync --daemon --sever-mode=1"
# /usr/bin/rsyncd --daemon --sever-mode=1
# fi
# fi
/etc/init.d/rsyncd.sh start
}
[ -f /sbin/hd_util ] && /sbin/daemon_mgr hd_util stop "/sbin/hd_util &"
[ -f /sbin/hd_util ] && /sbin/daemon_mgr hd_util start "/sbin/hd_util &"
[ -f /sbin/hotswap ] && /sbin/daemon_mgr hotswap stop "/sbin/hotswap &"
[ -f /sbin/hotswap ] && /sbin/daemon_mgr hotswap start "/sbin/hotswap &"
[ -f /sbin/qsmartd ] && /sbin/daemon_mgr qsmartd stop "/sbin/qsmartd -d"
[ -f /sbin/qsmartd ] && /sbin/daemon_mgr qsmartd start "/sbin/qsmartd -d"
[ -f /sbin/gen_bandwidth ] && /sbin/daemon_mgr gen_bandwidth start "/sbin/gen_bandwidth -r -i 5 &"
[ -f /etc/init.d/klogd.sh ] && /sbin/daemon_mgr klogd.sh start "/etc/init.d/klogd.sh start &"
[ x`/bin/pidof bcclient` = x ] || /bin/kill -USR1 `/bin/pidof bcclient`
rsync_startup
#start syslog server
[ -f /etc/init.d/rsyslog.sh ] && /etc/init.d/rsyslog.sh start
#add for online users
/sbin/initsem 2>/dev/null 1>/dev/null
# add for Buzzer of warning
BUZZER="/root/.buzzer_warnning.conf"
echo "[Misc]" >> $BUZZER
if [ `/sbin/getcfg "Misc" "Buzzer Warning Enable" -u -d TRUE` = TRUE ]; then
/sbin/setcfg "Misc" "Buzzer Warning Enable" TRUE -f $BUZZER
else
/sbin/setcfg "Misc" "Buzzer Warning Enable" FALSE -f $BUZZER
fi
/sbin/gen_exports >/etc/config/nfssetting
/etc/init.d/ddns_update.sh
#prepare default ssl cert/key for download
/etc/init.d/stunnel.sh prepare_cert_key
#unlook usb copy function
/sbin/setcfg "usb copy" "lock flag" 0 -f "/etc/config/uLinux.conf"
#init qpkg
[ -d ${UPDATEPKG_DIR} ] || /bin/mkdir ${UPDATEPKG_DIR}
/bin/mount | /bin/grep HDA_ROOT 1>>/dev/null 2>>/dev/null
if [ $? = 0 ] && [ "x${BOOT_CONF}" = "xTS-NASX86" ]; then
if [ `/sbin/getcfg "QWEB" "Enable" -d 0` = 0 ]; then
/etc/init.d/Qthttpd.sh start # to extract apache/php
fi
if [ `/sbin/getcfg MySQL Enable -u -d FALSE` = FALSE ]; then
/etc/init.d/mysqld.sh start # to extract mysql
fi
[ -d $FLASH_TMP ] || /bin/mkdir $FLASH_TMP
/bin/mount $FLASH_RFS1 $FLASH_TMP -o ro
check_sum "$FLASH_TMP/boot/qpkg.tar" "$FLASH_TMP/boot/qpkg.tar.cksum"
if [ $? = 0 ]; then
/bin/tar xf $FLASH_TMP/boot/qpkg.tar -C ${UPDATEPKG_DIR}
/bin/umount $FLASH_RFS1
else
/bin/umount $FLASH_RFS1
/bin/mount $FLASH_RFS2 $FLASH_TMP -o ro
check_sum "$FLASH_TMP/boot/qpkg.tar" "$FLASH_TMP/boot/qpkg.tar.cksum"
[ $? = 0 ] && /bin/tar xf $FLASH_TMP/boot/qpkg.tar -C ${UPDATEPKG_DIR}
/bin/umount $FLASH_RFS2
fi
/bin/rmdir $FLASH_TMP
if [ -f ${UPDATEPKG_DIR}/ffmpeg.tgz ]; then
/etc/init.d/installtgz.sh ffmpeg ${UPDATEPKG_DIR}/ffmpeg.tgz
/etc/init.d/installtgz.sh ImageMagick ${UPDATEPKG_DIR}/ImageMagick.tgz
fi
/etc/init.d/Qthttpd.sh restart
/etc/init.d/ImRd.sh restart
/etc/init.d/installtgz.sh jsLib ${UPDATEPKG_DIR}/jsLib.tgz
/etc/init.d/installtgz.sh language ${UPDATEPKG_DIR}/language.tgz &
/etc/init.d/installtgz.sh vim ${UPDATEPKG_DIR}/vim.tgz
/etc/init.d/installtgz.sh samba ${UPDATEPKG_DIR}/samba.tgz
/etc/init.d/installtgz.sh radius ${UPDATEPKG_DIR}/radius.tgz &
/etc/init.d/installtgz.sh printer ${UPDATEPKG_DIR}/printer.tgz
/etc/init.d/installtgz.sh vaultServices ${UPDATEPKG_DIR}/vaultServices.tgz
/etc/init.d/installtgz.sh WFM2 ${UPDATEPKG_DIR}/WFM2.tgz &
/etc/init.d/installtgz.sh DSv3 ${UPDATEPKG_DIR}/DSv3.tgz
/etc/init.d/installtgz.sh vpnpptp ${UPDATEPKG_DIR}/vpnpptp.tgz
/etc/init.d/installtgz.sh vpnopenvpn ${UPDATEPKG_DIR}/vpnopenvpn.tgz
/etc/init.d/installtgz.sh ldap_server ${UPDATEPKG_DIR}/ldap_server.tgz
/etc/init.d/installtgz.sh avahi0630 ${UPDATEPKG_DIR}/avahi0630.tgz
if [ -f ${UPDATEPKG_DIR}/medialibrary.tgz ]; then
/etc/init.d/installtgz.sh medialibrary ${UPDATEPKG_DIR}/medialibrary.tgz
fi
/bin/touch ${UPDATEPKG_DIR}/update_qpkg_f
[ ! -f /etc/init.d/init_mozyclient.sh ] || /etc/init.d/init_mozyclient.sh start
/etc/init.d/smb.sh restart
/etc/init.d/init_qpkg.sh start
fi
# init lunportman
if [ -f /etc/init.d/lunportman.sh ]; then
/etc/init.d/lunportman.sh start 2>/dev/null 1>/dev/null
fi
# init qsyncman
if [ -f /etc/init.d/qsyncman.sh ]; then
/etc/init.d/qsyncman.sh start 2>/dev/null 1>/dev/null
fi
/etc/init.d/update_def_share.sh &
if [ -x "/sbin/appriv" ]; then
if [ ! -f /etc/config/nas_priv.db -o ! -s /etc/config/nas_priv.db ]; then
/sbin/appriv -i
else
/sbin/appriv -g &
fi
fi
[ x`/sbin/getcfg QPHOTO UseSysAccount` != x ] || /sbin/setcfg QPHOTO UseSysAccount 1
[ x`/sbin/getcfg MUSICSTATION UseSysAccount` != x ] || /sbin/setcfg MUSICSTATION UseSysAccount 1
[ x`/sbin/getcfg PHOTOSTATION UseSysAccount` != x ] || /sbin/setcfg PHOTOSTATION UseSysAccount 1
#start media library services
if [ -f /usr/local/medialibrary/bin/mymediadbserver ]; then
/etc/init.d/StartMediaService.sh start
fi
[ -x /etc/init.d/twonkymedia.sh ] && ( /etc/init.d/twonkymedia.sh restart 2>/dev/null 1>/dev/null & ) && sleep 3
_init_spool
[ -f /etc/init.d/printer.sh ] && /etc/init.d/printer.sh start 2>/dev/null 1>/dev/null
[ -f /etc/init.d/cupsd.sh ] && /etc/init.d/cupsd.sh start &> /dev/null
[ -f /etc/init.d/antivirus.sh ] && /etc/init.d/antivirus.sh init &> /dev/null
[ -f /etc/init.d/ldap_server.sh ] && /etc/init.d/ldap_server.sh init &> /dev/null
[ x`/sbin/getcfg BTDownload addonEnable -u -d FALSE` = xTRUE ] || /sbin/setcfg BTDownload addonEnable TRUE
[ ! -f /etc/init.d/btd.sh ] || /etc/init.d/btd.sh restart &> /dev/null
. /etc/init.d/check_nss2
[ "x$_NSS2_SUPPORT" = "xyes" ] && /bin/cp -f /etc/init.d/nvr_svc.sh /etc/init.d/nvrd.sh 2>/dev/null
/bin/touch ${UPDATEPKG_DIR}/.Squid_required
[ -x ${UPDATEPKG_DIR}/Squid.bin ] && ( ${UPDATEPKG_DIR}/Squid.bin 2>/dev/null 1>/dev/null & ) && sleep 3 && /bin/rm -f ${UPDATEPKG_DIR}/.Squid_required

206
init_hardware.sh Executable file
View File

@@ -0,0 +1,206 @@
#!/bin/sh
mknod /dev/rtcmon c 10 81
mknod /dev/watchdog c 10 130
mknod -m 666 /dev/fuse c 10 229
[ "x$COMPRT4LCD" != "xyes" ] && [ -f /sbin/lcd_tool ] && /sbin/lcd_tool -1 "Loading Driver" -2 "Please Wait..."
if [ -f /lib/modules/misc/usbcore.ko ]; then
[ ! -f /lib/modules/misc/usb-common.ko ] || /sbin/insmod /lib/modules/misc/usb-common.ko 2>>/dev/null
[ ! -f /lib/modules/misc/usbcore.ko ] || /sbin/insmod /lib/modules/misc/usbcore.ko 2>>/dev/null
[ ! -f /lib/modules/misc/ehci-hcd.ko ] || /sbin/insmod /lib/modules/misc/ehci-hcd.ko 2>>/dev/null
[ ! -f /lib/modules/misc/uhci-hcd.ko ] || /sbin/insmod /lib/modules/misc/uhci-hcd.ko 2>>/dev/null
/bin/mount -t usbfs none /proc/bus/usb 2>>/dev/null
fi
#ARM add model
[ ! -f /lib/modules/others/fuse.ko ] || /sbin/insmod /lib/modules/others/fuse.ko
[ ! -f /lib/modules/others/quota_tree.ko ] || /sbin/insmod /lib/modules/others/quota_tree.ko
[ ! -f /lib/modules/others/quota_v1.ko ] || /sbin/insmod /lib/modules/others/quota_v1.ko
[ ! -f /lib/modules/others/quota_v2.ko ] || /sbin/insmod /lib/modules/others/quota_v2.ko
[ ! -f /lib/modules/others/llc.ko ] || /sbin/insmod /lib/modules/others/llc.ko
[ ! -f /lib/modules/others/psnap.ko ] || /sbin/insmod /lib/modules/others/psnap.ko
[ ! -f /lib/modules/others/appletalk.ko ] || /sbin/insmod /lib/modules/others/appletalk.ko
[ ! -f /lib/modules/others/fat.ko ] || /sbin/insmod /lib/modules/others/fat.ko
[ ! -f /lib/modules/others/vfat.ko ] || /sbin/insmod /lib/modules/others/vfat.ko
[ ! -f /lib/modules/others/nls_cp437.ko ] || /sbin/insmod /lib/modules/others/nls_cp437.ko
[ ! -f /lib/modules/others/nls_cp850.ko ] || /sbin/insmod /lib/modules/others/nls_cp850.ko
[ ! -f /lib/modules/others/nls_iso8859-2.ko ] || /sbin/insmod /lib/modules/others/nls_iso8859-2.ko
[ ! -f /lib/modules/others/nls_utf8.ko ] || /sbin/insmod /lib/modules/others/nls_utf8.ko
[ ! -f /lib/modules/others/autofs.ko ] || /sbin/insmod /lib/modules/others/autofs.ko
[ ! -f /lib/modules/misc/linear.ko ] || /sbin/insmod /lib/modules/misc/linear.ko
[ ! -f /lib/modules/misc/raid0.ko ] || /sbin/insmod /lib/modules/misc/raid0.ko
[ ! -f /lib/modules/misc/raid10.ko ] || /sbin/insmod /lib/modules/misc/raid10.ko
#---- RAID 6 ----
[ ! -f /lib/modules/misc/xor.ko ] || /sbin/insmod /lib/modules/misc/xor.ko
[ ! -f /lib/modules/misc/raid6_pq.ko ] || /sbin/insmod /lib/modules/misc/raid6_pq.ko
[ ! -f /lib/modules/misc/async_tx.ko ] || /sbin/insmod /lib/modules/misc/async_tx.ko
[ ! -f /lib/modules/misc/async_memcpy.ko ] || /sbin/insmod /lib/modules/misc/async_memcpy.ko
[ ! -f /lib/modules/misc/async_xor.ko ] || /sbin/insmod /lib/modules/misc/async_xor.ko
[ ! -f /lib/modules/misc/async_pq.ko ] || /sbin/insmod /lib/modules/misc/async_pq.ko
[ ! -f /lib/modules/misc/async_raid6_recov.ko ] || /sbin/insmod /lib/modules/misc/async_raid6_recov.ko
[ ! -f /lib/modules/misc/raid456.ko ] || /sbin/insmod /lib/modules/misc/raid456.ko
#------------
[ ! -f /lib/modules/misc/dm-mod.ko ] || /sbin/insmod /lib/modules/misc/dm-mod.ko
[ ! -f /lib/modules/misc/dm-crypt.ko ] || /sbin/insmod /lib/modules/misc/dm-crypt.ko
[ ! -f /lib/modules/misc/aes_generic.ko ] || /sbin/insmod /lib/modules/misc/aes_generic.ko
[ ! -f /lib/modules/misc/sha1_generic.ko ] || /sbin/insmod /lib/modules/misc/sha1_generic.ko
[ ! -f /lib/modules/misc/sha256_generic.ko ] || /sbin/insmod /lib/modules/misc/sha256_generic.ko
[ ! -f /lib/modules/misc/sha512_generic.ko ] || /sbin/insmod /lib/modules/misc/sha512_generic.ko
[ ! -f /lib/modules/misc/mv_cesa.ko ] || /sbin/insmod /lib/modules/misc/mv_cesa.ko
if [ -f /lib/modules/misc/cryptodev.ko ]; then
/sbin/insmod /lib/modules/misc/cryptodev.ko
_maj=`/bin/cat /sys/class/misc/crypto/dev 2>/dev/null | /bin/cut -d ":" -f 1`
_min=`/bin/cat /sys/class/misc/crypto/dev 2>/dev/null | /bin/cut -d ":" -f 2`
if [ ! -z "$_maj" ] && [ ! -z "$_min" ]; then
/bin/mknod -m 0666 /dev/crypto c "$_maj" "$_min"
fi
fi
#-------------
[ ! -f /lib/modules/misc/usb-storage.ko ] || /sbin/insmod /lib/modules/misc/usb-storage.ko 2>>/dev/null
[ ! -f /lib/modules/misc/usbhid.ko ] || /sbin/insmod /lib/modules/misc/usbhid.ko
[ ! -f /lib/modules/misc/rtcmod.ko ] || /sbin/insmod /lib/modules/misc/rtcmod.ko
[ ! -f /lib/modules/misc/iTCO_vendor_support.ko ] || /sbin/insmod /lib/modules/misc/iTCO_vendor_support.ko
[ ! -f /lib/modules/misc/iTCO_wdt.ko ] || /sbin/insmod /lib/modules/misc/iTCO_wdt.ko heartbeat=120
[ ! -f /lib/modules/misc/usblp.ko ] || /sbin/insmod /lib/modules/misc/usblp.ko
[ ! -f /lib/modules/misc/atl1e.ko ] || /sbin/insmod /lib/modules/misc/atl1e.ko
[ ! -f /lib/modules/misc/e1000e.ko ] || /sbin/insmod /lib/modules/misc/e1000e.ko
[ ! -f /lib/modules/misc/sysinfo.ko ] || /sbin/insmod /lib/modules/misc/sysinfo.ko
[ ! -f /lib/modules/misc/jbd2.ko ] || /sbin/insmod /lib/modules/misc/jbd2.ko
[ ! -f /lib/modules/misc/ext4.ko ] || /sbin/insmod /lib/modules/misc/ext4.ko
[ ! -f /lib/modules/misc/ufsd.ko ] || /sbin/insmod /lib/modules/misc/ufsd.ko
[ ! -f /lib/modules/others/isofs.ko ] || /sbin/insmod /lib/modules/others/isofs.ko
[ ! -f /lib/modules/others/udf.ko ] || /sbin/insmod /lib/modules/others/udf.ko
[ ! -f /lib/modules/others/sunrpc.ko ] || /sbin/insmod /lib/modules/others/sunrpc.ko
[ ! -f /lib/modules/others/lockd.ko ] || /sbin/insmod /lib/modules/others/lockd.ko
[ ! -f /lib/modules/others/nfs_acl.ko ] || /sbin/insmod /lib/modules/others/nfs_acl.ko
[ ! -f /lib/modules/others/auth_rpcgss.ko ] || /sbin/insmod /lib/modules/others/auth_rpcgss.ko
[ ! -f /lib/modules/others/nfs.ko ] || /sbin/insmod /lib/modules/others/nfs.ko
[ ! -f /lib/modules/others/exportfs.ko ] || /sbin/insmod /lib/modules/others/exportfs.ko
[ ! -f /lib/modules/others/nfsd.ko ] || /sbin/insmod /lib/modules/others/nfsd.ko
[ ! -f /lib/modules/others/cifs.ko ] || /sbin/insmod /lib/modules/others/cifs.ko
[ ! -f /lib/modules/misc/ehci-hcd.ko ] || /sbin/insmod /lib/modules/misc/ehci-hcd.ko 2>>/dev/null
#[ ! -f /lib/modules/misc/uas.ko ] || /sbin/insmod /lib/modules/misc/uas.ko 2>>/dev/null
[ ! -f /lib/modules/misc/xhci.ko ] || /sbin/insmod /lib/modules/misc/xhci.ko
[ ! -f /lib/modules/misc/xhci-hcd.ko ] || /sbin/insmod /lib/modules/misc/xhci-hcd.ko
[ ! -f /lib/modules/misc/etxhci-hcd.ko ] || /sbin/insmod /lib/modules/misc/etxhci-hcd.ko
[ ! -f /lib/modules/others/smbfs.ko ] || /sbin/insmod /lib/modules/others/smbfs.ko
[ ! -f /lib/modules/misc/fnotify.ko ] || /sbin/insmod /lib/modules/misc/fnotify.ko
[ ! -f /usr/local/modules/lib80211.ko ] || /sbin/insmod /usr/local/modules/lib80211.ko
[ ! -f /usr/local/modules/cfg80211.ko ] || /sbin/insmod /usr/local/modules/cfg80211.ko
[ ! -f /usr/local/modules/mac80211.ko ] || /sbin/insmod /usr/local/modules/mac80211.ko
[ ! -f /usr/local/modules/hmac.ko ] || /sbin/insmod /usr/local/modules/hmac.ko
[ ! -f /usr/local/modules/ecb.ko ] || /sbin/insmod /usr/local/modules/ecb.ko
[ ! -f /usr/local/modules/md4.ko ] || /sbin/insmod /usr/local/modules/md4.ko
if [ -f /sbin/qwatchdogd ]; then
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
/sbin/daemon_mgr qwatchdogd start "/sbin/qwatchdogd -t 1 &"
if [ -x /sbin/hal_app ]; then
/sbin/hal_app --se_sys_set_pic_wdt enc_sys_id=root,mode=0
else
/sbin/pic_raw 103 # disable pic watch dog
fi
else
/sbin/daemon_mgr qwatchdogd start "/sbin/qwatchdogd -t 5 &"
fi
fi
#SOUND
[ ! -f /lib/modules/others/soundcore.ko ] || insmod /lib/modules/others/soundcore.ko
[ ! -f /lib/modules/others/snd.ko ] || insmod /lib/modules/others/snd.ko
[ ! -f /lib/modules/others/snd-timer.ko ] || insmod /lib/modules/others/snd-timer.ko
[ ! -f /lib/modules/others/snd-seq-device.ko ] || insmod /lib/modules/others/snd-seq-device.ko
[ ! -f /lib/modules/others/snd-page-alloc.ko ] || insmod /lib/modules/others/snd-page-alloc.ko
[ ! -f /lib/modules/others/snd-rawmidi.ko ] || insmod /lib/modules/others/snd-rawmidi.ko
[ ! -f /lib/modules/others/snd-seq.ko ] || insmod /lib/modules/others/snd-seq.ko
[ ! -f /lib/modules/others/snd-seq-midi-event.ko ] || insmod /lib/modules/others/snd-seq-midi-event.ko
[ ! -f /lib/modules/others/snd-seq-midi.ko ] || insmod /lib/modules/others/snd-seq-midi.ko
[ ! -f /lib/modules/others/snd-seq-oss.ko ] || insmod /lib/modules/others/snd-seq-oss.ko
[ ! -f /lib/modules/others/snd-pcm.ko ] || insmod /lib/modules/others/snd-pcm.ko
[ ! -f /lib/modules/others/snd-mixer-oss.ko ] || insmod /lib/modules/others/snd-mixer-oss.ko
[ ! -f /lib/modules/others/snd-pcm-oss.ko ] || insmod /lib/modules/others/snd-pcm-oss.ko
[ ! -f /lib/modules/others/snd-hwdep.ko ] || insmod /lib/modules/others/snd-hwdep.ko
[ ! -f /lib/modules/others/snd-usb-lib.ko ] || insmod /lib/modules/others/snd-usb-lib.ko
[ ! -f /lib/modules/others/snd-usbmidi-lib.ko ] || insmod /lib/modules/others/snd-usbmidi-lib.ko
#hd station
[ ! -f /lib/modules/others/hid-logitech.ko ] || insmod /lib/modules/others/hid-logitech.ko
[ ! -f /lib/modules/others/hid-logitech-dj.ko ] || insmod /lib/modules/others/hid-logitech-dj.ko
[ ! -f /lib/modules/others/snd-hda-codec.ko ] || insmod /lib/modules/others/snd-hda-codec.ko
[ ! -f /lib/modules/others/snd-hda-codec-analog.ko ] || insmod /lib/modules/others/snd-hda-codec-analog.ko
[ ! -f /lib/modules/others/snd-hda-codec-hdmi.ko ] || insmod /lib/modules/others/snd-hda-codec-hdmi.ko
if [ -f /lib/modules/others/snd-hda-intel.ko ]; then
insmod /lib/modules/others/snd-hda-intel.ko
[ ! -f /lib/modules/others/snd-usb-audio.ko ] || insmod /lib/modules/others/snd-usb-audio.ko qnap_start_index=1
else
[ ! -f /lib/modules/others/snd-usb-audio.ko ] || insmod /lib/modules/others/snd-usb-audio.ko
fi
[ ! -f /lib/modules/others/snd-usb-caiaq.ko ] || insmod /lib/modules/others/snd-usb-caiaq.ko
[ ! -f /lib/modules/others/drm_kms_helper.ko ] || insmod /lib/modules/others/drm_kms_helper.ko
[ ! -f /lib/modules/others/i915.ko ] || insmod /lib/modules/others/i915.ko
[ ! -f /lib/modules/others/v4l2-int-device.ko ] || insmod /lib/modules/others/v4l2-int-device.ko
[ ! -f /lib/modules/others/v4l1-compat.ko ] || insmod /lib/modules/others/v4l1-compat.ko
[ ! -f /lib/modules/others/v4l2-compat-ioctl32.ko ] || insmod /lib/modules/others/v4l2-compat-ioctl32.ko
[ ! -f /lib/modules/others/videodev.ko ] || insmod /lib/modules/others/videodev.ko
[ ! -f /lib/modules/others/v4l2-common.ko ] || insmod /lib/modules/others/v4l2-common.ko
[ ! -f /lib/modules/others/videobuf2-core.ko ] || insmod /lib/modules/others/videobuf2-core.ko
[ ! -f /lib/modules/others/videobuf2-memops.ko ] || insmod /lib/modules/others/videobuf2-memops.ko
[ ! -f /lib/modules/others/videobuf2-vmalloc.ko ] || insmod /lib/modules/others/videobuf2-vmalloc.ko
[ ! -f /lib/modules/others/uvcvideo.ko ] || insmod /lib/modules/others/uvcvideo.ko
[ -d /dev/snd ] || /bin/mkdir -m 777 /dev/snd
[ -c /dev/snd/seq ] || /bin/mknod -m 666 /dev/snd/seq c 116 1
[ -c /dev/snd/timer ] || /bin/mknod -m 666 /dev/snd/timer c 116 33
for (( i=0; i<5; i=i+1 ))
do
[ -c /dev/dsp${i} ] || /bin/mknod -m 666 /dev/dsp${i} c 14 `expr 3 + ${i} \* 16`
[ -c /dev/audio${i} ] || /bin/mknod -m 666 /dev/audio${i} c 14 `expr 4 + ${i} \* 16`
[ -c /dev/mixer${i} ] || /bin/mknod -m 666 /dev/mixer${i} c 14 `expr ${i} \* 16`
[ -c /dev/video${i} ] || /bin/mknod -m 666 /dev/video${i} c 81 ${i}
[ -c /dev/snd/controlC${i} ] || /bin/mknod -m 666 /dev/snd/controlC${i} c 116 `expr 0 + ${i} \* 32`
[ -c /dev/snd/pcmC${i}D0p ] || /bin/mknod -m 666 /dev/snd/pcmC${i}D0p c 116 `expr 16 + ${i} \* 32`
[ -c /dev/snd/pcmC${i}D0c ] || /bin/mknod -m 666 /dev/snd/pcmC${i}D0c c 116 `expr 24 + ${i} \* 32`
done
/bin/ln -sf dsp0 /dev/dsp
/bin/ln -sf audio0 /dev/audio
/bin/ln -sf mixer0 /dev/mixer
/bin/ln -sf video0 /dev/video
[ -c /dev/fb0 ] || /bin/mknod -m 666 /dev/fb0 c 29 0
[ -c /dev/fb1 ] || /bin/mknod -m 666 /dev/fb1 c 29 1
#/sbin/insmod /lib/modules/misc/sysinfo.ko
# Added by Ricky - for TS-101M
#insmod /lib/modules/misc/sd_mod.ko
#insmod /lib/modules/misc/sg.ko
#if [ -f /lib/modules/misc/usb-storage.ko ]; then
# insmod /lib/modules/misc/usb-storage.ko
#else
# insmod /lib/modules/usb-storage.ko
#fi
#insmod /lib/modules/misc/fat.ko
#insmod /lib/modules/misc/msdos.ko
#insmod /lib/modules/misc/vfat.ko
#insmod /lib/modules/misc/ntfs.ko
# for ntfs-3g
[ ! -f /lib/modules/misc/fuse.ko ] || /sbin/insmod /lib/modules/misc/fuse.ko
if [ -f /usr/local/lib/dm-ddsnap.ko ]; then
for i in a b c d e f g h
do
/sbin/mksdnod -p 7 sd$i > /dev/null
done
j=16
while [ $j -le 30 ] ; do
/bin/mknod /dev/md$j b 9 $j
j=$(($j+1))
done
fi
[ ! -f /usr/local/bin/vconfig ] || [ ! -f /usr/local/modules/8021q.ko ] || /sbin/insmod /usr/local/modules/8021q.ko
# scan network card on PCIE bus
/etc/init.d/check_lan_port.sh

149
init_iTune.sh Executable file
View File

@@ -0,0 +1,149 @@
#!/bin/sh
CONF_FILE=/etc/config/mt-daapd.conf
PLAY_LIST_FILE=/etc/config/mt-daapd.playlist
DB_DIR="/mnt/HDA_ROOT/.db_dir"
DB_PATH="${DB_DIR}/songs.gdb"
NEW_DB_PATH="${DB_DIR}/songs3.db"
LOCK_FILE=/var/lock/subsys/daapd
MultimediaShare=`/sbin/getcfg SHARE_DEF defMultimedia -d Qmultimedia -f /etc/config/def_share.info`
SHARE_PATH=/share/${MultimediaShare}
ITUNES_WEB=`/sbin/getcfg iTune "Web" -d FALSE`
SERVER="`/sbin/getcfg \"System\" \"Server Name\"`(iTunes)"
HOSTNAME=`/sbin/getcfg System "Server Name" -d NAS`
project_name=`/sbin/getcfg Project Name -f /var/default`
if [ "x$project_name" = "xAthens" ]; then
service_name=`/sbin/getcfg "Bonjour Service" "Web Service Name" -d $HOSTNAME`
SERVER="${service_name}(iTunes)"
fi
APP_RUNTIME_CONF="/var/.application.conf"
iTunes_Enable=`/sbin/getcfg iTune Enable -u -d FALSE`
function check_MultimediaShare()
{
if [ ! -d ${SHARE_PATH} ]; then
[ -d "/share/Multimedia" ] && SHARE_PATH="/share/Multimedia"
[ -d "/share/Qmultimedia" ] && SHARE_PATH="/share/Qmultimedia"
fi
}
function _install()
{
if [ ! -f "/mnt/ext/opt/mt-daapd/mt-daapd" ]; then
[ ! -d "/mnt/ext/opt/mt-daapd" ] || /bin/rm -rf /mnt/ext/opt/mt-daapd
[ -d /mnt/ext/opt ] || mkdir -p /mnt/ext/opt
if [ -f "/mnt/HDA_ROOT/update_pkg/mt-daapd.tgz" ]; then
/bin/tar -xf /mnt/HDA_ROOT/update_pkg/mt-daapd.tgz -C /mnt/ext/opt
/bin/ln -sf /mnt/ext/opt/mt-daapd /usr/local/mt-daapd
/bin/ln -sf /mnt/ext/opt/mt-daapd/mt-daapd /usr/sbin/mt-daapd
else
/bin/echo "mt-daapd.tgz does not exist"
exit 1
fi
[ -f /etc/config/mt-daapd.conf ] || /bin/cp /mnt/ext/opt/mt-daapd/mt-daapd.conf ${CONF_FILE}
fi
# check config file
check_MultimediaShare
[ -f ${CONF_FILE} ] || /bin/cp /mnt/ext/opt/mt-daapd/mt-daapd.conf ${CONF_FILE} 2>>/dev/null
if [ -f ${CONF_FILE} ]; then
RUNAS=`/sbin/getcfg general runas -d null -f ${CONF_FILE}`
if [ "x$RUNAS" != xadmin ]; then
[ -f /mnt/ext/opt/mt-daapd/mt-daapd.conf ] || /bin/echo "Default mt-daapd.conf not found."
/bin/cp -f /mnt/ext/opt/mt-daapd/mt-daapd.conf ${CONF_FILE} 2>>/dev/null
[ -f ${CONF_FILE} ] || exit 1
/sbin/setcfg general mp3_dir $SHARE_PATH -f ${CONF_FILE}
fi
/sbin/setcfg general servername "${SERVER}" -f ${CONF_FILE}
if [ "x${ITUNES_WEB}" = "xFALSE" ]; then
/sbin/setcfg general web_root "/dev/null" -f ${CONF_FILE}
else
/sbin/setcfg general web_root "/usr/local/mt-daapd/admin-root" -f ${CONF_FILE}
fi
/sbin/getcfg general mp3_dir -d null -f ${CONF_FILE} | /bin/grep "${SHARE_PATH}" 1>/dev/null 2>/dev/null
if [ $? != 0 ]; then
/sbin/getcfg general mp3_dir -d null -f ${CONF_FILE} | /bin/grep "/share/Multimedia" 1>/dev/null 2>/dev/null
_retM=$?
/sbin/getcfg general mp3_dir -d null -f ${CONF_FILE} | /bin/grep "/share/Qmultimedia" 1>/dev/null 2>/dev/null
_retQ=$?
if [ $_retM = 0 ] || [ $_retQ = 0 ]; then
/sbin/setcfg general mp3_dir $SHARE_PATH -f ${CONF_FILE}
fi
fi
fi
/bin/grep HDA_ROOT /proc/mounts 1>/dev/null 2>&1
[ $? = 0 ] || exit 1
[ -d ${DB_DIR} ] || /bin/mkdir ${DB_DIR}
}
stop()
{
/bin/kill -INT `/bin/pidof mt-daapd`
/bin/sleep 1
[ ! -f ${DB_PATH} ] || /bin/rm -rf ${DB_PATH}
/bin/rm -f ${LOCK_FILE} 2>/dev/null 1>/dev/null
/bin/kill -9 `/bin/pidof mt-daapd`
}
reset()
{
/bin/rm ${CONF_FILE} -f 1>/dev/null 2>/dev/null
/sbin/setcfg iTune Web FALSE
/sbin/setcfg iTune "Web Password" admin
/sbin/setcfg iTune "Password Enabled" 0
/sbin/setcfg iTune "Password" ""
$0 start
}
iTunes_Hide=`/sbin/getcfg DISABLE iTunes -d 0 -f $APP_RUNTIME_CONF`
if [ "x$iTunes_Hide" = "x1" ]; then
/sbin/setcfg iTune Enable FALSE
iTunes_Enable="FALSE"
fi
case "$1" in
start)
[ ! -f ${PLAY_LIST_FILE} ] || /bin/rm -f ${PLAY_LIST_FILE}
_install
if [ "x$iTunes_Enable" != "xTRUE" ]; then
echo "Starting iTune Services: disabled."
stop
exit 0
fi
echo -n "Starting iTunes services:"
[ -f ${LOCK_FILE} ] && stop
if [ ! -f ${CONF_FILE} ]; then
/bin/echo "${CONF_FILE} not found."
exit 1
fi
/bin/ln -sf ${CONF_FILE} /etc/mt-daapd.conf
/usr/sbin/mt-daapd -m -c /etc/mt-daapd.conf 2>/dev/null 1>/dev/null
if [ -f /tmp/.mt_daapd.err ]; then
_pid=`/bin/pidof mt-daapd`
[ x$_pid = x ] || /bin/kill -9 $_pid 2>/dev/null
[ ! -d ${DB_DIR} ] || /bin/rm -rf ${DB_DIR}/* 2>/dev/null 1>/dev/null
/bin/rm -f /tmp/.mt_daapd.err 2>/dev/null
/usr/sbin/mt-daapd -m -c /etc/mt-daapd.conf 2>/dev/null 1>/dev/null
fi
/etc/init.d/bonjour.sh reload 2>/dev/null 1>/dev/null
/bin/touch ${LOCK_FILE}
;;
stop)
echo -n "Shutting down iTunes services:"
stop
;;
reset)
echo -n "Reset iTunes services:"
reset;
;;
restart)
echo "Restarting iTunes services:"
$0 stop
$0 start
echo "done."
;;
*)
echo "Usage: init_iTune {start|stop|restart|reset}"
exit 1
esac

162
init_mac_addr.sh Executable file
View File

@@ -0,0 +1,162 @@
#!/bin/sh
#
# initialize MAC address
#
MOUNTPOINT="/tmp/config"
ETH0_MAC_ADDR="/ETH0.MAC_ADDR"
DEFAULT_MAC_ADDR="00:00:00:00:05:09"
GETCFG="/sbin/getcfg"
SETCFG="/sbin/setcfg"
NIC_NUM=`$GETCFG "Network" "Interface Number" -d "2"`
#only use for ARM && PPC
get_mac_address()
{
local mac_addr
local ret
mac_addr=`/sbin/iface_get_mac $1 ${DEFAULT_MAC_ADDR}`
ret=$?
if [ ${mac_addr} = ${DEFAULT_MAC_ADDR} ]; then
mac_addr=`/sbin/get_mac`
fi
/sbin/ifconfig $1 down
/sbin/ifconfig $1 hw ether $mac_addr
/sbin/ifconfig $1 up
if [ $ret -eq 0 ]; then
[ $? != 0 ] || /bin/echo "MAC_ADDR $mac_addr"
else
/sbin/ifconfig $1 hw ether $mac_addr
/bin/echo "MAC address not found. Set default MAC Addr $mac_addr"
fi
}
swap_two_nics()
{
/sbin/ifconfig eth0 down
/sbin/ifconfig eth1 down
/bin/ip link set dev eth0 name not_eth0
/bin/ip link set dev eth1 name eth0
/bin/ip link set dev not_eth0 name eth1
/sbin/ifconfig eth0 up
/sbin/ifconfig eth1 up
}
swap_four_nics()
{
/sbin/ifconfig eth1 down
/sbin/ifconfig eth2 down
/sbin/ifconfig eth3 down
/bin/ip link set dev eth1 name not_eth1
/bin/ip link set dev eth2 name eth1
/bin/ip link set dev eth3 name eth2
/bin/ip link set dev not_eth1 name eth3
/sbin/ifconfig eth1 up
/sbin/ifconfig eth2 up
/sbin/ifconfig eth3 up
}
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
if [ "x${BOOT_CONF}" = "xTS-NASARM" ] && [ ! -x /sbin/hal_app ]; then
/bin/touch /sbin/mac_sync
/bin/ln -sf /sbin/config_util /sbin/mac_sync
/sbin/mac_sync
/bin/rm /sbin/mac_sync
fi
if [ ! -x /sbin/hal_app ];then
# rename eth0 eth1
Model_Name=`/bin/cat /etc/default_config/Model_Name.conf 2>/dev/null`
if [ "x${Model_Name}" = "xTS-509" ] || [ "x${Model_Name}" = "xTS-419" ] || [ "x${Model_Name}" = "xTS-809" ] || [ "x${Model_Name}" = "xTS-259" ] || [ "x${Model_Name}" = "xTS-459" ] || [ "x${Model_Name}" = "xTS-559" ] || [ "x${Model_Name}" = "xTS-659" ] || [ "x${Model_Name}" = "xTS-859" ] || [ "x${Model_Name}" = "xTS-269" ] || [ "x${Model_Name}" = "xTS-469" ] || [ "x${Model_Name}" = "xTS-569" ] || [ "x${Model_Name}" = "xTS-669" ] || [ "x${Model_Name}" = "xTS-869" ] || [ "x${Model_Name}" = "xTS-1269" ];then
CPU_MODEL=""
_nic_num=`/sbin/getcfg Network "Interface Number" -d 2`
[ ! -f /proc/tsinfo/cpu_model ] || CPU_MODEL=`/bin/cat /proc/tsinfo/cpu_model | cut -d ' ' -f 1 2>/dev/null`
if [ "x${CPU_MODEL}" = "x88F6282" ] || [ "x${_nic_num}" = "x1" ] ;then
echo "nothing" >/dev/null
else
/sbin/ifconfig eth0 down
/sbin/ifconfig eth1 down
/bin/ip link set dev eth0 name not_eth0
/bin/ip link set dev eth1 name eth0
/bin/ip link set dev not_eth0 name eth1
/sbin/ifconfig eth0 up
/sbin/ifconfig eth1 up
fi
fi
Model_NameX=`/bin/cat /etc/default_config/uLinux.conf | grep "^Model =" | cut -d ' ' -f3 2>/dev/null`
if [ "x${Model_NameX}" = "xTS-1279" ] || [ "x${Model_NameX}" = "xTS-879U" ] || [ "x${Model_NameX}" = "xTS-1279U" ] || [ "x${Model_NameX}" = "xTS-1279-G" ] || [ "x${Model_NameX}" = "xTS-879U-G" ] || [ "x${Model_NameX}" = "xTS-1279U-G" ]; then
if [ -e /proc/tsinfo/hw_version ];then
Board=$(cat /proc/tsinfo/hw_version | cut -d ' ' -f2)
if [ $((Board & 2)) -eq 2 ];then
swap_four_nics
else
swap_two_nics
fi
else
swap_two_nics
fi
else
if [ "x${Model_NameX}" = "xTS-1679U" ] || [ "x${Model_NameX}" = "xTS-1679U-G" ]; then
swap_four_nics
fi
fi
fi
MAC_FILE="/var/MacAddress"
if [ "x${BOOT_CONF}" = "xTS-NASARM" ] && [ ! -x /sbin/hal_app ]; then
/bin/echo "[MAC]" > ${MAC_FILE}
mac_addr=`/sbin/iface_get_mac eth0 ${DEFAULT_MAC_ADDR}`
if [ ${mac_addr} = ${DEFAULT_MAC_ADDR} ]; then
mac_addr=`/sbin/get_mac`
fi
/bin/echo "eth0 = $mac_addr" >> ${MAC_FILE}
if [ "x${Model_Name}" = "xTS-419" ]; then
mac_addr=`/sbin/iface_get_mac eth1 ${DEFAULT_MAC_ADDR}`
/bin/echo "eth1 = $mac_addr" >> ${MAC_FILE}
fi
else
#set mac address to /var/MacAddress
/bin/echo "[MAC]" > ${MAC_FILE}
if_num=0
while [ $if_num -lt $NIC_NUM ]
do
if [ "x${BOOT_CONF}" = "xTS-NASARM" ] && [ -x /sbin/hal_app ]; then
mac_addr=`/sbin/hal_app --se_sys_get_mac obj_index=${if_num}`
if [ $? -ne 0 ] || [ "x${mac_addr}" = "x" ]; then
mac_addr=${DEFAULT_MAC_ADDR}
fi
/sbin/ifconfig eth${if_num} down
/sbin/ifconfig eth${if_num} hw ether ${mac_addr}
/sbin/ifconfig eth${if_num} up
fi
mac_addr=`/bin/cat /sys/class/net/eth${if_num}/address`
/bin/echo "eth${if_num} $mac_addr"
/bin/echo "eth${if_num} = $mac_addr" >> ${MAC_FILE}
if_num=$((${if_num} + 1))
done
fi
[ -d $MOUNTPOINT ] || /bin/mkdir $MOUNTPOINT
# setup lo
/sbin/ifconfig lo 127.0.0.1 up 2> /dev/null 1> /dev/null
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo 2> /dev/null 1> /dev/null
if [ "x${BOOT_CONF}" = "xTS-NASARM" ] && [ ! -x /sbin/hal_app ]; then
/sbin/ifconfig eth0 > /dev/null 2>&1
[ $? = 0 ] && get_mac_address eth0
/sbin/ifconfig eth1 > /dev/null 2>&1
[ $? = 0 ] && get_mac_address eth1
fi
#ldconfig
/sbin/ldconfig 1>/dev/null 2>&1

469
init_nas.sh Executable file
View File

@@ -0,0 +1,469 @@
#!/bin/sh
ROOT_PART="/mnt/HDA_ROOT"
MOUNTPOINT="/tmp/config"
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
BOOT_DEV=$(/sbin/hal_app --get_boot_pd port_id=0)
elif [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
BOOT_DEV="/dev/mtdblock"
else
BOOT_DEV="/dev/sdx"
fi
if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
DEV_NAS_CONFIG=${BOOT_DEV}5
else
DEV_NAS_CONFIG=${BOOT_DEV}6
fi
BOOTCOUNT="$MOUNTPOINT/BOOT_COUNT"
EXPR="/usr/bin/expr"
UPDATEPKG_DIR="${ROOT_PART}/update_pkg"
CMS_ENABLE=`/sbin/getcfg CMS Enable -d FALSE -f /etc/config/uLinux.conf`
if [ "`/sbin/getcfg -f /etc/default_config/uLinux.conf NVR Support -d FALSE`" == "TRUE" ]; then
SUPPORT_NVR=yes
else
SUPPORT_NVR=no
fi
#Look usb copy function in start QNAS
/sbin/setcfg "usb copy" "lock flag" 1 -f "/etc/config/uLinux.conf"
rsync_startup() {
rsync_support=`/sbin/getcfg System "Rsync Support" -u`
if [ "x${rsync_support}" = "x" ]; then
/sbin/setcfg System "Rsync Support" TRUE
fi
/etc/init.d/rsyncd.sh start &
}
check_def_share() {
defRecordingsShare=`/sbin/getcfg SHARE_DEF defRecordings -d Qrecordings -f /etc/default_config/def_share.info`
[ -f /etc/config/def_share.info ] && /bin/cp /etc/config/def_share.info /etc/default_config/def_share.info
[ -f /etc/config/def_share.info ] || /bin/touch /etc/config/def_share.info
PublicShare=`/sbin/getcfg SHARE_DEF defPublic -d Public -f /etc/config/def_share.info`
UsbShare=`/sbin/getcfg SHARE_DEF defUsb -d Qusb -f /etc/config/def_share.info`
WebShare=`/sbin/getcfg SHARE_DEF defWeb -d Qweb -f /etc/config/def_share.info`
MultimediaShare=`/sbin/getcfg SHARE_DEF defMultimedia -d Qmultimedia -f /etc/config/def_share.info`
DownloadShare=`/sbin/getcfg SHARE_DEF defDownload -d Qdownload -f /etc/config/def_share.info`
RecordingsShare=`/sbin/getcfg SHARE_DEF defRecordings -d Qrecordings -f /etc/config/def_share.info`
if [ "x$SUPPORT_NVR" = "xyes" ]; then
if [ x$RecordingsShare = x"none" ]; then
/sbin/setcfg SHARE_DEF defRecordings "${defRecordingsShare}" -f /etc/default_config/def_share.info
/sbin/setcfg SHARE_DEF defRecordings "${defRecordingsShare}" -f /etc/config/def_share.info
fi
if [ `/sbin/getcfg NVR "Enable" -u -d FALSE` = TRUE ]; then
DEF_SHARE="${PublicShare} ${UsbShare} ${WebShare} ${MultimediaShare} ${DownloadShare} ${RecordingsShare}"
else
DEF_SHARE="${PublicShare} ${UsbShare} ${WebShare} ${MultimediaShare} ${DownloadShare}"
fi
else
if [ x$RecordingsShare != x"none" ]; then
/sbin/setcfg SHARE_DEF defRecordings none -f /etc/default_config/def_share.info
/sbin/setcfg SHARE_DEF defRecordings none -f /etc/config/def_share.info
fi
DEF_SHARE="${PublicShare} ${UsbShare} ${WebShare} ${MultimediaShare} ${DownloadShare}"
fi
noshare=""
cnt=0
nofolder=""
fcnt=0
[ -z "`/bin/df | /bin/grep /share`" ] && return
for i in $DEF_SHARE
do
Dir_Path=`/sbin/getcfg $i path -d "none" -f /etc/config/smb.conf`
echo "$Dir_Path"
if [ "$i" != "none" ] && [ ! -d $Dir_Path ]; then
[ $cnt = 0 ] && noshare="$i" || noshare="$noshare, $i"
cnt=`expr $cnt + 1`
fi
done
for j in $DEF_SHARE
do
if [ "$i" != "none" ] && [ ! -d "/share/${j}" ]; then
[ $fcnt = 0 ] && nofolder="$j" || nofolder="$nofolder, $j"
fcnt=`expr $fcnt + 1`
fi
done
if [ $cnt -gt 0 ]; then
[ $cnt = 1 ] \
&& msg="Default network share($noshare) does not exist. Restore default network shares or format your disk volume." \
|| msg="Default network shares($noshare) do not exist. Restore default network shares or format your disk volume."
echo "Warning: $msg"
/sbin/write_log "$msg" 2
fi
if [ $fcnt -gt 0 ]; then
[ $fcnt = 1 ] \
&& msg="Folder($nofolder) for default network shares does not exist. Restore default network shares or format your disk volume." \
|| msg="Folders($nofolder) for default network shares do not exist. Restore default network shares or format your disk volume."
echo "Warning: $msg"
/sbin/write_log "$msg" 2
fi
}
# booting count
booting_count() {
[ -d $MOUNTPOINT ] || /bin/mkdir $MOUNTPOINT
/bin/mount $DEV_NAS_CONFIG -t ext2 $MOUNTPOINT > /dev/null 2>&1
if [ $? = 0 ]; then
[ -f $BOOTCOUNT ] || /bin/echo -n "0" > $BOOTCOUNT
bcount=`/bin/cat $BOOTCOUNT`
if [ ! -f $EXPR ]; then
[ -f /bin/expr ] || /bin/ln -sf busybox /bin/expr
EXPR="/bin/expr"
fi
bcount=`$EXPR ${bcount} + 1`
[ ${bcount} -lt 10000 ] || bcount=0
/bin/echo -n $bcount > $BOOTCOUNT
/bin/sync
/bin/umount $DEV_NAS_CONFIG
[ $? = 0 ] || /bin/echo "umount $DEV_NAS_CONFIG failed."
/bin/echo "The system had been started ${bcount} time(s)."
return 0
fi
}
booting_cur_count() {
[ -d $MOUNTPOINT ] || /bin/mkdir $MOUNTPOINT
/bin/mount $DEV_NAS_CONFIG -t ext2 $MOUNTPOINT > /dev/null 2>&1
if [ $? = 0 ]; then
[ -f $BOOTCOUNT ] || /bin/echo -n "0" > $BOOTCOUNT
bcount=`/bin/cat $BOOTCOUNT`
/bin/sync
/bin/umount $DEV_NAS_CONFIG
[ $? = 0 ] || /bin/echo "umount $DEV_NAS_CONFIG failed."
/bin/echo "The system had been started ${bcount} time(s)."
return 0
fi
}
reset_booting_count() {
[ -d $MOUNTPOINT ] || /bin/mkdir $MOUNTPOINT
/bin/mount $DEV_NAS_CONFIG -t ext2 $MOUNTPOINT > /dev/null 2>&1
if [ $? = 0 ]; then
/bin/echo -n "0" > $BOOTCOUNT
/bin/umount $DEV_NAS_CONFIG
[ $? = 0 ] || /bin/echo "umount $DEV_NAS_CONFIG failed."
/bin/echo "The booting count is set to 0."
return 0
fi
}
case "$1" in
booting_count)
booting_count
exit 0
;;
booting_cur_count)
booting_cur_count
exit 0
;;
reset_booting_count)
reset_booting_count
exit 0
;;
*)
echo
esac
# booting count end here
/sbin/daemon_mgr bcclient stop /sbin/bcclient
/bin/pidof bcclient >/dev/null
[ $? != 0 ] || /bin/kill -9 `pidof bcclient`
/sbin/daemon_mgr bcclient start /sbin/bcclient
/sbin/setcfg System Booting 1
# add for Buzzer of warning
BUZZER="/root/.buzzer_warnning.conf"
echo "[Misc]" >> $BUZZER
if [ `/sbin/getcfg "Misc" "Buzzer Warning Enable" -u -d TRUE` = TRUE ]; then
/sbin/setcfg "Misc" "Buzzer Warning Enable" TRUE -f $BUZZER
else
/sbin/setcfg "Misc" "Buzzer Warning Enable" FALSE -f $BUZZER
fi
[ -f /sbin/picd ] && /sbin/daemon_mgr picd start "/sbin/picd 1>/dev/null 2>/dev/null &" &
[ -f /sbin/gpiod ] && /sbin/daemon_mgr gpiod start "/sbin/gpiod &" &
CPU_MODEL=""
[ ! -f /proc/tsinfo/cpu_model ] || CPU_MODEL=`/bin/cat /proc/tsinfo/cpu_model 2>/dev/null`
MODEL_NAME=`/sbin/getcfg "System" "Model"`
if [ "x${CPU_MODEL}" = "x88F6281 A0" ] && [ "x${MODEL_NAME}" = "xTS-119" ];then
/bin/rm /sbin/hwmond
fi
[ -f /sbin/hwmond ] && /sbin/daemon_mgr hwmond start "/sbin/hwmond &" &
[ -f /sbin/acpid ] && /sbin/daemon_mgr acpid start "/sbin/acpid" &
[ -f /usr/sbin/upsutil ] && /sbin/daemon_mgr upsutil start "/usr/sbin/upsutil &" &
[ -f /sbin/gpiod ] && /bin/kill -USR1 `pidof gpiod`
if [ `/sbin/getcfg "" "User Enable" -u -d FALSE -f /etc/config/usr_quota.conf` = TRUE ]; then
/sbin/quotaon -au > /dev/null 2>&1
/sbin/setquota -u -F vfsv0 0 0 0 0 0 -a
/sbin/setquota -u -F vfsv0 99 0 0 0 0 -a 2>>/dev/null
fi
rsync_startup
#start syslog server
[ -f /etc/init.d/rsyslog.sh ] && /etc/init.d/rsyslog.sh start &
# for customer
touch /tmp/quick_tmp.conf
/bin/mount $DEV_NAS_CONFIG -t ext2 /tmp/config
if [ "$?" = "0" ]; then
echo -n "Automatically start autorun.sh: "
if [ -f /tmp/config/autorun.sh ]; then
echo "SUCCESS!"
/tmp/config/autorun.sh
else
echo "Not found."
fi
for i in /tmp/config/* ;do
case "$i" in
/tmp/config/K01*.sh)
echo $i start
. $i start &
cp $i /etc/rcK_init.d
;;
*)
;;
esac
done
if [ -f /tmp/config/.write_cache ]; then
/sbin/setcfg Misc "Enable Write Cache" 1
/sbin/setcfg Misc "Enable Write Cache" 1 -f /etc/default_config/uLinux.conf
fi
if [ -f /tmp/config/.case_sensitive ]; then
/sbin/setcfg Samba "Case Sensitive" yes
/sbin/setcfg Samba "Case Sensitive" yes -f /etc/default_config/uLinux.conf
fi
CNT=0
while [ $CNT -lt 5 ]; do
/bin/umount $DEV_NAS_CONFIG 2>/dev/null
if [ $? = 0 ]; then
break;
fi
sleep 1
CNT=`expr $CNT + 1`
done
[ $? = 0 ] || /bin/echo "init_nas.sh: umount $DEV_NAS_CONFIG failed."
fi
# For Badblocks Scan
if [ -f /etc/config/badblocks.conf ]; then
/sbin/setcfg -f /etc/config/badblocks.conf "Bad Block" Status 0
fi
check_def_share
/etc/init.d/update_def_share.sh &
[ -f /sbin/get_hwsn ] && /sbin/get_hwsn
if [ x`/sbin/getcfg Misc "Buzzer Quiet Enable"` != "xTRUE" ]; then
if [ -x /sbin/hal_app ]; then
/sbin/hal_app --se_buzzer enc_id=0,mode=1
else
/sbin/pic_raw 81
fi
fi
# For NASPPC TS-129 & TS-119P+ LOGO LED Mode
if [ "x${BOOT_CONF}" = "xTS-NASARM" ] || [ "x${BOOT_CONF}" = "xTS-NASPPC" ]; then
CPU_MODEL=""
[ ! -f /proc/tsinfo/cpu_model ] || CPU_MODEL=`/bin/cat /proc/tsinfo/cpu_model | cut -d ' ' -f 1 2>/dev/null`
if [ "x${CPU_MODEL}" = "x88F6282" ];then
LOGO_Model=`/sbin/getcfg System "QNAP_LOGO_Mode" -d 1`
case "x${LOGO_Model}" in
"x1")
/sbin/pic_raw 192
;;
"x2")
/sbin/pic_raw 193
;;
"x3")
/sbin/pic_raw 194
;;
*)
;;
esac
fi
fi
Internal_Model=`/sbin/getcfg System "Internal Model"`
/bin/echo "init_nas.sh: check_last_degrade_error storage_boot_init 5"
if [ -f /sbin/storage_boot_init ]; then
/sbin/storage_boot_init 5
fi
/bin/echo "init_nas.sh: set LED with storage_boot_init 4"
if [ -f /sbin/storage_boot_init ]; then
/sbin/storage_boot_init 4
fi
[ -f /sbin/hd_util ] && /sbin/daemon_mgr hd_util start "/sbin/hd_util &" &
[ -f /sbin/.tune ] && /sbin/.tune
[ -f /sbin/gen_bandwidth ] && /sbin/daemon_mgr gen_bandwidth start "/sbin/gen_bandwidth -r -i 5 &" &
# For utelnetd
/etc/init.d/runone.sh
/etc/init.d/gen_issue.sh
/etc/init.d/ddns_update.sh
/usr/bin/readlink /etc/inittab | grep enable > /dev/null
/sbin/ip_filter
#add for online users
/sbin/initsem 2>/dev/null 1>/dev/null
# add Wake On Lan
NIC_NUM=`/sbin/getcfg "Network" "Interface Number"`
if [ `/sbin/getcfg "Misc" "Wake On Lan" -u -d TRUE` = TRUE ]; then
echo "WOL: enabled."
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
/usr/sbin/ethtool -s eth$i wol g
done
else
echo "WOL: disabled."
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
/usr/sbin/ethtool -s eth$i wol d
done
fi
if [ "x$Internal_Model" = "xTS-119" ] || [ "x$Internal_Model" = "xTS-219" ] || [ "x$Internal_Model" = "xTS-419" ] ;then
if [ -x /sbin/hal_app ]; then
if [ `/sbin/getcfg System "EUP Status" -d 0` = 0 ]; then
echo "EUP: disable."
/sbin/hal_app --se_sys_disable_eup enc_sys_id=root
else
echo "EUP: enable."
/sbin/hal_app --se_sys_enable_eup enc_sys_id=root
fi
else
CPU_MODEL=""
[ ! -f /proc/tsinfo/cpu_model ] || CPU_MODEL=`/bin/cat /proc/tsinfo/cpu_model | cut -d ' ' -f 1 2>/dev/null`
if [ "x${CPU_MODEL}" = "x88F6282" ];then
if [ `/sbin/getcfg System "EUP Status" -d 0` = 0 ]; then
echo "EUP: disable."
/sbin/pic_raw 244
else
echo "EUP: enable."
/sbin/pic_raw 245
fi
fi
fi
fi
# For localtime
if [ -f /etc/config/localtime ]; then
/bin/echo "/etc/config/localtime is exist"
/bin/rm /etc/localtime
/bin/cp /etc/config/localtime /etc/localtime
else
/bin/echo "/etc/config/localtime is not exist"
fi
# Only allow read in GUI 2.0
if [ -f /home/httpd/cgi-bin/authLogin.cgi ]; then
/bin/chmod 444 /home/httpd/cgi-bin/quick/quick.cgi
/bin/chmod 444 /home/httpd/cgi-bin/quick/quick_info.cgi
fi
/sbin/setcfg System Booting 0
/sbin/setcfg "UPS" "AC Power" "OK"
#Look usb copy function in Booting QNAS
/sbin/setcfg "usb copy" "lock flag" 0 -f "/etc/config/uLinux.conf"
#Set power LED on
if [ -x /sbin/hal_app ]; then
/sbin/hal_app --power_led enc_id=0,enable=1
else
if [ "x$Internal_Model" = "xTS-609" ] || [ "x$Internal_Model" = "xTS-239" ] || [ "x$Internal_Model" = "xTS-439" ] || [ "x$Internal_Model" = "xTS-639" ] || [ "x$Internal_Model" = "xTS-839" ] || [ "x$Internal_Model" = "xTS-259" ] || [ "x$Internal_Model" = "xTS-459" ] || [ "x$Internal_Model" = "xTS-559" ]|| [ "x$Internal_Model" = "xTS-659" ] || [ "x$Internal_Model" = "xTS-859" ] || [ "x$Internal_Model" = "xTS-1279" ] || [ "x$Internal_Model" = "xTS-879" ] || [ "x$Internal_Model" = "xTS-1079" ] || [ "x$Internal_Model" = "xTS-469" ] || [ "x$Internal_Model" = "xTS-569" ] || [ "x$Internal_Model" = "xTS-669" ] || [ "x$Internal_Model" = "xTS-869" ]; then
/sbin/pic_raw 77
fi
fi
#set web file manager link
if [ `/sbin/getcfg "WebFS" "Enable" -u -d TRUE` = TRUE ]; then
[ -d /home/httpd/cgi-bin/filemanager/share ] || /bin/ln -sf /share /home/httpd/cgi-bin/filemanager/share
else
[ -d /home/httpd/cgi-bin/filemanager/share ] && /bin/rm -f /home/httpd/cgi-bin/filemanager/share
fi
#start Virtual Disk in TS-x10 TS-x19 TS-x12 This machine slower connection not occur before the boot process.
if [ "x$Internal_Model" = "xTS-119" ] || [ "x$Internal_Model" = "xTS-219" ] || [ "x$Internal_Model" = "xTS-419" ] || [ "x$Internal_Model" = "xTS-110" ] || [ "x$Internal_Model" = "xTS-210" ] || [ "x$Internal_Model" = "xTS-410" ] || [ "x$Internal_Model" = "xTS-112" ] || [ "x$Internal_Model" = "xTS-212" ] || [ "x$Internal_Model" = "xTS-412" ];then
VDD_ENABLED_LAST=yes
else
VDD_ENABLED_LAST=no
fi
if [ "${VDD_ENABLED_LAST}" = "no" ];then
[ -f /etc/init.d/iscsiinit.sh ] && /etc/init.d/iscsiinit.sh start &
fi
#start lcdmond
if [ -f /sbin/lcd_hwtest ] ;then
/sbin/lcd_hwtest -c
[ $? = 0 ] && /sbin/daemon_mgr lcdmond start /sbin/lcdmond
fi
[ -f /sbin/qLogEngined ] && /sbin/daemon_mgr qLogEngined start /sbin/qLogEngined &
[ "x${CMS_ENABLE}" != xTRUE ] && [ -f /sbin/qsyslogd ] && /sbin/daemon_mgr qsyslogd start /sbin/qsyslogd &
[ -f /sbin/qShield ] && /sbin/daemon_mgr qShield start /sbin/qShield &
[ -f /etc/config/update_fw_ok ] && /bin/rm /etc/config/update_fw_ok &
[ -f /sbin/update_krb5_ticket ] && /sbin/update_krb5_ticket &
[ -f /etc/init.d/klogd.sh ] && /sbin/daemon_mgr klogd.sh start "/etc/init.d/klogd.sh start &" &
#start Radius
[ -f /etc/init.d/radius.sh ] && /etc/init.d/radius.sh start &
#mount ISO share
[ -f /etc/init.d/iso_mount.sh ] && /etc/init.d/iso_mount.sh start &
#check wfm2 config file
[ ! -f /etc/config/wfm2.conf ] && /bin/cp -rf /etc/default_config/wfm2.conf /etc/config/
#init acl
[ -f /sbin/init_acl ] && /etc/init.d/init_acl.sh &
#check ldap
if [ `/sbin/getcfg LDAP Enable -u -d FALSE` = TRUE ]
then
/sbin/check_ldap & 1>/dev/null 2>/dev/null
fi
#start vpn pptp
[ -f /etc/init.d/vpn_pptp.sh ] && /etc/init.d/vpn_pptp.sh start &
#start vpn openvpn
[ -f /etc/init.d/vpn_openvpn.sh ] && /etc/init.d/vpn_openvpn.sh start &
#start ldap server
if [ -f /etc/init.d/ldap_server.sh ];then
/etc/init.d/ldap_server.sh init
/etc/init.d/ldap_server.sh start &
fi
if [ "${VDD_ENABLED_LAST}" = "yes" ];then
[ -f /etc/init.d/iscsiinit.sh ] && /etc/init.d/iscsiinit.sh start &
fi
if [ -x "/sbin/appriv" ]; then
if [ ! -f /etc/config/nas_priv.db -o ! -s /etc/config/nas_priv.db ]; then
/sbin/appriv -i
else
/sbin/appriv -g &
fi
fi

57
init_network.sh Executable file
View File

@@ -0,0 +1,57 @@
#!/bin/sh
#
# initialise network card
#
MOUNTPOINT="/tmp/config"
SATA="/dev/sda"
ESATA="/dev/sdf"
USB1="/dev/sdi"
USB2="/dev/sdo"
USB3="/dev/sdu"
hdperm_test()
{
# test SATA device
if [ ! -f $MOUNTPOINT/hdparm.sata ]; then
/bin/dd if=$SATA of=/tmp/pftest bs=1 count=1 2> /dev/null 1> /dev/null
if [ $? = 0 ]; then
/sbin/hdparm -t $SATA > $MOUNTPOINT/hdparm.sata
fi
fi
# test ESATA device
if [ ! -f $MOUNTPOINT/hdparm.esata ]; then
/bin/dd if=$ESATA of=/tmp/pftest bs=1 count=1 2> /dev/null 1> /dev/null
if [ $? = 0 ]; then
/sbin/hdparm -t $ESATA > $MOUNTPOINT/hdparm.esata
fi
fi
# test USB1 device
if [ ! -f $MOUNTPOINT/hdparm.usb1 ]; then
/bin/dd if=$USB1 of=/tmp/pftest bs=1 count=1 2> /dev/null 1> /dev/null
if [ $? = 0 ]; then
/sbin/hdparm -t $USB1 > $MOUNTPOINT/hdparm.usb1
fi
fi
# test USB2 device
if [ ! -f $MOUNTPOINT/hdparm.usb2 ]; then
/bin/dd if=$USB2 of=/tmp/pftest bs=1 count=1 2> /dev/null 1> /dev/null
if [ $? = 0 ]; then
/sbin/hdparm -t /dev/sdk > $MOUNTPOINT/hdparm.usb2
fi
fi
# test USB3 device
if [ ! -f $MOUNTPOINT/hdparm.usb3 ]; then
/bin/dd if=$USB3 of=/tmp/pftest bs=1 count=1 2> /dev/null 1> /dev/null
if [ $? = 0 ]; then
/sbin/hdparm -t /dev/sdr > $MOUNTPOINT/hdparm.usb3
fi
fi
}
#advanced bonding network rescan in booting
if [ `/sbin/getcfg "Network" "Advanced Bonding Support" -u -d "FALSE"` = "TRUE" ]; then
if [ -f /sbin/network_boot_rescan ]; then
/sbin/network_boot_rescan
fi
fi

103
init_qpkg.sh Executable file
View File

@@ -0,0 +1,103 @@
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
ROOT_PART="/mnt/HDA_ROOT"
HIDDEN_CONF_DIR="${ROOT_PART}/.config"
UPDATEPKG_DIR="${ROOT_PART}/update_pkg"
RET_RM_QPKG_SOURCE=10
JOOMLA_QPKG="${UPDATEPKG_DIR}/Joomla.qpkg"
PHPMYADMIN_QPKG="${UPDATEPKG_DIR}/phpMyAdmin.qpkg"
WORDPRESS_QPKG="${UPDATEPKG_DIR}/WordPress.qpkg"
Project_Name=`/sbin/getcfg Project Name -d null -f /var/default`
. /etc/init.d/functions
make_qpkg_base(){
FindDefVol
_ret=$?
if [ $_ret != 0 ]; then
echo "Default volume not found."
exit 1
fi
QPKG_BASE="${DEF_VOLMP}"
[ -d "${QPKG_BASE}/.qpkg" ] || /bin/mkdir -p "${QPKG_BASE}/.qpkg"
/bin/chmod 777 "${QPKG_BASE}/.qpkg"
if [ "x${Project_Name}" = "xAthens" ]; then
/bin/rm -rf "${QPKG_BASE}/.pkg"
[ -d "${QPKG_BASE}/.pkg" ] || /bin/ln -sf ".qpkg" "${QPKG_BASE}/.pkg"
fi
}
case "$1" in
start)
/usr/bin/readlink /etc/config | grep ".config" 1>>/dev/null 2>>/dev/null
make_qpkg_base
if [ $? = 0 ] && [ -d $HIDDEN_CONF_DIR ]; then
[ -f /etc/config/qpkg.conf ] || /bin/touch /etc/config/qpkg.conf
/sbin/qpkg --set-rc
if [ "x${Project_Name}" = "xAthens" ]; then
PHPMYADMIN_QPKG="${UPDATEPKG_DIR}/phpMyAdmin.pkg"
WORDPRESS_QPKG="${UPDATEPKG_DIR}/WordPress.pkg"
for i in ${UPDATEPKG_DIR}/*.pkg ;do
echo "Install ${i} ..."
if [ x`/sbin/qpkg --check ${i}` = xTRUE ]; then
if [ "x${i}" = "x${PHPMYADMIN_QPKG}" ]; then
/bin/sh ${i}
/bin/rm -f ${i}
elif [ "x${i}" = "x${WORDPRESS_QPKG}" ]; then
/bin/sh ${i}
/bin/rm -f ${i}
else
/bin/sh ${i}
[ $? == 0 ] || /bin/rm -f ${i}
fi
else
[ ! -f ${i} ] || /bin/rm -f ${i}
fi
done
fi
for i in ${UPDATEPKG_DIR}/*.qpkg ;do
echo "Install ${i} ..."
if [ x`/sbin/qpkg --check ${i}` = xTRUE ]; then
if [ "x${i}" = "x${PHPMYADMIN_QPKG}" ]; then
/bin/sh ${i}
/bin/rm -f ${i}
elif [ "x${i}" = "x${WORDPRESS_QPKG}" ]; then
/bin/sh ${i}
/bin/rm -f ${i}
else
/bin/sh ${i}
[ $? == 0 ] || /bin/rm -f ${i}
fi
else
[ ! -f ${i} ] || /bin/rm -f ${i}
fi
done
[ ! -f ${UPDATEPKG_DIR}/update_qpkg_f ] || /bin/rm -f ${UPDATEPKG_DIR}/update_qpkg_f
fi
;;
stop)
# nothing to do
;;
restart)
$0 stop
$0 start
;;
qfix)
if [ -d $HIDDEN_CONF_DIR ]; then
for i in ${UPDATEPKG_DIR}/*.qfix ;do
echo "Install ${i} ..."
if [ x`/sbin/qpkg --check ${i}` = xTRUE ]; then
/bin/sh ${i}
else
[ ! -f ${i} ] || /bin/rm -f ${i}
fi
done
fi
;; *)
echo "Usage: /etc/init.d/qpkg.sh {start|stop|restart}"
exit 1
esac
exit 0

56
init_symform.sh Executable file
View File

@@ -0,0 +1,56 @@
#!/bin/sh
LOG="/sbin/write_log"
SETCFG="/sbin/setcfg"
OPENSSL="/usr/bin/openssl"
. /etc/init.d/functions
FindDefVol
_ret=$?
if [ $_ret != 0 ]; then
echo "Default volume not found."
exit 1
fi
SYMFORM_DIR="${DEF_VOLMP}/.qpkg/Symform"
if [ -d $SYMFORM_DIR ] ; then
/bin/ln -sf "${SYMFORM_DIR}/Symform.sh" /etc/init.d/Symform.sh
fi
if [ ! -f /etc/config/symform/public.pem ] ; then
[ -d /etc/config/symform ] || /bin/mkdir -p /etc/config/symform
/bin/cp -f /etc/default_config/symform/public.pem /etc/config/symform/public.pem
fi
case "$1" in
start)
symformEnable=`/sbin/getcfg Symform Enable -d 0`
if [ $symformEnable -eq 1 ] ; then
[ -f $SYMFORM_DIR/Symform.sh ] || exit 1
$SYMFORM_DIR/Symform.sh start
fi
;;
stop)
[ -f $SYMFORM_DIR/Symform.sh ] || exit 1
$SYMFORM_DIR/Symform.sh stop
;;
restart)
[ -f $SYMFORM_DIR/Symform.sh ] || exit 1
$SYMFORM_DIR/Symform.sh restart
;;
uninstall)
$SYMFORM_DIR/Symform.sh stop
if [ -d $SYMFORM_DIR ] ; then
$SYMFORM_DIR/.uninstall.sh
/bin/rm -rf "${SYMFORM_DIR}"
/bin/rm -rf "${DEF_VOLMP}/.symform"
fi
;;
*)
echo "Usage: init_symform {start|stop|restart|uninstall}"
exit 1
;;
esac
exit 0

29
install.sh Executable file
View File

@@ -0,0 +1,29 @@
#! /bin/sh
if [ ! -d $1 ]; then
mkdir $1
fi
if [ ! -d $2 ]; then
mkdir $2
fi
if [ ! -d $3 ]; then
mkdir $3
fi
if [ ! -d $4 ]; then
mkdir $4
fi
if [ ! -d $5 ]; then
mkdir $5
fi
if [ ! -d $6 ]; then
mkdir $6
fi
if [ ! -e /usr/bin/cut ]; then
cp cut $7/usr/bin
fi

477
installtgz.sh Executable file
View File

@@ -0,0 +1,477 @@
#!/bin/sh
MNT_POINT="/mnt/ext"
MNT_HD_ROOT_TMP="/hd_root_tmp"
UPDATEPKG_DIR="${MNT_HD_ROOT_TMP}/update_pkg"
_PKG=$2
_LCK_FLAG=$1
if [ ! -z "${_PKG}" ] && [ -f "${_PKG}" ] && [ ! -z "${_LCK_FLAG}" ]; then
[ -f "/tmp/${_LCK_FLAG}.lck" ] && exit 1
/bin/touch "/tmp/${_LCK_FLAG}.lck"
fi
case "$1" in
ffmpeg)
_PKG=$2
if [ -f ${_PKG} ]; then
[ -d ${MNT_POINT}/opt/ffmpeg ] || /bin/mkdir -p ${MNT_POINT}/opt/ffmpeg
/bin/chmod 777 ${MNT_POINT}/opt/ffmpeg
/bin/tar zxf "${_PKG}" -C ${MNT_POINT}/opt/ffmpeg 2>/dev/null
/bin/ln -sf ${MNT_POINT}/opt/ffmpeg/usr/bin/ffmpeg /usr/bin/ffmpeg
[ ! -f ${MNT_POINT}/opt/ffmpeg/usr/bin/ffserver ] || /bin/ln -sf ${MNT_POINT}/opt/ffmpeg/usr/bin/ffserver /usr/bin/
for i in `/bin/ls ${MNT_POINT}/opt/ffmpeg/usr/lib/`
do
/bin/ln -sf "${MNT_POINT}/opt/ffmpeg/usr/lib/${i}" /usr/lib/
done
/bin/sync
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/ffmpeg
;;
ImageMagick)
_PKG=$2
if [ -f ${_PKG} ]; then
[ -d ${MNT_POINT}/opt/ImageMagick ] || /bin/mkdir -p ${MNT_POINT}/opt/ImageMagick
/bin/chmod 777 ${MNT_POINT}/opt/ImageMagick
/bin/tar zxf "${_PKG}" -C ${MNT_POINT}/opt/ImageMagick 2>/dev/null
/bin/ln -sf ${MNT_POINT}/opt/ImageMagick/usr/local/sbin/convert /usr/local/sbin/convert
/bin/ln -sf ${MNT_POINT}/opt/ImageMagick/usr/local/sbin/identify /usr/local/sbin/identify
/bin/ln -sf ${MNT_POINT}/opt/ImageMagick/usr/lib/libMagickWand.so.3.0.0 /usr/lib/libMagickWand.so.3.0.0
/bin/ln -sf libMagickWand.so.3.0.0 /usr/lib/libMagickWand.so.3
/bin/ln -sf ${MNT_POINT}/opt/ImageMagick/usr/lib/libMagickCore.so.3.0.0 /usr/lib/libMagickCore.so.3.0.0
/bin/ln -sf libMagickCore.so.3.0.0 /usr/lib/libMagickCore.so.3
/bin/sync
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/ImageMagick
;;
radius)
_PKG=$2
if [ -f ${_PKG} ]; then
[ -d ${MNT_POINT}/opt/radius ] || /bin/mkdir -p ${MNT_POINT}/opt/radius
/bin/chmod 777 ${MNT_POINT}/opt/radius
/bin/tar zxf "${_PKG}" -C ${MNT_POINT}/opt/radius 2>/dev/null
/bin/ln -sf ${MNT_POINT}/opt/radius/etc/raddb /etc/raddb
/bin/ln -sf ${MNT_POINT}/opt/radius/usr/local/sbin/radclient /usr/local/sbin/radclient
/bin/ln -sf ${MNT_POINT}/opt/radius/usr/local/sbin/radiusd /usr/local/sbin/radiusd
/bin/ln -sf ${MNT_POINT}/opt/radius/usr/local/sbin/radtest /usr/local/sbin/radtest
/bin/sync
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/radius
;;
vim)
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}"
[ -d ${MNT_POINT}/opt ] || /bin/mkdir -p ${MNT_POINT}/opt
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt 2>/dev/null
/bin/rm -f /bin/vi
/bin/ln -sf ${MNT_POINT}/opt/vim/vim /bin/vi
/bin/ln -sf ${MNT_POINT}/opt/vim/vim /bin/vim
/bin/cp -f ${MNT_POINT}/opt/vim/.vimrc /root/
else
echo "${_PKG} is not exist!"
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/vim
;;
samba)
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}"
[ -d ${MNT_POINT}/opt ] || /bin/mkdir -p ${MNT_POINT}/opt
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt 2>/dev/null
/bin/rm -rf /usr/local/samba
/bin/ln -sf ${MNT_POINT}/opt/samba /usr/local/samba
else
echo "${_PKG} is not exist!"
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/samba
;;
libtorrent)
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}"
[ -d ${MNT_POINT}/opt/libtorrent ] || /bin/mkdir -p ${MNT_POINT}/opt/libtorrent
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt/libtorrent 2>/dev/null
if [ -f ${MNT_POINT}/opt/libtorrent/libtorrent-0.15.9.so.enc ]; then
/bin/ln -sf ${MNT_POINT}/opt/libtorrent/libtorrent-0.15.9.so.enc /usr/lib/libtorrent-0.15.9.so.enc
fi
if [ -f ${MNT_POINT}/opt/libtorrent/libtorrent-0.15.9.so.nonenc ]; then
/bin/ln -sf ${MNT_POINT}/opt/libtorrent/libtorrent-0.15.9.so.nonenc /usr/lib/libtorrent-0.15.9.so.nonenc
fi
if [ -f ${MNT_POINT}/opt/libtorrent/libtorrent-0.13.so.enc ]; then
/bin/ln -sf ${MNT_POINT}/opt/libtorrent/libtorrent-0.13.so.enc /usr/lib/libtorrent-0.13.so.enc
fi
if [ -f ${MNT_POINT}/opt/libtorrent/libtorrent-0.13.so.nonenc ]; then
/bin/ln -sf ${MNT_POINT}/opt/libtorrent/libtorrent-0.13.so.nonenc /usr/lib/libtorrent-0.13.so.nonenc
fi
if [ -f ${MNT_POINT}/opt/libtorrent/libboost_date_time.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/libtorrent/libboost_date_time.so.1.42.0 /usr/lib/libboost_date_time.so.1.42.0
/bin/ln -sf /usr/lib/libboost_date_time.so.1.42.0 /usr/lib/libboost_date_time.so
fi
if [ -f ${MNT_POINT}/opt/libtorrent/libboost_filesystem.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/libtorrent/libboost_filesystem.so.1.42.0 /usr/lib/libboost_filesystem.so.1.42.0
/bin/ln -sf /usr/lib/libboost_filesystem.so.1.42.0 /usr/lib/libboost_filesystem.so
fi
if [ -f ${MNT_POINT}/opt/libtorrent/libboost_program_options.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/libtorrent/libboost_program_options.so.1.42.0 /usr/lib/libboost_program_options.so.1.42.0
/bin/ln -sf /usr/lib/libboost_program_options.so.1.42.0 /usr/lib/libboost_program_options.so
fi
if [ -f ${MNT_POINT}/opt/libtorrent/libboost_regex.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/libtorrent/libboost_regex.so.1.42.0 /usr/lib/libboost_regex.so.1.42.0
/bin/ln -sf /usr/lib/libboost_regex.so.1.42.0 /usr/lib/libboost_regex.so
fi
if [ -f ${MNT_POINT}/opt/libtorrent/libboost_system.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/libtorrent/libboost_system.so.1.42.0 /usr/lib/libboost_system.so.1.42.0
/bin/ln -sf /usr/lib/libboost_system.so.1.42.0 /usr/lib/libboost_system.so
fi
if [ -f ${MNT_POINT}/opt/libtorrent/libboost_thread.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/libtorrent/libboost_thread.so.1.42.0 /usr/lib/libboost_thread.so.1.42.0
/bin/ln -sf /usr/lib/libboost_thread.so.1.42.0 /usr/lib/libboost_thread.so
fi
else
echo "${_PKG} is not exist!"
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/libtorrent
;;
printer)
_PKG=$2
_MNT_POINT="/mnt/HDA_ROOT"
if [ -f ${_PKG} ]; then
echo "install ${_PKG}"
[ -d ${_MNT_POINT}/.driver ] || /bin/mkdir -p ${_MNT_POINT}/.driver
/bin/tar zxf ${_PKG} -C ${_MNT_POINT}/.driver 2>/dev/null
else
echo "${_PKG} is not exist!"
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/printer
;;
vaultServices)
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}"
[ -d ${MNT_POINT}/opt ] || /bin/mkdir -p ${MNT_POINT}/opt
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt 2>/dev/null
[ -d /etc/config/vaultServices ] || /usr/bin/install -d /etc/config/vaultServices
[ -f /etc/config/vaultServices/vaultServices.config ] || /bin/cp -p /etc/default_config/vaultServices/vaultServices.config /etc/config/vaultServices/vaultServices.config
/bin/ln -sf ${MNT_POINT}/opt/vaultServices/vaultServices /usr/sbin/vaultServices
/bin/ln -sf ${MNT_POINT}/opt/vaultServices/vaultServicesDaemon /usr/sbin/vaultServicesDaemon
else
echo "${_PKG} is not exist!"
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/vaultServices
;;
language)
_PKG=$2
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf`
/usr/bin/readlink /home/httpd/cgi-bin/inc 1>>/dev/null 2>>/dev/null
if [ $? != 0 ] && [ "x${BOOT_CONF}" = "xTS-NASX86" ]; then
[ -d ${MNT_POINT}/opt/lang/inc ] || /bin/mkdir -p ${MNT_POINT}/opt/lang/inc
/bin/mv /home/httpd/cgi-bin/inc/* ${MNT_POINT}/opt/lang/inc/
/bin/rm -rf /home/httpd/cgi-bin/inc
/bin/ln -sf ${MNT_POINT}/opt/lang/inc /home/httpd/cgi-bin/
fi
if [ -f ${_PKG} ]; then
echo "install ${_PKG}"
/bin/tar zxf ${_PKG} -C /
else
echo "${_PKG} is not exist!"
fi
[ ! -f /home/httpd/cgi-bin/inc/lang_es-mex.js ] || /bin/rm -rf /home/httpd/cgi-bin/inc/lang_es-mex.js
[ ! -f /home/httpd/cgi-bin/inc/s_lang_es-mex.js ] || /bin/rm -rf /home/httpd/cgi-bin/inc/s_lang_es-mex.js
[ ! -f /etc/init.d/genLanglist.sh ] || /etc/init.d/genLanglist.sh
[ ! -d /tmp/install ] || /bin/touch /tmp/install/language
;;
jsLib)
_PKG=$2
if [ -f ${_PKG} ]; then
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf`
/usr/bin/readlink /home/httpd/ajax_obj 1>>/dev/null 2>>/dev/null
if [ $? != 0 ] && [ "x${BOOT_CONF}" = "xTS-NASX86" ]; then
/bin/rm -rf ${MNT_POINT}/opt/ajax_obj 1>/dev/null 2>/dev/null
[ ! -d /home/httpd/ajax_obj ] || /bin/mv /home/httpd/ajax_obj ${MNT_POINT}/opt/
[ ! -d ${MNT_POINT}/opt/ajax_obj ] || /bin/mkdir ${MNT_POINT}/opt/ajax_obj
/bin/ln -sf ${MNT_POINT}/opt/ajax_obj /home/httpd/
else
[ -d /home/httpd/ajax_obj ] || /bin/mkdir -p /home/httpd/ajax_obj
fi
/bin/tar xf ${_PKG} -C /home/httpd/
[ ! -f /home/httpd/cgi-bin/user-settings.json.bg6 ] || /bin/mv /home/httpd/cgi-bin/user-settings.json.bg6 /home/httpd/cgi-bin/user-settings.json
fi
;;
DS)
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf`
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}"
if [ ! -d /home/httpd/cgi-bin/Qdownload ]; then
if [ "x${BOOT_CONF}" = "xTS-NASX86" ]; then
[ -d ${MNT_POINT}/opt ] && /bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt
/bin/ln -sf ${MNT_POINT}/opt/Qdownload /home/httpd/cgi-bin/
else
/bin/tar zxf ${_PKG} -C /home/httpd/cgi-bin/
fi
fi
else
echo "${_PKG} is not exist!"
fi
;;
vpnpptp)
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}!"
[ -d ${MNT_POINT}/opt/vpnpptp ] || /bin/mkdir -p ${MNT_POINT}/opt/vpnpptp
/bin/chmod 777 ${MNT_POINT}/opt/vpnpptp
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt/vpnpptp 2>/dev/null
/bin/ln -sf ${MNT_POINT}/opt/vpnpptp/usr/lib/libsmbpw.1.3.so /usr/lib/libsmbpw.1.3.so
/bin/ln -sf ${MNT_POINT}/opt/vpnpptp/usr/sbin/pppd /usr/sbin/pppd
/bin/ln -sf ${MNT_POINT}/opt/vpnpptp/usr/sbin/pptpd /usr/sbin/pptpd
/bin/ln -sf ${MNT_POINT}/opt/vpnpptp/usr/sbin/pptpctrl /usr/sbin/pptpctrl
/bin/ln -sf ${MNT_POINT}/opt/vpnpptp/usr/sbin/bcrelay /usr/sbin/bcrelay
/bin/ln -sf ${MNT_POINT}/opt/vpnpptp/sbin/xtables-multi /sbin/xtables-multi
/bin/ln -sf ${MNT_POINT}/opt/vpnpptp/usr/lib/libip4tc.so.0.0.0 /usr/lib/libip4tc.so.0.0.0
/bin/ln -sf ${MNT_POINT}/opt/vpnpptp/usr/lib/libip6tc.so.0.0.0 /usr/lib/libip6tc.so.0.0.0
/bin/ln -sf ${MNT_POINT}/opt/vpnpptp/usr/lib/libxtables.so.7.0.0 /usr/lib/libxtables.so.7.0.0
[ -L /usr/local/modules/vpn ] || /bin/ln -sf ${MNT_POINT}/opt/vpnpptp/usr/local/modules/vpn /usr/local/modules/vpn
[ -L /usr/lib/xtables ] || /bin/ln -sf ${MNT_POINT}/opt/vpnpptp/usr/lib/xtables /usr/lib/xtables
/bin/sync
[ ! -d /tmp/install ] || /bin/touch /tmp/install/vpnpptp
else
echo "${_PKG} is not exist!"
fi
;;
vpnopenvpn)
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}!"
[ -d ${MNT_POINT}/opt/vpnopenvpn ] || /bin/mkdir -p ${MNT_POINT}/opt/vpnopenvpn
/bin/chmod 777 ${MNT_POINT}/opt/vpnopenvpn
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt/vpnopenvpn 2>/dev/null
/bin/ln -sf ${MNT_POINT}/opt/vpnopenvpn/usr/lib/liblzo2.so.2.0.0 /usr/lib/liblzo2.so.2.0.0
/bin/ln -sf ${MNT_POINT}/opt/vpnopenvpn/usr/lib/liblzo2.so.2.0.0 /usr/lib/liblzo2.so.2
/bin/ln -sf ${MNT_POINT}/opt/vpnopenvpn/usr/lib/liblzo2.so.2.0.0 /usr/lib/liblzo2.so
/bin/ln -sf ${MNT_POINT}/opt/vpnopenvpn/usr/sbin/openvpn /usr/sbin/openvpn
/bin/ln -sf ${MNT_POINT}/opt/vpnopenvpn/etc/openvpn /etc/openvpn
/bin/sync
[ ! -d /tmp/install ] || /bin/touch /tmp/install/vpnopenvpn
else
echo "${_PKG} is not exist!"
fi
;;
avahi0630)
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}!"
[ -d ${MNT_POINT}/opt/avahi0630 ] || /bin/mkdir -p ${MNT_POINT}/opt/avahi0630
/bin/chmod 777 ${MNT_POINT}/opt/avahi0630
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt/avahi0630 2>/dev/null
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libdaemon.so.0.5.0 /usr/lib/libdaemon.so
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libdaemon.so.0.5.0 /usr/lib/libdaemon.so.0
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/dbus-daemon /usr/sbin/dbus-daemon
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/dbus-daemon-launch-helper /usr/sbin/dbus-daemon-launch-helper
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/dbus-send /usr/sbin/dbus-send
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/dbus-monitor /usr/sbin/dbus-monitor
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/dbus-uuidgen /usr/sbin/dbus-uuidgen
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libdbus-1.so.3.5.8 /usr/lib/libdbus-1.so
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libdbus-1.so.3.5.8 /usr/lib/libdbus-1.so.3
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/etc/dbus-1 /etc/dbus-1
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-autoipd /usr/sbin/avahi-autoipd
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libavahi-client.so.3.2.9 /usr/lib/libavahi-client.so
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libavahi-client.so.3.2.9 /usr/lib/libavahi-client.so.3
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libavahi-common.so.3.5.3 /usr/lib/libavahi-common.so
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libavahi-common.so.3.5.3 /usr/lib/libavahi-common.so.3
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libavahi-core.so.7.0.2 /usr/lib/libavahi-core.so
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libavahi-core.so.7.0.2 /usr/lib/libavahi-core.so.7
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-daemon /usr/sbin/avahi-daemon
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-dnsconfd /usr/sbin/avahi-dnsconfd
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libavahi-glib.so.1.0.2 /usr/lib/libavahi-glib.so
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libavahi-glib.so.1.0.2 /usr/lib/libavahi-glib.so.1
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libavahi-gobject.so.0.0.4 /usr/lib/libavahi-gobject.so
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/lib/libavahi-gobject.so.0.0.4 /usr/lib/libavahi-gobject.so.0
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-browse /usr/sbin/avahi-browse
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-publish /usr/sbin/avahi-publish
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-resolve /usr/sbin/avahi-resolve
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-set-host-name /usr/sbin/avahi-set-host-name
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-resolve /usr/sbin/avahi-resolve-host-name
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-resolve /usr/sbin/avahi-resolve-address
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-browse /usr/sbin/avahi-browse-domains
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-publish /usr/sbin/avahi-publish-address
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/usr/sbin/avahi-publish /usr/sbin/avahi-publish-service
/bin/ln -sf ${MNT_POINT}/opt/avahi0630/etc/avahi /etc/avahi
if [ -f /etc/init.d/avahi.sh ]; then
/etc/init.d/bonjour.sh stop 1>>/dev/null 2>>/dev/null
/bin/ln -sf avahi.sh /etc/init.d/bonjour.sh
fi
/bin/sync
[ ! -d /tmp/install ] || /bin/touch /tmp/install/avahi0630
else
echo "${_PKG} is not exist!"
fi
;;
ldap_server)
_PKG=$2
if [ -f ${_PKG} ]; then
[ -d ${MNT_POINT}/opt/ldap_server ] || /bin/mkdir -p ${MNT_POINT}/opt/ldap_server
/bin/chmod 777 ${MNT_POINT}/opt/ldap_server
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt/ldap_server 2>/dev/null
[ -d /etc/openldap ] || /bin/mkdir -p /etc/openldap
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/etc/openldap/schema /etc/openldap/schema
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/sbin/slapd /usr/sbin/slapd
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/sbin/slapd /usr/sbin/slapacl
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/sbin/slapd /usr/sbin/slapadd
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/sbin/slapd /usr/sbin/slapauth
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/sbin/slapd /usr/sbin/slapcat
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/sbin/slapd /usr/sbin/slapdn
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/sbin/slapd /usr/sbin/slapindex
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/sbin/slapd /usr/sbin/slappasswd
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/sbin/slapd /usr/sbin/slapschema
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/sbin/slapd /usr/sbin/slaptest
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/bin/ldapdelete /usr/bin/ldapdelete
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/bin/ldapmodify /usr/bin/ldapadd
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/bin/ldapmodify /usr/bin/ldapmodify
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/bin/ldappasswd /usr/bin/ldappasswd
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/usr/bin/mkntpwd /usr/bin/mkntpwd
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/sbin/ntpd /sbin/ntpd
/bin/ln -sf ${MNT_POINT}/opt/ldap_server/sbin/ntpq /sbin/ntpq
echo "install ${_PKG}!"
else
echo "${_PKG} is not exist!"
fi
;;
WFM2)
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}"
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt 2>/dev/null
/bin/rm -f /home/httpd/cgi-bin/filemanager 2>/dev/null
/bin/ln -sf ${MNT_POINT}/opt/filemanager /home/httpd/cgi-bin/
else
echo "${_PKG} is not exist!"
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/WFM2
;;
WFM3)
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}"
[ -d ${MNT_POINT}/opt/WFM ] || /bin/mkdir -p ${MNT_POINT}/opt/WFM
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt/WFM 2>/dev/null
[ -d /home/httpd/cgi-bin/apps ] || /bin/mkdir -p /home/httpd/cgi-bin/apps
/bin/rm -f /home/httpd/cgi-bin/apps/fileExplorer 2>/dev/null
/bin/rm -f /home/httpd/cgi-bin/css 2>/dev/null
/bin/rm -f /home/httpd/cgi-bin/js 2>/dev/null
[ -d /home/httpd/cgi-bin/apps/fileExplorer ] || /bin/ln -sf ${MNT_POINT}/opt/WFM/cgi-bin/apps/fileExplorer /home/httpd/cgi-bin/apps/
[ -d /home/httpd/cgi-bin/css ] || /bin/ln -sf ${MNT_POINT}/opt/WFM/cgi-bin/css /home/httpd/cgi-bin/
[ -d /home/httpd/cgi-bin/js ] || /bin/ln -sf ${MNT_POINT}/opt/WFM/cgi-bin/js /home/httpd/cgi-bin/
[ -d /home/httpd/libs ] || /bin/ln -sf ${MNT_POINT}/opt/WFM/libs /home/httpd/
/bin/ln -sf ${MNT_POINT}/opt/WFM/cgi-bin/filemanager.html /home/httpd/cgi-bin/
else
echo "${_PKG} is not exist!"
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/WFM2
;;
DSv3)
_PKG=$2
if [ -f ${_PKG} ]; then
#remove addons
_HG=`getcfg HappyGet Install_Path -f /etc/config/qpkg.conf`
if [ "x$_HG" != x ]; then
[ ! -d "$_HG" ] || /bin/rm -rf "$_HG"
/bin/rm -f /share/`/sbin/getcfg SHARE_DEF defWeb -d Qweb -f /etc/config/def_share.info`/gt 2>/dev/null
/sbin/rmcfg HappyGet -f /etc/config/qpkg.conf 2>/dev/null
fi
echo "install ${_PKG}"
[ -d ${MNT_POINT}/opt/DSv3 ] || /bin/mkdir -p ${MNT_POINT}/opt/DSv3
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt/DSv3 2>/dev/null
if [ -f ${MNT_POINT}/opt/DSv3/usr/lib/libtorrent-0.15.9.so.enc ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/lib/libtorrent-0.15.9.so.enc /usr/lib/libtorrent-0.15.9.so.enc
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/lib/libtorrent-0.15.9.so.nonenc ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/lib/libtorrent-0.15.9.so.nonenc /usr/lib/libtorrent-0.15.9.so.nonenc
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/lib/libboost_date_time.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/lib/libboost_date_time.so.1.42.0 /usr/lib/libboost_date_time.so.1.42.0
/bin/ln -sf /usr/lib/libboost_date_time.so.1.42.0 /usr/lib/libboost_date_time.so
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/lib/libboost_filesystem.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/lib/libboost_filesystem.so.1.42.0 /usr/lib/libboost_filesystem.so.1.42.0
/bin/ln -sf /usr/lib/libboost_filesystem.so.1.42.0 /usr/lib/libboost_filesystem.so
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/lib/libboost_program_options.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/lib/libboost_program_options.so.1.42.0 /usr/lib/libboost_program_options.so.1.42.0
/bin/ln -sf /usr/lib/libboost_program_options.so.1.42.0 /usr/lib/libboost_program_options.so
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/lib/libboost_regex.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/lib/libboost_regex.so.1.42.0 /usr/lib/libboost_regex.so.1.42.0
/bin/ln -sf /usr/lib/libboost_regex.so.1.42.0 /usr/lib/libboost_regex.so
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/lib/libboost_system.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/lib/libboost_system.so.1.42.0 /usr/lib/libboost_system.so.1.42.0
/bin/ln -sf /usr/lib/libboost_system.so.1.42.0 /usr/lib/libboost_system.so
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/lib/libboost_thread.so.1.42.0 ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/lib/libboost_thread.so.1.42.0 /usr/lib/libboost_thread.so.1.42.0
/bin/ln -sf /usr/lib/libboost_thread.so.1.42.0 /usr/lib/libboost_thread.so
fi
[ ! -d /home/httpd/cgi-bin/Qdownload ] || /bin/rm -rf /home/httpd/cgi-bin/Qdownload
/bin/ln -sf ${MNT_POINT}/opt/DSv3/home/httpd/cgi-bin/Qdownload /home/httpd/cgi-bin/
if [ -f ${MNT_POINT}/opt/DSv3/usr/sbin/bt_tool ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/sbin/bt_tool /usr/sbin/bt_tool
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/sbin/btd ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/sbin/btd /usr/sbin/btd
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/sbin/bt_scheduler ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/sbin/bt_scheduler /usr/sbin/bt_scheduler
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/sbin/torrent_util ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/sbin/torrent_util /usr/sbin/torrent_util
fi
if [ -f ${MNT_POINT}/opt/DSv3/usr/sbin/curl_download ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/usr/sbin/curl_download /usr/sbin/curl_download
fi
if [ -d ${MNT_POINT}/opt/DSv3/opt/gt ]; then
/bin/mv -f ${MNT_POINT}/opt/DSv3/opt/gt ${MNT_POINT}/opt/DSv3/
/bin/rm -r ${MNT_POINT}/opt/DSv3/opt
fi
if [ -f ${MNT_POINT}/opt/DSv3/gt/gt_run.sh ]; then
/bin/ln -sf ${MNT_POINT}/opt/DSv3/gt/gt_run.sh /etc/init.d/gt_run.sh
/bin/chmod 755 ${MNT_POINT}/opt/DSv3/gt/gt_run.sh
fi
if [ -f ${UPDATEPKG_DIR}/gt.tgz ]; then
/bin/tar zxf ${UPDATEPKG_DIR}/gt.tgz -C ${MNT_POINT}/opt/DSv3/ 2>/dev/null
fi
_UPDATEPKG_DIR="/mnt/HDA_ROOT/update_pkg"
if [ -f ${_UPDATEPKG_DIR}/gt.tgz ]; then
/bin/tar zxf ${_UPDATEPKG_DIR}/gt.tgz -C ${MNT_POINT}/opt/DSv3/ 2>/dev/null
fi
else
echo "${_PKG} is not exist!"
fi
;;
aMule)
_PKG=$2
if [ -f ${_PKG} ]; then
[ -d ${MNT_POINT}/opt/aMule ] || /bin/mkdir -p ${MNT_POINT}/opt/aMule
/bin/chmod 777 ${MNT_POINT}/opt/aMule
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt/aMule 2>/dev/null
/bin/ln -sf ${MNT_POINT}/opt/aMule /usr/local/aMule
echo "install ${_PKG}!"
else
echo "${_PKG} is not exist!"
fi
;;
medialibrary)
_PKG=$2
if [ -f ${_PKG} ]; then
echo "install ${_PKG}"
/bin/tar zxf ${_PKG} -C ${MNT_POINT}/opt 2>/dev/null
/bin/ln -sf ${MNT_POINT}/opt/medialibrary /usr/local/medialibrary
else
echo "${_PKG} is not exist!"
fi
[ ! -d /tmp/install ] || /bin/touch /tmp/install/medialibrary
;;
*)
exit 0
esac
/bin/rm "/tmp/${_LCK_FLAG}.lck" 2>/dev/null
exit 0

252
ipchange_notify.sh Executable file
View File

@@ -0,0 +1,252 @@
#!/bin/sh
# echo "Start ipchange_notify.sh:"
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
GETCFG="/sbin/getcfg"
DEFAULT_GW_DEV=`$GETCFG "Network" "Default GW Device" -d eth0`
BOND0_VLAN=`$GETCFG "bond0" "vlan_enable" -d FALSE`
BOND0_VLAN_ID=`$GETCFG "bond0" "vlan_id"`
BOND1_VLAN=`$GETCFG "bond1" "vlan_enable" -d FALSE`
BOND1_VLAN_ID=`$GETCFG "bond1" "vlan_id"`
ETH0_VLAN=`$GETCFG "eth0" "vlan_enable" -d FALSE`
ETH0_VLAN_ID=`$GETCFG "eth0" "vlan_id"`
ETH1_VLAN=`$GETCFG "eth1" "vlan_enable" -d FALSE`
ETH1_VLAN_ID=`$GETCFG "eth1" "vlan_id"`
ETH2_VLAN=`$GETCFG "eth2" "vlan_enable" -d FALSE`
ETH2_VLAN_ID=`$GETCFG "eth2" "vlan_id"`
ETH3_VLAN=`$GETCFG "eth3" "vlan_enable" -d FALSE`
ETH3_VLAN_ID=`$GETCFG "eth3" "vlan_id"`
NIC_NUM=`$GETCFG "Network" "Interface Number" -d "2"`
BOND_NUM=`/usr/bin/expr ${NIC_NUM} / 2`
ADV_BOND_SUPPORT=`$GETCFG "Network" "Advanced Bonding Support" -d "FALSE"`
NSS_ENABLED=`/sbin/getcfg NVR "NSS Enabled" -d no`
use_source_route()
{
# for each eth, bond,add a dedicate routing table with a default route.
for LAN_PREFIX in eth bond
do
for (( i=0; i <=$NIC_NUM; i++))
do
case "$LAN_PREFIX" in
eth)
let ROUTE_TBL=$i+1
DEFAULT_PRIORITY=500
;;
bond)
let ROUTE_TBL=$i+11
DEFAULT_PRIORITY=400
;;
esac
LAN=$LAN_PREFIX$i
# obtain the ipv4 ip for the specified eth device
IP_ADDR="$(/sbin/ifconfig $LAN 2> /dev/null | sed -n '/inet /{s/.*addr://;s/ .*//;p}')"
if [ x$IP_ADDR != "x" ]; then
# find the default gateway via this interface $LAN
# default via 172.17.22.1 dev $LAN
GATEWAY="$(/bin/ip route show | /bin/awk -v NIC=$LAN '{if ($1 == "default" && $5 == NIC) print $3}')"
SUBNET="$(/bin/ip route show | /bin/awk -v NIC=$LAN -v IP=$IP_ADDR '{if ($9 == IP && $3 == NIC) print $1}')"
# add a subnet route
/bin/ip route delete $SUBNET tab $ROUTE_TBL &> /dev/null
/bin/ip route add $SUBNET via $IP_ADDR dev $LAN tab $ROUTE_TBL &> /dev/null
# add a source routing rule
/bin/ip rule delete from $IP_ADDR/32 tab $ROUTE_TBL &> /dev/null
/bin/ip rule add from $IP_ADDR/32 tab $ROUTE_TBL priority $DEFAULT_PRIORITY
if [ x$GATEWAY != "x" ]; then
echo $GATEWAY
/bin/ip route delete default tab $ROUTE_TBL &> /dev/null
/bin/ip route add default via $GATEWAY dev $LAN tab $ROUTE_TBL
fi
fi
done
done
/bin/ip route flush cache
}
update_ddns()
{
if [ `/sbin/getcfg DDNS Enable -u -d FALSE` = TRUE ];then
# echo "ddns enable"
/sbin/test -f /usr/sbin/create_ddns_conf || return 0
# echo -n "ddns update"
/etc/init.d/ddns_update.sh > /dev/null
# echo "."
if [ -f /var/ddns_tmp.conf ];then
ddns_tmp=1
server_type=`/sbin/getcfg "DDNS" "Server Type" -u -d "0" -f "/var/ddns_tmp.conf"`
else
ddns_tmp=0
server_type=`/sbin/getcfg "DDNS" "Server Type" -u -d "0"`
fi
if [ "x${server_type}" != x5 ];then
# check the crontab
/bin/cat /etc/config/crontab | /bin/grep ddns_update.sh > /dev/null
result=$?
if [ $result -ne 0 ]
then
echo "0 5 * * * /etc/init.d/ddns_update.sh" >> /etc/config/crontab
/usr/bin/crontab /etc/config/crontab
echo "add success"
fi
if [ ${ddns_tmp} = 1 ]; then
set_time=`/sbin/getcfg "DDNS" "Check External IP" -d "0" -f "/var/ddns_tmp.conf"`
else
set_time=`/sbin/getcfg "DDNS" "Check External IP" -d "0"`
fi
/bin/sed -i '/check_ddns_external_ip.sh/d' /etc/config/crontab
if [ ${set_time} -eq 60 ]; then
/bin/echo "0 * * * * /etc/init.d/check_ddns_external_ip.sh 1>/dev/null 2>/dev/null" >> /etc/config/crontab
elif [ ${set_time} -ne 0 ]; then
/bin/echo "*/${set_time} * * * * /etc/init.d/check_ddns_external_ip.sh 1>/dev/null 2>/dev/null" >> /etc/config/crontab
fi
/usr/bin/crontab /etc/config/crontab
echo "add success"
fi
# else
# echo "ddns disable"
fi
}
/bin/sleep 2
update_ddns
/etc/init.d/winbind restart &
[ -f /etc/init.d/upnpd.sh ] && /etc/init.d/upnpd.sh restart &
/etc/init.d/gen_issue.sh
[ -f /sbin/lcd_tool ] && /sbin/lcd_tool -n 1
# restart nvrd
if [ -f /etc/init.d/nvrd.sh ] && [ -f /tmp/.boot_done ]; then
#echo "`date`" "begin ipchange_notify.sh restart nvrd" >> /tmp/nvrd_dbg
if [ "x${NSS_ENABLED}" = "xyes" ]; then
if [ "`/etc/init.d/nvrd.sh started`" == "1" ]; then
/etc/init.d/nvrd.sh _restart &
fi
else
/etc/init.d/nvrd.sh restart &
fi
#echo "`date`" "end ipchange_notify.sh restart nvrd" >> /tmp/nvrd_dbg
fi
[ -d /sys/kernel/config/target/iscsi ] && /sbin/iscsi_util --ip_change
[ "x`/bin/pidof bcclient`" = x ] || /bin/kill -USR1 `/bin/pidof bcclient`
model_name=`/bin/cat /etc/config/BOOT.conf`
# add the source routing policy
# it must be placed before default route removal
use_source_route
if [ "x$ADV_BOND_SUPPORT" = "xTRUE" ]; then
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
if [ "x${DEFAULT_GW_DEV}" != "xeth$i" ]; then
/sbin/route del default eth$i &>/dev/null
VLAN_ENABLE=`$GETCFG "eth$i" "vlan_enable" -d FALSE`
if [ "x$VLAN_ENABLE" = "xTRUE" ]; then
VLAN_ID=`$GETCFG "eth$i" "vlan_id"`
/sbin/route del default eth$i.${VLAN_ID} &>/dev/null
fi
fi
done
for (( i=0; i<$BOND_NUM; i=i+1 ))
do
if [ "x${DEFAULT_GW_DEV}" != "xbond$i" ]; then
/sbin/route del default bond$i &>/dev/null
VLAN_ENABLE=`$GETCFG "bond$i" "vlan_enable" -d FALSE`
if [ "x$VLAN_ENABLE" = "xTRUE" ]; then
VLAN_ID=`$GETCFG "bond$i" "vlan_id"`
/sbin/route del default bond$i.${VLAN_ID} &>/dev/null
fi
fi
done
else
if [ "$NIC_NUM" = "4" ]; then
if [ "x${DEFAULT_GW_DEV}" != "xeth0" ]; then
/sbin/route del default eth0 2>/dev/null 1>/dev/null
if [ "x${ETH0_VLAN}" = "xTRUE" ]; then
/sbin/route del default eth0.${ETH0_VLAN_ID} 2>/dev/null 1>/dev/null
fi
fi
if [ "x${DEFAULT_GW_DEV}" != "xeth1" ]; then
/sbin/route del default eth1 2>/dev/null 1>/dev/null
if [ "x${ETH1_VLAN}" = "xTRUE" ]; then
/sbin/route del default eth1.${ETH1_VLAN_ID} 2>/dev/null 1>/dev/null
fi
fi
if [ "x${DEFAULT_GW_DEV}" != "xeth2" ]; then
/sbin/route del default eth2 2>/dev/null 1>/dev/null
if [ "x${ETH2_VLAN}" = "xTRUE" ]; then
/sbin/route del default eth2.${ETH2_VLAN_ID} 2>/dev/null 1>/dev/null
fi
fi
if [ "x${DEFAULT_GW_DEV}" != "xeth3" ]; then
/sbin/route del default eth3 2>/dev/null 1>/dev/null
if [ "x${ETH3_VLAN}" = "xTRUE" ]; then
/sbin/route del default eth3.${ETH3_VLAN_ID} 2>/dev/null 1>/dev/null
fi
fi
if [ "x${DEFAULT_GW_DEV}" != "xbond0" ]; then
/sbin/route del default bond0 2>/dev/null 1>/dev/null
if [ "x${BOND0_VLAN}" = "xTRUE" ]; then
/sbin/route del default bond0.${BOND0_VLAN_ID} 2>/dev/null 1>/dev/null
fi
fi
if [ "x${DEFAULT_GW_DEV}" != "xbond1" ]; then
/sbin/route del default bond1 2>/dev/null 1>/dev/null
if [ "x${BOND1_VLAN}" = "xTRUE" ]; then
/sbin/route del default bond1.${BOND1_VLAN_ID} 2>/dev/null 1>/dev/null
fi
fi
if [ "x${DEFAULT_GW_DEV}" != "xwlan0" ]; then
/sbin/route del default wlan0 2>/dev/null 1>/dev/null
fi
else
if [ "x${DEFAULT_GW_DEV}" = "xeth1" ]; then
/sbin/route del default eth0 2>/dev/null 1>/dev/null
/sbin/route del default wlan0 2>/dev/null 1>/dev/null
if [ "x${ETH0_VLAN}" = "xTRUE" ]; then
/sbin/route del default eth0.${ETH0_VLAN_ID} 2>/dev/null 1>/dev/null
fi
if [ "x$model_name" == "xTS-NASARM" ] && [ ! -x /sbin/hal_app ]; then
/sbin/route add default gw `/sbin/getcfg "" GATEWAYS -f /etc/dhcpc/dhcpcd-eth1.info` eth1
fi
elif [ "x${DEFAULT_GW_DEV}" = "xeth0" ]; then
/sbin/route del default eth1 2>/dev/null 1>/dev/null
/sbin/route del default wlan0 2>/dev/null 1>/dev/null
if [ "x${ETH1_VLAN}" = "xTRUE" ]; then
/sbin/route del default eth1.${ETH1_VLAN_ID} 2>/dev/null 1>/dev/null
fi
if [ "x$model_name" == "xTS-NASARM" ] && [ ! -x /sbin/hal_app ]; then
/sbin/route add default gw `/sbin/getcfg "" GATEWAYS -f /etc/dhcpc/dhcpcd-eth0.info` eth0
fi
elif [ "x${DEFAULT_GW_DEV}" = "xbond0" ]; then
/sbin/route del default eth1 2>/dev/null 1>/dev/null
/sbin/route del default eth0 2>/dev/null 1>/dev/null
/sbin/route del default wlan0 2>/dev/null 1>/dev/null
#/sbin/route add default gw `/sbin/getcfg "" GATEWAY -f /etc/dhcpc/dhcpcd-bond0.info` bond0
elif [ "x${DEFAULT_GW_DEV}" = "xwlan0" ]; then
/sbin/route del default eth1 2>/dev/null 1>/dev/null
/sbin/route del default eth0 2>/dev/null 1>/dev/null
/sbin/route del default bond0 2>/dev/null 1>/dev/null
if [ "x${ETH1_VLAN}" = "xTRUE" ]; then
/sbin/route del default eth1.${ETH1_VLAN_ID} 2>/dev/null 1>/dev/null
fi
if [ "x${ETH0_VLAN}" = "xTRUE" ]; then
/sbin/route del default eth0.${ETH0_VLAN_ID} 2>/dev/null 1>/dev/null
fi
if [ "x${BOND0_VLAN}" = "xTRUE" ]; then
/sbin/route del default bond0.${BOND0_VLAN_ID} 2>/dev/null 1>/dev/null
fi
/sbin/route add default gw `/sbin/getcfg "" GATEWAY -f /etc/dhcpc/dhcpcd-wlan0.info` wlan0
fi
fi
fi
/etc/init.d/ads_register_dns.sh &
/usr/bin/killall -HUP upnpcd
[ -f /var/run/nat_pmp.bin ] && /bin/rm /var/run/nat_pmp.bin
[ -f /etc/init.d/yoics.sh ] && /etc/init.d/yoics.sh restart &
/etc/init.d/hostname.sh

267
ipv6.sh Executable file
View File

@@ -0,0 +1,267 @@
#!/bin/sh
# Copyright @ 2009 QNAP Systems Inc.
GETCFG="/sbin/getcfg"
SETCFG="/sbin/setcfg"
IPV6=`$GETCFG "Network" "IPV6" -u -d "FALSE"`
BOND_SUP=`$GETCFG "Network" "BONDING Support" -u -d "FALSE"`
RETVAL=0
BOND_NIC=`$GETCFG "Network" "BONDING NICs" -d "0"`
NIC_NUM=`$GETCFG "Network" "Interface Number" -d "2"`
ADV_BOND_SUPPORT=`$GETCFG "Network" "Advanced Bonding Support" -d "FALSE"`
GROUP_NUM=`$GETCFG "Network Group" "Group Count" -d $NIC_NUM`
set_ipv6_dns()
{
[ "$IPV6" = "TRUE" ] || exit 1
/bin/sed -i '/:/d' /etc/resolv.conf
local haveflg="0"
for i in 1 2
do
local ipv6_dns=`/sbin/getcfg "Network" "IPV6 Domain Name Server $i" -d "::"`
/bin/grep "$ipv6_dns" /etc/resolv.conf 2>/dev/null 1>/dev/null
if [ $? != 0 ]; then
if [ "$ipv6_dns" != "::" ]; then
/bin/echo "nameserver $ipv6_dns" >> /etc/resolv.conf
haveflg=1
fi
fi
done
if [ "x$haveflg" = "x1" ]; then
/bin/sed -i '/0.0.0.0/d' /etc/resolv.conf
fi
}
init_dhcpv6()
{
/sbin/lsmod | /bin/grep -sq ipv6
if [ $? -ne 0 ]; then
[ ! -f /lib/modules/others/ipv6.ko ] || /sbin/insmod /lib/modules/others/ipv6.ko
/bin/sleep 1
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
[ ! -f /proc/sys/net/ipv6/conf/eth$i/accept_ra ] || /bin/echo "0" > /proc/sys/net/ipv6/conf/eth$i/accept_ra
done
[ ! -f /proc/sys/net/ipv6/conf/all/accept_ra ] || /bin/echo 0 > /proc/sys/net/ipv6/conf/all/accept_ra
[ ! -f /proc/sys/net/ipv6/conf/default/accept_ra ] || /bin/echo 0 > /proc/sys/net/ipv6/conf/default/accept_ra
fi
/bin/echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6
[ -d /etc/config/dhcpv6 ] || /bin/mkdir -p /etc/config/dhcpv6
[ -d /var/lib/dhcpv6 ] || /bin/mkdir -p /var/lib/dhcpv6
[ -d /var/run/dhcpv6 ] || /bin/mkdir -p /var/run/dhcpv6
[ -d /var/db ] || /bin/mkdir /var/db
}
enable_autoconf()
{
#default is enabled
if [ `$GETCFG "${1}" "Enable Autoconf" -u -d "TRUE"` = "TRUE" ]; then
[ -f /proc/sys/net/ipv6/conf/${1}/autoconf ] && /bin/echo 1 > /proc/sys/net/ipv6/conf/${1}/autoconf
[ -f /proc/sys/net/ipv6/conf/${1}/accept_ra ] && /bin/echo 1 > /proc/sys/net/ipv6/conf/${1}/accept_ra
else
[ -f /proc/sys/net/ipv6/conf/${1}/autoconf ] && /bin/echo 0 > /proc/sys/net/ipv6/conf/${1}/autoconf
[ -f /proc/sys/net/ipv6/conf/${1}/accept_ra ] && /bin/echo 0 > /proc/sys/net/ipv6/conf/${1}/accept_ra
fi
}
set_static_ipv6()
{
#default is enabled
if [ `$GETCFG "${1}" "Enable Autoconf" -u -d "TRUE"` = "FALSE" ]; then
IPV6ADDR=`$GETCFG "${1}" "IPV6 Address" -d "2001:0:1:2::5000/64"`
/sbin/ifconfig "${1}" inet6 add "$IPV6ADDR"
GATEWAY=`$GETCFG "${1}" "IPV6 Gateway" -d "::/0"`
[ "${GATEWAY%%/*}" = "::" ] || /sbin/route -A inet6 add "2000::/3" gw "${GATEWAY%%/*}" dev "${1}"
fi
}
start()
{
[ "$IPV6" = "TRUE" ] || exit 1
[ -f "/lib/modules/others/ipv6.ko" ] || exit 1
init_dhcpv6
if [ "x$ADV_BOND_SUPPORT" = "xTRUE" ]; then
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
local net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
enable_autoconf ${net_interface}
[ `$GETCFG "${net_interface}" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_${net_interface}.pid ${net_interface}
set_static_ipv6 ${net_interface}
fi
done
else
if [ "$NIC_NUM" = "4" ]; then
if [ "$BOND_SUP" = "TRUE" ]; then
if [ "$BOND_NIC" = "0" ]; then
enable_autoconf bond0
if [ `$GETCFG "bond0" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ]; then
/sbin/dhcp6c bond0
fi
set_static_ipv6 bond0
enable_autoconf eth2
enable_autoconf eth3
[ `$GETCFG "eth2" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_eth2.pid eth2
[ `$GETCFG "eth3" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_eth3.pid eth3
set_static_ipv6 eth2
set_static_ipv6 eth3
elif [ "$BOND_NIC" = "1" ]; then
enable_autoconf bond1
if [ `$GETCFG "bond1" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ]; then
/sbin/dhcp6c bond1
fi
set_static_ipv6 bond1
enable_autoconf eth0
enable_autoconf eth1
[ `$GETCFG "eth0" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_eth0.pid eth0
[ `$GETCFG "eth1" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_eth1.pid eth1
set_static_ipv6 eth0
set_static_ipv6 eth1
elif [ "$BOND_NIC" = "2" ]; then
enable_autoconf bond0
if [ `$GETCFG "bond0" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ]; then
/sbin/dhcp6c bond0
fi
set_static_ipv6 bond0
enable_autoconf bond1
if [ `$GETCFG "bond1" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ]; then
/sbin/dhcp6c bond1
fi
set_static_ipv6 bond1
elif [ "$BOND_NIC" = "3" ]; then
enable_autoconf bond0
if [ `$GETCFG "bond0" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ]; then
/sbin/dhcp6c bond0
fi
set_static_ipv6 bond0
fi
else
enable_autoconf eth0
enable_autoconf eth1
enable_autoconf eth2
enable_autoconf eth3
[ `$GETCFG "eth0" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_eth0.pid eth0
[ `$GETCFG "eth1" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_eth1.pid eth1
[ `$GETCFG "eth2" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_eth2.pid eth2
[ `$GETCFG "eth3" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_eth3.pid eth3
set_static_ipv6 eth0
set_static_ipv6 eth1
set_static_ipv6 eth2
set_static_ipv6 eth3
fi
else
if [ "$BOND_SUP" = "TRUE" ]; then
enable_autoconf bond0
if [ `$GETCFG "bond0" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ]; then
/sbin/dhcp6c bond0
fi
set_static_ipv6 bond0
else
enable_autoconf eth0
enable_autoconf eth1
[ `$GETCFG "eth0" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_eth0.pid eth0
[ `$GETCFG "eth1" "Use DHCPV6" -u -d "FALSE"` = "TRUE" ] && /sbin/dhcp6c -p /var/run/dhcpv6/dhcp6c_eth1.pid eth1
set_static_ipv6 eth0
set_static_ipv6 eth1
fi
fi
fi
set_ipv6_dns
/etc/init.d/radvd.sh start
[ -d /sys/kernel/config/target/iscsi ] && /sbin/iscsi_util --ip_change
}
stop()
{
/etc/init.d/radvd.sh stop
if [ "x$ADV_BOND_SUPPORT" = "xTRUE" ]; then
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
local net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
enable_autoconf ${net_interface}
fi
done
else
if [ "$NIC_NUM" = "4" ]; then
if [ "$BOND_SUP" = "TRUE" ]; then
if [ "$BOND_NIC" = "0" ]; then
enable_autoconf bond0
enable_autoconf eth2
enable_autoconf eth3
elif [ "$BOND_NIC" = "1" ]; then
enable_autoconf bond1
enable_autoconf eth0
enable_autoconf eth1
elif [ "$BOND_NIC" = "2" ]; then
enable_autoconf bond0
enable_autoconf bond1
elif [ "$BOND_NIC" = "3" ]; then
enable_autoconf bond0
fi
else
enable_autoconf eth0
enable_autoconf eth1
enable_autoconf eth2
enable_autoconf eth3
fi
else
if [ "$BOND_SUP" = "TRUE" ]; then
enable_autoconf bond0
else
enable_autoconf eth0
enable_autoconf eth1
fi
fi
fi
pid=`/bin/pidof dhcp6c`
if [ ! -z "$pid" ]; then
/bin/kill $pid
/bin/sleep 2
fi
pid=`/bin/pidof dhcp6c`
[ ! -z "$pid" ] && /bin/kill -9 $pid
#/bin/echo "To disable IPv6 needs to restart the system."
}
restart()
{
stop
/bin/sleep 1
start
/bin/sleep 1
}
case "$1" in
start)
stop
/bin/sleep 1
start
;;
stop)
stop
;;
restart)
restart
;;
setdns)
set_ipv6_dns
;;
init)
[ "$IPV6" = "TRUE" ] || exit 1
[ -f "/lib/modules/others/ipv6.ko" ] || exit 1
init_dhcpv6
;;
*)
/bin/echo $"Usage: $0 {start|stop|restart|setdns|init}"
exit 1
esac
exit 0

131
iscsiinit.sh Executable file
View File

@@ -0,0 +1,131 @@
#!/bin/sh
#
# chkconfig: 345 13 89
# description: Starts and stops the iSCSI initiator
#
# processname: /sbin/iscsid
# pidfile: /var/run/sbin/iscsid.pid
# config: /etc/config/iscsi/sbin/iscsid.conf
# Source function library.
PATH=/sbin:/bin:/usr/sbin:/usr/bin
INITNAME_FILE=/etc/iscsi/initiatorname.iscsi
CONF_FILE=/etc/config/iscsi/sbin/iscsid.conf
MAPPING_FILE=/etc/config/virtual_share_mapping
RETVAL=0
mkinitname()
{
[ -d /etc/iscsi ] || /bin/mkdir -p /etc/iscsi
MODEL=`/sbin/getcfg System Model`
SERVER_NAME=`/sbin/getcfg System "Server Name"`
project_name=`/sbin/getcfg Project Name -f /var/default`
if [ "x$project_name" = "xAthens" ]; then
/bin/echo "InitiatorName=iqn.1987-05.com.cisco:${MODEL}.${SERVER_NAME}" > $INITNAME_FILE
else
if [ -f /etc/IS_G ]; then
/bin/echo "InitiatorName=iqn.2004-04.com.NAS:Initiator.${SERVER_NAME}" > $INITNAME_FILE
else
/bin/echo "InitiatorName=iqn.2004-04.com.qnap:${MODEL}.${SERVER_NAME}" > $INITNAME_FILE
fi
fi
}
start()
{
INSTALL_FLAG_FILE=/tmp/check_install.flag
# echo Test $INSTALL_FLAG_FILE >> /tmp/inst.log
if [ -f $INSTALL_FLAG_FILE ] ; then
# /bin/cat $INSTALL_FLAG_FILE >> /tmp/inst.log
INSTALLING=`/bin/cat $INSTALL_FLAG_FILE`
[ $INSTALLING = "1" ] && exit 0
fi
Q_CONF_FILE=/etc/config/iscsi-init.conf
/bin/echo $"Starting iSCSI initiator service: "
[ -f $Q_CONF_FILE ] || /bin/echo "#QNAP iSCSI initiator configure file" > $Q_CONF_FILE
[ -f $MAPPING_FILE ] || echo "[VirtualDisk1]" > $MAPPING_FILE
/sbin/insmod /lib/modules/misc/scsi_transport_iscsi.ko
/sbin/insmod /lib/modules/misc/libiscsi.ko
[ -f /lib/modules/misc/libiscsi_tcp.ko ] && /sbin/insmod /lib/modules/misc/libiscsi_tcp.ko
/sbin/insmod /lib/modules/misc/iscsi_tcp.ko
mkinitname
/sbin/iscsid --config=${CONF_FILE} --initiatorname=${INITNAME_FILE}
RETVAL=$?
[ $RETVAL -eq 0 ] || return
/bin/touch /var/lock/subsys/open-iscsi
#VDD enhancement version uses vdd_control daemon to replace vdd_control+vdd_scan_target
[ -f /sbin/vdd_scan_target ] || /sbin/daemon_mgr vdd_control start "/sbin/vdd_control -d >/dev/null 2>&1 &"
[ -f /etc/config/virtual_share_mapping ] || echo "" >> /etc/config/virtual_share_mapping
if [ -f /sbin/storage_boot_init ]; then
/sbin/storage_boot_init 8
fi
# /bin/echo -n $"Setting up iSCSI targets: "
# /sbin/iscsiadm -m node --loginall=automatic
# success
# /bin/echo
}
stop()
{
[ -f /sbin/umount_all_vdd ] && /sbin/umount_all_vdd
/bin/echo -n $"Stopping iSCSI initiator service: "
/bin/sync
/sbin/iscsiadm -m node --logoutall=all
/usr/bin/killall iscsid
/bin/rm -f /var/run/sbin/iscsid.pid
[ $RETVAL -eq 0 ] && /bin/rm -f /var/lock/subsys/open-iscsi
status=0
/sbin/rmmod /lib/modules/misc/iscsi_tcp.ko
if [ "$?" -ne "0" -a "$?" -ne "1" ]; then
status=1
fi
/sbin/rmmod /lib/modules/misc/libiscsi_tcp.ko
if [ "$?" -ne "0" -a "$?" -ne "1" ]; then
status=1
fi
/sbin/rmmod /lib/modules/misc/libiscsi.ko
if [ "$?" -ne "0" -a "$?" -ne "1" ]; then
status=1
fi
/sbin/rmmod /lib/modules/misc/scsi_transport_iscsi.ko
if [ "$?" -ne "0" -a "$?" -ne "1" ]; then
status=1
fi
}
restart()
{
stop
/bin/sleep 1
start
}
ISCSI_INIT_KO=/lib/modules/misc/iscsi_tcp.ko
[ -f $ISCSI_INIT_KO ] || exit 0
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
/bin/echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $RETVAL

92
iscsitrgt.sh Executable file
View File

@@ -0,0 +1,92 @@
#!/bin/sh
FBDISK_SH=/etc/init.d/fbdisk.sh
ISCSI_TARGET_KO=/lib/modules/misc/target_core_mod.ko
ISCSI_UTILITY=/sbin/iscsi_util
ISCSI_LOG_DAEMON=/sbin/iscsi_logd
ISNS_CLIENT_DAEMON=/sbin/isns_cd
ISCSI_CONFIG=/etc/config/iscsi_trgt.conf
MIN_FSIZE=200 #minimum config file size required
start_target()
{
# check if fbdisk loaded
if [ -z "`/sbin/lsmod | /bin/grep fbdisk | /bin/awk {'print $1'}`" ];
then
$FBDISK_SH start;
fi
[ -d "/var/target/pr" ] || mkdir -p /var/target/pr
[ -f $ISCSI_CONFIG ] || $ISCSI_UTILITY --new
if [ -x /usr/bin/du ] && [ -f $ISCSI_CONFIG ]; then
conf_size=`/usr/bin/du -b $ISCSI_CONFIG | /bin/awk '{print $1}'`
if [ -z "$conf_size" ] || [ "$conf_size" -lt $MIN_FSIZE ]; then
/bin/cp $ISCSI_CONFIG ${ISCSI_CONFIG}.replaced
last_conf_size=0
[ -f ${ISCSI_CONFIG}.last ] && last_conf_size=`/usr/bin/du -b ${ISCSI_CONFIG}.last | /bin/awk '{print $1}'`
if [ ! -z "$last_conf_size" ] && [ "$last_conf_size" -ge $MIN_FSIZE ]; then
/bin/cp ${ISCSI_CONFIG}.last $ISCSI_CONFIG
else
[ -x /etc/init.d/backup_conf.sh ] && /etc/init.d/backup_conf.sh restore iscsi_trgt.conf
fi
fi
fi
ENABLE_ISCSI=`/sbin/getcfg iSCSIPortal bServiceEnable -f $ISCSI_CONFIG -u -d 1`
if [ "$ENABLE_ISCSI" != "TRUE" ];
then
$ISCSI_UTILITY --config
exit 0;
fi
ENABLE_ISNS=`/sbin/getcfg iSCSIPortal bISNSEnable -f $ISCSI_CONFIG -u -d 1`
if [ "$ENABLE_ISNS" == "TRUE" ];
then
ISNS_IP=`/sbin/getcfg iSCSIPortal ISNSIP -f $ISCSI_CONFIG -u -d 127.0.0.1`
$ISNS_CLIENT_DAEMON --address $ISNS_IP
fi
$ISCSI_UTILITY --load --config
# log daemon should be launched after the target service
$ISCSI_LOG_DAEMON
}
stop_target()
{
if [[ $0 == *K* ]]
then
/usr/bin/killall iscsi_lun_setting.cgi &> /dev/null
fi
/usr/bin/killall isns_cd &> /dev/null
/usr/bin/killall iscsi_logd &> /dev/null
$ISCSI_UTILITY --unload
}
unload_fbdisk()
{
# check if fbdisk loaded
if [ -n "`/sbin/lsmod | /bin/grep fbdisk | /bin/awk {'print $1'}`" ];
then
$FBDISK_SH stop;
fi
}
# Check that iscsi_trgt.ko exists.
[ -f $ISCSI_TARGET_KO ] || exit 0
# See how we were called.
case "$1" in
start)
start_target;
;;
stop)
stop_target;
unload_fbdisk;
;;
restart)
stop_target;
sleep 1
start_target;
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

77
iso_mount.sh Executable file
View File

@@ -0,0 +1,77 @@
#!/bin/sh
MOUNT_DVD="/bin/mount -t iso9660 -o ro,loop"
MOUNT_BD="/bin/mount -t udf -o ro,loop"
UMOUNT="/bin/umount"
LOSETUP="/usr/local/sbin/losetup"
ISO_CONF="/etc/config/iso_share_mapping"
MAX_NUM=256
mount_iso()
{
for (( i=1; i<=$MAX_NUM; i=i+1 ))
do
/bin/grep "\[ISOShare$i\]" /etc/config/iso_share_mapping 1>/dev/null 2>/dev/null
[ $? = 0 ] || continue
#echo "Mount ISOShare$i"
auto_mount=`/sbin/getcfg ISOShare$i Auto_mount -d TRUE -f $ISO_CONF`
if [ "$auto_mount" == "TRUE" ]; then
source=`/sbin/getcfg ISOShare$i Source -d none -f $ISO_CONF`
if [ "$source" != "none" ]; then
dest=`/sbin/getcfg ISOShare$i Dest -d none -f $ISO_CONF`
type=`/sbin/getcfg ISOShare$i Type -d none -f $ISO_CONF`
if [ "$type" == "iso9660" ] && [ "$dest" != "none" ]; then
/bin/df | /bin/grep "$dest" 1>/dev/null 2>/dev/null
if [ $? != 0 ]; then
$MOUNT_DVD "$source" "$dest" 2>/dev/null
fi
# if [ $? != 0 ]; then
# /sbin/iso_check -d "$dest" 1>/dev/null 2>/dev/null
# fi
elif [ "$type" == "udf" ] && [ "$dest" != "none" ]; then
/bin/df | /bin/grep "$dest" 1>/dev/null 2>/dev/null
if [ $? != 0 ]; then
$MOUNT_BD "$source" "$dest" 2>/dev/null
fi
# if [ $? != 0 ]; then
# /sbin/iso_check -d "$dest" 1>/dev/null 2>/dev/null
# fi
fi
fi
fi
done
}
unmount_iso()
{
for (( i=1; i<=$MAX_NUM; i=i+1 ))
do
/bin/grep "\[ISOShare$i\]" /etc/config/iso_share_mapping 1>/dev/null 2>/dev/null
[ $? = 0 ] || continue
#echo "Unmount ISOShare$i"
source=`/sbin/getcfg ISOShare$i Source -d none -f $ISO_CONF`
if [ "$source" != "none" ]; then
dest=`/sbin/getcfg ISOShare$i Dest -d none -f $ISO_CONF`
loop_dev=`/bin/cat /proc/mounts | /bin/grep loop | /bin/grep "${dest}" | /bin/awk '{print $1}'`
$UMOUNT "$dest" 2>/dev/null
$LOSETUP -d "$loop_dev" 2>/dev/null
fi
done
}
case "$1" in
start)
mount_iso
;;
stop)
/bin/grep "/dev/loop" /proc/mounts 1>/dev/null 2>&1
[ $? != 0 ] || unmount_iso
;;
restart)
$0 stop
$0 start
;;
*)
/bin/echo "Usage: /etc/init.d/iso_mount.sh {start|stop|restart}"
exit 1
esac

66
klogd.sh Executable file
View File

@@ -0,0 +1,66 @@
#!/bin/sh
_lock_file=/var/lock/subsys/klogd.sh
_klogd_path=/mnt/HDA_ROOT/.logs
_klogd_file=kmsg
dump()
{
[ -f ${_klogd_path}/${_klogd_file}.2 ] && /bin/cat ${_klogd_path}/${_klogd_file}.2
[ -f ${_klogd_path}/${_klogd_file}.1 ] && /bin/cat ${_klogd_path}/${_klogd_file}.1
[ -f ${_klogd_path}/${_klogd_file} ] && /bin/cat ${_klogd_path}/${_klogd_file}
}
start()
{
_max_size=1024000
if [ -f ${_lock_file} ]; then
/bin/echo "klogd.sh is already run"
exit 1
fi
/bin/touch ${_lock_file}
if [ -d ${_klogd_path} ]; then
/bin/cat ${_klogd_path}/${_klogd_file} >> ${_klogd_path}/${_klogd_file}.1
_tmp=`/usr/bin/du -b ${_klogd_path}/${_klogd_file}.1`
_size=`/bin/echo ${_tmp} | /bin/cut -d ' ' -f 1`
if [ ${_size} -gt ${_max_size} ]; then
/bin/mv ${_klogd_path}/${_klogd_file}.1 ${_klogd_path}/${_klogd_file}.2
fi
/bin/rm ${_klogd_path}/${_klogd_file}
else
/bin/mkdir -p ${_klogd_path}
fi
while [ 1 ]; do
/bin/dd if=/proc/kmsg of=${_klogd_path}/${_klogd_file} bs=1 count=${_max_size}
/bin/mv ${_klogd_path}/${_klogd_file} ${_klogd_path}/${_klogd_file}.2
done
}
stop()
{
/bin/rm -f ${_lock_file}
/bin/kill -TERM `pidof klogd.sh dd`
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
dump)
dump
;;
*)
echo $"Usage: $0 {start|stop|restart|dump}"
exit 1
esac
exit 0

64
ldap.sh Executable file
View File

@@ -0,0 +1,64 @@
#!/bin/sh
#
NSS_CONFIG=/etc/nsswitch.conf
# Check that smb.conf exists.
[ -f $NSS_CONFIG ] || exit 0
start() {
echo -n "Starting ldap services:"
if [ `/sbin/getcfg LDAP Enable -u -d FALSE` = FALSE ]; then
echo " disabled."
exit 0
fi
ldap_host=`/sbin/getcfg LDAP host -d ""`
lret=0
if [ "x$ldap_host" != "x" ]; then
if [ -f /sbin/dns_resolve ] && [ ! -f /tmp/.boot_done ]; then
/sbin/dns_resolve "$ldap_host" 1>/dev/null 2>&1
lret=$?
fi
if [ $lret = 0 ]; then
/bin/sed "/compat winbind/d" ${NSS_CONFIG} > ${NSS_CONFIG}.tmp
/bin/sed "21i\\passwd: compat winbind ldap" ${NSS_CONFIG}.tmp > ${NSS_CONFIG}.tmp1
/bin/sed "23i\\group: compat winbind ldap" ${NSS_CONFIG}.tmp1 > ${NSS_CONFIG}
/bin/rm -f ${NSS_CONFIG}.tmp ${NSS_CONFIG}.tmp1
else
if [ ! -f /tmp/.boot_done ]; then
/sbin/setcfg LDAP Enable FALSE
fi
fi
fi
echo " done."
}
stop() {
echo -n "Shutting down ldap services:"
/bin/sed "/compat winbind/d" ${NSS_CONFIG} > ${NSS_CONFIG}.tmp
/bin/sed "21i\\passwd: compat winbind" ${NSS_CONFIG}.tmp > ${NSS_CONFIG}.tmp1
/bin/sed "23i\\group: compat winbind" ${NSS_CONFIG}.tmp1 > ${NSS_CONFIG}
/bin/rm -f ${NSS_CONFIG}.tmp ${NSS_CONFIG}.tmp1
echo " done."
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?

49
ldap_backup_db.sh Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/sh
EXPORT_DB_PRFIX="LDAP_Backup"
TAR_CMD=/bin/tar
LDAP_BK_CONF_FILE="/var/openldap-data/.ldaps_conf"
EXPORT_DEST=
BACKUP_DB_FILE="DB_CONFIG __db.* *.bdb alock log.*"
BACKUP_DEST="`/sbin/getcfg "LDAP Server" "Backup destination" -d ""`"
APPEND_DATE_STR="`date --date="now" +%Y_%m_%d`"
PWD=`pwd`
LDAP_ENABLE="`/sbin/getcfg "LDAP Server" "Enable" -u -d FALSE`"
LDAP_FQDN="`/sbin/getcfg "LDAP Server" "fqdn" -d ""`"
LDAP_ROOTDN="`/sbin/getcfg "LDAP Server" "rootdn" -d ""`"
LDAP_BASDN="`/sbin/getcfg "LDAP Server" "base" -d ""`"
LDAP_ROOTPW="`/sbin/getcfg "LDAP Server" "rootpw" -d ""`"
set_ldap_bk_conf_file()
{
LDAP_ENABLE="`/sbin/getcfg "LDAP Server" "Enable" -u -d FALSE`"
LDAP_FQDN="`/sbin/getcfg "LDAP Server" "fqdn" -d ""`"
LDAP_ROOTDN="`/sbin/getcfg "LDAP Server" "rootdn" -d ""`"
LDAP_BASEDN="`/sbin/getcfg "LDAP Server" "base" -d ""`"
LDAP_ROOTPW="`/sbin/getcfg "LDAP Server" "rootpw" -d ""`"
/bin/touch ${LDAP_BK_CONF_FILE}
/sbin/setcfg "LDAP Server" "Enable" "${LDAP_ENABLE}" -f ${LDAP_BK_CONF_FILE}
/sbin/setcfg "LDAP Server" "fqdn" "${LDAP_FQDN}" -f ${LDAP_BK_CONF_FILE}
/sbin/setcfg "LDAP Server" "base" "${LDAP_BASEDN}" -f ${LDAP_BK_CONF_FILE}
/sbin/setcfg "LDAP Server" "rootdn" "${LDAP_ROOTDN}" -f ${LDAP_BK_CONF_FILE}
/sbin/setcfg "LDAP Server" "rootpw" "${LDAP_ROOTPW}" -f ${LDAP_BK_CONF_FILE}
}
if [ `/sbin/getcfg "LDAP Server" "Export DB" -u -d FALSE` = TRUE ]; then
set_ldap_bk_conf_file
if [ `/sbin/getcfg "LDAP Server" "Overwrite" -u -d FALSE` = TRUE ]; then
cd /var/openldap-data
echo "overwrite backup db file, Backup destination=>${BACKUP_DEST}"
$TAR_CMD -czvf ${EXPORT_DB_PRFIX}.exp .ldaps_conf $BACKUP_DB_FILE
/bin/mv ${EXPORT_DB_PRFIX}.exp ${BACKUP_DEST}
cd $PWD
elif [ `/sbin/getcfg "LDAP Server" "Create new file" -u -d FALSE` = TRUE ]; then
cd /var/openldap-data
echo "create new backup db file, Backup destination=>${BACKUP_DEST}"
$TAR_CMD -czvf ${EXPORT_DB_PRFIX}_${APPEND_DATE_STR}.exp $BACKUP_DB_FILE .ldaps_conf
/bin/mv ${EXPORT_DB_PRFIX}_${APPEND_DATE_STR}.exp ${BACKUP_DEST}
cd $PWD
fi
/bin/rm ${LDAP_BK_CONF_FILE}
fi

122
ldap_server.sh Executable file
View File

@@ -0,0 +1,122 @@
#!/bin/sh
RETVAL=0
STUNNEL_KEY=/etc/config/stunnel/backup.key
STUNNEL_CERT=/etc/config/stunnel/backup.cert
STUNNEL_KEY_DEFAULT=/etc/default_config/stunnel/backup.key
STUNNEL_CERT_DEFAULT=/etc/default_config/stunnel/backup.cert
QPKG_LDAP_DIR=/mnt/ext/opt/ldap_server
LDAP_DB_DIR=""
. /etc/init.d/functions
prepare_cert_key()
{
if [ ! -f $STUNNEL_CERT ] && [ -f $STUNNEL_CERT_DEFAULT ]; then
/bin/cp $STUNNEL_CERT_DEFAULT $STUNNEL_CERT 2>>/dev/null
fi
if [ ! -f $STUNNEL_KEY ] && [ -f $STUNNEL_KEY_DEFAULT ]; then
/bin/cp $STUNNEL_KEY_DEFAULT $STUNNEL_KEY 2>>/dev/null
fi
}
find_db_base(){
FindDefVol
_ret=$?
if [ $_ret != 0 ]; then
exit 1
fi
LDAP_DB_DIR="${DEF_VOLMP}/.ldapdb"
}
init_ldap_conf()
{
if [ -f ${QPKG_LDAP_DIR}/etc/openldap/slapd.conf ];then
[ -d /etc/config/openldap ] || /bin/mkdir -p /etc/config/openldap
[ -f /etc/config/openldap/slapd.conf ] || /bin/cp ${QPKG_LDAP_DIR}/etc/openldap/slapd.conf /etc/config/openldap
/bin/cp ${QPKG_LDAP_DIR}/etc/openldap/slapdacl.conf /etc/config/openldap
[ -L /etc/openldap/slapd.conf ] || /bin/ln -sf /etc/config/openldap/slapd.conf /etc/openldap/slapd.conf
[ -L /etc/openldap/slapdacl.conf ] || /bin/ln -sf /etc/config/openldap/slapdacl.conf /etc/openldap/slapdacl.conf
fi
}
init_ntp_conf()
{
if [ -f ${QPKG_LDAP_DIR}/etc/ntp/ntp.conf ];then
[ -d /etc/config/ntp ] || /bin/mkdir -p /etc/config/ntp
[ -f /etc/config/ntp/ntp.conf ] || /bin/cp ${QPKG_LDAP_DIR}/etc/ntp/ntp.conf /etc/config/ntp
[ -L /etc/ntp.conf ] || /bin/ln -sf /etc/config/ntp/ntp.conf /etc/ntp.conf
fi
}
init_db_dir()
{
[ -d ${LDAP_DB_DIR} ] || /bin/mkdir -p $LDAP_DB_DIR
cp /mnt/ext/opt/ldap_server/var/openldap-data/DB_CONFIG $LDAP_DB_DIR
}
case "$1" in
start)
echo "Starting LDAP server service: "
find_db_base
[ -f ${LDAP_DB_DIR}/DB_CONFIG ] || init_db_dir
if [ -L /var/openldap-data ]; then
if [ ! -e /var/openldap-data ]; then
/bin/rm -f /var/openldap-data
/bin/ln -sf ${LDAP_DB_DIR} /var/openldap-data
fi
else
/bin/ln -sf ${LDAP_DB_DIR} /var/openldap-data
fi
prepare_cert_key
if [ `/sbin/getcfg "LDAP Server" "Enable" -u -d FALSE` = TRUE ]; then
if [ -f /usr/sbin/slapd ]; then
/sbin/daemon_mgr slapd start '/usr/sbin/slapd -4 -h "ldap:/// ldaps:///"'
fi
RETVAL=$?
echo "slapd."
echo "Starting NTP server service: "
if [ -f /sbin/ntpd ]; then
if [ ! -f /etc/ntp.drift ]; then
echo "0.000" > /etc/ntp.drift
fi
/sbin/daemon_mgr ntpd start "/sbin/ntpd"
fi
echo "ntpd."
else
echo "slapd is disabled."
fi
;;
stop)
echo "Shutting down LDAP service: "
/sbin/daemon_mgr slapd stop "/usr/sbin/slapd"
/bin/kill -INT `pidof slapd` 1>/dev/null 2>/dev/null
echo "slapd."
echo "Shutting down NTP service: "
/sbin/daemon_mgr ntpd stop "/sbin/ntpd"
/bin/kill -INT `pidof ntpd` 1>/dev/null 2>/dev/null
echo "ntpd."
;;
init)
echo "Initailize ldap server config file"
init_ldap_conf
echo "Initailize ntp config file"
init_ntp_conf
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $RETVAL

20
log_rotation.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/sh
if [ "$1" = "" ]; then
/bin/echo "no file"
elif [ "$1" = "/tmp/rsyslog/root_file" ]; then
/bin/rm -f "$1"
else
new_file=$1"_"`/bin/date '+20%y_%m_%d'`
i=0
test_file=$new_file
while [ -f $test_file ]
do
i=$(($i+1))
test_file=$new_file"."$i
done
/bin/mv -f "$1" $test_file
fi
exit 0

136
login.sh Executable file
View File

@@ -0,0 +1,136 @@
#!/bin/sh
SSH=/usr/sbin/sshd
TELNET=/bin/utelnetd
SSHD_CONF=/etc/ssh/sshd_config
/sbin/test -f $SSHD || exit 0
/sbin/test -f $TELNET || exit 0
[ -f "/bin/cmp" ] || ln -sf /bin/busybox /bin/cmp
SSH_PORT=`/sbin/getcfg LOGIN "SSH Port" -d 22`
DEAFULT_TELNET_PORT=`/sbin/getcfg -f /var/default LOGIN "TELNET Port" -d 13131`
TELNET_PORT=`/sbin/getcfg LOGIN "TELNET Port" -d $DEAFULT_TELNET_PORT`
SSHKEY_CONFIG_DIR=/etc/config/ssh
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf`
generte_ssh_key()
{
[ -d $SSHKEY_CONFIG_DIR ] || /bin/mkdir $SSHKEY_CONFIG_DIR
if [ -f /usr/bin/ssh-keygen ]; then
if [ ! -f ${SSHKEY_CONFIG_DIR}/ssh_host_rsa_key ] || [ ! -f ${SSHKEY_CONFIG_DIR}/ssh_host_rsa_key.pub ]; then
/bin/rm -f ${SSHKEY_CONFIG_DIR}/ssh_host_rsa_key*
/usr/bin/ssh-keygen -t rsa -f ${SSHKEY_CONFIG_DIR}/ssh_host_rsa_key -N ""
/bin/touch /etc/config/ssh_key.fla
/bin/sync
fi
if [ ! -f ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key ] || [ ! -f ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key.pub ]; then
/bin/rm -f ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key*
/usr/bin/ssh-keygen -t dsa -f ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key -N ""
/bin/touch /etc/config/ssh_key.fla
/bin/sync
fi
/bin/cmp /etc/ssh/ssh_host_rsa_key ${SSHKEY_CONFIG_DIR}/ssh_host_rsa_key 1>>/dev/null 2>>/dev/null
retrsa1=$?
/bin/cmp /etc/ssh/ssh_host_dsa_key.pub ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key.pub 1>>/dev/null 2>>/dev/null
retrsa2=$?
/bin/cmp /etc/ssh/ssh_host_dsa_key ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key 1>>/dev/null 2>>/dev/null
retdsa1=$?
/bin/cmp /etc/ssh/ssh_host_dsa_key.pub ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key.pub 1>>/dev/null 2>>/dev/null
retdsa2=$?
[ $retrsa1 -eq 0 ] || /bin/cp -a ${SSHKEY_CONFIG_DIR}/ssh_host_rsa_key /etc/ssh/
[ $retrsa2 -eq 0 ] || /bin/cp -a ${SSHKEY_CONFIG_DIR}/ssh_host_rsa_key.pub /etc/ssh/
[ $retdsa1 -eq 0 ] || /bin/cp -a ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key /etc/ssh/
[ $retdsa2 -eq 0 ] || /bin/cp -a ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key.pub /etc/ssh/
if [ -d /etc/config/ssh ]; then
/bin/rm -rf /root/.ssh 1>>/dev/null 2>>/dev/null
/bin/ln -sf /etc/config/ssh /root/.ssh
[ -f /etc/config/ssh/id_rsa ] || /bin/ln -sf ssh_host_rsa_key /etc/config/ssh/id_rsa
[ -f /etc/config/ssh/id_rsa.pub ] || /bin/ln -sf ssh_host_rsa_key.pub /etc/config/ssh/id_rsa.pub
fi
if [ "x${BOOT_CONF}" = "xTS-NASX86" ] && [ ! -f /etc/config/ssh_key.fla ]; then
/bin/rm -f ${SSHKEY_CONFIG_DIR}/ssh_host_rsa_key* 2>>/dev/null
/bin/rm -f ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key* 2>>/dev/null
/usr/bin/ssh-keygen -t rsa -f ${SSHKEY_CONFIG_DIR}/ssh_host_rsa_key -N ""
/usr/bin/ssh-keygen -t dsa -f ${SSHKEY_CONFIG_DIR}/ssh_host_dsa_key -N ""
/bin/touch /etc/config/ssh_key.fla
fi
fi
}
update_sshd_config()
{
ENABLED_SFTP=`/sbin/getcfg LOGIN "SFTP Enable" -u -d TRUE`
if [ "x${ENABLED_SFTP}" = "xTRUE" ]; then
/bin/grep "/usr/libexec/sftp-server" ${SSHD_CONF} > /dev/null
if [ $? != 0 ]; then
/bin/sed '107i\Subsystem sftp \/usr\/libexec\/sftp-server' ${SSHD_CONF} > ${SSHD_CONF}.tmp
/bin/cp -f ${SSHD_CONF}.tmp ${SSHD_CONF}
fi
else
/bin/grep "/usr/libexec/sftp-server" ${SSHD_CONF} > /dev/null
if [ $? = 0 ]; then
/bin/sed "/\/usr\/libexec\/sftp-server/d" ${SSHD_CONF} > ${SSHD_CONF}.tmp
/bin/cp -f ${SSHD_CONF}.tmp ${SSHD_CONF}
fi
fi
}
case "$1" in
start)
if [ `/sbin/getcfg LOGIN "SSH Enable" -u -d TRUE` = FALSE ]; then
echo "Starting sshd services: disabled."
else
echo -n "Starting sshd services: "
generte_ssh_key
update_sshd_config
/sbin/daemon_mgr sshd start "$SSH -f ${SSHD_CONF} -p $SSH_PORT"
echo "sshd."
touch /var/lock/subsys/sshd
fi
if [ `/sbin/getcfg LOGIN "TELNET Enable" -u -d FALSE` = FALSE ]; then
echo "Starting telnet services: disabled."
else
echo -n "Starting telnet services: "
/sbin/daemon_mgr utelnetd start "$TELNET -p $TELNET_PORT &"
echo "utelnetd."
touch /var/lock/subsys/utelnetd
fi
if [ `/sbin/getcfg "TFTP Server" "Enable" -u -d FALSE` = FALSE ]; then
echo "Starting opentftpd services: disabled."
else
/etc/init.d/opentftp.sh start
fi
;;
stop)
echo -n "Shutting down sshd services:"
/sbin/daemon_mgr sshd stop $SSH
/usr/bin/killall sshd
rm -f /var/lock/subsys/sshd
echo "sshd"
echo -n "Shutting down telnet services:"
/sbin/daemon_mgr utelnetd stop $TELNET
rm -f /var/lock/subsys/utelnetd
echo "utelnetd"
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/login.sh {start|stop|restart}"
exit 1
esac
exit 0

85
logo.sh Executable file
View File

@@ -0,0 +1,85 @@
#!/bin/sh
#
# description: logo.sh provide the logo files on the appropriate directory of NAS machine.
# 2002/02/01 Johnson Hsu created
# 2002/02/23 Kent re-format
# 2002/03/01 Johnson Hsu modify (pic5 - system logo)
#
SYSTEM_DEVICE=`/sbin/getcfg System "System Device" -d /dev/hda`
HTTPD_IMG_PATH=/home/httpd/v3_menu/images
DEFAULT_IMG=/etc/config/logo/default_logo_img.gif
SHOW_IMG=$HTTPD_IMG_PATH/show_logo_img.gif
copy_file()
{
if [ ! -f $1 ]; then
/bin/cp -f $DEFAULT_IMG $1 2>/dev/null 1>/dev/null
/bin/cp -f $1 $HTTPD_IMG_PATH 2>/dev/null 1>/dev/null
else
/bin/cp -f $1 $HTTPD_IMG_PATH 2>/dev/null 1>/dev/null
fi
}
# check if any file exist???
if [ ! -f $DEFAULT_IMG ]; then
/bin/cp -f $HTTPD_IMG_PATH/spacer.gif $DEFAULT_IMG
fi
pic1=`/sbin/getcfg LOGO "PIC1 LOGO Image Path" -d /etc/config/logo/pic1_logo_img.gif`
copy_file $pic1
pic2=`/sbin/getcfg LOGO "PIC2 LOGO Image Path" -d /etc/config/logo/pic2_logo_img.gif`
copy_file $pic2
pic3=`/sbin/getcfg LOGO "PIC3 LOGO Image Path" -d /etc/config/logo/pic3_logo_img.gif`
copy_file $pic3
pic4=`/sbin/getcfg LOGO "PIC4 LOGO Image Path" -d /etc/config/logo/pic4_logo_img.gif`
copy_file $pic4
upload=`/sbin/getcfg LOGO "UPLOAD LOGO Image Path" -d /etc/config/logo/upload_logo_img.gif`
copy_file $upload
index=`/sbin/getcfg "LOGO" "Show PIC Index" -u -d "0"`
case $index in
0)
# disable logo function, use default image
pic=$DEFAULT_IMG
;;
1)
pic=`/sbin/getcfg "LOGO" "PIC1 LOGO Image Path" -d /etc/config/logo/pic1_logo_img.gif`
;;
2)
pic=`/sbin/getcfg "LOGO" "PIC2 LOGO Image Path" -d /etc/config/logo/pic2_logo_img.gif`
;;
3)
pic=`/sbin/getcfg "LOGO" "PIC3 LOGO Image Path" -d /etc/config/logo/pic3_logo_img.gif`
;;
4)
pic=`/sbin/getcfg "LOGO" "PIC4 LOGO Image Path" -d /etc/config/logo/pic4_logo_img.gif`
;;
5)
pic=`/sbin/getcfg "LOGO" "Upload LOGO Image Path" -d /etc/config/logo/upload_logo_img.gif`
;;
*)
echo "LOGO session error !!"
exit 1
esac
echo use PIC$index as default image
if [ -f $pic ]; then
/bin/cp -f $pic $SHOW_IMG 2>/dev/null 1>/dev/null
fi
pic5=`/sbin/getcfg LOGO "PIC5 LOGO Image Path" -d /etc/config/logo/pic5_logo_img.gif`
if [ -f $SHOW_IMG ]; then
/bin/cp -f $SHOW_IMG $pic5 2>/dev/null 1>/dev/null
/bin/cp -f $pic5 $HTTPD_IMG_PATH 2>/dev/null 1>/dev/null
fi
exit 0

52
lunportman.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/sh
start()
{
if [ -z "`/sbin/lsmod | /bin/grep fbdisk | /bin/awk {'print $1'}`" ];then
/etc/init.d/fbdisk.sh start
fi
if [ -f /usr/bin/lunportman ]; then
echo "Starting LUN Porter manitor: lunportman..."
[ -d /etc/config/lunporter ] || /usr/bin/install -d /etc/config/lunporter
[ -h /etc/lunporter ] || /bin/ln -sf config/lunporter /etc/lunporter
[ -f /etc/config/lunporter/lunporter.conf ] || /bin/cp -p /etc/default_config/lunporter/lunporter.conf /etc/config/lunporter/lunporter.conf
/usr/bin/lunportman
fi
}
stop()
{
echo "Shutting down LUN Porter manitor: lunportman..."
/usr/bin/killall -q lunportman
CNT=0
while [ $CNT -lt 10 ]; do
sleep 3
/bin/pidof lunporter 1>>/dev/null 2>>/dev/null
[ $? = 0 ] || break
CNT=`expr $CNT + 1`
done
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
*)
echo "Usage: /etc/init.d/lunportman.sh {start|stop|restart}"
exit 1
esac
exit 0

21
mkchangepwd.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/sh
if [ "x$1" = "x" -o "x$2" = "x" ]; then
echo $0 [username] [password]
fi
OUT_FILE=/etc/config/runone/changepwd.sh
USER=$1
PWD=$2
if [ ! -d /etc/config/runone ]; then
echo "mkdir /etc/config/runone"
/bin/mkdir /etc/config/runone
fi
echo "#!/bin/sh" > $OUT_FILE
echo "" >> $OUT_FILE
echo "/usr/bin/passwd -p $PWD $USER" >> $OUT_FILE
echo "/usr/local/samba/bin/smbpasswd $USER $PWD" >> $OUT_FILE
/bin/chmod 755 $OUT_FILE

255
mountall Executable file
View File

@@ -0,0 +1,255 @@
#!/bin/sh
. /etc/init.d/functions
PATH=/bin:/sbin
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
HD_DEVICE="/dev/md13"
else
HD_DEVICE="/dev/sda4"
fi
EXT_MD_NAME="md13"
FLASH_RFS1="/dev/sdx2"
FLASH_RFS2="/dev/sdx3"
FLASH_TMP="/flashfs_tmp"
MNT_POINT="/mnt/ext"
CONFIG_Dev="/dev/md9"
MNT_HD_ROOT_TMP="/hd_root_tmp"
UPDATEPKG_DIR="${MNT_HD_ROOT_TMP}/update_pkg"
ROOTFS2="$FLASH_TMP/boot/rootfs2.bz"
ROOTFS_EXT="$FLASH_TMP/boot/rootfs_ext.tgz"
FLASH_RFS2_16M="/dev/mtdblock3"
ROOTFS2_16M="$FLASH_TMP/rootfs2.bz"
check_if_hd_ready_arg()
{
local ret=0
dd if=$1 of=/tmp/mycheck skip=384M bs=1 count=4
if [ $? = 0 ] && [ `cat /tmp/mycheck` = "QNAP" ]; then
ret=1
fi
rm -f /tmp/mycheck
return $ret
}
check_sum()
{
if [ ! -f $1 ] || [ ! -f $2 ];then
echo "${1} or ${2} not found."
return 1
fi
local file_cksum=`/sbin/cksum $1`
local file_crc=`echo $file_cksum | cut -d ' ' -f 1`
local file_size=`echo $file_cksum | cut -d ' ' -f 2`
local cksum_cksum=`cat $2`
local cksum_crc=`echo $cksum_cksum | cut -d ' ' -f 1`
local cksum_size=`echo $cksum_cksum | cut -d ' ' -f 2`
if [ $file_crc = $cksum_crc ] && [ $file_size = $cksum_size ]; then
return 0
fi
return 1
}
extract_rootfs2()
{
[ -d $FLASH_TMP ] || /bin/mkdir $FLASH_TMP
/bin/mount $1 $FLASH_TMP -o ro
if [ $? != 0 ]; then
/bin/echo "mountall: mount $1 failed."
/bin/umount $1 1>/dev/null 2>&1
return 1
else
check_sum "${ROOTFS2}" "${ROOTFS2}.cksum"
if [ $? = 0 ]; then
/bin/tar xjf ${ROOTFS2} -C / 2>/dev/null
else
/bin/umount $1 1>/dev/null 2>&1
/bin/sync
return 1
fi
fi
return 0
}
#
# Mounting extended rootfs
#
check_if_hd_ready_arg $HD_DEVICE
if [ $? = 1 ]; then
HD_BOOT_CONF=`cat /tmp/BOOT_CONF 2>/dev/null`
/bin/rm /tmp/BOOT_CONF
fi
grep ${EXT_MD_NAME} /proc/mdstat | grep active 1>>/dev/null 2>>/dev/null
if [ $? = 0 ]; then
EXT_MD_EXIST=1
else
EXT_MD_EXIST=0
fi
if [ -f /var/ch_model_update.fla ]; then
EXT_MD_EXIST=0
fi
Model_Name=`/bin/cat /etc/default_config/Model_Name.conf 2>/dev/null`
HD_Model_Name=`/bin/cat /tmp/Internal_Model 2>/dev/null`
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
/bin/echo "Extract RootFS Ext..."
[ -d $FLASH_TMP ] || /bin/mkdir $FLASH_TMP
if [ "x${BOOT_CONF}" = "xTS-NASX86" ]; then
extract_rootfs2 "${FLASH_RFS1}"
[ $? = 0 ] || extract_rootfs2 "${FLASH_RFS2}"
/bin/sync
fi
if [ "x${HD_BOOT_CONF}" = "xTS-NASX86" -a "x$HD_Model_Name" = "x$Model_Name" ] || \
[ "x${HD_BOOT_CONF}" = "xTS-NASPPC" -a "x$HD_Model_Name" = "x$Model_Name" ] || \
[ "x${HD_BOOT_CONF}" = "xTS-NASARM" -a "x$HD_Model_Name" = "x$Model_Name" ]; then
[ -d ${MNT_HD_ROOT_TMP} ] || /bin/mkdir ${MNT_HD_ROOT_TMP}
/bin/mount $CONFIG_Dev $MNT_HD_ROOT_TMP
if [ $? = 0 ]; then
/bin/echo "mountall: mount $CONFIG_Dev successful."
else
/bin/echo "mountall: mount $CONFIG_Dev failed."
fi
if [ -f ${ROOTFS_EXT} ] && [ "x${BOOT_CONF}" = "xTS-NASX86" ]; then
/bin/echo "Update Extended ${ROOTFS_EXT}..."
check_sum "${ROOTFS_EXT}" "${ROOTFS_EXT}.cksum"
if [ $? = 0 ]; then
/bin/tar xzf ${ROOTFS_EXT} -O > $HD_DEVICE
/bin/sync
fi
fi
/bin/umount $FLASH_TMP 1>/dev/null 2>&1
if [ -f ${MNT_HD_ROOT_TMP}/update/rootfs_ext.tgz ]; then
check_sum "${MNT_HD_ROOT_TMP}/update/rootfs_ext.tgz" "${MNT_HD_ROOT_TMP}/update/rootfs_ext.tgz.cksum"
if [ $? = 0 ]; then
/bin/tar xzf $MNT_HD_ROOT_TMP/update/rootfs_ext.tgz -O > $HD_DEVICE
fi
fi
if [ -f ${MNT_HD_ROOT_TMP}/update/qpkg.tar ]; then
check_sum "${MNT_HD_ROOT_TMP}/update/qpkg.tar" "${MNT_HD_ROOT_TMP}/update/qpkg.tar.cksum"
if [ $? = 0 ]; then
[ -d ${UPDATEPKG_DIR} ] || /bin/mkdir ${UPDATEPKG_DIR}
[ ! -f ${UPDATEPKG_DIR}/apache_php5.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/apache_php5.tgz
[ ! -f ${UPDATEPKG_DIR}/mysql5.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/mysql5.tgz
[ ! -f ${UPDATEPKG_DIR}/pgsql9.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/pgsql9.tgz
[ ! -f ${UPDATEPKG_DIR}/language.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/language.tgz
[ ! -f ${UPDATEPKG_DIR}/avahi0630.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/avahi0630.tgz
[ ! -f ${UPDATEPKG_DIR}/centerim.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/centerim.tgz
[ ! -f ${UPDATEPKG_DIR}/musicstation.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/musicstation.tgz
[ ! -f ${UPDATEPKG_DIR}/photostation2.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/photostation2.tgz
[ ! -f ${UPDATEPKG_DIR}/MSV2.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/MSV2.tgz
/bin/rm -f ${UPDATEPKG_DIR}/WFM*.tgz 2>/dev/null
/bin/rm -f ${UPDATEPKG_DIR}/jsLib.tgz 2>/dev/null
/bin/rm -f ${UPDATEPKG_DIR}/nvr_app.tar.gz 2>/dev/null
/bin/rm -f ${UPDATEPKG_DIR}/nvr_app2.tar.gz 2>/dev/null
/bin/tar xf $MNT_HD_ROOT_TMP/update/qpkg.tar -C ${UPDATEPKG_DIR}
[ ! -f ${UPDATEPKG_DIR}/photostation2.tgz ] || /bin/rm -rf ${UPDATEPKG_DIR}/PhotoStation 2>/dev/null
[ ! -f ${UPDATEPKG_DIR}/musicstation.tgz ] || /bin/rm -rf ${UPDATEPKG_DIR}/MusicStation 2>/dev/null
[ ! -f ${MNT_HD_ROOT_TMP}/update/update_qpkg_f ] || /bin/mv ${MNT_HD_ROOT_TMP}/update/update_qpkg_f ${UPDATEPKG_DIR}
fi
fi
/bin/rm -rf $MNT_HD_ROOT_TMP/update/* 1>/dev/null 2>&1
/bin/sync
if [ ! -f /var/ch_model_update.fla ]; then
/bin/mount $HD_DEVICE $MNT_POINT
_mnt_result=$?
if [ "x${BOOT_CONF}" = "xTS-NASARM" ] || [ "x${BOOT_CONF}" = "xTS-NASPPC" ]; then
if [ -d ${MNT_POINT}/home ] && [ -d ${MNT_POINT}/usr ]; then
/bin/rm -rf /home 2>/dev/null
/bin/rm -rf /usr 2>/dev/null
if [ -d ${MNT_POINT}/lib/modules/misc ]; then
/bin/rm -rf /lib/modules/misc 1>/dev/null 2>&1
/bin/ln -s $MNT_POINT/lib/modules/misc /lib/modules/misc
fi
/bin/ln -s $MNT_POINT/home /home
/bin/ln -s $MNT_POINT/usr /usr
[ ! -f /sbin/_thttpd_ ] || /bin/rm -rf /sbin/_thttpd_
/sbin/ldconfig
else
ROOTFS2=${ROOTFS2_16M}
extract_rootfs2 "${FLASH_RFS2_16M}"
/bin/umount $FLASH_TMP 1>/dev/null 2>&1
fi
fi
if [ ${_mnt_result} = 0 ]; then
[ -f /tmp/booting ] || /bin/touch /tmp/booting
[ -d /tmp/install ] || /bin/mkdir /tmp/install
/etc/init.d/installtgz.sh radius ${UPDATEPKG_DIR}/radius.tgz &
/etc/init.d/installtgz.sh samba ${UPDATEPKG_DIR}/samba.tgz &
/etc/init.d/installtgz.sh jsLib ${UPDATEPKG_DIR}/jsLib.tgz
/etc/init.d/installtgz.sh language ${UPDATEPKG_DIR}/language.tgz &
/etc/init.d/installtgz.sh WFM2 ${UPDATEPKG_DIR}/WFM2.tgz &
/etc/init.d/installtgz.sh WFM3 ${UPDATEPKG_DIR}/WFM3.tgz &
/etc/init.d/installtgz.sh ffmpeg ${UPDATEPKG_DIR}/ffmpeg.tgz
/etc/init.d/installtgz.sh ImageMagick ${UPDATEPKG_DIR}/ImageMagick.tgz
/etc/init.d/installtgz.sh vaultServices ${UPDATEPKG_DIR}/vaultServices.tgz &
[ ! -f ${UPDATEPKG_DIR}/libtorrent.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/libtorrent.tgz &
[ ! -f ${UPDATEPKG_DIR}/DS.tgz ] || /bin/rm -f ${UPDATEPKG_DIR}/DS.tgz &
/etc/init.d/installtgz.sh DSv3 ${UPDATEPKG_DIR}/DSv3.tgz &
/etc/init.d/installtgz.sh vpnpptp ${UPDATEPKG_DIR}/vpnpptp.tgz
/etc/init.d/installtgz.sh vpnopenvpn ${UPDATEPKG_DIR}/vpnopenvpn.tgz
/etc/init.d/installtgz.sh ldap_server ${UPDATEPKG_DIR}/ldap_server.tgz
/etc/init.d/installtgz.sh avahi0630 ${UPDATEPKG_DIR}/avahi0630.tgz
/etc/init.d/installtgz.sh printer ${UPDATEPKG_DIR}/printer.tgz &
/etc/init.d/installtgz.sh vim ${UPDATEPKG_DIR}/vim.tgz &
if [ -f ${UPDATEPKG_DIR}/medialibrary.tgz ]; then
/etc/init.d/installtgz.sh medialibrary ${UPDATEPKG_DIR}/medialibrary.tgz &
fi
fi
fi
# /bin/umount $CONFIG_Dev -> move to sysinit.sh
elif [ $EXT_MD_EXIST = 1 ]; then
# might be invalid HD case
/bin/umount $FLASH_TMP 1>/dev/null 2>&1
/bin/mount $HD_DEVICE $MNT_POINT
[ -d /home ] || /bin/ln -sf $MNT_POINT/home /home
if [ $? = 0 ]; then
if [ -x /sbin/hal_app ]; then
/sbin/hal_app --status_led_set enc_id=0,event=0x400,status=1
else
/sbin/set_status_led 1024 1
fi
fi
else
if [ "x${BOOT_CONF}" = "xTS-NASARM" ] || [ "x${BOOT_CONF}" = "xTS-NASPPC" ]; then
ROOTFS2=${ROOTFS2_16M}
extract_rootfs2 "${FLASH_RFS2_16M}"
fi
/bin/umount $FLASH_TMP 1>/dev/null 2>&1
fi
#/bin/df
/sbin/dmsetup targets 1>/dev/null 2>&1
[ $? = 0 ] && /bin/echo "dev-mapper ready."
for i in a b c d e f g h; do
#/bin/echo "hdparm -a 8192 /dev/sd$i"
/sbin/hdparm -a 8192 /dev/sd$i 1>/dev/null 2>&1
done
if [ -x /usr/bin/wget-s ]; then
/bin/rm -f /bin/wget-s 2>/dev/null
/bin/cp /usr/bin/wget-s /bin/wget-s
fi
[ -f /sbin/daemon_mgr ] && /sbin/daemon_mgr
/bin/sleep 1
[ -f /sbin/daemon_mgr.nvr ] && /sbin/daemon_mgr.nvr
#send loading systen to LCD
[ "x$COMPRT4LCD" != "xyes" ] && [ -f /sbin/lcd_tool ] && /sbin/lcd_tool -1 "Loading System" -2 "Please Wait..." &
/bin/touch "/var/.system.info"
if [ -f /sbin/dmidecode ]; then
/sbin/dmidecode -t memory | /bin/grep ECC > /dev/null 2>&1
[ $? = 0 ] && /sbin/setcfg RAM UseECC TRUE -f "/var/.system.info"
fi
/sbin/daemon_mgr hotswap start "/sbin/hotswap &"
. /etc/init.d/check_nss2
if [ "x$_NSS2_SUPPORT" = "xyes" ]; then
cp -v /etc/init.d/nvr_svc.sh /etc/init.d/nvrd.sh
fi

471
mysqld.sh Executable file
View File

@@ -0,0 +1,471 @@
#!/bin/sh
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind
# MySQL daemon start/stop script.
# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
# When this is done the mysql server will be started when the machine is
# started and shut down when the systems goes down.
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.
# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MySQL
# Description: MySQL is a very fast and reliable SQL database engine.
### END INIT INFO
# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
# [mysqld]
# basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
# and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
# below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=
datadir=
# The following variables are only set for letting mysql.server find things.
# Set some defaults
MNT_POINT="/mnt/ext"
MYSQL_SOURCE="${MNT_POINT}/opt/source/mysql5.tgz"
MYSQL_DIR="/usr/local/mysql"
ROOT_PART="/mnt/HDA_ROOT"
UPDATEPKG_DIR="${ROOT_PART}/update_pkg"
Project_Name=`/sbin/getcfg Project Name -d null -f /var/default`
DB_Inited="FALSE"
if [ -f ${UPDATEPKG_DIR}/mysql5.tgz ];then
[ ! -f $MYSQL_SOURCE ] || /bin/rm -f $MYSQL_SOURCE
MYSQL_SOURCE="${UPDATEPKG_DIR}/mysql5.tgz"
fi
if [ -f ${MYSQL_SOURCE} ] && [ ! -d ${MNT_POINT}/opt/mysql ]; then
/bin/tar xzf ${MYSQL_SOURCE} -C ${MNT_POINT}/opt
/bin/rm -f ${MYSQL_DIR}
/bin/ln -sf ${MNT_POINT}/opt/mysql ${MYSQL_DIR}
/bin/ln -sf /etc/config/my.cnf ${MYSQL_DIR}/my.cnf
/bin/sync
elif [ -d ${MNT_POINT}/opt/mysql ]; then
/usr/bin/readlink ${MYSQL_DIR}
if [ $? != 0 ]; then
/bin/rm -f ${MYSQL_DIR}
/bin/ln -sf ${MNT_POINT}/opt/mysql ${MYSQL_DIR}
/bin/ln -sf /etc/config/my.cnf ${MYSQL_DIR}/my.cnf
/bin/sync
fi
fi
pid_file=
server_pid_file=
use_mysqld_safe=1
user=admin
if test -z "$basedir"
then
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
if test -z "$datadir"
then
datadir=/usr/local/mysql/var
fi
sbindir=/usr/local/mysql/sbin
libexecdir=/usr/local/mysql/libexec
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
volume_test="HDA_DATA"
volume="HDA_DATA"
/sbin/test -f /usr/local/mysql/bin/mysqld_safe || exit 1
chown -R admin.administrators /usr/local/mysql/
chown -R admin.administrators /usr/local/mysql
chmod 644 /etc/my.cnf
chmod 644 /usr/local/mysql/my.cnf
chmod 644 /etc/config/my.cnf
/usr/bin/readlink "/share/Public" 1>>/dev/null 2>>/dev/null;
if [ $? = 0 ] && [ -d "/share/Public" ]; then
volume_test=`/sbin/getcfg Public path -f /etc/smb.conf | cut -d '/' -f 3`
[ "x${volume_test}" = "x" ] || volume=${volume_test}
if [ ! -d "/share/${volume}/Public" ]; then
/sbin/setcfg MySQL Enable FALSE
[ x"${1}" != "xstop" ] && exit 1
fi
# volume=`/usr/bin/readlink /share/Public | /bin/cut -d '/' -f 3`
[ -d /share/${volume}/.@mysql ] || /bin/mkdir /share/${volume}/.@mysql
if [ ! -d $datadir ]; then
[ ! -f $datadir ] || /bin/rm $datadir
/bin/ln -sf /share/${volume}/.@mysql $datadir
fi
else
[ x"${1}" != "xstop" ] && exit 1
fi
volume_test=`/sbin/getcfg Public path -f /etc/smb.conf | cut -d '/' -f 3`
if [ "x${volume_test}" = "x" ]; then
[ x"${1}" != "xstop" ] && exit 1
fi
/bin/mount | /bin/grep "/share/${volume_test}" 1>>/dev/null 2>>/dev/null
if [ $? != 0 ]; then
[ x"${1}" != "xstop" ] && exit 1
fi
# MySQL 5.1.x doesn't support "innodb_log_arch_dir" variable
/bin/sed -i "/innodb_log_arch_dir/d" /etc/config/my.cnf
#end here
# datadir_set is used to determine if datadir was set (and so should be
# *not* set inside of the --basedir= handler.)
datadir_set=
#
# Use LSB init script functions for printing messages, if possible
#
lsb_functions="/lib/lsb/init-functions"
if test -f $lsb_functions ; then
source $lsb_functions
else
log_success_msg()
{
echo " SUCCESS! $@"
}
log_failure_msg()
{
echo " ERROR! $@"
}
fi
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
export PATH
mode=$1 # start or stop
shift
other_args="$*" # uncommon, but needed when called from an RPM upgrade action
# Expected: "--skip-networking --skip-grant-tables"
# They are not checked here, intentionally, as it is the resposibility
# of the "spec" file author to give correct arguments only.
case `echo "testing\c"`,`echo -n testing` in
*c*,-n*) echo_n= echo_c= ;;
*c*,*) echo_n=-n echo_c= ;;
*) echo_n= echo_c='\c' ;;
esac
parse_server_arguments() {
for arg do
case "$arg" in
--basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
bindir="$basedir/bin"
if test -z "$datadir_set"; then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
;;
--datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`
datadir_set=1
;;
--user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
--pid-file=*) server_pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
--use-mysqld_safe) use_mysqld_safe=1;;
--use-manager) use_mysqld_safe=0;;
esac
done
}
parse_manager_arguments() {
for arg do
case "$arg" in
--pid-file=*) pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
--user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
esac
done
}
wait_for_pid () {
i=0
while test $i -lt 35 ; do
sleep 1
case "$1" in
'created')
test -s $pid_file && i='' && break
;;
'removed')
test ! -s $pid_file && i='' && break
;;
*)
echo "wait_for_pid () usage: wait_for_pid created|removed"
exit 1
;;
esac
echo $echo_n ".$echo_c"
i=`expr $i + 1`
done
if test -z "$i" ; then
log_success_msg
else
log_failure_msg
fi
}
# Get arguments from the my.cnf file,
# the only group, which is read from now on is [mysqld]
if test -x ./bin/my_print_defaults
then
print_defaults="./bin/my_print_defaults"
elif test -x $bindir/my_print_defaults
then
print_defaults="$bindir/my_print_defaults"
elif test -x $bindir/mysql_print_defaults
then
print_defaults="$bindir/mysql_print_defaults"
else
# Try to find basedir in /etc/my.cnf
conf=/etc/my.cnf
print_defaults=
if test -r $conf
then
subpat='^[^=]*basedir[^=]*=\(.*\)$'
dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
for d in $dirs
do
d=`echo $d | sed -e 's/[ ]//g'`
if test -x "$d/bin/my_print_defaults"
then
print_defaults="$d/bin/my_print_defaults"
break
fi
if test -x "$d/bin/mysql_print_defaults"
then
print_defaults="$d/bin/mysql_print_defaults"
break
fi
done
fi
# Hope it's in the PATH ... but I doubt it
test -z "$print_defaults" && print_defaults="my_print_defaults"
fi
#
# Read defaults file from 'basedir'. If there is no defaults file there
# check if it's in the old (depricated) place (datadir) and read it from there
#
extra_args=""
if test -r "$basedir/my.cnf"
then
extra_args="-e $basedir/my.cnf"
else
if test -r "$datadir/my.cnf"
then
extra_args="-e $datadir/my.cnf"
fi
fi
parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`
# Look for the pidfile
parse_manager_arguments `$print_defaults $extra_args manager`
#
# Set pid file if not given
#
if test -z "$pid_file"
then
pid_file=$datadir/mysqlmanager-`/bin/hostname`.pid
else
case "$pid_file" in
/* ) ;;
* ) pid_file="$datadir/$pid_file" ;;
esac
fi
if test -z "$server_pid_file"
then
server_pid_file=$datadir/`/bin/hostname`.pid
else
case "$server_pid_file" in
/* ) ;;
* ) server_pid_file="$datadir/$server_pid_file" ;;
esac
fi
# Safeguard (relative paths, core dumps..)
cd $basedir
case "$mode" in
'start')
# Start daemon
#added by KenChen@QNAP
[ `/sbin/getcfg MySQL Enable -u -d FALSE` = TRUE ] || exit 1
if [ `/sbin/getcfg MySQL DB_Init -u -d FALSE` = FALSE ] && [ -d $datadir ]; then
/usr/local/mysql/mysql_util.sh --init_db >/dev/null >/dev/null 2>&1
DB_Inited="TRUE"
sleep 3
elif [ -d $datadir ] && [ ! -f $datadir/mysql-bin.index ]; then
/usr/local/mysql/mysql_util.sh --init_db >/dev/null >/dev/null 2>&1
DB_Inited="TRUE"
sleep 3
/bin/sync
fi
#end here
manager=$bindir/mysqlmanager
if test -x $libexecdir/mysqlmanager
then
manager=$libexecdir/mysqlmanager
elif test -x $sbindir/mysqlmanager
then
manager=$sbindir/mysqlmanager
fi
echo $echo_n "Starting MySQL"
if test -x $manager -a "$use_mysqld_safe" = "0"
then
if test -n "$other_args"
then
log_failure_msg "MySQL manager does not support options '$other_args'"
exit 1
fi
# Give extra arguments to mysqld with the my.cnf file. This script may
# be overwritten at next upgrade.
$manager --user=$user --pid-file=$pid_file >/dev/null 2>&1 &
wait_for_pid created
# Make lock for RedHat / SuSE
if test -w /var/lock/subsys
then
touch /var/lock/subsys/mysqlmanager
fi
elif test -x $bindir/mysqld_safe
then
# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
pid_file=$server_pid_file
#$bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
#modified by KenChen@QNAP
$bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file --user=$user $other_args >/dev/null 2>&1 &
wait_for_pid created
# Make lock for RedHat / SuSE
if test -w /var/lock/subsys
then
touch /var/lock/subsys/mysql
fi
else
log_failure_msg "Couldn't find MySQL manager or server"
fi
#added by KenChen
if [ "x${Project_Name}" = "xAthens" ] && [ $DB_Inited = "TRUE" ]; then
/bin/echo "CREATE DATABASE \`wordpress\` ;" > /tmp/wordpress.sql
/usr/local/mysql/bin/mysql -u root --password=admin < /tmp/wordpress.sql
/bin/rm -f /tmp/wordpress.sql
fi
#
#added by bryan Wu 2011/12
if [ $DB_Inited = "TRUE" ] && [ -f /usr/local/mysql/CMSDB.sql ] && [ -f /usr/local/mysql/AddCmsUser.sql ] ; then
/usr/local/mysql/bin/mysql -u root --password=admin < /usr/local/mysql/CMSDB.sql
/usr/local/mysql/bin/mysql -u root --password=admin < /usr/local/mysql/AddCmsUser.sql
fi
#end of bryan added
;;
'stop')
# Stop daemon. We use a signal here to avoid having to know the
# root password.
# The RedHat / SuSE lock directory to remove
lock_dir=/var/lock/subsys/mysqlmanager
# If the manager pid_file doesn't exist, try the server's
if test ! -s "$pid_file"
then
pid_file=$server_pid_file
lock_dir=/var/lock/subsys/mysql
fi
if test -s "$pid_file"
then
mysqlmanager_pid=`cat $pid_file`
echo $echo_n "Shutting down MySQL"
kill $mysqlmanager_pid
# mysqlmanager should remove the pid_file when it exits, so wait for it.
wait_for_pid removed
# delete lock for RedHat / SuSE
if test -f $lock_dir
then
rm -f $lock_dir
fi
else
echo "Try to shutting down MySQL"
_kill=0
for i in /usr/local/mysql/var/*.pid ;do
if [ "$i" = "/usr/local/mysql/var/*.pid" ]; then
break
fi
_pidfile=$i
mysqlmanager_pid=`cat $_pidfile`
/bin/grep mysqld /proc/$mysqlmanager_pid/stat 2>/dev/null 1>/dev/null
if [ $? = 0 ]; then
/bin/kill $mysqlmanager_pid
wait_for_pid removed
/bin/rm -f $_pidfile
_kill=1
fi
done
if [ $_kill = 0 ]; then
log_failure_msg "MySQL manager or server PID file could not be found!"
fi
fi
;;
'restart')
# Stop the service and regardless of whether it was
# running or not, start it again.
$0 stop $other_args
$0 start $other_args
;;
'reload')
if test -s "$server_pid_file" ; then
mysqld_pid=`cat $server_pid_file`
kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL"
touch $server_pid_file
else
log_failure_msg "MySQL PID file could not be found!"
fi
;;
*)
# usage
echo "Usage: $0 {start|stop|restart|reload} [ MySQL server options ]"
exit 1
;;
esac

982
network.sh Executable file
View File

@@ -0,0 +1,982 @@
#!/bin/sh
#
# Copyright @ 2012 QNAP Systems Inc.
#
# network This script start/stop/restart network.
#
# Version 2.0.0
#
DBG=0
dbg()
{
if [ -f /tmp/dbg_network ]; then
echo "[# DBG #] $@ " >> /tmp/dbg_network
fi
if [ "x$DBG" = "x1" ]; then
echo ""
echo -n "[# DBG #] $@ "
fi
}
dbg "============== network.sh =============="
GETCFG="/sbin/getcfg"
SETCFG="/sbin/setcfg"
DEFAULT_GW_DEV=`$GETCFG "Network" "Default GW Device" -d eth0`
BOND_SUP=`$GETCFG "Network" "BONDING Support" -u -d FALSE`
NIC_NUM=`$GETCFG "Network" "Interface Number" -d "1"`
DEFAULT_NIC_NUM=`$GETCFG "Network" "Interface Number" -d 1 -f /etc/default_config/uLinux.conf` #reset by check_lan_port
if [ x$NIC_NUM != x$DEFAULT_NIC_NUM ]; then
$SETCFG "Network" "Interface Number" "$DEFAULT_NIC_NUM"
NIC_NUM=$DEFAULT_NIC_NUM
fi
BOND_NUM=`/usr/bin/expr ${DEFAULT_NIC_NUM} / 2`
GROUP_NUM=`$GETCFG "Network Group" "Group Count" -d $DEFAULT_NIC_NUM`
ADV_BOND_SUPPORT=`$GETCFG "Network" "Advanced Bonding Support" -u -d FALSE -f /etc/default_config/uLinux.conf`
ULINUX_UPGRADE=`$GETCFG "Network" "uLinux Upgrade" -u -d FALSE`
TwonkyMedia_Enable=`$GETCFG "TwonkyMedia" "Enable" -u -d FALSE`
QPKG_TwonkyMedia_Enable=`$GETCFG "TwonkyMedia" "Enable" -u -d FALSE -f "/etc/config/qpkg.conf"`
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
HAVECHANGE=0
use_default()
{
dbg "Entering use_default()"
DEFAULT_IP=`$GETCFG "Network" "Default IP" -d "169.254.100.100" -f "/var/default"`
dbg "cmd:/sbin/ifconfig $1 $DEFAULT_IP up"
/sbin/ifconfig $1 $DEFAULT_IP up &>/dev/null
#wait NIC up
/bin/sleep 3
dbg "cmd:/sbin/route add -host 255.255.255.255 $1"
/sbin/route add -host 255.255.255.255 $1 &>/dev/null
DEFAULT_ROUTE=`$GETCFG "Network" "Default Route" -d "169.254.0.0" -f "/var/default"`
dbg "cmd:/sbin/route del -net $DEFAULT_ROUTE netmask 255.255.0.0 dev $1"
/sbin/route del -net $DEFAULT_ROUTE netmask 255.255.0.0 dev $1 &>/dev/null
dbg "cmd:/sbin/route add -net $DEFAULT_ROUTE netmask 255.255.0.0 dev $1"
/sbin/route add -net $DEFAULT_ROUTE netmask 255.255.0.0 dev $1 &>/dev/null
}
check_and_reset_default_gw()
{
if [ $HAVECHANGE = 1 ]; then
return 0;
fi
HAVECHANGE=1
dbg "Entering check_and_reset_default_gate() $1"
local status=`/bin/cat /sys/class/net/${DEFAULT_GW_DEV}/operstate`
dbg "${DEFAULT_GW_DEV} status $status"
if [ "$status" = "up" ]; then
return 0;
fi
local updev="$1"
if [ "x$updev" = "xall" ]; then
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
local net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
local status=`/bin/cat /sys/class/net/${net_interface}/operstate`
dbg "${net_interface} status $status"
if [ "$status" = "up" ]; then
DEFAULT_GW_DEV=${net_interface}
dbg "cmd:$SETCFG "Network" "Default GW Device" "$DEFAULT_GW_DEV""
$SETCFG "Network" "Default GW Device" "$DEFAULT_GW_DEV"
return 1;
fi
fi
done
return 0;
fi
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
local net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
local status=`/bin/cat /sys/class/net/${net_interface}/operstate`
/bin/echo "${net_interface}" | /bin/grep "^eth" &>/dev/null
if [ $? = 0 ]; then #eth
if [ "${net_interface}" = "$updev" ]; then
if [ "$status" = "up" ]; then
DEFAULT_GW_DEV=${net_interface}
dbg "cmd:$SETCFG "Network" "Default GW Device" "$DEFAULT_GW_DEV""
$SETCFG "Network" "Default GW Device" "$DEFAULT_GW_DEV"
return 1;
fi
fi
else #bond
if [ "$status" = "up" ]; then
local bond_member=`$GETCFG "${net_interface}" "Bonding Member" -d ""`
for eth_id in `echo ${bond_member//,/ }`;
do
if [ "eth${eth_id}" = "$updev" ]; then
DEFAULT_GW_DEV=${net_interface}
dbg "cmd:$SETCFG "Network" "Default GW Device" "$DEFAULT_GW_DEV""
$SETCFG "Network" "Default GW Device" "$DEFAULT_GW_DEV"
return 1;
fi
done
fi
fi
fi
done
return 0;
}
add_dns()
{
dbg "Entering add_dns()"
local nas_dns
local myflag=0
local i
if [ "$1" = "STATIC" ]; then
/bin/rm -f /etc/resolv.conf &>/dev/null
fi
for i in 2 1
do
nas_dns=`$GETCFG "Network" "Domain Name Server $i" -d 0.0.0.0`
/bin/grep $nas_dns /etc/resolv.conf &>/dev/null
if [ $? != 0 ]; then
if [ "$nas_dns" != "0.0.0.0" ]; then
[ -f /etc/resolv.conf ] && /bin/mv /etc/resolv.conf /etc/resolv.conf.bak
dbg "cmd:/bin/echo "nameserver $nas_dns" > /etc/resolv.conf"
/bin/echo "nameserver $nas_dns" > /etc/resolv.conf
if [ -f /etc/resolv.conf.bak ]; then
/bin/cat /etc/resolv.conf.bak >> /etc/resolv.conf
/bin/rm -f /etc/resolv.conf.bak &>/dev/null
fi
myflag=1
fi
else
myflag=1
fi
done
if [ $myflag = 0 ]; then
/bin/echo "nameserver 0.0.0.0" >> /etc/resolv.conf
fi
}
set_mtu()
{
/bin/rm -f /tmp/NowSpeed &>/dev/null
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
local net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
check_mtu ${net_interface}
fi
done
}
check_mtu()
{
dbg "Entering check_mtu()"
local MTU=`$GETCFG $1 MTU -d 1500`
local SPEED="1000"
/bin/echo "$1" | /bin/grep "^eth" &>/dev/null
if [ $? = 0 ]; then #eth
local STATUS=`/bin/cat /sys/class/net/$1/operstate`
if [ "$STATUS" = "up" ]; then
/bin/echo "[$1]" >> /tmp/NowSpeed
/sbin/eth_util $1 >> /tmp/NowSpeed
SPEED=`$GETCFG $1 "Speed of $1" -f /tmp/NowSpeed`
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
$SETCFG $1 MTU 1500
fi
fi
else #bond
local bond_member=`$GETCFG $1 "Bonding Member" -d ""`
local member_up="0"
for eth_id in `echo ${bond_member//,/ }`;
do
local STATUS=`/bin/cat /sys/class/net/eth$eth_id/operstate`
if [ "$STATUS" = "up" ]; then
member_up="1"
/bin/echo "[eth$eth_id]" >> /tmp/NowSpeed
/sbin/eth_util eth$eth_id >> /tmp/NowSpeed
local _SPEED=`$GETCFG eth${eth_id} "Speed of eth${eth_id}" -f /tmp/NowSpeed`
if [ "$_SPEED" = "100" ]; then
SPEED="100"
fi
fi
done
if [ "$member_up" = "0" ]; then
SPEED=`$GETCFG $1 Speed -d "auto"`
if [ "$SPEED" = "auto" ]; then
SPEED="1000"
fi
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
dbg "cmd:$SETCFG $1 MTU 1500"
$SETCFG $1 MTU 1500
/sbin/write_log "[$1] Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
if [ "$SPEED" = "100" ]; then
dbg "cmd:/sbin/ifconfig $1 mtu 1500"
/sbin/ifconfig $1 mtu 1500
else
dbg "cmd:/sbin/ifconfig $1 mtu $MTU"
/sbin/ifconfig $1 mtu $MTU
fi
}
set_speed()
{
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
local net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
check_speed ${net_interface}
fi
done
}
check_speed()
{
dbg "Entering check_speed()"
local SPEED=`$GETCFG $1 Speed -d "auto"`
if [ "$SPEED" = "10000" ] || [ "$SPEED" = "1000" ] || [ "$SPEED" = "auto" ]; then
local SPEEDX=0x02f
elif [ "$SPEED" = "100" ]; then
local SPEEDX=0x008
fi
/bin/echo "$1" | /bin/grep "^eth" &>/dev/null
if [ $? = 0 ]; then #eth
local S0=`/bin/cat /sys/class/net/$1/speed`
/usr/sbin/ethtool $1 | /bin/grep 10000baseT &>/dev/null
if [ $? = 0 ] || [ "$SPEED" = "auto" ] ; then # Fixed 10G
/usr/sbin/ethtool -s $1 autoneg on &>/dev/null
dbg "cmd:/usr/sbin/ethtool -s $1 autoneg on"
elif [ "$SPEED" != "$S0" ]; then
/usr/sbin/ethtool -s $1 speed $SPEED advertise $SPEEDX autoneg on &>/dev/null
dbg "cmd:/usr/sbin/ethtool -s $1 speed $SPEED advertise $SPEEDX autoneg on"
fi
else #bond
local bond_member=`$GETCFG $1 "Bonding Member" -d ""`
for eth_id in `echo ${bond_member//,/ }`;
do
local S0=`/bin/cat /sys/class/net/eth${eth_id}/speed`
/usr/sbin/ethtool eth${eth_id} | /bin/grep 10000baseT &>/dev/null
if [ $? = 0 ] || [ "$SPEED" = "auto" ]; then # Fixed 10G
/usr/sbin/ethtool -s eth${eth_id} autoneg on &>/dev/null
dbg "cmd:/usr/sbin/ethtool -s eth${eth_id} autoneg on"
elif [ "$SPEED" != "$S0" ]; then
/usr/sbin/ethtool -s eth${eth_id} speed $SPEED advertise $SPEEDX autoneg on &>/dev/null
dbg "cmd:/usr/sbin/ethtool -s eth${eth_id} speed $SPEED advertise $SPEEDX autoneg on"
fi
done
fi
}
reorder_routeing_table_up()
{
dbg "Entering reorder_routeing_table_up() $1"
/bin/cat /proc/net/route | /bin/sed '/^Iface/d' > /tmp/nasroute.org
/bin/sed '/lo/d' -i /tmp/nasroute.org
[ ! -f /tmp/.boot_done ] || check_and_reset_default_gw $1
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
local net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
local status=`/bin/cat /sys/class/net/${net_interface}/operstate`
if [ "$status" = "up" ]; then
/bin/grep "^${net_interface}" /tmp/nasroute.org &>/dev/null
if [ $? != 0 ]; then
dbg "cmd:/sbin/ifconfig ${net_interface} down"
/sbin/ifconfig ${net_interface} down
/bin/sleep 1
NIC_start ${net_interface}
fi
fi
fi
done
[ -f /tmp/nasroute.org ] && /bin/rm -f /tmp/nasroute.org &>/dev/null
[ ! -f /etc/init.d/ipv6.sh ] || /etc/init.d/ipv6.sh start
}
routeing_table_delete()
{
dbg "Entering routeing_table_delete()"
pid=$(/bin/ps | /bin/grep "dhcpcd" | /bin/grep "$1" | /bin/awk '{print $1}')
if [ "x$pid" != "x" ]; then
dbg "cmd:/bin/kill -9 $pid"
/bin/kill -9 $pid &>/dev/null
fi
/etc/init.d/vlan.sh revert_vid $1
while read LINE
do
dbg "LINE=$LINE"
ip_dest=`/bin/echo $LINE | /bin/cut -f 1 -d " "`
if [ "$ip_dest" = "default" ]; then
if [ "x${DEFAULT_GW_DEV}" != "x$1" ]; then
dbg "cmd:/bin/ip route del default via $ip_dest dev $1"
/bin/ip route del default via $ip_dest dev $1 &>/dev/null
dbg "cmd:/sbin/route del -net 224.0.0.0 netmask 240.0.0.0 dev $1"
/sbin/route del -net 224.0.0.0 netmask 240.0.0.0 dev $1 &>/dev/null
fi
else
dbg "cmd:/bin/ip route del $ip_dest dev $1"
/bin/ip route del $ip_dest dev $1 &>/dev/null
fi
done < /tmp/$1.route
dbg "cmd:/sbin/ifconfig $1 0.0.0.0"
/sbin/ifconfig $1 0.0.0.0
}
reorder_routeing_table_down()
{
if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
sleep 5
fi
dbg "Entering reorder_routeing_table_down()"
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
/bin/ip route | /bin/grep "eth$i" > /tmp/eth$i.route
done
for (( i=0; i<$BOND_NUM; i=i+1 ))
do
/bin/ip route | /bin/grep "bond$i" > /tmp/bond$i.route
done
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
local net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
local status=`/bin/cat /sys/class/net/${net_interface}/operstate`
/bin/echo "${net_interface}" | /bin/grep "^eth" &>/dev/null
if [ $? = 0 ]; then #eth
if [ "$status" = "down" ]; then
routeing_table_delete ${net_interface}
fi
else #bond
if [ "$status" = "down" ]; then
routeing_table_delete ${net_interface}
else # Fixed, 802.3ad can not get bond down or up message
local bond_down=1
local bond_member=`$GETCFG "${net_interface}" "Bonding Member" -d ""`
for eth_id in `echo ${bond_member//,/ }`;
do
local status=`/bin/cat /sys/class/net/${net_interface}/slave_eth${eth_id}/operstate`
if [ "$status" = "up" ]; then
bond_down=0
fi
done
if [ ${bond_down} -eq 1 ]; then
routeing_table_delete ${net_interface}
fi
fi
fi
fi
done
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
[ -f /tmp/eth${i}.route ] && /bin/rm -f /tmp/eth${i}.route &>/dev/null
/bin/ip route | /bin/grep "default" | /bin/grep eth${i}
if [ $? = 0 ]; then
if [ "x${DEFAULT_GW_DEV}" != "xeth${i}" ]; then
dbg "cmd:/bin/ip route del default via default dev eth${i}"
/bin/ip route del default via default dev eth${i} &>/dev/null
fi
fi
done
for (( i=0; i<$BOND_NUM; i=i+1 ))
do
[ -f /tmp/bond${i}.route ] && /bin/rm -f /tmp/bond${i}.route &>/dev/null
/bin/ip route | /bin/grep "default" | /bin/grep bond${i}
if [ $? = 0 ]; then
if [ "x${DEFAULT_GW_DEV}" != "xbond${i}" ]; then
dbg "cmd:/bin/ip route del default via default dev bond${i}"
/bin/ip route del default via default dev bond${i} &>/dev/null
fi
fi
done
}
NIC_start()
{
dbg "Entering NIC_start()"
if [ `$GETCFG "$1" "Use DHCP" -u -d "TRUE"` = "TRUE" ]; then
/bin/echo "$1 DHCP"
use_default $1
[ -f /etc/dhcpc/dhcpcd-$1.info ] && /bin/rm -f /etc/dhcpc/dhcpcd-$1.info &>/dev/null
[ -f /etc/dhcpc/dhcpcd-$1.pid ] && /bin/rm -f /etc/dhcpc/dhcpcd-$1.pid &>/dev/null
local vlan_enable=`$GETCFG $1 vlan_enable -u -d "FALSE"`
if [ "$vlan_enable" = "TRUE" ]; then
/etc/init.d/vlan.sh set_vid $1
dbg "cmd:/sbin/ifconfig $1 0.0.0.0"
/sbin/ifconfig $1 0.0.0.0 &>/dev/null
[ -f /etc/dhcpc/dhcpcd-$1.*.info ] && /bin/rm -f /etc/dhcpc/dhcpcd-$1.*.info &>/dev/null
[ -f /etc/dhcpc/dhcpcd-$1.*.pid ] && /bin/rm -f /etc/dhcpc/dhcpcd-$1.*.pid &>/dev/null
local vlan_id=`$GETCFG $1 vlan_id -d ""`
use_default $1.$vlan_id
if [ "x${DEFAULT_GW_DEV}" = "x$1" ]; then
dbg "cmd:/sbin/dhcpcd -h "`/bin/hostname`" -t 30 $1.$vlan_id &"
/sbin/dhcpcd -h "`/bin/hostname`" -t 30 $1.$vlan_id &>/dev/null &
else
dbg "cmd:/sbin/dhcpcd -h "`/bin/hostname`" -t 30 -G $1.$vlan_id &"
/sbin/dhcpcd -h "`/bin/hostname`" -t 30 -G $1.$vlan_id &>/dev/null &
fi
else
dbg "cmd:/sbin/dhcpcd -h "`/bin/hostname`" -t 30 $1 &"
/sbin/dhcpcd -h "`/bin/hostname`" -t 30 $1 &>/dev/null &
fi
if [ $? != 0 ]; then
dbg "$1 run dhcpcd failed"
/bin/echo "Run dhcpcd failed."
fi
else
/bin/echo "$1 STATIC"
local ipaddress=`$GETCFG "$1" "IP Address" -d "169.254.100.100"`
local netmask=`$GETCFG "$1" "Subnet Mask" -d "255.255.0.0"`
local broadcast=`$GETCFG "$1" "Broadcast" -d "169.254.255.255"`
local gateway=`$GETCFG "$1" "Gateway" -d "0.0.0.0"`
if [ "$gateway" = "0.0.0.0" ]; then
gateway=$ipaddress
fi
dbg "cmd:/sbin/ifconfig $1 $ipaddress netmask $netmask broadcast $broadcast up"
/sbin/ifconfig $1 $ipaddress netmask $netmask broadcast $broadcast up &>/dev/null
dbg "cmd:/sbin/route add -host 255.255.255.255 $1"
/sbin/route add -host 255.255.255.255 $1 &>/dev/null
dbg "cmd:/sbin/route add -host $ipaddress $1"
/sbin/route add -host $ipaddress $1 &>/dev/null
if [ "x${DEFAULT_GW_DEV}" = "x$1" ]; then
dbg "cmd:/sbin/route add default gw $gateway metric 1 $1"
/sbin/route add default gw $gateway metric 1 $1 &>/dev/null
fi
local vlan_enable=`$GETCFG $1 vlan_enable -u -d "FALSE"`
if [ "$vlan_enable" = "TRUE" ]; then
/etc/init.d/vlan.sh set_vid $1
dbg "cmd:/sbin/ifconfig $1 0.0.0.0"
/sbin/ifconfig $1 0.0.0.0 &>/dev/null
fi
set_dns_static=1
fi
if [ "x$TwonkyMedia_Enable" = "xTRUE" ] || [ "x$QPKG_TwonkyMedia_Enable" = "xTRUE" ]; then
dbg "cmd:/sbin/route add -net 224.0.0.0 netmask 240.0.0.0 dev $1"
/sbin/route add -net 224.0.0.0 netmask 240.0.0.0 dev $1 &>/dev/null
fi
}
start()
{
dbg "Entering start()"
/bin/echo -n "Starting network..."
[ -d /etc/dhcpc ] || /bin/mkdir /etc/dhcpc
set_dns_static=0
DEFAULT_GW_DEV=`$GETCFG "Network" "Default GW Device" -d "NULL"`
if [ "$DEFAULT_GW_DEV" = "NULL" ]; then
if [ "$BOND_SUP" = "TRUE" ] && [ "$NIC_NUM" != "1" ]; then
DEFAULT_GW_DEV=bond0
else
DEFAULT_GW_DEV=eth0
fi
dbg "cmd:$SETCFG "Network" "Default GW Device" "$DEFAULT_GW_DEV""
$SETCFG "Network" "Default GW Device" "$DEFAULT_GW_DEV"
fi
[ ! -f /etc/init.d/ipv6.sh ] || /etc/init.d/ipv6.sh init
if [ "$BOND_SUP" = "TRUE" ]; then
/sbin/lsmod | /bin/grep bonding &>/dev/null
if [ $? != 0 ]; then
if [ -f /lib/modules/misc/bonding.ko ]; then
local bond_mod=`$GETCFG "bond0" "Bonding Mode" -d "1"`
if [ "x${BOOT_CONF}" = "xTS-NASARM" ] && [ "x$bond_mod" = "x5" -o "x$bond_mod" = "x6" ]; then
dbg "cmd:/sbin/insmod /lib/modules/misc/bonding.ko mode=$bond_mod miimon=100 downdelay=8000 max_bonds=$BOND_NUM"
/sbin/insmod /lib/modules/misc/bonding.ko mode=$bond_mod miimon=100 downdelay=8000 max_bonds=$BOND_NUM &>/dev/null
else
dbg "cmd:/sbin/insmod /lib/modules/misc/bonding.ko mode=1 miimon=100 max_bonds=$BOND_NUM"
/sbin/insmod /lib/modules/misc/bonding.ko mode=1 miimon=100 max_bonds=$BOND_NUM &>/dev/null
fi
fi
fi
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
local net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
/bin/echo "${net_interface}" | /bin/grep "^bond" &>/dev/null
if [ $? = 0 ]; then #bond
local bond_mod=`$GETCFG "${net_interface}" "Bonding Mode" -d "1"`
dbg "cmd:/bin/echo $bond_mod > /sys/class/net/${net_interface}/bonding/mode"
/bin/echo $bond_mod > /sys/class/net/${net_interface}/bonding/mode
dbg "cmd:/sbin/ifconfig ${net_interface} up"
/sbin/ifconfig ${net_interface} up &>/dev/null
local bond_member=`$GETCFG "${net_interface}" "Bonding Member" -d ""`
for eth_id in `echo ${bond_member//,/ }`;
do
dbg "cmd:/sbin/ifenslave ${net_interface} eth${eth_id}"
/sbin/ifenslave ${net_interface} eth${eth_id} &>/dev/null
done
fi
fi
done
/bin/sleep 1
vlan_enable=`$GETCFG bond0 vlan_enable -u -d "FALSE"`
if [ "$vlan_enable" = "TRUE" ]; then
#avoid the devide down
/bin/sleep 10
fi
elif [ "x$GROUP_NUM" != "x$NIC_NUM" ]; then
$SETCFG "Network Group" "Group Count" ${NIC_NUM}
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
$SETCFG "Network Group" "Group ${i}" "eth${i}"
$SETCFG "eth${i}" "Configure" "TRUE"
done
GROUP_NUM=$NIC_NUM
fi
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
local net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
NIC_start ${net_interface}
fi
done
/etc/init.d/wireless.sh start
if [ "x${DEFAULT_GW_DEV}" = "xwlan0" ]; then
if [ `$GETCFG "wireless" "iptype" -d "dhcp"` = "static" ]; then
set_dns_static=1
fi
fi
if [ ${set_dns_static} -eq 1 ]; then
add_dns "STATIC"
/bin/sleep 1
restart_dhcpd
fi
/etc/init.d/ipchange_notify.sh
[ ! -f /etc/init.d/ipv6.sh ] || /etc/init.d/ipv6.sh start
}
stop()
{
dbg "Entering stop()"
/bin/echo "Stopping network..."
[ -f /etc/init.d/ipv6.sh ] && /etc/init.d/ipv6.sh stop
[ -f /etc/init.d/upnpd.sh ] && /etc/init.d/upnpd.sh stop
/bin/rm -f /etc/resolv.conf &>/dev/null
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
dbg "cmd:/sbin/ifconfig eth$i down"
/sbin/ifconfig eth$i down &>/dev/null
done
/etc/init.d/vlan.sh stop
for (( i=0; i<$BOND_NUM; i=i+1 ))
do
/sbin/ifconfig | /bin/grep bond$i &>/dev/null
[ $? = 0 ] && release_bond bond$i
done
dbg "cmd:/sbin/rmmod bonding"
/sbin/rmmod bonding &>/dev/null
local pid
pid=`/bin/pidof dhcpcd`
if [ ! -z "$pid" ]; then
dbg "cmd:/bin/kill -9 $pid"
/bin/kill -9 $pid &>/dev/null
fi
/etc/init.d/wireless.sh stop
/bin/echo "Stopped."
}
release_bond()
{
dbg "Entering release_bond()"
local Max_NIC_NUM=`/usr/bin/expr ${NIC_NUM} - 1`
for (( i=$Max_NIC_NUM; i>=0; i=i-1 ))
do
/bin/cat /proc/net/bonding/$1 | /bin/grep "Slave Interface" | /bin/grep eth$i &>/dev/null
if [ $? = 0 ]; then
dbg "cmd:/sbin/ifenslave -d $1 eth$i"
/sbin/ifenslave -d $1 eth$i &>/dev/null
fi
done
dbg "cmd:/sbin/ifconfig $1 0.0.0.0"
/sbin/ifconfig $1 0.0.0.0 &>/dev/null
dbg "cmd:/sbin/ifconfig $1 down"
/sbin/ifconfig $1 down &>/dev/null
}
restart_dhcpd()
{
dbg "Entering restart_dhcpd()"
/sbin/test -f /usr/local/sbin/dhcpd || return 1
if [ `$GETCFG "DHCP Server" Enable -u -d FALSE` = "TRUE" ]; then
/etc/init.d/dhcpd.sh restart &>/dev/null
if [ $? != 0 ]; then
dbg "Run dhcpd.sh failed"
echo "Run dhcpd.sh failed."
fi
return 0
fi
}
reload()
{
dbg "Entering reload($1)"
# Patch for one lan port model (Bug #27514)
if [ "x${NIC_NUM}" = "x1" ]; then
if [ `$GETCFG "eth0" "Use DHCP" -u -d "TRUE"` = "TRUE" ]; then
/bin/echo "DHCP"
use_default eth0
/bin/kill -9 `pidof dhcpcd`
/bin/rm -f /etc/dhcpc/dhcpcd-eth0.*
/sbin/dhcpcd -h "`/bin/hostname`" -t 30 eth0 &
else
echo "STATIC"
local ipaddress=`$GETCFG "eth0" "IP Address" -d "169.254.100.100"`
local netmask=`$GETCFG "eth0" "Subnet Mask" -d "255.255.0.0"`
local broadcast=`$GETCFG "eth0" "Broadcast" -d "169.254.255.255"`
local gateway=`$GETCFG "eth0" "Gateway" -d "0.0.0.0"`
if [ "$gateway" = "0.0.0.0" ]; then
gateway=$ipaddress
fi
/sbin/ifconfig eth0 $ipaddress netmask $netmask broadcast $broadcast up
/sbin/route add -host 255.255.255.255 eth0
/sbin/route add -host $ipaddress eth0
/sbin/route add default gw $gateway metric 1 eth0
add_dns "STATIC"
restart_dhcpd
return $?
fi
fi
# Reload network settings for bond.
/bin/echo "$1" | /bin/grep "^bond" &>/dev/null
if [ $? != 0 ]; then
dbg "network.sh reload $1 fail. (network reload is bond only)"
/bin/echo "network.sh reload $1 fail. (network reload is bond only)"
return 1
fi
/sbin/ifconfig | /bin/grep $1 &>/dev/null
[ $? = 0 ] || return 1
/bin/echo "reload $1..."
if [ `$GETCFG "$1" "Use DHCP" -u -d "TRUE"` = "TRUE" ]; then
/bin/echo "$1 DHCP"
local vlan_enable=`$GETCFG "$1" vlan_enable -u -d "FALSE"`
if [ "$vlan_enable" = "TRUE" ]; then
local vlan_id=`$GETCFG "$1" vlan_id -d ""`
/etc/init.d/vlan.sh revert_vid $1
/etc/init.d/vlan.sh set_vid $1
dbg "cmd:/sbin/ifconfig $1 0.0.0.0"
/sbin/ifconfig $1 0.0.0.0 &>/dev/null
use_default $1.$vlan_id
pid=$(/bin/ps | /bin/grep "dhcpcd" | /bin/grep "$1" | /bin/awk '{print $1}')
if [ "x$pid" != "x" ]; then
dbg "cmd:/bin/kill -9 $pid"
/bin/kill -9 $pid &>/dev/null
fi
[ -f /etc/dhcpc/dhcpcd-$1.info ] && /bin/rm -f /etc/dhcpc/dhcpcd-$1.info
[ -f /etc/dhcpc/dhcpcd-$1.pid ] && /bin/rm -f /etc/dhcpc/dhcpcd-$1.pid
if [ "x${DEFAULT_GW_DEV}" = "x$1" ]; then
/sbin/dhcpcd -h "`/bin/hostname`" -t 30 $1.$vlan_id &
else
/sbin/dhcpcd -h "`/bin/hostname`" -t 30 -G $1.$vlan_id &
fi
else
use_default $1
pid=$(/bin/ps | /bin/grep "dhcpcd" | /bin/grep "$1" | /bin/awk '{print $1}')
if [ "x$pid" != "x" ]; then
dbg "cmd:/bin/kill -9 $pid"
/bin/kill -9 $pid &>/dev/null
fi
[ -f /etc/dhcpc/dhcpcd-$1.info ] && /bin/rm -f /etc/dhcpc/dhcpcd-$1.info
[ -f /etc/dhcpc/dhcpcd-$1.pid ] && /bin/rm -f /etc/dhcpc/dhcpcd-$1.pid
dbg "cmd:/sbin/dhcpcd -h "`/bin/hostname`" -t 30 $1 &"
/sbin/dhcpcd -h "`/bin/hostname`" -t 30 $1 &>/dev/null &
fi
else
/bin/echo "$1 STATIC"
local ipaddress=`$GETCFG "$1" "IP Address" -d "169.254.100.100"`
local netmask=`$GETCFG "$1" "Subnet Mask" -d "255.255.0.0"`
local broadcast=`$GETCFG "$1" "Broadcast" -d "169.254.255.255"`
local gateway=`$GETCFG "$1" "Gateway" -d "0.0.0.0"`
if [ "$gateway" = "0.0.0.0" ]; then
gateway=$ipaddress
fi
dbg "cmd:/sbin/ifconfig $1 $ipaddress netmask $netmask broadcast $broadcast"
/sbin/ifconfig $1 $ipaddress netmask $netmask broadcast $broadcast &>/dev/null
dbg "cmd:/sbin/route add -host 255.255.255.255 $1"
/sbin/route add -host 255.255.255.255 $1 &>/dev/null
dbg "cmd:/sbin/route add -host $ipaddress $1"
/sbin/route add -host $ipaddress $1 &>/dev/null
if [ "x${DEFAULT_GW_DEV}" = "x$1" ]; then
dbg "cmd:/sbin/route add default gw $gateway metric 1 $1"
/sbin/route add default gw $gateway metric 1 $1 &>/dev/null
fi
set_dns_static=1
local vlan_enable=`$GETCFG "$1" vlan_enable -u -d "FALSE"`
if [ "$vlan_enable" = "TRUE" ]; then
/etc/init.d/vlan.sh revert_vid $1
/etc/init.d/vlan.sh set_vid $1
dbg "cmd:/sbin/ifconfig $1 0.0.0.0"
/sbin/ifconfig $1 0.0.0.0 &>/dev/null
fi
fi
}
upgrade_ulinux()
{
dbg "upgrade_ulinux() start"
$SETCFG "Network Group" "LAN Count" ${NIC_NUM}
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
local enable=`$GETCFG "eth$i" "Configure" -d "NULL"`
if [ "x$enable" != "xNULL" ]; then
$SETCFG "eth${i}" "Configure" "False"
fi
done
for (( i=0; i<$BOND_NUM; i=i+1 ))
do
local enable=`$GETCFG "bond$i" "Configure" -d "NULL"`
if [ "x$enable" != "xNULL" ]; then
$SETCFG "bond${i}" "Configure" "False"
fi
done
if [ "x${BOND_SUP}" != "xTRUE" ]; then #standalone
$SETCFG "Network Group" "Group Count" ${NIC_NUM}
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
$SETCFG "Network Group" "Group ${i}" "eth${i}"
$SETCFG "eth${i}" "Configure" "TRUE"
done
else #bonding mix
local bonding_type=`$GETCFG "bond0" "Bonding Mode" -d 1`
if [ $NIC_NUM -gt 2 ]; then # NAS has more than 2 NICs.
local legacy_bond_mode=`$GETCFG "Network" "BONDING NICs" -d 0`
if [ "x${legacy_bond_mode}" = "x0" ]; then
TMP_GROUP=3
$SETCFG "Network Group" "Group 0" "bond0"
$SETCFG "bond0" "Configure" "TRUE"
$SETCFG "Network Group" "Group 1" "eth2"
$SETCFG "eth2" "Configure" "TRUE"
$SETCFG "Network Group" "Group 2" "eth3"
$SETCFG "eth3" "Configure" "TRUE"
$SETCFG "bond0" "Bonding Mode" "$bonding_type"
$SETCFG "bond0" "Bonding Member" "0,1"
$SETCFG "bond0" "Bonding Index" "1"
elif [ "x${legacy_bond_mode}" = "x1" ]; then
TMP_GROUP=3
$SETCFG "Network Group" "Group 0" "bond0"
$SETCFG "bond0" "Configure" "TRUE"
$SETCFG "Network Group" "Group 1" "eth0"
$SETCFG "eth0" "Configure" "TRUE"
$SETCFG "Network Group" "Group 2" "eth1"
$SETCFG "eth1" "Configure" "TRUE"
$SETCFG "bond0" "Bonding Mode" "$bonding_type"
$SETCFG "bond0" "Bonding Member" "2,3"
$SETCFG "bond0" "Bonding Index" "1"
elif [ "x${legacy_bond_mode}" = "x2" ]; then
TMP_GROUP=2
$SETCFG "Network Group" "Group 0" "bond0"
$SETCFG "bond0" "Configure" "TRUE"
$SETCFG "Network Group" "Group 1" "bond1"
$SETCFG "bond1" "Configure" "TRUE"
$SETCFG "bond0" "Bonding Mode" "$bonding_type"
$SETCFG "bond1" "Bonding Mode" "$bonding_type"
$SETCFG "bond0" "Bonding Member" "0,1"
$SETCFG "bond1" "Bonding Member" "2,3"
$SETCFG "bond0" "Bonding Index" "1"
$SETCFG "bond1" "Bonding Index" "2"
elif [ "x${legacy_bond_mode}" = "x3" ]; then
TMP_GROUP=1
$SETCFG "Network Group" "Group 0" "bond0"
$SETCFG "bond0" "Configure" "TRUE"
$SETCFG "bond0" "Bonding Mode" "$bonding_type"
$SETCFG "bond0" "Bonding Member" "0,1,2,3"
$SETCFG "bond0" "Bonding Index" "1"
fi
if [ $NIC_NUM -gt 4 ]; then # Patch for legacy nas with more than 4 NICs.
for (( i=4; i<$NIC_NUM; i=i+1 ))
do
$SETCFG "Network Group" "Group ${TMP_GROUP}" "eth${i}"
$SETCFG "eth${i}" "Configure" "TRUE"
TMP_GROUP=$((TMP_GROUP+1))
done
fi
$SETCFG "Network Group" "Group Count" "${TMP_GROUP}"
else # NAS has 2 NICs.
$SETCFG "Network Group" "Group Count" "1"
$SETCFG "Network Group" "Group 0" "bond0"
$SETCFG "bond0" "Configure" "TRUE"
$SETCFG "bond0" "Bonding Mode" "$bonding_type"
$SETCFG "bond0" "Bonding Member" "0,1"
$SETCFG "bond0" "Bonding Index" "1"
fi
fi
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
MAC_ADDR=`$GETCFG "MAC" "eth$i" -d "00:00:00:00:00:00" -f "/var/MacAddress"`
$SETCFG "eth${i}" "Mac Addresss" "$MAC_ADDR"
done
$SETCFG "Network" "Advanced Bonding Support" "TRUE"
$SETCFG "Network" "uLinux Upgrade" "TRUE"
dbg "upgrade_ulinux() finished"
}
resetgw()
{
dbg "reset default gateway"
check_and_reset_default_gw all
if [ $? = 1 ]; then
if [ `$GETCFG "${DEFAULT_GW_DEV}" "Use DHCP" -u -d "TRUE"` = "TRUE" ]; then
pid=$(/bin/ps | /bin/grep "dhcpcd" | /bin/grep "${DEFAULT_GW_DEV}" | /bin/awk '{print $1}')
if [ "x$pid" != "x" ]; then
dbg "cmd:/bin/kill -9 $pid"
/bin/kill -9 $pid &>/dev/null
fi
fi
/sbin/ifconfig ${DEFAULT_GW_DEV} down
/bin/sleep 1
NIC_start ${DEFAULT_GW_DEV}
fi
}
_lock()
{
[ -f /tmp/touch_network ] && exit 0
/bin/touch /tmp/touch_network
}
_wait_lock()
{
count=60
while [ -f /tmp/touch_network ] && [ $count -gt 0 ]; do
count=$(($count-1));
/bin/sleep 1
done
[ -f /tmp/touch_network ] && exit 0
}
_unlock()
{
/bin/rm -f /tmp/touch_network &>/dev/null
}
###################
# Main Function #
###################
if [ "x$ADV_BOND_SUPPORT" = "xTRUE" ] && [ "x$ULINUX_UPGRADE" != "xTRUE" ]; then
upgrade_ulinux
fi
#if [ x"$1" = xrouteup ] || [ x"$1" = xstart ] || [ x"$1" = xrestart ]; then
# /etc/init.d/bonjour.sh stop 1>>/dev/null 2>>/dev/null
#fi
case "$1" in
start)
_lock
stop
/bin/sleep 1
start
/bin/sleep 1
resetgw
/bin/sleep 1
reorder_routeing_table_down
/bin/sleep 1
set_speed
/bin/sleep 1
set_mtu
/bin/touch /etc/config/ipsec_deny.conf
/bin/touch /etc/config/ipsec.conf
/bin/touch /etc/config/ipsec_allow.conf
[ "x`/bin/pidof bcclient`" = "x" ] || /bin/kill -USR1 `/bin/pidof bcclient`
/etc/init.d/ads_register_dns.sh
_unlock
;;
stop)
stop
;;
restart)
_lock
stop
/bin/sleep 1
start
/bin/sleep 1
resetgw
/bin/sleep 1
reorder_routeing_table_down
/bin/sleep 1
set_speed
/bin/sleep 1
set_mtu
_unlock
;;
setdns)
add_dns
;;
write_hosts)
/etc/init.d/hostname.sh
;;
mtu)
set_mtu
exit 0
;;
speed)
set_speed
/bin/sleep 1
set_mtu
exit 0
;;
routedown)
reorder_routeing_table_down
;;
routeup)
_wait_lock
/bin/sleep 3
reorder_routeing_table_up $2
;;
reload)
reload $2
;;
cleanip)
/sbin/ifconfig bond0 0.0.0.0
;;
*)
/bin/echo $"Usage: $0 {start|stop|restart|setdns|write_hosts|mtu|speed|routedown|routeup|reload bond[i]}"
exit 1
esac
if [ x"$1" = xrouteup ] || [ x"$1" = xstart ] || [ x"$1" = xrestart ]; then
# Service binding
/sbin/getbindaddr -refresh &>/dev/null
dbg "/etc/init.d/bonjour.sh reload"
/etc/init.d/bonjour.sh reload &>/dev/null
fi
exit 0

232
nfs Executable file
View File

@@ -0,0 +1,232 @@
#!/bin/sh
# $NFSV4 means NFSv4 is installed or not.
# $ENABLE_NFS_V3 & $ENABLE_NFS_V4 mean NFS v3 or v4 are enabled or not.
[ -x /usr/sbin/rpc.nfsd ] || exit 0
[ -x /usr/sbin/rpc.mountd ] || exit 0
[ -x /usr/sbin/exportfs ] || exit 0
NFSV4=no
[ -f /usr/sbin/rpc.idmapd ] && NFSV4=yes
# For Service-Binding.
BIND_ADDR=`/sbin/getbindaddr NFS`
PORTMAP_PARAM=
# This function will update the parameter string which is fed to the 'portmap' program for service-binding.
update_portmap_parameter()
{
# if get "0.0.0.0", the service binding is disabled.
if [ "x0.0.0.0" != "x$BIND_ADDR" ] ; then
for ADDR in $BIND_ADDR
do
# Skip the loopback address. ( 127.0.0.1(IPv4) or ::1(IPv6) )
if [ "x127.0.0.1" != "x$ADDR" ] && [ "x::1" != "x$ADDR" ]; then
PORTMAP_PARAM="$PORTMAP_PARAM -h $ADDR"
fi
done
fi
}
insert_nfs_users()
{
i=1
tmp_nfs_conf="/tmp/nfs.conf.`date +%s`"
/bin/cp /etc/nfs.conf ${tmp_nfs_conf}
nfs_conf_cnt=`/usr/bin/wc -l ${tmp_nfs_conf}|/sbin/cut -c1-8`
while [ ${i} -le ${nfs_conf_cnt} ]
do
nfsuser=`/bin/sed -n "${i}p" ${tmp_nfs_conf}|/bin/sed -n "s/\([^:]*\):.*/\1/p"`
nfsluid=`/bin/sed -n "s/${nfsuser}:[^:]*:\([^:]*\):.*/\1/p" /etc/passwd`
paramline=`/bin/sed -n "${i}p" ${tmp_nfs_conf}|/bin/sed -n "s/${nfsuser}:\(.*\)/${nfsuser}:${nfsluid}:\1:/p"`
cmdline="add ${paramline}"
i=`expr $i + 1`
done
/bin/rm -f ${tmp_nfs_conf}
}
restart_mountd()
{
mountd_port_enabled=`/sbin/getcfg NFS "Mount Port Enable" -u -d NONE`
echo "Shutting down NFS mountd: "
/sbin/daemon_mgr rpc.mountd stop /usr/sbin/rpc.mountd
/bin/rm -f /var/lock/subsys/rpc.mountd
/bin/kill -9 `pidof rpc.mountd` 1>/dev/null 2>/dev/null
if [ "x${mountd_port_enabled}" = "xTRUE" ]; then
mountd_port=`/sbin/getcfg NFS "Port Number" -u -d 0`
if [ "x${mountd_port}" = "x0" ]; then
echo "Starting NFS mountd. Mountd port number assigned automatically."
/sbin/daemon_mgr rpc.mountd start "/usr/sbin/rpc.mountd -F 2>/dev/null 1>/dev/null &"
/bin/touch /var/lock/subsys/rpc.mountd
else
echo "Starting NFS mountd. Mountd port number = ${mountd_port}."
/sbin/daemon_mgr rpc.mountd start "/usr/sbin/rpc.mountd -p ${mountd_port} -F 2>/dev/null 1>/dev/null &"
/bin/touch /var/lock/subsys/rpc.mountd
fi
elif [ "x${mountd_port_enabled}" = "xFALSE" ]; then
echo "Starting NFS mountd. Mountd port number assigned automatically."
/sbin/daemon_mgr rpc.mountd start "/usr/sbin/rpc.mountd -F 2>/dev/null 1>/dev/null &"
/bin/touch /var/lock/subsys/rpc.mountd
else
echo "Starting NFS mountd. Mountd port number assigned automatically."
/sbin/daemon_mgr rpc.mountd start "/usr/sbin/rpc.mountd -F 2>/dev/null 1>/dev/null &"
/bin/touch /var/lock/subsys/rpc.mountd
fi
}
# See how we were called.
case "$1" in
reexport)
ENABLE_NFS_V3=`/sbin/getcfg NFS Enable -u -d FALSE`
if [ "x$NFSV4" = "xyes" ]; then
ENABLE_NFS_V4=`/sbin/getcfg NFS Enable_V4 -u -d FALSE`
else
ENABLE_NFS_V4=FALSE
fi
if [ "x$ENABLE_NFS_V3" = "xFALSE" ] && [ "x$ENABLE_NFS_V4" = "xFALSE" ]; then
echo " disabled."
exit 0
fi
/bin/mkdir /var/lib/nfs -p
# Re-export /etc/exprotfs.
tmp_smb_conf="/tmp/smb.conf.`date +%s`"
/bin/cp /etc/smb.conf ${tmp_smb_conf}
/sbin/gen_exports > /etc/exports
#/bin/sed -n 's/^path = \(\/share\/.*\)/\1 \*\(rw,async,no_root_squash\)/p' ${tmp_smb_conf} > /etc/exports
#/bin/sed -n 's/^path = \(\/share\/.*\)/\1 \*\(rw,sync,no_root_squash,all_squash,anonuid=100,anongid=100\)/p' /tmp/smb.conf.tmp > /etc/exports
#/bin/grep -v "global" /tmp/smb.conf.tmp | /bin/grep -v "printers" | /bin/sed -n 's/^\[\(.*\)\]/\/\1 \*\(rw,sync,no_root_squash,anonuid=100,anongid=100\)/p' > /etc/exports
/usr/sbin/exportfs -r 1>/dev/null 2>/dev/null
/bin/rm -f ${tmp_smb_conf}
#/bin/kill -s SIGHUP `pidof nasnfsd` 1>/dev/null 2>/dev/null
echo "re-export."
;;
start)
# Start daemons.
[ -f /var/lock/subsys/rpc.nfsd ] && $0 stop
[ -d /var/lib/nfs/sm ] || /bin/mkdir -p /var/lib/nfs/sm
[ -d /var/lib/nfs/sm.bak ] || /bin/mkdir -p /var/lib/nfs/sm.bak
TCP_PAYLOAD_SIZE=`/sbin/getcfg NFS TCP_PAYLOAD_SIZE -d FALSE`
UDP_PAYLOAD_SIZE=`/sbin/getcfg NFS UDP_PAYLOAD_SIZE -d FALSE`
[ ${TCP_PAYLOAD_SIZE} != "FALSE" ]&& echo $TCP_PAYLOAD_SIZE > /proc/net/rpc/tcp_payload_size
[ ${UDP_PAYLOAD_SIZE} != "FALSE" ]&& echo $UDP_PAYLOAD_SIZE > /proc/net/rpc/udp_payload_size
touch /etc/config/nfssetting
echo -n "Starting NFS services: "
ENABLE_NFS_V3=`/sbin/getcfg NFS Enable -u -d FALSE`
if [ "$NFSV4" = "yes" ]; then
ENABLE_NFS_V4=`/sbin/getcfg NFS Enable_V4 -u -d FALSE`
else
ENABLE_NFS_V4=FALSE
fi
if [ $ENABLE_NFS_V3 = FALSE ] && [ $ENABLE_NFS_V4 = FALSE ]
then
echo " disabled."
exit 0
fi
echo -n "Starting portmapper:"
#start-stop-daemon --start --quiet --exec /sbin/portmap
# Update the portmap parameter for Service-binding.
update_portmap_parameter
/usr/bin/portmap $PORTMAP_PARAM > /dev/null 2>/dev/null
echo -n "."
echo
if grep -qs nfsd /proc/filesystems ; then
if ! grep -qs "^nfsd[[:space:]]/proc/fs/nfsd[[:space:]]" /proc/mounts ; then
mount -t nfsd nfsd /proc/fs/nfsd
fi
fi
if [ "$ENABLE_NFS_V4" = "TRUE" ] && grep -qs rpc_pipefs /proc/filesystems ; then
if ! grep -qs "^rpc_pipefs[[:space:]]/var/lib/nfs/rpc_pipefs[[:space:]]" /proc/mounts ; then
[ -d /var/lib/nfs/rpc_pipefs ] || mkdir -p /var/lib/nfs/rpc_pipefs
mount -t rpc_pipefs rpc_pipefs /var/lib/nfs/rpc_pipefs
fi
fi
$0 reexport
echo -n "Starting NFS quotas: "
echo -n " rpc.rquotad"
/sbin/daemon_mgr rpc.rquotad start /usr/sbin/rpc.rquotad 1>/dev/null 2>/dev/null
/bin/touch /var/lock/subsys/rpc.rquotad
echo "."
echo -n "Starting NFS mountd daemon: "
restart_mountd
echo -n "Starting NFS daemon: "
echo " rpc.nfsd"
NO_V3=""
if [ $ENABLE_NFS_V3 = FALSE ]; then
NO_V3="-N 3 -N 2"
fi
NO_V4=""
if [ $ENABLE_NFS_V4 = FALSE ]; then
NO_V4="-N 4"
fi
/sbin/daemon_mgr nfsd start "/usr/sbin/rpc.nfsd $NO_V3 $NO_V4 8" 1>/dev/null 2>/dev/null
/bin/touch /var/lock/subsys/rpc.nfsd
if [ "$ENABLE_NFS_V4" = "TRUE" ] ; then
/usr/sbin/rpc.idmapd 1>/dev/null 2>/dev/null
fi
echo -n "Starting NFS lockd status:"
/usr/sbin/rpc.statd 1>/dev/null 2>/dev/null
echo "."
;;
stop)
# Stop daemons.
echo -n "Shutting down NFS daemon: "
echo -n " rpc.nfsd"
[ "$NFSV4" = "yes" ] && /bin/kill -9 `pidof rpc.idmapd` 1>/dev/null 2>/dev/null
/sbin/daemon_mgr nfsd stop /usr/sbin/rpc.nfsd
/bin/rm -f /var/lock/subsys/rpc.nfsd
/bin/kill -9 `/sbin/pidof nfsd` 1>/dev/null 2>/dev/null
/bin/kill -9 `/sbin/pidof statd` 1>/dev/null 2>/dev/null
/bin/kill -9 `/sbin/pidof rpc.statd` 1>/dev/null 2>/dev/null
echo "."
echo -n "Shutting down NFS mountd: "
echo -n " rpc.mountd"
/sbin/daemon_mgr rpc.mountd stop /usr/sbin/rpc.mountd
/bin/rm -f /var/lock/subsys/rpc.mountd
/bin/kill -9 `pidof rpc.mountd` 1>/dev/null 2>/dev/null
echo "."
echo -n "Shutting down NFS quotas: "
echo -n " rpc.rquotad"
/sbin/daemon_mgr rpc.rquotad stop /usr/sbin/rpc.rquotad
/bin/rm -f /var/lock/subsys/rpc.rquotad
/bin/kill -9 `pidof rpc.rquotad` 1>/dev/null 2>/dev/null
echo "."
exportfs -au
echo -n "Stopping portmap"
/bin/kill -9 `/sbin/pidof portmap` 1>/dev/null 2>/dev/null
echo "."
[ "$NFSV4" = "yes" ] && /sbin/umount_nfs_mp >/dev/null 2>&1
;;
restart)
$0 stop
$0 start
;;
remountd)
$0 reexport
echo "Restarting rpc.mountd: "
restart_mountd
;;
*)
echo "Usage: $0 {start|stop|restart|reexport|remountd}"
exit 1
esac
exit 0

6
nss2_dusg.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/sh
if [ -f /var/.nvr_init_ok ]; then
/usr/bin/qcmd DUSG
fi

36
ntpclient.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/sh
RETVAL=0
case "$1" in
start)
# check if it is necessary startup ntpdate daemon : ntpdated
mypid=`/bin/pidof ntpdated`
if [ ! -z $mypid ]; then
echo "ntpdate daemon has been started."
exit 1
else
echo -n "Starting NTP services: "
/sbin/daemon_mgr ntpdated start "/usr/sbin/ntpdated"
echo "ntpdated."
RETVAL=$?
fi
;;
stop)
echo "Shutting down NTP services: "
/sbin/daemon_mgr ntpdated stop "/usr/sbin/ntpdated"
echo "ntpdated."
RETVAL=$?
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $RETVAL

68
ntpd.sh Executable file
View File

@@ -0,0 +1,68 @@
#!/bin/sh
RETVAL=0
case "$1" in
start)
mypid=`/bin/pidof ntpd`
if [ ! -z $mypid ]; then
echo "NTP server has been started."
exit 1
else
#check if it is necessary to startup NTP server : ntpd
if [ `/sbin/getcfg NTP "Use NTP Server" -u -d FALSE` = TRUE ]; then
if [ `/sbin/getcfg NTP "Enable NTP Server" -u -d FALSE` = TRUE ]; then
if [ -f /etc/config/ntp.conf ]; then
echo "Remove the old ntp.conf"
rm -f /etc/config/ntp.conf
fi
echo "Create the new ntp.conf"
echo > /etc/config/ntp.conf
srvip1=`/sbin/getcfg NTP "Server1 IP" -d ""`
if [ "$srvip1" != "" ]; then
echo "server $srvip1" >> /etc/config/ntp.conf
/usr/sbin/ntpdate -q $srvip1 2>/dev/null 1>/dev/null
srvip1ok=$?
fi
srvip2=`/sbin/getcfg NTP "Server2 IP" -d ""`
if [ "$srvip2" != "" ]; then
echo "server $srvip2" >> /etc/config/ntp.conf
/usr/sbin/ntpdate -q $srvip2 2>/dev/null 1>/dev/null
srvip2ok=$?
fi
srvip3=`/sbin/getcfg NTP "Server3 IP" -d ""`
if [ "$srvip3" != "" ]; then
echo "server $srvip3" >> /etc/config/ntp.conf
/usr/sbin/ntpdate -q $srvip3 2>/dev/null 1>/dev/null
srvip3ok=$?
fi
if [ "$srvip1" == "" -a "$srvip2" == "" -a "$srvip3" == "" ] ||
[ "$srvip1ok" != "0" -a "$srvip2ok" != "0" -a "$srvip3ok" != "0" ]; then
echo > /etc/config/ntp.conf
echo "server 127.127.1.0" >> /etc/config/ntp.conf
echo "Error: No available IP address for time synchronization. Use local system clock as reference clock."
/sbin/write_log "There is no available IP address for time synchronization. System will use the local system clock as the reference clock." 2
fi
echo "driftfile /etc/ntp.drift" >> /etc/config/ntp.conf
echo "Starting NTP server: "
/sbin/daemon_mgr ntpd start "/usr/sbin/ntpd -c /etc/config/ntp.conf"
RETVAL=$?
fi
fi
fi
;;
stop)
echo "Shutting down NTP server: "
/sbin/daemon_mgr ntpd stop "/usr/sbin/ntpd"
RETVAL=$?
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $RETVAL

501
nvr_svc.sh Executable file
View File

@@ -0,0 +1,501 @@
#!/bin/sh
. /etc/init.d/functions
FindDefVol
_ret=$?
if [ $_ret != 0 ]; then
echo "Default volume not found."
exit 1
fi
#echo "${DEF_VOLMP}"
INSTALL_FLAG_FILE=/tmp/check_install.flag
if [ -f $INSTALL_FLAG_FILE ] ; then
INSTALLING=`/bin/cat $INSTALL_FLAG_FILE`
[ x"$INSTALLING" != x"1" ] || exit 0
fi
NSS_ENABLED=`/sbin/getcfg NVR Enable -d FALSE`
NVR_CLASS=`/sbin/getcfg System "NVR Class" -d NSS -f /etc/default_config/uLinux.conf`
NVR_ROOTFS=
export NVR_ROOTFS
RecordingsShare=`/sbin/getcfg SHARE_DEF defRecordings -d Qrecordings -f /etc/config/def_share.info`
WGET=/usr/bin/wget-s
[ -x ${WGET} ] || WGET=/usr/bin/wget
if [ "$NVR_CLASS" == "NVR" ]; then
NVR_DATA_ROOT=/data
else
NVR_DATA_ROOT=/share/$RecordingsShare
fi
# used only for NAS
MNT_POINT="/mnt/ext"
NVR_SOURCE="${MNT_POINT}/opt/source/nvr_app2.tar.gz"
NVR_DIR="/"
ROOT_PART="/mnt/HDA_ROOT"
UPDATEPKG_DIR="${ROOT_PART}/update_pkg"
if [ -f "${NVR_SOURCE}" ] && [ x`/sbin/getcfg "NVR" "NSS Enabled" -d no` = xno ]; then
/sbin/setcfg NVR "NSS Enabled" yes
fi
check_nvr_bin()
{
if [ ! -f /usr/bin/nvrd ] || [ ! -f /usr/bin/evtLogd ] || [ ! -f /usr/bin/evtd ]; then
echo "Surveillance Station not available."
return 1
fi
return 0
}
install_nvr_svc()
{
if [ "$NVR_CLASS" == "NVR" ]; then
return
fi
if [ ! -f /usr/bin/nvrd ]; then
_nvr_create_link=0
if [ -f ${UPDATEPKG_DIR}/nvr_app2.tar.gz ]; then
_nvr_target=${DEF_VOLMP}/.nvr
cd /
/bin/tar zxf ${UPDATEPKG_DIR}/nvr_app2.tar.gz --exclude *.cab --exclude msb --exclude ajax_obj_v2 --exclude libtranscoder.so.0.0
[ -d ${_nvr_target} ] || /bin/mkdir -p ${_nvr_target}
/bin/tar zxvf ${UPDATEPKG_DIR}/nvr_app2.tar.gz -C ${_nvr_target} --wildcards *.cab usr/msb home/httpd/ajax_obj_v2 usr/lib/libtranscoder.so.0.0
_nvr_create_link=1
elif [ -f ${NVR_SOURCE} ]; then
_nvr_target=/mnt/ext/opt/nvr
cd /
/bin/tar zxf ${NVR_SOURCE} --exclude *.cab --exclude msb --exclude ajax_obj_v2 --exclude libtranscoder.so.0.0
[ -d /mnt/ext/opt/nvr ] || /bin/mkdir -p ${_nvr_target}
/bin/tar zxvf ${NVR_SOURCE} -C /mnt/ext/opt/nvr --wildcards *.cab usr/msb home/httpd/ajax_obj_v2 usr/lib/libtranscoder.so.0.0
_nvr_create_link=1
else
echo "Surveillance Station not available."
/sbin/setcfg NVR Enable FALSE
exit 1
fi
if [ "x${_nvr_create_link}" = "x1" ]; then
/bin/rm -f /home/httpd/cgi-bin/NNVRVMon.cab 2>/dev/null
/bin/rm -f /home/httpd/cgi-bin/X86VMon.cab 2>/dev/null
/bin/rm -f /home/httpd/cgi-bin/Playback.cab 2>/dev/null
/bin/rm -f /home/httpd/cgi-bin/QNAP*.cab 2>/dev/null
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/X86VMon.cab /home/httpd/cgi-bin/X86VMon.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/Playback.cab /home/httpd/cgi-bin/Playback.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPG726.cab /home/httpd/cgi-bin/QNAPG726.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQ264.cab /home/httpd/cgi-bin/QNAPQ264.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQIVG.cab /home/httpd/cgi-bin/QNAPQIVG.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQMP4.cab /home/httpd/cgi-bin/QNAPQMP4.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQVivoTek.cab /home/httpd/cgi-bin/QNAPQVivoTek.cab
/bin/rm -rf /usr/msb 2>/dev/null
/bin/ln -sf ${_nvr_target}/usr/msb /usr/msb
/bin/rm -f /home/httpd/ajax_obj_v2 2>/dev/null
/bin/ln -sf ${_nvr_target}/home/httpd/ajax_obj_v2 /home/httpd/ajax_obj_v2
/bin/rm -f /usr/lib/libtranscoder.so.0.0 2>/dev/null
/bin/ln -sf ${_nvr_target}/usr/lib/libtranscoder.so.0.0 /usr/lib/libtranscoder.so.0.0
fi
[ ! -f /home/httpd/ajax_obj/js/qnapui.js_bak ] || /bin/cp /home/httpd/ajax_obj/js/qnapui.js_bak /home/httpd/ajax_obj/js/qnapui.js
[ ! -f /home/httpd/cgi-bin/html/login.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login.html_bak /home/httpd/cgi-bin/html/login.html
[ ! -f /home/httpd/cgi-bin/html/login_2.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login_2.html_bak /home/httpd/cgi-bin/html/login_2.html
fi
if [ -f /home/httpd/ajax_obj/js/qnapui.js ] && [ -f /home/httpd/cgi-bin/html/login.html ]; then
[ -f /home/httpd/ajax_obj/js/qnapui.js_bak ] || /bin/cp /home/httpd/ajax_obj/js/qnapui.js /home/httpd/ajax_obj/js/qnapui.js_bak
[ -f /home/httpd/cgi-bin/html/login.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login.html /home/httpd/cgi-bin/html/login.html_bak
[ -f /home/httpd/cgi-bin/html/login_2.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login_2.html /home/httpd/cgi-bin/html/login_2.html_bak
/bin/sed -i 's/\/cgi-bin\/camera_view.cgi/\/nssindex.html/g' /home/httpd/ajax_obj/js/qnapui.js 2>/dev/null
/bin/sed -i 's/\/cgi-bin\/camera_view.cgi/\/nssindex.html/g' /home/httpd/cgi-bin/html/login.html 2>/dev/null
/bin/sed -i 's/\/cgi-bin\/camera_view.cgi/\/nssindex.html/g' /home/httpd/cgi-bin/html/login_2.html 2>/dev/null
fi
check_nvr_bin
if [ $? != 0 ]; then
/sbin/setcfg NVR Enable FALSE
exit 1
fi
}
create_nvr_cfg_files()
{
if [ ! -e /etc/config/nvrd.xml ]; then
/bin/cp -a /etc/default_config/nvrd.xml /etc/config/
fi
if [ ! -e /etc/config/nvrstat.xml ]; then
/bin/cp -a /etc/default_config/nvrstat.xml /etc/config/
fi
if [ ! -e /var/.nvr_quota_info ]; then
/bin/mkdir /var/.nvr_quota_info
fi
if [ ! -f /etc/config/cact.xml ]; then
cp /etc/default_config/cact.xml /etc/config/cact.xml
fi
if [ ! -f /etc/config/nvrd2.xml ]; then
cp /etc/default_config/nvrd2.xml /etc/config/nvrd2.xml
fi
if [ ! -f /etc/config/emapinfo.xml ]; then
cp /etc/default_config/emapinfo.xml /etc/config/
if [ ! -e /etc/config/emap ]; then
mkdir /etc/config/emap
cp /etc/default_config/emap/emap.jpg /etc/config/emap/
fi
fi
evt_xml_file_list="evt act evt_act_list nvr_evt preset_tab sms_provider email_last_change cms_evt";
for f in $evt_xml_file_list; do
if [ ! -e /etc/config/$f.xml ]; then
/bin/cp /etc/default_config/$f.xml /etc/config/
if [ "$f" == "evt" ]; then
qcmd ms_evt
fi
if [ "$f" == "cms_evt" ]; then
qcmd cms_evt
fi
else
if [ "$f" == "evt" ]; then
qcmd ms_evt_upd
fi
if [ "$f" == "cms_evt" ]; then
qcmd cms_evt_upd
fi
fi
done
if [ ! -e /etc/config/evt_sch0.xml ]; then
cp /etc/default_config/evt_sch*.xml /etc/config/ ;
fi
if [ -e /etc/default_config/sys_sch.xml ]; then
cp /etc/default_config/sys_sch.xml /etc/
fi
if [ -f /usr/nvr/model.xml ]; then
max_ch=`/sbin/getcfg NVR NSS_MAX_CH_NUM -d 16 -f /etc/default_config/uLinux.conf`
/bin/grep "<max_channel_num>$max_ch</max_channel_num>" /usr/nvr/model.xml 1>/dev/null 2>/dev/null
[ $? = 0 ] || /bin/sed -i 's/^.*<max_channel_num>.*/'"<max_channel_num>$max_ch<\/max_channel_num>"'/g' /usr/nvr/model.xml
fi
}
create_nvr_links()
{
touch /home/httpd/cgi-bin/getstream.cgi
chmod +x /home/httpd/cgi-bin/getstream.cgi
touch /home/httpd/cgi-bin/ptz.cgi
chmod +x /home/httpd/cgi-bin/ptz.cgi
touch /home/httpd/cgi-bin/http_stream_start.cgi
touch /home/httpd/cgi-bin/http_stream_stop.cgi
chmod +x /home/httpd/cgi-bin/http_stream_start.cgi
chmod +x /home/httpd/cgi-bin/http_stream_stop.cgi
#Hugo add. correct link path for Marvell
[ -e /usr/bin/nvrvideo_backup2usb.sh ] || ln -s /etc/init.d/nvrvideo_backup2usb.sh /usr/bin/nvrvideo_backup2usb.sh 2>/dev/null
if [ ! -e /usr/bin/msfinder0 ]; then
ln -s /usr/bin/msfinder /usr/bin/msfinder0
fi
if [ ! -e /usr/bin/msfinder1 ]; then
ln -s /usr/bin/msfinder /usr/bin/msfinder1
fi
if [ ! -e /play ]; then
mkdir /play
fi
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
do
if [ ! -e /play/ch$i ]; then
mkdir /play/ch$i
fi
if [ ! -e /play/ch$i/record_nvr ]; then
mkdir /play/ch$i/record_nvr
fi
if [ ! -e /play/ch$i/record_nvr/channel$i ]; then
ln -s $NVR_DATA_ROOT/record_nvr/channel$i /play/ch$i/record_nvr/channel$i
fi
if [ ! -e /play/ch$i/.record_nvr_unk ]; then
mkdir /play/ch$i/.record_nvr_unk
fi
if [ ! -e /play/ch$i/.record_nvr_unk/channel$i ]; then
ln -s $NVR_DATA_ROOT/.record_nvr_unk/channel$i /play/ch$i/.record_nvr_unk/channel$i
fi
if [ ! -e /play/ch$i/record_nvr_alarm ]; then
mkdir /play/ch$i/record_nvr_alarm
fi
if [ ! -e /play/ch$i/record_nvr_alarm/channel$i ]; then
ln -s $NVR_DATA_ROOT/record_nvr_alarm/channel$i /play/ch$i/record_nvr_alarm/channel$i
fi
done
if [ -e /home/httpd/cgi-bin/record ]; then
/bin/rm /home/httpd/cgi-bin/record
fi
/bin/ln -s $NVR_DATA_ROOT /home/httpd/cgi-bin/record
if [ -e /home/httpd/record ]; then
/bin/rm /home/httpd/record
fi
# remove unused data folders
/bin/ln -s $NVR_DATA_ROOT /home/httpd/record
if [ -e $NVR_DATA_ROOT/record_nvr_tmp ]; then
/bin/rm -rf $NVR_DATA_ROOT/record_nvr_tmp
fi
if [ -e $NVR_DATA_ROOT/record_nvr_unk ]; then
/bin/rm -rf $NVR_DATA_ROOT/record_nvr_unk
fi
if [ -e $NVR_DATA_ROOT/record_nvr_pre ]; then
/bin/rm -rf $NVR_DATA_ROOT/record_nvr_pre
fi
}
remove_nvr_links()
{
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
do
rm /play/ch$i/record_nvr/channel$i
rm /play/ch$i/record_nvr_alarm/channel$i
rm /play/ch$i/.record_nvr_unk/channel$i
done
}
ROOT_PART="/mnt/HDA_ROOT"
HIDDEN_LOG_DIR="${ROOT_PART}/.logs"
HIDDEN_CONF_FILE=/mnt/HDA_ROOT/.conf
TS_LOG_DIR=/etc/logs
create_nvr_log_database()
{
if [ -f $HIDDEN_CONF_FILE ] && [ -d $HIDDEN_LOG_DIR ]; then
if [ -e $TS_LOG_DIR ] && [ ! -f $TS_LOG_DIR/nvrlog.log ]; then
/sbin/nvr_log_tool -v -c
/sbin/nvr_log_tool -v -b 10000
fi
else
echo log hidden config directory not exist, initial 10K surv log file... [OK]
if [ -e $TS_LOG_DIR ] && [ ! -f $TS_LOG_DIR/nvrlog.log ]; then
/sbin/nvr_log_tool -v -c
/sbin/nvr_log_tool -v -b 50
fi
fi
}
init_nvr_svc()
{
if [ `/sbin/getcfg NVR Enable -u -d FALSE` != TRUE ]; then
return 0;
fi
if [ -e /var/.nvr_init_ok ]; then
check_nvr_bin
[ $? != 0 ] || return 0
/bin/rm -f /var/.nvr_init_ok 2>/dev/null
fi
/bin/touch /var/.nvr_init_ok
install_nvr_svc
create_nvr_cfg_files
create_nvr_links
create_nvr_log_database
/usr/bin/qcmd XMLCR
/usr/bin/sysadm init
/usr/bin/sysadm start
/usr/bin/qcmd nvrd_xml
#update cron table for NVR here...
# start http streaming here
count=30;
while [ $count -gt 0 ]; do
${WGET} -4 -N http://127.0.0.1:`/sbin/getcfg System "Web Access Port" -d 8080`/cgi-bin/http_stream_start.cgi >& /dev/null
if [ -e /home/httpd/cgi-bin/getstream.cgi ]; then
count=0
else
/bin/sleep 1
count=$(($count-1));
fi
done
return 1
}
start_nvrd()
{
check_nvr_bin
[ $? = 0 ] || exit 1
# dont't do reentry control here!, do it in nvrd
/sbin/daemon_mgr.nvr evtLogd start "/usr/bin/evtLogd"
if [ -e $NVR_DATA_ROOT/.mxpg_raw ]; then /bin/rm -rf $NVR_DATA_ROOT/.mxpg_raw/*; fi
if [ ! -e $NVR_DATA_ROOT/.mxpg_raw ]; then /bin/mkdir $NVR_DATA_ROOT/.mxpg_raw; fi
echo -n "Starting nvrd services:"
/bin/touch /var/.nvrd_alive
/sbin/daemon_mgr.nvr nvrd start "/usr/bin/nvrd 2>/dev/null"
echo -n " nvrd"
echo -n "Starting evtd services:"
/sbin/daemon_mgr.nvr evtd start "/usr/bin/evtd 2>/dev/null"
echo -n " evtd"
if [ -f /usr/bin/snapshotd ]; then
echo -n "Starting snapshotd services:"
/sbin/daemon_mgr.nvr snapshotd start "/usr/bin/snapshotd 2>/dev/null"
echo -n " snapshotd"
fi
/usr/bin/qcmd adv_user_check
echo "."
}
stop_nvrd()
{
if [ -f /usr/bin/snapshotd ]; then
echo -n "Shutting down snapshotd services:"
/sbin/daemon_mgr.nvr snapshotd stop /usr/bin/snapshotd
echo -n " snapshotd"
fi
echo -n "Shutting down evtd services:"
/sbin/daemon_mgr.nvr evtd stop /usr/bin/evtd
echo -n " evtd"
echo -n "Shutting down nvrd services:"
/sbin/daemon_mgr.nvr nvrd stop /usr/bin/nvrd
echo -n " nvrd"
/sbin/daemon_mgr.nvr evtLogd stop /usr/bin/evtLogd
echo "."
}
_start_nvr_svc()
{
if [ ! -e /var/.nvr_init_ok ]; then
return 0
fi
# remove cache
qcmd rmcache > /dev/null 2> /dev/null
start_nvrd
/etc/init.d/qplayd.sh start
/etc/init.d/cacd.sh start
# start HTTP Live Streaming here...
# start NVR-RR here...
if [ "$NVR_CLASS" == "NVR" ]; then
# Check last time RR is finished
if [ `/sbin/getcfg "ScheduleStatus" "Enable" -d False -f /etc/config/rsync_schedule.conf` = "True" ]; then
if [ `/sbin/getcfg "ScheduleStatus" "isRRFinish" -d True -f /etc/config/rsync_schedule.conf` = "False" ]; then
echo "start dataBackup that last time not finish"
/usr/bin/dataBackup &
fi
fi
fi
return 1
}
start_nvr_svc()
{
if [ ! -e /var/.nvr_init_ok ]; then
return 0
fi
APP_RUNTIME_CONF="/var/.application.conf"
NSS_Hide=`/sbin/getcfg DISABLE survielance -d 0 -f $APP_RUNTIME_CONF`
if [ "x$NSS_Hide" = "x1" ] && [ x"$NSS_ENABLED" = x"TRUE" ]; then
/sbin/setcfg NVR Enable FALSE
NSS_ENABLED="FALSE"
fi
if [ "$NVR_CLASS" != "NSS" ] || [ "$NSS_ENABLED" != "TRUE" ]; then
return 0
fi
_start_nvr_svc
}
_stop_nvr_svc()
{
if [ ! -e /var/.nvr_init_ok ]; then
return 0
fi
# stop HTTP Live Streaming here...
/etc/init.d/cacd.sh stop
/etc/init.d/qplayd.sh stop
stop_nvrd
return 1
}
stop_nvr_svc()
{
if [ "$NVR_CLASS" != "NSS" ] || [ "$NSS_ENABLED" != "TRUE" ]; then
return 0
fi
_stop_nvr_svc
}
nvr_svc_started()
{
if [ ! -e /var/.nvr_start_ok ]; then
echo 0
else
echo 1
fi
}
uninit_nvr_svc()
{
if [ ! -e /var/.nvr_init_ok ]; then
return 0
fi
/bin/rm /var/.nvr_init_ok
remove_nvr_links
file_list="/usr/bin/msfinder0 /usr/bin/msfinder1 /home/httpd/cgi-bin/ptz.cgi /home/httpd/cgi-bin/getstream.cgi";
for f in $file_list; do
if [ ! -e $f ]; then
/bin/rm $f
fi
done
/usr/bin/sysadm stop
/usr/bin/sysadm uninit
/usr/bin/qcmd XMLRM
# stop http streaming here
count=30;
while [ $count -gt 0 ]; do
${WGET} -4 -N http://127.0.0.1:`/sbin/getcfg System "Web Access Port" -d 8080`/cgi-bin/http_stream_stop.cgi >& /dev/null
if [ -e /home/httpd/cgi-bin/getstream.cgi ]; then
/bin/sleep 1
count=$(($count-1));
else
count=0
fi
done
return 1
}
# _init, _uninit, _start, _stop used by NVR
# start, stop used by NSS
case "$1" in
start)
init_nvr_svc
start_nvr_svc
;;
stop)
stop_nvr_svc
uninit_nvr_svc
;;
restart)
$0 stop
$0 start
;;
started)
nvr_svc_started
;;
_init)
init_nvr_svc
;;
_unint)
uninit_nvr_svc
;;
_start)
_start_nvr_svc
;;
_stop)
_stop_nvr_svc
;;
_restart)
$0 _stop
$0 _start
;;
*)
echo "Usage: /etc/init.d/nvr_svc {start|stop|restart}"
exit 1
esac
exit 0

257
nvrd.sh Executable file
View File

@@ -0,0 +1,257 @@
#!/bin/sh
# For Administration
INSTALL_FLAG_FILE=/tmp/check_install.flag
if [ -f $INSTALL_FLAG_FILE ] ; then
INSTALLING=`/bin/cat $INSTALL_FLAG_FILE`
[ x"$INSTALLING" != x"1" ] || exit 0
fi
NVR_ROOTFS=
export NVR_ROOTFS
RecordingsShare=`/sbin/getcfg SHARE_DEF defRecordings -d Qrecordings -f /etc/config/def_share.info`
ROOTFS=$NVR_ROOTFS
WGET=/usr/bin/wget-s
[ -x ${WGET} ] || WGET=/usr/bin/wget
# Set some defaults
MNT_POINT="/mnt/ext"
NVR_SOURCE="${MNT_POINT}/opt/source/nvr_app.tar.gz"
NVR_DIR="/"
ROOT_PART="/mnt/HDA_ROOT"
UPDATEPKG_DIR="${ROOT_PART}/update_pkg"
if [ "`/sbin/getcfg -f /etc/default_config/uLinux.conf NVR Support -d FALSE`" == "TRUE" ]; then
SUPPORT_NVR=yes
else
SUPPORT_NVR=no
fi
init_nvrd()
{
if [ ! -f /usr/bin/nvrd ]; then
_nvr_target=/mnt/ext/opt/nvr
_nvr_create_link=0
if [ -f ${NVR_SOURCE} ]; then
/bin/rm -rf /usr/msb 2>/dev/null; mkdir /usr/msb
cd /
/bin/tar zxf ${NVR_SOURCE} --exclude *.cab
[ -d /mnt/ext/opt/nvr ] || /bin/mkdir -p ${_nvr_target}
/bin/tar zxvf ${NVR_SOURCE} -C /mnt/ext/opt/nvr --wildcards *.cab
_nvr_create_link=1
elif [ -f ${UPDATEPKG_DIR}/nvr_app.tar.gz ]; then
/bin/rm -rf /usr/msb 2>/dev/null; mkdir /usr/msb
cd /
/bin/tar zxf ${UPDATEPKG_DIR}/nvr_app.tar.gz --exclude *.cab
[ -d /mnt/ext/opt/nvr ] || /bin/mkdir -p ${_nvr_target}
/bin/tar zxvf ${UPDATEPKG_DIR}/nvr_app.tar.gz -C /mnt/ext/opt/nvr --wildcards *.cab
_nvr_create_link=1
fi
if [ "x${_nvr_create_link}" = "x1" ]; then
/bin/rm -f /home/httpd/cgi-bin/NNVRVMon.cab 2>/dev/null
/bin/rm -f /home/httpd/cgi-bin/QNAP*.cab 2>/dev/null
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/NNVRVMon.cab /home/httpd/cgi-bin/NNVRVMon.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPG726.cab /home/httpd/cgi-bin/QNAPG726.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQ264.cab /home/httpd/cgi-bin/QNAPQ264.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQIVG.cab /home/httpd/cgi-bin/QNAPQIVG.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQMP4.cab /home/httpd/cgi-bin/QNAPQMP4.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQVivoTek.cab /home/httpd/cgi-bin/QNAPQVivoTek.cab
fi
[ ! -f /home/httpd/ajax_obj/js/qnapui.js_bak ] || /bin/cp /home/httpd/ajax_obj/js/qnapui.js_bak /home/httpd/ajax_obj/js/qnapui.js
[ ! -f /home/httpd/cgi-bin/html/login.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login.html_bak /home/httpd/cgi-bin/html/login.html
[ ! -f /home/httpd/cgi-bin/html/login_2.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login_2.html_bak /home/httpd/cgi-bin/html/login_2.html
fi
if [ -f /home/httpd/ajax_obj/js/qnapui.js ] && [ -f /home/httpd/cgi-bin/html/login.html ]; then
[ -f /home/httpd/ajax_obj/js/qnapui.js_bak ] || /bin/cp /home/httpd/ajax_obj/js/qnapui.js /home/httpd/ajax_obj/js/qnapui.js_bak
[ -f /home/httpd/cgi-bin/html/login.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login.html /home/httpd/cgi-bin/html/login.html_bak
[ -f /home/httpd/cgi-bin/html/login_2.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login_2.html /home/httpd/cgi-bin/html/login_2.html_bak
/bin/sed -i 's/\/nssindex.html/\/cgi-bin\/camera_view.cgi/g' /home/httpd/ajax_obj/js/qnapui.js 2>/dev/null
/bin/sed -i 's/\/nssindex.html/\/cgi-bin\/camera_view.cgi/g' /home/httpd/cgi-bin/html/login.html 2>/dev/null
/bin/sed -i 's/\/nssindex.html/\/cgi-bin\/camera_view.cgi/g' /home/httpd/cgi-bin/html/login_2.html 2>/dev/null
fi
if [ "$SUPPORT_NVR" == "yes" ]; then
/bin/mkdir /play
for i in 1 2 3 4 5 6 7 8
do
/bin/mkdir /play/ch$i
/bin/mkdir /play/ch$i/record_nvr
/bin/ln -s $NVR_ROOTFS/data/record_nvr/channel$i /play/ch$i/record_nvr/channel$i
/bin/mkdir /play/ch$i/record_nvr_unk
/bin/ln -s $NVR_ROOTFS/data/record_nvr_unk/channel$i $/play/ch$i/record_nvr_unk/channel$i
/bin/mkdir /play/ch$i/record_nvr_alarm
/bin/ln -s $NVR_ROOTFS/data/record_nvr_alarm/channel$i /play/ch$i/record_nvr_alarm/channel$i
done
#ln -s $NVR_ROOTFS/data /data
#ln -s /data /home/httpd/record
#ln -s /data /home/httpd/cgi-bin/record
if [ -e /home/httpd/cgi-bin/record ]; then
/bin/rm /home/httpd/cgi-bin/record
fi
/bin/ln -s $NVR_ROOTFS/share/$RecordingsShare /home/httpd/cgi-bin/record
if [ -e /home/httpd/record ]; then
/bin/rm /home/httpd/record
fi
/bin/ln -s $NVR_ROOTFS/share/$RecordingsShare /home/httpd/record
if [ ! -e /etc/config/nvrd.xml ]; then
/bin/cp -a /etc/default_config/nvrd.xml /etc/config/
fi
if [ ! -e /etc/config/nvrstat.xml ]; then
/bin/cp -a /etc/default_config/nvrstat.xml /etc/config/
fi
if [ ! -e /var/.nvr_quota_info ]; then
/bin/mkdir /var/.nvr_quota_info
fi
if [ -e /share/$RecordingsShare/record_nvr_tmp ]; then
/bin/rm -rf /share/$RecordingsShare/record_nvr_tmp
fi
if [ -e /share/$RecordingsShare/record_nvr_unk ]; then
/bin/rm -rf /share/$RecordingsShare/record_nvr_unk
fi
if [ -e /share/$RecordingsShare/record_nvr_pre ]; then
/bin/rm -rf /share/$RecordingsShare/record_nvr_pre
fi
/usr/bin/qcmd XMLCR
/usr/bin/qcmd umsid_info
/usr/bin/qcmd DUSG
fi
}
HIDDEN_CONF_FILE=/mnt/HDA_ROOT/.conf
NVR_HIDDEN_LOG_DIR=/mnt/HDA_ROOT/.sqdatabase
NVR_VS_LOG_ROOT_DIR=/home/sqdatabase
NVR_VS_LOG_DIR=$NVR_ROOTFS$NVR_VS_LOG_ROOT_DIR
NVR_LOG_DATABASE=nvrevent.db
NVR_ORG_LOG_DATABASE=.nvrevent.db
create_nvr_log_database()
{
# create nvr log symbolic link
if [ "$SUPPORT_NVR" == "yes" ]; then
if [ -f $HIDDEN_CONF_FILE ]; then
#check log dir
if [ ! -d $NVR_HIDDEN_LOG_DIR ]; then
echo $NVR_HIDDEN_LOG_DIR not create, create $NVR_HIDDEN_LOG_DIR... [OK]
/bin/mkdir -p $NVR_HIDDEN_LOG_DIR
fi
# create NVR_VS_LOG_DIR
if [ ! -f $NVR_HIDDEN_LOG_DIR/$NVR_LOG_DATABASE ]; then
echo sqdatabase file not found, create symboloc link $NVR_VS_LOG_DIR... [OK]
/bin/cp $NVR_VS_LOG_DIR/$NVR_ORG_LOG_DATABASE $NVR_HIDDEN_LOG_DIR/$NVR_LOG_DATABASE
/bin/rm -rf $NVR_VS_LOG_DIR
/bin/ln -sf $NVR_HIDDEN_LOG_DIR $NVR_VS_LOG_DIR
else
# NVR_VS_LOG_DIR link not exist
echo log hidden config directory exist, create symboloc link $NVR_VS_LOG_DIR... [OK]
/bin/rm -rf $NVR_VS_LOG_DIR
/bin/ln -sf $NVR_HIDDEN_LOG_DIR $NVR_VS_LOG_DIR
fi
else
/bin/mv $NVR_VS_LOG_DIR/$NVR_ORG_LOG_DATABASE $NVR_VS_LOG_DIR/$NVR_LOG_DATABASE
echo check no HD exist... [OK]
fi
if [ "$NVR_ROOTFS" != "" ]; then
if [ ! -e $NVR_VS_LOG_ROOT_DIR ]; then
/bin/rm -rf $NVR_VS_LOG_ROOT_DIR
/bin/ln -s $NVR_VS_LOG_DIR $NVR_VS_LOG_ROOT_DIR
fi
fi
fi
}
case "$1" in
init)
touch /home/httpd/cgi-bin/http_stream_start.cgi
touch /home/httpd/cgi-bin/http_stream_stop.cgi
chmod +x /home/httpd/cgi-bin/http_stream_start.cgi
chmod +x /home/httpd/cgi-bin/http_stream_stop.cgi
[ -f /usr/bin/nvrd ] && create_nvr_log_database
;;
start)
# only mount if no previous mount
APP_RUNTIME_CONF="/var/.application.conf"
NSS_Hide=`/sbin/getcfg DISABLE survielance -d 0 -f $APP_RUNTIME_CONF`
if [ "x$NSS_Hide" = "x1" ]; then
/sbin/setcfg NVR Enable FALSE
fi
if [ `/sbin/getcfg NVR Enable -u -d FALSE` = TRUE ]; then
# dont't do reentry control here!, do it in nvrd
[ -f /usr/bin/nvrd ] || init_nvrd
/usr/bin/qcmd XMLCR
/usr/bin/sysadm init
/usr/bin/sysadm start
create_nvr_log_database
echo -n "Starting nvrd services:"
/bin/kill -HUP `pidof proftpd`
/bin/touch /tmp/.nvrd_alive
/sbin/daemon_mgr.nvr evtLogd start "/usr/bin/evtLogd"
/sbin/daemon_mgr.nvr nvrd start "/usr/bin/nvrd 2>/dev/null"
/sbin/daemon_mgr.nvr qplayd start "/usr/bin/qplayd 2>/dev/null"
# start http streaming here
count=30;
while [ $count -gt 0 ]; do
${WGET} -4 -N http://127.0.0.1:`/sbin/getcfg System "Web Access Port" -d 8080`/cgi-bin/http_stream_start.cgi >& /dev/null
if [ -e /home/httpd/cgi-bin/getstream.cgi ]; then
count=0
else
/bin/sleep 1
count=$(($count-1));
fi
done
echo -n " nvrd"
echo "."
fi
/etc/init.d/refresh_nvr_crontab.sh
/etc/init.d/ftp.sh reconfig
;;
stop)
echo -n "Shutting down nvrd services:"
# stop http streaming here
count=30;
while [ $count -gt 0 ]; do
${WGET} -4 -N http://127.0.0.1:`/sbin/getcfg System "Web Access Port" -d 8080`/cgi-bin/http_stream_stop.cgi >& /dev/null
if [ -e /home/httpd/cgi-bin/getstream.cgi ]; then
/bin/sleep 1
count=$(($count-1));
else
count=0
fi
done
/sbin/daemon_mgr.nvr qplayd stop /usr/bin/qplayd
/sbin/daemon_mgr.nvr nvrd stop /usr/bin/nvrd
echo -n " nvrd"
echo "."
count=30;
while [ $count -gt 0 ] && [ "`pidof nvrd`" != "" ]; do
/bin/sleep 1
count=$(($count-1));
done
if [ $count -gt 0 ]; then
/bin/kill -9 `pidof nvrd` > /dev/null 2> /dev/null
fi
/sbin/daemon_mgr.nvr evtLogd stop /usr/bin/evtLogd
if [ "`pidof evtLogd`" != "" ]; then
/bin/kill -9 `pidof evtLogd` > /dev/null 2> /dev/null
fi
/etc/init.d/refresh_nvr_crontab.sh
/usr/bin/sysadm stop
/usr/bin/sysadm uninit
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/nvrd {start|stop|restart}"
exit 1
esac
exit 0

257
nvrd.sh_bak Executable file
View File

@@ -0,0 +1,257 @@
#!/bin/sh
# For Administration
INSTALL_FLAG_FILE=/tmp/check_install.flag
if [ -f $INSTALL_FLAG_FILE ] ; then
INSTALLING=`/bin/cat $INSTALL_FLAG_FILE`
[ x"$INSTALLING" != x"1" ] || exit 0
fi
NVR_ROOTFS=
export NVR_ROOTFS
RecordingsShare=`/sbin/getcfg SHARE_DEF defRecordings -d Qrecordings -f /etc/config/def_share.info`
ROOTFS=$NVR_ROOTFS
WGET=/usr/bin/wget-s
[ -x ${WGET} ] || WGET=/usr/bin/wget
# Set some defaults
MNT_POINT="/mnt/ext"
NVR_SOURCE="${MNT_POINT}/opt/source/nvr_app.tar.gz"
NVR_DIR="/"
ROOT_PART="/mnt/HDA_ROOT"
UPDATEPKG_DIR="${ROOT_PART}/update_pkg"
if [ "`/sbin/getcfg -f /etc/default_config/uLinux.conf NVR Support -d FALSE`" == "TRUE" ]; then
SUPPORT_NVR=yes
else
SUPPORT_NVR=no
fi
init_nvrd()
{
if [ ! -f /usr/bin/nvrd ]; then
_nvr_target=/mnt/ext/opt/nvr
_nvr_create_link=0
if [ -f ${NVR_SOURCE} ]; then
/bin/rm -rf /usr/msb 2>/dev/null; mkdir /usr/msb
cd /
/bin/tar zxf ${NVR_SOURCE} --exclude *.cab
[ -d /mnt/ext/opt/nvr ] || /bin/mkdir -p ${_nvr_target}
/bin/tar zxvf ${NVR_SOURCE} -C /mnt/ext/opt/nvr --wildcards *.cab
_nvr_create_link=1
elif [ -f ${UPDATEPKG_DIR}/nvr_app.tar.gz ]; then
/bin/rm -rf /usr/msb 2>/dev/null; mkdir /usr/msb
cd /
/bin/tar zxf ${UPDATEPKG_DIR}/nvr_app.tar.gz --exclude *.cab
[ -d /mnt/ext/opt/nvr ] || /bin/mkdir -p ${_nvr_target}
/bin/tar zxvf ${UPDATEPKG_DIR}/nvr_app.tar.gz -C /mnt/ext/opt/nvr --wildcards *.cab
_nvr_create_link=1
fi
if [ "x${_nvr_create_link}" = "x1" ]; then
/bin/rm -f /home/httpd/cgi-bin/NNVRVMon.cab 2>/dev/null
/bin/rm -f /home/httpd/cgi-bin/QNAP*.cab 2>/dev/null
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/NNVRVMon.cab /home/httpd/cgi-bin/NNVRVMon.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPG726.cab /home/httpd/cgi-bin/QNAPG726.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQ264.cab /home/httpd/cgi-bin/QNAPQ264.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQIVG.cab /home/httpd/cgi-bin/QNAPQIVG.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQMP4.cab /home/httpd/cgi-bin/QNAPQMP4.cab
/bin/ln -sf ${_nvr_target}/home/httpd/cgi-bin/QNAPQVivoTek.cab /home/httpd/cgi-bin/QNAPQVivoTek.cab
fi
[ ! -f /home/httpd/ajax_obj/js/qnapui.js_bak ] || /bin/cp /home/httpd/ajax_obj/js/qnapui.js_bak /home/httpd/ajax_obj/js/qnapui.js
[ ! -f /home/httpd/cgi-bin/html/login.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login.html_bak /home/httpd/cgi-bin/html/login.html
[ ! -f /home/httpd/cgi-bin/html/login_2.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login_2.html_bak /home/httpd/cgi-bin/html/login_2.html
fi
if [ -f /home/httpd/ajax_obj/js/qnapui.js ] && [ -f /home/httpd/cgi-bin/html/login.html ]; then
[ -f /home/httpd/ajax_obj/js/qnapui.js_bak ] || /bin/cp /home/httpd/ajax_obj/js/qnapui.js /home/httpd/ajax_obj/js/qnapui.js_bak
[ -f /home/httpd/cgi-bin/html/login.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login.html /home/httpd/cgi-bin/html/login.html_bak
[ -f /home/httpd/cgi-bin/html/login_2.html_bak ] || /bin/cp /home/httpd/cgi-bin/html/login_2.html /home/httpd/cgi-bin/html/login_2.html_bak
/bin/sed -i 's/\/nssindex.html/\/cgi-bin\/camera_view.cgi/g' /home/httpd/ajax_obj/js/qnapui.js 2>/dev/null
/bin/sed -i 's/\/nssindex.html/\/cgi-bin\/camera_view.cgi/g' /home/httpd/cgi-bin/html/login.html 2>/dev/null
/bin/sed -i 's/\/nssindex.html/\/cgi-bin\/camera_view.cgi/g' /home/httpd/cgi-bin/html/login_2.html 2>/dev/null
fi
if [ "$SUPPORT_NVR" == "yes" ]; then
/bin/mkdir /play
for i in 1 2 3 4 5 6 7 8
do
/bin/mkdir /play/ch$i
/bin/mkdir /play/ch$i/record_nvr
/bin/ln -s $NVR_ROOTFS/data/record_nvr/channel$i /play/ch$i/record_nvr/channel$i
/bin/mkdir /play/ch$i/record_nvr_unk
/bin/ln -s $NVR_ROOTFS/data/record_nvr_unk/channel$i $/play/ch$i/record_nvr_unk/channel$i
/bin/mkdir /play/ch$i/record_nvr_alarm
/bin/ln -s $NVR_ROOTFS/data/record_nvr_alarm/channel$i /play/ch$i/record_nvr_alarm/channel$i
done
#ln -s $NVR_ROOTFS/data /data
#ln -s /data /home/httpd/record
#ln -s /data /home/httpd/cgi-bin/record
if [ -e /home/httpd/cgi-bin/record ]; then
/bin/rm /home/httpd/cgi-bin/record
fi
/bin/ln -s $NVR_ROOTFS/share/$RecordingsShare /home/httpd/cgi-bin/record
if [ -e /home/httpd/record ]; then
/bin/rm /home/httpd/record
fi
/bin/ln -s $NVR_ROOTFS/share/$RecordingsShare /home/httpd/record
if [ ! -e /etc/config/nvrd.xml ]; then
/bin/cp -a /etc/default_config/nvrd.xml /etc/config/
fi
if [ ! -e /etc/config/nvrstat.xml ]; then
/bin/cp -a /etc/default_config/nvrstat.xml /etc/config/
fi
if [ ! -e /var/.nvr_quota_info ]; then
/bin/mkdir /var/.nvr_quota_info
fi
if [ -e /share/$RecordingsShare/record_nvr_tmp ]; then
/bin/rm -rf /share/$RecordingsShare/record_nvr_tmp
fi
if [ -e /share/$RecordingsShare/record_nvr_unk ]; then
/bin/rm -rf /share/$RecordingsShare/record_nvr_unk
fi
if [ -e /share/$RecordingsShare/record_nvr_pre ]; then
/bin/rm -rf /share/$RecordingsShare/record_nvr_pre
fi
/usr/bin/qcmd XMLCR
/usr/bin/qcmd umsid_info
/usr/bin/qcmd DUSG
fi
}
HIDDEN_CONF_FILE=/mnt/HDA_ROOT/.conf
NVR_HIDDEN_LOG_DIR=/mnt/HDA_ROOT/.sqdatabase
NVR_VS_LOG_ROOT_DIR=/home/sqdatabase
NVR_VS_LOG_DIR=$NVR_ROOTFS$NVR_VS_LOG_ROOT_DIR
NVR_LOG_DATABASE=nvrevent.db
NVR_ORG_LOG_DATABASE=.nvrevent.db
create_nvr_log_database()
{
# create nvr log symbolic link
if [ "$SUPPORT_NVR" == "yes" ]; then
if [ -f $HIDDEN_CONF_FILE ]; then
#check log dir
if [ ! -d $NVR_HIDDEN_LOG_DIR ]; then
echo $NVR_HIDDEN_LOG_DIR not create, create $NVR_HIDDEN_LOG_DIR... [OK]
/bin/mkdir -p $NVR_HIDDEN_LOG_DIR
fi
# create NVR_VS_LOG_DIR
if [ ! -f $NVR_HIDDEN_LOG_DIR/$NVR_LOG_DATABASE ]; then
echo sqdatabase file not found, create symboloc link $NVR_VS_LOG_DIR... [OK]
/bin/cp $NVR_VS_LOG_DIR/$NVR_ORG_LOG_DATABASE $NVR_HIDDEN_LOG_DIR/$NVR_LOG_DATABASE
/bin/rm -rf $NVR_VS_LOG_DIR
/bin/ln -sf $NVR_HIDDEN_LOG_DIR $NVR_VS_LOG_DIR
else
# NVR_VS_LOG_DIR link not exist
echo log hidden config directory exist, create symboloc link $NVR_VS_LOG_DIR... [OK]
/bin/rm -rf $NVR_VS_LOG_DIR
/bin/ln -sf $NVR_HIDDEN_LOG_DIR $NVR_VS_LOG_DIR
fi
else
/bin/mv $NVR_VS_LOG_DIR/$NVR_ORG_LOG_DATABASE $NVR_VS_LOG_DIR/$NVR_LOG_DATABASE
echo check no HD exist... [OK]
fi
if [ "$NVR_ROOTFS" != "" ]; then
if [ ! -e $NVR_VS_LOG_ROOT_DIR ]; then
/bin/rm -rf $NVR_VS_LOG_ROOT_DIR
/bin/ln -s $NVR_VS_LOG_DIR $NVR_VS_LOG_ROOT_DIR
fi
fi
fi
}
case "$1" in
init)
touch /home/httpd/cgi-bin/http_stream_start.cgi
touch /home/httpd/cgi-bin/http_stream_stop.cgi
chmod +x /home/httpd/cgi-bin/http_stream_start.cgi
chmod +x /home/httpd/cgi-bin/http_stream_stop.cgi
[ -f /usr/bin/nvrd ] && create_nvr_log_database
;;
start)
# only mount if no previous mount
APP_RUNTIME_CONF="/var/.application.conf"
NSS_Hide=`/sbin/getcfg DISABLE survielance -d 0 -f $APP_RUNTIME_CONF`
if [ "x$NSS_Hide" = "x1" ]; then
/sbin/setcfg NVR Enable FALSE
fi
if [ `/sbin/getcfg NVR Enable -u -d FALSE` = TRUE ]; then
# dont't do reentry control here!, do it in nvrd
[ -f /usr/bin/nvrd ] || init_nvrd
/usr/bin/qcmd XMLCR
/usr/bin/sysadm init
/usr/bin/sysadm start
create_nvr_log_database
echo -n "Starting nvrd services:"
/bin/kill -HUP `pidof proftpd`
/bin/touch /tmp/.nvrd_alive
/sbin/daemon_mgr.nvr evtLogd start "/usr/bin/evtLogd"
/sbin/daemon_mgr.nvr nvrd start "/usr/bin/nvrd 2>/dev/null"
/sbin/daemon_mgr.nvr qplayd start "/usr/bin/qplayd 2>/dev/null"
# start http streaming here
count=30;
while [ $count -gt 0 ]; do
${WGET} -4 -N http://127.0.0.1:`/sbin/getcfg System "Web Access Port" -d 8080`/cgi-bin/http_stream_start.cgi >& /dev/null
if [ -e /home/httpd/cgi-bin/getstream.cgi ]; then
count=0
else
/bin/sleep 1
count=$(($count-1));
fi
done
echo -n " nvrd"
echo "."
fi
/etc/init.d/refresh_nvr_crontab.sh
/etc/init.d/ftp.sh reconfig
;;
stop)
echo -n "Shutting down nvrd services:"
# stop http streaming here
count=30;
while [ $count -gt 0 ]; do
${WGET} -4 -N http://127.0.0.1:`/sbin/getcfg System "Web Access Port" -d 8080`/cgi-bin/http_stream_stop.cgi >& /dev/null
if [ -e /home/httpd/cgi-bin/getstream.cgi ]; then
/bin/sleep 1
count=$(($count-1));
else
count=0
fi
done
/sbin/daemon_mgr.nvr qplayd stop /usr/bin/qplayd
/sbin/daemon_mgr.nvr nvrd stop /usr/bin/nvrd
echo -n " nvrd"
echo "."
count=30;
while [ $count -gt 0 ] && [ "`pidof nvrd`" != "" ]; do
/bin/sleep 1
count=$(($count-1));
done
if [ $count -gt 0 ]; then
/bin/kill -9 `pidof nvrd` > /dev/null 2> /dev/null
fi
/sbin/daemon_mgr.nvr evtLogd stop /usr/bin/evtLogd
if [ "`pidof evtLogd`" != "" ]; then
/bin/kill -9 `pidof evtLogd` > /dev/null 2> /dev/null
fi
/etc/init.d/refresh_nvr_crontab.sh
/usr/bin/sysadm stop
/usr/bin/sysadm uninit
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/nvrd {start|stop|restart}"
exit 1
esac
exit 0

30
openssl_signature.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/bin/sh
OPENSSL="/usr/bin/openssl"
case "$1" in
sign)
$OPENSSL dgst -sha1 < $2 > /tmp/hash
$OPENSSL rsautl -sign -inkey $4 -keyform PEM -in hash > $3
exit 0
;;
verify)
hash=`$OPENSSL dgst -sha1 < $2`
verified=`$OPENSSL rsautl -verify -inkey $4 -keyform PEM -certin -in $3`
if [ "${verified}" = "${hash}" ]; then
echo "Verified"
exit 0
else
echo "Invalid"
exit 1
fi
;;
*)
echo "Usage: openssl_signature {sign|verify}\n"
echo "sign: openssl_signature sign [file path] [signature path] [private key] "
echo "verify: openssl_signature verify [file path] [signature path] [public key] "
exit 1
;;
esac
exit 0

92
opentftp.sh Executable file
View File

@@ -0,0 +1,92 @@
#!/bin/sh
pidnum=`/bin/pidof opentftpd`
TFTP_ENABLE=`/sbin/getcfg "TFTP Server" "Enable" -d FALSE`
if [ "${TFTP_ENABLE}" = "FALSE" ]; then
/sbin/setcfg "TFTP Server" "Enable" "FALSE"
/sbin/setcfg "TFTP Server" "PORT" "69"
/sbin/setcfg "TFTP Server" "Root Folder" "Public"
/sbin/setcfg "TFTP Server" "Root Subfolder" ""
/sbin/setcfg "TFTP Server" "Log Folder" "Public"
/sbin/setcfg "TFTP Server" "Log Subfolder" ""
/sbin/setcfg "TFTP Server" "Allowed mode" "0"
fi
# Start opentftp:
opentftpd_start() {
##### Modify line below for location of executive and other files #####
/usr/sbin/create_tftpd_conf > /dev/null
TFTP_LOG=`/sbin/getcfg "TFTP Server" "Save Log" -d 0`
if [ "x${TFTP_LOG}" = "x1" ]; then
TFTP_SHARE_FOLDER=`/sbin/getcfg "TFTP Server" "Log Folder" -d "Public"`
TFTP_LOG_FOLDER=`/sbin/getcfg "${TFTP_SHARE_FOLDER}" "path" -f /etc/config/smb.conf`
TFTP_SUB_FOLDER=`/sbin/getcfg "TFTP Server" "Log Subfolder" -d ""`
/usr/sbin/opentftpd -i /etc/opentftpd.ini -l ${TFTP_LOG_FOLDER}/${TFTP_SUB_FOLDER}/opentftpd.log
else
/usr/sbin/opentftpd -i /etc/opentftpd.ini
fi
echo "Server opentftpd started"
}
# Stop opentftp:
opentftpd_stop() {
kill $pidnum
i=0
while [ ${i} -lt 5 ]
do
pidnum=`/bin/pidof opentftpd`
if [ -z "$pidnum" ]; then
break
fi
sleep 1
i=`/usr/bin/expr ${i} + 1`
done
pidnum=`/bin/pidof opentftpd`
[ -z "$pidnum" ] || kill -9 $pidnum
echo "Server opentftp stopped"
}
case "$1" in
'start')
if [ -z "$pidnum" ]; then
opentftpd_start
RETVAL=0
else
echo "Server opentftp is already running - Try restart"
RETVAL=1
fi
;;
'stop')
if [ -z "$pidnum" ]; then
RETVAL=1
else
opentftpd_stop
RETVAL=0
fi
;;
'restart')
if [ -z "$pidnum" ]; then
echo "Server opentftp is not running"
opentftpd_start
else
opentftpd_stop
opentftpd_start
fi
RETVAL=0
;;
'status')
if [ -z "$pidnum" ]; then
echo "Server opentftp is not running"
RETVAL=1
else
echo "Server opentftp is running - Pid : $pidnum"
RETVAL=0
fi
;;
*)
echo "Usage $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL
# Enjoy!

66
photo_scand.sh Executable file
View File

@@ -0,0 +1,66 @@
#!/bin/sh
PHOTO_SCAND=photo_scand
PHOTO_SCAND_CMD="/sbin/photo_scand"
INOTIFYWAIT=/usr/sbin/inotifywait
lock_time=0
MultimediaShare=`/sbin/getcfg SHARE_DEF defMultimedia -d Qmultimedia -f /etc/config/def_share.info`
_lock()
{
if [ -f /var/lock/NAS/photo_scan.record.lck ]; then
if [ "$lock_time" != "0" ]; then
now=`date +%s`
wait=`expr $now - $lock_time`
if [ "$wait" -gt 10 ]; then
lock_time=0
/bin/rm -f /var/lock/NAS/photo_scan.record.lck
echo "unlock"
return 0
fi
fi
lock_time=`date +%s`
return 1
else
lock_time=0
return 0
fi
}
# start photo scand
/bin/touch /mnt/HDA_ROOT/photo_scan.record
/bin/chown httpdusr /mnt/HDA_ROOT/photo_scan.record
/bin/chmod 666 /mnt/HDA_ROOT/photo_scan.record
/sbin/daemon_mgr $PHOTO_SCAND stop "/sbin/photo_scand"
sleep 1
/sbin/daemon_mgr $PHOTO_SCAND start "/sbin/photo_scand&"
$INOTIFYWAIT -m "/share/${MultimediaShare}" -r -e moved_to -e close_write --format "%w%f" --exclude "Network Trash Folder|.@__thumb|Temporary Items" | while read line
do
folder=`dirname "${line}"`
type=${line##*.}
found_img=1
if [ "$folder" == "/share/${MultimediaShare}" ]; then
##echo "folder= $folder ignore"
continue
fi
case "${type}" in
"PNG" | "png" | "GIF" | "gif" )
;;
"jpg" | "JPG" | "bmp" | "BMP" )
;;
*)
found_img=0
;;
esac
if [ $found_img == 1 ]; then
_lock
if [ $? == 1 ]; then
continue
fi
##echo "found img folder=$folder type=$type"
echo "${folder}" >> /mnt/HDA_ROOT/photo_scan.record
kill -s USR1 `pidof $PHOTO_SCAND`
fi
done

27
power_button.sh Executable file
View File

@@ -0,0 +1,27 @@
#This script is for pressing power button
#!/bin/sh
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
/sbin/hal_app --power_led_blink enc_id=0,enable=1
else
Internal_Model=`/sbin/getcfg System "Internal Model"`
if [ "x$Internal_Model" = "xTS-609" ] || [ "x$Internal_Model" = "xTS-239" ] || [ "x$Internal_Model" = "xTS-439" ] || [ "x$Internal_Model" = "xTS-639" ] || [ "x$Internal_Model" = "xTS-839" ] || [ "x$Internal_Model" = "xTS-259" ] || [ "x$Internal_Model" = "xTS-459" ] || [ "x$Internal_Model" = "xTS-559" ]|| [ "x$Internal_Model" = "xTS-659" ] || [ "x$Internal_Model" = "xTS-859" ] || [ "x$Internal_Model" = "xTS-1279" ] || [ "x$Internal_Model" = "xTS-879" ] || [ "x$Internal_Model" = "xTS-1079" ] || [ "x$Internal_Model" = "xTS-469" ] || [ "x$Internal_Model" = "xTS-569" ] || [ "x$Internal_Model" = "xTS-669" ] || [ "x$Internal_Model" = "xTS-869" ]; then
# power LED blinking
/sbin/pic_raw 76
fi
fi
if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
if [ -x /sbin/hal_app ]; then
/sbin/hal_app --se_sys_set_pic_wdt enc_sys_id=root,mode=2
else
/sbin/pic_raw 105 #enable pic watch dog timer 5 min,power-off
fi
fi
/sbin/poweroff
[ -f /sbin/lcd_tool ] && /sbin/lcd_tool -s 3

11
poweroff Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/sh
if [ -x /sbin/storage_util ];then
/sbin/storage_util --shutdown_check
if [ $? -eq 0 ];then
/sbin/log_tool -t 1 -a "Auto shutdown was canceled because one volume was busy"
exit 0
fi
fi
. /etc/init.d/wait_RR
echo shutdown start...
/sbin/poweroff

56
printer.sh Executable file
View File

@@ -0,0 +1,56 @@
#!/bin/sh
#
# Copyright @ 2005 QNAP Systems Inc.
#
# network This script start/stop/restart network.
#
# Version 1.0.0
#
# Author Ricky Chen
LPD_LOCK="/var/spool/lpd"
LPD_SPOOL="/var/spool/smb"
LPD_SPOOL2="/var/spool/smb/2"
LPD_SPOOL3="/var/spool/smb/3"
LPD_SPOOL4="/var/spool/smb/4"
LPD_SPOOL5="/var/spool/smb/5"
LPD_SPOOL6="/var/spool/smb/6"
LPD_SPOOL7="/var/spool/smb/7"
start(){
[ -d ${LPD_LOCK} ] || mkdir -p ${LPD_LOCK}
[ -d ${LPD_SPOOL} ] || mkdir -p ${LPD_SPOOL}
[ -d ${LPD_SPOOL2} ] || mkdir -p ${LPD_SPOOL2}
[ -d ${LPD_SPOOL3} ] || mkdir -p ${LPD_SPOOL3}
[ -d ${LPD_SPOOL4} ] || mkdir -p ${LPD_SPOOL4}
[ -d ${LPD_SPOOL5} ] || mkdir -p ${LPD_SPOOL5}
[ -d ${LPD_SPOOL6} ] || mkdir -p ${LPD_SPOOL6}
[ -d ${LPD_SPOOL7} ] || mkdir -p ${LPD_SPOOL7}
chmod 777 ${LPD_SPOOL}
chmod 777 ${LPD_SPOOL2}
chmod 777 ${LPD_SPOOL3}
chmod 777 ${LPD_SPOOL4}
chmod 777 ${LPD_SPOOL5}
chmod 777 ${LPD_SPOOL6}
chmod 777 ${LPD_SPOOL7}
}
case "$1" in
start)
start
;;
stop)
;;
restart)
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

29
qplayd.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/sh
# For Administration
test -f /usr/bin/qplayd || exit 0
case "$1" in
start)
# dont't do reentry control here!, do it in qplayd
echo -n "Starting qplayd services:"
/sbin/daemon_mgr.nvr qplayd start "/usr/bin/qplayd 2>/dev/null"
echo -n " qplayd"
echo "."
;;
stop)
echo -n "Shutting down qplayd services:"
/sbin/daemon_mgr.nvr qplayd stop /usr/bin/qplayd
echo -n " qplayd"
echo "."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/qplayd {start|stop|restart}"
exit 1
esac
exit 0

10
qraid1.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
/sbin/getcfg "QRAID1" "device name" > /dev/null
result=$?
if [ $result -eq 0 ]
then
[ -f /sbin/gpiod ] && /bin/kill -USR1 `pidof gpiod`
fi

48
qsyncman.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/sh
start()
{
if [ -f /usr/bin/qsyncman ]; then
echo "Remove old configuration files"
[ ! -f /etc/config/hdcopyusb.conf ] || /bin/rm -f /etc/config/hdcopyusb.conf
/bin/sed -i '/hdusb_copy/d' /etc/config/crontab
/usr/bin/crontab /etc/config/crontab
echo "Starting QSync manitor: qsyncman..."
[ -d /etc/config/qsync ] || /usr/bin/install -d /etc/config/qsync
[ -f /etc/config/qsync/qhost.conf ] || /bin/touch /etc/config/qsync/qhost.conf
[ -f /etc/config/qsync/qsyncjobdef.conf ] || /bin/touch /etc/config/qsync/qsyncjobdef.conf
[ -f /etc/config/qsync/qsync.conf ] || /bin/cp -p /etc/default_config/qsync/qsync.conf /etc/config/qsync/qsync.conf
[ -f /etc/config/qsync/extdrv.conf ] || /bin/cp -p /etc/default_config/qsync/extdrv.conf /etc/config/qsync/extdrv.conf
[ -f /etc/config/qsync/qsyncd.conf ] || /bin/cp -p /etc/default_config/qsync/qsyncd.conf /etc/config/qsync/qsyncd.conf
/usr/bin/qsyncman
fi
}
stop()
{
echo "Shutting down QSync manitor: qsyncman..."
/usr/bin/killall -q qsyncman
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
*)
echo "Usage: /etc/init.d/qsyncman.sh {start|stop|restart}"
exit 1
esac
exit 0

86
radius.sh Executable file
View File

@@ -0,0 +1,86 @@
#!/bin/sh
# For radius
[ ! -f "/etc/config/radius_global.conf" ] && /bin/touch "/etc/config/radius_global.conf"
init_conf()
{
if [ ! -f /sbin/radius_util ]; then
/bin/echo "/sbin/radius_util is not exit."
exit 1
fi
if [ -d /etc/raddb/log ]; then
/bin/rm -rf /etc/raddb/log/*
/bin/touch /etc/raddb/log/radutmp
else
/bin/mkdir -p /etc/raddb/log
/bin/touch /etc/raddb/log/radutmp
fi
/sbin/radius_util init
}
start()
{
if [ ! -f /usr/local/sbin/radiusd ]; then
/bin/echo "radiusd is not exit."
exit 1
fi
if [ -f /var/run/radiusd.pid ]; then
/bin/echo "radiusd is aleady run."
exit 1
fi
if [ `/sbin/getcfg "Global" "Enable" -u -d "FALSE" -f "/etc/config/radius_global.conf"` = "TRUE" ]; then
/bin/echo "radiusd start."
init_conf
# /usr/local/sbin/radiusd -d /etc/raddb
/sbin/daemon_mgr radiusd start "/usr/local/sbin/radiusd -d /etc/raddb"
else
/bin/echo "radiusd is disabled."
fi
}
stop()
{
/bin/echo "radiusd stop."
/sbin/daemon_mgr radiusd stop "/usr/local/sbin/radiusd -d /etc/raddb"
/bin/kill -9 `/bin/cat /var/run/radiusd.pid` 1>>/dev/null 2>&1
/bin/rm -f /var/run/radiusd.pid 1>>/dev/null 2>&1
}
reload()
{
/bin/echo "radiusd reload."
init_conf
if [ -f /var/run/radiusd.pid ]; then
/bin/kill -HUP `/bin/cat /var/run/radiusd.pid`
else
/bin/kill -HUP `/bin/pidof radiusd`
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
/bin/sleep 3
start
;;
reload)
reload
;;
*)
echo "Usage: /etc/init.d/$0 {start|stop|restart|reload}"
exit 1
esac
exit 0

148
radvd.sh Executable file
View File

@@ -0,0 +1,148 @@
#!/bin/sh
# Copyright @ 2009 QNAP Systems Inc.
GETCFG="/sbin/getcfg"
SETCFG="/sbin/setcfg"
DAEMON_MGR="/sbin/daemon_mgr"
IPV6=`$GETCFG "Network" "IPV6" -u -d "FALSE"`
BOND_SUP=`$GETCFG "Network" "BONDING Support" -u -d "FALSE"`
RA_INTERFACE=`$GETCFG "Network" "RA_INTERFACE" -d "eth0"`
BOND_NIC=`$GETCFG "Network" "BONDING NICs" -d "0"`
NIC_NUM=`$GETCFG "Network" "Interface Number" -d "1"`
ADV_BOND_SUPPORT=`$GETCFG "Network" "Advanced Bonding Support" -d "FALSE"`
GROUP_NUM=`$GETCFG "Network Group" "Group Count" -d $NIC_NUM`
BOND_NUM=`/usr/bin/expr ${NIC_NUM} / 2`
if [ "x$ADV_BOND_SUPPORT" = "xTRUE" ]; then
for (( i=0; i<$GROUP_NUM; i=i+1 ))
do
net_interface=`$GETCFG "Network Group" "Group $i" -d ""`
if [ "x${net_interface}" != "x" ]; then
/bin/echo "${net_interface}" | /bin/grep "^eth" &>/dev/null
if [ $? = 0 ]; then #eth
/bin/echo "${net_interface}" | /bin/grep "^eth0" &>/dev/null
if [ $? = 0 ]; then
RA_INTERFACE="${net_interface}"
break;
fi
else #bond
bond_member=`$GETCFG "${net_interface}" "Bonding Member" -d ""`
/bin/echo "${bond_member}" | /bin/grep "0" &>/dev/null
if [ $? = 0 ]; then
RA_INTERFACE="${net_interface}"
break;
fi
fi
fi
done
else
if [ "$BOND_SUP" = "TRUE" ]; then
RA_INTERFACE=bond0
fi
if [ "$BOND_NIC" = 1 ]; then
RA_INTERFACE=eth0
fi
fi
PREFIX=`$GETCFG $RA_INTERFACE "RA_PREFIX" -d "2002:509:1F00:168::/64"`
RADVD_CONF="/etc/radvd.conf"
GATEWAY=`$GETCFG $RA_INTERFACE "IPV6 Gateway" -d "::/0"`
gen_radvd_conf()
{
/bin/echo "interface $RA_INTERFACE" > "$RADVD_CONF"
/bin/echo "{" >> "$RADVD_CONF"
/bin/echo " AdvSendAdvert on;" >> "$RADVD_CONF"
/bin/echo " MaxRtrAdvInterval 300;" >> "$RADVD_CONF"
/bin/echo " prefix $PREFIX" >> "$RADVD_CONF"
/bin/echo " {" >> "$RADVD_CONF"
/bin/echo " AdvOnLink on;" >> "$RADVD_CONF"
/bin/echo " AdvAutonomous on;" >> "$RADVD_CONF"
/bin/echo " AdvRouterAddr on;" >> "$RADVD_CONF"
/bin/echo " };" >> "$RADVD_CONF"
/bin/echo " route $GATEWAY" >> "$RADVD_CONF"
/bin/echo " {" >> "$RADVD_CONF"
/bin/echo " };" >> "$RADVD_CONF"
/bin/echo "};" >> "$RADVD_CONF"
}
start()
{
[ "$IPV6" = "TRUE" ] || exit 1
[ `/bin/cat /sys/class/net/$RA_INTERFACE/operstate 2>>/dev/null` = "up" ] || return 1;
if [ `$GETCFG $RA_INTERFACE "Use RADVD" -u -d "FALSE"` = "TRUE" ]; then
[ -f /proc/sys/net/ipv6/conf/all/forwarding ] && /bin/echo "1" > /proc/sys/net/ipv6/conf/all/forwarding
# [ -f /proc/sys/net/ipv6/conf/bond0/forwarding ] && /bin/echo "1" > /proc/sys/net/ipv6/conf/bond0/forwarding
# [ -f /proc/sys/net/ipv6/conf/eth0/forwarding ] && /bin/echo "1" > /proc/sys/net/ipv6/conf/eth0/forwarding
# [ -f /proc/sys/net/ipv6/conf/eth1/forwarding ] && /bin/echo "0" > /proc/sys/net/ipv6/conf/eth1/forwarding
for (( i=0; i<$NIC_NUM; i=i+1 ))
do
if [ -f /proc/sys/net/ipv6/conf/eth$i/forwarding ]; then
if [ "eth$i" != "$RA_INTERFACE" ]; then
/bin/echo "0" > /proc/sys/net/ipv6/conf/eth$i/forwarding
fi
fi
done
for (( i=0; i<$BOND_NUM; i=i+1 ))
do
if [ -f /proc/sys/net/ipv6/conf/bond$i/forwarding ]; then
if [ "bond$i" != "$RA_INTERFACE" ]; then
/bin/echo "0" > /proc/sys/net/ipv6/conf/bond$i/forwarding
fi
fi
done
[ -f /proc/sys/net/ipv6/conf/$RA_INTERFACE/forwarding ] && /bin/echo "1" > /proc/sys/net/ipv6/conf/$RA_INTERFACE/forwarding
gen_radvd_conf
$DAEMON_MGR radvd start "/usr/sbin/radvd -d 1 -C $RADVD_CONF &"
fi
}
stop()
{
local pid
$DAEMON_MGR radvd stop /usr/sbin/radvd
/bin/sleep 2
pid=`/bin/pidof radvd`
if [ ! -z "$pid" ]; then
/bin/kill $pid
/bin/sleep 2
fi
pid=`/bin/pidof radvd`
[ ! -z "$pid" ] && /bin/kill -9 $pid
[ -f /proc/sys/net/ipv6/conf/all/forwarding ] && /bin/echo "0" > /proc/sys/net/ipv6/conf/all/forwarding
# [ -f /proc/sys/net/ipv6/conf/bond0/forwarding ] && /bin/echo "0" > /proc/sys/net/ipv6/conf/bond0/forwarding
# [ -f /proc/sys/net/ipv6/conf/eth0/forwarding ] && /bin/echo "0" > /proc/sys/net/ipv6/conf/eth0/forwarding
[ -f /proc/sys/net/ipv6/conf/$RA_INTERFACE/forwarding ] && /bin/echo "0" > /proc/sys/net/ipv6/conf/$RA_INTERFACE/forwarding
}
restart()
{
stop
/bin/sleep 1
start
/bin/sleep 1
}
case "$1" in
start)
stop
/bin/sleep 1
start
;;
stop)
stop
;;
restart)
restart
;;
*)
/bin/echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

182
rcK Executable file
View File

@@ -0,0 +1,182 @@
#!/bin/sh
. /etc/profile
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
# Turn off ERROR_NO_HD and ERROR_HD_WRONG_FORMAT
if [ ! -x /sbin/hal_app ]; then
/sbin/set_status_led 3 0
fi
# QNAP_PIC_STATUS_OFF=0x59, QNAP_PIC_POWER_LED_BLINK=0x4C
if [ x`/sbin/getcfg Misc "Buzzer Quiet Enable"` != "xTRUE" ]; then
if [ -x /sbin/hal_app ]; then
/sbin/hal_app --se_buzzer enc_id=0,mode=0
else
/sbin/pic_raw 80
fi
fi
if [ -x /sbin/hal_app ]; then
/sbin/hal_app --status_led_set enc_id=0,event=0x20000,status=1
/sbin/hal_app --power_led_blink enc_id=0,enable=1
else
/sbin/pic_raw 89
/sbin/pic_raw 76
fi
waitrc()
{
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ];then
return 1
fi
cnt=$1
while [ $cnt -lt $2 ]; do
/bin/ps | grep "$3" | grep -v grep >/dev/null
if [ $? = 0 ]; then
sleep 2
else
cnt=$2
fi
cnt=$(($cnt+1))
done
return 0
}
#for QPKG
w=10
for i in /etc/rcK.d/QK??* ;do
# Ignore dangling symlinks (if any).
[ -f "$i" ] || continue
case "$i" in
*.sh)
w=0
# Source shell script for speed.
(
trap - INT QUIT TSTP
set stop &
. $i
)
;;
*)
w=0
# No sh extension, so fork subprocess.
[ -f $i ] && $i stop &
;;
esac
done
waitrc $w 10 "/etc/rcK.d/QK"
w=0
for i in /etc/rcK.d/K0?* ;do
# Ignore dangling symlinks (if any).
[ -f "$i" ] || continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set stop
. $i &
)
;;
*)
# No sh extension, so fork subprocess.
$i stop &
;;
esac
done
waitrc $w 5 "/etc/rcK.d/K0"
for i in /etc/rcK.d/K1?* ;do
# Ignore dangling symlinks (if any).
[ -f "$i" ] || continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set stop
. $i &
)
;;
*)
# No sh extension, so fork subprocess.
$i stop &
;;
esac
done
waitrc $w 5 "/etc/rcK.d/K1"
for i in /etc/rcK.d/K2?* ;do
# Ignore dangling symlinks (if any).
[ -f "$i" ] || continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set stop
. $i &
)
;;
*smb)
$i stop
;;
*ftp)
$i stop
;;
*nfs)
$i stop
;;
*)
# No sh extension, so fork subprocess.
$i stop &
;;
esac
done
waitrc $w 5 "/etc/rcK.d/K2"
for i in /etc/rcK.d/K[3-5]?* ;do
# Ignore dangling symlinks (if any).
[ -f "$i" ] || continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set stop
. $i &
)
;;
*)
# No sh extension, so fork subprocess.
$i stop &
;;
esac
done
waitrc $w 30 "/etc/rcK.d/K3"
waitrc $w 10 "/etc/rcK.d/K4"
waitrc $w 10 "/etc/rcK.d/K5"
for i in /etc/rcK.d/K[6-9]?* ;do
# Ignore dangling symlinks (if any).
[ -f "$i" ] || continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set stop
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i stop
;;
esac
done
/bin/umount -a

29
rcS Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/sh
. /etc/profile
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
for i in /etc/rcS_init.d/S??* ;do
# Ignore dangling symlinks (if any).
#[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*atalk)
$i start &
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
done

131
rcS_normal Executable file
View File

@@ -0,0 +1,131 @@
#!/bin/sh
. /etc/profile
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
waitrc()
{
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ];then
return 1
fi
cnt=$1
while [ $cnt -lt $2 ]; do
/bin/ps | grep "$3" | grep -v grep >/dev/null
if [ $? = 0 ]; then
sleep 2
else
cnt=$2
fi
cnt=$(($cnt+1))
done
return 0
}
w=0
for i in /etc/rcS.d/S[0-5]?* ;do
# Ignore dangling symlinks (if any).
#[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
done
for i in /etc/rcS.d/S[6-8]?* ;do
[ -f "$i" ] || continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*httpd)
$i start
;;
*Qthttpd)
$i start
;;
*cupsd)
$i start
;;
*smb)
$i start
;;
*ftp)
$i start
;;
*nfs)
$i start
;;
*recycled)
$i start
;;
*nvrd)
$i start
;;
*)
# No sh extension, so fork subprocess.
$i start &
;;
esac
done
waitrc $w 40 "/etc/rcS.d/S"
for i in /etc/rcS.d/S9?* ;do
[ -f "$i" ] || continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*init_nas)
# No sh extension, so fork subprocess.
waitrc $w 10 "/etc/rcS.d/S9"
$i start
;;
*)
# No sh extension, so fork subprocess.
$i start &
;;
esac
done
waitrc $w 20 "/etc/rcS.d/S9"
#for QPKG
for i in /etc/rcS.d/QS??* ;do
# Ignore dangling symlinks (if any).
[ -f "$i" ] || continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
done

72
rcS_normal_fast Executable file
View File

@@ -0,0 +1,72 @@
#!/bin/sh
. /etc/profile
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
for i in /etc/rcS.d/S??* ;do
# Ignore dangling symlinks (if any).
#[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*init_qpkg)
$i start
;;
*mountall)
$i start
;;
*Qthttpd)
$i start
;;
*smb)
$i start
;;
*ftp)
$i start
;;
*nfs)
$i start
;;
*recycled)
$i start
;;
*init_nas)
$i start
;;
*)
# No sh extension, so fork subprocess.
$i start &
;;
esac
done
#for QPKG
for i in /etc/rcS.d/QS??* ;do
# Ignore dangling symlinks (if any).
#[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
[ -f $i ] && $i start
;;
esac
done

34
rcv_port.sh Executable file
View File

@@ -0,0 +1,34 @@
#!/bin/sh
RCV_PORT="/proc/tsinfo/sk_rcv_port"
if [ ! -f $RCV_PORT ]; then
exit 0
fi
case "$1" in
start)
echo -n "Start rcv_port: "
PORT="set 139 445 20"
echo "$PORT" > $RCV_PORT
echo -n $PORT
echo .
;;
stop)
echo -n "Stop rcv_port: "
PORT="set"
echo "$PORT" > $RCV_PORT
echo -n $PORT
echo .
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/rcv_port.sh {start|stop|restart}"
exit 1
esac
exit 0

20
reboot Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/sh
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
if [ -x /sbin/storage_util ];then
/sbin/storage_util --shutdown_check
if [ $? -eq 0 ];then
/sbin/log_tool -t 1 -a "Auto reboot was canceled because one volume was busy"
exit 0
fi
fi
. /etc/init.d/wait_RR
echo reboot start...
if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then
if [ -x /sbin/hal_app ]; then
/sbin/hal_app --se_sys_set_pic_wdt enc_sys_id=root,mode=1
else
/sbin/pic_raw 104 #enable pic watch dog timer 5 min,reboot
fi
fi
/sbin/reboot

91
recycled.sh Executable file
View File

@@ -0,0 +1,91 @@
#!/bin/sh
LIBTRASH="/etc/config/libtrash.conf"
DEF_LIBTRASH="/etc/default_config/libtrash.conf"
case "$1" in
start)
if [ ! -f ${LIBTRASH} ]; then
/bin/cp -fp ${DEF_LIBTRASH} ${LIBTRASH} 1>>/dev/null 2>>/dev/null
fi
if [ `/sbin/getcfg "Network Recycle Bin" Enable -u -d FALSE` = TRUE ]; then
echo -n "Starting recycled services:"
/sbin/getcfg "Network Recycle Bin 1" public -f /etc/config/smb.conf
result=$?
if [ $result -eq 0 ]
then
/sbin/setcfg "Network Recycle Bin 1" "veto files" "" -f /etc/config/smb.conf
fi
/sbin/getcfg "Network Recycle Bin 2" public -f /etc/config/smb.conf
result=$?
if [ $result -eq 0 ]
then
/sbin/setcfg "Network Recycle Bin 2" "veto files" "" -f /etc/config/smb.conf
fi
/sbin/getcfg "Network Recycle Bin 3" public -f /etc/config/smb.conf
result=$?
if [ $result -eq 0 ]
then
/sbin/setcfg "Network Recycle Bin 3" "veto files" "" -f /etc/config/smb.conf
fi
/sbin/getcfg "Network Recycle Bin 4" public -f /etc/config/smb.conf
result=$?
if [ $result -eq 0 ]
then
/sbin/setcfg "Network Recycle Bin 4" "veto files" "" -f /etc/config/smb.conf
fi
/sbin/getcfg "Network Recycle Bin 5" public -f /etc/config/smb.conf
result=$?
if [ $result -eq 0 ]
then
/sbin/setcfg "Network Recycle Bin 5" "veto files" "" -f /etc/config/smb.conf
fi
/sbin/getcfg "Network Recycle Bin 6" public -f /etc/config/smb.conf
result=$?
if [ $result -eq 0 ]
then
/sbin/setcfg "Network Recycle Bin 6" "veto files" "" -f /etc/config/smb.conf
fi
/sbin/getcfg "Network Recycle Bin 7" public -f /etc/config/smb.conf
result=$?
if [ $result -eq 0 ]
then
/sbin/setcfg "Network Recycle Bin 7" "veto files" "" -f /etc/config/smb.conf
fi
/sbin/getcfg "Network Recycle Bin 8" public -f /etc/config/smb.conf
result=$?
if [ $result -eq 0 ]
then
/sbin/setcfg "Network Recycle Bin 8" "veto files" "" -f /etc/config/smb.conf
fi
#/usr/bin/killall -SIGHUP smbd
[ x`/sbin/getcfg Misc Configured -u -d FALSE` = xTRUE ] && /etc/init.d/smb.sh restart 1>>/dev/null 2>>/dev/null
#/sbin/daemon_mgr recycled start "/sbin/recycled"
[ -f /sbin/gpiod ] && /bin/kill -USR1 `pidof gpiod`
if [ `/sbin/getcfg AppleTalk Enable` = TRUE ] && [ -f /tmp/.boot_done ]; then
echo -n "restart atalk...."
/etc/init.d/atalk.sh restart 1>>/dev/null 2>>/dev/null
fi
echo -n " recycled"
echo "."
fi
;;
stop)
echo -n "Shutting down recycled services:"
[ -f /sbin/gpiod ] && /bin/kill -USR1 `pidof gpiod`
#/sbin/daemon_mgr recycled stop /sbin/recycled
echo -n " recycled"
echo "."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/recycled {start|stop|restart}"
exit 1
esac
exit 0

33
refresh_nvr_crontab.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/sh
LOG_CHK_NOTIFY_FILE=/tmp/.log_chk_notify
if [ "`/sbin/getcfg -f /etc/default_config/uLinux.conf NVR Support -d FALSE`" == "TRUE" ]; then
SUPPORT_NVR=yes
else
SUPPORT_NVR=no
fi
if [ "`/sbin/getcfg -f /etc/config/uLinux.conf NVR Enable -d FALSE`" == "TRUE" ]; then
NVR_ENABLED=yes
else
NVR_ENABLED=
fi
if [ "$SUPPORT_NVR" == "yes" -a "$NVR_ENABLED" == "yes" -a "`/usr/bin/qcmd recfg`" == "1" ]; then
if [ x"`/bin/cat /etc/config/crontab | /bin/grep "logChecker"`" = x ]; then
echo "*/60 * * * * /usr/bin/logChecker" >> /etc/config/crontab
fi
if [ x"`/bin/cat /etc/config/crontab | /bin/grep "DUSG"`" = x ]; then
echo "0-59/15 * * * * /usr/bin/qcmd DUSG" >> /etc/config/crontab
fi
if [ x"`/bin/cat /etc/config/crontab | /bin/grep rec_report`" != x"5 * * * * /usr/bin/qcmd rec_report" ]; then
/bin/sed -i '/qcmd rec_report/d' /etc/config/crontab
echo "5 * * * * /usr/bin/qcmd rec_report" >> /etc/config/crontab
fi
/bin/touch $LOG_CHK_NOTIFY_FILE
else
/bin/sed -i '/qcmd/d' /etc/config/crontab
/bin/sed -i '/logChecker/d' /etc/config/crontab
/bin/rm -rf $LOG_CHK_NOTIFY_FILE
fi
/usr/bin/crontab /etc/config/crontab

48
reset_all.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/sh
case "$1" in
stop_all)
/etc/init.d/smb stop
/etc/init.d/mars-nwe stop
/etc/init.d/ftp.sh stop
/etc/init.d/atalk stop
/etc/init.d/nfs stop
/etc/init.d/cron stop
;;
start_all)
/etc/init.d/smb start
/etc/init.d/mars-nwe start
/etc/init.d/ftp.sh start
/etc/init.d/atalk start
/etc/init.d/nfs start
/etc/init.d/cron start
;;
copy_default)
/bin/cp -af /etc/default_config/* /mnt/config
/etc/init.d/update_config init
;;
reset_cache)
/sbin/init_nas_cache
;;
delete_unused)
/bin/rm -f /etc/config/raidtab
/bin/rm -f /etc/config/storage.conf
/bin/rm -f /etc/storage.conf
/bin/rm -f /etc/config/pdcgroup
/bin/rm -f /etc/config/fw*
/bin/rm -f /etc/config/named.conf
/bin/rm -f /etc/config/dhcp_log
/bin/rm -f /etc/config/usr_quota.conf
/bin/rm -f /etc/config/grp_quota.conf
/bin/rm -f /etc/config/backup_schedule.conf
;;
clear_log)
/bin/rm -f /etc/logs/nas4000.cnt
;;
*)
echo "Usage: /etc/init.d/reset_all {copy_default|reset_cache|delete_unused|clear_log|save_all}"
exit 1
esac
exit 0

695
rsyncRR.sh Executable file
View File

@@ -0,0 +1,695 @@
#!/bin/sh
# $1 [$2 $3 $4] = Schedule0...ScheduleN [ user_name ip_addr host_name ]
#
#
ERROR_DESC[0]="Success."
ERROR_DESC[1]="Unexpected error."
ERROR_DESC[41]="Remote host does not exist."
ERROR_DESC[42]="Connection refused. Remote service is not enabled or the port number is incorrect."
ERROR_DESC[43]="Authentication failed. Please check the user name and password."
ERROR_DESC[44]="The destination folder path does not exist."
ERROR_DESC[45]="Connection reset by peer. Remote backup service might be restarted/stopped."
ERROR_DESC[46]="Connection timed out, please check the connectivity."
ERROR_DESC[47]="Some files have been vanished, the source files might be removed during backup."
ERROR_DESC[48]="Replication job has been terminated by user."
ERROR_DESC[49]="The source folder path does not exist."
ERROR_DESC[50]="The previous scheduled job has not been finished yet."
# Check if a string contains the specified prefix
# Is_Prefix_Matched string prefix
Is_Prefix_Matched()
{
cbPrefix=`/usr/bin/expr length "$2"`
SubStr=`/usr/bin/expr substr "$1" 1 $cbPrefix`
if [ "$SubStr" == "$2" ]; then
echo "1"
else
echo "0"
fi
}
# Check if a string contains the specified postfix
# Is_Prefix_Matched string postfix
Is_Postfix_Matched()
{
cbString=`/usr/bin/expr length "$1"`
cbPostfix=`/usr/bin/expr length "$2"`
nbPos=`/usr/bin/expr $cbString - $cbPostfix + 1`
SubStr=`/usr/bin/expr substr "$1" $nbPos $cbPostfix`
if [ "$SubStr" == "$2" ]; then
echo "1"
else
nbPos=`/usr/bin/expr $cbString - $cbPostfix`
SubStr=`/usr/bin/expr substr "$1" $nbPos $cbPostfix`
if [ "$SubStr" == "$2" ]; then
echo "1"
else
echo "0"
fi
fi
}
# Check the rsync error by comparing the key words
# Is_Error_Pattern_Matched string prefix postfix
Is_Error_Pattern_Matched()
{
if [ "1" == $(Is_Prefix_Matched "$1" "$2") ] && [ "1" == $(Is_Postfix_Matched "$1" "$3") ]; then
echo "1"
else
echo "0"
fi
}
# Is_Contain_Substring() string substr
Is_Contain_Substring()
{
[ ${#2} -eq 0 ] && { echo "0"; return; }
case "$1" in
*$2*) echo "1";;
*) echo "0";;
esac
}
# Filter_Log_Msg() msg_from msg_to
Filter_Log_Msg()
{
/bin/rm -f "$2" 1>/dev/null 2>/dev/null
/bin/touch "$2" 1>/dev/null 2>/dev/null
if [ -s "$1" ]; then
while read szLine
do
if [ "1" == $( Is_Contain_Substring "$szLine" "Warning: Permanently added" ) ]; then
continue
elif [ "1" == $( Is_Error_Pattern_Matched "$szLine" "rsync: mkstemp " " Invalid argument (22)" ) ]; then
continue
elif [ "1" == $( Is_Error_Pattern_Matched "$szLine" "rsync: recv_generator: mkdir " " Invalid argument (22)" ) ]; then
continue
elif [ "1" == $( Is_Contain_Substring "$szLine" "*** Skipping any contents from this failed directory ***" ) ]; then
continue
elif [ "1" == $( Is_Error_Pattern_Matched "$szLine" "Could not create directory" "admin/.ssh'." ) ]; then
continue
elif [ "1" == $( Is_Error_Pattern_Matched "$szLine" "Failed to add the host to the list of known hosts" ".ssh/known_hosts)." ) ]; then
continue
fi
/bin/echo "$szLine" >> "$2"
done < "$1"
fi
}
# SetStatus() "Schedule${i}" 2
SetStatus()
{
local iCnt=0
while [ $iCnt -le 5 ]
do
iCnt=$(($iCnt+1))
/sbin/setcfg "${1}" "Status" "${2}" -f "${RR_CONF}"
if [ $? = 0 ]; then
break
else
/bin/sleep 1
fi
done
}
# Get a message line from the error log file.
Get_First_Error_Msg()
{
SZLINE=""
while read szLine
do
if [ "1" == $( Is_Error_Pattern_Matched "$szLine" "rsync: mkstemp " " Invalid argument (22)" ) ]; then
continue
fi
if [ "1" == $( Is_Contain_Substring "$szLine" "Warning: " ) ]; then
continue
fi
if [ "1" == $( Is_Contain_Substring "$szLine" "Operation not permitted (1)" ) ]; then
continue
fi
if [ "1" == $( Is_Contain_Substring "$szLine" "some files/attrs were not transferred" ) ]; then
continue
fi
if [ "1" == $( Is_Error_Pattern_Matched "$szLine" "rsync: recv_generator: mkdir " " Invalid argument (22)" ) ]; then
continue
fi
if [ "1" == $( Is_Contain_Substring "$szLine" "*** Skipping any contents from this failed directory ***" ) ]; then
continue
fi
SZLINE="$szLine"
break
done < "$1"
}
# Check the rsync error code by parsing the rsync error log file. Will set error code to $iError.
# Parse_Error_Log_File rsync_error_log_file
Parse_Error_Log_File()
{
SZLINE=""
Get_First_Error_Msg "$1"
if [ "x" == "x$SZLINE" ]; then
iError=0
echo ""
elif [ "1" == $( Is_Error_Pattern_Matched "$SZLINE" "rsync: failed to connect to " " No route to host (113)" ) ]; then
iError=41
echo ERROR_NO_ROUTE_TO_HOST
elif [ "1" == $( Is_Error_Pattern_Matched "$SZLINE" "rsync: failed to connect to " " Invalid argument (22)" ) ]; then
iError=41
echo ERROR_NO_ROUTE_TO_HOST
elif [ "1" == $( Is_Error_Pattern_Matched "$SZLINE" "ssh: connect to host " ": No route to host" ) ]; then
iError=41
echo ERROR_NO_ROUTE_TO_HOST
elif [ "1" == $( Is_Error_Pattern_Matched "$SZLINE" "rsync: failed to connect to " " Connection refused (111)" ) ]; then
iError=42
echo ERROR_NO_REMOTE_SERVICE
elif [ "1" == $( Is_Error_Pattern_Matched "$SZLINE" "ssh: connect to host " ": Connection refused" ) ]; then
iError=42
echo ERROR_NO_REMOTE_SERVICE
elif [ "1" == $(Is_Prefix_Matched "$SZLINE" "@ERROR: auth failed on module") ]; then
iError=43
echo ERROR_AUTH_FAILED
elif [ "1" == $(Is_Prefix_Matched "$SZLINE" "@ERROR: Unknown module") ]; then
iError=44
echo ERROR_PATH_NOT_FOUND
elif [ "1" == $(Is_Prefix_Matched "$SZLINE" "@ERROR: chroot failed") ]; then
iError=44
echo ERROR_PATH_NOT_FOUND
elif [ "1" == $( Is_Error_Pattern_Matched "$SZLINE" "rsync: " " Input/output error (5)" ) ]; then
iError=44
echo ERROR_PATH_NOT_FOUND
elif [ "1" == $( Is_Error_Pattern_Matched "$SZLINE" "rsync: " " No such file or directory (2)" ) ]; then
iError=44
echo ERROR_PATH_NOT_FOUND
elif [ "1" == $( Is_Error_Pattern_Matched "$SZLINE" "rsync: " " Connection reset by peer (104)" ) ]; then
iError=45
echo ERROR_CONN_RESET
elif [ "1" == $( Is_Error_Pattern_Matched "$SZLINE" "io timeout after " " exiting" ) ]; then
iError=46
echo ERROR_CONN_TIMEOUT
elif [ "1" == $(Is_Prefix_Matched "$SZLINE" "file has vanished: ") ]; then
iError=47
echo ERROR_FILE_NOT_EXISTED
elif [ "1" == $(Is_Prefix_Matched "$SZLINE" "rsync: cancelled by user") ]; then
iError=48
echo ERROR_OPER_CANCELLED
elif [ "1" == $(Is_Prefix_Matched "$SZLINE" "rsync error: received SIGINT, SIGTERM, or SIGHUP") ]; then
iError=48
echo ERROR_OPER_CANCELLED
elif [ "1" == $(Is_Prefix_Matched "$SZLINE" "ERROR: ${ERROR_DESC[49]}") ]; then
iError=49
echo ERROR_SOURCE_PATH_NOT_FOUND
else
iError=1
ERROR_DESC[1]="$SZLINE"
echo ERROR_UNEXPECTED
fi
}
stop_network()
{
/etc/init.d/smb.sh stop &
/etc/init.d/atalk.sh stop &
/etc/init.d/ftp.sh stop &
}
start_network()
{
# kenttest=0
/etc/init.d/smb.sh start &
/etc/init.d/atalk.sh start &
/etc/init.d/ftp.sh start &
}
# Update the finished status, time, error code and log after remote backup finished.
# Update_Status $schedule $szUser $szAddr $szHost $szRetry
Update_Status()
{
if [ "80" == "$RR_result" ]; then
iError=50
echo "ERROR_JOB_ALREADY_RUNNING"
else
Parse_Error_Log_File "$SZF_ERROR"
fi
szName=`/sbin/getcfg "$1" "Name" -f "${RR_CONF}" -d ""`
/sbin/setcfg "$1" "ErrorCode" "$iError" -f "${RR_CONF}"
szFinishedTime=`/bin/date +%s`
/sbin/setcfg "$1" "Finished Time" "$szFinishedTime" -f "${RR_CONF}"
if [ "0" == "$iError" ]; then
# /sbin/setcfg "$1" "Status" "2" -f "${RR_CONF}"
SetStatus "$1" "2"
/sbin/log_tool -t 0 -u "$2" -p "$3" -m "$4" -a "[Remote Replication] $szName finished."
elif [ "48" == "$iError" ]; then
# /sbin/setcfg "$1" "Status" "2" -f "${RR_CONF}"
SetStatus "$1" "2"
/sbin/log_tool -t 0 -u "$2" -p "$3" -m "$4" -a "[Remote Replication] $szName stopped."
elif [ "50" == "$iError" ]; then
# /sbin/setcfg "$1" "Status" "2" -f "${RR_CONF}"
SetStatus "$1" "2"
/sbin/log_tool -t 0 -u "$2" -p "$3" -m "$4" -a "[Remote Replication] $szName has been cancelled, because the previous scheduled job has not been finished yet."
elif [ "43" == "$iError" ] || [ "44" == "$iError" ] || [ "49" == "$iError" ]; then
# /sbin/setcfg "$1" "Status" "7" -f "${RR_CONF}"
SetStatus "$1" "7"
/sbin/log_tool -t 2 -u "$2" -p "$3" -m "$4" -a "[Remote Replication] $szName failed: ${ERROR_DESC[$iError]}"
else
# /sbin/setcfg "$1" "Status" "7" -f "${RR_CONF}"
SetStatus "$1" "7"
/sbin/log_tool -t 2 -u "$2" -p "$3" -m "$4" -a "[Remote Replication] $szName failed: ${ERROR_DESC[$iError]}.$5"
fi
}
Replace_Date()
{
SZ_RETURN="$1"
SZ_RETURN=${SZ_RETURN//\$YEAR/`/bin/date +%Y`}
SZ_RETURN=${SZ_RETURN//\$MONTH/`/bin/date +%m`}
SZ_RETURN=${SZ_RETURN//\$DAY/`/bin/date +%d`}
SZ_RETURN=${SZ_RETURN//\$HOUR/`/bin/date +%H`}
SZ_RETURN=${SZ_RETURN//\$MINUTE/`/bin/date +%M`}
echo $SZ_RETURN
}
check_rsync_error()
{
local ret=0
out_msg=`cut -d ' ' -f 2 ${SZF_OUTPUT}`
out_msg2=`/usr/bin/expr substr "$out_msg" 1 5`
if [ $out_msg2 = "auth" ]; then
ret=1
fi
if [ $out_msg2 = "Unknown" ]; then
ret=2
fi
return $ret
}
modify_known_hosts()
{
/bin/ps | /bin/grep ${Remote_IP} > "/tmp/rsync-tmp"
/bin/grep /usr/bin/ssh "/tmp/rsync-tmp" >> /dev/null
if [ $? != 0 ]; then
/usr/bin/ssh-keygen -R ${Remote_IP}
fi
}
write_err_log() {
case "x$1" in
"x5")
check_rsync_error ${SZF_OUTPUT}
if [ $? = 1 ]; then
msg="[Remote Replication] Remote backup schedule $2 failed. (Authentication failure)"
else
msg="[Remote Replication] Remote backup schedule $2 failed. (Error starting client-server protocol, maybe the destination path is nonexistent.)"
fi
;;
"x10")
msg="[Remote Replication] Remote backup schedule $2 failed. (Error in socket IO, maybe the network connection is disconnect.)"
;;
"x11")
msg="[Remote Replication] Remote backup schedule $2 failed. (Error in file IO)"
;;
"x12")
if [ "x${RR_opt_SSH}" = "xTRUE" ]; then
msg="[Remote Replication] Remote backup schedule $2 failed. (Error in SSH , maybe SSH of the server is disconnect.)"
else
msg="[Remote Replication] Remote backup schedule $2 failed. (Error in rsync protocol data stream, maybe the capacity of destination is full.)"
fi
;;
"x23")
msg="[Remote Replication] Remote backup schedule $2 failed. (Some files could not be transfered, maybe the source path is incorrect.)"
;;
*)
msg="[Remote Replication] Remote backup schedule $2 failed. (Other error with error code $1)"
esac
/sbin/write_log "$msg" 1
}
report_error()
{
if [ "${LOG_FILE_NAME}+log" = "log" ]; then
echo "Please provide log file name"
else # no log file name specified
qnap_rsync_log="${LOG_FILE_NAME}"
while read LINE
do
if [ "`/bin/echo $LINE | /usr/bin/cut -c1-1`" = "[" ]; then
/sbin/write_log "[Remote Replication] Failed to copy $LINE" 1
[ "$DEBUG" = "yes" ] && echo "Error : $LINE"
else # the final result
RESULT_STRING=$LINE
fi
done < $qnap_rsync_log
fi
case "x${RR_result}" in
"x0")
echo "RR [${RR_name}] succeed..."
RR_Num=`/sbin/getcfg "global" "Schedule Number" -f "${RR_CONF}" -d "0"`
i=0
while [ ${i} -lt ${RR_Num} ]
do
RR_name2=`/sbin/getcfg "Schedule${i}" Name -f "${RR_CONF}" -d ""`
if [ "x${RR_name}" = "x${RR_name2}" ]; then
# /sbin/setcfg "Schedule${i}" Status 2 -f "${RR_CONF}"
SetStatus "Schedule${i}" "2"
RR_finished_time_s=`/bin/date +%s`
/sbin/setcfg "Schedule${i}" "Finished Time" ${RR_finished_time_s} -f "${RR_CONF}"
break
fi
i=`/usr/bin/expr ${i} + 1`
done
/sbin/write_log "[Remote Replication] Remote backup schedule ${RR_name} finished successfully." 4
;;
# Remove file level backup Paul chen
# "x10"|"x13")
# echo "rsync failed, trying ${RR_name} with old RR method..."
# /sbin/write_log "[Remote Replication] Remote NAS doesn't support block level replication, trying file level replication." 4
# #/sbin/backup2nas -j "${RR_name}" & Ricky remarked 2005/3/16 this script has run at backupground!
# /sbin/backup2nas -j "${RR_name}"
# RR_Num=`/sbin/getcfg "global" "Schedule Number" -f "${RR_CONF}" -d "0"`
# i=0
# while [ ${i} -lt ${RR_Num} ]
# do
# RR_name2=`/sbin/getcfg "Schedule${i}" Name -f "${RR_CONF}" -d ""`
# if [ "x${RR_name}" = "x${RR_name2}" ]; then
# /sbin/setcfg "Schedule${i}" Status 2 -f "${RR_CONF}"
# RR_finished_time_s=`/bin/date +%s`
# /sbin/setcfg "Schedule${i}" "Finished Time" ${RR_finished_time_s} -f "${RR_CONF}"
# break
# fi
# i=`/usr/bin/expr ${i} + 1`
# done
# ;;
# Paul Chen ends
*)
echo "RR [${RR_name}] failed... Error Code=${RR_result}"
RR_Num=`/sbin/getcfg "global" "Schedule Number" -f "${RR_CONF}" -d "0"`
i=0
while [ ${i} -lt ${RR_Num} ]
do
RR_name2=`/sbin/getcfg "Schedule${i}" Name -f "${RR_CONF}" -d ""`
if [ "x${RR_name}" = "x${RR_name2}" ]; then
# /sbin/setcfg "Schedule${i}" Status 7 -f "${RR_CONF}"
SetStatus "Schedule${i}" "7"
RR_finished_time_s=`/bin/date +%s`
/sbin/setcfg "Schedule${i}" "Finished Time" ${RR_finished_time_s} -f "${RR_CONF}"
break
fi
i=`/usr/bin/expr ${i} + 1`
done
write_err_log $RR_result "$RR_name"
esac
}
function signal_handler()
{
bAbort="1"
iProcPid=`/sbin/getcfg "$1" "PID" -f "${RR_CONF}" -d "0"`
if [ "$iProcPid" -gt 0 ]; then
/bin/kill -9 "$iProcPid"
fi
}
# Setup conf file pathes.
SMB_CONF="/etc/smb.conf"
RR_CONF="/etc/config/rsync_schedule.conf"
# Exit if there is no schedule specified.
RR_sche=${1}
[ "x${RR_sche}" = "x" ] && exit -1
# Exit if I am not the first instance launched.
iPid="$$"
iPrevPid=`/sbin/getcfg "$RR_sche" "ScriptPID" -f "${RR_CONF}" -d "0"`
if [ "$iPrevPid" -gt 0 ]; then
/bin/kill -0 "$iPrevPid" 2> /dev/null
if [ "$?" -eq "0" ]; then
szName=`/sbin/getcfg "$1" "Name" -f "${RR_CONF}" -d ""`
/sbin/log_tool -t 0 -u "$2" -p "$3" -m "$4" -a "[Remote Replication] $szName started."
/sbin/log_tool -t 0 -u "$2" -p "$3" -m "$4" -a "[Remote Replication] $szName has been cancelled, because the previous scheduled job has not been finished yet."
exit -1
fi
fi
/sbin/setcfg "$RR_sche" "ScriptPID" "$iPid" -f "${RR_CONF}"
/sbin/setcfg "$RR_sche" "ErrorCode" "0" -f "${RR_CONF}"
bAbort=0
trap 'signal_handler' 2
trap 'signal_handler' 15
# 20090925: keep stdout and stderr to logs files
SZD_LOGS="/etc/logs/rsync"
SZF_OUTPUT="$SZD_LOGS/rsync-out-$1"
SZF_ERROR="$SZD_LOGS/rsync-err-$1"
SZF_ERROR_TMP="$SZD_LOGS/rsync-tmp-$1"
/bin/mkdir $SZD_LOGS 1>/dev/null 2>/dev/null
/bin/rm -f $SZF_ERROR 1>/dev/null 2>/dev/null
/bin/touch $SZF_ERROR 1>/dev/null 2>/dev/null
DEBUG=no
# setup user name, ip addres and host name from parameters
szUser="System"
szAddr="127.0.0.1"
szHost="localhost"
if [ 4 -le $# ]; then
szUser="$2"
szAddr="$3"
szHost="$4"
fi
RR_name=`/sbin/getcfg "${RR_sche}" Name -f "${RR_CONF}" -d ""`
#[ "x${RR_name}" = "x" ] && exit -1
Remote_IP=`/sbin/getcfg "${RR_sche}" "Remote IP" -f ${RR_CONF} -d "0.0.0.0"`
#[ "x${Remote_IP}" = "x0.0.0.0" ] && exit -1
Remote_IP=`/sbin/get_domain_ip ${Remote_IP}`
Local_vol=`/sbin/getcfg "${RR_sche}" "Local Volume" -f ${RR_CONF} -d ""`
Local_path=`/sbin/getcfg "${RR_sche}" "Local Path" -f ${RR_CONF} -d ""`
SMB_path=`/sbin/getcfg "${Local_vol}" "path" -f ${SMB_CONF} -d ""`
RR_PORT=`/sbin/getcfg "${RR_sche}" "Rsync Port" -f ${RR_CONF} -d "873"`
if [ "x${Local_path}" = "x/" ]
then
RR_local_path="${SMB_path}"
else
RR_local_path="${SMB_path}${Local_path}"
fi
Remote_vol=`/sbin/getcfg "${RR_sche}" "Remote Volume" -f ${RR_CONF} -d ""`
Remote_path=`/sbin/getcfg "${RR_sche}" "Remote Path" -f ${RR_CONF} -d ""`
Remote_path=$(Replace_Date "$Remote_path")
if [ "x${Remote_path}" = "x/" ]
then
RR_remote_path="${Remote_vol}"
else
RR_remote_path="${Remote_vol}${Remote_path}"
fi
# Verify User/Pwd through samba / added by KenChen 20060418
UserName=`/sbin/getcfg "${RR_sche}" "User Name" -f ${RR_CONF} -d ""`
Passwd=`/sbin/getcfg "${RR_sche}" "Password" -f ${RR_CONF} -d ""`
# RichardChang 20070917 disable for check user by rsync
#RemotePath=`/sbin/getcfg "${RR_sche}" "Remote Path" -f ${RR_CONF} -d ""`
#smbtmp=`/bin/mktemp -d '/tmp/temp.XXXXXX'`
#/bin/mount -t cifs "//${Remote_IP}/${Remote_vol}" "${smbtmp}" -o lfs,username="${UserName}",password="${Passwd}",iocharset=utf8
#if [ $? = 0 ]; then
# #/bin/ls "${smbtmp}${RemotePath}"
# #if [ $? = 0 ]; then
# if [ -d "${smbtmp}${RemotePath}" ]; then
# /bin/umount "${smbtmp}"
# if [ $? = 0 ]; then
# /bin/rm "${smbtmp}" -rf
# fi
# else
# /sbin/write_log "[Remote Replication] Remote backup schedule "$RR_name" failed. (Remote destination path does not exist.)" 1
# /bin/umount "${smbtmp}"
# if [ $? = 0 ]; then
# /bin/rm "${smbtmp}" -rf
# fi
# exit -1
# fi
#else
# /sbin/write_log "[Remote Replication] Remote backup schedule "$RR_name" failed. (Authentication failure)" 1
# /bin/rm "${smbtmp}" -rf
# exit -1
#fi
# End here
RR_opt_sparse=`/sbin/getcfg "${RR_sche}" "Sparse" -f ${RR_CONF} -d "FALSE" -u`
[ "x${RR_opt_sparse}" = "xTRUE" ] && RR_options=${RR_options}"--sparse "
RR_opt_compress=`/sbin/getcfg "${RR_sche}" "Compressed" -f ${RR_CONF} -d "FALSE" -u`
[ "x${RR_opt_compress}" = "xTRUE" ] && RR_options=${RR_options}"--compress "
RR_opt_sync=`/sbin/getcfg "${RR_sche}" "Delete Extra" -f "${RR_CONF}" -d "FALSE" -u`
[ "x${RR_opt_sync}" = "xTRUE" ] && RR_options=${RR_options}"--delete "
RR_opt_inc=`/sbin/getcfg ${RR_sche} "Incremental" -f ${RR_CONF} -d "FALSE" -u`
[ "x${RR_opt_inc}" = "xFALSE" ] && RR_options=${RR_options}"--whole-file -I "
RR_opt_KBPS=`/sbin/getcfg ${RR_sche} "Bandwith KBPS" -f ${RR_CONF} -d "0" -u`
RR_opt_KBPS=`/bin/echo "${RR_opt_KBPS}" | /bin/sed -e 's/[^0-9]//g'`
RR_opt_KBPS=$((${RR_opt_KBPS} + 0))
[ "x${RR_opt_KBPS}" != "x0" ] && RR_options=${RR_options}"--bwlimit=${RR_opt_KBPS} "
RR_opt_stopnet=`/sbin/getcfg ${RR_sche} "Stop Net" -f ${RR_CONF} -d "FALSE" -u`
#Richard add 20070608 for rsync of ssh
RR_opt_SSH=`/sbin/getcfg "${RR_sche}" "Use of SSH" -f ${RR_CONF} -d "FALSE" -u`
RR_SSH_PORT=`/sbin/getcfg "${RR_sche}" "SSH PORT" -f ${RR_CONF} -d "22"`
RR_com_ssh="/usr/bin/ssh -o StrictHostKeyChecking=no -l ${UserName} -j ${Passwd} -p ${RR_SSH_PORT}"
#Richard add 20080409 for rsync mode
RR_MODE=`/sbin/getcfg "${RR_sche}" "RSYNC MODE" -f ${RR_CONF} -d "1" -u`
[ "x${RR_opt_stopnet}" = "xTRUE" ] && stop_network
# set status to "Replicating"
szName=`/sbin/getcfg "$1" "Name" -f "${RR_CONF}" -d ""`
if [ "$szUser" != "System" ]; then
/sbin/log_tool -t 0 -u "$2" -p "$3" -m "$4" -a "[Remote Replication] $szName started."
else
/sbin/log_tool -t 0 -u "$2" -p "$3" -m "$4" -a "[Remote Replication] $szName started."
fi
if [ "x${SMB_path}" = "x" ]; then
#write_err_log 23 "$RR_name"
echo "ERROR: ${ERROR_DESC[49]}" > "$SZF_ERROR"
Update_Status $1 $szUser $szAddr $szHost
/sbin/setcfg "$RR_sche" "ScriptPID" "0" -f "${RR_CONF}"
exit -1
fi
#/sbin/setcfg "${RR_sche}" Status 9 -f ${RR_CONF}
SetStatus "${RR_sche}" "9"
LOG_FILE_NAME="/tmp/${RR_name}_`/bin/date +'%Y%m%d%H%M'`.log"
touch "${LOG_FILE_NAME}"
# 2010/01/20 Add retry / timeout options.
iRetry=0
xsTimeout=`/sbin/getcfg "Global" "Timeout" -f "${RR_CONF}" -d "600"`
xnRetry=`/sbin/getcfg "Global" "Retry Times" -f "${RR_CONF}" -d "3"`
xsInterval=`/sbin/getcfg "Global" "Retry Intervals" -f "${RR_CONF}" -d "60"`
if [ "x${RR_opt_KBPS}" = "x0" ]; then
RR_options=${RR_options}"--qnap-bwlimit "
if [ "x${RR_opt_SSH}" = "xTRUE" ]; then
/usr/bin/rsync --sever-mode=1 --dry-run -e "${RR_com_ssh}" --qnap-ssh-bwlimit --timeout=${xsTimeout} --password="${Passwd}" "${UserName}"@[${Remote_IP}]::
if [ "x$?" = "x0" ]; then
RR_options=${RR_options}"--qnap-ssh-bwlimit "
fi
fi
fi
while [ $iRetry -le "$xnRetry" ]
do
# Increment $iRetry
iRetry=$(($iRetry+1))
Remote_IP=`/sbin/getcfg "${RR_sche}" "Remote IP" -f ${RR_CONF} -d "0.0.0.0"`
Remote_IP=`/sbin/get_domain_ip ${Remote_IP}`
if [ "$bAbort" -eq "0" ]; then
if [ "$DEBUG" = "yes" ]; then
echo "Debuging mode"
# /usr/bin/rsync -a ${RR_options} --timeout=0 --port=873 --qnap_log_file="${LOG_FILE_NAME}" "${RR_local_path}/" ${Remote_IP}::"${RR_remote_path}" -v -v -v
# /usr/bin/rsync -a ${RR_options} --timeout=0 --port=873 "${RR_local_path}/" ${Remote_IP}::"${RR_remote_path}" -v -v -v
# /usr/bin/rsync -a ${RR_options} --password="${Passwd}" --timeout=0 --port=873 "${RR_local_path}" "${UserName}"@${Remote_IP}::"${RR_remote_path}" -v -v -v
if [ "x${RR_opt_SSH}" = "xTRUE" ]; then
modify_known_hosts
LC_ALL=en_US.UTF-8 /usr/bin/rsync -H -a --sever-mode=${RR_MODE} -e "${RR_com_ssh}" ${RR_options} --exclude=':2eDS_Store' --exclude='.AppleDB/' --exclude='.AppleDesktop/' --exclude='.AppleDouble/' --schedule="$1" --password="${Passwd}" --timeout=${xsTimeout} "${RR_local_path}/" "${UserName}"@[${Remote_IP}]::"${RR_remote_path}" -v -v -v 1>${SZF_OUTPUT} 2>"$SZF_ERROR_TMP"
else
LC_ALL=en_US.UTF-8 /usr/bin/rsync -H -a --sever-mode=${RR_MODE} ${RR_options} --exclude=':2eDS_Store' --exclude='.AppleDB/' --exclude='.AppleDesktop/' --exclude='.AppleDouble/' --schedule="$1" --password="${Passwd}" --timeout=${xsTimeout} --port=${RR_PORT} "${RR_local_path}/" "${UserName}"@[${Remote_IP}]::"${RR_remote_path}" -v -v -v 1>${SZF_OUTPUT} 2>"$SZF_ERROR_TMP"
fi
else
echo "Normal mode"
# /usr/bin/rsync -a ${RR_options} --timeout=0 --port=873 --qnap_log_file="${LOG_FILE_NAME}" "${RR_local_path}/" ${Remote_IP}::"${RR_remote_path}"
# /usr/bin/rsync -a ${RR_options} --timeout=0 --port=873 "${RR_local_path}/" ${Remote_IP}::"${RR_remote_path}"
# /usr/bin/rsync -a ${RR_options} --password="${Passwd}" --timeout=0 --port=873 "${RR_local_path}" "${UserName}"@${Remote_IP}::"${RR_remote_path}"
if [ "x${RR_opt_SSH}" = "xTRUE" ]; then
modify_known_hosts
LC_ALL=en_US.UTF-8 /usr/bin/rsync -H -a --sever-mode=${RR_MODE} -e "${RR_com_ssh}" ${RR_options} --exclude=':2eDS_Store' --exclude='.AppleDB/' --exclude='.AppleDesktop/' --exclude='.AppleDouble/' --schedule="$1" --password="${Passwd}" --timeout=${xsTimeout} "${RR_local_path}/" "${UserName}"@[${Remote_IP}]::"${RR_remote_path}" 1>${SZF_OUTPUT} 2>"$SZF_ERROR_TMP"
else
LC_ALL=en_US.UTF-8 /usr/bin/rsync -H -a --sever-mode=${RR_MODE} ${RR_options} --exclude=':2eDS_Store' --exclude='.AppleDB/' --exclude='.AppleDesktop/' --exclude='.AppleDouble/' --schedule="$1" --password="${Passwd}" --timeout=${xsTimeout} --port=${RR_PORT} "${RR_local_path}/" "${UserName}"@[${Remote_IP}]::"${RR_remote_path}" 1>${SZF_OUTPUT} 2>"$SZF_ERROR_TMP"
fi
fi
# report errors to log
RR_result=$?
/sbin/setcfg "$RR_sche" "PID" "0" -f "${RR_CONF}"
Filter_Log_Msg "$SZF_ERROR_TMP" "$SZF_ERROR"
else
RR_result="137"
fi
/bin/rm -f $SZF_ERROR_TMP
# rsync is stopped by kill
if [ "137" == "$RR_result" ]; then
echo "rsync: cancelled by user" > "$SZF_ERROR"
fi
[ "$DEBUG" = "yes" ] && echo "log file = ${LOG_FILE_NAME}"
if [ "$iRetry" -gt "$xnRetry" ]; then
szRetry=""
elif [ "$iRetry" -eq 1 ]; then
szRetry=" Begin 1st retry."
elif [ "$iRetry" -eq 2 ]; then
szRetry=" Begin 2nd retry."
elif [ "$iRetry" -eq 3 ]; then
szRetry=" Begin 3rd retry."
else
szRetry=" Begin ${iRetry}th retry."
fi
#report_error
Update_Status "$1" "$szUser" "$szAddr" "$szHost" "$szRetry"
[ -f "${LOG_FILE_NAME}" -a "$DEBUG" = "no" ] && /bin/rm "${LOG_FILE_NAME}"
# Don't retry on the following cases.
if [ "$iError" -eq 0 ] || [ "$iError" -eq 43 ] || [ "$iError" -eq 44 ] || [ "$iError" -eq 48 ] || [ "$iError" -eq 49 ] || [ "$iError" -eq 50 ]; then
break
fi
# Sleep a while before the next try.
/sbin/setcfg "$RR_sche" "Retry" "$iRetry" -f "${RR_CONF}"
if [ $iRetry -le "$xnRetry" ] && [ "$xsInterval" -gt 0 ]; then
iInterval=$xsInterval
while [ $iInterval -gt 0 ]
do
if [ "$bAbort" -ne "0" ]; then
break
fi
/sbin/setcfg "$RR_sche" "RemainTime" "$iInterval" -f "${RR_CONF}"
if [ $iInterval -gt 4 ]; then
iInterval=$(($iInterval-5))
/bin/sleep 5
else
iInterval=$(($iInterval-1))
/bin/sleep 1
fi
done
/sbin/setcfg "$RR_sche" "RemainTime" "$iInterval" -f "${RR_CONF}"
fi
done
[ "x${RR_opt_stopnet}" = "xTRUE" ] && start_network
# Clear PID and ScriptPID before exit.
/sbin/setcfg "$RR_sche" "PID" "0" -f "${RR_CONF}"
/sbin/setcfg "$RR_sche" "ScriptPID" "0" -f "${RR_CONF}"

52
rsyncd.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/sh
start()
{
[ -f /etc/config/rsyncd.conf ] || /etc/init.d/rsyncd_srv.sh
[ -f /etc/config/rsync_schedule.conf ] || echo "" > /etc/config/rsync_schedule.conf
if [ `/sbin/getcfg System "Rsync Support" -u -d FALSE` = TRUE ]; then
[ -f /var/run/rsyncd.pid ] && /bin/rm -f /var/run/rsyncd.pid
echo "Starting rsync services: rsync."
# Always launching rsyncd in server mode 1.
#if [ `/sbin/getcfg "System" "Rsync Model" -u -d QNAP` = NORMAL ]; then
#/sbin/daemon_mgr rsync start "/usr/bin/rsyncd --daemon --sever-mode=0"
#/usr/bin/rsyncd --daemon --sever-mode=0 &
#else
#/sbin/daemon_mgr rsync start "/usr/bin/rsyncd --daemon --sever-mode=1"
/usr/bin/rsyncd --daemon --sever-mode=1 --qnap-bwlimit &
#fi
fi
}
stop()
{
echo "Shutting down rsync services: rsync."
#/sbin/daemon_mgr rsync stop "/sbin/rsync --daemon"
# /bin/kill -9 `/bin/cat /var/run/rsyncd.pid`
/bin/kill -9 `/bin/pidof rsyncd`
/bin/kill -9 `/bin/pidof rsync`
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
*)
echo "Usage: /etc/init.d/rsyncd.sh {start|stop|restart}"
exit 1
esac
exit 0

34
rsyncd_srv.sh Executable file
View File

@@ -0,0 +1,34 @@
#!/bin/sh
RSYNCD_CONF="/etc/config/rsyncd.conf"
#RSYNC_SCHEDULE_CONF="/etc/config/rsync_schedule.conf"
rsyncd_port=`/sbin/getcfg "" "port" -f "${RSYNCD_CONF}" -d "873"`
rsyncd_user=`/sbin/getcfg "" "rsync user" -f "${RSYNCD_CONF}" -d "rsync"`
rsyncd_pswd=`/sbin/getcfg "" "rsync pswd" -f "${RSYNCD_CONF}" -d ""`
rsyncd_slimitrate=`/sbin/getcfg "" "SLimitRate" -f "${RSYNCD_CONF}" -d ""`
rsyncd_rlimitrate=`/sbin/getcfg "" "RLimitRate" -f "${RSYNCD_CONF}" -d ""`
echo "uid = admin" > ${RSYNCD_CONF}
echo "gid = administrators" >> ${RSYNCD_CONF}
#echo "log file = /var/log/rsyncd.log" >> ${RSYNCD_CONF}
echo "pid file = /var/run/rsyncd.pid" >> ${RSYNCD_CONF}
echo "read only = false" >> ${RSYNCD_CONF}
echo "hosts allow = *" >> ${RSYNCD_CONF}
echo "port = ${rsyncd_port}" >> ${RSYNCD_CONF}
echo "rsync user = ${rsyncd_user}" >> ${RSYNCD_CONF}
echo "rsync pswd = ${rsyncd_pswd}" >> ${RSYNCD_CONF}
echo "SLimitRate = ${rsyncd_slimitrate}" >> ${RSYNCD_CONF}
echo "RLimitRate = ${rsyncd_rlimitrate}" >> ${RSYNCD_CONF}
echo >> ${RSYNCD_CONF}
tmp_smb_conf="/tmp/smb.conf.`date +%s`"
/bin/cp /etc/smb.conf ${tmp_smb_conf}
share_list="/tmp/share_list.`date +%s`"
/bin/sed -n 's/^\[\(.*\)\]/\1/p' ${tmp_smb_conf} | /bin/grep global -v | /bin/grep printer -v > ${share_list}
while read LINE
do
share_path=`/sbin/getcfg "${LINE}" "path" -f ${tmp_smb_conf} -d ""`
[ "x${share_path}" = "x" ] || /sbin/setcfg "${LINE}" "path" "${share_path}" -f ${RSYNCD_CONF}
done < ${share_list}
/bin/rm -f ${tmp_smb_conf} ${share_list}

119
rsyslog.sh Executable file
View File

@@ -0,0 +1,119 @@
#/bin/sh
# Copyright @ 2009 QNAP Systems Inc.
GETCFG="/sbin/getcfg"
SETCFG="/sbin/setcfg"
DAEMON_MGR="/sbin/daemon_mgr"
volume_test="HDA_DATA"
volume="HDA_DATA"
CONFIG_FILE="/etc/rsyslog.conf"
MAILDIR="/var/syslog_maildir"
ret_val=0
init_settings()
{
[ -d ${MAILDIR} ] || /bin/mkdir -p ${MAILDIR}
/bin/mount | /bin/grep "${MAILDIR}"
[ $? = 0 ] || /bin/mount -t tmpfs tmpfs ${MAILDIR} -o size=8M
/bin/chmod 777 ${MAILDIR}
/sbin/rsyslog_util init
ret_val=$?
[ -d "/tmp/rsyslog" ] || /bin/mkdir "/tmp/rsyslog"
}
start()
{
[ -f "/usr/sbin/rsyslogd" ] || exit 1
if [ `$GETCFG "Global" "Enable" -d "False" -f "/etc/config/syslog_server.conf"` != "TRUE" ]; then
/bin/echo "rsyslogd is not Enabled."
exit 1
fi
SyslogShareName=`$GETCFG "Global" "log file share" -d "Download" -f "/etc/config/syslog_server.conf"`
SyslogSharePath=`$GETCFG "${SyslogShareName}" "path" -f "/etc/config/smb.conf"`
if [ "x${SyslogSharePath}" = x ] || [ ! -d "${SyslogSharePath}" ]; then
#/sbin/write_log "[Syslog Server] Log file path does not exist." 2
/bin/echo "[Syslog Server] Log file path does not exist."
exit 1
fi
SyslogFilePath=`$GETCFG "Global" "log file path" -d "" -f "/etc/config/syslog_server.conf"`
if [ "x${SyslogFilePath}" != x ] && [ ! -f "${SyslogSharePath}/${SyslogFilePath}" ]; then
/bin/echo "${SyslogSharePath}/${SyslogFilePath} does not exist."
/bin/mkdir -p "${SyslogSharePath}/${SyslogFilePath}"
/bin/rm -rf "${SyslogSharePath}/${SyslogFilePath}"
fi
if [ -f "/var/run/rsyslogd.pid" ]; then
/bin/echo "rsyslogd aleardy running."
exit 1
fi
/bin/echo $"Starting rsyslog: "
init_settings
if [ ${ret_val} != 0 ]; then
/bin/echo "rsyslogd can't init."
exit 1
fi
$DAEMON_MGR rsyslogd start "/usr/sbin/rsyslogd -f $CONFIG_FILE -c4 -M /usr/local/lib/rsyslog/"
$DAEMON_MGR syslog_maild start "/sbin/syslog_maild -d"
}
stop()
{
/bin/echo $"Shutting down rsyslog: "
$DAEMON_MGR rsyslogd stop "/usr/sbin/rsyslogd -f $CONFIG_FILE -c4 -M /usr/local/lib/rsyslog/"
/bin/sleep 2
if [ -f "/var/run/rsyslogd.pid" ]; then
/bin/kill `/bin/cat /var/run/rsyslogd.pid` 1>>/dev/null 2>>/dev/null
/bin/kill `/sbin/pidof rsyslogd` 1>>/dev/null 2>>/dev/null
/bin/sleep 2
/bin/rm -f /var/run/rsyslogd.pid
fi
$DAEMON_MGR syslog_maild stop "/sbin/syslog_maild -d"
/bin/kill `/bin/pidof syslog_maild` 1>>/dev/null 2>>/dev/null
}
restart()
{
stop
/bin/sleep 1
start
}
reload()
{
/bin/echo $"Reloading rsyslog: "
if [ -f "/var/run/rsyslogd.pid" ]; then
/sbin/rsyslog_util init
/bin/sleep 1
/bin/kill -SIGHUP `/bin/cat /var/run/rsyslogd.pid`
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
*)
/bin/echo $"Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0

17
runone.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/sh
# run all script in /etc/config/runone
# after finish, rm all files in /etc/config/runone
for i in /etc/config/runone/* ;do
case "$i" in
*.sh)
echo run [$i]
$i
/bin/rm $i
;;
*)
echo "[$i] do nothing"
;;
esac
done

125
services.sh Executable file
View File

@@ -0,0 +1,125 @@
#!/bin/sh
NSS_ENABLED=`/sbin/getcfg NVR "NSS Enabled" -d no`
SERVICES="recycled.sh mysqld.sh atalk.sh ftp.sh bt_scheduler.sh btd.sh StartMediaService.sh ImRd.sh init_iTune.sh twonkymedia.sh Qthttpd.sh crond.sh nfs smb.sh lunportman.sh iscsitrgt.sh nvrd.sh snmp rsyslog.sh qsyncman.sh iso_mount.sh init_mozyclient.sh antivirus.sh ldap_server.sh vpn_pptp.sh vpn_openvpn.sh cloud3p.sh"
SERVICES_STOP="cloud3p.sh vpn_openvpn.sh vpn_pptp.sh ldap_server.sh antivirus.sh init_mozyclient.sh iso_mount.sh qsyncman.sh rsyslog.sh snmp nvrd.sh lunportman.sh iscsitrgt.sh smb.sh nfs crond.sh Qthttpd.sh twonkymedia.sh init_iTune.sh ImRd.sh StartMediaService.sh bt_scheduler.sh btd.sh ftp.sh atalk.sh mysqld.sh recycled.sh"
Other_Services()
{
if [ -z "$1" ] || ([ "$1" != start ] && [ "$1" != stop ]); then
return
fi
#service list
[ -f /etc/init.d/init_symform.sh ] && /etc/init.d/init_symform.sh $1
}
case "$1" in
start)
echo -n "Start services: "
[ ! -f "/tmp/quick_format.flag" ] || exit 0
for i in $SERVICES
do
if [ -f /etc/init.d/$i ]; then
echo -n "$i "
if [ "x$i" = "xnvrd.sh" ]; then
#echo "`date`" "begin service.sh start $i" >> /tmp/nvrd_dbg
if [ "x${NSS_ENABLED}" = "xyes" ]; then
if [ "`/etc/init.d/nvrd.sh started`" == "1" ]; then
/etc/init.d/$i _start 2>/dev/null 1>/dev/null
fi
else
/etc/init.d/$i start 2>/dev/null 1>/dev/null
fi
#echo "`date`" "begin service.sh start $i" >> /tmp/nvrd_dbg
else
/etc/init.d/$i start 2>/dev/null 1>/dev/null
fi
fi
done
echo .
$0 qpkg_start
Other_Services start
;;
stop)
Other_Services stop
$0 qpkg_stop
echo -n "Stop service: "
for i in $SERVICES_STOP
do
if [ -f /etc/init.d/$i ]; then
echo -n "$i "
if [ "x$i" = "xnvrd.sh" ]; then
#echo "`date`" "begin service.sh stop $i" >> /tmp/nvrd_dbg
if [ "x${NSS_ENABLED}" = "xyes" ]; then
if [ "`/etc/init.d/nvrd.sh started`" == "1" ]; then
/etc/init.d/$i _stop 2>/dev/null 1>/dev/null
fi
else
/etc/init.d/$i stop 2>/dev/null 1>/dev/null
fi
#echo "`date`" "end service.sh stop $i" >> /tmp/nvrd_dbg
else
/etc/init.d/$i stop 2>/dev/null 1>/dev/null
fi
fi
done
echo .
. /etc/init.d/check_nss2
if [ ! -f "/tmp/quick_format.flag" ] && [ "x$_NSS2_SUPPORT" = "xyes" ]; then
/etc/init.d/thttpd.sh restart 2>/dev/null 1>/dev/null
fi
;;
qpkg_start)
echo -n "Start qpkg service: "
for i in /etc/rcS.d/QS??* ;do
[ -f "$i" ] || continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
[ -f $i ] && $i start
;;
esac
done
echo .
;;
qpkg_stop)
echo -n "Stop qpkg service: "
for i in /etc/rcK.d/QK??* ;do
[ -f "$i" ] || continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set stop
. $i
)
;;
*)
# No sh extension, so fork subprocess.
[ -f $i ] && $i stop
;;
esac
done
echo .
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/services.sh {start|stop|restart}"
exit 1
esac
exit 0

395
set_mtu.sh Executable file
View File

@@ -0,0 +1,395 @@
#!/bin/sh
GETCFG="/sbin/getcfg"
SETCFG="/sbin/setcfg"
BOND_SUP=`$GETCFG "Network" "BONDING Support" -d "FALSE"`
IF_NUM=`$GETCFG "Network" "Interface Number" -d "1"`
set_mtu()
{
/bin/sleep 7
local MTU=`$GETCFG eth0 MTU -d 1500`
/bin/echo "[eth0]" > /tmp/NowSpeed
/sbin/eth_util eth0 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth0 "Speed of eth0" -f /tmp/NowSpeed`
if [ "$SPEED" = "1000" ]; then
/sbin/ifconfig eth0 mtu $MTU
else
/sbin/ifconfig eth0 mtu 1500
if [ ! "$MTU" = "1500" ]; then
$SETCFG eth0 MTU 1500
/sbin/write_log "Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
}
set_mtu_2lan()
{
/bin/sleep 12
if [ "$BOND_SUP" = "TRUE" ]; then
local MTU=`$GETCFG bond0 MTU -d 1500`
local STATUS1=`/bin/cat /sys/class/net/eth0/operstate`
local STATUS2=`/bin/cat /sys/class/net/eth1/operstate`
if [ "$STATUS1" = "up" ]; then
/bin/echo "[eth0]" > /tmp/NowSpeed
/sbin/eth_util eth0 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth0 "Speed of eth0" -f /tmp/NowSpeed`
elif [ "$STATUS2" = "up" ]; then
/bin/echo "[eth1]" > /tmp/NowSpeed
/sbin/eth_util eth1 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth1 "Speed of eth1" -f /tmp/NowSpeed`
else
local SPEED=`$GETCFG bond0 Speed -d "auto"`
/bin/echo "[Lan 1] $STATUS1 [Lan2] $STATUS2 [bond0 Speed] $SPEED"
if [ "$SPEED" = "auto" ]; then
SPEED="1000"
fi
fi
if [ "$SPEED" = "1000" ]; then
/sbin/ifconfig bond0 mtu $MTU
else
/sbin/ifconfig bond0 mtu 1500
fi
if [ ! "$SPEED" = "1000" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG bond0 MTU 1500`
/sbin/write_log "Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
else
local STATUS=`/bin/cat /sys/class/net/eth0/operstate`
if [ "$STATUS" = "up" ]; then
local MTU=`$GETCFG eth0 MTU -d 1500`
/bin/echo "[eth0]" > /tmp/NowSpeed
/sbin/eth_util eth0 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth0 "Speed of eth0" -f /tmp/NowSpeed`
if [ "$SPEED" = "1000" ]; then
/sbin/ifconfig eth0 mtu $MTU
else
/sbin/ifconfig eth0 mtu 1500
fi
if [ ! "$SPEED" = "1000" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG eth0 MTU 1500`
/sbin/write_log "LAN 1 Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
STATUS=`/bin/cat /sys/class/net/eth1/operstate`
if [ "$STATUS" = "up" ]; then
MTU=`$GETCFG eth1 MTU -d 1500`
/bin/echo "[eth1]" >> /tmp/NowSpeed
/sbin/eth_util eth1 >> /tmp/NowSpeed
SPEED=`$GETCFG eth1 "Speed of eth1" -f /tmp/NowSpeed`
if [ "$SPEED" = "1000" ]; then
/sbin/ifconfig eth1 mtu $MTU
else
/sbin/ifconfig eth1 mtu 1500
fi
if [ ! "$SPEED" = "1000" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG eth1 MTU 1500`
/sbin/write_log "LAN 2 Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
fi
}
set_mtu_4lan()
{
/bin/sleep 12
if [ "$BOND_SUP" = "TRUE" ]; then
local MTU=`$GETCFG bond0 MTU -d 1500`
local MTU1=`$GETCFG bond1 MTU -d 1500`
local STATUS1=`/bin/cat /sys/class/net/eth0/operstate`
local STATUS2=`/bin/cat /sys/class/net/eth1/operstate`
local STATUS3=`/bin/cat /sys/class/net/eth2/operstate`
local STATUS4=`/bin/cat /sys/class/net/eth3/operstate`
/bin/rm /tmp/NowSpeed
if [ "$BOND_NIC" = "0" ]; then
if [ "$STATUS1" = "up" ]; then
/bin/echo "[eth0]" >> /tmp/NowSpeed
/sbin/eth_util eth0 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth0 "Speed of eth0" -f /tmp/NowSpeed`
elif [ "$STATUS2" = "up" ]; then
/bin/echo "[eth1]" >> /tmp/NowSpeed
/sbin/eth_util eth1 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth1 "Speed of eth1" -f /tmp/NowSpeed`
else
local SPEED=`$GETCFG bond0 Speed -d "auto"`
/bin/echo "[Lan 1] $STATUS1 [Lan2] $STATUS2 [bond0 Speed] $SPEED"
if [ "$SPEED" = "auto" ]; then
SPEED="1000"
fi
fi
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig bond0 mtu 1500
else
/sbin/ifconfig bond0 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG bond0 MTU 1500`
/sbin/write_log "Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
if [ "$NIC_NUM" = "4" ]; then
STATUS=`/bin/cat /sys/class/net/eth2/operstate`
if [ "$STATUS" = "up" ]; then
MTU=`$GETCFG eth2 MTU -d 1500`
/bin/echo "[eth2]" >> /tmp/NowSpeed
/sbin/eth_util eth2 >> /tmp/NowSpeed
SPEED=`$GETCFG eth2 "Speed of eth2" -f /tmp/NowSpeed`
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig eth2 mtu 1500
else
/sbin/ifconfig eth2 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG eth2 MTU 1500`
/sbin/write_log "LAN 3 Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
STATUS=`/bin/cat /sys/class/net/eth3/operstate`
if [ "$STATUS" = "up" ]; then
MTU=`$GETCFG eth3 MTU -d 1500`
/bin/echo "[eth3]" >> /tmp/NowSpeed
/sbin/eth_util eth3 >> /tmp/NowSpeed
SPEED=`$GETCFG eth3 "Speed of eth3" -f /tmp/NowSpeed`
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig eth3 mtu 1500
else
/sbin/ifconfig eth3 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG eth1 MTU 1500`
/sbin/write_log "LAN 4 Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
fi
elif [ "$BOND_NIC" = "1" ]; then
STATUS=`/bin/cat /sys/class/net/eth0/operstate`
/bin/rm /tmp/NowSpeed
if [ "$STATUS" = "up" ]; then
MTU=`$GETCFG eth0 MTU -d 1500`
/bin/echo "[eth0]" >> /tmp/NowSpeed
/sbin/eth_util eth0 >> /tmp/NowSpeed
SPEED=`$GETCFG eth0 "Speed of eth0" -f /tmp/NowSpeed`
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig eth0 mtu 1500
else
/sbin/ifconfig eth0 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG eth0 MTU 1500`
/sbin/write_log "LAN 1 Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
STATUS=`/bin/cat /sys/class/net/eth1/operstate`
if [ "$STATUS" = "up" ]; then
MTU=`$GETCFG eth1 MTU -d 1500`
/bin/echo "[eth1]" >> /tmp/NowSpeed
/sbin/eth_util eth1 >> /tmp/NowSpeed
SPEED=`$GETCFG eth1 "Speed of eth1" -f /tmp/NowSpeed`
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig eth1 mtu 1500
else
/sbin/ifconfig eth1 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG eth1 MTU 1500`
/sbin/write_log "LAN 2 Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
MTU=`$GETCFG bond0 MTU -d 1500`
if [ "$STATUS3" = "up" ]; then
/bin/echo "[eth2]" >> /tmp/NowSpeed
/sbin/eth_util eth2 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth2 "Speed of eth2" -f /tmp/NowSpeed`
elif [ "$STATUS4" = "up" ]; then
/bin/echo "[eth3]" >> /tmp/NowSpeed
/sbin/eth_util eth3 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth3 "Speed of eth3" -f /tmp/NowSpeed`
else
local SPEED=`$GETCFG bond0 Speed -d "auto"`
/bin/echo "[Lan 3] $STATUS3 [Lan4] $STATUS4 [bond0 Speed] $SPEED"
if [ "$SPEED" = "auto" ]; then
SPEED="1000"
fi
fi
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig bond0 mtu 1500
else
/sbin/ifconfig bond0 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG bond0 MTU 1500`
/sbin/write_log "Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
elif [ "$BOND_NIC" = "2" ]; then
if [ "$STATUS1" = "up" ]; then
/bin/echo "[eth0]" >> /tmp/NowSpeed
/sbin/eth_util eth0 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth0 "Speed of eth0" -f /tmp/NowSpeed`
elif [ "$STATUS2" = "up" ]; then
/bin/echo "[eth1]" >> /tmp/NowSpeed
/sbin/eth_util eth1 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth1 "Speed of eth1" -f /tmp/NowSpeed`
else
local SPEED=`$GETCFG bond0 Speed -d "auto"`
/bin/echo "[Lan 1] $STATUS1 [Lan2] $STATUS2 [bond0 Speed] $SPEED"
if [ "$SPEED" = "auto" ]; then
SPEED="1000"
fi
fi
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig bond0 mtu 1500
else
/sbin/ifconfig bond0 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG bond0 MTU 1500`
/sbin/write_log "Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
if [ "$STATUS3" = "up" ]; then
/bin/echo "[eth2]" >> /tmp/NowSpeed
/sbin/eth_util eth2 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth2 "Speed of eth2" -f /tmp/NowSpeed`
elif [ "$STATUS4" = "up" ]; then
/bin/echo "[eth3]" >> /tmp/NowSpeed
/sbin/eth_util eth3 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth3 "Speed of eth3" -f /tmp/NowSpeed`
else
local SPEED=`$GETCFG bond0 Speed -d "auto"`
/bin/echo "[Lan 3] $STATUS3 [Lan4] $STATUS4 [bond1 Speed] $SPEED"
if [ "$SPEED" = "auto" ]; then
SPEED="1000"
fi
fi
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig bond1 mtu 1500
else
/sbin/ifconfig bond1 mtu $MTU1
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU1" = "1500" ]; then
`$SETCFG bond1 MTU 1500`
/sbin/write_log "Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
elif [ "$BOND_NIC" = "3" ]; then
if [ "$STATUS1" = "up" ]; then
/bin/echo "[eth0]" >> /tmp/NowSpeed
/sbin/eth_util eth0 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth0 "Speed of eth0" -f /tmp/NowSpeed`
elif [ "$STATUS2" = "up" ]; then
/bin/echo "[eth1]" > /tmp/NowSpeed
/sbin/eth_util eth1 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth1 "Speed of eth1" -f /tmp/NowSpeed`
elif [ "$STATUS3" = "up" ]; then
/bin/echo "[eth2]" > /tmp/NowSpeed
/sbin/eth_util eth2 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth2 "Speed of eth2" -f /tmp/NowSpeed`
elif [ "$STATUS4" = "up" ]; then
/bin/echo "[eth3]" > /tmp/NowSpeed
/sbin/eth_util eth3 >> /tmp/NowSpeed
local SPEED=`$GETCFG eth3 "Speed of eth3" -f /tmp/NowSpeed`
else
local SPEED=`$GETCFG bond0 Speed -d "auto"`
/bin/echo "[Lan 1] $STATUS1 [Lan2] $STATUS2 [bond0 Speed] $SPEED"
if [ "$SPEED" = "auto" ]; then
SPEED="1000"
fi
fi
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig bond0 mtu 1500
else
/sbin/ifconfig bond0 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG bond0 MTU 1500`
/sbin/write_log "Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
else
/bin/echo "network error: BONDING NICs unmatched"
fi
else
local STATUS=`/bin/cat /sys/class/net/eth0/operstate`
/bin/rm /tmp/NowSpeed
if [ "$STATUS" = "up" ]; then
MTU=`$GETCFG eth0 MTU -d 1500`
/bin/echo "[eth0]" >> /tmp/NowSpeed
/sbin/eth_util eth0 >> /tmp/NowSpeed
SPEED=`$GETCFG eth0 "Speed of eth0" -f /tmp/NowSpeed`
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig eth0 mtu 1500
else
/sbin/ifconfig eth0 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG eth0 MTU 1500`
/sbin/write_log "LAN 1 Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
STATUS=`/bin/cat /sys/class/net/eth1/operstate`
if [ "$STATUS" = "up" ]; then
MTU=`$GETCFG eth1 MTU -d 1500`
/bin/echo "[eth1]" >> /tmp/NowSpeed
/sbin/eth_util eth1 >> /tmp/NowSpeed
SPEED=`$GETCFG eth1 "Speed of eth1" -f /tmp/NowSpeed`
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig eth1 mtu 1500
else
/sbin/ifconfig eth1 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG eth1 MTU 1500`
/sbin/write_log "LAN 2 Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
if [ "$NIC_NUM" = "4" ]; then
STATUS=`/bin/cat /sys/class/net/eth2/operstate`
if [ "$STATUS" = "up" ]; then
MTU=`$GETCFG eth2 MTU -d 1500`
/bin/echo "[eth2]" >> /tmp/NowSpeed
/sbin/eth_util eth2 >> /tmp/NowSpeed
SPEED=`$GETCFG eth2 "Speed of eth2" -f /tmp/NowSpeed`
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig eth2 mtu 1500
else
/sbin/ifconfig eth2 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG eth2 MTU 1500`
/sbin/write_log "LAN 3 Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
STATUS=`/bin/cat /sys/class/net/eth3/operstate`
if [ "$STATUS" = "up" ]; then
MTU=`$GETCFG eth3 MTU -d 1500`
/bin/echo "[eth3]" >> /tmp/NowSpeed
/sbin/eth_util eth3 >> /tmp/NowSpeed
SPEED=`$GETCFG eth3 "Speed of eth3" -f /tmp/NowSpeed`
if [ "$SPEED" = "100" ]; then
/sbin/ifconfig eth3 mtu 1500
else
/sbin/ifconfig eth3 mtu $MTU
fi
if [ "$SPEED" = "100" ] && [ ! "$MTU" = "1500" ]; then
`$SETCFG eth1 MTU 1500`
/sbin/write_log "LAN 4 Jumbo Frame is disabled because the connection speed is not Gigabit." 1
fi
fi
fi
fi
}
case $IF_NUM in
1)
set_mtu
;;
2)
set_mtu_2lan
;;
4)
set_mtu_4lan
;;
*)
echo "IF_NUM = $IF_NUM ,not support"
exit 1
esac
exit 0

Some files were not shown because too many files have changed in this diff Show More