Project

General

Profile

« Previous | Next » 

Revision 9a2d499c

Added by Colin Smith about 20 years ago

*Rework package installation interface. * Use progress bar to indicate download progress. * Handle nested dependencies. * Handle dependencies needed by more than one package/depend (please test) * Some minor optimizations.
*Add pkg_fetch_recursive().

View differences:

usr/local/www/guiconfig.inc
538 538
}
539 539

  
540 540
function read_body($ch, $string) {
541
        global $fout, $file_size, $downloaded, $counter;
541
        global $fout, $file_size, $downloaded, $counter, $sendto, $static_output;
542 542
        $length = strlen($string);
543 543
        $downloaded += intval($length);
544 544
        $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
......
554 554
        $text .= "  Percent    : {$c}%\\n";
555 555
        $text .= "---------------------------------\\n";
556 556
        */
557
        $counter++;
558
        if($counter > 150) {
559
                $tostatus = $static_status . $downloadProgress;
560
                update_status($tostatus);
557
//        $counter++;
558
//        if($counter > 150) {
559
		if($sendto == "status") {
560
                	$tostatus = $static_status . $downloadProgress . "%";
561
                	update_status($tostatus);
562
		} else {
563
			$tooutput = $static_output . $downloadProgress . "%"; 
564
			update_output_window($tooutput);
565
		}
561 566
                update_progress_bar($downloadProgress);
562
                $counter = 0;
563
        }
567
//                $counter = 0;
568
//        }
564 569
        fwrite($fout, $string);
565 570
        return $length;
566 571
}
572

  
573
function pkg_fetch_recursive($pkgname, $filename, $dependlevel = 0, $base_url = 'http://ftp2.freebsd.org/pub/FreeBSD/ports/i386/packages-5-stable/Latest') {
574
	global $static_status, $static_output, $g;
575
	$pkg_extension = strrchr($filename, '.');
576
	$static_output .= "\n" . str_repeat(" ", $dependlevel * 2) . $pkgname . " ";
577
	$fetchto = "/tmp/apkg_" . $pkgname . $pkg_extension;
578
        download_file_with_progress_bar($base_url . "/" . $filename, $fetchto);
579
//	update_output_window($static_output . "\n\n" . $pkg_progress);
580
        exec("/usr/bin/tar -O -f {$fetchto} -x +CONTENTS", $slaveout);
581
        $workingdir = preg_grep("/instmp/", $slaveout);
582
        $workingdir = $workingdir[0];
583
        $raw_depends_list = array_values(preg_grep("/\@pkgdep/", $slaveout));
584
	if($raw_depends_list != "") {
585
                foreach($raw_depends_list as $adepend) {
586
			$working_depend = explode(" ", $adepend);
587
                        $working_depend = explode("-", $working_depend[1]);
588
			$depend_filename = $working_depend[0] . $pkg_extension;
589
			exec("ls /var/db/pkg", $is_installed);
590
			$is_installed = array_values(preg_grep("/{$working_depend[0]}/i", $is_installed));
591
			if($is_installed[0] == "") pkg_fetch_recursive($working_depend[0], $depend_filename, $dependlevel + 1);
592
		}
593
        }
594
	mwexec("cat {$g['tmp_path']}/y | /usr/sbin/pkg_add {$fetchto}");
595
	return true;
596
}
597

  
567 598
?>
usr/local/www/pkg_mgr_install.php
4 4
/*
5 5
    pkg_mgr_install.php
6 6
    part of pfSense (http://www.pfSense.com)
7
    Copyright (C) 2004 Scott Ullrich
7
    Copyright (C) 2005 Scott Ullrich and Colin Smith
8 8
    All rights reserved.
9 9

  
10 10
    Redistribution and use in source and binary forms, with or without
......
41 41
/* /usr/local/www/ext is where package links live for the left hand pane */
42 42
make_dirs("/usr/local/www/ext");
43 43

  
44
$pb_percent = 1;
45

  
46 44
$a_out = &$pkg_config['packages'];
47

  
48 45
$packages_to_install = Array();
46
$static_output = "";
47
$static_status = "";
48
$sendto = "output";
49 49

  
50 50
?>
51 51
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
......
115 115
                     <table id="progholder" name="progholder" height='20' border='1' bordercolor='black' width='420' bordercolordark='#000000' bordercolorlight='#000000' style='border-collapse: collapse' colspacing='2' cellpadding='2' cellspacing='2'><tr><td><img border='0' src='progress_bar.gif' width='280' height='23' name='progressbar' id='progressbar'></td></tr></table>
116 116
                     <br>
