1#!/bin/bash
2# Run with no arguments from any directory, with no special setup required.
3
4# Abort if any command returns an error exit status, or if an undefined
5# variable is used.
6set -e
7set -u
8
9base_dir=$(realpath $(dirname $0))
10
11# Extract the latest version from the web page.
12new_version=$(wget -O - --no-verbose -q http://zlib.net/ | \
13              grep 'http://zlib.net/zlib-[0-9].*.tar.gz' | \
14              sed 's/.*zlib-\(.*\)\.tar\.gz.*/\1/')
15tgz_file="zlib-$new_version.tar.gz"
16
17echo "Upgrading zlib to version $new_version..."
18echo "-------------------------------------------------------------------"
19
20echo "Downloading $tgz_file..."
21wget -O /tmp/$tgz_file --no-verbose "http://zlib.net/$tgz_file"
22
23echo "Cleaning out old version..."
24src_dir=$base_dir/src
25rm -rf $src_dir
26
27echo "Unpacking new version..."
28cd $base_dir
29tar zxf /tmp/$tgz_file
30mv zlib-$new_version src
31
32echo "Configuring new version..."
33cd src
34./configure
35rm Makefile configure.log
36cd ..
37
38echo "Fixing NOTICE file..."
39grep -A21 'Copyright notice:' src/README | tail -20 > NOTICE
40
41md5_sum=$(md5sum /tmp/$tgz_file)
42echo "MD5: $md5_sum"
43