由于portal是以建立daemon的形式运行,因此最适合以服务的方式运行和调用,即用sudo service thunder start以及sudo service thunder stop就可以启动和终止服务,好在thunder远程下载论坛的一位老鸟已经做出了此thunder service脚本,在这里我们拿来用即可,脚本内容如下:
# Check ACTIVE CODE local MSG="" MSG=`cat$LOG | tail -n 4 | grep "ACTIVE CODE"` if [ "$MSG" != "" ] ; then cat$LOG | tail -n 5 | head -n 4 | whileread l; do log_warning_msg $l; done return 2 fi
# Check if bound MSG=`cat$LOG | tail -n 4 | grep "BOUND TO USER"` if [ "$MSG" != "" ] ; then cat$LOG | tail -n 4 | head -n 3 | whileread l; do log_warning_msg $l; done [ -e /var/run/$NAME ] || mkdir /var/run/$NAME ps aux | grep $DAEMON | grep -v grep | awk '{print $2}' > $PIDFILE return 0 fi
return 2 }
# stop the daemon/service
do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred
# killproc -p $PIDFILE $DAEMON
local RET=0
if pidof $DAEMON > /dev/null 2>&1 ; then if [ -e $PIDFILE ] && pidof $DAEMON | tr' ''\n' | grep -w $(cat$PIDFILE) > /dev/null 2>&1 ; then RET=2 else RET=1 fi else RET=0 fi
# RET is: # 0 if Deamon (whichever) is not running # 1 if Deamon (whichever) is running # 2 if Deamon from the PIDFILE is running
if [ $RET = 0 ] ; then return 1 elif [ $RET = 2 ] ; then su $USER -c "$RUN -s" > $LOG 2>/dev/null local COUNT=`cat$LOG | grep -c stopped` if [ $COUNT > 0 ] ; then # remove pidfile if daemon could not delete on exit. rm -f $PIDFILE return 0 else FAIL=`cat$LOG | tail -n 1` return 2 fi elif [ $RET = 1 ] ; then FAIL="There are processes named '$DNAME' running which do not match your pid file which are left untouched in the name of safety, Please review the situation by hand." return 2 fi
* Starting Embed Thunder Manager thunder * * THIS DEVICE HAS BOUND TO USER: ptbsare. * *
若下载器尚未被绑定,则输出类似于:
1 2 3 4 5 6
* Starting Embed Thunder Manager thunder * * THE ACTIVE CODE IS: BXZAMY * * go to http://yuancheng.xunlei.com, bind your device with the active code. *
ptbsare@ptbsare-PC70:~$ cat /opt/Xware/start-thunder #!/bin/bash if [ $USER == "thunder" ];then echo"Please change current user." notify-send "Please change current user." -i /opt/Xware/icon/before.ico exit 1; fi SER=`service thunder status |awk '{print $4}'` if [ "$SER" == "not" ];then notify-send "Thunder Service is Starting..." -i /opt/Xware/icon/before.ico ; gksudo -S -k /opt/Xware/mount&& MSG=`cat /tmp/._code_|grep ACTIVE|awk -F ' ''{print $6}'` echo$MSG #MSG=sudo service thunder start; if [ "$MSG" != "" ];then notify-send "Please login and Active Your Device then Restart. Active Code: $MSG" -i /opt/Xware/icon/code.ico notify-send "Please login and Active Your Device then Restart. Active Code: $MSG" -i /opt/Xware/icon/code.ico notify-send "Please login and Active Your Device then Restart. Active Code: $MSG" -i /opt/Xware/icon/code.ico notify-send "Please login and Active Your Device then Restart. Active Code: $MSG" -i /opt/Xware/icon/code.ico notify-send "Please login and Active Your Device then Restart. Active Code: $MSG" -i /opt/Xware/icon/code.ico notify-send "Please Restart After Activing." -i /opt/Xware/icon/restart.ico notify-send "Please Restart After Activing." -i /opt/Xware/icon/restart.ico fi SER=`service thunder status |awk '{print $4}'` if [ "$SER" == "running" ];then notify-send "Thunder Service has Started Successfully!" -i /opt/Xware/icon/after.ico; elif [ "$MSG" == "" ];then notify-send "Thunder Service Fail to Start : ETMDaemon is not running " -i /opt/Xware/icon/fail.ico ; fi fi if [ -e /usr/bin/google-chrome ];then if [ ! -d $HOME/.thunder-x/chrome ];then mkdir -p $HOME/.thunder-x/chrome; touch$HOME/.thunder-x/chrome/'First Run'; fi google-chrome --user-data-dir=$HOME/.thunder-x/chrome --window-size=1064,570 --window-position=100,100 --app=http://yuancheng.xunlei.com; elif [ -e /usr/bin/google-chrome-unstable ];then if [ ! -d $HOME/.thunder-x/chrome-un ];then mkdir -p $HOME/.thunder-x/chrome-un touch$HOME/.thunder-x/chrome-un/'First Run'; fi /usr/bin/google-chrome-unstable --user-data-dir=$HOME/.thunder-x/chrome-un --window-size=1064,570 --window-position=100,100 --app=http://yuancheng.xunlei.com elif [ -e /usr/bin/google-chrome-beta ];then if [ ! -d $HOME/.thunder-x/chrome-be ];then mkdir -p $HOME/.thunder-x/chrome-be touch$HOME/.thunder-x/chrome-be/'First Run'; fi /usr/bin/google-chrome-beta --user-data-dir=$HOME/.thunder-x/chrome-be --window-size=1064,570 --window-position=100,100 --app=http://yuancheng.xunlei.com elif [ -e /usr/bin/chromium-browser ];then if [ ! -d $HOME/.thunder-x/chromium ];then mkdir -p $HOME/.thunder-x/chromium touch$HOME/.thunder-x/chromium/'First Run'; fi /usr/bin/chromium-browser --user-data-dir=$HOME/.thunder-x/chromium-browser --window-size=1064,570 --window-position=100,100 --app=http://yuancheng.xunlei.com fi echo"Done"
Files: debian/* Copyright: 2014 ptbsare <ptbsare@gmail.com> License: GPL-2+ This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. . This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/> . On Debian systems, the complete text of the GNU General Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". # Please also look if there are files or directories which have a # different copyright/license attached and list them here.