From Xiaoguang Liu
[obnox/wireshark/wip.git] / tools / win32-setup.sh
1 #!/bin/sh
2
3 # This MUST be in the form
4 #   http://anonsvn.wireshark.org/wireshark-win32-libs/tags/<date>/packages
5 # in order to provide backward compatibility with older trees (e.g. a
6 # previous release or an older SVN checkout).
7 DOWNLOAD_PREFIX="http://anonsvn.wireshark.org/wireshark-win32-libs/tags/2006-11-26/packages"
8
9 err_exit () {
10         echo ""
11         echo "ERROR: $1"
12         echo ""
13         exit 1
14 }
15
16 usage () {
17         echo "Usage:"
18         echo "  $0 --appverify <appname> [<appname>] ..."
19         echo "  $0 --download <destination> <subdirectory> <package>"
20         echo ""
21         exit 1
22 }
23
24
25 case "$1" in
26 --appverify)
27         shift
28         if [ -z "$*" ] ; then
29                 usage
30         fi
31         echo "Checking for required applications:"
32         which which > /dev/null 2>&1 || \
33                 err_exit "Can't find 'which'.  Unable to proceed."
34         for APP in $* ; do
35                 APP_PATH=`cygpath --unix $APP`
36                 if [ -x "$APP_PATH" -a ! -d "$APP_PATH" ] ; then
37                         APP_LOC="$APP_PATH"
38                 else
39                         APP_LOC=`which $APP_PATH 2> /dev/null`
40                 fi
41                 if [ "$APP_LOC" = "" ] ; then
42                         err_exit "Can't find $APP. This is probably an optional cygwin package not yet installed. Try to install it using cygwin's setup.exe!"
43                 fi
44                 echo "  $APP: $APP_LOC $res"
45         done
46         ;;
47 --download)
48         if [ -z "$2" -o -z "$3" -o -z "$4" ] ; then
49                 usage
50         fi
51         DEST_PATH=`cygpath --dos "$2"`
52         DEST_SUBDIR=$3
53         PACKAGE_PATH=$4
54         PACKAGE=`basename "$PACKAGE_PATH"`
55         echo "****** $PACKAGE ******"
56         if [ -z "$http_proxy" -a -z "$HTTP_PROXY" ] ; then
57                 echo "No HTTP proxy specified (http_proxy and HTTP_PROXY are empty)."
58                 # a proxy might also be specified using .wgetrc, so don't switch off the proxy
59                 #use_proxy="-Y off"
60         else
61                 use_proxy="-Y on"
62                 if [ -z "$http_proxy" ] ; then
63                         echo "HTTP proxy ($HTTP_PROXY) has been specified and will be used."
64                 else
65                         echo "HTTP proxy ($http_proxy) has been specified and will be used."
66                 fi
67         fi
68         echo "Downloading $4 into $DEST_PATH, installing into $3"
69         if [ ! -d "$DEST_PATH/$DEST_SUBDIR" ] ; then
70                 mkdir -p "$DEST_PATH/$DEST_SUBDIR" || \
71                         err_exit "Can't create $DEST_PATH/$DEST_SUBDIR"
72         fi
73         cd "$DEST_PATH" || err_exit "Can't find $DEST_PATH"
74         wget $use_proxy -nc "$DOWNLOAD_PREFIX/$PACKAGE_PATH" || \
75                 err_exit "Can't download $DOWNLOAD_PREFIX/$PACKAGE_PATH"
76         cd "$DEST_SUBDIR" || err_exit "Can't find $DEST_SUBDIR"
77         echo "Extracting $DEST_PATH/$PACKAGE into $DEST_PATH/$DEST_SUBDIR"
78         unzip -nq "$DEST_PATH/$PACKAGE" ||
79                 err_exit "Couldn't unpack $DEST_PATH/$PACKAGE"
80         echo "Verifying that the DLLs in $DEST_PATH/$DEST_SUBDIR are executable."
81         for i in `/usr/bin/find $DEST_PATH/$DEST_SUBDIR -name \*\.dll` ; do
82                 if [ ! -x "$i" ] ; then
83                         echo "Changing file permissions (add executable bit) to:"
84                         echo "$i"
85                         chmod a+x "$i"
86                 fi
87         done
88         ;;
89 *)
90         usage
91         ;;
92 esac
93
94 exit 0