aboutsummaryrefslogtreecommitdiff
path: root/unix/hlib/buglog.sh
blob: ac4e614e45542fa82c96b510e9fba6e16cee0a1b (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
140
#!/bin/bash
#
# BUGLOG -- Format, edit, and log a new bug to the system bugs file.
#
# Usage:
#
#	buglog [module]		log a new bug to the system bugsfile
#	buglog -e		edit the system bugfile (with locking)
#
# The system bugsfile is locked for exclusive access while a bug is being
# logged, or while the bugsfile is being edited.  Logging can be aborted either
# by typing <ctrl/c>, or by editing the editor with ":q!" (i.e., by exiting
# the editor without modifying the temporary file being edited).  Bugs are
# formatted and edited in a small temporary file in /tmp and are added at the
# end of the bugsfile only if the task is not aborted and the edit modifies
# the input bug template.  To go back and edit a previously logged bug use
# "buglog -e".
#
# Record Format:
#
#	NUMBER:		record number, decimal, sequential.
#	MODULE:		package.task or library.procedure or 'unknown'
#	SYSTEM:		versions of iraf in which bug was present
#	DATE:		date bug logged, unix format date string
#	FROM:		user login name
#	BUG:		description of the bug
#	STATUS:		'fixed in V2.X', 'unresolved', etc.
#
# New records are added to the tail of the bugfile.  Left justify field labels,
# indent text to the first tab stop, one blank line between bug entries.
# ----------------------------------------------------------------------------

iraf="`/bin/echo ${iraf}/ | tr -s '/'`"

bugfile="${iraf}local/bugs.log"
arcfile="/u1/ftp/iraf/v216/bugs.log"
tmpfile="/tmp/bug."
lokfile="/tmp/bug.lok"

number=1
module="$1"
from="`whoami`"
date="`date`"
system="V2.16"
irafmail="admin@iraf.net"
buglog="adass-iraf-buglog@iraf.noao.edu"

# Cleanup (vector here on interrupt).

cleanup() {
    if [ -e $lokfile ]; then
	rm -f $lokfile
    fi
    exit 0
}

# Get exclusive access to the bugfile.

if [ -e $lokfile ]; then
    find $bugfile -newer $lokfile -exec rm -f $lokfile \;
    while [ -e $lokfile ]; do
	/bin/echo "waiting for access to system bugfile"
	sleep 15
    done
fi

date > $lokfile
trap cleanup 2

# If we were called as "buglog -e", simply edit the locked bugfile.

if [ "$1" = "-e" ]; then
    vi + $bugfile
    cleanup
fi

# Increment the bug record number.

number="`grep '^NUMBER:' $bugfile | tail -1 | sed -e 's/^NUMBER:.//'`"
if [ "$number" = "" ]; then
    number=1
else
    number="`expr $number + 1`"
fi

# Get module name if not given on command line.

if [ "$module" = "" ]; then
    /bin/echo -n "Module: "
    read module
fi

# Format new bug entry in a temporary file and edit it.

SKP=0
tmpfile=$tmpfile$number
if [ -e $tmpfile ]; then
    /bin/echo "file $tmpfile already exists"
    rm -i $tmpfile
    if [ -e $tmpfile ]; then
	SKP=1
    fi
fi

if [ $SKP = 0 ]; then
    /bin/echo "NUMBER:	$number" >> $tmpfile
    /bin/echo "MODULE:	$module" >> $tmpfile
    /bin/echo "SYSTEM:	$system" >> $tmpfile
    /bin/echo "DATE:	$date"	>> $tmpfile
    /bin/echo "FROM:	$from"	>> $tmpfile
    /bin/echo ""		>> $tmpfile
    /bin/echo "BUG:	..."	>> $tmpfile
    /bin/echo ""			>> $tmpfile
    /bin/echo "STATUS:	..."	>> $tmpfile
fi

cp $tmpfile $tmpfile.ORIG
vi $tmpfile

# Add new bug entry to bugfile (exiting the editor without modifying the file
# causes the bug to be discarded).

cmp -s $tmpfile $tmpfile.ORIG
if [ $? = 0 ]; then
    /bin/echo "system bugfile not modified"
    rm -f $tmpfile $tmpfile.ORIG
else
    /bin/echo "" >> $bugfile;  cat $tmpfile >> $bugfile
    if [ -e $arcfile ]; then
        /bin/echo "" >> $arcfile;  cat $tmpfile >> $arcfile
    fi
    mail -s "buglog.$number"": module = $module, author = $from" $irafmail\
	< $tmpfile
#    mail -s "buglog.$number"": module = $module, author = $from" $buglog\
#	< $tmpfile
    rm -f $tmpfile $tmpfile.ORIG
fi

cleanup