Merge lp://staging/~smoser/runurl/runurl.smoser into lp://staging/runurl

Proposed by Scott Moser
Status: Merged
Approved by: Eric Hammond
Approved revision: 13
Merged at revision: 13
Proposed branch: lp://staging/~smoser/runurl/runurl.smoser
Merge into: lp://staging/runurl
Diff against target: 103 lines (+36/-41)
1 file modified
runurl (+36/-41)
To merge this branch: bzr merge lp://staging/~smoser/runurl/runurl.smoser
Reviewer Review Type Date Requested Status
Eric Hammond Approve
Review via email: mp+18097@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

Here are some cleanups (well, i think so) for runurl.

Revision history for this message
Eric Hammond (esh) wrote :

Looks good and continues to work based on my testing.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'runurl'
--- runurl 2009-10-10 06:41:32 +0000
+++ runurl 2010-01-26 19:15:22 +0000
@@ -1,64 +1,59 @@
1#!/bin/bash1#!/bin/sh
2#2#
3# runurl - Download a URL and run as a program, passing in arguments3# runurl - Download a URL and run as a program, passing in arguments
4#4#
5# Copyright (C) 2009 Eric Hammond <ehammond@thinksome.com>5# Copyright (C) 2009 Eric Hammond <ehammond@thinksome.com>
6#6#
77
8error() { echo "$@" 1>&2; }
9fail() { [ $# -eq 0 ] || error "${BNAME}:" "$1"; exit ${2:-1}; }
10debug() { [ "$DEBUG" = "0" ] || error "${BNAME}:" "$@"; }
11cleanup() { [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"; }
12
13DEBUG="0"
14TEMP_D=""
15BNAME=${0##*/}
16
8while [ $# -gt 0 ]; do17while [ $# -gt 0 ]; do
9 case $1 in18 case $1 in
10 -\?|--help) help=1; shift 1 ;;19 -\?|--help) pod2text "${0}"; exit 0;;
11 -d|--debug) debug=1; shift 1 ;;20 -d|--debug) DEBUG=1; shift 1 ;;
12 -*) echo "$0: Unrecognized option: $1 (try --help)" >&2; exit 1 ;;21 -*) fail "Unrecognized option: $1 (try --help)";;
13 *) url=$1; shift 1; break ;;22 *) url="$1"; shift 1; break ;;
14 esac23 esac
15done24done
1625
17if [ "$help" ]; then26[ -n "$url" ] || fail "Missing URL specification (try --help)"
18 pod2text $027
19 exit 128trap cleanup 0
20fi29
2130TEMP_D=$(mktemp -d ${TEMPDIR:-/tmp}/${BNAME}.XXXXXX) &&
22if [ "$url" = "" ]; then31 runfile="${TEMP_D}/runfile" && wgetfile="${TEMP_D}/wget.out" ||
23 echo "$0: Missing URL specification (try --help)"32 fail "failed to make tempdir"
24 exit 1;33
25fi34debug "downloading $url"
2635
27runfile=$(mktemp /tmp/runurl.XXXX)36wget \
28chmod 700 $runfile37 --retry-connrefused \
29wgetfile="$runfile.wget"38 --tries=20 \
3039 "--output-document=$runfile" \
31if [ $debug ]; then40 "--output-file=$wgetfile" \
32 echo "runurl: downloading $url" >&2
33fi
34
35wget \
36 --retry-connrefused \
37 --tries=20 \
38 --output-document=$runfile \
39 --output-file=$wgetfile \
40 "$url"41 "$url"
4142
42wgetstatus=$?43wgetstatus=$?
43if [ $wgetstatus != 0 ]; then44if [ $wgetstatus != 0 ]; then
44 cat $wgetfile >&245 cat $wgetfile >&2
45 echo "runurl: wget failed: $wgetstatus" >&246 fail "wget failed: $wgetstatus" "${wgetstatus}"
46 rm $runfile $wgetfile47fi
47 exit $wgetstatus48
48fi49chmod 700 "${runfile}" || fail "failed to change perms of ${runfile}"
4950
50if [ $debug ]; then51debug "running"
51 echo "runurl: running" >&2
52fi
53
54$runfile "$@"52$runfile "$@"
5553
56exitstatus=$?54exitstatus=$?
57rm $runfile $wgetfile
5855
59if [ $debug ]; then56debug "exit status $exitstatus"
60 echo "runurl: exit status: $exitstatus" >&2
61fi
6257
63exit $exitstatus58exit $exitstatus
6459

Subscribers

People subscribed via source and target branches

to all changes: