diff options
Diffstat (limited to 'src/webhttrack')
-rwxr-xr-x | src/webhttrack | 79 |
1 files changed, 7 insertions, 72 deletions
diff --git a/src/webhttrack b/src/webhttrack index e41991a..879a5d8 100755 --- a/src/webhttrack +++ b/src/webhttrack @@ -29,81 +29,15 @@ echo "$0($$): $@" >&2 return 0 } -function mozillabrowser { -# returns 0, if the browser is mozilla type -echo "$1" | grep -q "iceape" -[ $? -eq 0 ] && return 0 -echo "$1" | grep -q "mozilla" -[ $? -eq 0 ] && return 0 -echo "$1" | grep -q "netscape" -[ $? -eq 0 ] && return 0 -echo "$1" | grep -q "firebird" -[ $? -eq 0 ] && return 0 -echo "$1" | grep -q "firefox" -[ $? -eq 0 ] && return 0 -echo "$1" | grep -q "iceweasel" -[ $? -eq 0 ] && return 0 -echo "$1" | grep -q "abrowser" -[ $? -eq 0 ] && return 0 -echo "$1" | grep -q "icecat" -[ $? -eq 0 ] && return 0 -return 1; -} -function mozillaloaded { -user_name=`logname 2>/dev/null` -if ! test -n "${user_name}"; then -user_name=`id -un` -fi -if test -n "${user_name}"; then -ps -e -U "$user_name" | grep -E "(iceape|mozilla|netscape|firebird|firefox)" | grep -qv "grep -E" -else -false -fi -} - function launch_browser { log "launching $1" -start_t=`date +%s` browser=$1 url=$2 -moz= -if mozillaloaded; then -moz=1 -fi -# launch any browser -# if it is a mozilla like browser, check if the browser is running and use -# -remote if needed. Change the URL into openURL($url) too. -# (thanks to Torsten Werner for the patch) -# see http://www.mozilla.org/unix/remote.html -# 04/2006: openurl() fix from Samuel Suther -if mozillabrowser ${browser}; then - if ! ${browser} -remote "openurl(${url})"; then - log "spawning browser.." - ${browser} "${url}" - fi -else - log "spawning regular browser.." - ${browser} "${url}" -fi -# this is a real pain in the neck: browser can hiddenly use the -remote feature of +log "spawning browser.." +${browser} "${url}" +# note: browser can hiddenly use the -remote feature of # mozilla and therefore return immediately -# this loop is the only reliable solution AFAIK -end_t=`date +%s` -if test -n "$start_t" -a -n "$end_t"; then - int_t=$[$end_t-$start_t] -else - int_t=0 -fi -if test -n "${int_t}" -a "${int_t}" -lt 60; then - if test -n "$moz"; then - log "waiting for browser to terminate.." - while mozillaloaded; do - sleep 3 - done - log "browser seems to have been closed.." - fi -fi -log "browser exited" +log "browser (or helper) exited" } # First ensure that we can launch the server @@ -164,7 +98,7 @@ fi # Create a temporary filename TMPSRVFILE="$(mktemp ${TMPDIR:-/tmp}/.webhttrack.XXXXXXXX)" || ! log "cound not create the temporary file ${TMPSRVFILE}" || exit 1 # Launch htsserver binary and setup the server -(${BINPATH}/htsserver "${DISTPATH}/" path "${HOME}/websites" lang "${LANGN}" $@; echo SRVURL=error) > ${TMPSRVFILE}& +(${BINPATH}/htsserver "${DISTPATH}/" --ppid "$$" path "${HOME}/websites" lang "${LANGN}" $@; echo SRVURL=error) > ${TMPSRVFILE}& # Find the generated SRVURL SRVURL= MAXCOUNT=60 @@ -180,7 +114,8 @@ done # Cleanup function function cleanup { test -n "$1" && log "nasty signal caught, cleaning up.." -test -f ${TMPSRVFILE} && SRVPID=`grep -E PID= ${TMPSRVFILE} | cut -f2- -d=` +# Do not kill if browser exited (chrome bug issue) ; server will die itself +test -n "$1" && test -f ${TMPSRVFILE} && SRVPID=`grep -E PID= ${TMPSRVFILE} | cut -f2- -d=` test -n "${SRVPID}" && kill -9 ${SRVPID} test -f ${TMPSRVFILE} && rm ${TMPSRVFILE} test -n "$1" && log "..done" |