Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afsinstall / lib / InstallGuides / HPx00_UX9 / rc
1 # Copyright 2000, International Business Machines Corporation and others.
2 # All Rights Reserved.
3 #
4 # This software has been released under the terms of the IBM Public
5 # License. For details, see the LICENSE file in the top-level source
6 # directory or online at http://www.openafs.org/dl/license10.html
7
8 # An InstallGuide for installing the initialization script
9 # For HP 9000 systems running HPUX 9.x
10 #
11
12 sub rc {
13 # Defaults
14 $rcfile = "/etc/rc";
15
16 # Add AFS kernel loader to RC file
17 &VPrint("Updating $rcfile file");
18 &ErrorsAreFatal(1);
19 &DisplaceFile("/etc/rc.afs");
20
21 # Append the generic RC file
22 &ReadInstallGuide("$InstallGuideDir/GENERIC/rc");
23 &Appendrc;
24
25 # Read in the current RC file
26 $Section = "rc";
27 $rc = open(RC, $rcfile);
28 &ErrorMsg("Could not read file", $rcfile) if (!$rc);
29 @line = <RC>;
30 close(RC);
31
32 # Check if AFS is already referenced
33 if (grep(/\bAFS\b/, @line) || grep(/\/usr\/vice\/etc/, @line)) {
34 &Print("AFS appears to already be in $rcfile");
35 return; };
36
37 # Find where function localrc() is. If it is not there, put it in after
38 # all of the leading comments
39 $localrc = -1;
40 $comments = 0;
41 foreach $n (0 ... $#line) {
42 $comments = $n unless (@line[$n] =~ /^#/ || $comments > 0);
43 if (@line[$n] =~ /^localrc\(\)/) {
44 $localrc = $n;
45 last; }; };
46
47 # Insert a localrc() function if one was not already there
48 if ($localrc == -1) {
49 splice(@line, $comments, 0, "localrc()\n", "{\n", "}\n", "\n");
50 $localrc = $comments;
51 &Print("Inserted function localrc() in $rcfile");
52 &Print("This should be run after NFS is started"); };
53
54 # Skip past the function name and opening curly brace. Account for "{}"
55 until (@line[$localrc] =~ /\{/ || $localrc > $#line) { $localrc ++; };
56 if (@line[$localrc] =~ /\}/) {
57 @line[$localrc] =~ s/\}//;
58 splice(@line, $localrc+1, 0, "}\n"); };
59 $localrc++;
60
61 # Insert a call to the AFS rc file
62 splice(@line, $localrc, 0,
63 "\# Start AFS\n",
64 "if [ -f /etc/rc.afs ]; then\n",
65 " /bin/sh /etc/rc.afs\n",
66 "fi\n");
67
68 # Rewrite the RC file
69 $rc = open(RC, "> $rcfile");
70 &ErrorMsg("Could not rewrite file" , $rcfile) if (!$rc);
71 foreach $line (@line) {
72 print RC $line; };
73 close(RC);
74 }