diff options
author | S. Davilla <davilla@4pi.com> | 2011-04-11 13:00:28 -0400 |
---|---|---|
committer | S. Davilla <davilla@4pi.com> | 2011-04-12 18:19:24 -0400 |
commit | 3c39e45375ef23099572a4cbbd1e8d2f6869c82b (patch) | |
tree | 8529de20be6632a6ba8ed48662e40619d0b610cb /tools/darwin/runtime/preflight | |
parent | 1b4f11c4f023893ef3cddf0fe863da8e67f9373d (diff) |
[osx/ios] refactor depends build system to use config.site, for testing only right now
Diffstat (limited to 'tools/darwin/runtime/preflight')
-rwxr-xr-x | tools/darwin/runtime/preflight | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/tools/darwin/runtime/preflight b/tools/darwin/runtime/preflight new file mode 100755 index 0000000000..e1fa21081c --- /dev/null +++ b/tools/darwin/runtime/preflight @@ -0,0 +1,176 @@ +#!/usr/bin/perl + +die("No HOME set, cannot install defaults.\n") + if !$ENV{HOME}; + +die("No XBMC_HOME set, cannot install defaults.\n") + if !$ENV{'XBMC_HOME'}; + +sub get_home { + return $ENV{'HOME'} if defined $ENV{'HOME'}; +} + +sub get_extras { + # XBMC_HOME is assumed to be always setup + return $ENV{'XBMC_HOME'}."/extras/" if get_os() eq "osx"; + return; +} + +sub get_xbmc_home { + my $os = get_os(); + my $home = get_home(); + return if !defined $home; + if ( $os eq "osx" ) { + return $home."/Library/Application Support/XBMC"; + } + elsif ( $os eq "linux" ) { + return $home."/.xbmc"; + } + return; +} + +sub get_os { + if ( defined $ENV{'OSTYPE'} && $ENV{'OSTYPE'} =~ /linux/ ) { + return "linux"; + } + return "osx"; +} + +sub get_userdata_path { + my $xhome = get_xbmc_home(); + return if !defined $xhome; + return "$xhome/userdata"; +} + +sub setup_sources { + my $xbmchome = get_xbmc_home(); + my $userdata = get_userdata_path(); + my $sources = $userdata."/sources.xml"; + + # check whether a sources.xml already exists, and if it does back it up + if ( -f $sources ) { + print STDERR "sources.xml found at \"$sources\", backing up\n"; + my $backup_sources = $sources.".".time().".xml"; + `cp -f \"$sources\" \"$backup_sources\"`; + } + + # construct a sources.xml string + my $sources_xml = get_sources_xml( get_default_sources() ); + if ( $sources_xml ) { + open SOURCES, ">$sources" || exit; + print SOURCES get_sources_xml( get_default_sources() ); + close SOURCES; + } +} + +sub get_sources_xml { + my $sources = shift; + my ($sourcetype, $source); + + return if !defined $sources; + + my $xml = "<sources>\n"; + while ( ($sourcetype, $source) = each ( %$sources ) ) { + $xml .= (" " x 4)."<$sourcetype>\n"; + $xml .= (" " x 8)."<default></default>\n"; + my ($name, $path); + while ( ($name, $path) = each( %{ $source } ) ) { + $xml .= (" " x 8)."<source>\n"; + $xml .= (" " x 12)."<name>$name</name>\n"; + if ( $path =~ /(.*)\^\^(.*)/ ) { + $xml .= (" " x 12)."<path>".$1."</path>\n"; + $xml .= (" " x 12)."<thumbnail>".$2."</thumbnail>\n"; + } + else { + $xml .= (" " x 12)."<path>".$path."</path>\n"; + } + $xml .= (" " x 8)."</source>\n"; + } + $xml .= (" " x 4)."</$sourcetype>\n"; + } + $xml .= "</sources>\n"; + return $xml; +} + +sub get_default_sources { + my $sources = {}; + my $home = get_home(); + my $xbmchome = get_xbmc_home(); + return if !defined $xbmchome; + + $sources->{'programs'} = {}; + $sources->{'video'} = {}; + $sources->{'music'} = {}; + $sources->{'pictures'} = {}; + $sources->{'files'} = {}; + + if ( get_os() eq "osx" ) { + + # Default sources for OS X + $sources->{'music'}->{'Music'} = $home."/Music"; + $sources->{'music'}->{'Music Playlists'} = "special://musicplaylists"; + $sources->{'video'}->{'Movies'} = $home."/Movies"; + $sources->{'video'}->{'Video Playlists'} = "special://videoplaylists"; + $sources->{'pictures'}->{'Pictures'} = $home."/Pictures"; + } + elsif ( get_os() eq "linux" ) { + + # Default source for Linux + for my $key ( keys %$sources ) { + $sources->{$key}->{'Media'} = "/media"; + $sources->{$key}->{'Home'} = "$home"; + $sources->{$key}->{'Desktop'} = "$home/Desktop"; + $sources->{$key}->{'Root'} = "/"; + } + } + return $sources; +} + +sub first_xbmc_run() { + my $home = get_xbmc_home(); + if ( ! -f "$home/.setup_complete" ) { + return 1; + } + return; +} + +sub first_xbmc_version_run() { + my $home = get_xbmc_home(); + if ( ! -f "$home/.setup_complete" ) { + return 1; + } + return; +} + +sub setup_default_xbmc() { + my $extras = get_extras(); + my $xhome = get_xbmc_home(); + my $userdata = get_userdata_path(); + + die("No extras :(\n") + if !defined $extras; + die("No XBMC home folder :(\n") + if !defined $xhome; + die ("No userdata folder :(\n") + if !defined $userdata; + + # create userdata directory if it doesn't exist + `mkdir -p "$userdata"`; + # copy extra stuff to xbmc's userdata directory + `cp -fRv "$extras/user/" "$userdata"`; + + setup_sources(); + `touch -f "$xhome/.setup_complete"`; +} + +sub setup_version_xbmc() { + #TODO +} + +if (first_xbmc_run()) { + setup_default_xbmc(); +} + +if (first_xbmc_version_run()) { + setup_version_xbmc(); +} |