File: gopherindex.raw

package info (click to toggle)
gopher 2.3-2
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 2,364 kB
  • ctags: 2,030
  • sloc: ansic: 22,451; perl: 1,950; sh: 1,510; makefile: 397; asm: 1
file content (230 lines) | stat: -rw-r--r-- 3,865 bytes parent folder | download | duplicates (3)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/sh

export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)

#
#Set up variables
#
USAGE="$0: usage: $0 -wais waisargs -gd gopher-datadir -t next|wais -N 'long link name' datadir"
gopherhome=GHOME
indextype=ITYPE
verbose=0
indexname="Index of files in this directory"
waisargs=""
useinplaceindex=0
Indexdir="moo"
PATH=${PATH}:/usr/local/bin

# Parse args.
while true ; do
    case "$1" in
        -t )
	shift
	if [ ! ${1-""} ] ; then	
		echo $USAGE 1>&2
		exit 1
	fi
       	indextype="$1"
        shift
        ;;

	-a )
	useinplaceindex=1
	shift
	;;

	-N )
	shift
	if [ ! "${1}" ] ; then	
		echo $USAGE 1>&2
		exit 1
	fi
       	indexname="$1"
	shift
	;;

	-i )
	shift
	if [ ! "${1}" ] ; then	
		echo $USAGE 1>&2
		exit 1
	fi
       	Indexdir="$1"
	shift
	;;

	-wais )
	shift
	if [ ! "${1}" ] ; then	
		echo $USAGE 1>&2
		exit 1
	fi
	waisargs="$1"
	shift
	;;

	-gd )
	shift
	if [ ! "${1}" ] ; then	
		echo $USAGE 1>&2
		exit 1
	fi
	gopherhome="$1"
	shift
	;;

	-v )
	verbose=1
	shift
	;;

	-D )
	set -x
	shift
	;;
        -* )
        echo "$USAGE" 1>&2
        exit 1
        ;;
        * )
        break
        ;;
    esac
done

#
# Now we have the directory
#

#
# Find out if it's a relative path
#

if (cd /;cd "$1") ; then
	Datadir="$1"
else
	Datadir="$PWD/$1"
fi


#
# Set the indexdir if it isn't set
#

if [ $Indexdir = "moo" ]; then
	Indexdir=$Datadir
fi


#
# Find the path relative to the gopher-root (for Path= line)
#

Pathdir=`echo "$Indexdir" | sed "s.$gopherhome.."`

if test "$verbose" = "1" ; then
	echo "Gopher Home directory is $gopherhome"
	echo "Indexes are hidden in $Indexdir"
	echo "Indexing files in $Datadir"
fi


################################################################

nextindex() {	
	#
	# See if it's writable
	#
	if test ! -w "$gopherhome" ;  then
		echo "Sorry, can't write to $gopherhome"
		exit 1;
	fi

	if test -h "$gopherhome/.index" ; then
		echo "Another indexing job is probably running"
		echo "Check the link $gopherhome/.index"
		exit 1
	fi

	mkdir /tmp/gopherindex$$
	mkdir /tmp/gopherindex$$/.index
	mkdir "$Datadir/.index"
	ln -s /tmp/gopherindex$$/.index "$gopherhome/.index"


	if [ $useinplaceindex = 1 ]; then
		cp "$Datadir/.index/index.ixif" "/tmp/gopherindex$$/.index"
	fi

	if test $verbose = 1 ; then
		ixargs="-Vv"
	else
		ixargs=""
	fi
	
	ixargs="$ixargs -f ascii -i $gopherhome/.index/index.ixif"

	cd $gopherhome
	ixBuild $ixargs "$Datadir"

	mv /tmp/gopherindex$$/.index/index.ixif "$Datadir/.index"
	rm -rf  "/tmp/gopherindex$$"
	rm "$gopherhome/.index"

	#
	# Make the link
	#
	echo "Name=$indexname" >  "$Datadir/.IndexLink"
	echo "Numb=1"	       >> "$Datadir/.IndexLink"
	echo "Type=7"          >> "$Datadir/.IndexLink"
	echo "Host=+"          >> "$Datadir/.IndexLink"
	echo "Port=+" 	       >> "$Datadir/.IndexLink"
	echo "Path=7$Pathdir"   >> "$Datadir/.IndexLink"
}


waisindexer() {
	mkdir "$Indexdir/.waisindex$$"

	if [ $useinplaceindex = 1 ]; then
		cp "$Indexdir/.waisindex/"* "$Indexdir/.waisindex$$"
	fi

	if test $verbose = 1 ; then
		waisargs="$waisargs"
	else
		waisargs="$waisargs -l 2"
	fi

	
	cd "$Indexdir/.waisindex$$"
	find "$Datadir" -type f -print | \
		grep -v '/\.' |waisindex -stdin $waisargs

	#
	# Make the link
	#
	echo "Name=$indexname"                  >  "$Datadir/.IndexLink"
	echo "Numb=1"                           >> "$Datadir/.IndexLink"
	echo "Type=7"                           >> "$Datadir/.IndexLink"
	echo "Host=+"                           >> "$Datadir/.IndexLink"
	echo "Port=+" 	                        >> "$Datadir/.IndexLink"
	echo "Path=7$Pathdir/.waisindex/index"  >> "$Datadir/.IndexLink"

	rm -rf	"$Indexdir/.waisindex"
	mv "$Indexdir/.waisindex$$" "$Indexdir/.waisindex"
}




if [ "$indextype" = "next" ]; then 
	nextindex
else
	#
	#Must be WAIS instead
	#
	waisindexer
fi

exit 0