117 117
	             <!-- status box -->
118
                     <textarea cols="60" rows="1" name="status" id="status" wrap="hard">One moment please... This will take a while!</textarea>
118
                     <textarea cols="60" rows="1" name="status" id="status" wrap="hard">Beginning package installation.</textarea>
119 119
                     <!-- command output box -->
120 120
	             <textarea cols="60" rows="25" name="output" id="output" wrap="hard"></textarea>
121 121
                     </center>
......
139 139
     *  Loop through installed packages and if name matches
140 140
     *  push the package id onto array to reinstall
141 141
     */
142
    $output_static = "";
142 143
    $counter = 0;
143 144
    foreach($pkg_config['packages']['package'] as $available_package) {
144 145
        foreach($config['installedpackages']['package'] as $package) {
145 146
            if($package['name'] == $available_package['name']) {
146 147
                array_push($packages_to_install, $counter);
147
                update_status("Adding package " . $package['name']);
148
		$output_static .= "Adding " . $package['name'] . " to installation array.\n";
149
		update_output_window($output_static);
148 150
                fwrite($fd_log, "Adding (" . $counter . ") " . $package['name'] . " to package installation array.\n" . $status);
149 151
            }
150 152
        }
......
165 167

  
166 168
    $pkg_config = parse_xml_config_pkg("{$g['tmp_path']}/pkg_config.xml", "pfsensepkgs");
167 169

  
168
    update_progress_bar($pb_percent);
169
    $pb_percent += 10;
170

  
171 170
    /*
172 171
     * install the package
173 172
     */
......
182 181
    safe_mkdir("{$g['www_path']}/ext/Diagnostics", 0755);
183 182
    safe_mkdir("/usr/local/pkg", 0755);
184 183

  
185
    update_progress_bar($pb_percent);
186
    $pb_percent += 10;
187

  
188 184
    $a_out = &$pkg_config['packages']['package'];
189 185

  
190 186
    if($pkg_config['packages']['package'][$id]['verifyinstalledpkg'] <> "")
......
218 214
    fwrite($fd_log, "Begining (" . $id. ") " . $pkgent['name'] . " package installation.\n" . $status);
219 215

  
220 216
    log_error("Begining (" . $id. ") " . $pkgent['name'] . " package installation.");
221

  
222
    update_progress_bar($pb_percent);
223
    $pb_percent += 10;
217
    $static_status = "Beginning package installation for " . $pkgent['name'] . "...";
218
    update_status($static_status);
224 219

  
225 220
    fwrite($fd_log, "ls {$g['vardb_path']}/pkg | grep " . $package_to_verify . "\n" . $status);
226 221
    if($status <> "") {
......
230 225
    }
231 226

  
232 227
    if($pkg_config['packages']['package'][$id]['config_file'] <> "") {
233
        update_status("Downloading configuration file.");
234
        fwrite($fd_log, "Downloading configuration file " . $pkg_config['packages']['package'][$id]['config_file'] . " ... \n");
235
        update_progress_bar($pb_percent);
236
        $pb_percent += 10;
237
        mwexec("cd /usr/local/pkg/ && fetch " . $pkg_config['packages']['package'][$id]['config_file']);
238
        if(!file_exists("/usr/local/pkg/" . $pkgent['name'] . ".xml")) {
228
        $static_output .= "Downloading package configuration file... ";
229
	download_file_with_progress_bar($pkg_config['packages']['package'][$id]['config_file'], "/usr/local/pkg/" . substr(strrchr($pkg_config['packages']['package'][$id]['config_file'], '/'), 1));
230
        fwrite($fd_log, "Downloading configuration file " . $pkg_config['packages']['package'][$id]['config_file'] . "...\n");
231
        if(!file_exists("/usr/local/pkg/" . substr(strrchr($pkg_config['packages']['package'][$id]['config_file'], '/'), 1))) {
239 232
            fwrite($fd_log, "ERROR!  Could not fetch " . $pkg_config['packages']['package'][$id]['config_file']);
240
            update_output_window("ERROR!  Could not fetch " . $pkg_config['packages']['package'][$id]['config_file'] . "\n");
233
            $static_output .= "failed!\n\nInstallation aborted.";
234
            update_output_window($static_output);
241 235
            exit;
242 236
        }
237
	$static_output .= "done.\n";
238
	update_output_window($static_output);
243 239
    }
244 240

  
245
    update_status("Downloading and installing " . $pkgent['name'] . " - " . $pkgent['pfsense_package'] . " and its dependencies ... This could take a moment ...");
246
    fwrite($fd_log, "Downloading and installing " . $pkgent['name'] . " - " . $pkgent['pfsense_package'] . " ... \n");
247

  
248
    update_progress_bar($pb_percent);
249
    $pb_percent += 10;
241
    update_status("Downloading and installing " . $pkgent['name'] . " and its dependencies.");
242
    fwrite($fd_log, "Downloading and installing " . $pkgent['name'] . " - " . $pkgent['pfsense_package'] . "...\n");
250 243

  
251 244
    /*
252 245
     * Open a /tmp/y file which will basically tell the
......
270 263
    fwrite($fd, "y\n");
271 264
    fclose($fd);
272 265

  
266
    /* This directive is not yet used.
273 267
    if ($pkgent['pfsense_package_base_url'] <> "") {
274 268
        fwrite($fd_log, "Executing: cd {$g['tmp_path']}/ && /usr/sbin/pkg_add -r " . $pkgent['pfsense_package_base_url'] . "/" . $pkgent['pfsense_package'] . "\n" . $text);
275 269
        $text = exec_command_and_return_text("cd {$g['tmp_path']}/ && cat {$g['tmp_path']}/y | /usr/sbin/pkg_add -r " . $pkgent['pfsense_package_base_url'] . "/" . $pkgent['pfsense_package']);
276 270
        update_output_window($text);
277 271
    }
278

  
279
    update_progress_bar($pb_percent);
280
    $pb_percent += 10;
272
    */
281 273

  
282 274
    if ($pkgent['depends_on_package_base_url'] <> "") {
283
                update_status("Downloading and installing " . $pkgent['name'] . " and its dependencies ... This could take a moment ...");
284
                $text = exec_command_and_return_text("cd {$g['tmp_path']}/ && cat {$g['tmp_path']}/y && /usr/sbin/pkg_add -r " . $pkgent['depends_on_package_base_url'] . "/" . $pkgent['depends_on_package']);
285
                update_output_window($text);
286
                fwrite($fd_log, "cd {$g['tmp_path']}/ && /usr/sbin/pkg_add -r " . $pkgent['depends_on_package_base_url'] . "/" . $pkgent['depends_on_package'] . "\n" . $text);;
275
                update_status("Installing " . $pkgent['name'] . " and its dependencies.");
276
                $static_output .= "Downloading " . $pkgent['name'] . " and its dependencies... ";
277
		$static_orig = $static_output;
278
		$static_output .= "\n";
279
		update_output_window($static_output);
280
		pkg_fetch_recursive($pkgent['name'], $pkgent['depends_on_package'], 0, $pkgent['depends_on_package_base_url']);
281
		$static_output = $static_orig . "done.\n";
282
		update_output_window($static_output);
287 283
    }
288 284

  
289 285
    if ($pkgent['depends_on_package_base_url'] <> "" or $pkgent['pfsense_package_base_url'] <> "") {
290
        $status = exec_command_and_return_text("ls {$g['vardb_path']}/pkg | grep " . $package_to_verify);
291
        fwrite($fd_log, "ls {$g['vardb_path']}/pkg | grep " . $package_to_verify . "\n" . $status);
292
        if($status <> "") {
293
                    update_status("Package installed.  Lets finish up.");
294
                    fwrite($fd_log, "Package installed.  Lets finish up.\n");
286
        $static_output .= "Checking for successful package installation... ";
287
	update_output_window($static_output);
288
        exec("ls {$g['vardb_path']}/pkg | grep " . $package_to_verify, $status);
289
        fwrite($fd_log, $status[0] . "\n");
290
        if($status[0] <> "") {
291
                    $static_output .= "done.\n";
292
		    update_output_window($static_output);
293
                    fwrite($fd_log, "pkg_add successfully completed.\n");
295 294
        } else {
295
		    $static_output .= "failed!\n\nInstallation aborted.";
296
		    update_output_window($static_output);
296 297
                    fwrite($fd_log, "Package WAS NOT installed properly.\n");
297 298
                    fclose($fd_log);
298
                    $filecontents = exec_command_and_return_text("cat " . $file);
299
                    update_progress_bar(100);
300 299
                    echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';</script>";
301 300
                    echo "\n<script language=\"JavaScript\">document.progholder.style.visibility='hidden';</script>";
302
                    update_status("Package WAS NOT installed properly...Something went wrong.." . $filecontents);
303
                    update_output_window("Error during package installation.");
304 301
                    sleep(1);
305 302
                    die;
306 303
        }
307 304
    }
308 305

  
309
    update_progress_bar($pb_percent);
310
    $pb_percent += 10;
311

  
312 306
    $config = parse_xml_config("{$g['conf_path']}/config.xml", $g['xml_rootobj']);
313 307

  
314
    update_progress_bar($pb_percent);
315
    $pb_percent += 10;
316

  
317 308
    $config['installedpackages']['package'][] = $pkgent;
318 309

  
319 310
    if (isset($id) && $a_out[$id])
......
321 312
    else
322 313
            $a_out[] = $pkgent;
323 314

  
324
    update_progress_bar($pb_percent);
325
    $pb_percent += 10;
326

  
327 315
    if(!$_GET['mode'] == "reinstallall") {
328
        update_output_window("Saving updated package information ...");
316
	$static_output .= "Saving updated package information... ";
317
        update_output_window($static_output);
329 318
        fwrite($fd_log, "Saving updated package information ...\n");
330 319
        write_config("Installed package {$pkgent['name']}");
331 320
        // remount rw after write_config() since it will mount ro.
332 321
        conf_mount_rw();
322
	$static_output .= "done.\n";
323
	update_output_window($static_output);
333 324
    }
334 325

  
335
    update_progress_bar($pb_percent);
336
    $pb_percent += 10;
337

  
338 326
    $name = $pkgent['name'];
339 327

  
340
    update_progress_bar($pb_percent);
341
    $pb_percent++;
328
    update_status("Finishing package installation...");
342 329

  
343 330
    /*
344 331
     * parse the config file for this package and install neededtext items.
......
347 334
    if(file_exists("/usr/local/pkg/" . $pkgent['name'] . ".xml")) {
348 335
                $package_conf = parse_xml_config_pkg("/usr/local/pkg/" . $pkgent['name'] . ".xml", "packagegui");
349 336
                if($package_conf['modify_system']['item'] <> "") {
337
		    $static_output .= "Modifying system files... ";
338
		    update_output_window($static_output);
350 339
                    foreach ($package_conf['modify_system']['item'] as $ms) {
351
                        update_progress_bar($pb_percent);
352
                        $pb_percent += 10;
353 340
                        if($ms['textneeded']) {
354 341
                            add_text_to_file($ms['modifyfilename'],$ms['textneeded']);
355 342
                        }
356 343
                    }
344
		    $static_output .= "done.\n";
345
		    update_output_window($static_output);
357 346
                }
358 347

  
359 348
                /*
......
361 350
                 * and uncompress if needed.
362 351
                 */
363 352
                if ($package_conf['additional_files_needed'] <> "") {
353
		    $static_output .= "Downloading additional files needed for " . $pkgent['name'] . "... ";
354
                    update_output_window($static_output);
355
		    $i = 0;
356
		    $afn_count = count($package_conf['additional_files_needed']) -1;
364 357
                    foreach($package_conf['additional_files_needed'] as $afn) {
365
                        update_progress_bar($pb_percent);
366
                        $pb_percent += 10;
367 358
                        $filename = get_filename_from_url($afn['item'][0]);
368 359
                        fwrite($fd_log, "Downloading additional files needed for package " . $filename . " ...\n");
369
                        update_status("Downloading additional files needed for package " . $filename . " ...");
360
			if ($i == $afn_count) {
361
				$static_orig = $static_output . $filename . ".\n";
362
			} else {
363
				$static_orig = $static_output . $filename . ", ";
364
			}
365
			$static_output .= $filename . " ";
366
			update_output_window($static_output);
370 367
                        $prefix = "/usr/local/pkg/";
371 368
                        $pkg_chmod = "";
372 369
                        if($afn['chmod'] <> "")
373 370
                            $pkg_chmod = $afn['chmod'];
374 371
                        if($afn['prefix'] <> "")
375 372
                            $prefix = $afn['prefix'];
376
                        system("cd {$prefix} && /usr/bin/fetch " .  $afn['item'][0] . " 2>/dev/null");
373
                        download_file_with_progress_bar($afn['item'][0], $prefix . $filename);
374
			$static_output = $static_orig;
375
			update_output_window($static_output);
377 376
                        if(stristr($filename, ".tgz") <> "") {
378 377
                            update_status("Extracting tgz archive to -C for " . $filename);
379 378
                            fwrite($fd_log, "Extracting tgz archive to -C for " . $filename . " ...\n");
......
384 383
                            chmod($prefix . $filename, $pkg_chmod);
385 384
                            system("/bin/chmod {$pkg_chmod} {$prefix}{$filename}");
386 385
                        }
386
		        $i++;
387 387
                    }
388 388
                }
389 389

  
......
391 391
                 * loop through menu installation items
392 392
                 * installing multiple items if need be.
393 393
                */
394
                if(is_array($package_conf['menu']))
394
                if(is_array($package_conf['menu'])) {
395
		    $static_output .= "Installing menu items... ";
396
		    update_output_window($static_output);
395 397
                    foreach ($package_conf['menu'] as $menu) {
396 398
                        // install menu item into the ext folder
397 399
                        fwrite($fd_log, "Adding menu option to " . $menu['section'] . "/" . $menu['name'] . "\n");
......
415 417
                        }
416 418
                        fclose($fd);
417 419
                    }
420
		    $static_output .= "done.\n";
421
		    update_output_window($static_output);
422
		}
418 423
    } else {
419 424
                update_output_window("WARNING! /usr/local/pkg/" . $pkgent['name'] . ".xml" . " does not exist!\n");
420 425
                fwrite($fd_log, "WARNING! /usr/local/pkg/" . $pkgent['name'] . ".xml" . " does not exist!\n");
421 426
    }
422 427
    fwrite($fd_log, "End of Package Manager installation session.\n");
423 428

  
424
    update_progress_bar($pb_percent);
425
    $pb_percent += 10;
426

  
427
    // return dependency list to output later.
429
    /* return dependency list to output later.
428 430
    $command = "TODELETE=`ls /var/db/pkg | grep " . $name . "` && /usr/sbin/pkg_info -r \$TODELETE | grep Dependency: | cut -d\" \" -f2";
429 431
    $dependencies = exec_command_and_return_text($command);
430 432
    if($dependencies == "")
431 433
        fwrite($fd_log, "Installed package " . $name);
432 434
    else
433 435
        fwrite($fd_log, "Installed package " . $name . " and the following dependencies:\n" . $dependencies);
434

  
435
    update_progress_bar($pb_percent);
436
    $pb_percent += 10;
436
    */
437 437

  
438 438
    if($package_conf['custom_php_install_command'] <> "") {
439
	$static_output .= "Executing post install commands... ";
440
	update_output_window($static_output);
439 441
	if($package_conf['custom_php_global_functions'] <> "")
440 442
	    if(php_check_syntax($package_conf['custom_php_global_functions'], $error_message) == false)
441 443
		eval($package_conf['custom_php_global_functions']);
442
        update_status("Executing post install commands...");
443 444
        fwrite($fd_log, "Executing post install commands...\n");
444 445
        $error_message = "";
445 446
        if($package_conf['custom_php_command_before_form'] <> "")
446 447
            if(php_check_syntax($package_conf['custom_php_command_before_form'], $error_message) == false)
447 448
                eval($package_conf['custom_php_command_before_form']);
448
        $pb_percent += 50;
449
        update_progress_bar(50);
450 449
        if(php_check_syntax($package_conf['custom_php_install_command'], $error_message) == false)
451 450
            eval($package_conf['custom_php_install_command']);
451
	$static_output .= "done.\n";
452
	update_output_window($static_output);
452 453
    }
453

  
454
    $pb_percent += 10;
455
    update_progress_bar($pb_percent);
456

  
457
    if ($pkgent['depends_on_package_base_url'] <> "" or $pkgent['pfsense_package_base_url'] <> "") {
458
        $status = exec_command_and_return_text("ls {$g['vardb_path']}/pkg | grep " . $package_to_verify);
459
        fwrite($fd_log, "ls {$g['vardb_path']}/pkg | grep " . $package_to_verify . "\n" . $status);
460
        if($status <> "") {
461
                    update_status("Package installation completed.");
462
                    fwrite($fd_log, "Package installation completed.\n");
463
                    log_error("Package " . $pkgent['name'] . " installation completed okay.");
464
                    update_progress_bar(100);
465
        } else {
466
                    update_status("Package WAS NOT installed properly.");
467
                    update_output_window("Package WAS NOT installed properly.");
468
                    fwrite($fd_log, "Package WAS NOT installed properly.\n");
469
                    log_error("Package " . $pkgent['name'] . " did not install correctly.");
470
                    update_progress_bar(100);
471
        }
472
    } else {
473
        update_status("Package installation completed.");
474
        fwrite($fd_log, "Package installation completed.\n");
475
    }
476

  
477
    update_progress_bar(100);
478

  
454
    update_status("Package installation completed.");
455
    $static_output .= "\nPackage installation successful.";
456
    update_output_window($static_output);
457
    fwrite($fd_log, "Package installation completed.\n");
458
    log_error("Package " . $pkgent['name'] . " installation completed okay.");
479 459
}
480 460

  
481 461
// close log

Also available in: Unified diff