commit 8e3af042d26a48a04741a7724b8920161cd6a18f Author: eleksir Date: Sun Sep 4 22:20:40 2016 +0300 Add original scripts diff --git a/ImRd.sh b/ImRd.sh new file mode 100755 index 0000000..5d3bbf6 --- /dev/null +++ b/ImRd.sh @@ -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 diff --git a/Qthttpd.sh b/Qthttpd.sh new file mode 100755 index 0000000..3018d66 --- /dev/null +++ b/Qthttpd.sh @@ -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 "^" ${APACHE_CONF} 1>/dev/null 2>/dev/null + [ $? = 0 ] || /bin/sed -i 's/^"'/' ${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 "^" ${APACHE_CONF_DIR}/extra/apache-ssl.conf 1>>/dev/null 2>>/dev/null + [ $? = 0 ] || /bin/sed -i 's/^"'/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 2>/dev/null >/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 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 diff --git a/StartMediaService.sh b/StartMediaService.sh new file mode 100755 index 0000000..a54a791 --- /dev/null +++ b/StartMediaService.sh @@ -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 + + + diff --git a/_check_nss2 b/_check_nss2 new file mode 100755 index 0000000..a1438ab --- /dev/null +++ b/_check_nss2 @@ -0,0 +1,4 @@ +#!/bin/sh + +_NSS2_SUPPORT=yes + diff --git a/ads_register_dns.sh b/ads_register_dns.sh new file mode 100755 index 0000000..e0c3810 --- /dev/null +++ b/ads_register_dns.sh @@ -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 + diff --git a/antivirus.sh b/antivirus.sh new file mode 100755 index 0000000..c2950b8 --- /dev/null +++ b/antivirus.sh @@ -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 diff --git a/atalk.sh b/atalk.sh new file mode 100755 index 0000000..764fe69 --- /dev/null +++ b/atalk.sh @@ -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 diff --git a/avahi.sh b/avahi.sh new file mode 100755 index 0000000..22dac06 --- /dev/null +++ b/avahi.sh @@ -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__ + + + +$BROWSENAME + +_http._tcp +${WEB_PORT} +path=/ + + +__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__ + + + +$BROWSENAME + +_smb._tcp +445 + + +__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__ + + + +$BROWSENAME + +_afpovertcp._tcp +548 + + +_device-info._tcp +0 +model=Mac + + +__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__ + + + +$BROWSENAME + +_ssh._tcp +${SSH_PORT} + + +__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__ + + + +$BROWSENAME + +_ftp._tcp +${FTP_PORT} +model=path=/ + + +__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__ + + + +$BROWSENAME + +_https._tcp +${HTTPS_PORT} +model=path=/ + + +__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__ + + + +$BROWSENAME + +_upnp._tcp +${UPNP_PORT} + + +__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__ + + + +$BROWSENAME + +_qmobile._tcp +${QMOBILE_PORT} + + +__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__ + + + +$BROWSENAME + +_qdiscover._tcp +${WEB_PORT} +$qTXT + + +__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__ + + + +$HOSTNAME(iTunes) + +_daap._tcp +3689 +txtvers=1 +Machine Name=$HOSTNAME(iTunes) +Database ID=${_iTunes_ID} +iTSh Version=131073 +Version=196610 +Passowrd=${_Passowrd} + + + +__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__ + + + +%h(csco) + +_csco-sb._tcp +${WEB_PORT} +version=1.0 +model=${model_name} +deviceType=NAS +deviceDescr=Cisco NSS ${devicedescr} Smart Storage +fmVersion=$fmVersion +PIDVID=${model_name} V${vid} +MACAddress=${MACAddress} +serialNo=${serialNo} +hostname=${hostname} +MDFID=${mdf_id} +accessType=${accesstype} + + + +__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__ + + + +%h(Airprint) + +_ipp._tcp +_universal._sub._ipp._tcp +$printer_port +txtvers=1 +qtotal=1 +priority=0 +rp=printers/$printer_name +ty=$manufacture $model +note=$manufacture $model +product=(GPL Ghostscript) +pdl=application/pdf,application/postscript,application/vnd.cups-raster,application/octet-stream,image/png +URF=none + + + +__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 diff --git a/backup2nas.sh b/backup2nas.sh new file mode 100755 index 0000000..386aa28 --- /dev/null +++ b/backup2nas.sh @@ -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 + diff --git a/backup_conf.sh b/backup_conf.sh new file mode 100755 index 0000000..11b2153 --- /dev/null +++ b/backup_conf.sh @@ -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 diff --git a/boot_done.sh b/boot_done.sh new file mode 100755 index 0000000..a304111 --- /dev/null +++ b/boot_done.sh @@ -0,0 +1,6 @@ +#!/bin/sh +/bin/sleep 20 +/bin/touch /tmp/.boot_done + +exit 0 + diff --git a/bt_scheduler.sh b/bt_scheduler.sh new file mode 100755 index 0000000..89b82c2 --- /dev/null +++ b/bt_scheduler.sh @@ -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 diff --git a/btd.sh b/btd.sh new file mode 100755 index 0000000..92dfc50 --- /dev/null +++ b/btd.sh @@ -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 + diff --git a/cacd.sh b/cacd.sh new file mode 100755 index 0000000..a22ba35 --- /dev/null +++ b/cacd.sh @@ -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 diff --git a/check_bootcmd.sh b/check_bootcmd.sh new file mode 100755 index 0000000..2d23d66 --- /dev/null +++ b/check_bootcmd.sh @@ -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 + diff --git a/check_ddns_external_ip.sh b/check_ddns_external_ip.sh new file mode 100755 index 0000000..28650e0 --- /dev/null +++ b/check_ddns_external_ip.sh @@ -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 diff --git a/check_lan_port.sh b/check_lan_port.sh new file mode 100755 index 0000000..bce7cd8 --- /dev/null +++ b/check_lan_port.sh @@ -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 diff --git a/check_nss2 b/check_nss2 new file mode 100755 index 0000000..2cead4f --- /dev/null +++ b/check_nss2 @@ -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 diff --git a/chkcfgpart.sh b/chkcfgpart.sh new file mode 100755 index 0000000..f8608bb --- /dev/null +++ b/chkcfgpart.sh @@ -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 diff --git a/cloud3p.sh b/cloud3p.sh new file mode 100755 index 0000000..be978f2 --- /dev/null +++ b/cloud3p.sh @@ -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 diff --git a/crond.sh b/crond.sh new file mode 100755 index 0000000..1977bc3 --- /dev/null +++ b/crond.sh @@ -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 diff --git a/cupsd.sh b/cupsd.sh new file mode 100755 index 0000000..fe51695 --- /dev/null +++ b/cupsd.sh @@ -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 "#" >> /etc/config/cups/cupsd.conf + echo "# Order allow,deny" >> /etc/config/cups/cupsd.conf + echo "# allow all" >> /etc/config/cups/cupsd.conf + echo "#" >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo "# Restrict access to the admin pages..." >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo " Order allow,deny" >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo "# Restrict access to configuration files..." >> /etc/config/cups/cupsd.conf + echo "" >> /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 "" >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo "# Set the default printer/job policies..." >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo " # Job-related operations must be done by the owner or an administrator..." >> /etc/config/cups/cupsd.conf + echo " " >> /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 " " >> /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 " " >> /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 " " >> /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 " " >> /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 " " >> /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 " " >> /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 " " >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo " " >> /etc/config/cups/cupsd.conf + echo " Order deny,allow" >> /etc/config/cups/cupsd.conf + echo " " >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo "# Set the authenticated printer/job policies..." >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo " # Job-related operations must be done by the owner or an administrator..." >> /etc/config/cups/cupsd.conf + echo " " >> /etc/config/cups/cupsd.conf + echo " AuthType Default" >> /etc/config/cups/cupsd.conf + echo " Order deny,allow" >> /etc/config/cups/cupsd.conf + echo " " >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo " " >> /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 " " >> /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 " " >> /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 " " >> /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 " " >> /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 " " >> /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 " " >> /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 " " >> /etc/config/cups/cupsd.conf + echo "" >> /etc/config/cups/cupsd.conf + echo " " >> /etc/config/cups/cupsd.conf + echo " Order deny,allow" >> /etc/config/cups/cupsd.conf + echo " " >> /etc/config/cups/cupsd.conf + echo "" >> /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 "" > /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 "" >> /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 diff --git a/ddns_update.sh b/ddns_update.sh new file mode 100755 index 0000000..a210e5d --- /dev/null +++ b/ddns_update.sh @@ -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 diff --git a/ddns_update_for_cgi.sh b/ddns_update_for_cgi.sh new file mode 100755 index 0000000..72b0129 --- /dev/null +++ b/ddns_update_for_cgi.sh @@ -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 diff --git a/dhcpd.sh b/dhcpd.sh new file mode 100755 index 0000000..87cedfd --- /dev/null +++ b/dhcpd.sh @@ -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 diff --git a/fbdisk.sh b/fbdisk.sh new file mode 100755 index 0000000..89b19f3 --- /dev/null +++ b/fbdisk.sh @@ -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 + diff --git a/ftp.sh b/ftp.sh new file mode 100755 index 0000000..80b1ca0 --- /dev/null +++ b/ftp.sh @@ -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 + diff --git a/functions b/functions new file mode 100755 index 0000000..76d974b --- /dev/null +++ b/functions @@ -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 +} diff --git a/genLanglist.sh b/genLanglist.sh new file mode 100755 index 0000000..8f27bd0 --- /dev/null +++ b/genLanglist.sh @@ -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 + + + diff --git a/gen_issue.sh b/gen_issue.sh new file mode 100755 index 0000000..45fe759 --- /dev/null +++ b/gen_issue.sh @@ -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 + diff --git a/genpowerfail.sh b/genpowerfail.sh new file mode 100755 index 0000000..c84a391 --- /dev/null +++ b/genpowerfail.sh @@ -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 +# +# +# Modification: +# 2002/03/28 by Tiger Fu /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 diff --git a/getmac.sh b/getmac.sh new file mode 100755 index 0000000..4a29512 --- /dev/null +++ b/getmac.sh @@ -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 + diff --git a/hostname.sh b/hostname.sh new file mode 100755 index 0000000..42c3ffa --- /dev/null +++ b/hostname.sh @@ -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 diff --git a/idmap.sh b/idmap.sh new file mode 100755 index 0000000..88bdc64 --- /dev/null +++ b/idmap.sh @@ -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 diff --git a/init_acl.sh b/init_acl.sh new file mode 100755 index 0000000..85eec9e --- /dev/null +++ b/init_acl.sh @@ -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 + diff --git a/init_check.sh b/init_check.sh new file mode 100755 index 0000000..4589905 --- /dev/null +++ b/init_check.sh @@ -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 diff --git a/init_disk.sh b/init_disk.sh new file mode 100755 index 0000000..128de09 --- /dev/null +++ b/init_disk.sh @@ -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 diff --git a/init_dns_type.sh b/init_dns_type.sh new file mode 100755 index 0000000..655e2b5 --- /dev/null +++ b/init_dns_type.sh @@ -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; diff --git a/init_final.sh b/init_final.sh new file mode 100755 index 0000000..90095a1 --- /dev/null +++ b/init_final.sh @@ -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 diff --git a/init_hardware.sh b/init_hardware.sh new file mode 100755 index 0000000..587c782 --- /dev/null +++ b/init_hardware.sh @@ -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 + diff --git a/init_iTune.sh b/init_iTune.sh new file mode 100755 index 0000000..92163bf --- /dev/null +++ b/init_iTune.sh @@ -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 + + diff --git a/init_mac_addr.sh b/init_mac_addr.sh new file mode 100755 index 0000000..5f2f485 --- /dev/null +++ b/init_mac_addr.sh @@ -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 + + + diff --git a/init_nas.sh b/init_nas.sh new file mode 100755 index 0000000..0670b57 --- /dev/null +++ b/init_nas.sh @@ -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 diff --git a/init_network.sh b/init_network.sh new file mode 100755 index 0000000..8520495 --- /dev/null +++ b/init_network.sh @@ -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 diff --git a/init_qpkg.sh b/init_qpkg.sh new file mode 100755 index 0000000..1a6b989 --- /dev/null +++ b/init_qpkg.sh @@ -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 + diff --git a/init_symform.sh b/init_symform.sh new file mode 100755 index 0000000..3893b28 --- /dev/null +++ b/init_symform.sh @@ -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 diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..90d3780 --- /dev/null +++ b/install.sh @@ -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 diff --git a/installtgz.sh b/installtgz.sh new file mode 100755 index 0000000..3a39028 --- /dev/null +++ b/installtgz.sh @@ -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 diff --git a/ipchange_notify.sh b/ipchange_notify.sh new file mode 100755 index 0000000..231ceec --- /dev/null +++ b/ipchange_notify.sh @@ -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 diff --git a/ipv6.sh b/ipv6.sh new file mode 100755 index 0000000..039de16 --- /dev/null +++ b/ipv6.sh @@ -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 diff --git a/iscsiinit.sh b/iscsiinit.sh new file mode 100755 index 0000000..b21ea32 --- /dev/null +++ b/iscsiinit.sh @@ -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 diff --git a/iscsitrgt.sh b/iscsitrgt.sh new file mode 100755 index 0000000..0845705 --- /dev/null +++ b/iscsitrgt.sh @@ -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 diff --git a/iso_mount.sh b/iso_mount.sh new file mode 100755 index 0000000..369c925 --- /dev/null +++ b/iso_mount.sh @@ -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 diff --git a/klogd.sh b/klogd.sh new file mode 100755 index 0000000..7bee0b3 --- /dev/null +++ b/klogd.sh @@ -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 + diff --git a/ldap.sh b/ldap.sh new file mode 100755 index 0000000..9c6360e --- /dev/null +++ b/ldap.sh @@ -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 $? diff --git a/ldap_backup_db.sh b/ldap_backup_db.sh new file mode 100755 index 0000000..e24fed8 --- /dev/null +++ b/ldap_backup_db.sh @@ -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 diff --git a/ldap_server.sh b/ldap_server.sh new file mode 100755 index 0000000..38df43f --- /dev/null +++ b/ldap_server.sh @@ -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 + diff --git a/log_rotation.sh b/log_rotation.sh new file mode 100755 index 0000000..d218fdc --- /dev/null +++ b/log_rotation.sh @@ -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 diff --git a/login.sh b/login.sh new file mode 100755 index 0000000..674160e --- /dev/null +++ b/login.sh @@ -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 diff --git a/logo.sh b/logo.sh new file mode 100755 index 0000000..f171050 --- /dev/null +++ b/logo.sh @@ -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 diff --git a/lunportman.sh b/lunportman.sh new file mode 100755 index 0000000..a7a4189 --- /dev/null +++ b/lunportman.sh @@ -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 diff --git a/mkchangepwd.sh b/mkchangepwd.sh new file mode 100755 index 0000000..870808e --- /dev/null +++ b/mkchangepwd.sh @@ -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 + diff --git a/mountall b/mountall new file mode 100755 index 0000000..4f013cd --- /dev/null +++ b/mountall @@ -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 diff --git a/mysqld.sh b/mysqld.sh new file mode 100755 index 0000000..4595f2e --- /dev/null +++ b/mysqld.sh @@ -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= +# - 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 diff --git a/network.sh b/network.sh new file mode 100755 index 0000000..966750c --- /dev/null +++ b/network.sh @@ -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 diff --git a/nfs b/nfs new file mode 100755 index 0000000..f0cd817 --- /dev/null +++ b/nfs @@ -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 + diff --git a/nss2_dusg.sh b/nss2_dusg.sh new file mode 100755 index 0000000..3b84190 --- /dev/null +++ b/nss2_dusg.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +if [ -f /var/.nvr_init_ok ]; then + /usr/bin/qcmd DUSG +fi + diff --git a/ntpclient.sh b/ntpclient.sh new file mode 100755 index 0000000..14c12c9 --- /dev/null +++ b/ntpclient.sh @@ -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 + + diff --git a/ntpd.sh b/ntpd.sh new file mode 100755 index 0000000..4879a89 --- /dev/null +++ b/ntpd.sh @@ -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 diff --git a/nvr_svc.sh b/nvr_svc.sh new file mode 100755 index 0000000..871b72c --- /dev/null +++ b/nvr_svc.sh @@ -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_ch" /usr/nvr/model.xml 1>/dev/null 2>/dev/null + [ $? = 0 ] || /bin/sed -i 's/^.*.*/'"$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 diff --git a/nvrd.sh b/nvrd.sh new file mode 100755 index 0000000..eb70336 --- /dev/null +++ b/nvrd.sh @@ -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 diff --git a/nvrd.sh_bak b/nvrd.sh_bak new file mode 100755 index 0000000..eb70336 --- /dev/null +++ b/nvrd.sh_bak @@ -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 diff --git a/openssl_signature.sh b/openssl_signature.sh new file mode 100755 index 0000000..87d5ad7 --- /dev/null +++ b/openssl_signature.sh @@ -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 \ No newline at end of file diff --git a/opentftp.sh b/opentftp.sh new file mode 100755 index 0000000..f4aa948 --- /dev/null +++ b/opentftp.sh @@ -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! diff --git a/photo_scand.sh b/photo_scand.sh new file mode 100755 index 0000000..1557359 --- /dev/null +++ b/photo_scand.sh @@ -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 diff --git a/power_button.sh b/power_button.sh new file mode 100755 index 0000000..dc73629 --- /dev/null +++ b/power_button.sh @@ -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 + diff --git a/poweroff b/poweroff new file mode 100755 index 0000000..9a7bc30 --- /dev/null +++ b/poweroff @@ -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 diff --git a/printer.sh b/printer.sh new file mode 100755 index 0000000..7b0ff32 --- /dev/null +++ b/printer.sh @@ -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 + diff --git a/qplayd.sh b/qplayd.sh new file mode 100755 index 0000000..5e0eb0e --- /dev/null +++ b/qplayd.sh @@ -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 diff --git a/qraid1.sh b/qraid1.sh new file mode 100755 index 0000000..4b94e5a --- /dev/null +++ b/qraid1.sh @@ -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 diff --git a/qsyncman.sh b/qsyncman.sh new file mode 100755 index 0000000..7ab0c6b --- /dev/null +++ b/qsyncman.sh @@ -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 diff --git a/radius.sh b/radius.sh new file mode 100755 index 0000000..1a595b7 --- /dev/null +++ b/radius.sh @@ -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 diff --git a/radvd.sh b/radvd.sh new file mode 100755 index 0000000..d909ea9 --- /dev/null +++ b/radvd.sh @@ -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 + diff --git a/rcK b/rcK new file mode 100755 index 0000000..654229f --- /dev/null +++ b/rcK @@ -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 diff --git a/rcS b/rcS new file mode 100755 index 0000000..c0c2f03 --- /dev/null +++ b/rcS @@ -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 diff --git a/rcS_normal b/rcS_normal new file mode 100755 index 0000000..18e3669 --- /dev/null +++ b/rcS_normal @@ -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 diff --git a/rcS_normal_fast b/rcS_normal_fast new file mode 100755 index 0000000..de69e10 --- /dev/null +++ b/rcS_normal_fast @@ -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 diff --git a/rcv_port.sh b/rcv_port.sh new file mode 100755 index 0000000..dec59e2 --- /dev/null +++ b/rcv_port.sh @@ -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 diff --git a/reboot b/reboot new file mode 100755 index 0000000..28d7dde --- /dev/null +++ b/reboot @@ -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 + diff --git a/recycled.sh b/recycled.sh new file mode 100755 index 0000000..aef86b8 --- /dev/null +++ b/recycled.sh @@ -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 diff --git a/refresh_nvr_crontab.sh b/refresh_nvr_crontab.sh new file mode 100755 index 0000000..8b2a611 --- /dev/null +++ b/refresh_nvr_crontab.sh @@ -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 diff --git a/reset_all.sh b/reset_all.sh new file mode 100755 index 0000000..3d23e1a --- /dev/null +++ b/reset_all.sh @@ -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 + diff --git a/rsyncRR.sh b/rsyncRR.sh new file mode 100755 index 0000000..a228b2e --- /dev/null +++ b/rsyncRR.sh @@ -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}" diff --git a/rsyncd.sh b/rsyncd.sh new file mode 100755 index 0000000..e577a1d --- /dev/null +++ b/rsyncd.sh @@ -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 diff --git a/rsyncd_srv.sh b/rsyncd_srv.sh new file mode 100755 index 0000000..4c26a6f --- /dev/null +++ b/rsyncd_srv.sh @@ -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} diff --git a/rsyslog.sh b/rsyslog.sh new file mode 100755 index 0000000..a235aaa --- /dev/null +++ b/rsyslog.sh @@ -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 diff --git a/runone.sh b/runone.sh new file mode 100755 index 0000000..8a05fc8 --- /dev/null +++ b/runone.sh @@ -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 + diff --git a/services.sh b/services.sh new file mode 100755 index 0000000..881406d --- /dev/null +++ b/services.sh @@ -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 diff --git a/set_mtu.sh b/set_mtu.sh new file mode 100755 index 0000000..4fd0ce7 --- /dev/null +++ b/set_mtu.sh @@ -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 diff --git a/shutdown_check.sh b/shutdown_check.sh new file mode 100755 index 0000000..dcd4b56 --- /dev/null +++ b/shutdown_check.sh @@ -0,0 +1,256 @@ +#!/bin/sh + +# 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 +FLASH_TMP="/flashfs_tmp" +FLASH_TMP1="/flashfs_tmp1" +BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null` +CMS_ENABLE=`/sbin/getcfg CMS Enable -d FALSE -f /etc/config/uLinux.conf` + +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 +} + +check_flash_files() +{ + local ckflag=0 + check_sum "${1}/boot/bzImage" "${1}/boot/bzImage.cksum" + [ $? = 0 ] || ckflag=1 + check_sum "${1}/boot/initrd.boot" "${1}/boot/initrd.boot.cksum" + [ $? = 0 ] || ckflag=1 + check_sum "${1}/boot/rootfs2.bz" "${1}/boot/rootfs2.bz.cksum" + [ $? = 0 ] || ckflag=1 + check_sum "${1}/boot/rootfs_ext.tgz" "${1}/boot/rootfs_ext.tgz.cksum" + [ $? = 0 ] || ckflag=1 + + if [ $ckflag = 1 ]; then + [ x"${1}" = x"${FLASH_TMP}" ] && /sbin/write_log "The first boot area on the flash is corrupted." 1 + [ x"${1}" = x"${FLASH_TMP1}" ] && /sbin/write_log "The second boot area on the flash is corrupted." 1 + return 1 + fi + + return 0 +} + +check_flash() +{ + [ -d $FLASH_TMP ] || /bin/mkdir $FLASH_TMP + /bin/mount ${FLASH_RFS1} $FLASH_TMP -o ro + if [ $? != 0 ]; then + /sbin/write_log "Flash read error." 1 + else + check_flash_files $FLASH_TMP + fi + /bin/umount $FLASH_TMP + /bin/sync + /bin/mount ${FLASH_RFS2} $FLASH_TMP -o ro + if [ $? != 0 ]; then + /sbin/write_log "Flash read error." 1 + else + check_flash_files $FLASH_TMP + fi + /bin/umount $FLASH_TMP + /bin/sync + + return 0 +} + +check_restore_flash() +{ + local status1=0 + local status2=0 + + /bin/echo "Check/Restore Flash..." + [ -d $FLASH_TMP ] || /bin/mkdir $FLASH_TMP + [ -d $FLASH_TMP1 ] || /bin/mkdir $FLASH_TMP1 + /bin/mount ${FLASH_RFS1} $FLASH_TMP -o ro + if [ $? != 0 ]; then + /bin/umount ${FLASH_RFS1} 1>>/dev/null 2>>/dev/null + /sbin/write_log "The first boot area on the flash is corrupted." 1 + status1=1 + else + check_flash_files $FLASH_TMP + [ $? = 0 ] || status1=1 + fi + /bin/umount $FLASH_RFS1 + + /bin/mount ${FLASH_RFS2} $FLASH_TMP1 -o ro + if [ $? != 0 ]; then + /bin/umount ${FLASH_RFS2} 1>>/dev/null 2>>/dev/null + /sbin/write_log "The second boot area on the flash is corrupted." 1 + status2=1 + else + check_flash_files $FLASH_TMP1 + [ $? = 0 ] || status2=1 + fi + /bin/umount $FLASH_RFS2 + + if [ $status1 = 0 ] && [ $status2 = 1 ]; then + /bin/mount ${FLASH_RFS1} ${FLASH_TMP} -o ro + /sbin/mke2fs -m0 -F -b 1024 -I 128 ${FLASH_RFS2} + /bin/sync + sleep 1 + /bin/mount ${FLASH_RFS2} ${FLASH_TMP1} + if [ $? = 0 ]; then + /bin/cp -a ${FLASH_TMP}/. ${FLASH_TMP1} + [ $? = 0 ] && /sbin/write_log "The second boot area on the flash has been recovered." 2 + fi + /bin/umount ${FLASH_RFS2} + /bin/umount ${FLASH_RFS1} + elif [ $status1 = 1 ] && [ $status2 = 0 ]; then + /bin/mount ${FLASH_RFS2} ${FLASH_TMP1} -o ro + /sbin/mke2fs -m0 -F -b 1024 -I 128 ${FLASH_RFS1} + /bin/sync + sleep 1 + /bin/mount ${FLASH_RFS1} ${FLASH_TMP} + if [ $? = 0 ]; then + /bin/cp -a ${FLASH_TMP1}/. ${FLASH_TMP} + [ $? = 0 ] && /sbin/write_log "The first boot area on the flash has been recovered." 2 + fi + /bin/umount ${FLASH_RFS1} + /bin/umount ${FLASH_RFS2} + fi + + [ ! -d $FLASH_TMP1 ] || /bin/rmdir $FLASH_TMP1 + + return 0 +} + + +check_ver_build() +{ + # check if version is the same between flash/disk + FLASH_BUILD_NUM=`/sbin/getcfg System "Build Number" -d 0000 -f /etc/default_config/uLinux.conf` + FLASH_VERSION=`/sbin/getcfg System "Version" -d 1.0.0 -f /etc/default_config/uLinux.conf` + DISK_BUILD_NUM=`/sbin/getcfg System "Build Number" -d 0000 -f /etc/config/uLinux.conf` + DISK_VERSION=`/sbin/getcfg System "Version" -d 1.0.0 -f /etc/config/uLinux.conf` + if [ $FLASH_BUILD_NUM != $DISK_BUILD_NUM ]; then + /sbin/write_log "The firmware versions of the system built-in flash ($FLASH_VERSION Build $FLASH_BUILD_NUM) and the hard drive ($DISK_VERSION Build $DISK_BUILD_NUM) are not consistent. It is recommended to update the firmware again for higher system stability." 2 + fi +} + +write_dhcp_tftp_logs() +{ + # check if version is the same between flash/disk + RET_UPDATECONFIG=`/sbin/getcfg "" "ret_updateconfig" -d "2" -f "/tmp/dhcp_tftp.log"` + RET_TFTPSRVADDR=`/sbin/getcfg "" "ret_tftpsrvaddr" -d "2" -f "/tmp/dhcp_tftp.log"` + RET_TFTPSRVNAME=`/sbin/getcfg "" "ret_tftpsrvname" -d "2" -f "/tmp/dhcp_tftp.log"` + RET_TFTPBROADCAST=`/sbin/getcfg "" "ret_tftpbroadcast" -d "2" -f "/tmp/dhcp_tftp.log"` + RET_BACKUPDRV=`/sbin/getcfg "" "ret_backupdrv" -d "2" -f "/tmp/dhcp_tftp.log"` + + if [ $RET_TFTPSRVNAME = 0 ] || [ $RET_TFTPSRVADDR = 0 ] || [ $RET_TFTPBROADCAST = 0 ] || [ $RET_BACKUPDRV = 0 ]; then + /sbin/write_log "Download system configuration from TFTP server succeeded." 4 + else + /sbin/write_log "Download system configuration from TFTP server failed." 2 + fi + if [ $RET_UPDATECONFIG = 0 ]; then + /sbin/write_log "Update system configuration succeeded." 4 + else + /sbin/write_log "Update system configuration failed." 2 + fi +} + +case "$1" in + start) + STARTED=`/sbin/getcfg Misc "System Started" -u -d FALSE` + if [ $STARTED = TRUE ]; then + echo "Last system shutdown process is incomplete." + /sbin/log_tool -t 1 -a "The system was not shut down properly last time." + /sbin/daemon_mgr + /sbin/daemon_mgr.nvr + /bin/touch /tmp/send_alert_mail + else + /sbin/setcfg Misc "System Started" TRUE + fi + /sbin/log_tool -t 0 -a "System started." + RESULT=$? + if [ "x${BOOT_CONF}" = "xTS-NASPPC" ]; then + retry=0; + while [ $RESULT -ne 0 -a $retry -le 10 ]; do + retry=`expr $retry + 1` + sleep 5 + /sbin/log_tool -t 0 -a "System started." + RESULT=$? + done + fi + check_ver_build + [ "x${BOOT_CONF}" = "xTS-NASX86" ] && check_restore_flash + [ -f /tmp/dhcp_tftp.log ] && write_dhcp_tftp_logs + if [ -x /sbin/hal_event ]; then + /sbin/hal_event --retrieve_booting_event + else + /sbin/kerrd + fi + ;; + stop) + /sbin/setcfg Misc "System Started" FALSE + /sbin/log_tool -t 0 -a "System was shut down on `/bin/date`." +#wokes set rtc alarm + /sbin/gen_next_alarm 2 + cat /proc/acpi/alarm > /etc/config/rtc_last_save + cat /proc/driver/rtc >> /etc/config/rtc_last_save +##### + [ -f /sbin/picd ] && /sbin/daemon_mgr picd stop "/sbin/picd 1>/dev/null 2>/dev/null &" + [ -f /sbin/gpiod ] && /sbin/daemon_mgr gpiod stop "/sbin/gpiod &" + [ -f /sbin/hwmond ] && /sbin/daemon_mgr hwmond stop "/sbin/hwmond &" + [ -f /sbin/acpid ] && /sbin/daemon_mgr acpid stop "/sbin/acpid" + [ -f /sbin/gen_bandwidth ] && /sbin/daemon_mgr gen_bandwidth stop "/sbin/gen_bandwidth &" + /etc/init.d/wireless.sh stop + + /bin/kill -INT `pidof qLogEngined` + /sbin/daemon_mgr qLogEngined stop /sbin/qLogEngined + [ "x${CMS_ENABLE}" != xTRUE ] && /bin/kill -INT `pidof qsyslogd` + [ "x${CMS_ENABLE}" != xTRUE ] && /sbin/daemon_mgr qsyslogd stop /sbin/qsyslogd + /bin/kill -INT `pidof qShield` + /sbin/daemon_mgr qShield stop /sbin/qShield + Internal_Model=`/sbin/getcfg System "Internal Model"` + 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 "Misc" "Wake On Lan" -u -d TRUE` = TRUE ]; then + /usr/sbin/ethtool -s eth0 wol d + /usr/sbin/ethtool -s eth0 wol g + 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 "Misc" "Wake On Lan" -u -d TRUE` = TRUE ]; then + /usr/sbin/ethtool -s eth0 wol d + /usr/sbin/ethtool -s eth0 wol g + fi + fi + fi + fi + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: /etc/init.d/shutdown_check.sh {start|stop|restart}" + exit 1 +esac + diff --git a/smb.sh b/smb.sh new file mode 100755 index 0000000..122e31c --- /dev/null +++ b/smb.sh @@ -0,0 +1,390 @@ +#!/bin/sh +. /etc/init.d/functions +CONFIG=/etc/config/smb.conf +SMBD_LOCKS="/usr/local/samba/var/locks" +GROUP_FILE="/etc/group" +SAMBA_NET="/usr/local/samba/bin/net" +WBINFO="/usr/bin/wbinfo" +# Check that smb.conf exists. +[ -f $CONFIG ] || exit 0 +. /etc/init.d/functions +DATA_VOL_PATH= + +make_vol_base(){ + FindDefVol + _ret=$? + if [ $_ret = 0 ]; then + DATA_VOL_PATH="${DEF_VOLMP}" + fi +} +conv_old_msdfs() +{ + if [ -d /etc/config/msdfs_root ]; then + echo conver MSDFS + make_vol_base + if [ "x$DATA_VOL_PATH" != "x" ]; then + mkdir ${DATA_VOL_PATH}/.@msdfs_root + cd /etc/config/msdfs_root + tar cf - * | tar xf - -C ${DATA_VOL_PATH}/.@msdfs_root + if [ $? = 0 ]; then + sed -i "s:/etc/config/msdfs_root:${DATA_VOL_PATH}/.@msdfs_root:g" $CONFIG + if [ $? = 0 ]; then + cd ~ + rm -rf /etc/config/msdfs_root + fi + fi + fi + fi +} + +_init_smbconf() +{ + if [ -x /sbin/hal_app ]; then + /sbin/setcfg global "socket options" "TCP_NODELAY SO_KEEPALIVE" -f ${CONFIG} + else + SO_SNDBUF=`/sbin/getcfg Samba SO_SNDBUF -d 65536 -f /etc/default_config/uLinux.conf` + SO_RCVBUF=`/sbin/getcfg Samba SO_RCVBUF -d 65536 -f /etc/default_config/uLinux.conf` + /sbin/setcfg global "socket options" "TCP_NODELAY SO_KEEPALIVE SO_SNDBUF=${SO_SNDBUF} SO_RCVBUF=${SO_RCVBUF}" -f ${CONFIG} + fi + #/sbin/setcfg global "passdb backend" smbpasswd -f ${CONFIG} + /sbin/setcfg global "null passwords" yes -f ${CONFIG} + /sbin/setcfg global "use sendfile" yes -f ${CONFIG} + /sbin/setcfg global "oplocks" yes -f ${CONFIG} + DEAD_TIME=`/sbin/getcfg Samba deadtime -d 10 -f /etc/config/uLinux.conf` + /sbin/setcfg global "deadtime" "${DEAD_TIME}" -f ${CONFIG} + /sbin/setcfg global "username level" 0 -f ${CONFIG} + /sbin/setcfg global "display charset" "UTF8" -f ${CONFIG} + /sbin/setcfg global "unix extensions" no -f ${CONFIG} + /sbin/setcfg global "store dos attributes" yes -f ${CONFIG} + /sbin/setcfg global "client ntlmv2 auth" yes -f ${CONFIG} + /sbin/setcfg global "dos filetime resolution" no -f ${CONFIG} + /sbin/setcfg global "inherit acls" yes -f ${CONFIG} + /sbin/setcfg global "wide links" yes -f ${CONFIG} + /sbin/setcfg global "force unknown acl user" yes -f ${CONFIG} + /sbin/setcfg global "template homedir" "/share/homes/DOMAIN=%D/%U" -f ${CONFIG} + /sbin/setcfg global "domain logons" "no" -f ${CONFIG} + /sbin/setcfg -e global "config file" -f ${CONFIG} + /sbin/setcfg -e global "template shell" -f ${CONFIG} + /sbin/setcfg -e global 'obey pam restrictions' -f ${CONFIG} + _dos_charset=`/sbin/getcfg global "dos charset" -d none -f ${CONFIG}` + if [ "x${_dos_charset}" = "xUTF8" ]; then + /sbin/setcfg -e global 'dos charset' -f ${CONFIG} + fi + if [ -x /sbin/hal_app ]; then + _splice=0 + else + _splice=`/sbin/getcfg Samba "SPLICE" -d 1` + fi + if [ "x${_splice}" = "x1" ]; then + /sbin/setcfg global "min receivefile size" 4096 -f ${CONFIG} + else + /sbin/setcfg -e global "min receivefile size" -f ${CONFIG} + fi + _case_sensitive=`/sbin/getcfg Samba "Case Sensitive" -d auto` + /sbin/setcfg global "case sensitive" ${_case_sensitive} -f ${CONFIG} + OS_LEVEL=`/sbin/getcfg global "os level" -d none -f ${CONFIG}` + if [ "x${OS_LEVEL}" != "x20" ]; then + /sbin/setcfg global "preferred master" no -f ${CONFIG} + /sbin/setcfg global "domain master" auto -f ${CONFIG} + /sbin/setcfg global "local master" no -f ${CONFIG} + /sbin/setcfg global "os level" 20 -f ${CONFIG} + fi + map_dos=`/sbin/getcfg global "map archive" -d yes -f ${CONFIG}` + if [ "x${map_dos}" = "xyes" ]; then + /sbin/setcfg global "map archive" no -f ${CONFIG} + /sbin/setcfg global "map system" no -f ${CONFIG} + /sbin/setcfg global "map hidden" no -f ${CONFIG} + /sbin/setcfg global "map read only" no -f ${CONFIG} + fi + + mode=`/sbin/getcfg global "force directory security mode" -f ${CONFIG}` + if [ "x${mode}" = "x0777" ]; then + /sbin/setcfg global "force directory security mode" 0000 -f ${CONFIG} + fi + + # for Mac OS 10.5 smb catnot upload the file to the empty share + /sbin/setcfg global "veto files" "/.AppleDB/.AppleDouble/.AppleDesktop/:2eDS_Store/Network Trash Folder/Temporary Items/TheVolumeSettingsFolder/.@__thumb/.@__desc/:2e*/" -f ${CONFIG} + + /usr/bin/readlink /usr/local/samba 2>/dev/null 1>/dev/null + if [ $? != 0 ] && [ -f /mnt/HDA_ROOT/update_pkg/samba.tgz ]; then + /etc/init.d/installtgz.sh samba /mnt/HDA_ROOT/update_pkg/samba.tgz + fi + + if [ `/sbin/getcfg LDAP Enable -u -d FALSE` = TRUE ]; then + _passwd=`/sbin/getcfg global "passdb backend" -d smbpasswd -f ${CONFIG}` + if [ "x$_passwd" != "xsmbpasswd" ]; then + _ldap_host=`/sbin/getcfg LDAP host -d "127.0.0.1"` + _ssl=`/sbin/getcfg LDAP ssl -d 0` + if [ "x$_ssl" = "x1" ]; then # ssl + /sbin/setcfg global "passdb backend" "ldapsam:ldaps://$_ldap_host" -f ${CONFIG} + /sbin/setcfg global "ldap ssl" "off" -f ${CONFIG} + elif [ "x$_ssl" = "x2" ]; then # tls + /sbin/setcfg global "passdb backend" "ldapsam:ldap://$_ldap_host" -f ${CONFIG} + /sbin/setcfg global "ldap ssl" "start tls" -f ${CONFIG} + else + /sbin/setcfg global "passdb backend" "ldapsam:ldap://$_ldap_host" -f ${CONFIG} + /sbin/setcfg global "ldap ssl" "off" -f ${CONFIG} + fi + # set WORKGROUP if backend LDAP is QNAP NAS + # LDAP Server Type = 0 (Remote QNAP NAS) + # LDAP Server Type = 1 (Local QNAP NAS) + # LDAP Server Type = 2 (Remote LDAP Server) + if [ `/sbin/getcfg LDAP "LDAP Server Type" -u -d 2` != "2" ]; then + base_dn=`/sbin/getcfg global "ldap suffix" -f ${CONFIG}` + dc=${base_dn#*dc=} + workgroup=${dc%%,*} + /sbin/setcfg global workgroup "$workgroup" -f ${CONFIG} + fi + /sbin/setcfg global "domain logons" "yes" -f ${CONFIG} + fi + else + /sbin/setcfg global "passdb backend" smbpasswd -f ${CONFIG} + fi + + ## QNAP private flag for enhance ACL. please notice switch this flag will break samba acl hash. + if [ x`/sbin/getcfg Samba "Win ACL" -u -d FALSE` = "xFALSE" ]; then + enhance_acl_v1=`/sbin/getcfg global "enhance acl v1" -d null -f ${CONFIG}` + if [ "x$enhance_acl_v1" != "xno" ]; then + /sbin/setcfg global "enhance acl v1" yes -f ${CONFIG} + fi + fi + + ## QNAP private flag for replacing Everyone to everyone or remove it if need. + if [ x`/sbin/getcfg System "ACL Enable" -u -d FALSE` = "xFALSE" ]; then + /sbin/setcfg global "remove everyone" no -f ${CONFIG} + else + /sbin/setcfg global "remove everyone" yes -f ${CONFIG} + fi + + offline_files=`/sbin/getcfg Samba "offline_files" -d TRUE` + if [ "x${offline_files}" == "xTRUE" ]; then + /sbin/setcfg global 'kernel oplocks' no -f ${CONFIG} + else + /sbin/setcfg global 'kernel oplocks' yes -f ${CONFIG} + fi + + mangled_names=`/sbin/getcfg Samba "mangled_names" -d FALSE` + if [ "x${mangled_names}" == "xFALSE" ]; then + /sbin/setcfg global 'mangled names' no -f ${CONFIG} + else + /sbin/setcfg global 'mangled names' yes -f ${CONFIG} + fi + [ `/sbin/getcfg global "printcap cache time" -d "1" -f ${CONFIG}` == "0" ] || /sbin/setcfg global "printcap cache time" "0" -f ${CONFIG} + +} + + +_init_group() +{ + + _passwd=`/sbin/getcfg global "passdb backend" -d smbpasswd -f ${CONFIG}` + if [ "x$_passwd" != "xsmbpasswd" ]; then + return + fi + HIDDEN_GROUP="dovecot guest xmail" + /bin/cat $GROUP_FILE | while read line + do + group_name=${line%%:*} + hidden_flag=0 + for hidden in $HIDDEN_GROUP + do + if [ "$group_name" = "$hidden" ]; then + hidden_flag=1 + break + fi + done + if [ "$hidden_flag" = 0 -a -x ${SAMBA_NET} ]; then + ${SAMBA_NET} groupmap add unixgroup=$group_name > /dev/null 2>&1 + fi + done +} + +_del_group() +{ + /bin/cat $GROUP_FILE | while read line + do + group_name=${line%%:*} + if [ -x ${SAMBA_NET} ]; then + ${SAMBA_NET} groupmap delete ntgroup=$group_name > /dev/null 2>&1 + fi + done +} + +_init_home() +{ + home_func=`/sbin/getcfg Samba HomeLink -u -d FALSE` + local acl_list="\"%u\"" + winbind_separator=`/sbin/getcfg global "winbind separator" -d '\\' -f ${CONFIG}` + homes_path=`/sbin/getcfg homes path -d FALSE -f ${CONFIG}` + + if [ $home_func == "FALSE" -o $homes_path == "FALSE" ]; then + #echo "home folder is disabled" + return + fi + + if [ ! -e "$homes_path" ]; then + #echo "homes is lost" + return + fi + + /sbin/setcfg home "comment" Home -f ${CONFIG} + /sbin/setcfg home "path" %H -f ${CONFIG} + /sbin/setcfg home "browsable" yes -f ${CONFIG} + /sbin/setcfg home "oplocks" yes -f ${CONFIG} + /sbin/setcfg home "ftp write only" no -f ${CONFIG} + /sbin/setcfg home "inherit permissions" yes -f ${CONFIG} + /sbin/setcfg home "writable" yes -f ${CONFIG} + /sbin/setcfg home "read list" $acl_list -f ${CONFIG} + /sbin/setcfg home "write list" $acl_list -f ${CONFIG} + /sbin/setcfg home "valid users" $acl_list -f ${CONFIG} + /sbin/setcfg home "root preexec" "/sbin/create_home -u '%q'" -f ${CONFIG} +} + +_del_home() +{ + home_path=`/sbin/getcfg home "path" -d home -f ${CONFIG}` + if [ "$home_path" == "%H" ]; then + /sbin/rmcfg home -f ${CONFIG} + fi +} + +# move samba locks directory to /mnt/HDA_ROOT/.locks +_locks() +{ + if [ -d /mnt/HDA_ROOT/.locks ]; then + /bin/rm -rf /mnt/HDA_ROOT/.locks + /bin/rm $SMBD_LOCKS + fi + volume_test=`/sbin/getcfg Public path -f /etc/smb.conf | cut -d '/' -f 3` + [ "x${volume_test}" = "x" ] || volume=${volume_test} + _lock_real_path=/share/${volume}/.locks + if [ ! -d ${_lock_real_path} ]; then + echo "samba locks directory is not exist, create it" + if [ ! -d /share/${volume} ]; then + /bin/mkdir -p /share/${volume} + /bin/chmod 777 /share/${volume} + fi + /bin/mkdir ${_lock_real_path} + /bin/rm -rf $SMBD_LOCKS + /bin/ln -sf ${_lock_real_path} $SMBD_LOCKS + else + /usr/bin/readlink $SMBD_LOCKS 2>/dev/null 1>/dev/null + if [ $? != 0 ]; then + # not symbolic link + /bin/rm -rf $SMBD_LOCKS + /bin/ln -sf ${_lock_real_path} $SMBD_LOCKS + else + # symbolic link + ret=`/usr/bin/readlink $SMBD_LOCKS` + if [ "x${ret}" != "x${_lock_real_path}" ]; then + /bin/rm -f $SMBD_LOCKS + /bin/ln -sf ${_lock_real_path} $SMBD_LOCKS + fi + fi + fi + /bin/mkdir ${_lock_real_path}/.test_locks 2>/dev/null 1>/dev/null + if [ $? != 0 ]; then + _lock_real_path=/mnt/HDA_ROOT/.locks + /bin/mkdir ${_lock_real_path} + /bin/rm -f $SMBD_LOCKS + /bin/ln -sf ${_lock_real_path} $SMBD_LOCKS + /bin/mkdir ${_lock_real_path}/.test_locks 2>/dev/null 1>/dev/null + if [ $? != 0 ]; then + _lock_real_path=/var/.locks + /bin/mkdir ${_lock_real_path} 2>/dev/null 1>/dev/null + /bin/rm -f $SMBD_LOCKS + /bin/ln -sf ${_lock_real_path} $SMBD_LOCKS + else + /bin/rmdir ${_lock_real_path}/.test_locks + fi + else + /bin/rmdir ${_lock_real_path}/.test_locks + fi + /bin/echo "locks path was set to ${_lock_real_path}" +} + +# See how we were called. +case "$1" in + start) + conv_old_msdfs + test -f /usr/local/samba/sbin/smbd || exit 0 + if [ `/sbin/getcfg Samba Enable -u -d TRUE` = FALSE ] + then + _del_home + _init_home + echo "Starting SMB Services: disabled." + exit 0 + fi + if [ x`/sbin/getcfg Samba "Win ACL" -u -d FALSE` = xTRUE ]; then + [ ! -f /usr/local/samba/lib/acl_xattr.so.disable ] || /bin/mv /usr/local/samba/lib/acl_xattr.so.disable /usr/local/samba/lib/acl_xattr.so 2>>/dev/null + else + [ ! -f /usr/local/samba/lib/acl_xattr.so ] || /bin/mv /usr/local/samba/lib/acl_xattr.so /usr/local/samba/lib/acl_xattr.so.disable 2>>/dev/null + fi + _init_smbconf + _locks + _init_group + _del_home + /etc/init.d/winbind start + _init_home + echo -n "Starting SMB services:" + /sbin/daemon_mgr smbd start "/usr/local/samba/sbin/smbd -l /var/log -D -s $CONFIG" + if [ "$?" = "0" ]; then echo -n " smbd"; fi + /sbin/daemon_mgr nmbd start "/usr/local/samba/sbin/nmbd -l /var/log -D -s $CONFIG" + if [ "$?" = "0" ]; then echo -n " nmbd"; fi + echo "." + touch /var/lock/subsys/smb + ;; + stop) + echo -n "Shutting down SMB services:" + + ## we have to get all the smbd process here instead of just the + ## main parent (i.e. killproc) because it can take a long time + ## for an individual process to process a TERM signal + smbdpids=`pidof smbd` + /sbin/daemon_mgr smbd stop /usr/local/samba/sbin/smbd + for pid in $smbdpids; do + /bin/kill -TERM $pid 2>/dev/null 1>/dev/null + done + echo -n " smbd" + nmbdpids=`pidof nmbd` + /sbin/daemon_mgr nmbd stop /usr/local/samba/sbin/nmbd + for pid in $nmbdpids; do + /bin/kill -TERM $pid 2>/dev/null 1>/dev/null + done + echo " nmbd." + /bin/rm -f /var/lock/subsys/smb + /bin/rm -f $SMBD_LOCKS/smbd.pid $SMBD_LOCKS/nmbd.pid + /etc/init.d/winbind stop + _del_group + ;; + nmbdrestart) + test -f /usr/local/samba/sbin/smbd || exit 0 + if [ `/sbin/getcfg Samba Enable -u -d TRUE` = FALSE ] + then + echo "Starting nmbd Services: disabled." + exit 0 + fi + echo -n "Restarting nmbd services:" + nmbdpids=`pidof nmbd` + /sbin/daemon_mgr nmbd stop /usr/local/samba/sbin/nmbd + for pid in $nmbdpids; do + /bin/kill -TERM $pid 2>/dev/null 1>/dev/null + done + /bin/rm -f $SMBD_LOCKS/nmbd.pid + /sbin/daemon_mgr nmbd start "/usr/local/samba/sbin/nmbd -l /var/log -D -s $CONFIG" + if [ "$?" = "0" ]; then echo -n " nmbd"; fi + echo "." + + echo "done." + ;; + restart) + echo "Restarting SMB services:" + $0 stop + $0 start + echo "done." + ;; + *) + echo "Usage: smb {start|stop|restart}" + exit 1 +esac + diff --git a/snapshot.sh b/snapshot.sh new file mode 100755 index 0000000..7b1a0e9 --- /dev/null +++ b/snapshot.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# +# chkconfig: 345 13 89 +# description: Starts and stops the snapshot service +# + +# Source function library. + +DDSNAP_KO=/usr/local/lib/dm-ddsnap.ko + +start() +{ + echo $"Starting snapshot service: " + /sbin/insmod $DDSNAP_KO +} + +stop() +{ + echo $"Stopping snapshot service: " + /sbin/rmmod dm_ddsnap +} + +restart() +{ + stop + sleep 1 + start + +} + +[ -f $DDSNAP_KO ] || exit 0 + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; +esac + +exit $RETVAL diff --git a/snmp b/snmp new file mode 100755 index 0000000..42b296f --- /dev/null +++ b/snmp @@ -0,0 +1,114 @@ +#!/bin/sh +# +# description: Starts and stops the snmp agent deamon +# + +SNMPD=/usr/local/bin/snmpd +SYSCONF=/etc/config/uLinux.conf +ETCCONF=/etc/config/snmpd.conf +VARCONF=/var/ucd-snmp/snmpd.conf +TMPVARCONF=/etc/config/snmpd.var.conf +NEW_CONF=/tmp/new_snmpd_conf.flag +RETVAL=0 + +reset_snmp_conf_file() +{ + SNMPV=`/sbin/getcfg SNMP "Version" -d 1` + if [ $"SNMPV" = "1" ]; then + COMM=`/sbin/getcfg SNMP "Trap Community" -d public` + else + ENGINE_ID=`/sbin/getcfg SNMP "Engine ID" -d ""` + USER=`/sbin/getcfg SNMP "User" -d ""` + I_AUTH_PROTOCOL=`/sbin/getcfg SNMP "Auth Protocol" -d 0` + AUTH_KEY=`/sbin/getcfg SNMP "Auth Key" -d ""` + I_PRIV_PROTOCOL=`/sbin/getcfg SNMP "Priv Protocol" -d 0` + PRIV_KEY=`/sbin/getcfg SNMP "Priv Key" -d ""` + AUTH_PROTOCOL=MD5 + if [ $I_AUTH_PROTOCOL = 1 ]; then + AUTH_PROTOCOL=SHA + fi + PRIV_PROTOCOL=DES +# if [ $I_PRIV_PROTOCOL = 1 ]; then +# PRIV_PROTOCOL=AES +# fi + cp $TMPVARCONF ${TMPVARCONF}.bak + + AUTH_TYPE=`/sbin/getcfg SNMP "Auth Type" -d 0` + if [ "x$ENGINE_ID" = "x" ]; then + ENGINE_CMD="" + else + ENGINE_CMD="-e $ENGINE_ID" + fi + case "$AUTH_TYPE" in + "0") + echo createUser $ENGINE_CMD \"$USER\" > $TMPVARCONF + ;; + "1") + echo createUser $ENGINE_CMD \"$USER\" $AUTH_PROTOCOL \"$AUTH_KEY\" > $TMPVARCONF + ;; + "2") + echo createUser $ENGINE_CMD \"$USER\" $AUTH_PROTOCOL \"$AUTH_KEY\" $PRIV_PROTOCOL \"$PRIV_KEY\" > $TMPVARCONF + ;; + esac + fi +} +start() +{ + ENABLE=`/sbin/getcfg SNMP "Service Enable" -d FALSE -u -f $SYSCONF` + if [ "x${ENABLE}" == "xTRUE" ] ; then + /bin/echo "Starting snmp agent:" + mkdir -p /var/ucd-snmp +# /bin/echo "****** /etc/config/snmpd.conf" > /tmp/snmp.log +# /bin/cat /etc/config/snmpd.conf >> /tmp/snmp.log +# /bin/echo "****** /etc/config/snmpd.var.conf" >> /tmp/snmp.log +# /bin/cat /etc/config/snmpd.var.conf >> /tmp/snmp.log +# if [ -f $VARCONF ]; then +# /bin/echo "****** $VARCONF" >> /tmp/snmp.log +# /bin/cat $VARCONF >> /tmp/snmp.log +# fi + if [ -f $NEW_CONF ] || [ ! -f $VARCONF ]; then +# /bin/echo "Copy /etc/config/snmpd.var.conf" >> /tmp/snmp.log + cp /etc/config/snmpd.var.conf $VARCONF + fi + PORT_NO=`/sbin/getcfg SNMP "Listen Port" -d 161` + $SNMPD -c /etc/config/snmpd.conf -p ${PORT_NO} + RETVAL=$? + [ -f $NEW_CONF ] && rm $NEW_CONF + /bin/sleep 1 + cp $VARCONF /etc/config/snmpd.var.conf +# /bin/echo "****** /etc/config/snmpd.var.conf" >> /tmp/snmp.log +# /bin/cat /etc/config/snmpd.var.conf >> /tmp/snmp.log + fi +} + +stop() +{ + /bin/echo "Stopping snmp agent: " + killall snmpd + RETVAL=$? +} + +restart() +{ + stop + sleep 1 + start + +} + +##[ -f $SNMPD ] || exit 0 + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; +esac + +exit $RETVAL diff --git a/snmp_ups.sh b/snmp_ups.sh new file mode 100755 index 0000000..1f044b4 --- /dev/null +++ b/snmp_ups.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# +# ups.sh This shell script takes care of that starting or stoping ups daemon +# + +# See how we were called. +DAEMON_TYPE=`/sbin/getcfg "UPS" "Daemon Type"` + +case "$1" in + start) + # Start daemons. + if [ `/sbin/getcfg "UPS" "Enable" -u -d "FALSE"` = FALSE ] + then + echo disabled + exit 0 + fi + if [ $DAEMON_TYPE = "2" ] + then + UPS_IP=`/sbin/getcfg "UPS" "UPS IP" -d "127.0.0.1"` + /sbin/daemon_mgr min_snmptrapd start "/sbin/min_snmptrapd /etc/config/ups_snmptrapd.conf $UPS_IP" + touch /var/lock/subsys/genpowerd + fi + + ;; + stop) + # Stop daemons. + /sbin/daemon_mgr min_snmptrapd stop /sbin/min_snmptrapd 2> /dev/null + /bin/rm -f /var/lock/subsys/genpowerd + + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 +esac + + diff --git a/start_service.sh b/start_service.sh new file mode 100755 index 0000000..f0e3e39 --- /dev/null +++ b/start_service.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +[ -f /sbin/lcd_tool ] && /sbin/lcd_tool -1 "Starting Service" -2 "Please Wait..." diff --git a/startup b/startup new file mode 100755 index 0000000..620d566 --- /dev/null +++ b/startup @@ -0,0 +1,3 @@ +#!/bin/sh +. /etc/init.d/wait_RR +echo system startup will be done by /dev/rtc ... diff --git a/stunnel.sh b/stunnel.sh new file mode 100755 index 0000000..64c54c0 --- /dev/null +++ b/stunnel.sh @@ -0,0 +1,113 @@ +#!/bin/sh +# For Administration +# default port: 6000 + +STUNNEL_CONF_DIR=/etc/config/stunnel +STUNNEL_CONF_DEFAULT=/etc/default_config/stunnel +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 +STUNNEL_PEM=/etc/config/stunnel/stunnel.pem +STUNNEL_PEM_DEFAULT=/etc/default_config/stunnel/stunnel.pem +STUNNEL_DOWNLOAD_PATH=/home/httpd +DOWNLOAD_PATH=/home/httpd/cgi-bin/download +STUNNEL_CONF=/etc/stunnel/stunnel.conf + +test -f /usr/sbin/stunnel || exit 0 +project_name=`/sbin/getcfg Project Name -d QNAP -f /var/default` + +prepare_cert_key() +{ + if [ ! -f $STUNNEL_CERT ] && [ -f $STUNNEL_CERT_DEFAULT ]; then + /bin/cp $STUNNEL_CERT_DEFAULT $STUNNEL_CERT + fi + + if [ ! -f $STUNNEL_KEY ] && [ -f $STUNNEL_KEY_DEFAULT ]; then + /bin/cp $STUNNEL_KEY_DEFAULT $STUNNEL_KEY + fi + + if [ -f $STUNNEL_CERT ] && [ -f $STUNNEL_KEY ]; then + #avaiable to download default SSL key + [ x`/sbin/getcfg "SSL Import" "default certificate"` = xno ] || /sbin/setcfg "SSL Import" "default certificate" no + fi +} + +case "$1" in + start) + echo -n "Starting stunnel services: " + STUNNEL_PORT=`/sbin/getcfg "Stunnel" "Port" -d "443"` + WFM_ENABLE_DEFINED_PORT=`/sbin/getcfg "WebFS" "Enable_Defined_Port" -d "FALSE"` + WFM_DEFINED_PORT=`/sbin/getcfg "WebFS" "Port" -d "8008"` + WFM_DEFINED_SSL_PORT=`/sbin/getcfg "WebFS" "SSL_Port" -d "8090"` + + prepare_cert_key + + [ `/sbin/getcfg "Stunnel" "Enable" -d "1"` = "0" ] && exit 1 + + if [ ! -d ${STUNNEL_CONF_DIR} ]; then + [ ! -f ${STUNNEL_CONF_DIR} ] || /bin/rm ${STUNNEL_CONF_DIR} + /bin/mkdir ${STUNNEL_CONF_DIR} + [ -d ${STUNNEL_CONF_DEFAULT} ] && /bin/cp ${STUNNEL_CONF_DEFAULT}/* ${STUNNEL_CONF_DIR} + else + if [ `/sbin/getcfg "SSL Import" "default certificate" -d "yes"` = "yes" ]; then + /bin/cmp ${STUNNEL_PEM_DEFAULT} ${STUNNEL_PEM} 1>/dev/null 2>/dev/null + if [ $? != 0 ]; then + [ -f ${STUNNEL_PEM_DEFAULT} ] && /bin/cp -f ${STUNNEL_PEM_DEFAULT} ${STUNNEL_PEM} + fi + fi + fi + + /bin/grep "Some security enhancements" ${STUNNEL_CONF} 1>>/dev/null 2>>/dev/null + [ $? = 0 ] && /bin/sed -i 's/^.*Some security enhancements.*$/ciphers = ALL:!SSLv2:!LOW:!EXPORT40:@STRENGTH/' ${STUNNEL_CONF} + /bin/sed -i 's/^ciphers.*$/ciphers = ALL:!SSLv2:!LOW:!EXPORT40:@STRENGTH/' ${STUNNEL_CONF} + if [ `/sbin/getcfg "Network" "IPV6" -u -d "FALSE"` = "TRUE" ]; then + /sbin/setcfg "https" "accept" ":::${STUNNEL_PORT}" -f "${STUNNEL_CONF}" + if [ $WFM_ENABLE_DEFINED_PORT = "TRUE" ]; then + /sbin/setcfg "wfm" "accept" ":::${WFM_DEFINED_SSL_PORT}" -f "${STUNNEL_CONF}" + fi + else + /sbin/setcfg "https" "accept" "${STUNNEL_PORT}" -f "${STUNNEL_CONF}" + if [ $WFM_ENABLE_DEFINED_PORT = "TRUE" ]; then + /sbin/setcfg "wfm" "accept" "${WFM_DEFINED_SSL_PORT}" -f "${STUNNEL_CONF}" + fi + fi + /sbin/setcfg "https" "TIMEOUTclose" "0" -f "${STUNNEL_CONF}" + /sbin/setcfg "https" "TIMEOUTconnect" "2" -f "${STUNNEL_CONF}" + + if [ $WFM_ENABLE_DEFINED_PORT = "TRUE" ]; then + /sbin/setcfg "wfm" "connect" "127.0.0.1:${WFM_DEFINED_PORT}" -f "${STUNNEL_CONF}" + /sbin/setcfg "wfm" "TIMEOUTclose" "0" -f "${STUNNEL_CONF}" + /sbin/setcfg "wfm" "TIMEOUTconnect" "2" -f "${STUNNEL_CONF}" + else + /sbin/rmcfg "wfm" -f "${STUNNEL_CONF}" 2>/dev/null + fi + /sbin/setcfg "" debug 0 -f "${STUNNEL_CONF}" + /bin/touch /var/qfunc/stunnel.enable + /sbin/daemon_mgr stunnel start \ + "/usr/sbin/stunnel ${STUNNEL_CONF} 2>/dev/null 1>/dev/null" + echo -n " stunnel" + echo "." + ;; + stop) + echo -n "Shutting down stunnel services:" + /sbin/daemon_mgr stunnel stop /usr/sbin/stunnel + /bin/kill -9 `pidof stunnel` + /bin/rm -f /var/qfunc/stunnel.enable + echo -n " stunnel" + echo "." + ;; + restart) + $0 stop + /bin/sleep 2 + $0 start + ;; + prepare_cert_key) + prepare_cert_key + ;; + *) + echo "Usage: /etc/init.d/stunnel {start|stop|restart|prepare_cert_key}" + exit 1 +esac + +exit 0 diff --git a/sysinit.sh b/sysinit.sh new file mode 100755 index 0000000..c7a62b1 --- /dev/null +++ b/sysinit.sh @@ -0,0 +1,308 @@ +#!/bin/sh + +ROOT_PART="/mnt/HDA_ROOT" +MNT_POINT="/mnt/ext" +HIDDEN_CONF_FILE="${ROOT_PART}/.conf" +HIDDEN_CONF_DIR="${ROOT_PART}/.config" +TS_CONF_DIR=/etc/config +HIDDEN_LOG_DIR="${ROOT_PART}/.logs" +TS_LOG_DIR=/etc/logs +SYSTEM_TEMP_DIR=/tmp +QPKG_RSS_DOC_LINK="/home/httpd/RSS/rssdoc" +QPKG_RSS_DOC_DIR="/etc/config/rssdoc" +GETCFG="/sbin/getcfg" +SETCFG="/sbin/setcfg" +FUNC_SWITCH_CONF="/etc/config/.funcSwitch.conf" +APP_RUNTIME_CONF="/var/.application.conf" + +_init_smart_conf() +{ + _SMART_CONF=/etc/config/smart.conf + if [ ! -f ${_SMART_CONF} ]; then + /bin/touch /etc/config/smart.conf + _tmp=`${GETCFG} SMART "Temperature Type" -d NONE` + if [ "x$_tmp" != "xNONE" ]; then + ${SETCFG} SMART "Temperature Type" "${_tmp}" -f /etc/config/smart.conf + fi + _disk_no=`${GETCFG} Storage "Disk Drive Number" -d 8 -f /etc/default_config/uLinux.conf` + _cnt=1 + while [ ${_cnt} -le ${_disk_no} ]; do + _tmp=`${GETCFG} SMART "HD ${_cnt} Now Test Type" -d NONE` + if [ "x$_tmp" != "xNONE" ]; then + ${SETCFG} SMART "HD ${_cnt} Now Test Type" "${_tmp}" -f /etc/config/smart.conf + fi + _tmp=`${GETCFG} SMART "HD ${_cnt} Last Test Time" -d NONE` + if [ "x$_tmp" != "xNONE" ]; then + ${SETCFG} SMART "HD ${_cnt} Last Test Time" "${_tmp}" -f /etc/config/smart.conf + fi + _tmp=`${GETCFG} SMART "HD ${_cnt} Last Test Type" -d NONE` + if [ "x$_tmp" != "xNONE" ]; then + ${SETCFG} SMART "HD ${_cnt} Last Test Type" "${_tmp}" -f /etc/config/smart.conf + fi + _tmp=`${GETCFG} SMART "Enable Temperature Threshold ${_cnt}" -d NONE` + if [ "x$_tmp" != "xNONE" ]; then + ${SETCFG} SMART "Enable Temperature Threshold ${_cnt}" "${_tmp}" -f /etc/config/smart.conf + fi + _tmp=`${GETCFG} SMART "Temperature Threshold ${_cnt}" -d NONE` + if [ "x$_tmp" != "xNONE" ]; then + ${SETCFG} SMART "Temperature Threshold ${_cnt}" "${_tmp}" -f /etc/config/smart.conf + fi + _tmp=`${GETCFG} SMART "Short Test Schedule ${_cnt}" -d NONE` + if [ "x$_tmp" != "xNONE" ]; then + ${SETCFG} SMART "Short Test Schedule ${_cnt}" "${_tmp}" -f /etc/config/smart.conf + fi + _tmp=`${GETCFG} SMART "Enable Short Schedule ${_cnt}" -d NONE` + if [ "x$_tmp" != "xNONE" ]; then + ${SETCFG} SMART "Enable Short Schedule ${_cnt}" "${_tmp}" -f /etc/config/smart.conf + fi + _tmp=`${GETCFG} SMART "Extended Test Schedule ${_cnt}" -d NONE` + if [ "x$_tmp" != "xNONE" ]; then + ${SETCFG} SMART "Extended Test Schedule ${_cnt}" "${_tmp}" -f /etc/config/smart.conf + fi + _tmp=`${GETCFG} SMART "Enable Extended Schedule ${_cnt}" -d NONE` + if [ "x$_tmp" != "xNONE" ]; then + ${SETCFG} SMART "Enable Extended Schedule ${_cnt}" "${_tmp}" -f /etc/config/smart.conf + fi + _cnt=`/usr/bin/expr ${_cnt} + 1` + done + fi +} + +_hide_apps() +{ + [ -f "$FUNC_SWITCH_CONF" ] || return 1 + DisHF=`$GETCFG DISABLE HomeFeature -d x -f "${FUNC_SWITCH_CONF}"` + [ x"${DisHF}" = "xx" ] || $SETCFG DISABLE HomeFeature "${DisHF}" -f "${APP_RUNTIME_CONF}" + _buf=`$GETCFG DISABLE qdownload -d x -f "${FUNC_SWITCH_CONF}"` + [ x"${_buf}" = "xx" ] || $SETCFG DISABLE qdownload "${_buf}" -f "${APP_RUNTIME_CONF}" + _buf=`$GETCFG DISABLE musics -d x -f "${FUNC_SWITCH_CONF}"` + [ x"${_buf}" = "xx" ] || $SETCFG DISABLE musics "${_buf}" -f "${APP_RUNTIME_CONF}" + _buf=`$GETCFG DISABLE photos -d x -f "${FUNC_SWITCH_CONF}"` + [ x"${_buf}" = "xx" ] || $SETCFG DISABLE photos "${_buf}" -f "${APP_RUNTIME_CONF}" + _buf=`$GETCFG DISABLE qmultimedia -d x -f "${FUNC_SWITCH_CONF}"` + [ x"${_buf}" = "xx" ] || $SETCFG DISABLE qmultimedia "${_buf}" -f "${APP_RUNTIME_CONF}" + _buf=`$GETCFG DISABLE iTunes -d x -f "${FUNC_SWITCH_CONF}"` + [ x"${_buf}" = "xx" ] || $SETCFG DISABLE iTunes "${_buf}" -f "${APP_RUNTIME_CONF}" + _buf=`$GETCFG DISABLE upnp -d x -f "${FUNC_SWITCH_CONF}"` + [ x"${_buf}" = "xx" ] || $SETCFG DISABLE upnp "${_buf}" -f "${APP_RUNTIME_CONF}" + _buf=`$GETCFG DISABLE survielance -d x -f "${FUNC_SWITCH_CONF}"` + [ x"${_buf}" = "xx" ] || $SETCFG DISABLE survielance "${_buf}" -f "${APP_RUNTIME_CONF}" + +} + +case "$1" in + start) +##[ -f /sbin/zfs-fuse ] && /sbin/daemon_mgr zfs-fuse start /sbin/zfs-fuse && /bin/mknod /dev/fuse c 10 229 + [ x`/bin/pidof bcclient` != x ] || /sbin/daemon_mgr bcclient start "/sbin/bcclient" + [ -f /sbin/zfs-fuse ] && /sbin/zfs-fuse && /bin/mknod /dev/fuse c 10 229 + if [ -f /tmp/booting ]; then + tmpdir=/tmp/install + CNT=0 + while [ $CNT -lt 10 ]; do + if [ -f $tmpdir/ffmpeg ] && [ -f $tmpdir/ImageMagick ] && [ -f $tmpdir/radius ] &&\ + [ -f $tmpdir/vim ] && [ -f $tmpdir/samba ] && [ -f $tmpdir/libtorrent ] && \ + [ -f $tmpdir/printer ] && [ -f $tmpdir/vaultServices ] && [ -f $tmpdir/language ]; then + rm -rf /tmp/install + break + else + [ ! -d $tmpdir ] && break + sleep 1 + CNT=`expr $CNT + 1` + fi + done + if [ -f /sbin/storage_boot_init ]; then + /bin/umount /dev/md9 1>/dev/null 2>&1 + [ $? = 0 ] || /bin/echo "mountall: umount dev/md9 failed." + fi + /bin/rm -rf /tmp/booting + fi + if [ -f /sbin/storage_boot_init ]; then + [ "x$2" = "x" ] && /sbin/storage_boot_init 1 + driveno=`/sbin/getcfg "Storage" "Disk Drive Number" -d 0` + driveno_ram=`/sbin/getcfg "Storage" "Disk Drive Number" -d 0 -f /etc/default_config/uLinux.conf` + if [ $driveno != $driveno_ram ] && [ $driveno_ram -gt 0 ]; then + /sbin/setcfg "Storage" "Disk Drive Number" $driveno_ram + fi + fi + /bin/sync + /sbin/ldconfig + /sbin/hwclock --hctosys + # create config symbolic link and event log symbolic link + /usr/bin/readlink $TS_CONF_DIR | grep ".config" 1>/dev/null 2>&1 + # for HAL enable system, the symbolic link is created in storage_util + if [ $? != 0 -o -x "/sbin/hal_app" ] && [ -f $HIDDEN_CONF_FILE ] && [ -d $HIDDEN_CONF_DIR ]; then + /bin/echo config hidden config directory exist, create symbolic link $TS_CONF_DIR... [OK] + # create $TS_CONF_DIR + /bin/rm -rf $TS_CONF_DIR + /bin/ln -sf $HIDDEN_CONF_DIR $TS_CONF_DIR + [ -f /etc/init.d/init_config.sh ] && /etc/init.d/init_config.sh dhcp_info + /bin/chown admin.administrators $HIDDEN_CONF_DIR + /bin/touch ${SYSTEM_TEMP_DIR}/check.status + /bin/touch ${SYSTEM_TEMP_DIR}/format.status + /bin/cp -a ${HIDDEN_CONF_DIR}/TZ /etc/ + /sbin/hwclock --hctosys + + echo Writing model version information... + if [ -f /etc/config/update_fw_ok ]; then + TS_VERSION=`/sbin/getcfg System Version -f /etc/default_config/uLinux.conf` + [ "x`echo -n $TS_VERSION`" != "x" ] && /sbin/setcfg System Version $TS_VERSION + TS_BUILDVER=`/sbin/getcfg System "Build Version" -f /etc/default_config/uLinux.conf` + [ "x`echo -n $TS_BUILDVER`" != "x" ] && /sbin/setcfg System "Build Version" $TS_BUILDVER + TS_BUILDNUM=`/sbin/getcfg System "Build Number" -f /etc/default_config/uLinux.conf` + [ "x`echo -n $TS_BUILDNUM`" != "x" ] && /sbin/setcfg System "Build Number" $TS_BUILDNUM + TS_BUILDDATE=`/sbin/getcfg System "Build Date" -f /etc/default_config/uLinux.conf` + [ "x`echo -n $TS_BUILDDATE`" != "x" ] && /sbin/setcfg System "Build Date" $TS_BUILDDATE + fi + MANUFACTURER=`/sbin/getcfg System Manufacturer -f /etc/default_config/uLinux.conf -d ""` + MANUFACTURER_HD=`/sbin/getcfg System Manufacturer -d ""` + [ x"${MANUFACTURER}" = x"${MANUFACTURER_HD}" ] || /sbin/setcfg System Manufacturer "${MANUFACTURER}" + MANUFACTURER_URL=`/sbin/getcfg System ManufacturerURL -f /etc/default_config/uLinux.conf -d ""` + MANUFACTURER_URL_HD=`/sbin/getcfg System ManufacturerURL -d ""` + [ x"${MANUFACTURER_URL}" = x"${MANUFACTURER_URL_HD}" ] || /sbin/setcfg System ManufacturerURL "${MANUFACTURER_URL}" + COMPANY_INFO=`/sbin/getcfg iSCSI "Company Info" -f /etc/default_config/uLinux.conf -d ""` + COMPANY_INFO_HD=`/sbin/getcfg iSCSI "Company Info" -d ""` + [ x"${COMPANY_INFO}" = x"${COMPANY_INFO_HD}" ] || /sbin/setcfg iSCSI "Company Info" "${COMPANY_INFO}" + MODEL_NAME=`/sbin/getcfg iSCSI "Model Name" -f /etc/default_config/uLinux.conf -d ""` + MODEL_NAME_HD=`/sbin/getcfg iSCSI "Model Name" -d ""` + [ x"${MODEL_NAME}" = x"${MODEL_NAME_HD}" ] || /sbin/setcfg iSCSI "Model Name" "${MODEL_NAME}" + + TS_MODEL=`/sbin/getcfg System Model -f /etc/default_config/uLinux.conf` + [ "x`echo -n $TS_MODEL`" != "x" ] && /sbin/setcfg System Model $TS_MODEL + TS_INTERNAL_MODEL=`/sbin/getcfg System "Internal Model" -f /etc/default_config/uLinux.conf` + [ "x`echo -n $TS_INTERNAL_MODEL`" != "x" ] && /sbin/setcfg System "Internal Model" $TS_INTERNAL_MODEL + if [ $? = 0 ]; then + echo Writing model version info...[OK] + else + echo Writing Internal Model...[Failed] + fi + _hide_apps + #QTS UI + /bin/rm -rf /home/httpd/cgi-bin/loginTheme/theme + /bin/ln -sf theme`/sbin/getcfg System LoginTheme -d 2` /home/httpd/cgi-bin/loginTheme/theme + /bin/ln -sf "../../images/desktop/desktop-`/sbin/getcfg System LoginBgNum -d 1`.jpg" /home/httpd/cgi-bin/loginTheme/theme/desktop.jpg + if [ ! -f /home/httpd/cgi-bin/images/desktop/desktop-5.jpg ] && [ ! -f /mnt/HDA_ROOT/update_pkg/jsLib.tgz ]; then + /bin/mv /home/httpd/cgi-bin/user-settings.json /home/httpd/cgi-bin/user-settings.json.bg6 2>/dev/null + /bin/cp /home/httpd/cgi-bin/user-settings.json.bg2 /home/httpd/cgi-bin/user-settings.json 2>/dev/null + fi + fi + + /sbin/set_home_directory + /sbin/sss_convert + if [ -f $HIDDEN_CONF_FILE ] && [ -d $HIDDEN_LOG_DIR ]; then + # create $TS_LOG_DIR + if [ ! -f $HIDDEN_LOG_DIR/event.log ]; then + echo log file not found, create symbolic link $TS_LOG_DIR and initial log file... [OK] + if [ -f $TS_LOG_DIR/event.log ]; then + /bin/cp $TS_LOG_DIR/event.log $HIDDEN_LOG_DIR + /bin/cp $TS_LOG_DIR/conn.log $HIDDEN_LOG_DIR + /bin/rm -rf $TS_LOG_DIR + /bin/ln -sf $HIDDEN_LOG_DIR $TS_LOG_DIR + /sbin/log_tool -v -b 10000 + /sbin/conn_log_tool -v -b 10000 + else + /bin/rm -rf $TS_LOG_DIR + /bin/ln -sf $HIDDEN_LOG_DIR $TS_LOG_DIR + /sbin/log_tool -v -c + /sbin/log_tool -v -b 10000 + /sbin/conn_log_tool -v -c + /sbin/conn_log_tool -v -b 10000 + # delete old nas logs + if [ -f $TS_LOG_DIR/nas4000.cnt ]; then + rm $TS_LOG_DIR/nas4000.cnt + fi + if [ -f $TS_LOG_DIR/nas4000.log ]; then + echo delete old nas logs... [OK] + rm $TS_LOG_DIR/nas4000.log + fi + fi + else + /usr/bin/readlink $TS_LOG_DIR 1>/dev/null 2>&1 + if [ $? != 0 ]; then + # TS_LOG_DIR link not exist + echo log hidden config directory exist, create symboloc link $TS_LOG_DIR... [OK] + /bin/ln -sf $HIDDEN_LOG_DIR $TS_LOG_DIR + fi + fi + else + echo log hidden config directory not exist, initial 10K log file... [OK] + /bin/mkdir $TS_LOG_DIR + /sbin/log_tool -v -c + /sbin/log_tool -v -b 50 + /sbin/conn_log_tool -v -c + /sbin/conn_log_tool -v -b 50 + fi + + #QFIX + [ -f /etc/config/qpkg.conf ] || /bin/touch /etc/config/qpkg.conf & + /etc/init.d/init_qpkg.sh qfix + + /sbin/setcfg Printers "Phy exist" 0 + /sbin/setcfg Printers "Phy exist2" 0 + /sbin/setcfg Printers "Phy exist3" 0 + /sbin/setcfg Printers "Phy exist4" 0 + /sbin/setcfg Printers "Phy exist5" 0 + /bin/echo "" > /etc/config/printcap + [ -f /etc/init.d/nvrd.sh ] && /etc/init.d/nvrd.sh init & + #[ -d /mnt/HDA_ROOT/.spool ] || /etc/init.d/printer.sh start + #create QPKG_RSS_DOC_DIR + /usr/bin/readlink $TS_CONF_DIR | grep ".config" 1>/dev/null 2>&1 + if [ $? = 0 ] && [ ! -d ${QPKG_RSS_DOC_LINK} ]; then + [ -d ${QPKG_RSS_DOC_DIR} ] || /bin/mkdir ${QPKG_RSS_DOC_DIR} + /bin/ln -sf ${QPKG_RSS_DOC_DIR} ${QPKG_RSS_DOC_LINK} + /bin/rm -f ${QPKG_RSS_DOC_DIR}/qpkgcenter* 2>/dev/null + /bin/rm -f ${QPKG_RSS_DOC_DIR}/last_uptime* 2>/dev/null + /bin/rm -f ${QPKG_RSS_DOC_DIR}/newsrss_* 2>/dev/null + fi + + /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/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 + /bin/touch /etc/config/schedule_boot_setting + /bin/touch /etc/default_config/schedule_boot_setting + _init_smart_conf + [ -d /etc/config/vaultServices ] || /bin/mkdir /etc/config/vaultServices & + + [ `/sbin/getcfg "System" "Date Format Index" -d 0` = 0 ] && /sbin/setcfg "System" "Date Format Index" 1 + #/sbin/setcfg "System" "Date Format Index" 0 + # init rcv_port + if [ -f /etc/init.d/rcv_port.sh ]; then + /etc/init.d/rcv_port.sh start + fi + /sbin/modagent + /etc/init.d/snapshot.sh start +# /etc/init.d/iscsiinit.sh start + + # For locale en_US.utf-8 + if [ -d /usr/share/i18n ]; then + [ -d /usr/lib/locale ] || /bin/mkdir /usr/lib/locale + [ -f /usr/lib/locale/locale-archive ] || /usr/bin/localedef -i en_US -f UTF-8 en_US.UTF-8 + fi + /etc/init.d/init_dns_type.sh + if [ -f /.disable_home_features ]; then + /sbin/setcfg QPHOTO Enable FALSE + /sbin/setcfg BTDownload Enable FALSE + /sbin/setcfg iTune Enable FALSE + /sbin/setcfg TwonkyMedia Enable FALSE + fi + + ;; + stop) + # nothing to do + /etc/init.d/iscsiinit.sh stop + /etc/init.d/snapshot.sh stop + /usr/bin/killall modagent + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: /etc/init.d/sysinit.sh {start|stop|restart}" + exit 1 +esac + +exit 0 diff --git a/thttpd.sh b/thttpd.sh new file mode 100755 index 0000000..5c0c74f --- /dev/null +++ b/thttpd.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# For Administration +# default port: 6000 +THTTPD_PATH=/usr/local/sbin/_thttpd_ +#/sbin/http_link +PORT=`/sbin/getcfg System "Web Access Port"` + +case "$1" in + start) + echo -n "Starting thttpd services:" + /usr/bin/readlink /home/httpd/favicon.ico 1>>/dev/null 2>>/dev/null + if [ $? != 0 ]; then + [ -f /home/httpd/v3_menu/images/favicon.ico ] && /bin/ln -sf v3_menu/images/favicon.ico /home/httpd/favicon.ico + fi + [ -f /tmp/error_thttpd.html ] || /bin/cp /home/httpd/errors/error_thttpd.html /tmp/ + /bin/echo ${PORT} > /var/lock/._thttpd_.port + if [ -d /home/httpd/cgi-bin/apps ]; then + /sbin/user_cmd -1 x > /tmp/.x.json + [ $? != 0 ] || /bin/cp -f /tmp/.x.json /home/httpd/cgi-bin/apps/start.json + /sbin/user_cmd -2 x > /tmp/.x.json + [ $? != 0 ] || /bin/cp -f /tmp/.x.json /home/httpd/cgi-bin/apps/systemPreferences/systemPreferences.json + [ ! -f /tmp/.x.json ] || /bin/rm -f /tmp/.x.json + fi + /sbin/daemon_mgr _thttpd_ start \ + "${THTTPD_PATH} -p ${PORT} -nor -nos -u admin -d /home/httpd -c '**.*' -i /var/lock/._thttpd_.pid" + echo -n " thttpd" + touch /var/lock/subsys/thttpd + [ x`/bin/pidof bcclient` = x ] || /bin/kill -USR1 `/bin/pidof bcclient` + echo "." + ;; + stop) + echo -n "Shutting down thttpd services:" + /sbin/daemon_mgr _thttpd_ stop ${THTTPD_PATH} + /bin/rm -f /var/lock/subsys/thttpd 2>/dev/null + /bin/rm -f /var/lock/._thttpd_.pid 2>/dev/null + /bin/sleep 1 + /bin/pidof _thttpd_ 1>>/dev/null 2>>/dev/null + if [ $? = 0 ]; then + /bin/kill -9 `/bin/pidof _thttpd_` + /bin/sleep 1 + fi + echo -n " thttpd" + echo "." + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: /etc/init.d/thttpd {start|stop|restart}" + exit 1 +esac + +exit 0 diff --git a/timechange_notify.sh b/timechange_notify.sh new file mode 100755 index 0000000..27a3f06 --- /dev/null +++ b/timechange_notify.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +#. /etc/init.d/check_nss2 +NSS_ENABLED=`/sbin/getcfg NVR "NSS Enabled" -d no` + +restart_other_services() +{ +# restart daemon_mgr +#/usr/bin/killall daemon_mgr 2>/dev/null 1>/dev/null +#/sbin/daemon_mgr & 2>/dev/null 1>/dev/null +#/bin/sleep 1 +# restart daemon_mgr.nvr +/usr/bin/killall daemon_mgr.nvr 2>/dev/null 1>/dev/null +/sbin/daemon_mgr.nvr & 2>/dev/null 1>/dev/null +/bin/sleep 1 + +# restart qLogEngined +/bin/kill -INT `pidof qLogEngined` +/sbin/daemon_mgr qLogEngined stop /sbin/qLogEngined +[ -f /sbin/qLogEngined ] && /sbin/daemon_mgr qLogEngined start /sbin/qLogEngined + +# restart crond +/etc/init.d/crond.sh restart +/sbin/gen_next_alarm + +[ -f /sbin/hd_util ] && /sbin/daemon_mgr hd_util stop "/sbin/hd_util -d" +[ -f /sbin/hd_util ] && /sbin/daemon_mgr hd_util start "/sbin/hd_util &" +} + +case "$1" in + before) + echo "timechange_notify.sh before" + if [ "x${NSS_ENABLED}" = "xyes" ]; then + if [ "`/etc/init.d/nvrd.sh started`" == "1" ]; then + [ -f /etc/init.d/nvrd.sh ] && /etc/init.d/nvrd.sh _stop + fi + else + [ -f /etc/init.d/nvrd.sh ] && /etc/init.d/nvrd.sh stop + fi + + ;; + after) + echo "timechange_notify.sh after" + restart_other_services + if [ `/sbin/getcfg NVR Enable -u -d FALSE` = TRUE ]; then + /usr/bin/qcmd rmcache + fi + if [ "x${NSS_ENABLED}" = "xyes" ]; then + if [ "`/etc/init.d/nvrd.sh started`" == "1" ]; then + [ -f /etc/init.d/nvrd.sh ] && /etc/init.d/nvrd.sh _start + fi + else + [ -f /etc/init.d/nvrd.sh ] && /etc/init.d/nvrd.sh start + fi + ;; + *) + echo "Usage: /etc/init.d/timechange_notify.sh {before|after}" + exit 1 +esac + +exit 0 diff --git a/timemachine.sh b/timemachine.sh new file mode 100755 index 0000000..fdfdfac --- /dev/null +++ b/timemachine.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +AFP_TIMEMACHINE_SHARE=`/sbin/getcfg "TimeMachine" "Display Name" -d "TMBackup"` +TM_CONF_FILE=/etc/config/timemachine.conf +TM_VOL_UUID_CONF=/usr/local/etc/netatalk/afp_voluuid.conf +AVAHI_CONF_DIR=/etc/avahi/services +AVAHI_TM_CONF=${AVAHI_CONF_DIR}/timemachine.service +AVAHI_DAEMON=/usr/sbin/avahi-daemon + +#/usr/bin/readlink /share/${AFP_TIMEMACHINE_SHARE} 2>/dev/null 1>/dev/null +#if [ "$?" != "0" ]; then +# echo "TimeMachine share \"${AFP_TIMEMACHINE_SHARE}\" is not exist !!" +# exit 0 +#fi + +create_tm_conf() +{ + BOND=`/sbin/getcfg "Network" "BONDING Support" -d "FALSE"` + if [ "x$BOND" = "xTRUE" ]; then + MAC_ADDR=`/bin/cat /sys/class/net/bond0/address` + else + MAC_ADDR=`/bin/cat /sys/class/net/eth0/address` + fi + + VOL_MNT=`/usr/bin/readlink /share/${AFP_TIMEMACHINE_SHARE} | /bin/cut -d '/' -f 1` + VOL_DEV1=`/bin/mount | /bin/grep "${VOL_MNT} " | /bin/cut -d ' ' -f 1` + VOL_DEV=`/bin/echo $VOL_DEV1 | /bin/cut -d ' ' -f 1` + VOL_UUID=`/usr/local/sbin/blkid | /bin/grep "${VOL_DEV}" | /bin/cut -d\" -f2` + SERVER_NAME=`/sbin/getcfg System "Server Name" -d "NAS"` + + echo "${SERVER_NAME}(TimeMachine)" > ${TM_CONF_FILE} + echo "_adisk._tcp." >> ${TM_CONF_FILE} + echo "9" >> ${TM_CONF_FILE} + echo "sys=waMA=${MAC_ADDR}" >> ${TM_CONF_FILE} + echo "dk0=adVF=0x83,adVN=${AFP_TIMEMACHINE_SHARE},adVU=${VOL_UUID}" >> ${TM_CONF_FILE} + + echo "${AFP_TIMEMACHINE_SHARE} ${VOL_UUID}" > $TM_VOL_UUID_CONF + + /bin/touch /share/${AFP_TIMEMACHINE_SHARE}/.com.apple.timemachine.supported +cat > ${AVAHI_TM_CONF} <<__EOF__ + + + +%h(TimeMachine) + +_adisk._tcp. +9 +sys=waMA=${MAC_ADDR} +dk0=adVF=0x83,adVN=${AFP_TIMEMACHINE_SHARE},adVU=${VOL_UUID} + + +__EOF__ +} + +case "$1" in + start) + /sbin/tm_quota_check + create_tm_conf + ${AVAHI_DAEMON} --reload > /dev/null 2>&1 + ;; + stop) + if [ -f ${TM_CONF_FILE} ]; then + /bin/rm ${TM_CONF_FILE} + fi + /bin/kill -INT `/bin/cat /var/lock/bonjour.timemachine 2>/dev/null` 2>/dev/null 1>/dev/null + /bin/rm -f /var/lock/bonjour.timemachine 2>/dev/null 1>/dev/null + /bin/rm -f ${AVAHI_TM_CONF} + ${AVAHI_DAEMON} --reload > /dev/null 2>&1 + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 +esac + +exit 0 diff --git a/twonkymedia.sh b/twonkymedia.sh new file mode 100755 index 0000000..4ea588c --- /dev/null +++ b/twonkymedia.sh @@ -0,0 +1,302 @@ +#!/bin/sh +# +# MediaServer Control File written by Itzchak Rehberg +# Modified for fedora/redhat by Landon Bradshaw +# Adapted to TwonkyMedia 3.0 by TwonkyVision GmbH +# Adapted to TwonkyMedia 4.0 by TwonkyVision GmbH +# +# This script is intended for SuSE and Fedora systems. Please report +# problems and suggestions at http://www.twonkyvision.de/mantis/ +# +# +############################################################################### +# +### BEGIN INIT INFO +# Provides: twonkymedia +# Required-Start: $network $remote_fs +# Default-Start: 3 5 +# Default-Stop: 0 1 2 6 +# Description: TwonkyVision UPnP server +### END INIT INFO +# +# Comments to support chkconfig on RedHat/Fedora Linux +# chkconfig: 345 71 29 +# description: TwonkyVision UPnP server +# +#==================================================================[ Setup ]=== + +WORKDIR1="/mnt/HDA_ROOT/twonkymedia" +WORKDIR2="`dirname $0`" +DAEMON=twonkymedia +PIDFILE=/var/run/mediaserver.pid +MNT_POINT="/mnt/ext" +TWONKY_SOURCE="${MNT_POINT}/opt/source/twonkymedia.tar.gz" +ROOT_PART="/mnt/HDA_ROOT" +UPDATEPKG_DIR="${ROOT_PART}/update_pkg" +MULTIMEDIA_SHARE=`/sbin/getcfg SHARE_DEF defMultimedia -d Qmultimedia -f /etc/config/def_share.info` +BOND_SUP=`/sbin/getcfg "Network" "BONDING Support" -d "FALSE"` +NIC_NUM=`/sbin/getcfg "Network" "Interface Number" -d "FALSE"` +APP_RUNTIME_CONF="/var/.application.conf" +TwonkyMedia_Enable=`/sbin/getcfg TwonkyMedia Enable -u -d FALSE` +RETVAL=0 + +#=================================================================[ Script ]=== +clean_twonky_cache() +{ + if [ -d /mnt/HDA_ROOT/twonkymedia/twonkymedia.db/cache ]; then + /bin/rm -rf /mnt/HDA_ROOT/twonkymedia/twonkymedia.db/cache/* + [ $? = 0 ] && echo "TwonkyMedia cache have been cleaned." + fi + if [ x"`/bin/cat /etc/config/crontab | /bin/grep "twonkymedia"`" = x ]; then + echo "0 3 * * * /bin/rm -rf /mnt/HDA_ROOT/twonkymedia/twonkymedia.db/cache/*" >> /etc/config/crontab + /usr/bin/crontab /etc/config/crontab + fi +} + +move_db_path_to_hdd() +{ + volume_test=`/sbin/getcfg ${MULTIMEDIA_SHARE} path -f /etc/smb.conf | cut -d '/' -f 3` + [ "x${volume_test}" = "x" ] || volume=${volume_test} + if [ ! -d "/share/${volume}/${MULTIMEDIA_SHARE}" ]; then + /bin/echo "db can't be moved to HDD" + /bin/echo "Default share ${MULTIMEDIA_SHARE} is not found." + #/sbin/write_log "Default share ${MULTIMEDIA_SHARE} is not found. TwonkyMedia start failed." 2 + exit 1 + fi + [ -d /share/${volume}/.@twonkymedia.db ] || /bin/mkdir /share/${volume}/.@twonkymedia.db + twonkydb=`/usr/bin/readlink "/mnt/HDA_ROOT/twonkymedia/twonkymedia.db" 2>>/dev/null` + if [ -z $twonkydb ] || [ "$twonkydb" != "/share/${volume}/.@twonkymedia.db" ]; then + /bin/rm -rf /mnt/HDA_ROOT/twonkymedia/twonkymedia.db + /bin/ln -sf /share/${volume}/.@twonkymedia.db /mnt/HDA_ROOT/twonkymedia/twonkymedia.db + fi + [ ! -f "${WORKDIR}/twonkymediaserver6-log.txt" ] || /bin/rm -f "${WORKDIR}/twonkymediaserver6-log.txt" + [ -f /share/${volume}/.@twonkymedia.db/twonkymediaserver-log.txt ] || /bin/touch /share/${volume}/.@twonkymedia.db/twonkymediaserver-log.txt + /bin/ln -sf /share/${volume}/.@twonkymedia.db/twonkymediaserver-log.txt "${WORKDIR}/twonkymediaserver6-log.txt" + logtxt=`/usr/bin/readlink "/mnt/HDA_ROOT/twonkymedia/twonkymediaserver-log.txt" 2>>/dev/null` + if [ "x$logtxt" != "x/share/${volume}/.@twonkymedia.db/twonkymediaserver-log.txt" ]; then + /bin/rm -rf /mnt/HDA_ROOT/twonkymedia/twonkymediaserver-log.txt + /bin/ln -sf /share/${volume}/.@twonkymedia.db/twonkymediaserver-log.txt /mnt/HDA_ROOT/twonkymedia/twonkymediaserver-log.txt + fi + + # twonky 5.0 default config is /var/twonkymedia + if [ -d "/var/twonkymedia" ]; then + /bin/rm -rf /var/twonkymedia + fi + /usr/bin/readlink /var/twonkymedia 2>>/dev/null + if [ $? = 0 ]; then + /bin/rm /var/twonkymedia + fi + /bin/ln -sf /share/${volume}/.@twonkymedia.db /var/twonkymedia + /bin/rm -rf /share/twonkymedia 2>>/dev/null + /bin/ln -sf /share/${volume}/.@twonkymedia.db /share/twonkymedia +} + +check_twonky_qpkg() +{ + QPKG_Twonky_Ver=`/sbin/getcfg TwonkyMedia Version -d "0.0" -f /etc/config/qpkg.conf` + QPKG_Twonky_Enable=`/sbin/getcfg TwonkyMedia ENABLE -u -d "FALSE" -f /etc/config/qpkg.conf` + QPKG_Twonky_Shell=`/sbin/getcfg TwonkyMedia Shell -d "null" -f /etc/config/qpkg.conf` + if [ "x$QPKG_Twonky_Enable" = "xTRUE" ] && [ -x "${QPKG_Twonky_Shell}" ]; then + ${QPKG_Twonky_Shell} stop 1>>/dev/null 2>>/dev/null + /sbin/setcfg TwonkyMedia ENABLE FALSE -f /etc/config/qpkg.conf + fi +} + +# Source function library. +if [ -f /etc/rc.status ]; then + # SUSE + . /etc/rc.status + rc_reset +else + # Reset commands if not available + rc_status() { + case "$1" in + -v) + true + ;; + *) + false + ;; + esac + echo + } + alias rc_exit=exit +fi + +#QNAP + if [ -f ${UPDATEPKG_DIR}/twonkymedia.tar.gz ]; then + [ ! -f $TWONKY_SOURCE ] || /bin/rm -f $TWONKY_SOURCE + TWONKY_SOURCE="${UPDATEPKG_DIR}/twonkymedia.tar.gz" + fi + if [ -f $TWONKY_SOURCE ] && [ ! -d ${MNT_POINT}/opt/twonkymedia ]; then + /bin/mkdir ${MNT_POINT}/opt/twonkymedia + /bin/rm -f ${WORKDIR1} 1>>/dev/null 2>>/dev/null + /bin/ln -sf ${MNT_POINT}/opt/twonkymedia ${WORKDIR1} + #/bin/cp $TWONKY_SOURCE $WORKDIR1 + #/bin/gunzip $WORKDIR1/twonkymedia.tar.gz + /bin/tar -zxf $TWONKY_SOURCE -C $WORKDIR1 + #/bin/rm $WORKDIR1/twonkymedia.tar + /bin/sync + fi + [ -d /rpc ] || /bin/mkdir /rpc +#END + +if [ -x "$WORKDIR1" ]; then +WORKDIR="$WORKDIR1" +else +WORKDIR="$WORKDIR2" +fi + +if [ ! -f "${WORKDIR}/${DAEMON}" ]; then + DAEMON=twonkymusic +fi +TWONKYSRV="${WORKDIR}/${DAEMON}" +INIFILE="/etc/config/twonkyvision-mediaserver6.ini" +DEFAULT_INIFILE="${WORKDIR}/twonkymedia6-default.ini" +DEFAULT_SERVER_INIFILE="${WORKDIR}/twonkymedia-server-default.ini" +LOG_FILE="${WORKDIR}/twonkymediaserver6-log.txt" +TwonkyMedia_Hide=`/sbin/getcfg DISABLE upnp -d 0 -f $APP_RUNTIME_CONF` +if [ "x$TwonkyMedia_Hide" = "x1" ]; then + /sbin/setcfg TwonkyMedia Enable FALSE + TwonkyMedia_Enable="FALSE" +fi + +cd $WORKDIR + +case "$1" in + start) + if [ "x$TwonkyMedia_Enable" != "xTRUE" ]; then + echo "UPnP MediaServer is disabled. If the process still existed, try to run \"${0} stop\"" + exit 0 + fi + check_twonky_qpkg + clean_twonky_cache + move_db_path_to_hdd + if [ -e $PIDFILE ]; then + PID=`cat $PIDFILE` + echo "Twonky server seems already be running under PID $PID" + echo "(PID file $PIDFILE already exists). Checking for process..." + running=`ps --no-headers -o "%c" -p $PID` + if ( [ "${DAEMON}"=="${running}" ] ); then + echo "Process IS running. Not started again." + else + echo "Looks like the daemon crashed: the PID does not match the daemon." + echo "Removing flag file..." + rm $PIDFILE + $0 start + exit $? + fi + exit 0 + else + if [ ! -x "${TWONKYSRV}" ]; then + echo "Twonky servers not found". + rc_status -u + exit $? + fi + + echo -n "Starting UPnP MediaServer: ($TWONKYSRV) " + + _contentdir=`/sbin/getcfg "" contentdir -d "/Qmultimedia" -f ${DEFAULT_INIFILE}` + [ "+A|/${MULTIMEDIA_SHARE}" = "${_contentdir}" ] || /bin/sed -i 's/^contentdir.*$/'"contentdir=+A|\/${MULTIMEDIA_SHARE}"'/' ${DEFAULT_INIFILE} + _contentdir=`/sbin/getcfg "" contentdir -d "/Qmultimedia" -f ${DEFAULT_SERVER_INIFILE}` + [ "+A|/${MULTIMEDIA_SHARE}" = "${_contentdir}" ] || /bin/sed -i 's/^contentdir.*$/'"contentdir=+A|\/${MULTIMEDIA_SHARE}"'/' ${DEFAULT_SERVER_INIFILE} + + if [ ! -f ${INIFILE} ]; then + /bin/cp ${DEFAULT_INIFILE} ${INIFILE} + fi + + # end + if [ `/sbin/getcfg TwonkyMedia "Web Enable" -u -d FALSE` = FALSE ]; then + $TWONKYSRV -inifile "${INIFILE}" -enableweb 1 -powersavemode 1 -logfile ${LOG_FILE} -suppressmenu mediafeeds 2>/dev/null 1>/dev/null & + else + enableweb=`/sbin/getcfg main enableweb -d 9 -f "${INIFILE}"` # 9 should not exist + if [ $enableweb = 1 ] || [ $enableweb = 0 ]; then + /sbin/setcfg main enableweb 2 -f "${INIFILE}" + fi + $TWONKYSRV -inifile "${INIFILE}" -enableweb 2 -powersavemode 1 -logfile ${LOG_FILE} -suppressmenu mediafeeds 2>/dev/null 1>/dev/null & + fi + rc_status -v + /bin/sleep 2 + + fi + ;; + stop) + if [ ! -e $PIDFILE ]; then + echo "Shutting down UPnP MediaServer services: twonkymedia." + echo "PID file $PIDFILE not found, stopping server anyway..." + killall twonkymedia twonkymusic 2>/dev/null 1>/dev/null + rc_status -u +# exit 3 + else + echo -n "Shutting down UPnP MediaServer services: twonkymedia." + PID=`cat $PIDFILE` + kill -s TERM $PID + kill -9 `pidof twonkymediaserver` + rm -f $PIDFILE + # end + rc_status -v + fi + + _pid=`/bin/pidof twonkymediaserver` + [ -z "$_pid" ] || kill $_pid 2>/dev/null 1>/dev/null + _pid=`/bin/pidof twonkymedia` + [ -z "$_pid" ] || kill $_pid 2>/dev/null 1>/dev/null + + if [ "x${NIC_NUM}" = "x1" ]; then + /sbin/route del -net 224.0.0.0 netmask 240.0.0.0 dev eth0 2> /dev/null 1>/dev/null + else + /sbin/route del -net 224.0.0.0 netmask 240.0.0.0 dev bond0 2> /dev/null 1>/dev/null + /sbin/route del -net 224.0.0.0 netmask 240.0.0.0 dev eth0 2> /dev/null 1>/dev/null + /sbin/route del -net 224.0.0.0 netmask 240.0.0.0 dev eth1 2> /dev/null 1>/dev/null + fi + ;; + reload) + [ -f ${INIFILE} ] || /bin/cp ${DEFAULT_INIFILE} ${INIFILE} + if [ ! -e $PIDFILE ]; then + echo "PID file $PIDFILE not found, stopping server anyway..." + killall twonkymedia twonkymusic 2>/dev/null 1>/dev/null + rc_status -u + exit 3 + else + echo -n "Reloading Twonky server ... " + PID=`cat $PIDFILE` + kill -s HUP $PID + rc_status -v + fi + ;; + restart) + $0 stop + /bin/sleep 2 + $0 start + ;; + status) + if [ ! -e $PIDFILE ]; then + running="`ps ax --no-headers | grep -e twonkymedia -e twonkymusic | grep -v grep | grep -v twonkymedia.sh | cut -d ' ' -f 1`" + if [ "${running}" == "" ]; then + echo "No twonky server is running" + else + echo "A twonky server seems to be running (PID: "${running}"), but no PID file exists." + echo "Probably no write permission for ${PIDFILE}." + fi + exit 0 + fi + PID=`cat $PIDFILE` + running=`ps --no-headers -o "%c" -p $PID` + if ( [ "${DAEMON}"=="${running}" ] ); then + echo "Twonky server IS running." + else + echo "Looks like the daemon crashed: the PID does not match the daemon." + fi + ;; + *) + echo "" + echo "Twonky server" + echo "-------------" + echo "Syntax:" + echo " $0 {start|stop|restart|reload|status}" + echo "" + exit 3 + ;; +esac + +rc_exit diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..05d2d4a --- /dev/null +++ b/update.sh @@ -0,0 +1,254 @@ +#!/bin/sh +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin + +UPDATE_FOLDER="/mnt/update" +UPDATEPKG_DIR="/mnt/HDA_ROOT/update_pkg" +PIC_RAW="/sbin/pic_raw" +SET_STATUS_LED="/sbin/set_status_led" +UPDATE_PROCESS="/tmp/update_process" +UPDATE_FW_PROCESS="/tmp/update_fx_process" +RAIDMNG_STATUS="/tmp/raidmng.status" +BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null` +USING_RAM1=0 +FUNC_SWITCH_CONF="/etc/config/.funcSwitch.conf" +APP_RUNTIME_CONF="/var/.application.conf" +UPDATE_LOCKED=6 + +begin_led() +{ +# check if the HAL subsystem exist + if [ -x /sbin/hal_app ]; then + /sbin/hal_app --status_led_set enc_id=0,event=64,status=1 + /sbin/hal_app --power_led_blink enc_id=0,enable=1 + else + ${SET_STATUS_LED} 64 1; ${PIC_RAW} 76 + fi +} +end_led() +{ +# check if the HAL subsystem exist + if [ -x /sbin/hal_app ]; then + /sbin/hal_app --status_led_set enc_id=0,event=64,status=0 + /sbin/hal_app --power_led enc_id=0,enable=1 + else + ${SET_STATUS_LED} 64 0; ${PIC_RAW} 77 + fi +} +do_beep() +{ + + if [ x`/sbin/getcfg Misc "Buzzer Quiet Enable"` != "xTRUE" ]; then +# check if the HAL subsystem exist + if [ -x /sbin/hal_app ]; then + /sbin/hal_app --se_buzzer enc_id=0,mode=1 + sleep 1 + /sbin/hal_app --se_buzzer enc_id=0,mode=1 + sleep 1 + /sbin/hal_app --se_buzzer enc_id=0,mode=1 + else + ${PIC_RAW} 81; sleep 1; ${PIC_RAW} 81; sleep 1; ${PIC_RAW} 81 + fi + fi +} + +remove_update() +{ + /bin/rm -rf ${UPDATE_FOLDER}/* +} + +get_new_ver() +{ + local filename=$path_name + set -- `/usr/bin/du -b "$filename"` + local pos=`expr $1 - 48` + /bin/dd if=$filename of=${UPDATE_FOLDER}/newver skip=$pos bs=1 count=16 + [ $? = 0 ] && cat ${UPDATE_FOLDER}/newver || echo "" +} + +md5="0" +cksum="0" +project_name=`/sbin/getcfg Project Name -d QNAP -f /var/default` + +get_md5_cksum() +{ + if [ "x$project_name" = "xAthens" ]; then + [ -f /bin/md5sum ] || /bin/ln -sf /bin/busybox /bin/md5sum + md5=`/bin/md5sum $path_name | /bin/cut -d ' ' -f 1` + echo "md5=${md5}" + else + cksum=`/sbin/cksum $path_name | /bin/cut -d ' ' -f 1` + echo "cksum=${cksum}" + fi +} + +set_md5_cksum() +{ + if [ "x$project_name" = "xAthens" ]; then + /sbin/setsum md5 ${md5} + else + /sbin/setsum cksum ${cksum} + fi +} + +check_hidden_feature() +{ +if [ $1 \> $2 ]; then + echo "Downgrade from $1 to $2" + if [ "x1" = "x`/sbin/getcfg OPTION HomeFeature -d 0 -f $APP_RUNTIME_CONF`" ]; then + /sbin/setcfg DISABLE qdownload 1 -f $APP_RUNTIME_CONF + /sbin/setcfg DISABLE musics 1 -f $APP_RUNTIME_CONF + /sbin/setcfg DISABLE photos 1 -f $APP_RUNTIME_CONF + /sbin/setcfg DISABLE qmultimedia 1 -f $APP_RUNTIME_CONF + /sbin/setcfg DISABLE iTunes 1 -f $APP_RUNTIME_CONF + /sbin/setcfg DISABLE upnp 1 -f $APP_RUNTIME_CONF + /sbin/setcfg DISABLE survielance 1 -f $APP_RUNTIME_CONF + /sbin/setcfg DISABLE HomeFeature 1 -f $APP_RUNTIME_CONF + if [ -f $FUNC_SWITCH_CONF ]; then + /sbin/setcfg DISABLE qdownload 1 -f $FUNC_SWITCH_CONF + /sbin/setcfg DISABLE musics 1 -f $FUNC_SWITCH_CONF + /sbin/setcfg DISABLE photos 1 -f $FUNC_SWITCH_CONF + /sbin/setcfg DISABLE qmultimedia 1 -f $FUNC_SWITCH_CONF + /sbin/setcfg DISABLE iTunes 1 -f $FUNC_SWITCH_CONF + /sbin/setcfg DISABLE upnp 1 -f $FUNC_SWITCH_CONF + /sbin/setcfg DISABLE survielance 1 -f $FUNC_SWITCH_CONF + /sbin/setcfg DISABLE HomeFeature 1 -f $FUNC_SWITCH_CONF + fi + /sbin/setcfg OPTION HomeFeature 0 -f $APP_RUNTIME_CONF + echo "HomeFeature disabled." + fi +fi +} +do_exit() +{ + local ret=0 + local old_ver=`/sbin/getcfg System Version` + local new_ver=`/bin/cat ${UPDATE_FOLDER}/newver` + + if [ "x${BOOT_CONF}" = "xTS-NASX86" ] && [ "x$USING_RAM1" = "x1" ]; then + /bin/umount /mnt/ram1 2>/dev/null 1>/dev/null + fi + if [ $1 != $UPDATE_LOCKED ]; then + /sbin/lock_system_update unlock + fi + + case $1 in + 0)#normal exit + set_md5_cksum + ret=0 + [ ! -z $new_ver ] && [ ! -z $old_ver ] && check_hidden_feature "$old_ver" "$new_ver" + [ ! -z $new_ver ] \ + && /sbin/write_log "[Firmware Upgrade] System updated successfully from $old_ver to $new_ver." 4 \ + || /sbin/write_log "[Firmware Upgrade] System updated successfully." 4 + ;; + 1)#list tar failed + echo -1 > ${UPDATE_PROCESS} + echo -1 > ${UPDATE_FW_PROCESS} + ret=1 + [ ! -z $new_ver ] \ + && /sbin/write_log "[Firmware Upgrade] System update failed." 1 \ + || /sbin/write_log "[Firmware Upgrade] System update failed." 1 + ;; + 2)#extract tar failed + echo -2 > ${UPDATE_PROCESS} + echo -2 > ${UPDATE_FW_PROCESS} + ret=1 + [ ! -z $new_ver ] \ + && /sbin/write_log "[Firmware Upgrade] System update failed." 1 \ + || /sbin/write_log "[Firmware Upgrade] System update failed." 1 + ;; + $UPDATE_LOCKED)#update is locked + echo -$UPDATE_LOCKED > ${UPDATE_PROCESS} + echo -$UPDATE_LOCKED > ${UPDATE_FW_PROCESS} + ret=1 + /sbin/write_log "[Firmware Upgrade] System update failed. Maybe system is rebooting or another update is processing" 1 + ;; + *) + echo -5 > ${UPDATE_PROCESS} + echo -5 > ${UPDATE_FW_PROCESS} + ret=1 + [ ! -z $new_ver ] \ + && /sbin/write_log "[Firmware Upgrade] System update failed." 1 \ + || /sbin/write_log "[Firmware Upgrade] System update failed." 1 + ;; + esac + + if [ $ret != 0 ]; then + remove_update + fi + /sbin/setcfg -e System "QPKG CENTER XML" + grep VOLUME ${RAIDMNG_STATUS} 1>>/dev/null 2>>/dev/null + if [ $? = 0 ]; then + grep VOLUME ${RAIDMNG_STATUS} | grep "\-1" 1>>/dev/null 2>>/dev/null + [ $? != 0 ] && exit $ret + fi + + + end_led + exit $ret +} + +remove_pre_pkg() +{ + if [ -f "${UPDATEPKG_DIR}/antivirus.tgz" ]; then + /etc/init.d/antivirus.sh stop 2>>/dev/null + /bin/rm -f "${UPDATEPKG_DIR}/antivirus.tgz" + fi +} + +begin_led +/sbin/lock_system_update lock +if [ $? != 0 ]; then + do_exit $UPDATE_LOCKED +fi +path_name=$1 +if [ -f $path_name ]; then + get_md5_cksum + _tgz=${path_name}.tgz + if [ "x${BOOT_CONF}" = "xTS-NASX86" ]; then + _imgsize=`/usr/bin/du -k $path_name | /bin/cut -f 1` + _imgsize=`/usr/bin/expr $_imgsize \* 2` + /sbin/mke2fs -m0 /dev/ram1 2>/dev/null 1>/dev/null + [ -d /mnt/ram1 ] || /bin/mkdir /mnt/ram1 > /dev/null + /bin/mount /dev/ram1 /mnt/ram1 2>/dev/null 1>/dev/null + if [ $? = 0 ]; then + _ram1size=`/bin/df -k | /bin/grep "/dev/ram1" | /bin/awk '{print $4}'` + if [ ! -z ${_ram1size} ] && [ ${_ram1size} -gt ${_imgsize} ]; then + _tgz=/mnt/ram1/update_image.tgz + USING_RAM1=1 + else + /bin/umount /mnt/ram1 2>/dev/null 1>/dev/null + fi + fi + fi + #remove existing package + #remove_pre_pkg + /sbin/PC1 d QNAPNASVERSION4 $path_name ${_tgz}; \ + get_new_ver + /sbin/degrade_check $path_name + if [ $? = 0 ]; then + do_exit 3 + fi + /bin/rm -f $path_name + /bin/tar tzf ${_tgz}; [ $? != 0 ] && do_exit 1; + /bin/tar xzf ${_tgz} -C ${UPDATE_FOLDER}; [ $? != 0 ] && do_exit 2; \ + /bin/rm -f ${_tgz} + if [ "x${BOOT_CONF}" = "xTS-NASX86" ] && [ "x$USING_RAM1" = "x1" ]; then + /bin/umount /mnt/ram1 2>/dev/null 1>/dev/null + fi + [ -f ${UPDATE_FOLDER}/update_img.sh ] && /bin/mv ${UPDATE_FOLDER}/update_img.sh /tmp/update_img.sh + + if [ -f /tmp/update_img.sh ]; then + /tmp/update_img.sh $path_name + else + /etc/init.d/update_img.sh $path_name + fi + if [ $? = 0 ]; then +# do_beep +# do_beep_check_flag + do_exit 0 + elif [ `/bin/cat $UPDATE_PROCESS`x != -3x ]; then + do_exit 5 + fi +else + do_exit 1 +fi diff --git a/update_def_share.sh b/update_def_share.sh new file mode 100755 index 0000000..4af3715 --- /dev/null +++ b/update_def_share.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +DEF_SHARE="/etc/config/def_share.info" +GETCFG="/sbin/getcfg" +SED="/bin/sed" + +DOWNLOAD=`${GETCFG} SHARE_DEF defDownload -d Download -f ${DEF_SHARE}` +MULTIMEDIA=`${GETCFG} SHARE_DEF defMultimedia -d Multimedia -f ${DEF_SHARE}` +RECORDINGS=`${GETCFG} SHARE_DEF defRecordings -d Recordings -f ${DEF_SHARE}` +USB=`${GETCFG} SHARE_DEF defUsb -d Usb -f ${DEF_SHARE}` +WEB=`${GETCFG} SHARE_DEF defWeb -d Web -f ${DEF_SHARE}` + +${SED} -i "s/@Qrecordings@/${RECORDINGS}/g" /home/httpd/cgi-bin/Qrecordings/help/*.html +${SED} -i "s/@Qmultimedia@/${MULTIMEDIA}/g" /home/httpd/help/inc/app/*.js +${SED} -i "s/@Qmultimedia@/${MULTIMEDIA}/g" /home/httpd/cgi-bin/inc/*.js +[ ! -d /home/httpd/cgi-bin/langs ] || ${SED} -i "s/@Qweb@/${WEB}/g" /home/httpd/cgi-bin/langs/lang_*.js +${SED} -i "s/@Qweb@/${WEB}/g" /home/httpd/cgi-bin/inc/*.js + diff --git a/update_img.sh b/update_img.sh new file mode 100755 index 0000000..eb66623 --- /dev/null +++ b/update_img.sh @@ -0,0 +1,650 @@ +#!/bin/sh +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin + +PIC_RAW="/sbin/pic_raw" +TMP_UPDATE_FLAG="/tmp/update_flag" +UPDATE_PROCESS="/tmp/update_process" +UPDATE_FW_PROCESS="/tmp/update_fw_process" +UPDATE_FOLDER="/mnt/update" +BLOCK_SIZE=512 +# 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" +else + BOOT_DEV="/dev/sdx" + EXT_ROOT="/dev/sda4" +fi +PURE_BOOT_DEV=$(/bin/echo $BOOT_DEV | /bin/cut -f3 -d/) +FLASH_BOOT=${BOOT_DEV}1 +FLASH_RFS1=${BOOT_DEV}2 +FLASH_RFS2=${BOOT_DEV}3 +FLASH_BOOT_MP="/root/FLASH_BOOT" +FLASH_RFS1_MP="/root/FLASH_RFS1" +FLASH_RFS2_MP="/root/FLASH_RFS2" +FLASH_RFS1_SIZE=52560 +#FLASH_SIZE_ARM=mtd1+mtd2+mtd3 +FLASH_SIZE_ARM=14336 +FLASH_SIZE_PPC=14336 +FLASH_RFS1_SIZE_X59=230188 +FLASH_RFS1_BLOCK_X59=484608 +FLASH_RFS1_SIZE_X59H=110000 +FLASH_RFS1_BLOCK_X59H=235008 +FLASH_RFS_ERR=0 +DEFAULT_CFG_FILE="/etc/config/uLinux.conf" +IMG_FILE_LIST="bzImage initrd.boot rootfs2.bz rootfs_ext.tgz" +MNT_ROOTFS2_TMP="/rootfs2_tmp" +FLASH_KERNEL="/dev/mtdblock1" +FLASH_ROOTFS_BASIC="/dev/mtdblock2" +FLASH_ROOTFS2="/dev/mtdblock3" +FLASH_FDT="/dev/mtdblock6" +IMG_FILE_LIST_ARM="uImage initrd.boot rootfs2.img" +IMG_FILE_LIST_PPC="uImage initrd.uboot rootfs2.bz canyonlands_qnap.dts" +BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null` +FLASH_RFS1_BLOCK=`/bin/cat /sys/block/${PURE_BOOT_DEV}/${PURE_BOOT_DEV}2/size 2>/dev/null` +Project_Name=`/sbin/getcfg Project Name -d null -f /var/default` +TMP_CONFIG="/tmp/nasconfig_tmp" +MIN_FSIZE=200 #minimum config file size required + +do_beep() +{ + + if [ x`/sbin/getcfg Misc "Buzzer Quiet Enable"` != "xTRUE" ]; then +# check if the HAL subsystem exist + if [ -x /sbin/hal_app ]; then + /sbin/hal_app --se_buzzer enc_id=0,mode=1 + sleep 1 + /sbin/hal_app --se_buzzer enc_id=0,mode=1 + sleep 1 + /sbin/hal_app --se_buzzer enc_id=0,mode=1 + else + ${PIC_RAW} 81; sleep 1; ${PIC_RAW} 81; sleep 1; ${PIC_RAW} 81 + fi + fi +} + + +check_tune_config_partition() +{ +echo check_tune_config_partition $1 $2 >> /tmp/check.log +NAS_CONFIG_BAK=/tmp/nas_config.tgz +NAS_CONFIG_IMG=/tmp/nas_config.img +TMP_MP=/tmp/nasconfig_mp +NAS_CONFIG=$1 +NAS_CONFIG_SIZE=$2 +[ -d $TMP_MP ] || /bin/mkdir $TMP_MP +/bin/mount $NAS_CONFIG $TMP_MP -o ro +CFG_SIZE=`/bin/df -k | /bin/grep "$NAS_CONFIG" | /bin/awk '{print $2}'` +echo Current NAS config formatted size is $CFG_SIZE >> /tmp/check.log +if [ $CFG_SIZE -ge $NAS_CONFIG_SIZE ]; then + #Backup /tmp/mp6 + cd $TMP_MP + /bin/tar czf $NAS_CONFIG_BAK * + RET=$? + cd / + /bin/umount $TMP_MP + echo Backup config_partition return $RET >> /tmp/check.log + if [ $RET = 0 ]; then + if [ -f /opt/nasconfig_fs.img.tgz ]; then + echo Use /opt/nasconfig_fs.img.tgz >> /tmp/check.log + /bin/tar xzf /opt/nasconfig_fs.img.tgz -O > $NAS_CONFIG + RET=$? + else + echo Create a image with size $NAS_CONFIG_SIZE >> /tmp/check.log + /bin/dd if=/dev/zero of=$NAS_CONFIG_IMG bs=1k count=$NAS_CONFIG_SIZE + RET=$? + if [ $RET = 0 ]; then + echo Fine tune config partition >> /tmp/check.log + /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 + fi + /bin/rm $NAS_CONFIG_IMG + fi + echo Dump config_partition image return $RET >> /tmp/check.log + if [ $RET = 0 ]; then + /bin/mount $NAS_CONFIG $TMP_MP + /bin/tar xzf $NAS_CONFIG_BAK -C $TMP_MP + /bin/umount $TMP_MP + fi + fi + /bin/rm $NAS_CONFIG_BAK +fi +/bin/umount $TMP_MP +/sbin/tune2fs -i 0 -c 0 ${NAS_CONFIG} +/bin/sync +} + +remove_update() +{ + for i in $IMG_FILE_LIST + do + if [ -f "$UPDATE_FOLDER/$i" ]; then + /bin/rm -f ${UPDATE_FOLDER}/${i}* 2>/dev/null + fi + done + /bin/rm -f ${path_name}* 2>>/dev/null + if [ $1 = 1 ]; then + /bin/rm -rf ${UPDATE_FOLDER}/* + fi + [ -d "/mnt/HDA_ROOT/update_pkg" ] && /bin/rm -f /mnt/HDA_ROOT/update_pkg/*.qfix 2>>/dev/null + [ ! -d "/mnt/HDA_ROOT/update_pkg/.qfix" ] || /bin/rm -rf /mnt/HDA_ROOT/update_pkg/.qfix 2>>/dev/null + [ ! -f /etc/config/qfix.conf ] || /bin/rm -f /etc/config/qfix.conf 2>>/dev/null + /bin/grep "/dev/ram2" /proc/mounts | /bin/grep "${UPDATE_FOLDER} " 2>/dev/null 1>/dev/null + if [ $? = 0 ]; then + /bin/umount /dev/ram2 2>/dev/null + readlink ${UPDATE_FOLDER} 1>/dev/null 2>/dev/null + [ $? != 0 ] || /bin/rm -rf ${UPDATE_FOLDER} + fi +} + +get_new_ver() +{ + local filename=$path_name + set -- `ls -l "$path_name"` + local pos=`expr $5 - 48` + /bin/dd if=$filename of=${UPDATE_FOLDER}/newver skip=$pos bs=1 count=16 + [ $? = 0 ] && cat ${UPDATE_FOLDER}/newver || echo "" +} + +do_exit() +{ + local ret=0 + local old_ver=`/sbin/getcfg System Version` + local new_ver=`/bin/cat ${UPDATE_FOLDER}/newver` + + case $1 in + 0)#normal exit + ret=0 + [ ! -z $new_ver ] \ + && /sbin/write_log "[Firmware Upgrade] System updated successfully from $old_ver to $new_ver." 4 \ + || /sbin/write_log "[Firmware Upgrade] System updated successfully." 4 + ;; + 2)#size check failed + echo -2 > ${UPDATE_PROCESS} + echo -2 > ${UPDATE_FW_PROCESS} + ret=1 + [ ! -z $new_ver ] \ + && /sbin/write_log "[Firmware Upgrade] System update failed from $old_ver to $new_ver due to update image size error." 1 \ + || /sbin/write_log "[Firmware Upgrade] System update failed." 1 + ;; + 3)#CRC check failed + echo -3 > ${UPDATE_PROCESS} + echo -3 > ${UPDATE_FW_PROCESS} + ret=1 + [ ! -z $new_ver ] \ + && /sbin/write_log "[Firmware Upgrade] System update failed from $old_ver to $new_ver." 1 \ + || /sbin/write_log "[Firmware Upgrade] System update failed." 1 + ;; + 4)#Flash failed + echo -4 > ${UPDATE_PROCESS} + echo -4 > ${UPDATE_FW_PROCESS} + ret=1 + [ ! -z $new_ver ] \ + && /sbin/write_log "[Firmware Upgrade] System update failed from $old_ver to $new_ver due to flash read/write error." 1 \ + || /sbin/write_log "[Firmware Upgrade] System update failed due to flash read/write error." 1 + ;; + 7) + echo -7 > ${UPDATE_PROCESS} + echo -7 > ${UPDATE_FW_PROCESS} + ret=1 + /sbin/write_log "[Firmware Upgrade] System update failed. The system is being shut down. Please try again after the system started." 1 + ;; + *) + echo -5 > ${UPDATE_PROCESS} + echo -5 > ${UPDATE_FW_PROCESS} + ret=1 + [ ! -z $new_ver ] \ + && /sbin/write_log "[Firmware Upgrade] System update failed from $old_ver to $new_ver." 1 \ + || /sbin/write_log "[Firmware Upgrade] System update failed." 1 + ;; + esac + + if [ $ret = 0 ]; then + remove_update 2 + else + remove_update 1 + fi + /bin/mv /usr/local/sbin/blkid_ /usr/local/sbin/blkid 2>/dev/null + /sbin/setcfg -e System "QPKG CENTER XML" + exit $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 +} + +size_check() +{ + local sizetotal=0 + local sizekb=0 + for i in $IMG_FILE_LIST + do + if [ -f "$UPDATE_FOLDER/$i" ]; then + sizekb=`/usr/bin/du -k "$UPDATE_FOLDER/$i" | /bin/cut -f 1 -d '/'` + sizetotal=`/usr/bin/expr $sizetotal + $sizekb` + fi + done + [ $sizetotal -le $FLASH_RFS1_SIZE ] || do_exit 2 + return 0 +} + +size_check_arm() +{ + local mtd1_size=2097152 + local mtd2_size=9437184 + local mtd3_size=3145728 + + for i in $IMG_FILE_LIST + do + if [ -f "$UPDATE_FOLDER/$i" ] && [ -f "$UPDATE_FOLDER/${i}.cksum" ]; then + if [ ${i} = uImage ]; then + mtdsize=$mtd1_size + elif [ ${i} = initrd.boot ]; then + mtdsize=$mtd2_size + elif [ ${i} = rootfs2.img ]; then + mtdsize=$mtd3_size + else + break + fi + /bin/echo -n "Check $i size ... " + tmpsize=`/bin/cat "$UPDATE_FOLDER/${i}.cksum" | /bin/cut -d ' ' -f 2` + if [ -z "$tmpsize" ] || [ $tmpsize -gt $mtdsize ]; then + /bin/echo Error + do_exit 2 + fi + /bin/echo Pass + fi + done + return 0 +} + +CRC_check() +{ + for i in $IMG_FILE_LIST rootfs_ext.tgz qpatch.tgz + do + if [ -f "$UPDATE_FOLDER/$i" ]; then + check_sum "$UPDATE_FOLDER/$i" "$UPDATE_FOLDER/$i.cksum" + [ $? = 0 ] || do_exit 3 + fi + done + return 0 +} + +DOM_CRC_check() +{ + for i in $IMG_FILE_LIST + do + /bin/echo -n "Checking ${i} ... " + check_sum "${1}/boot/$i" "$UPDATE_FOLDER/$i.cksum" + if [ $? != 0 ]; then + /bin/umount "${1}" 1>>/dev/null 2>>/dev/null + /bin/echo "Failed." + do_exit 4 + fi + /bin/echo "ok" + done + return 0 +} + +set_status_flag() +{ + /bin/mount | /bin/grep $EXT_ROOT 1>>/dev/null 2>>/dev/null + if [ $? = 0 ]; then + echo $1 > $TMP_UPDATE_FLAG + # 402653200 = 384M + 16 bytes = 384 * 1024 * 1024 + 16 + /bin/dd if=$TMP_UPDATE_FLAG of=$EXT_ROOT seek=402653200 bs=1 count=1 + /bin/rm -f $TMP_UPDATE_FLAG + fi +} +refresh_flash_config_file() +{ + [ -d $TMP_CONFIG ] || /bin/mkdir $TMP_CONFIG + + if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then + /bin/mount /dev/mtdblock5 $TMP_CONFIG + elif [ "x${BOOT_CONF}" = "xTS-NASPPC" ]; then + /bin/mount /dev/mtdblock5 $TMP_CONFIG + else + /bin/mount ${BOOT_DEV}6 $TMP_CONFIG + fi + [ ! -f ${TMP_CONFIG}/system.map.key ] || rm -f ${TMP_CONFIG}/system.map.key + [ ! -f ${TMP_CONFIG}/smb.conf ] || rm -f ${TMP_CONFIG}/smb.conf + [ ! -f ${TMP_CONFIG}/smb.conf.cksum ] || rm -f ${TMP_CONFIG}/smb.conf.cksum + /bin/umount $TMP_CONFIG + /bin/touch /tmp/donotrecover +} + +img_update() +{ + /bin/grep ram2 /proc/mounts 2>/dev/null 1>/dev/null + if [ $? = 0 ]; then + BLOCK_SIZE=2 + fi + [ -d ${FLASH_BOOT_MP} ] || /bin/mkdir ${FLASH_BOOT_MP} + [ -d ${FLASH_RFS1_MP} ] || /bin/mkdir ${FLASH_RFS1_MP} + [ -d ${FLASH_RFS2_MP} ] || /bin/mkdir ${FLASH_RFS2_MP} + echo "Update RFS1..." + echo 1 > ${UPDATE_PROCESS} + echo 1 > ${UPDATE_FW_PROCESS} + /bin/mount | /bin/grep "${FLASH_RFS1}" + [ $? != 0 ] || /bin/umount ${FLASH_RFS1} + /sbin/mke2fs -m0 -F -b 1024 -I 128 ${FLASH_RFS1} + /bin/sync + sleep 1 + /bin/mount ${FLASH_RFS1} ${FLASH_RFS1_MP} + if [ $? = 0 ]; then + [ -d ${FLASH_RFS1_MP}/boot ] || /bin/mkdir ${FLASH_RFS1_MP}/boot + [ -f ${UPDATE_FOLDER}/bzImage ] && /bin/cp ${UPDATE_FOLDER}/bzImage* ${FLASH_RFS1_MP}/boot + [ -f ${UPDATE_FOLDER}/initrd.boot ] && /bin/cp ${UPDATE_FOLDER}/initrd.boot* ${FLASH_RFS1_MP}/boot + [ -f ${UPDATE_FOLDER}/rootfs2.bz ] && /bin/cp ${UPDATE_FOLDER}/rootfs2.bz* ${FLASH_RFS1_MP}/boot + [ -f ${UPDATE_FOLDER}/rootfs_ext.tgz ] && /bin/cp ${UPDATE_FOLDER}/rootfs_ext.tgz* ${FLASH_RFS1_MP}/boot + if [ $FLASH_RFS1_SIZE = $FLASH_RFS1_SIZE_X59 -o $FLASH_RFS1_SIZE = $FLASH_RFS1_SIZE_X59H ] && [ -f ${UPDATE_FOLDER}/qpkg.tar ]; then + check_sum "$UPDATE_FOLDER/qpkg.tar" "$UPDATE_FOLDER/qpkg.tar.cksum" + [ $? = 0 ] && /bin/cp ${UPDATE_FOLDER}/qpkg.tar* ${FLASH_RFS1_MP}/boot + touch ${UPDATE_FOLDER}/update_qpkg_f + fi + else + /sbin/write_log "A read/write error occurred on the first boot partition of the flash disk during system update." 1 + FLASH_RFS_ERR=1 + fi + /bin/sync + [ ${FLASH_RFS_ERR} = 0 ] && DOM_CRC_check "${FLASH_RFS1_MP}" + /bin/umount ${FLASH_RFS1} 1>>/dev/null 2>>/dev/null + [ ${FLASH_RFS_ERR} = 0 ] || do_exit 4 + /bin/sleep 2 + echo "Update RFS2..." + echo 2 > ${UPDATE_PROCESS} + echo 2 > ${UPDATE_FW_PROCESS} + /bin/mount | /bin/grep "${FLASH_RFS2}" + [ $? != 0 ] || /bin/umount ${FLASH_RFS2} + [ ${FLASH_RFS_ERR} = 0 ] && /sbin/mke2fs -m0 -F -b 1024 -I 128 ${FLASH_RFS2} + /bin/sync + sleep 1 + /bin/mount ${FLASH_RFS2} ${FLASH_RFS2_MP} + if [ $? = 0 ] && [ ${FLASH_RFS_ERR} = 0 ]; then + [ -d ${FLASH_RFS2_MP}/boot ] || /bin/mkdir ${FLASH_RFS2_MP}/boot + [ -f ${UPDATE_FOLDER}/bzImage ] && /bin/cp ${UPDATE_FOLDER}/bzImage* ${FLASH_RFS2_MP}/boot + [ -f ${UPDATE_FOLDER}/initrd.boot ] && /bin/cp ${UPDATE_FOLDER}/initrd.boot* ${FLASH_RFS2_MP}/boot + [ -f ${UPDATE_FOLDER}/rootfs2.bz ] && /bin/cp ${UPDATE_FOLDER}/rootfs2.bz* ${FLASH_RFS2_MP}/boot + [ -f ${UPDATE_FOLDER}/rootfs_ext.tgz ] && /bin/cp ${UPDATE_FOLDER}/rootfs_ext.tgz* ${FLASH_RFS2_MP}/boot + if [ $FLASH_RFS1_SIZE = $FLASH_RFS1_SIZE_X59 -o $FLASH_RFS1_SIZE = $FLASH_RFS1_SIZE_X59H ] && [ -f ${UPDATE_FOLDER}/qpkg.tar ]; then + check_sum "$UPDATE_FOLDER/qpkg.tar" "$UPDATE_FOLDER/qpkg.tar.cksum" + [ $? = 0 ] && /bin/cp ${UPDATE_FOLDER}/qpkg.tar* ${FLASH_RFS2_MP}/boot + touch ${UPDATE_FOLDER}/update_qpkg_f + fi + else + /sbin/write_log "A read/write error occurred on the second boot partition of the flash disk during system update." 1 + [ ${FLASH_RFS_ERR} = 0 ] || FLASH_RFS_ERR=2 + fi + /bin/sync + /bin/umount ${FLASH_RFS2} + +# /usr/bin/readlink /usr 1>>/dev/null 2>>/dev/null +# if [ $? = 0 ]; then +# [ -f ${UPDATE_FOLDER}/qpatch.tgz ] && /bin/tar -xzf ${UPDATE_FOLDER}/qpatch.tgz -C / +# fi + /bin/sleep 3 + [ ${FLASH_RFS_ERR} = 0 ] || do_exit 4 + set_status_flag 1 + refresh_flash_config_file + echo "Update Finished." + echo 3 > ${UPDATE_FW_PROCESS} + /bin/touch /etc/config/update_fw_ok + + return 0 +} + +# $1: Kernel Image +# $2: Basic RootFS +# $3: Basic RootFS2 +# $4: ARM: Ignore, PPC: FDT blob +img_update_16M() +{ + /bin/grep ram2 /proc/mounts 2>/dev/null 1>/dev/null + if [ $? = 0 ]; then + BLOCK_SIZE=2 + fi + + /bin/echo 1 > ${UPDATE_PROCESS} + /bin/echo 1 > ${UPDATE_FW_PROCESS} + if [ -x /sbin/badblocks ]; then + /bin/echo "Check Flash ROM" + /sbin/badblocks ${FLASH_KERNEL} 1>/dev/null 2>/dev/null + [ $? = 0 ] || do_exit 4 + /sbin/badblocks ${FLASH_ROOTFS_BASIC} 1>/dev/null 2>/dev/null + [ $? = 0 ] || do_exit 4 + /sbin/badblocks ${FLASH_ROOTFS2} 1>/dev/null 2>/dev/null + [ $? = 0 ] || do_exit 4 + fi + /bin/echo "Update Kernel ..." + /bin/dd if=${UPDATE_FOLDER}/${1} of=${FLASH_KERNEL} bs=${BLOCK_SIZE} 2>/dev/null + if [ $? != 0 ]; then + #try again + /bin/dd if=${UPDATE_FOLDER}/${1} of=${FLASH_KERNEL} bs=${BLOCK_SIZE} + [ $? = 0 ] || do_exit 4 + fi + + /bin/echo "Update Basic RootFS ..." + /bin/echo 2 > ${UPDATE_PROCESS} + /bin/echo 2 > ${UPDATE_FW_PROCESS} + /bin/dd if=${UPDATE_FOLDER}/${2} of=${FLASH_ROOTFS_BASIC} bs=${BLOCK_SIZE} 2>/dev/null + if [ $? != 0 ]; then + /bin/dd if=${UPDATE_FOLDER}/${2} of=${FLASH_ROOTFS_BASIC} bs=${BLOCK_SIZE} + [ $? = 0 ] || do_exit 4 + fi + + /bin/echo "Update Basic RootFS2 ..." + /bin/dd if=${UPDATE_FOLDER}/${3} of=${FLASH_ROOTFS2} bs=${BLOCK_SIZE} 2>/dev/null + if [ $? != 0 ]; then + /bin/dd if=${UPDATE_FOLDER}/${3} of=${FLASH_ROOTFS2} bs=${BLOCK_SIZE} + [ $? = 0 ] || do_exit 4 + fi + + if [ x${4} != x ]; then + /bin/echo "Update Kernel Device Tree Blob ..." + /bin/cp ${UPDATE_FOLDER}/${4} ${FLASH_FDT} + fi + + set_status_flag 1 + refresh_flash_config_file + echo "Update Finished." + echo 3 > ${UPDATE_FW_PROCESS} + /bin/touch /etc/config/update_fw_ok + + return 0 +} + +config_add_endflag() +{ + ISCSI_CONFIG=/etc/config/iscsi_trgt.conf + + /bin/grep "\[END_FLAG\]" $DEFAULT_CFG_FILE 1>>/dev/null 2>>/dev/null + if [ $? != 0 ] ; then + [ `/sbin/getcfg Misc Configured -u -d FALSE` = TRUE ] && /bin/echo "[END_FLAG]" >> $DEFAULT_CFG_FILE + fi +#also check/backup configs + 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" -ge $MIN_FSIZE ]; then + [ -f ${ISCSI_CONFIG}.last ] || /bin/cp $ISCSI_CONFIG ${ISCSI_CONFIG}.last + fi + fi + /bin/sync + return 0 +} + +change_pm_cmd() +{ + /bin/touch /sbin/qpm.sh + /bin/chmod 755 /sbin/qpm.sh + /bin/ln -sf /sbin/qpm.sh /sbin/poweroff + /bin/ln -sf /sbin/qpm.sh /sbin/halt + /bin/ln -sf /sbin/qpm.sh /sbin/reboot + /bin/ln -sf /bin/busybox /root/reboot + /bin/ln -sf /bin/busybox /root/poweroff + /bin/ln -sf /bin/busybox /root/halt + /bin/echo -e "#!/bin/sh + /bin/sleep 5 + /bin/ps | /bin/grep \"/etc/init.d/update.sh\" | /bin/grep -v grep 1>>/dev/null 2>>/dev/null + [ \$? != 0 ] || exit 1 + /root/\`/usr/bin/basename \${0}\` + exit 0" > /sbin/qpm.sh + /bin/chmod 755 /sbin/qpm.sh +} + +recover_pm_cmd() +{ + /bin/ln -sf /sbin/busybox /sbin/poweroff + /bin/ln -sf /sbin/busybox /sbin/halt + /bin/ln -sf /sbin/busybox /sbin/reboot +} + +path_name=$1 +if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then + IMG_FILE_LIST=$IMG_FILE_LIST_ARM + FLASH_RFS1_SIZE=$FLASH_SIZE_ARM +elif [ "x${BOOT_CONF}" = "xTS-NASPPC" ]; then + IMG_FILE_LIST=$IMG_FILE_LIST_PPC + FLASH_RFS1_SIZE=$FLASH_SIZE_PPC +fi +now_process=`/bin/cat /tmp/update_process 2>>/dev/null` +if [ ! -z "$now_process" ] && [ $now_process = 3 ]; then + /bin/rm -f /tmp/update_process 2>/dev/null + [ ! -f /tmp/do_reboot ] || /bin/rm -f /tmp/do_reboot + /bin/echo "/tmp/update_process is removed. Please try again." + do_exit 7 +fi +[ -x /usr/bin/basename ] || /bin/ln -sf /bin/busybox /usr/bin/basename +/bin/ps | /bin/grep "/sbin/reboot" | /bin/grep -v grep 1>>/dev/null 2>>/dev/null +doing_reboot=$? +/bin/ps | /bin/grep "/sbin/poweroff" | /bin/grep -v grep 1>>/dev/null 2>>/dev/null +doing_poweroff=$? +/bin/ps | /bin/grep "/sbin/halt" | /bin/grep -v grep 1>>/dev/null 2>>/dev/null +doing_halt=$? +/bin/ps | /bin/grep "/etc/init.d/rcK" | /bin/grep -v grep 1>>/dev/null 2>>/dev/null +doing_rcK=$? +if [ $doing_reboot = 0 ] || [ $doing_poweroff = 0 ] || [ $doing_halt = 0 ] || [ $doing_rcK = 0 ]; then + /bin/rm -f /tmp/update_process 2>/dev/null + [ ! -f /tmp/do_reboot ] || /bin/rm -f /tmp/do_reboot + do_exit 7 +fi +change_pm_cmd + +#===== ready to update F/W ===== +USING_HDD=0 +/bin/grep HDA_ROOT /proc/mounts 2>/dev/null 1>/dev/null +if [ $? = 0 ]; then + USING_HDD=1 +else + /bin/grep HDA_ROOT /proc/mounts 2>/dev/null 1>/dev/null + if [ $? = 0 ]; then + USING_HDD=1 + fi +fi + +if [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then + /bin/mv /usr/local/sbin/blkid /usr/local/sbin/blkid_ 2>/dev/null + check_tune_config_partition /dev/mtdblock5 1024 +elif [ "x${BOOT_CONF}" = "xTS-NASPPC" ]; then + check_tune_config_partition /dev/mtdblock5 1024 +else + check_tune_config_partition ${BOOT_DEV}6 4096 +fi + +if [ "x${BOOT_CONF}" = "xTS-NASX86" ] && [ $FLASH_RFS1_BLOCK -ge $FLASH_RFS1_BLOCK_X59 ]; then + FLASH_RFS1_SIZE=$FLASH_RFS1_SIZE_X59 +elif [ "x${BOOT_CONF}" = "xTS-NASX86" ] && [ $FLASH_RFS1_BLOCK -ge $FLASH_RFS1_BLOCK_X59H ]; then + FLASH_RFS1_SIZE=$FLASH_RFS1_SIZE_X59H +fi + + +if [ -f $UPDATE_FOLDER/update_check ]; then + $UPDATE_FOLDER/update_check + if [ $? != 0 ]; then + [ ! -x /sbin/lock_system_update ] || /sbin/lock_system_update unlock + do_exit 3 + fi +fi + +/sbin/write_log "[Firmware Upgrade] Start to update the firmware." 4 + +if [ -f $UPDATE_FOLDER/update_bios.sh ]; then + $UPDATE_FOLDER/update_bios.sh $UPDATE_FOLDER/flashrom.img +fi + +if [ -f $UPDATE_FOLDER/sas_fw/sas_fw_update.sh ]; then + $UPDATE_FOLDER/sas_fw/sas_fw_update.sh +fi + +if [ "x${BOOT_CONF}" = "xTS-NASX86" ]; then + if [ $USING_HDD = 1 ]; then + echo "Update image using HDD ..." + CRC_check + size_check + img_update + remove_update 2 + else + echo "Update image using RAM disk ..." + CRC_check + size_check + img_update + remove_update 1 + fi +elif [ "x${BOOT_CONF}" = "xTS-NASARM" ]; then + if [ $USING_HDD = 1 ]; then + echo "Update image using HDD ..." + CRC_check + size_check_arm + img_update_16M uImage initrd.boot rootfs2.img + remove_update 2 + else + echo "Update image using RAM disk ..." + CRC_check + size_check_arm + img_update_16M uImage initrd.boot rootfs2.img + remove_update 1 + fi +elif [ "x${BOOT_CONF}" = "xTS-NASPPC" ]; then + if [ $USING_HDD = 1 ]; then + echo "Update image using HDD ..." + CRC_check + size_check + img_update_16M uImage initrd.uboot rootfs2.img canyonlands_qnap.dtb + remove_update 2 + else + echo "Update image using RAM disk ..." + CRC_check + size_check + img_update_16M uImage initrd.uboot rootfs2.img canyonlands_qnap.dtb + remove_update 1 + fi +fi +/bin/mv /usr/local/sbin/blkid_ /usr/local/sbin/blkid 2>/dev/null +config_add_endflag +/sbin/setcfg -e System "QPKG CENTER XML" +if [ x`/bin/cat ${UPDATE_FW_PROCESS} 2>/dev/null` = x3 ]; then + /bin/grep do_beep_check_flag /etc/init.d/update.sh 1>/dev/null 2>/dev/null + [ $? = 0 ] && do_beep + [ ! -x /sbin/lock_system_update ] || /sbin/lock_system_update unlock + /bin/echo 3 > ${UPDATE_PROCESS} + exit 0 +else + exit 1 +fi + diff --git a/upnpd.sh b/upnpd.sh new file mode 100755 index 0000000..6420d78 --- /dev/null +++ b/upnpd.sh @@ -0,0 +1,95 @@ +#!/bin/sh +PATH=/bin:/sbin:/usr/bin:/usr/sbin + +UPNPD="/sbin/upnpd" +BOND_SUP=`/sbin/getcfg "Network" "BONDING Support" -d "FALSE"` +ADV_BOND_SUP=`/sbin/getcfg "Network" "Advanced Bonding Support" -d "FALSE"` +ETH0STATUS=`/bin/cat /sys/class/net/eth0/operstate 2>>/dev/null` +ETH1STATUS=`/bin/cat /sys/class/net/eth1/operstate 2>>/dev/null` +EXTIFACE="eth0" +INTIFACE="eth0" +ALLOW_MULTICAST="FALSE" +RETVAL=0 +IS_GATEWAY_EXIT=0 + +if [ "$BOND_SUP" = "TRUE" ]; then + EXTIFACE="bond0" + INTIFACE="bond0" +else + if [ "$ETH0STATUS" = "up" ]; then + EXTIFACE="eth0" + INTIFACE="eth0" + else + if [ "$ETH1STATUS" = "up" ]; then + EXTIFACE="eth1" + INTIFACE="eth1" + fi + fi +fi + +if [ "x$ADV_BOND_SUP" = "xTRUE" ]; then + EXTIFACE=`/sbin/getcfg "Network" "Default GW Device" -d "eth0"` + INTIFACE=$EXTIFACE +fi + +ckeck_gateway_is_exit() +{ + /bin/ip route | /bin/grep "^default" > /tmp/nasroute.org + + while read LINE + do + interface=`/bin/echo $LINE | /bin/cut -d ' ' -f 5` + gateway=`/bin/echo $LINE | /bin/cut -d ' ' -f 3` + if [ x"${interface}" = x"${INTIFACE}" ] ; then + /bin/echo " get $interface gateway = $gateway" + /bin/ping -q -c 3 $gateway 1>>/dev/null 2>>/dev/null + [ $? = 0 ] && IS_GATEWAY_EXIT=1 + break; + fi + done < /tmp/nasroute.org + /bin/rm -f /tmp/nasroute.org 2>>/dev/null +} + +case "$1" in + start) + [ `/sbin/getcfg "UPnP Service" "Enable" -d TRUE` = "FALSE" ] && exit 1 + [ -f "$UPNPD" ] || exit 1 + if [ -f /var/lock/subsys/upnpd ]; then + /bin/echo "upnpd service seems already be running" + exit 1 + fi + echo -n "Starting upnpd:" + ckeck_gateway_is_exit + if [ $IS_GATEWAY_EXIT = 0 ];then + /bin/echo "Gateway failed. UPnP Discovery Service stopped." + #/sbin/write_log "[Network Service Discovery] Gateway failed. UPnP Discovery Service stopped." 2 + exit 1 + fi + [ "$ALLOW_MULTICAST" = "TRUE" ] && route add -net 239.0.0.0 netmask 255.0.0.0 $INTIFACE + /sbin/gen_upnp_desc + [ $? != 0 ] && exit 1 + /sbin/daemon_mgr upnpd start "$UPNPD $EXTIFACE $INTIFACE" + RETVAL=$? + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/upnpd + echo "." + ;; + stop) + echo -n "Shutting down upnpd services:" + /sbin/daemon_mgr upnpd stop "$UPNPD $EXTIFACE $INTIFACE" + /bin/sleep 5 + /sbin/pidof upnpd + [ $? = 0 ] && /bin/kill `/sbin/pidof upnpd` + /bin/rm -f /var/lock/subsys/upnpd + echo "." + ;; + restart) + $0 stop + /bin/sleep 5 + $0 start + ;; + *) + echo "Usage: /etc/init.d/upnpd.sh {start|stop|restart}" + exit 1 +esac + +exit $RETVAL diff --git a/ups.sh b/ups.sh new file mode 100755 index 0000000..270d3e9 --- /dev/null +++ b/ups.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +case "$1" in + start) + # Start daemons. + UPS_DRV=`/sbin/getcfg qnapups driver -d "" -f /etc/config/ups/ups.conf` + /etc/init.d/usb_ups.sh start "$UPS_DRV" + /etc/init.d/snmp_ups.sh start + ;; + stop) + # Stop daemons. + /etc/init.d/usb_ups.sh stop + /etc/init.d/snmp_ups.sh stop + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 +esac + + diff --git a/urandom b/urandom new file mode 100755 index 0000000..433fafe --- /dev/null +++ b/urandom @@ -0,0 +1,44 @@ +#! /bin/sh +# +# urandom This script saves the random seed between reboots. +# It is called from the boot, halt and reboot scripts. +# +# Version: @(#)urandom 1.33 22-Jun-1998 miquels@cistron.nl +# + +[ -c /dev/urandom ] || exit 0 +#. /etc/default/rcS + +case "$1" in + start|"") + if [ "$VERBOSE" != no ] + then + echo -n "Initializing random number generator... " + fi + # Load and then save 512 bytes, + # which is the size of the entropy pool + if [ -f /etc/random-seed ] + then + cat /etc/random-seed >/dev/urandom + fi + rm -f /etc/random-seed + umask 077 + dd if=/dev/urandom of=/etc/random-seed count=1 \ + >/dev/null 2>&1 || echo "urandom start: failed." + umask 022 + [ "$VERBOSE" != no ] && echo "done." + ;; + stop) + # Carry a random seed from shut-down to start-up; + # see documentation in linux/drivers/char/random.c + [ "$VERBOSE" != no ] && echo -n "Saving random seed... " + umask 077 + dd if=/dev/urandom of=/etc/random-seed count=1 \ + >/dev/null 2>&1 || echo "urandom stop: failed." + [ "$VERBOSE" != no ] && echo "done." + ;; + *) + echo "Usage: urandom {start|stop}" >&2 + exit 1 + ;; +esac diff --git a/usb_device_check.sh b/usb_device_check.sh new file mode 100755 index 0000000..0294749 --- /dev/null +++ b/usb_device_check.sh @@ -0,0 +1,94 @@ +#!/bin/sh +# +# Copyright @ 2010 QNAP Systems Inc. +# +# This script use to check the inserted usb devices +# +# Version 1.0.0 +# +RT2870_Vid=(050d 07d1 148f 14b2 7392) +RT2870_Pid=(815c 3c09 2770 3c25 7717) +RT3070_Vid=(083a 0b05 1737 7392 0411 0586 0586 07d1 07b8 07d1) +RT3070_Pid=(a701 1784 0077 7711 015d 341a 341e 3c16 3071 3c0a) +RT5370_Vid=(2001 2001) +RT5370_Pid=(3c19 3c15) +RT3572_Vid=(13b1 1737) +RT3572_Pid=(002f 0079) +RTL8712_Vid=(050d 050d 0b05 0586 07d1 0bda) +RTL8712_Pid=(845a 945a 1786 341f 3303 8172) +RTL8192CU_Vid=(0bda) +RTL8192CU_Pid=(8176) + +WIRELESS_CHECK_TEMP="/tmp/wireless_check_tmp" +/usr/sbin/lsusb | /bin/awk '{print $6}' > $WIRELESS_CHECK_TEMP + + while read LINE + do + #echo $LINE + usb_idVendor=`echo $LINE | cut -f 1 -d ':'` + usb_idProduct=`echo $LINE | cut -f 2 -d ':'` + for (( i=0; i<${#RT2870_Vid[@]}; i=i+1 )) + do + if [ "${RT2870_Vid[$i]}" = "$usb_idVendor" ] && [ "${RT2870_Pid[$i]}" = "$usb_idProduct" ]; then + #echo ${RT2870_Vid[$i]} ${RT2870_Pid[$i]} "MATCH!!!" >> /tmp/usbdebug + DEVNAME="WIFI_RT2870" + /etc/init.d/wireless_modules.sh start $DEVNAME + break; + fi + done + + for (( i=0; i<${#RT3070_Vid[@]}; i=i+1 )) + do + if [ "${RT3070_Vid[$i]}" = "$usb_idVendor" ] && [ "${RT3070_Pid[$i]}" = "$usb_idProduct" ]; then + #echo ${RT3070_Vid[$i]} ${RT3070_Pid[$i]} "MATCH!!!" >> /tmp/usbdebug + DEVNAME="WIFI_RT3070" + /etc/init.d/wireless_modules.sh start $DEVNAME + break; + fi + done + + for (( i=0; i<${#RT5370_Vid[@]}; i=i+1 )) + do + if [ "${RT5370_Vid[$i]}" = "$usb_idVendor" ] && [ "${RT5370_Pid[$i]}" = "$usb_idProduct" ]; then + #echo ${RT5370_Vid[$i]} ${RT5370_Pid[$i]} "MATCH!!!" >> /tmp/usbdebug + DEVNAME="WIFI_RT5370" + /etc/init.d/wireless_modules.sh start $DEVNAME + break; + fi + done + + for (( i=0; i<${#RT3572_Vid[@]}; i=i+1 )) + do + if [ "${RT3572_Vid[$i]}" = "$usb_idVendor" ] && [ "${RT3572_Pid[$i]}" = "$usb_idProduct" ]; then + #echo ${RT3572_Vid[$i]} ${RT3572_Pid[$i]} "MATCH!!!" >> /tmp/usbdebug + DEVNAME="WIFI_RT3572" + /etc/init.d/wireless_modules.sh start $DEVNAME + break; + fi + done + + for (( i=0; i<${#RTL8192CU_Vid[@]}; i=i+1 )) + do + if [ "${RTL8192CU_Vid[$i]}" = "$usb_idVendor" ] && [ "${RTL8192CU_Pid[$i]}" = "$usb_idProduct" ]; then + #echo ${RTL8192CU_Vid[$i]} ${RTL8192CU_Pid[$i]} "MATCH!!!" >> /tmp/usbdebug + DEVNAME="WIFI_RTL8192CU" + /etc/init.d/wireless_modules.sh start $DEVNAME + break; + fi + done + + /bin/uname -a | /bin/grep x86_64 + if [ $? != 0 ]; then + for (( i=0; i<${#RTL8712_Vid[@]}; i=i+1 )) + do + if [ "${RTL8712_Vid[$i]}" = "$usb_idVendor" ] && [ "${RTL8712_Pid[$i]}" = "$usb_idProduct" ]; then + #echo ${RTL8712_Vid[$i]} ${RTL8712_Pid[$i]} "MATCH!!!" >> /tmp/usbdebug + DEVNAME="WIFI_RTL8712" + /etc/init.d/wireless_modules.sh start $DEVNAME + break; + fi + done + fi + + done < $WIRELESS_CHECK_TEMP + diff --git a/usb_ups.sh b/usb_ups.sh new file mode 100755 index 0000000..343d14f --- /dev/null +++ b/usb_ups.sh @@ -0,0 +1,207 @@ +#!/bin/sh +# +# ups.sh This shell script takes care of that starting or stoping ups daemon +# +clear_debug_file() +{ + local filesize=`/usr/bin/du -k /tmp/usbdebug|/bin/awk '{printf $1}'` + if [ $filesize -gt 10 ]; then + /bin/mv /tmp/usbdebug /tmp/usbdebug.1 + fi +} +DAEMON_TYPE=`/sbin/getcfg "UPS" "Daemon Type"` +UPS_CONF_DIR=/etc/config/ups +UPS_CONF_DEFAULT=/etc/default_config/ups +UPPID=`/bin/grep PPid: /proc/$$/status|/bin/awk -F ' ' '{printf $2}'` + +check_upsd_conf() +{ + [ -f $UPS_CONF_DIR/upsd.conf ] || return 0 + /bin/grep "^LISTEN" $UPS_CONF_DIR/upsd.conf > /dev/null 2>&1 + [ $? = 0 ] || echo "LISTEN 0.0.0.0" >> $UPS_CONF_DIR/upsd.conf +} + +try_ups_drivers() +{ + [ -d /usr/local/ups/bin ] || return 1 + if [ "x$1" = "x" ] && [ "x$2" = "x" ]; then + return 1 + fi + if [ "x$1" = "x0x" ] || [ "x$2" = "x0x" ]; then + return 1 + fi + local cwd=$PWD + local drv + echo "$UPPID::Try [$1:$2]" >> /tmp/usbdebug + cd /usr/local/ups/bin + for drv in *; do + /sbin/setcfg qnapups driver $drv -f /etc/config/ups/ups.conf + vendorid=`printf "%.4x" $1` + productid=`printf "%.4x" $2` + echo "$UPPID::/usr/local/ups/bin/$drv -a qnapups -u admin -x vendorid=$vendorid -x productid=$productid" >> /tmp/usbdebug + /usr/local/ups/bin/$drv -a qnapups -u admin -x vendorid=$vendorid -x productid=$productid + if [ $? = 0 ]; then + UPS_DRV=$drv + printf "%s,%s,%s\n" $1 $2 $drv >> /etc/config/ups/upsdrv.map + return 0 + fi + done + UPS_DRV= + printf "%s,%s,NOT_UPS\n" $1 $2 >> /etc/config/ups/upsdrv.map + return 1 +} +clear_debug_file +case "$1" in + start) + UPS_ENABLE=`/sbin/getcfg UPS Enable -u -d FALSE` + + if [ "$2" != "" ]; then + USB_UPS_LCK=/var/lock/usb_ups_$2.lck + elif [ "$3" != "" ]; then + if [ "$4" != "" ]; then + USB_UPS_LCK=/var/lock/usb_ups_$3_$4.lck + else + USB_UPS_LCK=/var/lock/usb_ups_$3.lck + fi + else + USB_UPS_LCK=/var/lock/usb_ups.lck + fi + echo "$UPPID::USB_UPS_LCK of [$@] is $USB_UPS_LCK" >> /tmp/usbdebug + + if [ ! -d ${UPS_CONF_DIR} ]; then + [ ! -f ${UPS_CONF_DIR} ] || /bin/rm ${UPS_CONF_DIR} + /bin/mkdir ${UPS_CONF_DIR} + [ -d ${UPS_CONF_DEFAULT} ] && /bin/cp ${UPS_CONF_DEFAULT}/* ${UPS_CONF_DIR} + fi + + # Start daemons. + echo -n "Starting UPS monitoring:" + if [ -f ${USB_UPS_LCK} ]; then + echo $0 is running + exit 0 + fi + /bin/touch ${USB_UPS_LCK} + echo "$UPPID::ups start....." >> /tmp/usbdebug + #wait for kernel driver + sleep 3 + if [ -f /var/run/upsisrunning ]; then + + echo $UPPID::ups driver is running. + + if [ "$UPS_ENABLE" = "FALSE" ] + then + echo disabled + /bin/rm ${USB_UPS_LCK} + exit 0 + fi + + if [ $DAEMON_TYPE = "3" ] + then + /bin/kill -USR1 `/sbin/pidof upsutil` + fi + + /bin/rm ${USB_UPS_LCK} + exit 0 + fi + LOAD_DRV_RET="1" + UPS_DRV=$2 + if [ "$UPS_DRV" != "" ]; then + if [ ! -x /usr/local/ups/bin/$UPS_DRV ]; then + /bin/rm ${USB_UPS_LCK} + exit 0 + fi + /sbin/setcfg qnapups driver $UPS_DRV -f /etc/config/ups/ups.conf + echo "$UPPID::FIX::/usr/local/ups/bin/$UPS_DRV -a qnapups -u admin" >> /tmp/usbdebug + /usr/local/ups/bin/$UPS_DRV -a qnapups -u admin + LOAD_DRV_RET=$? + fi +# while [ 1 ]; do +# /usr/bin/upsdrvctl -u admin start +# echo "upsdrvctl start....." >> /tmp/usbdebug +# if [ $? = 0 ]; then +# echo "success...." >> /tmp/usbdebug +# break; +# fi +# /bin/sleep 1 +# done + + echo "$UPPID::LOAD_DRV_RET $LOAD_DRV_RET" >> /tmp/usbdebug + if [ "$LOAD_DRV_RET" != "0" ]; then + UPS_DRV="" + if [ "$3" != "" ] && [ "$4" != "" ]; then + try_ups_drivers "$3" "$4" + fi + fi + #check ups driver is dead or not + /bin/sleep 3 + ups_drv_pid= + ups_drv_pid=`/bin/pidof $UPS_DRV` + echo "$UPPID::ups_drv_pid is $ups_drv_pid" >> /tmp/usbdebug + if [ "$ups_drv_pid" = "" ]; then + try_ups_drivers +# /usr/bin/upsdrvctl -u admin start + ups_drv_pid=`/bin/pidof $UPS_DRV` + echo "$UPPID::upsdrvctl start after dead.....$ups_drv_pid" >> /tmp/usbdebug + else + /sbin/setcfg UPS "Server Mode" TRUE + /sbin/setcfg UPS "Daemon Type" 3 + /bin/kill -USR1 `/sbin/pidof upsutil` + fi + echo $ups_drv_pid > /var/run/upsdrv.pid + + if [ "x$ups_drv_pid" = "x" ]; then + if [ "$UPS_ENABLE" != "FALSE" ]; then + [ $DAEMON_TYPE = "3" ] && /bin/kill -USR1 `/sbin/pidof upsutil` + fi + /bin/rm ${USB_UPS_LCK} + exit 0 + fi + check_upsd_conf + /sbin/daemon_mgr upsd start "/usr/sbin/upsd -u admin" 2>/dev/null + /bin/touch /var/run/upsisrunning + + if [ "$UPS_ENABLE" = "FALSE" ] + then + echo disabled + /bin/rm ${USB_UPS_LCK} + exit 0 + fi + + if [ $DAEMON_TYPE = "3" ] + then + /bin/kill -USR1 `/sbin/pidof upsutil` + fi + + /bin/rm ${USB_UPS_LCK} + ;; + stop) + # Stop daemons. + echo -n "Shutting down UPS monitoring:" + + #/sbin/daemon_mgr upsmon stop "/usr/sbin/upsmon" 2>/dev/null 1>/dev/null + + /usr/bin/upsdrvctl stop + + /sbin/daemon_mgr upsd stop "/usr/sbin/upsd" 2> /dev/null 1>/dev/null + + /bin/kill `pidof poweroff` 2> /dev/null + + /bin/kill -USR2 `/sbin/pidof upsutil` + ups_drv_pid=`/bin/cat /var/run/upsdrv.pid` 2>/dev/null + /bin/rm /var/run/upsdrv.pid + /bin/kill -9 $ups_drv_pid + + /sbin/setcfg UPS "Server Mode" FALSE + + /bin/rm -f /var/run/upsisrunning + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 +esac + + diff --git a/vpn_openvpn.sh b/vpn_openvpn.sh new file mode 100755 index 0000000..99a183f --- /dev/null +++ b/vpn_openvpn.sh @@ -0,0 +1,331 @@ +#!/bin/sh + +OPENVPN=/usr/sbin/openvpn +PIDFILE="/var/run/openvpn.server.pid" +OPENVPN_CONF="/etc/openvpn/server.conf" +OPENVPN_CONF_PATH="/etc/openvpn" +OPENVPN_CA_FILE="/etc/openvpn/easy-rsa/keys/ca.crt" +VPN_CONF="/etc/config/vpn.conf" +VPN_OPENVPN_CONF_PATH="/etc/config/openvpn" +VPN_ONLINE_LOG="/var/log/openvpn_online_user.log" +NIC_NUM=`/sbin/getcfg "Network" "Interface Number" -d "2"` + +use_source_route_for_openvpn() +{ + TUN_DEV="tun0" + TUN_IP_ADDR="$(/sbin/ifconfig ${TUN_DEV} 2> /dev/null | /bin/sed -n '/inet /{s/.*addr://;s/ .*//;p}')" + TUN_SUBNET=`/bin/grep "^server" ${OPENVPN_CONF} | /bin/cut -d' ' -f 2` + + for LAN_PREFIX in eth bond + do + for (( i=0; i<$NIC_NUM; i=i+1 )) + do + case "$LAN_PREFIX" in + eth) + let ROUTE_TBL=$i+1 + ;; + bond) + let ROUTE_TBL=$i+11 + ;; + esac + LAN=$LAN_PREFIX$i + IP_ADDR="$(/sbin/ifconfig $LAN 2> /dev/null | /bin/sed -n '/inet /{s/.*addr://;s/ .*//;p}')" + if [ x$IP_ADDR != "x" ]; then + /bin/ip route add $TUN_SUBNET/24 via $TUN_IP_ADDR dev ${TUN_DEV} tab $ROUTE_TBL &> /dev/null + fi + done + done + /bin/ip route flush cache +} + +init_modules() +{ + /bin/echo "init insmod for openvpn" + /bin/echo "1" > /proc/sys/net/ipv4/ip_forward + /sbin/insmod /lib/modules/others/tun.ko 1>>/dev/null 2>&1 + if [ ! -L /usr/sbin/vpn_check_account ]; then + /bin/ln -sf /sbin/nasutil /usr/sbin/vpn_check_account + fi + if [ ! -L /usr/sbin/vpn_openvpn_download ]; then + /bin/ln -sf /sbin/nasutil /usr/sbin/vpn_openvpn_download + fi +} + +init_iptable_modules() +{ + [ -L /usr/lib/libxtables.so.7 ] || /bin/ln -sf /usr/lib/libxtables.so.7.0.0 /usr/lib/libxtables.so.7 + [ -L /usr/lib/libxtables.so ] || /bin/ln -sf /usr/lib/libxtables.so.7.0.0 /usr/lib/libxtables.so + [ -L /usr/lib/libip4tc.so.0 ] || /bin/ln -sf /usr/lib/libip4tc.so.0.0.0 /usr/lib/libip4tc.so.0 + [ -L /usr/lib/libip4tc.so ] || /bin/ln -sf /usr/lib/libip4tc.so.0.0.0 /usr/lib/libip4tc.so + [ -L /usr/lib/libip6tc.so.0 ] || /bin/ln -sf /usr/lib/libip6tc.so.0.0.0 /usr/lib/libip6tc.so.0 + [ -L /usr/lib/libip6tc.so ] || /bin/ln -sf /usr/lib/libip6tc.so.0.0.0 /usr/lib/libip6tc.so + /sbin/lsmod | /bin/grep x_tables 1>>/dev/null 2>>/dev/null + if [ $? != 0 ]; then + /bin/echo "insmod iptable modules" + for i in x_tables.ko nf_conntrack.ko xt_tcpudp.ko nf_defrag_ipv4.ko nf_conntrack_ipv4.ko nf_nat.ko \ + ip_tables.ko iptable_nat.ko iptable_filter.ko ipt_MASQUERADE.ko ipt_REDIRECT.ko + do + [ ! -f /lib/modules/others/vpn/$i ] || /sbin/insmod /lib/modules/others/vpn/$i + done + fi +} + + +remove_iptable_modules() +{ + for i in ipt_REDIRECT ipt_MASQUERADE iptable_filter iptable_nat ip_tables nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 \ + xt_tcpudp nf_conntrack x_tables + do + /sbin/rmmod $i + done +} + +init_vars() +{ + /bin/rm -rf ${OPENVPN_CONF_PATH}/easy-rsa/vars + /bin/touch ${OPENVPN_CONF_PATH}/easy-rsa/vars +cat >${OPENVPN_CONF_PATH}/easy-rsa/vars <<__EOF__ +export EASY_RSA="\`/bin/pwd\`" +export OPENSSL="openssl" +export PKCS11TOOL="pkcs11-tool" +export GREP="/bin/grep" +export KEY_CONFIG=\`\$EASY_RSA/whichopensslcnf \$EASY_RSA\` +export KEY_DIR="\$EASY_RSA/keys" +export PKCS11_MODULE_PATH="dummy" +export PKCS11_PIN="dummy" +export KEY_SIZE=1024 +export CA_EXPIRE=3650 +export KEY_EXPIRE=3650 +export KEY_COUNTRY="TW" +export KEY_PROVINCE="Taiwan" +export KEY_CITY="Taipei" +export KEY_ORG="QNAP Systems Inc." +export KEY_EMAIL="admin@qnap.com" +export KEY_CN="TS Series NAS" +export KEY_NAME="NAS" +export KEY_OU="NAS" +export PKCS11_MODULE_PATH=changeme +export PKCS11_PIN=1234 +__EOF__ + +/bin/chmod 755 ${OPENVPN_CONF_PATH}/easy-rsa/vars + +} + + +init() +{ + /bin/echo "openvpn init." + if [ ! -L /etc/rcK.d/K48vpn_openvpn ]; then + /bin/ln -sf ../init.d/vpn_openvpn.sh /etc/rcK.d/K48vpn_openvpn + fi + /sbin/vpn_util init_openvpn + sleep 1 + /sbin/vpn_util init_client + sleep 1 + /sbin/vpn_util init_readme + sleep 1 + + /bin/rm ${OPENVPN_CONF_PATH}/connect.sh + /bin/ln -sf /sbin/nasutil ${OPENVPN_CONF_PATH}/connect.sh + /bin/rm ${OPENVPN_CONF_PATH}/disconnect.sh + /bin/ln -sf /sbin/nasutil ${OPENVPN_CONF_PATH}/disconnect.sh + /bin/rm ${OPENVPN_CONF_PATH}/kick.sh + /bin/ln -sf /sbin/nasutil ${OPENVPN_CONF_PATH}/kick.sh + + /bin/rm -rf /etc/openvpn/keys + + if [ -d ${VPN_OPENVPN_CONF_PATH} ]; then + ADMIN_NAME=`/bin/grep "Subject: C=TW" ${VPN_OPENVPN_CONF_PATH}/keys/myserver.crt | /bin/cut -d= -f 9` + if [ "${ADMIN_NAME}" == "peterlai@qnap.com" ]; then + /bin/rm -rf ${VPN_OPENVPN_CONF_PATH} + sleep 1 + fi + fi + + if [ ! -d ${VPN_OPENVPN_CONF_PATH} ]; then + /bin/mkdir -p /etc/config/openvpn/keys + init_vars + sleep 1 + cd /etc/openvpn/easy-rsa + source /etc/openvpn/easy-rsa/vars 1>>/dev/null 2>&1 + /etc/openvpn/easy-rsa/clean-all 1>>/dev/null 2>&1 + sleep 1 + /etc/openvpn/easy-rsa/build-dh 1>>/dev/null 2>&1 + sleep 80 + /etc/openvpn/easy-rsa/pkitool --initca 1>>/dev/null 2>&1 + sleep 1 + /etc/openvpn/easy-rsa/pkitool --server myserver 1>>/dev/null 2>&1 + sleep 1 + + if [ ! -f ${OPENVPN_CA_FILE} ]; then + sleep 80 + if [ -f ${OPENVPN_CA_FILE} ]; then + /bin/cp -rf /etc/openvpn/easy-rsa/keys /etc/config/openvpn + /bin/ln -sf /etc/config/openvpn/keys /etc/openvpn/keys + else + sleep 100 + if [ -f ${OPENVPN_CA_FILE} ]; then + /bin/cp -rf /etc/openvpn/easy-rsa/keys /etc/config/openvpn + /bin/ln -sf /etc/config/openvpn/keys /etc/openvpn/keys + else + /bin/echo "openvpn init ${OPENVPN_CA_FILE} ERROR !." >/var/log/err_openvpn_ca.txt + fi + fi + else + /bin/cp -rf /etc/openvpn/easy-rsa/keys /etc/config/openvpn + /bin/ln -sf /etc/config/openvpn/keys /etc/openvpn/keys + fi + else + if [ -f /etc/config/openvpn/keys/ca.crt ]; then + /bin/ln -sf /etc/config/openvpn/keys /etc/openvpn/keys + else + init_vars + sleep 1 + cd /etc/openvpn/easy-rsa + source /etc/openvpn/easy-rsa/vars 1>>/dev/null 2>&1 + /etc/openvpn/easy-rsa/clean-all 1>>/dev/null 2>&1 + sleep 1 + /etc/openvpn/easy-rsa/build-dh 1>>/dev/null 2>&1 + sleep 60 + /etc/openvpn/easy-rsa/pkitool --initca 1>>/dev/null 2>&1 + sleep 1 + /etc/openvpn/easy-rsa/pkitool --server myserver 1>>/dev/null 2>&1 + sleep 1 + + if [ ! -f ${OPENVPN_CA_FILE} ]; then + sleep 80 + if [ -f ${OPENVPN_CA_FILE} ]; then + /bin/cp -rf /etc/openvpn/easy-rsa/keys /etc/config/openvpn + /bin/ln -sf /etc/config/openvpn/keys /etc/openvpn/keys + else + sleep 100 + if [ -f ${OPENVPN_CA_FILE} ]; then + /bin/cp -rf /etc/openvpn/easy-rsa/keys /etc/config/openvpn + /bin/ln -sf /etc/config/openvpn/keys /etc/openvpn/keys + else + /bin/echo "openvpn init ${OPENVPN_CA_FILE} ERROR !." >/var/log/err_openvpn_ca.txt + fi + fi + else + /bin/cp -rf /etc/openvpn/easy-rsa/keys /etc/config/openvpn + /bin/ln -sf /etc/config/openvpn/keys /etc/openvpn/keys + fi + fi + fi + + /bin/echo "openvpn init OK !." +} + +start() +{ + if [ ! -f ${OPENVPN} ]; then + /bin/echo "openvpn is not exit." + exit 1 + fi + + if [ -f ${PIDFILE} ]; then + /bin/echo "openvpn is aleady run." + exit 1 + fi + + sleep 1 + + init + + if [ `/sbin/getcfg "OPENVPN" "Enable" -u -d "FALSE" -f "${VPN_CONF}"` = "TRUE" ]; then + /bin/echo "openvpn start." + + init_modules + sleep 1 + init_iptable_modules + + /usr/bin/killall openvpn 1>>/dev/null 2>&1 + + if [ -f ${VPN_ONLINE_LOG} ]; then + /bin/rm ${VPN_ONLINE_LOG} + fi + sleep 1 + + /sbin/daemon_mgr openvpn start "${OPENVPN} --writepid ${PIDFILE} --daemon ovpn-server --cd ${OPENVPN_CONF_PATH} --config ${OPENVPN_CONF} --script-security 3" + + LOCALIP=`/bin/grep "^server" ${OPENVPN_CONF} | /bin/cut -d' ' -f 2` + INTERFACE=`/sbin/getcfg "OPENVPN" "interface" -d "eth0" -f "${VPN_CONF}"` + /bin/echo "LOCALIP = ${LOCALIP} INTERFACE = ${INTERFACE}" + /sbin/iptables -t nat -A POSTROUTING -s ${LOCALIP}/24 -o ${INTERFACE} -j MASQUERADE + use_source_route_for_openvpn + else + /bin/echo "openvpn is disabled." + fi + +} + +stop() +{ + /bin/echo "openvpn stop." + LOCALIP=`/bin/grep "^server" ${OPENVPN_CONF} | /bin/cut -d' ' -f 2` + INTERFACE=`/sbin/getcfg "OPENVPN" "interface" -d "eth0" -f "${VPN_CONF}"` + /bin/echo "LOCALIP = ${LOCALIP} INTERFACE = ${INTERFACE}" + /sbin/iptables -t nat -D POSTROUTING -s ${LOCALIP}/24 -o ${INTERFACE} -j MASQUERADE + + + if [ -f ${PIDFILE} ]; then + /sbin/daemon_mgr openvpn stop "{OPENVPN}" + /bin/kill -9 `/bin/cat ${PIDFILE}` 1>>/dev/null 2>&1 + fi + + if [ -f ${PIDFILE} ]; then + /bin/rm -f ${PIDFILE} 1>>/dev/null 2>&1 + fi + + if [ -f ${VPN_ONLINE_LOG} ]; then + /bin/rm -f ${VPN_ONLINE_LOG} 1>>/dev/null 2>&1 + /bin/touch ${VPN_ONLINE_LOG} + fi + + sleep 2 + /sbin/rmmod tun 1>>/dev/null 2>&1 +} + +reload() +{ + /bin/echo "openvpn reload." + LOCALIP=`/bin/grep "^server" ${OPENVPN_CONF} | /bin/cut -d' ' -f 2` + INTERFACE=`/sbin/getcfg "OPENVPN" "interface" -d "eth0" -f "${VPN_CONF}"` + /bin/echo "LOCALIP = ${LOCALIP} INTERFACE = ${INTERFACE}" + /sbin/iptables -t nat -D POSTROUTING -s ${LOCALIP}/24 -o ${INTERFACE} -j MASQUERADE + if [ -f ${PIDFILE} ]; then + /bin/kill -s HUP `/bin/cat ${PIDFILE}` 1>>/dev/null 2>&1 + fi + + LOCALIP=`/bin/grep "^server" ${OPENVPN_CONF} | /bin/cut -d' ' -f 2` + INTERFACE=`/sbin/getcfg "OPENVPN" "interface" -d "eth0" -f "${VPN_CONF}"` + /bin/echo "LOCALIP = ${LOCALIP} INTERFACE = ${INTERFACE}" + /sbin/iptables -t nat -A POSTROUTING -s ${LOCALIP}/24 -o ${INTERFACE} -j MASQUERADE + use_source_route_for_openvpn +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + /bin/sleep 2 + start + ;; + init) + init + ;; + reload) + reload + ;; + *) + echo "Usage: /etc/init.d/$0 {start|stop|restart|reload}" + exit 1 +esac + +exit 0 diff --git a/vpn_pptp.sh b/vpn_pptp.sh new file mode 100755 index 0000000..84d6022 --- /dev/null +++ b/vpn_pptp.sh @@ -0,0 +1,180 @@ +#!/bin/sh + +PPTPD=/usr/sbin/pptpd +PIDFILE="/var/run/pptpd.pid" +PPTPD_CONF="/etc/ppp/pptpd.conf" +OPTIONS_PPTPD="/etc/ppp/options.pptpd" +VPN_CONF="/etc/config/vpn.conf" + +DBG="nodebug" +if [ "x$2" == "xdebug" ]; then + DBG="debug" +fi + +init_pptp_modules() +{ + /bin/echo "init insmod and mknod" + [ -c /dev/ppp ] || /bin/mknod --mode=644 /dev/ppp c 108 0 + [ -d /etc/config/ppp ] || mkdir -p /etc/config/ppp + [ -L /etc/ppp ] || /bin/ln -sf /etc/config/ppp /etc/ppp + /bin/echo "1" > /proc/sys/net/ipv4/ip_forward + [ -L /etc/ppp/ip-up ] || /bin/ln -sf /sbin/nasutil /etc/ppp/ip-up + [ -L /etc/ppp/ip-down ] || /bin/ln -sf /sbin/nasutil /etc/ppp/ip-down + [ -L /usr/lib/libsmbpw.so ] || /bin/ln -sf /usr/lib/libsmbpw.1.3.so /usr/lib/libsmbpw.so + + /sbin/lsmod | grep ppp_generic 1>>/dev/null 2>>/dev/null + if [ $? != 0 ]; then + /bin/echo "insmod pptp and pppd modules" + for i in sha1_generic.ko arc4.ko ecb.ko slhc.ko crc-ccitt.ko ppp_generic.ko ppp_async.ko ppp_mppe.ko \ + bsd_comp.ko ppp_deflate.ko + do + [ ! -f /lib/modules/others/vpn/$i ] || /sbin/insmod /lib/modules/others/vpn/$i + done + fi +} + +init_iptable_modules() +{ + [ -L /usr/lib/libxtables.so.7 ] || /bin/ln -sf /usr/lib/libxtables.so.7.0.0 /usr/lib/libxtables.so.7 + [ -L /usr/lib/libxtables.so ] || /bin/ln -sf /usr/lib/libxtables.so.7.0.0 /usr/lib/libxtables.so + [ -L /usr/lib/libip4tc.so.0 ] || /bin/ln -sf /usr/lib/libip4tc.so.0.0.0 /usr/lib/libip4tc.so.0 + [ -L /usr/lib/libip4tc.so ] || /bin/ln -sf /usr/lib/libip4tc.so.0.0.0 /usr/lib/libip4tc.so + [ -L /usr/lib/libip6tc.so.0 ] || /bin/ln -sf /usr/lib/libip6tc.so.0.0.0 /usr/lib/libip6tc.so.0 + [ -L /usr/lib/libip6tc.so ] || /bin/ln -sf /usr/lib/libip6tc.so.0.0.0 /usr/lib/libip6tc.so + /sbin/lsmod | grep x_tables 1>>/dev/null 2>>/dev/null + if [ $? != 0 ]; then + /bin/echo "insmod iptable modules" + for i in x_tables.ko nf_conntrack.ko xt_tcpudp.ko nf_defrag_ipv4.ko nf_conntrack_ipv4.ko nf_nat.ko \ + ip_tables.ko iptable_nat.ko iptable_filter.ko ipt_MASQUERADE.ko ipt_REDIRECT.ko + do + [ ! -f /lib/modules/others/vpn/$i ] || /sbin/insmod /lib/modules/others/vpn/$i + done + fi +} + +remove_pptp_modules() +{ + for i in ppp_deflate bsd_comp ppp_mppe ppp_async ppp_generic crc-ccitt slhc + do + /sbin/rmmod $i + done +} + +remove_iptable_modules() +{ + for i in ipt_REDIRECT ipt_MASQUERADE iptable_filter iptable_nat ip_tables nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 \ + xt_tcpudp nf_conntrack x_tables + do + /sbin/rmmod $i + done +} + +start() +{ + if [ ! -f ${PPTPD} ]; then + /bin/echo "pptpd is not exit." + exit 1 + fi + + if [ ! -f /usr/sbin/pppd ]; then + /bin/echo "pppd is not exit." + exit 1 + fi + + if [ ! -L /etc/rcK.d/K47vpn_pptp ]; then + /bin/ln -sf ../init.d/vpn_pptp.sh /etc/rcK.d/K47vpn_pptp + fi + + if [ -f ${PIDFILE} ]; then + /bin/echo "pptpd is aleady run." + exit 1 + fi + + if [ `/sbin/getcfg "PPTP" "Enable" -u -d "FALSE" -f "${VPN_CONF}"` = "TRUE" ]; then + /bin/echo "pptpd start." + init_pptp_modules + init_iptable_modules + /sbin/vpn_util init_pptp ${DBG} + /sbin/daemon_mgr pptpd start "${PPTPD} -c ${PPTPD_CONF} -o ${OPTIONS_PPTPD} -p ${PIDFILE}" + LOCALIP=`grep "^localip" ${PPTPD_CONF} | cut -d' ' -f 2` + INTERFACE=`grep "^bcrelay" ${PPTPD_CONF} | cut -d' ' -f 2` + /bin/echo "LOCALIP = ${LOCALIP} INTERFACE = ${INTERFACE}" + /sbin/iptables -t nat -A POSTROUTING -s ${LOCALIP}/24 -o ${INTERFACE} -j MASQUERADE + else + /bin/echo "pptpd is disabled." + fi +} + +stop() +{ + /bin/echo "pptpd stop." + LOCALIP=`grep "^localip" ${PPTPD_CONF} | cut -d' ' -f 2` + INTERFACE=`grep "^bcrelay" ${PPTPD_CONF} | cut -d' ' -f 2` + /bin/echo "LOCALIP = ${LOCALIP} INTERFACE = ${INTERFACE}" + /sbin/iptables -t nat -D POSTROUTING -s ${LOCALIP}/24 -o ${INTERFACE} -j MASQUERADE + + /bin/kill -9 `/bin/pidof pppd` 1>>/dev/null 2>&1 + /bin/kill -9 `/bin/pidof bcrelay` 1>>/dev/null 2>&1 + /sbin/daemon_mgr pptpd stop "${PPTPD} -c ${PPTPD_CONF} -o ${OPTIONS_PPTPD} -p ${PIDFILE}" + /bin/kill -9 `/bin/cat ${PIDFILE}` 1>>/dev/null 2>&1 + /bin/rm -f ${PIDFILE} 1>>/dev/null 2>&1 + /bin/rm -f /var/log/pptp_online_user 1>>/dev/null 2>&1 +} + +reload() +{ + if [ `/sbin/getcfg "PPTP" "Enable" -u -d "FALSE" -f "${VPN_CONF}"` = "FALSE" ]; then + /bin/echo "pptpd is disabled." + exit 1; + fi + /bin/echo "pptpd stop." + /bin/kill -9 `/bin/pidof bcrelay` 1>>/dev/null 2>&1 + /sbin/daemon_mgr pptpd stop "${PPTPD} -c ${PPTPD_CONF} -o ${OPTIONS_PPTPD} -p ${PIDFILE}" + /bin/kill -9 `/bin/cat ${PIDFILE}` 1>>/dev/null 2>&1 + /bin/rm -f ${PIDFILE} 1>>/dev/null 2>&1 + LOCALIP=`grep "^localip" ${PPTPD_CONF} | cut -d' ' -f 2` + INTERFACE=`grep "^bcrelay" ${PPTPD_CONF} | cut -d' ' -f 2` + /bin/echo "LOCALIP = ${LOCALIP} INTERFACE = ${INTERFACE}" + /sbin/iptables -t nat -D POSTROUTING -s ${LOCALIP}/24 -o ${INTERFACE} -j MASQUERADE + + /sbin/vpn_util init_pptp ${DBG} + /sbin/daemon_mgr pptpd start "${PPTPD} -c ${PPTPD_CONF} -o ${OPTIONS_PPTPD} -p ${PIDFILE}" + LOCALIP=`grep "^localip" ${PPTPD_CONF} | cut -d' ' -f 2` + INTERFACE=`grep "^bcrelay" ${PPTPD_CONF} | cut -d' ' -f 2` + /bin/echo "LOCALIP = ${LOCALIP} INTERFACE = ${INTERFACE}" + /sbin/iptables -t nat -A POSTROUTING -s ${LOCALIP}/24 -o ${INTERFACE} -j MASQUERADE +} + +restart() +{ + stop + sleep 1 + start +} + +case "$1" in + start) + start + ;; + stop) + stop + remove_pptp_modules + ;; + restart) + restart + ;; + init) + /bin/echo "pptpd init." + init_pptp_modules + init_iptable_modules + /sbin/vpn_util init_pptp + ;; + reload) + reload + ;; + *) + echo "Usage: /etc/init.d/$0 {start|stop|restart|reload}" + exit 1 +esac + +exit 0 diff --git a/wait_RR b/wait_RR new file mode 100755 index 0000000..81ffa2c --- /dev/null +++ b/wait_RR @@ -0,0 +1,27 @@ +#!/bin/sh +POSTPONE_PFILE=/tmp/postpone-RR.pid +WAIT_FOR_RR=`/sbin/getcfg "Schedule Booting And Shutdown" "Wait RR" -d 0 -f /etc/config/schedule_boot_setting` +if [ "$WAIT_FOR_RR" = "1" ]; then + RR_RUNNING=1 + if [ -f $POSTPONE_PFILE ]; then + kill `/bin/cat $POSTPONE_PFILE` + fi + echo $$ > $POSTPONE_PFILE + while [ $RR_RUNNING = 1 ]; do + /bin/ps | /bin/grep /usr/bin | /bin/grep "rsync " + if [ $? != 0 ]; then + RR_RUNNING=0 + fi + if [ -f /usr/bin/qsync ]; then + /usr/bin/qsync -busy + if [ 1 = $? ]; then + RR_RUNNING=1 + fi + fi + if [ 1 = $RR_RUNNING ]; then + sleep 10 + fi + done + rm $POSTPONE_PFILE +fi + diff --git a/wfm_thttpd.sh b/wfm_thttpd.sh new file mode 100755 index 0000000..488afbe --- /dev/null +++ b/wfm_thttpd.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# For Administration +# default port: 8008 +WFM_THTTPD_PATH="/usr/local/sbin/wfm_thttpd" +ENABLE_WFM=`/sbin/getcfg WebFS Enable` +ENABLE_WFM_PORT=`/sbin/getcfg WebFS Enable_Defined_Port -d "FALSE"` +WFM_PORT=`/sbin/getcfg WebFS Port -d "8008"` +WFM_SSLPORT=`/sbin/getcfg WebFS SSL_Port` +RUNNING_FILE="/var/lock/subsys/wfm_thttpd" +APP_RUNTIME_CONF="/var/.application.conf" +PortSettingSupport=`/sbin/getcfg WebFS PortSettingSupport -d TRUE -f ${APP_RUNTIME_CONF}` + +if [ "$PortSettingSupport" = "FALSE" ]; then + [ "$ENABLE_WFM_PORT" = "FALSE" ] || /sbin/setcfg WebFS Enable_Defined_Port "FALSE" +fi +if [ "$ENABLE_WFM" = "FALSE" ]; then + [ ! -f /home/httpd/cgi-bin/filemanager.html ] || /bin/mv /home/httpd/cgi-bin/filemanager.html /home/filemanager.html + exit 1 +fi + +case "$1" in + start) + echo -n "Starting wfm_thttpd services:" + if [ "$ENABLE_WFM_PORT" = "TRUE" ]; then + ${WFM_THTTPD_PATH} -p ${WFM_PORT} -nor -nos -u admin -d /home/httpd/cgi-bin/filemanager -c '**.*' + else + echo " no enable defined port." + exit 1 + fi + echo -n " wfm_thttpd" + /bin/touch $RUNNING_FILE + echo "." + [ -f /home/httpd/cgi-bin/filemanager/utilRequest.cgi ] && `/home/httpd/cgi-bin/filemanager/utilRequest.cgi check_sharelink_db 1>>/dev/null 2>>/dev/null` + if [ $? = 1 ]; then + /bin/echo "rm share_link.db" + /bin/rm -rf /etc/config/share_link.db + fi + ;; + stop) + echo -n "Shutting down wfm_thttpd services:" + /bin/rm -f $RUNNING_FILE + pid=`/bin/ps |/bin/grep wfm_thttpd` + [ $? = 0 ] && /usr/bin/killall wfm_thttpd 2> /dev/null + echo -n " wfm_thttpd" + echo "." + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: /etc/init.d/wfm_thttpd {start|stop|restart}" + exit 1 +esac + +exit 0 diff --git a/winbind b/winbind new file mode 100755 index 0000000..f9b9d5f --- /dev/null +++ b/winbind @@ -0,0 +1,72 @@ +#!/bin/sh +# +CONFIG=/etc/config/smb.conf + +# Check that smb.conf exists. +[ -f $CONFIG ] || exit 0 + +start() { + echo -n "Starting winbindd services:" + if [ `/sbin/getcfg Samba Enable -u -d TRUE` = FALSE ]; then + echo " disabled." + exit 0 + fi + RETVAL=1 + /bin/grep -i idmap $CONFIG >/dev/null 2>&1 + RETIDMAP=$? + /bin/grep -i winbind.*uid $CONFIG >/dev/null 2>&1 + RETWINBIND=$? + if [ $RETIDMAP = 0 ] || [ $RETWINBIND = 0 ]; then + /sbin/daemon_mgr winbindd start "/usr/local/samba/sbin/winbindd -s $CONFIG" + /bin/touch /etc/krb5.keytab + /bin/chmod 666 /mnt/HDA_ROOT/.domain_* + RETVAL=$? + fi + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/winbind || RETVAL=1 + if [ "$RETVAL" = "0" ]; then echo " winbindd."; fi + + idmap_rid=`/sbin/getcfg Samba "idmap_rid" -d "FALSE"` + if [ "$idmap_rid" = "FALSE" ]; then + /bin/cat /etc/config/crontab | /bin/grep idmap.sh > /dev/null + if [ $? -ne 0 ]; then + echo "0 3 * * 0 /etc/init.d/idmap.sh dump" >> /etc/config/crontab + /usr/bin/crontab /etc/config/crontab + fi + fi + return $RETVAL +} +stop() { + echo -n "Shutting down winbindd services:" +# winbinddpids=`ps guax | grep winbindd | grep -v grep | awk '{print $1}'` +# for pid in $winbinddpids; do +# kill -TERM $pid +# done + /sbin/daemon_mgr winbindd stop "/usr/local/samba/sbin/winbindd" + echo " winbindd." + /bin/sleep 1 + /bin/pidof winbindd 1>>/dev/null 2>>/dev/null + [ $? != 0 ] || /bin/kill `/bin/pidof winbindd` + [ ! -f /var/lock/subsys/winbind ] || rm -f /var/lock/subsys/winbind + return $RETVAL +} +restart() { + stop + start +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 +esac + +exit $? diff --git a/wireless.sh b/wireless.sh new file mode 100755 index 0000000..f5beba6 --- /dev/null +++ b/wireless.sh @@ -0,0 +1,529 @@ +#/bin/sh + +GETCFG="/sbin/getcfg" +WPA_SUPPLICANT="/usr/local/bin/wpa_supplicant" +WPA_SUPPLICANT_CONF="/etc/config/wpa_supplicant.conf" +WIRELESS_PROFILE="/etc/config/wireless.conf" +WIRELESS_STATUS="/tmp/wireless_status" +WIRELESS_TEMP="/tmp/wireless_temp" + +net="" +IP_FORWARD=`/bin/cat /proc/sys/net/ipv4/ip_forward` + +check_ip_forward() +{ + #check ip_forward is 0 or not + if [ "$IP_FORWARD" != "0" ]; then + /bin/echo "0" > /proc/sys/net/ipv4/ip_forward + fi +} + +do_exit() +{ + /bin/echo "$IP_FORWARD" > /proc/sys/net/ipv4/ip_forward + exit $1 +} + +get_net() +{ + ip1=`/bin/echo $1|cut -d '.' -f 1` + ip2=`/bin/echo $1|cut -d '.' -f 2` + ip3=`/bin/echo $1|cut -d '.' -f 3` + ip4=`/bin/echo $1|cut -d '.' -f 4` + netmask1=`/bin/echo $2|cut -d '.' -f 1` + netmask2=`/bin/echo $2|cut -d '.' -f 2` + netmask3=`/bin/echo $2|cut -d '.' -f 3` + netmask4=`/bin/echo $2|cut -d '.' -f 4` + if [ $netmask2 -ne 255 ]; then + left=`expr 255 - $(($netmask2)) + 1` + remainder=`expr $(($ip2)) % $left` + mask=`expr $(($ip2)) - $remainder` + net="$ip1.$mask.0.0" + elif [ $netmask3 -ne 255 ]; then + left=`expr 255 - $(($netmask3)) + 1` + remainder=`expr $(($ip3)) % $left` + mask=`expr $(($ip3)) - $remainder` + net="$ip1.$ip2.$mask.0" + elif [ $netmask4 -ne 255 ]; then + left=`expr 255 - $(($netmask4)) + 1` + remainder=`expr $(($ip4)) % $left` + mask=`expr $(($ip4)) - $remainder` + net="$ip1.$ip2.$ip3.$mask" + else + net="$ip1.$ip2.$ip3.$ip4" + fi +} + +reset_status() +{ + while read LINE + do + ssid=`/bin/echo $LINE |/bin/grep '\['|/bin/cut -d'[' -f2|/bin/cut -d']' -f1` + [ "x$ssid" = "x" ] && continue + status=`/sbin/getcfg "$ssid" status -f $WIRELESS_PROFILE` + [ $status -ge 5 ] && /sbin/setcfg "$ssid" status 0 -f $WIRELESS_PROFILE + done < $WIRELESS_PROFILE +} + +auto_connect() +{ + /bin/rm -f $WIRELESS_STATUS 2>>/dev/null + /bin/touch $WIRELESS_STATUS + ifname=`/bin/cat /proc/net/wireless |/bin/grep -v Inter|/bin/grep -v face|cut -d':' -f 1|sed 's/\ //g'` + if [ "x$ifname" = "x" ]; then + /sbin/setcfg "" status "1" -f $WIRELESS_STATUS + do_exit 1 + fi + + stop + /sbin/ifconfig $ifname up + local check=0 + while [ 1 ]; do + if [ ! -f $WIRELESS_PROFILE ]; then + check=$(($check+1)) + sleep 5 + else + break + fi + [ $check -gt 10 ] && break + done + + while read LINE + do + essid=`/bin/echo $LINE |/bin/grep '\['|/bin/cut -d'[' -f2|/bin/cut -d']' -f1` + [ "x$essid" = "x" ] && continue + iwlist=`/bin/ps|/bin/grep iwlist|/bin/grep scan` + while [ "$iwlist" != "" ]; do + iwlist=`/bin/ps|/bin/grep iwlist|/bin/grep scan` + [ "x$iwlist" = "x" ] && break + sleep 1 + done + + check=0 + while [ 1 ];do + in_range=`/usr/local/bin/iwlist $ifname scanning | /bin/grep "$essid"` + [ "x$in_range" != "x" ] && break + check=$(($check+1)) + [ $check -gt 10 ] && break + sleep 1 + /sbin/ifconfig $ifname up + done + [ "x$in_range" = "x" ] && continue + autoconnect=`/sbin/getcfg "$essid" autoconnect -f $WIRELESS_PROFILE` + if [ "$autoconnect" = "1" ]; then + /bin/rm -f $WPA_SUPPLICANT_CONF + /bin/touch $WPA_SUPPLICANT_CONF + mode=`/sbin/getcfg "$essid" mode -f $WIRELESS_PROFILE` + if [ "$mode" = "Ad-Hoc" ]; then + /bin/echo "ap_scan=2" >> $WPA_SUPPLICANT_CONF + fi + + /bin/echo "network={" >> $WPA_SUPPLICANT_CONF + /bin/echo " ssid=\"$essid\"" >> $WPA_SUPPLICANT_CONF + if [ "$mode" = "Ad-Hoc" ]; then + /bin/echo " mode=1" >> $WPA_SUPPLICANT_CONF + /bin/echo " frequency=2412" >> $WPA_SUPPLICANT_CONF + fi + + auth=`/sbin/getcfg "$essid" auth -f $WIRELESS_PROFILE` + if [ "$auth" = "OPEN" ]; then + /bin/echo " key_mgmt=NONE" >> $WPA_SUPPLICANT_CONF + elif [ "$auth" = "WEP" ]; then + /bin/echo " key_mgmt=NONE" >> $WPA_SUPPLICANT_CONF + wep_tx_keyidx=`/sbin/getcfg "$essid" wep_tx_keyidx -f $WIRELESS_PROFILE` + wep="wep_key$wep_tx_keyidx" + wep_key=`/sbin/getcfg "$essid" $wep -f $WIRELESS_PROFILE` + if [ ${#wep_key} = 5 -o ${#wep_key} = 13 ]; then + /bin/echo " $wep=\"$wep_key\"" >> $WPA_SUPPLICANT_CONF + elif [ ${#wep_key} = 10 -o ${#wep_key} = 26 ]; then + /bin/echo " $wep=$wep_key" >> $WPA_SUPPLICANT_CONF + fi + + /bin/echo " wep_tx_keyidx=$wep_tx_keyidx" >> $WPA_SUPPLICANT_CONF + + if [ "$mode" != "Ad-Hoc" ]; then + /bin/echo " auth_alg=OPEN" >> $WPA_SUPPLICANT_CONF + + fi + else + if [ "$mode" = "Ad-Hoc" ]; then + /bin/echo " key_mgmt=WPA-NONE" >> $WPA_SUPPLICANT_CONF + else + /bin/echo " key_mgmt=WPA-PSK" >> $WPA_SUPPLICANT_CONF + fi + cipher=`/sbin/getcfg "$essid" cipher -f $WIRELESS_PROFILE` + psk=`/sbin/getcfg "$essid" psk -f $WIRELESS_PROFILE` + if [ ${#psk} -ge 8 -o ${#psk} -le 63 ]; then + /bin/echo " psk=\"$psk\"" >> $WPA_SUPPLICANT_CONF + elif [ ${#psk} -eq 64 ]; then + /bin/echo " psk=$psk" >> $WPA_SUPPLICANT_CONF + fi + fi + /bin/echo "}" >> $WPA_SUPPLICANT_CONF + + start + /sbin/ifconfig $ifname|/bin/grep "inet addr:" + if [ $? = 0 ]; then + mac_addr=`/sbin/getcfg "$essid" mac_addr -f $WIRELESS_PROFILE` + channel=`/sbin/getcfg "$essid" channel -f $WIRELESS_PROFILE` + freq=`/sbin/getcfg "$essid" freq -f $WIRELESS_PROFILE` + quality=`/sbin/getcfg "$essid" quality -f $WIRELESS_PROFILE` + auth=`/sbin/getcfg "$essid" auth -f $WIRELESS_PROFILE` + cipher=`/sbin/getcfg "$essid" cipher -f $WIRELESS_PROFILE` + enc=`/sbin/getcfg "$essid" enc -f $WIRELESS_PROFILE` + wep_key0=`/sbin/getcfg "$essid" wep_key0 -f $WIRELESS_PROFILE` + wep_key1=`/sbin/getcfg "$essid" wep_key1 -f $WIRELESS_PROFILE` + wep_key2=`/sbin/getcfg "$essid" wep_key2 -f $WIRELESS_PROFILE` + wep_key3=`/sbin/getcfg "$essid" wep_key3 -f $WIRELESS_PROFILE` + wep_tx_keyidx=`/sbin/getcfg "$essid" wep_tx_keyidx -f $WIRELESS_PROFILE` + mode=`/sbin/getcfg "$essid" mode -f $WIRELESS_PROFILE` + psk=`/sbin/getcfg "$essid" psk -f $WIRELESS_PROFILE` + autoconnect=`/sbin/getcfg "$essid" autoconnect -f $WIRELESS_PROFILE` + status=`/sbin/getcfg "$essid" status -f $WIRELESS_PROFILE` + protocol=`/sbin/getcfg "$essid" protocol -f $WIRELESS_PROFILE` + /bin/rm -f $WIRELESS_TEMP + /bin/touch $WIRELESS_TEMP + /sbin/setcfg "$essid" mac_addr "$mac_addr" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" channel "$channel" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" freq "$freq" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" quality "$quality" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" auth "$auth" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" cipher "$cipher" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" enc "$enc" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" mode "$mode" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" wep_key0 "$wep_key0" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" wep_key1 "$wep_key1" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" wep_key2 "$wep_key2" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" wep_key3 "$wep_key3" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" autoconnect "$autoconnect" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" protocol "$protocol" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" status "$status" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" wep_tx_keyidx "$wep_tx_keyidx" -f $WIRELESS_TEMP + /sbin/setcfg "$essid" psk "$psk" -f $WIRELESS_TEMP + + /sbin/rmcfg "$essid" -f $WIRELESS_PROFILE + /bin/cat $WIRELESS_PROFILE >> $WIRELESS_TEMP + /bin/mv $WIRELESS_TEMP $WIRELESS_PROFILE + break + fi + #stop #not to let wlan0 down + fi + done < $WIRELESS_PROFILE +} + +stop() +{ + local ssid=`/sbin/getcfg "" ssid -f $WPA_SUPPLICANT_CONF |/bin/cut -d '"' -f 2` + local status=`/sbin/getcfg "$ssid" status -f $WIRELESS_PROFILE` + [ $(($status)) -le 4 ] && /sbin/setcfg "$ssid" status 0 -f $WIRELESS_PROFILE + + # init log file + /sbin/setcfg "" status "" -f $WIRELESS_STATUS 2> /dev/null + + # disconnect AP + /usr/bin/killall wpa_supplicant 2> /dev/null + + if [ -f /etc/dhcpc/dhcpcd-$ifname.pid ]; then + local pid=`/bin/cat /etc/dhcpc/dhcpcd-$ifname.pid` + /bin/kill -9 $pid 2>>/dev/null + /bin/rm -f /etc/dhcpc/dhcpcd-$ifname.pid &> /dev/null + /bin/rm -f /etc/dhcpc/dhcpcd-$ifname.info &> /dev/null + fi + pid=$(/bin/ps | /bin/grep "dhcpcd" | /bin/grep "wlan0" | /bin/awk '{print $1}') + /bin/kill $pid 2>>/dev/null + + [ "$status" = "1" -o "$status" = "2" ] && [ ! -z "$ssid" ] && /sbin/write_log "[TCP/IP] You have successfully disconnected from the wireless network [$ssid]." 4 + + ifname=`/bin/cat /proc/net/wireless |/bin/grep -v Inter|/bin/grep -v face|cut -d':' -f 1|sed 's/\ //g'` + if [ "x$ifname" = "x" ]; then + #/sbin/setcfg "" status "1" -f $WIRELESS_STATUS + do_exit 1 + fi + + # release ip + /sbin/ifconfig $ifname 0.0.0.0 2> /dev/null + + sleep 1 + # free interface + /sbin/ifconfig $ifname down + + /bin/ps | /bin/grep "wireless.sh" | /bin/grep start | /bin/cut -d 'a' -f 1| sed 's/\ //g'|xargs kill 2> /dev/null +} + +start() +{ + #check interface plugin + [ ! -d /sys/class/net/wlan0 ] && do_exit 0 + + # init log file + /bin/rm -f $WIRELESS_STATUS + /bin/touch $WIRELESS_STATUS + + # set interface up + ifname=`/bin/cat /proc/net/wireless |/bin/grep -v Inter|/bin/grep -v face|cut -d':' -f 1|sed 's/\ //g'` + if [ "x$ifname" = "x" ]; then + /sbin/setcfg "" status "1" -f $WIRELESS_STATUS + do_exit 1 + fi + /sbin/ifconfig $ifname up + + # pre-set static ip + iptype=`/sbin/getcfg wireless iptype` + if [ "$iptype" = "static" ]; then + # set ip + ip=`/sbin/getcfg wireless ip -d ""` + [ "x$ip" != "x" ] || do_exit 1 + netmask=`/sbin/getcfg wireless netmask` + gateway=`/sbin/getcfg wireless gateway` + /sbin/ifconfig $ifname $ip netmask $netmask + if [ $? != 0 ]; then + #Error : set static ip fail. + /sbin/setcfg "" status "4" -f $WIRELESS_STATUS + /sbin/setcfg "$ssid" status 6 -f $WIRELESS_PROFILE + stop + return + #exit 1 + fi + fi + + [ ! -f $WPA_SUPPLICANT ] && do_exit 0 + [ ! -f $WPA_SUPPLICANT_CONF ] && do_exit 0 + + # set status "connecting" + ssid=`/sbin/getcfg "" ssid -f $WPA_SUPPLICANT_CONF |/bin/cut -d '"' -f 2` + /sbin/setcfg "$ssid" status 2 -f $WIRELESS_PROFILE + # connect to AP + $WPA_SUPPLICANT -d -D wext -i $ifname -c $WPA_SUPPLICANT_CONF &> /dev/null & + if [ $? != 0 ]; then + #Error : can't start wireless tool. + /sbin/setcfg "" status "2" -f $WIRELESS_STATUS + stop + do_exit 1 + fi + /usr/local/bin/iwconfig "$ifname" essid "$ssid" + # check ap link + local count=0 + local mode=`/sbin/getcfg "$ssid" mode -f $WIRELESS_PROFILE` + while [ 1 ]; do + # authentication fail (key incorrect) + status=`/sbin/getcfg "" status -f $WIRELESS_STATUS` + if [ "$status" = "9" ]; then + /sbin/setcfg "$ssid" status 7 -f $WIRELESS_PROFILE + #stop + #return + #exit 1 + fi + + # check if AP linked + /usr/local/bin/iwconfig $ifname 2> /dev/null |/bin/grep "Not-Associated" + if [ $? = 0 ]; then + count=$(($count + 2)) + [ $count = 60 ] && /sbin/setcfg "$ssid" status 6 -f $WIRELESS_PROFILE && stop && return + fi + + local mac=`/sbin/getcfg "$ssid" mac_addr -d "use_profile" -f $WIRELESS_PROFILE` + if [ "$mac" = "use_profile" ]; then + /usr/local/bin/iwconfig $ifname 2> /dev/null|/bin/grep "ESSID:" + else + if [ "$mode" = "Ad-Hoc" ]; then + /usr/local/bin/iwconfig $ifname 2> /dev/null|/bin/grep "Cell:"|/bin/grep $mac + else + /usr/local/bin/iwconfig $ifname 2> /dev/null|/bin/grep "Access Point:"|/bin/grep $mac + fi + fi + [ $? = 0 ] && break + sleep 2 + done + + # set ip and route + iptype=`/sbin/getcfg wireless iptype` + if [ "$iptype" = "static" ]; then + # set ip + ip=`/sbin/getcfg wireless ip` + netmask=`/sbin/getcfg wireless netmask` + gateway=`/sbin/getcfg wireless gateway` + /sbin/ifconfig $ifname $ip netmask $netmask + if [ $? != 0 ]; then + #Error : set static ip fail. + /sbin/setcfg "" status "4" -f $WIRELESS_STATUS + /sbin/setcfg "$ssid" status 6 -f $WIRELESS_PROFILE + stop + return + #exit 1 + fi + + #/sbin/route del -net $net netmask $netmask + if [ "x$gateway" != "x" -a ${#gateway} -gt 3 ]; then + if [ "$mode" != "Ad-Hoc" ]; then + keyerr_ssid="" + while [ 1 ]; do + # authentication fail (key incorrect) + status=`/sbin/getcfg "" status -f $WIRELESS_STATUS` + if [ "$status" = "9" ]; then + /sbin/setcfg "$ssid" status 7 -f $WIRELESS_PROFILE + keyerr_ssid="$ssid" + #stop + #return + #exit 1 + fi + + count=`expr $count + 1` + if [ $count = 60 ]; then + auth=`/sbin/getcfg "$ssid" auth -f $WIRELESS_PROFILE` + if [ "$auth" = "WEP" ]; then + /usr/local/bin/iwconfig $ifname 2> /dev/null |/bin/grep "Encryption key" |/bin/grep "off" + if [ $? != 0 ]; then + /sbin/setcfg "$ssid" status 7 -f $WIRELESS_PROFILE + stop + return + fi + fi + #Error : key incorrect. + if [ -z "$keyerr_ssid" ] || [ "x$keyerr_ssid" != "x$ssid" ]; then + /bin/ping -c 1 $gateway 2> /dev/null + if [ $? = 0 ]; then + break + fi + /sbin/setcfg "" status "8" -f $WIRELESS_STATUS + /sbin/setcfg "$ssid" status 6 -f $WIRELESS_PROFILE + fi + #stop #not to stop wlan0 even without correct key + return + #exit 1 + fi + sleep 1 + done + fi + #get_net $ip $netmask + + # check and add default gateway + local dfgw=`$GETCFG "Network" "Default GW Device" -d "eth0"` + if [ "$dfgw" = "wlan0" ]; then + #/sbin/route add -net $net netmask $netmask gw $gateway + /sbin/route add default gw $gateway wlan0 + if [ $? != 0 ]; then + #Error : set routing fail. + /sbin/setcfg "" status "5" -f $WIRELESS_STATUS + /sbin/setcfg "$ssid" status 6 -f $WIRELESS_PROFILE + stop + return + #exit 1 + fi + fi + + fi + + #/sbin/setcfg "" status "Message : wireless is working." -f $WIRELESS_STATUS + /sbin/setcfg "$ssid" status 1 -f $WIRELESS_PROFILE + /sbin/write_log "[TCP/IP] You have successfully connected to the wireless network [$ssid]." 4 + reset_status + else # include dhcp + #/sbin/setcfg "" status "Message : geting wireless ip ..." -f $WIRELESS_STATUS + + # starting dhcp + local dfgw=`$GETCFG "Network" "Default GW Device" -d "eth0"` + if [ "$dfgw" = "wlan0" ]; then + /sbin/dhcpcd -h "`/bin/hostname`" -t 30 $ifname & + else + /sbin/dhcpcd -h "`/bin/hostname`" -t 30 -G $ifname & + fi + if [ $? != 0 ]; then + #Error : can't start dhcp client. + /sbin/setcfg "" status "6" -f $WIRELESS_STATUS + /sbin/setcfg "$ssid" status 5 -f $WIRELESS_PROFILE + stop + return + #exit 1 + fi + + #/sbin/setcfg "" status "Message : dhcp ok." -f $WIRELESS_STATUS + + # check ip was set on interface + keyerr_ssid="" + while [ 1 ]; do + # authentication fail (key incorrect) + status=`/sbin/getcfg "" status -f $WIRELESS_STATUS` + if [ "$status" = "9" ]; then + /sbin/setcfg "$ssid" status 7 -f $WIRELESS_PROFILE + keyerr_ssid="$ssid" + #stop + #return + #exit 1 + fi + + /sbin/ifconfig $ifname|/bin/grep "inet addr:" + if [ $? = 0 ]; then + ip=`/sbin/ifconfig $ifname|/bin/grep inet|/bin/cut -d : -f 2|/bin/cut -d ' ' -f 1` + netmask=`/sbin/ifconfig $ifname|/bin/grep Mask|/bin/cut -d : -f 4|/bin/cut -d ' ' -f 1` + gateway=`/sbin/route -e|/bin/grep $ifname|/bin/grep default|/bin/cut -d' ' -f 10` + get_net $ip $netmask + #/sbin/route del default gw $gateway + #/sbin/route add -net $net netmask $netmask gw $gateway + if [ $? != 0 ]; then + #Error : set routing fail. + /sbin/setcfg "" status "5" -f $WIRELESS_STATUS + /sbin/setcfg "$ssid" status 5 -f $WIRELESS_PROFILE + stop + return + #exit 1 + fi + #/sbin/setcfg "" status "Message : wireless is working." -f $WIRELESS_STATUS + /sbin/setcfg "$ssid" status 1 -f $WIRELESS_PROFILE + /sbin/write_log "[TCP/IP] You have successfully connected to the wireless network [$ssid]." 4 + reset_status + return + #exit 0 + else + count=`expr $count + 1` + if [ $count = 60 ]; then + auth=`/sbin/getcfg "$ssid" auth -f $WIRELESS_PROFILE` + if [ "$auth" = "WEP" ]; then + /usr/local/bin/iwconfig $ifname 2> /dev/null |/bin/grep "Encryption key" |/bin/grep "off" + if [ $? != 0 ]; then + /sbin/setcfg "$ssid" status 7 -f $WIRELESS_PROFILE + stop + return + fi + fi + #Error : dhcp can't get ip information. + /sbin/setcfg "" status "7" -f $WIRELESS_STATUS + if [ -z "$keyerr_ssid" ] || [ "x$keyerr_ssid" != "x$ssid" ]; then + /sbin/setcfg "$ssid" status 5 -f $WIRELESS_PROFILE + fi + #stop #not to let wlan0 down even without ip + return + #exit 1 + fi + fi + sleep 1 + done + + fi +} + +case "$1" in +start) + check_ip_forward + start + ;; +stop) + stop + ;; +restart) + stop + check_ip_forward + start + ;; +auto_connect) + check_ip_forward + auto_connect + ;; +*) + /bin/echo $"Usage: $0 {start|stop|restart|auto_connect}" + exit 1 +esac + +# Service binding +/sbin/getbindaddr -refresh > /dev/null 2>/dev/null + +do_exit 0 diff --git a/wireless_modules.sh b/wireless_modules.sh new file mode 100755 index 0000000..7e23013 --- /dev/null +++ b/wireless_modules.sh @@ -0,0 +1,170 @@ +#!/bin/sh +# +# Copyright @ 2005 QNAP Systems Inc. +# +# network This script insert/remove wireless modules. +# +# Version 1.0.0 +# +case "$1" in +start) + if [ "x$2" = "xWIFI_RT5370" ]; then + while [ 1 ]; do + /sbin/lsmod | /bin/grep rt5370sta 1>/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + exit 0 + fi + echo "insert modules $2..." >> /tmp/wifidebug + /sbin/insmod /usr/local/modules/rt5370sta.ko + if [ "$?" = "0" ]; then + echo "insert modules $2 success..." >> /tmp/wifidebug + /bin/sleep 1 + /etc/init.d/wireless.sh auto_connect & + exit 0 + fi + /bin/sleep 5 + done + elif [ "x$2" = "xWIFI_RT2870" ]; then + while [ 1 ]; do + /sbin/lsmod | /bin/grep rt2870sta 1>/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + exit 0 + fi + echo "insert modules $2..." >> /tmp/wifidebug + /sbin/insmod /usr/local/modules/rt2870sta.ko + if [ "$?" = "0" ]; then + echo "insert modules $2 success..." >> /tmp/wifidebug + /bin/sleep 1 + /etc/init.d/wireless.sh auto_connect & + exit 0 + fi + /bin/sleep 5 + done + elif [ "x$2" = "xWIFI_RT3070" ]; then + while [ 1 ]; do + /sbin/lsmod | /bin/grep rt3070sta 1>/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + exit 0 + fi + echo "insert modules $2..." >> /tmp/wifidebug + /sbin/insmod /usr/local/modules/rt3070sta.ko + if [ "$?" = "0" ]; then + echo "insert modules $2 success..." >> /tmp/wifidebug + /bin/sleep 1 + /etc/init.d/wireless.sh auto_connect & + exit 0 + fi + /bin/sleep 5 + done + elif [ "x$2" = "xWIFI_RT3572" ]; then + while [ 1 ]; do + /sbin/lsmod | /bin/grep rt3572sta 1>/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + exit 0 + fi + echo "insert modules $2..." >> /tmp/wifidebug + /sbin/insmod /usr/local/modules/rt3572sta.ko + if [ "$?" = "0" ]; then + echo "insert modules $2 success..." >> /tmp/wifidebug + /bin/sleep 1 + /etc/init.d/wireless.sh auto_connect & + exit 0 + fi + /bin/sleep 5 + done + elif [ "x$2" = "xWIFI_RTL8192CU" ]; then + while [ 1 ]; do + /sbin/lsmod | /bin/grep 8192cu 1>/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + exit 0 + fi + echo "insert modules $2..." >> /tmp/wifidebug + /sbin/insmod /usr/local/modules/8192cu.ko + if [ "$?" = "0" ]; then + echo "insert modules $2 success..." >> /tmp/wifidebug + /bin/sleep 1 + /etc/init.d/wireless.sh auto_connect & + exit 0 + fi + /bin/sleep 5 + done + elif [ "x$2" = "xWIFI_RTL8712" ]; then + while [ 1 ]; do + /sbin/lsmod | /bin/grep 8712u 1>/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + exit 0 + fi + echo "insert modules $2..." >> /tmp/wifidebug + /sbin/insmod /usr/local/modules/8712u.ko + if [ "$?" = "0" ]; then + echo "insert modules $2 success..." >> /tmp/wifidebug + /bin/sleep 1 + /etc/init.d/wireless.sh auto_connect & + exit 0 + fi + /bin/sleep 5 + done + elif [ "x$2" = "xWIFI_RT5592" ]; then + while [ 1 ]; do + /sbin/lsmod | /bin/grep rt5592sta 1>/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + exit 0 + fi + echo "insert modules $2..." >> /tmp/wifidebug + /sbin/insmod /usr/local/modules/rt5592sta.ko + if [ "$?" = "0" ]; then + echo "insert modules $2 success..." >> /tmp/wifidebug + /bin/sleep 1 + /etc/init.d/wireless.sh auto_connect & + exit 0 + fi + /bin/sleep 5 + done + elif [ "x$2" = "xWIFI_RTL8192" ]; then + while [ 1 ]; do + /sbin/lsmod | /bin/grep rtl8192ce 1>/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + exit 0 + fi + echo "insert modules $2..." >> /tmp/wifidebug + /sbin/insmod /usr/local/modules/rtlwifi.ko + /sbin/insmod /usr/local/modules/rtl8192ce.ko + if [ "$?" = "0" ]; then + echo "insert modules $2 success..." >> /tmp/wifidebug + /bin/sleep 1 + /etc/init.d/wireless.sh auto_connect & + exit 0 + fi + /bin/sleep 5 + done + fi + ;; +stop) + /etc/init.d/wireless.sh stop 1>>/dev/null 2>>/dev/null + /bin/sleep 1 + echo "remove modules $2..." >> /tmp/wifidebug + if [ "x$2" = "xWIFI_RT5370" ]; then + /sbin/rmmod /usr/local/modules/rt5370sta.ko + elif [ "x$2" = "xWIFI_RT2870" ]; then + /sbin/rmmod /usr/local/modules/rt2870sta.ko + elif [ "x$2" = "xWIFI_RT3070" ]; then + /sbin/rmmod /usr/local/modules/rt3070sta.ko + elif [ "x$2" = "xWIFI_RT3572" ]; then + /sbin/rmmod /usr/local/modules/rt3572sta.ko + elif [ "x$2" = "xWIFI_RTL8192CU" ]; then + /sbin/rmmod /usr/local/modules/8192cu.ko + elif [ "x$2" = "xWIFI_RTL8712" ]; then + /sbin/rmmod /usr/local/modules/8712u.ko + elif [ "x$2" = "xWIFI_RT5592" ]; then + /sbin/rmmod /usr/local/modules/rt5592sta.ko + elif [ "x$2" = "xWIFI_RTL8192" ]; then + /sbin/rmmod /usr/local/modules/rtl8192ce.ko + /sbin/rmmod /usr/local/modules/rtlwifi.ko + fi + ;; + +*) + /bin/echo $"Usage: $0 {start|stop} {chipset}" + exit 1 +esac +