File: sarinstall.c

package info (click to toggle)
searchandrescue 0.8.2-10
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,656 kB
  • ctags: 6,111
  • sloc: ansic: 89,072; cpp: 7,691; sh: 90; makefile: 80
file content (150 lines) | stat: -rw-r--r-- 2,615 bytes parent folder | download | duplicates (6)
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "../include/disk.h"

#include "sar.h"
#include "optionio.h"
#include "sarinstall.h"


Boolean SARIsInstalledLocal(
	sar_dname_struct *dn,
	sar_fname_struct *fn
);
Boolean SARIsInstalledGlobal(
	sar_dname_struct *dn,
	sar_fname_struct *fn
);

int SARDoInstallLocal(
	sar_dname_struct *dn,
        sar_fname_struct *fn,
        sar_option_struct *opt
);


/*
 *	Checks if the program's compoent appears to be installed locally,
 *	returns true if it is installed.
 *
 *	The input path structures need to be specified.
 */
Boolean SARIsInstalledLocal(
	sar_dname_struct *dn,
	sar_fname_struct *fn
)
{
	struct stat stat_buf;


	if((dn == NULL) || (fn == NULL))
	    return(False);

	/* Nessasary paths specified? */
	if((*(dn->local_data) == '\0') ||
           (*(fn->options) == '\0')
	)
	    return(False);


	/* Local directory exists? */
	if(stat(dn->local_data, &stat_buf))
	    return(False);

	/* Is a directory? */
#ifdef S_ISDIR
	if(!S_ISDIR(stat_buf.st_mode))
	    return(False);
#endif	/* S_ISDIR */

	/* Configuration file exists? */
	if(stat(fn->options, &stat_buf))
	    return(False);

	/* Is a file? */
#ifdef S_ISREG
	if(!S_ISREG(stat_buf.st_mode))
	    return(False);
#endif	/* S_ISREG */

	return(True);
}

/*
 *      Checks if the program's compoent appears to be installed globally,
 *      returns true if it is installed.
 *
 *	The input path structures need to be specified.
 */
Boolean SARIsInstalledGlobal(
        sar_dname_struct *dn,
        sar_fname_struct *fn
)
{
	struct stat stat_buf;


	if((dn == NULL) || (fn == NULL))
	    return(False);

	/* Nessasary paths specified? */
	if(*(dn->global_data) == '\0')
	    return(False);


	/* Global directory exists? */
	if(stat(dn->global_data, &stat_buf))
	    return(False);

	/* Is a directory? */
#ifdef S_ISDIR
	if(!S_ISDIR(stat_buf.st_mode))
	    return(False);
#endif	/* S_ISDIR */

        return(True);
}  


/*
 *	Procedure to install program files locally.
 *
 *	Returns non-zero on error.
 */
int SARDoInstallLocal(
	sar_dname_struct *dn,
	sar_fname_struct *fn,
	sar_option_struct *opt
)
{
	struct stat stat_buf;


	if((dn == NULL) || (fn == NULL))
	    return(-1);

	/* Create local program directory as meeded */
	if(stat(dn->local_data, &stat_buf))
	{
	    if(rmkdir(
		dn->local_data,
#ifdef __MSW__
		0
#else
		S_IRUSR | S_IWUSR | S_IXUSR	/* User rwx only */
#endif
	    ))
		return(-1);
	}

	/* Create default configuration file */
	if(SAROptionsSaveToFile(opt, fn->options))
	    return(-1);

	return(0);
}