2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
10 #include "Installer.h"
16 #include "variables.h"
23 char test_script
[] = "SYS:Tests/Installer/test.script";
26 char *filename
= NULL
;
28 char buffer
[MAXARGSIZE
];
29 int error
= 0, grace_exit
= 0;
31 InstallerPrefs preferences
;
34 IPTR args
[TOTAL_ARGS
] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
40 int main(int argc
, char *argv
[])
42 struct RDArgs
*rda
= NULL
;
44 ScriptArg
*currentarg
, *dummy
;
45 int nextarg
, endoffile
, count
;
50 { /* Invoked from Shell */
51 preferences
.fromcli
= TRUE
;
52 /* evaluate args with RDArgs(); */
53 rda
= ReadArgs(ARG_TEMPLATE
, args
, NULL
);
56 PrintFault(IoErr(), INSTALLER_NAME
);
60 /* open script file */
63 filename
= (STRPTR
)args
[ARG_SCRIPT
];
67 fprintf(stderr
, "No SCRIPT specified!\n");
69 fprintf(stderr
, "Using %s instead...\n", test_script
);
70 filename
= test_script
;
81 /* Invoked from Workbench */
82 preferences
.fromcli
= FALSE
;
83 tooltypes
= ArgArrayInit(argc
, (UBYTE
**)argv
);
85 /* open script file */
86 ttemp
= ArgString(tooltypes
, "SCRIPT", NULL
);
90 fprintf(stderr
, "No SCRIPT ToolType in Icon!\n");
100 inputfile
= Open(filename
, MODE_OLDFILE
);
101 if (inputfile
== BNULL
)
104 fprintf(stderr
, "Error opening script <%s>\n",filename
);
105 PrintFault(IoErr(), INSTALLER_NAME
);
110 preferences
.welcome
= FALSE
;
111 preferences
.transcriptstream
= BNULL
;
112 preferences
.pretend
= 0;
116 preferences
.debug
= TRUE
;
119 preferences
.novicelog
= FALSE
;
123 preferences
.novicelog
= TRUE
;
125 preferences
.transcriptfile
= strdup((args
[ARG_LOGFILE
]) ? (char *)args
[ARG_LOGFILE
] : "install_log_file");
126 preferences
.nopretend
= (int)args
[ARG_NOPRETEND
];
127 if (args
[ARG_MINUSER
])
129 preferences
.minusrlevel
= _NOVICE
;
130 if (strcasecmp("average", (char *)args
[ARG_MINUSER
]) == 0)
132 preferences
.minusrlevel
= _AVERAGE
;
134 else if (strcasecmp("expert", (char *)args
[ARG_MINUSER
]) == 0)
136 preferences
.minusrlevel
= _EXPERT
;
140 preferences
.minusrlevel
= _NOVICE
;
145 preferences
.minusrlevel
= _NOVICE
;
147 if (args
[ARG_DEFUSER
])
149 preferences
.defusrlevel
= preferences
.minusrlevel
;
150 if (strcasecmp("average", (char *)args
[ARG_DEFUSER
]) == 0)
152 preferences
.defusrlevel
= _AVERAGE
;
154 else if (strcasecmp("expert", (char *)args
[ARG_DEFUSER
]) == 0)
156 preferences
.defusrlevel
= _EXPERT
;
160 preferences
.defusrlevel
= _NOVICE
;
165 preferences
.defusrlevel
= _NOVICE
;
167 if (preferences
.defusrlevel
< preferences
.minusrlevel
)
169 preferences
.defusrlevel
= preferences
.minusrlevel
;
174 STRPTR ttemp
, tstring
;
176 preferences
.debug
= TRUE
;
178 /* Create a log file in Novice mode? (TRUE) */
179 if (strcmp("TRUE", ArgString(tooltypes
, "LOG", "TRUE")) == 0)
181 preferences
.novicelog
= TRUE
;
185 preferences
.novicelog
= FALSE
;
188 /* Write to which LOGFILE? */
189 preferences
.transcriptfile
= strdup(ArgString(tooltypes
, "LOGFILE", "install_log_file"));
190 /* Is PRETEND possible? */
191 preferences
.nopretend
= (strcmp("TRUE", ArgString(tooltypes
, "PRETEND", "TRUE")) != 0);
192 ttemp
= ArgString(tooltypes
, "MINUSER", "NOVICE");
194 preferences
.minusrlevel
= _NOVICE
;
195 if (strcasecmp("average", ttemp
) == 0)
197 preferences
.minusrlevel
= _AVERAGE
;
200 else if (strcasecmp("expert", ttemp
) == 0)
202 preferences
.minusrlevel
= _EXPERT
;
206 ttemp
= ArgString(tooltypes
, "DEFUSER", tstring
);
207 preferences
.defusrlevel
= preferences
.minusrlevel
;
208 if (strcasecmp("average", ttemp
) == 0)
210 preferences
.defusrlevel
= _AVERAGE
;
212 else if (strcasecmp("expert", ttemp
) == 0)
214 preferences
.defusrlevel
= _EXPERT
;
216 if (preferences
.defusrlevel
< preferences
.minusrlevel
)
218 preferences
.defusrlevel
= preferences
.minusrlevel
;
221 if (preferences
.defusrlevel
< preferences
.minusrlevel
)
223 preferences
.defusrlevel
= preferences
.minusrlevel
;
227 preferences
.copyfail
= COPY_FAIL
;
228 preferences
.copyflags
= 0;
230 preferences
.onerror
.cmd
= NULL
;
231 preferences
.onerror
.next
= NULL
;
232 preferences
.onerror
.parent
= NULL
;
233 preferences
.onerrorparent
= NULL
;
234 for ( count
= 0 ; count
< NUMERRORS
; count
++ )
236 dummy
= &(preferences
.trap
[count
]);
239 dummy
->parent
= NULL
;
240 preferences
.trapparent
[count
] = NULL
;
243 /* Init GUI -- i.e open empty window */
252 script
.parent
= NULL
;
255 currentarg
= script
.cmd
;
256 /* parse script file */
259 /* Allocate space for script cmd and save first one to scriptroot */
260 if (script
.cmd
== NULL
)
262 script
.cmd
= (ScriptArg
*)malloc(sizeof(ScriptArg
));
263 if (script
.cmd
== NULL
)
267 currentarg
= script
.cmd
;
268 currentarg
->parent
= &script
;
272 currentarg
->next
= (ScriptArg
*)malloc(sizeof(ScriptArg
));
273 if (currentarg
->next
== NULL
)
277 currentarg
->next
->parent
= currentarg
->parent
;
278 currentarg
= currentarg
->next
;
280 /* Set initial values */
281 currentarg
->arg
= NULL
;
282 currentarg
->cmd
= NULL
;
283 currentarg
->next
= NULL
;
284 currentarg
->intval
= 0;
285 currentarg
->ignore
= 0;
290 count
= Read(inputfile
, &buffer
[0], 1);
296 if (!isspace(buffer
[0]) && (endoffile
== FALSE
))
298 /* This is text, is it valid ? */
301 case SEMICOLON
: /* A comment, ok - Go on with next line */
304 count
= Read(inputfile
, &buffer
[0], 1);
305 } while (buffer
[0] != LINEFEED
&& count
!= 0);
313 case LBRACK
: /* A command (...) , parse the content of braces */
314 currentarg
->cmd
= (ScriptArg
*)malloc(sizeof(ScriptArg
));
315 if (currentarg
->cmd
== NULL
)
319 dummy
= currentarg
->cmd
;
320 dummy
->parent
= currentarg
;
326 parse_file(currentarg
->cmd
);
330 default: /* Plain text or closing bracket is not allowed */
332 show_parseerror("Too many closing brackets!", line
);
340 if (buffer
[0] == LINEFEED
)
345 } while (nextarg
!= TRUE
&& !endoffile
);
346 } while (!endoffile
);
348 /* Okay, we (again) have allocated one ScriptArg too much, so get rid of it */
349 currentarg
= script
.cmd
;
350 if (currentarg
->next
!= NULL
)
352 while (currentarg
->next
->next
!= NULL
)
354 currentarg
= currentarg
->next
;
356 free(currentarg
->next
);
357 currentarg
->next
= NULL
;
362 if (preferences
.transcriptfile
!= NULL
)
364 /* open transcript file */
365 preferences
.transcriptstream
= Open(preferences
.transcriptfile
, MODE_NEWFILE
);
366 if (preferences
.transcriptstream
== BNULL
)
368 PrintFault(IoErr(), INSTALLER_NAME
);
374 /* Set variables which are not constant */
375 set_preset_variables(argc
);
377 /* NOTE: Now everything from commandline(ReadArgs)/ToolTypes(Workbench)
381 { /* Finally free ReadArgs struct (set_preset_variables() needed them) */
385 { /* Or free tooltypes array if started from WB */
389 /* If the script does not contain a (welcome) section, call the default one */
390 if (preferences
.welcome
== FALSE
)
392 request_userlevel(NULL
);
396 /* Don't bother NOVICE */
397 if (get_var_int("@user-level") == _NOVICE
)
399 preferences
.copyflags
&= ~COPY_ASKUSER
;
403 preferences
.copyflags
|= COPY_ASKUSER
;
406 /* execute parsed script */
407 execute_script(script
.cmd
, 0);