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