8dde6c57b4ae90fc882c994b3a9cc8149d1ae82b
[xfstests-dev.git] / new
1 #! /bin/bash
2 #
3 #-----------------------------------------------------------------------
4 #  Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 #
19 #-----------------------------------------------------------------------
20 #
21 # Make a new test
22 #
23
24 # generic initialization
25 iam=new
26 . ./common.rc
27
28 trap "rm -f /tmp/$$.; exit" 0 1 2 3 15
29
30 _cleanup()
31 {
32     :
33 }
34
35 if [ ! -f group ]
36 then
37     echo "Creating the group index ..."
38     cat <<'End-of-File' >group
39 # QA groups control
40 #
41 # define groups and default group owners
42 # do not start group name with a digit
43 #
44
45 # catch-all
46 #
47 other           some-user-login
48
49 # test-group association ... one line per test
50 #
51 End-of-File
52 fi
53
54 if [ ! -w group ]
55 then
56     chmod u+w group
57     echo "Warning: making the index file \"group\" writeable"
58 fi
59
60 if make
61 then
62     :
63 else
64     echo "Warning: make failed -- some tests may be missing"
65 fi
66
67 last=`grep '^[0-9][0-9]* ' group | sort | tail -1 | sed -e 's/[         ].*//'`
68 # get rid of leading 0s as can be interpreted as octal
69 last=`echo $last | sed 's/^0*//'`
70 id=`$AWK_PROG </dev/null 'BEGIN{printf "%03d\n",'$last'+1}'`
71 echo "Next test is $id"
72
73 if [ -f $id ]
74 then
75     echo "Error: test $id already exists!"
76     _cleanup
77     exit 1
78 fi
79
80 echo -n "Creating skeletal script for you to edit ..."
81
82 year=`date +%Y`
83
84 cat <<End-of-File >$id
85 #! /bin/bash
86 # FS QA Test No. $id
87 #
88 # what am I here for?
89 #
90 #-----------------------------------------------------------------------
91 # Copyright (c) $year YOUR NAME HERE.  All Rights Reserved.
92 #
93 # This program is free software; you can redistribute it and/or
94 # modify it under the terms of the GNU General Public License as
95 # published by the Free Software Foundation.
96 #
97 # This program is distributed in the hope that it would be useful,
98 # but WITHOUT ANY WARRANTY; without even the implied warranty of
99 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
100 # GNU General Public License for more details.
101 #
102 # You should have received a copy of the GNU General Public License
103 # along with this program; if not, write the Free Software Foundation,
104 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
105 #-----------------------------------------------------------------------
106 #
107 # creator
108 seq=\`basename \$0\`
109 echo "QA output created by \$seq"
110
111 here=\`pwd\`
112 tmp=/tmp/\$\$
113 status=1        # failure is the default!
114 trap "_cleanup; exit \\\$status" 0 1 2 3 15
115
116 _cleanup()
117 {
118     cd /
119     rm -f \$tmp.*
120 }
121
122 # get standard environment, filters and checks
123 . ./common.rc
124 . ./common.filter
125
126 # real QA test starts here
127
128 # Modify as appropriate.
129 _supported_fs generic
130 _supported_os IRIX Linux
131
132 # if error
133 exit
134
135 # optional stuff if your test has verbose output to help resolve problems
136 #echo
137 #echo "If failure, check \$seq.full (this) and \$seq.full.ok (reference)"
138
139 # success, all done
140 status=0
141 exit
142 End-of-File
143
144 sleep 2         # latency to read messages to this point
145 echo ""
146
147 chmod 755 $id
148 ${EDITOR-vi} $id
149
150 if [ $# -eq 0 ]
151 then
152     while true
153     do
154         echo -n "Add to group(s) [other] (? for list): "
155         read ans
156         [ -z "$ans" ] && ans=other
157         if [ "X$ans" = "X?" ]
158         then
159             $AWK_PROG <group '
160 BEGIN           { text = "# ???" }
161 /^[a-z]/        { printf "%-16.16s %s\n",$1,text; text = "# ???"; next }
162 NF < 2          { next }
163                 { text = $0 }' \
164             | sort
165         else
166             break
167         fi
168     done
169 else
170     # expert mode, groups are on the command line
171     #
172     for g in $*
173     do
174         if grep "^$g[   ]" group >/dev/null
175         then
176             :
177         else
178             echo "Warning: group \"$g\" not defined in ./group"
179         fi
180     done
181     ans="$*"
182 fi
183
184 echo -n "Adding $id to group index ..."
185 echo "$id $ans" >>group
186 echo " done."
187
188 exit 0