summaryrefslogtreecommitdiff
path: root/scripts/ac_check_iraf_build
blob: aff6b92f1490e68a3d7c184b5c7e81894d2accd9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh

# Attempt to determine the success or failure of an IRAF package build (since
# mkpkg does not report a useful exit status) by checking the log for any
# unexpected patterns (assumed to be errors) and confirming whether all the
# binaries listed in an optional package manifest have been created.
#
# Status: 0 success
#         1 invocation error
#         2 probable error messages in log
#         4 build incomplete with respect to manifest
#         6 both of the above

usage="Usage: ac_check_iraf_build PATH"

# Source some common IRAF package defs (log_name etc.) from the same dir:
. `dirname "$0"`/ac_iraf_defs

# Parse argument(s):
st=1
unset pkg_path
while [ "$1" != "" ]; do
    case "$1" in
        -h)
            st=0; pkg_path=""
            break
            ;;
        -*)
            st=1
            ;;
        *)
            if [ "$pkg_path" ]; then
                st=1
            else
		st=0; pkg_path=$1
            fi
	    ;;
    esac
    shift
done

if [ $st != 0 -o -z "$pkg_path" ]; then
    echo "$usage" >&2
    exit $st
fi

# Add a trailing slash if needed (as per IRAF custom):
pkg_path=`echo "$pkg_path" | sed -e 's|/*$|/|'`

# Make sure the specified path is readable:
if [ ! -d "$pkg_path" -o ! -r "$pkg_path" ]; then
    echo "ERROR: cannot read dir: $pkg_path" >&2
    exit 1
fi

# Make sure we can find a package build log and a package-specific list of
# patterns to be ignored within it:
bld_log="${pkg_path}${log_name}"
if [ ! -r "$bld_log" ]; then
    echo "ERROR: cannot read $bld_log" >&2
    st=1
fi
pkg_patterns="${pkg_path}${pkg_patterns}"
if [ ! -r "$pkg_patterns" ]; then
    echo "ERROR: cannot read $pkg_patterns" >&2
    st=1
fi

# Check for an optional manifest:
manifest="${pkg_path}${pkg_manifest}"
if [ ! -r "$manifest" ]; then
    echo "Warning: no manifest in $pkg_path" >&2
    manifest=""
fi

# Exit due to missing files above:
[ $st != 0 ] && exit 1

# The environment must already be configured for running/building IRAF:
if [ -z "$iraf" ]; then
    echo "ERROR: must configure \$iraf first (eg. AstroConda"\
	 "\"source activate iraf\")" >&2
    exit 1
fi

# Add a trailing slash if needed:
iraf=`echo $iraf | sed -e 's|/*$|/|'`

# Check for master list of expected IRAF build log patterns (used in addition
# to the package-specific list):
iraf_patterns="$iraf/ur/mkpkg_patterns"
if [ ! -r "$iraf_patterns" ]; then
    echo "ERROR: missing $iraf_patterns" >&2
    exit 1
fi

# Look for unexpected string patterns in the log file (NB. grep returns 1 when
# all lines are successfully filtered out):
err_log="${pkg_path}${err_log_name}"
if tr -d '\015' < "$bld_log" | egrep -v -f "$iraf_patterns" -f "$pkg_patterns" > "$err_log"; then
    st=2
    echo "ERROR: unexpected build messages in $err_log" >&2
else
    rm -f "$err_log"
fi

# Check the existence of each file listed in the manifest. Currently there is
# no support for architecture-specific manifests (as we had in Ureka), since we
# haven't actually used any to date.
if [ "$manifest" ]; then

    nmissing=0
    lmissing=""

    exec < $manifest
    while read line
    do	
        case "$line" in
            '#'*|'')
                continue
                ;;
            *)
                if [ ! -r "${pkg_path}${line}" ]; then
                    nmissing=$((nmissing+1))
                    lmissing="${lmissing}  ${line}"$'\n'
                fi
                ;;
        esac
    done

    if [ $nmissing -gt 0 ]; then
       echo "ERROR: $nmissing expected file(s) missing after installation:" >& 2
       echo "$lmissing" >& 2
       st=$((st+4))
    fi
fi

exit $st