function install_required_packages() % install_required_packages() % Install packages required to build Techunited software % % Written by M. Briegel, Eindhoven, 2-Feb-2020 %% Parameters required_packages = { 'gcc-4.7'; 'g++-4.7'; 'libjson0'; 'libjson0-dev'; 'cmake'; 'flex;'; 'glade'; 'automake'; 'openssh-server'; 'libcv-dev'; 'libcvaux-dev'; 'libhighgui-dev'; 'ffmpeg'; 'libusb-1.0-0-dev'; 'bison'; 'valgrind'; 'ccache'; 'gconf-editor'; 'nfs-common'; 'zlib1g-dev'; 'openjdk-8-jre-headless'; 'libpng12-dev'; 'libjson0-dev'; 'gksu'; 'libsdl-image1.2'; 'cpufrequtils'; 'libssl-dev'; 'libxml2'; 'libxml2-dev' }; %% Identify packages that need to be installed missing_packages = {}; for idx = 1 : length(required_packages) package = required_packages{idx}; % Check if packages is installed cmd = ['dpkg -l ', package]; [ret, ~] = system(cmd); % If not add it to list of packages that need to be installed if ret ~= 0 missing_packages = [missing_packages; package]; end end % Give feedback to the user if isempty(missing_packages) fprintf('All required packages are installed!\n'); return; else fprintf('The following packages need to be installed:\n'); for idx = 1 : length(missing_packages) fprintf('- %s\n', missing_packages{idx}); end end %% Install missing packages % Ping Google DNS server to determine if we are connected to the internet [ret, ~] = system('ping -c 1 -w 1 8.8.8.8'); if ret ~= 0 fprintf('WARNING: No connection to the internet!\nCannot install all required packages! The build can possibly fail!\n'); return; end % Update package database [ret, output] = system('apt update'); if ret ~= 0 fprintf('Error while updating apt database!\n%s\n\nWill not attempt to install missing packages!\n', output); return; end % Install missing packages n_packages_installed = 0; for idx = 1 : length(missing_packages) package = missing_packages{idx}; cmd = ['apt -y install ', package]; [ret, ~] = system(cmd); if ret ~= 0 fprintf('Error while installing package ''%s''! Please try to install it manually!\n', package); continue; end n_packages_installed = n_packages_installed + 1; end %% Check if all packages were installed if n_packages_installed == length(missing_packages) fprintf('All missing packages were installed successfully!\n'); else fprintf('The installation of %d packages failed (see output above)!\n', ... length(missing_packages) - n_packages_installed); end end