4 tmp
=${DVDRIP_TMPDIR-${HOME?}/tmp
/dvdrip
}
5 archive
=${DVDRIP_ARCHIVE-jem.distorted.org.uk:/mnt/dvd/archive}
6 kill=nil listen
=nil verbose
=nil bogus
=nil opts
=; unset dir sub n label
12 while getopts "ha:klv" opt
; do
17 l
) listen
=t
; opts
=${opts}l
;;
18 v
) verbose
=t
; opts
=${opts}v
;;
22 shift $
(( $OPTIND - 1 ))
27 case $bogus in t
) usage
>&2; exit 2 ;; esac
28 case $verbose in t
) set -x
;; esac
32 echo "$(tput bold; tput setaf $colour)$message$(tput sgr0; tput op)"
34 fail
() { notify
1 "!!! $*"; exit 2; }
35 warn
() { notify
5 "??? $*"; }
36 info
() { notify
6 "--- $*"; }
39 set +e
; nice
"$@"; rc
=$?
; set -e
41 run
() { run_setrc
"$@"; case $rc in 0) ;; *) fail
"$1: exit $rc" ;; esac; }
44 *:*) archhost
=${archive%%:*} archpath
=${archive#*:} ;;
45 *) unset archhost
; archpath
=$archive ;;
54 qq
="${qq:+$qq }'${a//\'/"'\\''"}'" #" # emacs is confused
56 "$op" ssh "$archhost" "$qq"
63 archrun
() { archdo run
"$@"; }
66 info
"checking for pending uploads"
70 if [ -f
"$i/dest" ]; then
71 read dest
<"$i/dest"; any
=t
72 mv "$i/dest" "$i/dest.seen"
73 (info
"copy $i/iso -> $dest"
75 */*) dir
=${dest%/*} ;;
78 archrun mkdir
-p
"$archpath${dir:+/$dir}"
79 run rsync
-svP
--inplace
--bwlimit
728k
"$i/iso" "$archive/$dest"
83 case $any in nil
) break ;; esac
91 if [ -f
"$tmp/upload.pid" ]; then
92 daemon
=$
(cat "$tmp/upload.pid")
95 *) if kill -$sig $daemon >/dev
/null
2>&1; then return 0; fi ;;
106 *) kill $victim >/dev
/null
2>&1 ||
: ;;
110 case $kill,$listen in
112 fail
"inconsistent options \`-k' and \`-l'"
115 if ! try_kick_daemon TERM
; then fail
"failed to kill listener"; fi
118 if try_kick_daemon
0; then fail
"daemon already running (pid $daemon)"; fi
119 trap 'try_kill $sleepy; rm -f "$tmp/upload.pid"' EXIT
120 trap 'info "quitting on user request"; exit 0' INT TERM
121 trap 'try_kill $sleepy' HUP
122 echo $$
>"$tmp/upload.pid.new"
123 mv "$tmp/upload.pid.new" "$tmp/upload.pid"
125 sleep 3600& sleepy
=$
!
127 wait $sleepy ||
:; sleepy
=nil
131 if ! try_kick_daemon HUP
; then check
; fi