Allow for true error reporing.
[metze/wireshark/wip.git] / tools / win-setup.sh
1 #!/bin/bash
2 (set -o igncr) 2>/dev/null && set -o igncr;  # hack to force this file to be processed by cygwin bash with -o igncr
3                                              # needed when this file is exec'd from win32-setup.sh & win64-setup.sh
4 #
5 # $Id$
6
7 err_exit () {
8         echo ""
9         echo "ERROR: $1"
10         shift
11         for str in "$@" ; do
12                 echo "$str"
13         done
14         echo ""
15         exit 1
16 }
17
18 if [ -z "$DOWNLOAD_TAG" ]; then
19         err_exit "DOWNLOAD_TAG not defined (internal error)"
20 fi
21
22 if [ -z "$WIRESHARK_TARGET_PLATFORM" ]; then
23         err_exit "WIRESHARK_TARGET_PLATFORM not defined (internal error)"
24 fi
25
26 # This MUST be in the form
27 #   http://anonsvn.wireshark.org/wireshark-win32-libs/tags/<date>/packages
28 # or
29 #   http://anonsvn.wireshark.org/wireshark-win64-libs/tags/<date>/packages
30 # in order to provide backward compatibility with older trees (e.g. a
31 # previous release or an older SVN checkout).
32 # Save previous tag.
33
34 # Set DOWNLOAD_PREFIX to /packages to test uploads before creating the tag.
35 #DOWNLOAD_PREFIX="http://anonsvn.wireshark.org/wireshark-$WIRESHARK_TARGET_PLATFORM-libs/trunk/packages/"
36 DOWNLOAD_PREFIX="http://anonsvn.wireshark.org/wireshark-$WIRESHARK_TARGET_PLATFORM-libs/tags/$DOWNLOAD_TAG/packages/"
37
38 TAG_FILE="current_tag.txt"
39
40 usage () {
41         echo "Usage:"
42         echo "  $0 --appverify <appname> [<appname>] ..."
43         echo "  $0 --libverify <destination> <subdirectory> <package>"
44         echo "  $0 --download  <destination> <subdirectory> <package>"
45         echo "  $0 --settag  <destination>"
46         echo "  $0 --checktag  <destination>"
47         echo ""
48         exit 1
49 }
50
51 # Try to find our proxy settings, and set http_proxy/use_proxy accordingly.
52 find_proxy() {
53         # Someone went to the trouble of configuring wget.
54         if grep "^use_proxy *= *on" $HOME/.wgetrc > /dev/null 2>&1 ; then
55                 return
56         fi
57
58         # ...and wget can't fetch two registry keys because...?
59         proxy_enabled=`regtool get /HKCU/Software/Microsoft/Windows/CurrentVersion/Internet\ Settings/ProxyEnable 2>/dev/null | tr -d '\012'`
60         #
61         # Bash's test command appears not to use short-circuit evaluation,
62         # so
63         #
64         #       -n "$proxy_enabled" -a "$proxy_enabled" -ne 0
65         #
66         # causes a complaint if "$proxy_enabled" is an empty string -
67         # the first test fails, but the second test is done anyway,
68         # and generates a complaint about the LHS of -ne not being
69         # numeric.  Therefore, we do the tests separately.
70         #
71         if [ -n "$proxy_enabled" ] ; then
72                 if [ "$proxy_enabled" -ne 0 ] ; then
73                         export http_proxy=`regtool get /HKCU/Software/Microsoft/Windows/CurrentVersion/Internet\ Settings/ProxyServer 2>/dev/null`
74                         echo "Using Internet Explorer proxy settings."
75                 fi
76         fi
77
78         if [ -z "$http_proxy" -a -z "$HTTP_PROXY" ] ; then
79                 echo "No HTTP proxy specified (http_proxy and HTTP_PROXY are empty)."
80                 # a proxy might also be specified using .wgetrc, so don't switch off the proxy
81                 #use_proxy="-Y off"
82                 return
83         fi
84
85         # We found a proxy somewhere
86         use_proxy="-Y on"
87         if [ -z "$http_proxy" ] ; then
88                 echo "HTTP proxy ($HTTP_PROXY) has been specified and will be used."
89                 export http_proxy=$HTTP_PROXY
90         else
91                 echo "HTTP proxy ($http_proxy) has been specified and will be used."
92         fi
93 }
94
95
96
97 case "$1" in
98 --appverify)
99         shift
100
101         if [ -z "$*" ] ; then
102                 usage
103         fi
104
105         echo "Checking for required applications:"
106         which which > /dev/null 2>&1 || \
107                 err_exit "Can't find 'which'.  Unable to proceed."
108
109         MISSING_APPS=
110         PATH_RE=""
111         for APP in $* ; do
112
113                 case "$APP" in
114                         --windowsonly)
115                                 PATH_RE="^/cygdrive/.*/"
116                                 continue
117                                 ;;
118                         --cygwinonly)
119                                 PATH_RE="^/usr/.*/"
120                                 continue
121                                 ;;
122                 esac
123
124                 APP_PATH=`cygpath --unix "$APP"`
125                 if [ -x "$APP_PATH" -a ! -d "$APP_PATH" ] ; then
126                         APP_LOC="$APP_PATH"
127                 else
128                         APP_LOC=`which $APP_PATH 2> /dev/null`
129                 fi
130                 echo "$APP_LOC" | grep "$PATH_RE" > /dev/null 2>&1
131                 IN_PATH=$?
132                 if [ "$APP_LOC" = "" -o $IN_PATH -ne 0 ] ; then
133                         MISSING_APPS="$MISSING_APPS $APP"
134                 else
135                         echo "  $APP: $APP_LOC $res"
136                 fi
137
138                 PATH_RE=""
139         done
140
141         if [ -n "$MISSING_APPS" ]; then
142                 echo
143                 echo "Can't find: $MISSING_APPS"
144                 err_exit "These application(s) are either not installed or simply can't be found in the current PATH: $PATH." \
145                 "" "For additional help, please visit:" "    http://www.wireshark.org/docs/wsdg_html_chunked/ChSetupWin32.html"
146         fi
147         ;;
148 --libverify)
149         if [ -z "$2" -o -z "$3" -o -z "$4" ] ; then
150                 usage
151         fi
152         DEST_PATH=`cygpath "$2"`
153         PACKAGE_PATH=$4
154         PACKAGE=`basename "$PACKAGE_PATH"`
155         if [ ! -e $DEST_PATH/$PACKAGE ] ; then
156                 err_exit "Package $PACKAGE is needed but is apparently not downloaded; 'nmake -f ... setup' required ?"
157         fi
158         ;;
159 --download)
160         if [ -z "$2" -o -z "$3" -o -z "$4" ] ; then
161                 usage
162         fi
163         DEST_PATH=`cygpath "$2"`
164         DEST_SUBDIR=$3
165         PACKAGE_PATH=$4
166         PACKAGE=`basename "$PACKAGE_PATH"`
167         echo ""
168         echo "****** $PACKAGE ******"
169         find_proxy
170         echo "Downloading $4 into $DEST_PATH, installing into $3"
171         if [ ! -d "$DEST_PATH/$DEST_SUBDIR" ] ; then
172                 mkdir -p "$DEST_PATH/$DEST_SUBDIR" || \
173                         err_exit "Can't create $DEST_PATH/$DEST_SUBDIR"
174         fi
175         cd "$DEST_PATH" || err_exit "Can't find $DEST_PATH"
176         wget $use_proxy -nc "$DOWNLOAD_PREFIX/$PACKAGE_PATH" || \
177                 err_exit "Can't download $DOWNLOAD_PREFIX/$PACKAGE_PATH"
178         cd "$DEST_SUBDIR" || err_exit "Can't find $DEST_SUBDIR"
179         echo "Extracting $DEST_PATH/$PACKAGE into $DEST_PATH/$DEST_SUBDIR"
180         unzip -oq "$DEST_PATH/$PACKAGE" ||
181                 err_exit "Couldn't unpack $DEST_PATH/$PACKAGE"
182         echo "Verifying that the DLLs and EXEs in $DEST_SUBDIR are executable."
183         # XX: Note that find will check *all* dlls/exes in DEST_SUBDIR and below
184         #     which may be more than those just unzipped depending upon DEST_SUBDIR.
185         #     This may cause extra repeated checks but will do no harm.
186         for i in `/usr/bin/find . \( -name '*\.dll' -o -name '*\.exe' \)` ; do
187                 if [ ! -x "$i" ] ; then
188                         echo "Changing file permissions (add executable bit) to:"
189                         echo "$i"
190                         chmod a+x "$i"
191                 fi
192         done
193         ;;
194 --settag)
195         if [ -z "$2" ] ; then
196                 usage
197         fi
198         DEST_PATH=`cygpath "$2"`
199         echo "$DOWNLOAD_TAG" > $DEST_PATH/$TAG_FILE
200         ;;
201 --checktag)
202         if [ -z "$2" ] ; then
203                 usage
204         fi
205         DEST_PATH=`cygpath "$2"`
206         WIN_PATH=`cygpath --windows "$2"`
207         LAST_TAG=`cat $DEST_PATH/$TAG_FILE 2> /dev/null`
208         if [ "$DOWNLOAD_TAG" != "$LAST_TAG" ] ; then
209                 if [ -z "$LAST_TAG" ] ; then
210                         LAST_TAG="(unknown)"
211                 fi
212                 err_exit \
213                         "The contents of $WIN_PATH\\$TAG_FILE is $LAST_TAG." \
214                         "It should be $DOWNLOAD_TAG."
215         fi
216         ;;
217 *)
218         usage
219         ;;
220 esac
221
222 exit 0