You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

linux-install_dependencies.pl 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #!/usr/bin/perl
  2. =pod
  3. This script will install dependencies for OpenViBE SDK.
  4. The installer uses the native package manager.
  5. Currently supported Linux Distributions are:
  6. - Ubuntu 14.04 LTS
  7. - Ubuntu 16.04 LTS
  8. Operating on the specified manifest folder,
  9. 1) Carries out preliminary steps by running scripts matching
  10. ^linux-preinstall-.*pl from linux-dep-helpers/
  11. 2) Installs packages from distro-specific files
  12. (like linux-dependencies-ubuntu1404.txt)
  13. 3) May compile/fetch packages with perl scripts matching
  14. ^linux-compile-.*pl from linux-dep-helpers/
  15. n.b. The script globs all .pl scripts present that match the prefixes. If you don't want some dependency, remove the corresponding script.
  16. =cut
  17. use strict;
  18. use English;
  19. use FindBin;
  20. use File::Copy;
  21. use File::Spec;
  22. use Getopt::Long;
  23. sub usage {
  24. print "$0 [-h][-y]\n";
  25. print "Install OpenViBE SDK build dependencies\n";
  26. print " Options:\n";
  27. print " -h: this help\n";
  28. print " -y: assume 'yes' to all prompts. Make it possible to run non-interactively.\n";
  29. print " --no-gtest: will not compile gtest if set.\n";
  30. print " --no-install: will not do any installation if set.\n";
  31. print " --dependencies-dir [folder]: path to the dependencies\n";
  32. print " --manifest-dir [folder]: path to the manifest files (default: scripts folder/linux-dep-helpers/)\n";
  33. };
  34. my $assume_yes = 0;
  35. my $no_gtest = 0;
  36. my $no_install = 0;
  37. my $manifest_dir = "$FindBin::Bin";
  38. my $print_help = 0;
  39. my $dependencies_dir = "$FindBin::Bin/../dependencies/";
  40. GetOptions (
  41. "assume-yes" => \$assume_yes,
  42. "y" => \$assume_yes,
  43. "dependencies-dir=s" => \$dependencies_dir,
  44. "manifest-dir=s" => \$manifest_dir,
  45. "h" => \$print_help,
  46. "help" => \$print_help,
  47. "no-install" => \$no_install,
  48. "no-gtest" => \$no_gtest)
  49. or usage() and die("Error in command line arguments\n");
  50. if($print_help) {
  51. usage();
  52. exit(1);
  53. }
  54. $dependencies_dir = File::Spec->rel2abs($dependencies_dir);
  55. my $dependencies_arch_dir = "$dependencies_dir/arch";
  56. my $helper_script_dir = "$manifest_dir/linux-dep-helpers/";
  57. if (! -e $dependencies_dir) {
  58. mkdir($dependencies_dir) or die("Failed to create directory [$dependencies_dir]");
  59. }
  60. if (! -e $dependencies_arch_dir) {
  61. mkdir($dependencies_arch_dir) or die("Failed to create directory [$dependencies_arch_dir]");
  62. }
  63. # Check for the release version and set the update and install commands
  64. my $unsupported_distribution = 'Unsupported';
  65. my $distribution = $unsupported_distribution;
  66. my $update_packages_command = '';
  67. my $package_install_command = '';
  68. my $add_repository_command = '';
  69. my $os_release = `cat /etc/os-release`;
  70. # Check for NAME= and VERSION_ID=
  71. # Take into account distros placing quotes around values
  72. my ($lsb_distributor, $lsb_release) = ($os_release =~ m/NAME=["'\`]*([a-zA-Z]+).*VERSION_ID=["'\`]*([0-9.]+)/s);
  73. if ($lsb_distributor =~ 'Ubuntu') {
  74. if (!$no_install) {
  75. $update_packages_command = 'sudo apt-get update';
  76. if ($assume_yes) {
  77. $package_install_command = 'sudo apt-get -y install';
  78. $add_repository_command = 'sudo add-apt-repository -y universe';
  79. } else {
  80. $package_install_command = 'sudo apt-get install';
  81. $add_repository_command = 'sudo add-apt-repository universe';
  82. }
  83. }
  84. if ($lsb_release =~ '14.04'
  85. || $lsb_release =~ '16.04'
  86. || $lsb_release =~ '18.04'
  87. || $lsb_release =~ '19.10') {
  88. $distribution = 'Ubuntu ' . $lsb_release;
  89. }
  90. } elsif ($lsb_distributor =~ 'Fedora') {
  91. if (!$no_install) {
  92. if ($assume_yes) {
  93. $package_install_command = 'sudo dnf -y install';
  94. } else {
  95. $package_install_command = 'sudo dnf install';
  96. }
  97. }
  98. $distribution = 'Fedora';
  99. }
  100. $distribution eq $unsupported_distribution and die('This distribution is unsupported');
  101. print "Installing dependencies for: $distribution\n";
  102. print "Install command: $package_install_command\n";
  103. # Perform steps before installing packages
  104. opendir(my $dir_handle, $helper_script_dir) or die("unable to open $helper_script_dir");
  105. while(my $filename = readdir($dir_handle)) {
  106. if($filename =~ /^linux-preinstall.*pl/) {
  107. open(my $pl_file_handle, '<', "$helper_script_dir/$filename")
  108. or die "Unable to open file, $helper_script_dir/$filename";
  109. undef $/;
  110. my $program = <$pl_file_handle>;
  111. eval " $program "; warn $@ if $@;
  112. }
  113. }
  114. closedir($dir_handle);
  115. # Create the list of packages to install
  116. my $pkg_file = "";
  117. if ($distribution eq 'Ubuntu 14.04') {
  118. $pkg_file = "$manifest_dir/linux-dependencies-ubuntu1404.txt";
  119. } elsif ($distribution =~ 'Ubuntu') {
  120. $pkg_file = "$manifest_dir/linux-dependencies-ubuntu16_plus.txt";
  121. } elsif ($distribution eq 'Fedora') {
  122. $pkg_file = "$manifest_dir/linux-dependencies-fedora.txt";
  123. }
  124. # Install actual packages
  125. print "Opening package manifest file $pkg_file ...\n";
  126. # read package list to memory
  127. open(my $pkg_file_handle, '<:encoding(UTF-8)', $pkg_file)
  128. or die "Unable to open file, $pkg_file";
  129. my @packages = ();
  130. local $INPUT_RECORD_SEPARATOR = "\n";
  131. for my $line (<$pkg_file_handle>) {
  132. $line =~ s/\r?\n$//;
  133. push @packages, $line;
  134. }
  135. close($pkg_file_handle) or warn "Unable to close $pkg_file";
  136. if (!$no_install) {
  137. # Update package list
  138. if ($add_repository_command) {
  139. print "Updating package database...\n";
  140. system($add_repository_command);
  141. ($CHILD_ERROR != 0) and die('Failed to add additional repositories');
  142. }
  143. if ($update_packages_command) {
  144. system($update_packages_command);
  145. ($CHILD_ERROR != 0) and die('Failed to update the package databases');
  146. }
  147. # Install the packages
  148. print "Will install following packages:\n";
  149. print (join ' ', @packages), "\n";
  150. my $pkgs = (join ' ', @packages);
  151. system("$package_install_command " . (join ' ', @packages));
  152. ($CHILD_ERROR != 0) and die('Failed to install the required packages');
  153. }
  154. # Obtain specific dependencies that we dont get from packages
  155. opendir(my $dir_handle, $helper_script_dir) or die("unable to open $helper_script_dir");
  156. while(my $filename = readdir($dir_handle)) {
  157. if($filename =~ /^linux-compile.*pl/) {
  158. print "Running $helper_script_dir/$filename ...\n";
  159. open(my $pl_file_handle, '<', "$helper_script_dir/$filename")
  160. or die "Unable to open file, $helper_script_dir/$filename";
  161. undef $/;
  162. my $program = <$pl_file_handle>;
  163. eval " $program "; warn $@ if $@;
  164. }
  165. }
  166. closedir($dir_handle);
  167. print("OpenViBE SDK dependencies were successfully installed\n");