#!/bin/sh QPKG_CONF="/etc/config/qpkg.conf" QPKG_NAME=QuFTP QPKG_HOME=`/sbin/getcfg $QPKG_NAME Install_Path -f ${QPKG_CONF}` QPKG_ENABLE=`/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f ${QPKG_CONF}` AP_ENABLE=`/sbin/getcfg FTP Enable -u -d FALSE` QPKG_RUN_DIR="/mnt/ext/opt/QuFTP" export QNAP_QPKG=$QPKG_NAME # q_status Q_APP_NAME=ftp QUI_STATUS_PATH=/tmp/q_status/$Q_APP_NAME update_qui_status() { [ ! -f $QUI_STATUS_PATH ] || /sbin/setcfg $Q_APP_NAME q_status $1 -f $QUI_STATUS_PATH } # cert 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 } _install() { if [ ! -d "${QPKG_HOME}" ]; then echo "Can not found QuFTP install path ${QPKG_HOME}" exit 1 fi /bin/rm -rf ${QPKG_RUN_DIR} > /dev/null 2>&1 /bin/ln -sf ${QPKG_HOME} ${QPKG_RUN_DIR} > /dev/null 2>&1 /bin/ln -sf ${QPKG_RUN_DIR}/bin/proftpd /usr/local/sbin/proftpd /bin/ln -sf ${QPKG_RUN_DIR}/bin/ftptop /usr/local/sbin/ftptop /bin/ln -sf ${QPKG_RUN_DIR}/bin/quftp_util /usr/local/sbin/quftp_util /bin/ln -sf ${QPKG_RUN_DIR}/bin/quftp_daemon /usr/local/sbin/quftp_daemon /bin/ln -sf ${QPKG_RUN_DIR}/quftp.sh /etc/init.d/quftp.sh /bin/ln -sf ${QPKG_RUN_DIR}/www /home/httpd/cgi-bin/qpkg/QuFTP /usr/local/sbin/nc_tool register -P -p ${QPKG_RUN_DIR} > /dev/null 2>&1 /usr/bin/qevent subscribe -a nsswitch -e reload -s QuFTP -S ${QPKG_RUN_DIR}/quftp_event_handler.sh > /dev/null 2>&1 } _uninstall() { /usr/bin/qevent unsubscribe -a nsswitch -e reload -s QuFTP -S ${QPKG_RUN_DIR}/quftp_event_handler.sh > /dev/null 2>&1 /bin/rm -f /usr/local/sbin/proftpd /bin/rm -f /usr/local/sbin/ftptop /bin/rm -f /usr/local/sbin/quftp_util /bin/rm -f /usr/local/sbin/quftp_daemon /bin/rm -f /etc/init.d/quftp.sh /bin/rm -f /home/httpd/cgi-bin/qpkg/QuFTP /bin/rm -rf ${QPKG_RUN_DIR} > /dev/null 2>&1 } update_qui_status 2 case "$1" in start) _install prepare_cert_key echo -n "Starting QuFTP services: " if [ x$QPKG_ENABLE = xTRUE ] && [ x$AP_ENABLE = xFALSE ]; then DISABLED_BY_QPKG=`/sbin/getcfg FTP DisabledByQPKG -u -d FALSE` if [ x$DISABLED_BY_QPKG = xTRUE ]; then /sbin/setcfg FTP Enable TRUE /sbin/setcfg FTP DisabledByQPKG FALSE AP_ENABLE=TRUE fi fi if [ "x$AP_ENABLE" = xTRUE ]; then if [ -x /usr/local/sbin/quftp_util ]; then /usr/local/sbin/quftp_util -C >/dev/null 2>&1 fi if [ -x /usr/local/sbin/quftp_daemon ]; then /sbin/daemon_mgr quftp_daemon start "/usr/local/sbin/quftp_daemon >/dev/null 2>&1 &" fi if [ -x /usr/local/sbin/proftpd ]; then update_qui_status 3 /sbin/daemon_mgr proftpd start "LD_PRELOAD=/usr/local/lib/libtrash.so TZ=/etc/localtime /usr/local/sbin/proftpd -n > /dev/null 2>&1 &" RETVAL=$? fi fi echo "OK" ;; stop) echo -n "Shutting down QuFTP services: " if [ x$QPKG_ENABLE = xFALSE ] && [ x$AP_ENABLE = xTRUE ]; then /sbin/setcfg FTP Enable FALSE /sbin/setcfg FTP DisabledByQPKG TRUE fi update_qui_status 4 /usr/bin/killall proftpd 1>/dev/null 2>/dev/null /usr/bin/killall quftp_daemon 1>/dev/null 2>/dev/null sleep 1 /sbin/daemon_mgr proftpd stop "/usr/local/sbin/proftpd" /sbin/daemon_mgr quftp_daemon stop "/usr/local/sbin/quftp_daemon" RETVAL=$? count=5 while [ $count -gt 0 ]; do /bin/echo -n "." /bin/pidof proftpd >/dev/null 2>&1 if [ $? -ne 0 ]; then break else /bin/sleep 1 fi count=$(($count-1)); done if [ $count == 0 ]; then /usr/bin/killall -9 proftpd 2>>/dev/null RETVAL=$? fi echo "OK" ;; restart) $0 stop $0 start ;; reconfig) echo "Reconfigure QuFTP services: " if [ -x /usr/local/sbin/quftp_util ]; then /usr/local/sbin/quftp_util -C >/dev/null 2>&1 fi /usr/bin/killall -HUP proftpd RETVAL=$? echo "OK" ;; uninstall) _uninstall ;; *) echo "Usage: $0 {start|stop|restart|reconfig}" exit 1 esac exit $RETVAL