Chameleon

Chameleon Svn Source Tree

Root/branches/blackosx/package/Scripts.templates/Pre/clean_bootplist.pl

  • Property svn:executable set to *
1#!/usr/bin/perl
2
3use strict;
4use YAML::Syck;
5
6our $target_volume;
7our $boot_plist_filepath;
8our $logfile;
9
10our $yaml_file="@YAML_FILE@";
11
12if ($#ARGV < 0) {
13 print stderr "A target volume is needed\n";
14} else {
15 $target_volume=$ARGV[0];
16 $logfile=$ARGV[1];
17}
18
19$boot_plist_filepath = "${target_volume}/Extra/org.chameleon.Boot.plist";
20if ( -f "$boot_plist_filepath" ) {
21 main("$yaml_file");
22}
23
24sub _do_cmd {
25 my ($cmd, $key, $value) = @_;
26 my $out;
27 $key =~ s/([\s])/\\$1/g; # Escape characters in key
28 $value =~ s/([\s"])/\\$1/g; # Escape characters in value (space & ")
29 my $plistbuddy_command="$cmd :$key $value";
30 open ( OUTPUT, "-|", '/usr/libexec/plistbuddy', "-c", "$plistbuddy_command", "$boot_plist_filepath" );
31 my $exit_code = $?;
32 chomp($out = <OUTPUT>);
33 close OUTPUT;
34 return $out;
35}
36
37sub get_boot_plist_option {
38 my ($option) = @_;
39 return _do_cmd( "Print", "$option");
40}
41
42sub delete_boot_plist_option {
43 my ($option) = @_;
44 my $current_value = get_boot_plist_option "$option";
45 if ( $current_value ne "") {
46 print LOG "$option\n";
47 return _do_cmd( "Delete", "$option");
48 }
49 return "";
50}
51
52sub delete_boot_plist_text_option {
53 my ($option, $values) = @_;
54 my $current_value = get_boot_plist_option "$option";
55 if ( $current_value ne "") {
56 foreach my $recognized_value (@{$values}) {
57 if ($recognized_value eq $current_value) {
58 print LOG "$option $current_value\n";
59 return _do_cmd( "Delete", "$option");
60 }
61 }
62 }
63 return "";
64}
65
66sub delete_boot_plist_list_option {
67 my ($option, $values) = @_;
68 my $current_value = get_boot_plist_option "$option";
69 if ( $current_value ne "") {
70 my %count;
71 my @new_list;
72 foreach my $value (@{$values}) {
73 $count{$value} = 1;
74 }
75 foreach my $value (split(/\s+/,$current_value)) {
76 print LOG "$option $value\n";
77 if ( not exists $count{$value} ) {
78 push @new_list, $value;
79 }
80 }
81 return _do_cmd( "Set", $option, join(' ',@new_list) );
82 }
83 return "";
84}
85
86sub main() {
87 # Remove all options that installer can manage
88 open (LOG,">>$logfile");
89 my ($yaml_file) = @_;
90 my $hash_ref = LoadFile($yaml_file) or die "Can't open yaml file\n";
91 foreach my $option ( keys %{$hash_ref} ) {
92 my $type = $hash_ref->{$option}->{type};
93 if ( $type =~ /^bool$/i ) {
94 delete_boot_plist_option($option);
95 } elsif ( $type =~ /^text$/i ) {
96 delete_boot_plist_text_option( $option,
97 $hash_ref->{$option}->{values} );
98 } elsif ( $type =~ /^list$/i ) {
99 delete_boot_plist_list_option( $option,
100 $hash_ref->{$option}->{values} );
101 }
102 }
103 close(LOG);
104}
105

Archive Download this file

Revision: HEAD