1#!/bin/sh
2
3# Installation script for sirc, will try to find your perl interpreter,
4# C compiler, check your perl installation and setup sirc.
5
6# (bits stolen from ircII's "easyinst" and from various configure
7# scripts)
8
9cat << '_EOF_'
10
11This script will compile, configure and install sirc for your system.
12You can exit at any time by pressing ^C (Control-C) and start over if
13you wish to change your settings.
14
15Whenever asked for something, the default answer is shown between
16[brackets]. Pressing Enter at that point will take the default answer.
17
18_EOF_
19
20if test "`echo -n a`" = "a"
21then
22  n='-n'
23  c=''
24else
25  n=''
26  c='\c'
27fi
28
29echo $n "Continue with the installation? ([y]/n) " $c
30read A
31case "$A" in
32  n*|N*) echo "Aborting."
33  	 exit 1
34esac
35
36echo
37if test -r dsirc -a -r ssfe.c
38then
39  echo "Checking where dsirc and ssfe.c are - OK"
40else
41  echo "I can't find the files dsirc or ssfe.c, from the sirc distribution."
42  echo "Please run this script in the directory where these files are."
43  echo
44  exit 1
45fi
46
47rm -f ssfe sircsock.ph crfkbtsk.c crfkbtsk
48IFS="${IFS= 	}"; save_ifs=$IFS; IFS="${IFS}:"; CC=""; PERL=""
49for dir in $PATH
50do
51  test -z "$dir" && dir="."
52  test -f $dir/gcc && CC="$dir/gcc"
53  test -f $dir/cc -a -z "$CC" && CC="$dir/cc"
54  test -f $dir/perl5 && PERL="$dir/perl5"
55  test -f $dir/perl -a -z "$PERL" && PERL="$dir/perl"
56done
57
58IFS="$save_ifs"
59echo
60
61if test -z "$CC"
62then
63  echo "I can't find a C compiler, either cc or gcc."
64  echo
65  CC=none
66fi
67
68echo "Enter the name of the C compiler you want to use, or \"none\" if you"
69echo "don't have access to one. In that case you can only use this IRC"
70echo "client in dumb (not full-screen) mode."
71echo
72echo "If you don't know what this is all about, just press Enter :)"
73echo
74echo $n "Compiler? [$CC] " $c
75read compiler
76test -z "$compiler" || CC="$compiler"
77test "$CC" = none && CC=""
78
79if test "$CC"
80then
81  echo
82  echo "ssfe.c needs the termcap library, or something compatible with it,"
83  echo "such as ncurses.  Also, on some systems the termcap library is"
84  echo "included in the curses library, so \"curses\" might work."
85  echo
86  echo $n "Which library to use? [termcap] " $c
87  read library
88  test -z "$library" && library="termcap"
89  case "$library" in
90    -l*)
91      lib="$library"
92      ;;
93    *)
94      lib="-l$library"
95  esac
96  echo $n "Use the old BSD sgtty interface instead of the POSIX one? (y/[n]) " $c
97  read sgtty
98  case "$sgtty" in
99    y*|Y*)
100      opt="-DUSE_SGTTY"
101      ;;
102    *)
103      opt=""
104  esac
105  echo $n "Any other flags (-O, -L, -I ...) for the compiler? [none] " $c
106  read flags
107  echo
108  echo $n "Attempting to compile ssfe.c with $CC ... press Enter " $c
109  read blah
110  echo "$CC $opt $flags ssfe.c -o ssfe $lib"
111  eval "$CC $opt $flags ssfe.c -o ssfe $lib"
112  if test -x ssfe
113  then
114    echo
115    echo "It seems to have worked :)"
116  else
117    echo
118    echo "I can't compile ssfe, for whatever reason. Press ^C and try again"
119    echo "with a different compiler or different compile options, or press"
120    echo $n "Enter to go on and install sirc in dumb mode... " $c
121    read blah
122    echo "Going on."
123    echo
124  fi
125fi
126test -f ssfe && strip ssfe
127
128echo
129if test -z "$PERL"
130then
131  echo "I can't find your perl interpreter anywhere."
132  echo "There is no way sirc can run without perl; please check your"
133  echo "PATH and/or ask your sysadmin about it."
134  echo
135  echo "Enter the full pathname to the perl interpreter, or press ^C"
136  echo "to abort the installation."
137else
138  echo "Enter the name of the perl interpreter you want to use, or"
139  echo "press Enter to use $PERL"
140fi
141echo $n "Perl interpreter? [$PERL] " $c
142read perl
143test -z "$perl" || PERL="$perl"
144echo
145echo $n "Checking your perl interpreter... " $c
146perlmsg=`eval "$PERL -v" 2>&1`
147
148case "$perlmsg" in
149  *Wall*) echo "OK"
150  	  ;;
151   *)     echo "Doesn't seem to work ... aborting."
152	  exit 1
153esac
154
155if $PERL -e 'eval "use Socket; &AF_INET;" || exit 1'
156then
157  echo You have perl 5.  Congratulations.
158else
159  echo
160  echo "Trying to setup the perl include files sirc needs..."
161  sockfile="sircsock.ph"
162  hosttype=`uname -a`
163  test -z "$hosttype" && hosttype=unknown
164
165  case "$hosttype" in
166    AIX*|HP-UX*|Linux*|NEXT*|OSF1*|SunOS*4.1*|ULTRIX*|FreeBSD*|NetBSD*|OpenBSD*)
167      echo "... using the defaults I have for your type of system."
168      cat > $sockfile << '_EOF_'
169eval 'sub SOCK_STREAM {0x1;}';
170eval 'sub AF_INET {0x2;}';
171eval 'sub PF_INET {0x2;}';
172_EOF_
173      ;;
174    SunOS*5.*|IRIX*5.*)
175      echo "... using the defaults I have for your type of system."
176      cat > $sockfile << '_EOF_'
177eval 'sub SOCK_STREAM {0x2;}';
178eval 'sub AF_INET {0x2;}';
179eval 'sub PF_INET {0x2;}';
180_EOF_
181      ;;
182    *)
183      echo "I don't have any specific defaults for your type of system."
184      if test -z "$CC"
185      then
186	echo "Since we can't use a C compiler, we're stuck with the general"
187	echo "default values... I hope they work :>"
188	cat > $sockfile << '_EOF_'
189eval 'sub SOCK_STREAM {0x1;}';
190eval 'sub AF_INET {0x2;}';
191eval 'sub PF_INET {0x2;}';
192_EOF_
193      else
194	echo
195	echo "Do you want to use the general default values? If you answer \"no\","
196	echo "I will try to find out the right values for your system."
197	echo $n "Use general defaults? (y/[n]) " $c
198	read use
199	case "$use" in
200	  y*|Y*)
201	    echo "Going on with the global defaults... I hope they work for you"
202	    cat > $sockfile << '_EOF_'
203eval 'sub SOCK_STREAM {0x1;}';
204eval 'sub AF_INET {0x2;}';
205eval 'sub PF_INET {0x2;}';
206_EOF_
207	    ;;
208	  *)
209	    cat > crfkbtsk.c << '_EOF_'
210#include <sys/types.h>
211#include <sys/socket.h>
212#include <stdio.h>
213
214main() {
215  printf("eval 'sub SOCK_STREAM {0x%x;}';\n", SOCK_STREAM);
216  printf("eval 'sub AF_INET {0x%x;}';\n", AF_INET);
217  printf("eval 'sub PF_INET {0x%x;}';\n", PF_INET);
218}
219
220_EOF_
221
222	    echo
223	    echo "Compiling intermediary program..."
224	    echo
225	    eval "$CC crfkbtsk.c -o crfkbtsk"
226	    if test -f crfkbtsk
227	    then
228	      echo "The intermediary C program seems to have compiled OK."
229	    else
230	      echo
231	      echo "The intermediary C program seems NOT to compile OK."
232	      echo "Try again with the global defaults or another compiler..."
233	      echo "Aborting."
234	      exit
235	    fi
236	    ./crfkbtsk > $sockfile
237	    rm -f crfkbtsk crfkbtsk.c
238	    echo "We're done installing your perl include files for sirc"
239	esac
240      fi
241  esac
242fi
243
244if $PERL -e 'if (eval "require \"getopts.pl\";") { exit 1 } else { exit 0 }'
245then
246  echo
247  echo "Your perl installation is really messed up, you don't even have the"
248  echo "getopts.pl library... creating it in sirc's directory"
249  # this code comes from the perl distribution
250  cat > getopts.pl << '_EOF_'
251;# getopts.pl - a better getopt.pl
252
253;# Usage:
254;#      do Getopts('a:bc');  # -a takes arg. -b & -c not. Sets opt_* as a
255;#                           #  side effect.
256
257sub Getopts {
258    local($argumentative) = @_;
259    local(@args,$_,$first,$rest);
260    local($errs) = 0;
261    local($[) = 0;
262
263    @args = split( / */, $argumentative );
264    while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
265	($first,$rest) = ($1,$2);
266	$pos = index($argumentative,$first);
267	if($pos >= $[) {
268	    if($args[$pos+1] eq ':') {
269		shift(@ARGV);
270		if($rest eq '') {
271		    ++$errs unless @ARGV;
272		    $rest = shift(@ARGV);
273		}
274		eval "\$opt_$first = \$rest;";
275	    }
276	    else {
277		eval "\$opt_$first = 1";
278		if($rest eq '') {
279		    shift(@ARGV);
280		}
281		else {
282		    $ARGV[0] = "-$rest";
283		}
284	    }
285	}
286	else {
287	    print STDERR "Unknown option: $first\n";
288	    ++$errs;
289	    if($rest ne '') {
290		$ARGV[0] = "-$rest";
291	    }
292	    else {
293		shift(@ARGV);
294	    }
295	}
296    }
297    $errs == 0;
298}
299
3001;
301_EOF_
302else
303  echo "Your perl's getopts.pl library seems to be OK"
304fi
305
306curdir=`pwd`
307if test -w /bin
308then
309  bindir="/usr/local/bin"
310  plibdir="/usr/local/lib/sirc"
311else
312  bindir="$HOME/bin"
313  if test -d "$HOME/lib"
314  then
315    plibdir="$HOME/lib/sirc"
316  else
317    plibdir="$HOME/sirc"
318  fi
319fi
320
321echo
322echo "Where do you want to install the sirc binaries?"
323echo $n "Binaries directory? [$bindir] " $c
324read bin
325test -z "$bin" || bindir="$bin"
326
327if test -d "$bindir"
328then
329  true
330else
331  echo "The bin directory $bindir doesn't exist."
332  echo $n "Create it? ([y]/n) " $c
333  read creat
334  echo
335  case "$creat" in
336    n*|N*)
337      echo "I can't put your files there, then!"
338      echo "Aborting."
339      exit 1
340      ;;
341    *)
342      if mkdir "$bindir"
343      then
344        echo "Created!"
345      else
346        echo "Can't create directory... aborting"
347	exit 1
348      fi
349  esac
350fi
351if test -w "$bindir"
352then
353  true
354else
355  echo "I can't write in the $bindir directory."
356  echo "Aborting."
357  exit 1
358fi
359
360echo "Ok"
361echo
362echo "Other than the executable files in the bin directory, sirc needs to"
363echo "keep a small number of files in a directory of its own. You can either"
364echo "leave them here in $curdir,"
365echo "or specify another directory."
366echo
367echo $n "Pick another directory for sirc's files? (y/[n]) " $c
368read another
369filesmoved=""
370case "$another" in
371  y*|Y*)
372    echo $n "sirc directory? [$plibdir] " $c
373    read libdir
374    test -z "$libdir" && libdir="$plibdir"
375    if test -d "$libdir"
376    then
377      true
378    else
379      echo "The directory $libdir doesn't exist."
380      echo $n "Create it? ([y]/n) " $c
381      read creat
382      echo
383      case "$creat" in
384	n*|N*)
385	  echo "OK, up to you to move the files there later, then"
386	  ;;
387	*)
388	  if mkdir "$libdir"
389	  then
390	    echo "Created!"
391	  else
392	    echo "Can't create directory... aborting"
393	    exit 1
394	  fi
395      esac
396    fi
397    echo $n "Copy all the files sirc needs in that directory? ([y]/n) " $c
398    read copyfiles
399    case "$copyfiles" in
400      n*|N*)
401	echo "Ok, I'll leave that to you..."
402        ;;
403      *)
404	echo "Copying files from $curdir to $libdir..."
405	cp ChangeLog PROGRAMMING README dsirc sirc.help.gz ssfe.c n0thing.pl socks.pl $libdir
406	chmod 755 $libdir $libdir/dsirc
407	chmod 644 $libdir/ChangeLog $libdir/PROGRAMMING $libdir/README $libdir/sirc.help.gz $libdir/ssfe.c $libdir/n0thing.pl
408	if test -f getopts.pl
409	then
410	  cp getopts.pl $libdir
411	  chmod 644 $libdir/getopts.pl
412	fi
413	if test -f sircsock.ph
414	then
415	  cp sircsock.ph $libdir
416	  chmod 644 $libdir/sircsock.ph
417	fi
418	filesmoved="1"
419	if test -f "$libdir/dsirc"
420	then
421	  echo "done copying."
422	else
423	  echo
424	  echo "Something seems to have gone wrong... aborting."
425	  exit 1
426	fi
427    esac
428    ;;
429  *)
430    libdir="$curdir"
431    echo OK
432esac
433
434cat << '_EOF_'
435
436sirc now includes experimental support for SOCKS proxies.  If you are
437behind a firewall (i.e your host can't directly connect to outside) and
438the firewall is running a SOCKS proxy, answer "yes" to this question.
439Otherwise answer "no".
440
441_EOF_
442
443echo $n "Support SOCKS proxies? (y/[n]) " $c
444read socks
445soxtra1=""
446soxtra2=""
447soxtra3=""
448case "$socks" in
449  y*|Y*)
450    echo $n "Enter the hostname of your SOCKS proxy: " $c
451    read socksserver
452    if test -z "$socksserver"
453    then
454      echo "Uhm, I guess you don't really want SOCKS then"
455    else
456      soxtra1="SOCKS_SERVER=$socksserver; export SOCKS_SERVER
457"
458      echo $n "What port does your SOCKS proxy use? [1080] " $c
459      read socksport
460      if test "$socksport"
461      then
462        soxtra2="SOCKS_PORT=$socksport; export SOCKS_PORT
463"
464      fi
465      test -z "$proxyport" && proxyport=1080
466      cat << '_EOF_'
467
468sirc also supports the SOCKS4A extension to the SOCKS protocol, allowing
469clients to ask the SOCKS host to resolve hostnames if they can't
470themselves.  If your machine has access to a working nameserver, you
471don't want this.
472
473_EOF_
474      echo $n "Use SOCKS4A DNS extension? (y/[n]) " $c
475      read socks4a
476      case "$socks4a" in
477	y*|Y*)
478	  soxtra3="SOCKS_DNS=1; export SOCKS_DNS
479"
480      esac
481    fi
482esac
483
484if test -w /usr/local/man/man1
485then
486  manp=/usr/local/man/man1
487else
488  if test -w /usr/man/man1
489  then
490    manp=/usr/man/man1
491  else
492    if test -w /opt/man/man1
493    then
494      manp=/opt/man/man1
495    else
496      if test -w $HOME/man/man1
497      then
498	manp=$HOME/man/man1
499      else
500	manp=none
501      fi
502    fi
503  fi
504fi
505
506cat << '_EOF_'
507
508In which directory do you want to install sirc's manpages?  If you
509don't want them installed, enter "none".
510
511_EOF_
512
513echo $n "Manpage directory? [$manp] " $c
514read manp2
515test -z "$manp2" || manp="$manp2"
516if test "$manp" = "none"
517then
518  echo "Not copying manpages..."
519else
520  if test -d $manp -a -w $manp
521  then
522    cp sirc.1 ssfe.1 $manp
523    chmod 644 $manp/ssfe.1 $manp/sirc.1
524  else
525    echo "Can't write to manpage directory... not installing manpages"
526  fi
527fi
528
529server="irc.primenet.com"
530cat << '_EOF_'
531
532One thing left to setup now: the name of your default IRC server.
533You should pick the closest server to you in the net you wish to use.
534
535If you don't know which server to use, you can pick one of the following,
536or look at http://www.irchelp.org for information:
537
538     irc.primenet.com -  EFnet server in America
539     irc.ec-lille.fr  -  EFnet server in Europe
540     us.undernet.org  -  Undernet server in America
541     eu.undernet.org  -  Undernet server in Europe
542     irc.stealth.net  -  IRCnet server in America
543     irc.funet.fi     -  IRCnet server in Europe
544     irc.dal.net      -  DALnet server in America
545     fi.dal.net       -  DALnet server in Europe
546
547_EOF_
548echo $n "Default server? [$server] " $c
549read serv
550test -z "$serv" || server="$serv"
551
552echo
553echo "OK, time to put the binaries in the bin directory, and to create the"
554echo "startup script."
555echo $n "Press Enter to go on, or ^C to interrupt... " $c
556read blah
557echo
558
559rm -f $bindir/sirc
560if test -f ssfe
561then
562  chmod 755 ssfe
563  rm -f $bindir/ssfe
564  cp ssfe $bindir
565  echo "#!/bin/sh
566
567SIRCLIB=$libdir ; export SIRCLIB
568${soxtra1}${soxtra2}${soxtra3}
569if test -z \"\$SIRCSERVER\" && test -z \"\$IRCSERVER\"
570then
571  SIRCSERVER=\"$server\"
572  export SIRCSERVER
573fi
574
575case \"\$1\" in
576  -d) shift
577      exec $PERL $libdir/dsirc \"\$@\"
578      ;;
579  *)  eval exec $bindir/ssfe \$SSFE $PERL $libdir/dsirc \\\"\\\$@\\\"
580esac" > $bindir/sirc
581else
582  echo "#!/bin/sh
583
584SIRCLIB=$libdir ; export SIRCLIB
585${soxtra1}${soxtra2}${soxtra3}
586if test -z \"\$SIRCSERVER\" && test -z \"\$IRCSERVER\"
587then
588  SIRCSERVER=\"$server\"
589  export SIRCSERVER
590fi
591
592case \"\$1\" in
593  -d) shift
594esac
595exec $PERL $libdir/dsirc \"\$@\"" > $bindir/sirc
596
597fi
598chmod 755 $bindir/sirc
599
600if test -n "$soxtra1"
601then
602  echo '&load("socks.pl");' > $libdir/sircrc.pl
603fi
604
605if test "$filesmoved"
606then
607  echo
608  echo "Since you have copied the files in $libdir,"
609  echo "you probably don't need them here... you can delete them if you want."
610fi
611
612echo
613echo "We're done. You can start sirc at any time by typing \"sirc\" at the Unix"
614echo "prompt. If that doesn't work, check your PATH, or you can always start sirc"
615echo "by typing $bindir/sirc" | sed "s|$HOME|~|"
616echo
617
618
619if test -f $bindir/ssfe
620then
621  echo "Keep in mind that you can always exit sirc by pressing Control-X C"
622else
623  echo "Keep in mind that you can always exit sirc by pressing Control-C"
624fi
625
626echo
627echo "Happy IRCing..."
628echo "... and don't forget to read $libdir/README sometime :)" | sed "s|$HOME|~|"
629
630