diff --git a/modules/ksb/FirstRun.pm b/modules/ksb/FirstRun.pm index 9447912..0075200 100644 --- a/modules/ksb/FirstRun.pm +++ b/modules/ksb/FirstRun.pm @@ -1,542 +1,542 @@ package ksb::FirstRun 0.10; use 5.014; use strict; use warnings; use File::Spec qw(splitpath); use ksb::BuildException; use ksb::Debug qw(colorize); use ksb::OSSupport; use ksb::Util; =head1 NAME ksb::FirstRun =head1 DESCRIPTION Performs initial-install setup, implementing the C<--initial-setup> option. B This module is supposed to be loadable even under minimal Perl environments as fielded in "minimal Docker container" forms of popular distros. =head1 SYNOPSIS my $exitcode = ksb::FirstRun::setupUserSystem(); exit $exitcode; =cut sub setupUserSystem { my $baseDir = shift; my $os = ksb::OSSupport->new; my %shellRcMap = ( 'bash' => '.bashrc', 'zsh' => '.zshrc', ); my $envShell = $ENV{'SHELL'} // '/bin/bash'; my $shellName = (split '/', $envShell)[-1]; my $rcName = $shellRcMap{$shellName}; if (!defined($rcName)) { $rcName = '.bashrc'; say " - $envShell is not supported. Changes will go to ~/.bashrc."; } eval { _installSystemPackages($os); _setupBaseConfiguration($baseDir); _setupShellRcFile($rcName); }; if (had_an_exception($@)) { my $msg = $@->{message}; say colorize (" b[r[*] r[$msg]"); return 1; } return 0; } # Internal functions # Reads from the __DATA__ section below and dumps the contents in a hash keyed # by filename (the @@ part between each resource). my %packages; sub _readPackages { return \%packages if %packages; my $cur_file; my $cur_value; my $commit = sub { return unless $cur_file; $packages{$cur_file} = ($cur_value =~ s/ *$//r); $cur_value = ''; }; while(my $line = ) { next if $line =~ /^\s*#/ and $cur_file !~ /sample-rc/; chomp $line; my ($fname) = ($line =~ /^@@ *([^ ]+)$/); if ($fname) { $commit->(); $cur_file = $fname; } else { $cur_value .= "$line\n"; } } $commit->(); return \%packages; } sub _throw { my $msg = shift; die (make_exception('Setup', $msg)); } sub _installSystemPackages { my $os = shift; my $vendor = $os->vendorID; my $osVersion = $os->vendorVersion; print colorize(<> 8 == 0) { say colorize (" b[*] b[g[Looks like the necessary packages were successfully installed!]"); } else { say colorize (" r[b[*] Ran into an error with the installer!"); } } else { - say colorize (" r[b[*] Packages could not be installed, because kdesrc-build does not know your linux distribution."); + say colorize (" r[b[*] Packages could not be installed, because kdesrc-build does not know your distribution (" . $vendor .")"); } } sub _setupBaseConfiguration { my $baseDir = shift; if (-e "kdesrc-buildrc" || -e "$ENV{HOME}/.kdesrc-buildrc") { print colorize(</dev/null` || 4; $sampleRc =~ s/%\{num_cpus}/$numCpus/g; $sampleRc =~ s/%\{base_dir}/$baseDir/g; open my $sampleFh, '>', "$ENV{HOME}/.kdesrc-buildrc" or _throw("Couldn't open new ~/.kdesrc-buildrc: $!"); print $sampleFh $sampleRc or _throw("Couldn't write to ~/.kdesrc-buildrc: $!"); close $sampleFh or _throw("Error closing ~/.kdesrc-buildrc: $!"); } } sub _setupShellRcFile { my $rc = shift; my $rcFilepath = "$ENV{HOME}/$rc"; my $rcModified = 0; my $tag = '# auto-generated by kdesrc-build initial setup: do not remove!'; # Add kdesrc-build path to PATH if not already in there # Create kdesrc-run alias for more convenient program execution if (!ksb::Util::fileHasLine($rcFilepath, $tag)) { say colorize(<>', "$rcFilepath") or _throw("Couldn't open ~/$rc: $!"); say $rcFh ''; say $rcFh "$tag"; say $rcFh '# Add the kdesrc-build directory to the path'; say $rcFh 'export PATH="$HOME/kde/src/kdesrc-build:$PATH"'; say $rcFh '# Create alias for running software built with kdesrc-build'; say $rcFh 'kdesrc-run ()'; say $rcFh '{'; say $rcFh ' source "$HOME/kde/build/$1/prefix.sh" && "$HOME/kde/usr/bin/$1"'; say $rcFh '}'; $rcModified = 1; } if ($rcModified) { say colorize(<bestDistroMatch(@supportedDistros); say colorize (" Using installer for b[$bestVendor]"); my $version = $os->vendorVersion(); my @cmd; for my $opt ("$bestVendor/$version", "$bestVendor/unknown") { my $key = "cmd/install/$opt"; next unless exists $pkgsRef->{$key}; @cmd = split(' ', $pkgsRef->{$key}); last; } _throw("No installer for $bestVendor!") unless @cmd; # If not running as root already, add sudo unshift @cmd, 'sudo' if $> != 0; return @cmd; } sub _findBestVendorPackageList { my $os = shift; # Debian handles Ubuntu also my @supportedDistros = map { s{^pkg/([^/]+)/.*$}{$1}; $_ } grep { /^pkg\// } keys %{_readPackages()}; my $bestVendor = $os->bestDistroMatch(@supportedDistros); my $version = $os->vendorVersion(); say colorize (" Installing packages for b[$bestVendor]/b[$version]"); return _packagesForVendor($bestVendor, $version); } sub _packagesForVendor { my ($vendor, $version) = @_; my $packagesRef = _readPackages(); foreach my $opt ("pkg/$vendor/$version", "pkg/$vendor/unknown") { next unless exists $packagesRef->{$opt}; my @packages = split(' ', $packagesRef->{$opt}); return @packages; } return; } 1; __DATA__ @@ pkg/debian/unknown libyaml-libyaml-perl libio-socket-ssl-perl libjson-xs-perl git shared-mime-info cmake build-essential flex bison gperf libssl-dev intltool liburi-perl gettext @@ pkg/opensuse/unknown cmake docbook-xsl-stylesheets docbook_4 flex bison gettext-runtime gettext-tools giflib-devel git gperf intltool libboost_headers-devel libqt5-qtbase-common-devel libqt5-qtbase-private-headers-devel libqt5-qtimageformats-devel libQt5Core-private-headers-devel libQt5DesignerComponents5 libxml2-tools lmdb-devel make perl perl(IO::Socket::SSL) perl(JSON) perl(URI) perl(YAML::LibYAML) pkgconfig(libattr) pkgconfig(libical) pkgconfig(libpng) pkgconfig(libqrencode) pkgconfig(libudev) pkgconfig(libxml-2.0) pkgconfig(libxslt) pkgconfig(ModemManager) pkgconfig(NetworkManager) pkgconfig(openssl) pkgconfig(Qt5Core) pkgconfig(Qt5Multimedia) pkgconfig(Qt5Qml) pkgconfig(Qt5QuickControls2) pkgconfig(Qt5Script) pkgconfig(Qt5Svg) pkgconfig(Qt5UiTools) pkgconfig(Qt5WebKit) pkgconfig(Qt5WebKitWidgets) pkgconfig(Qt5X11Extras) pkgconfig(Qt5XmlPatterns) pkgconfig(sm) pkgconfig(wayland-server) pkgconfig(xcb-keysyms) pkgconfig(xrender) polkit-devel shared-mime-info @@ pkg/fedora/unknown bison boost-devel bzr cmake docbook-style-xsl docbook-utils doxygen flex gcc gcc-c++ gettext gettext-devel giflib-devel git gperf intltool libxml2 make pam-devel perl(IO::Socket::SSL) perl(IPC::Cmd) perl(JSON::PP) perl(URI) perl(YAML::LibYAML) pkgconfig(dbus-1) pkgconfig(gbm) pkgconfig(gl) pkgconfig(gstreamer-1.0) pkgconfig(libassuan) pkgconfig(libattr) pkgconfig(libnm) pkgconfig(libpng) pkgconfig(libqrencode) pkgconfig(libxml-2.0) pkgconfig(libxslt) pkgconfig(lmdb) pkgconfig(ModemManager) pkgconfig(openssl) pkgconfig(polkit-gobject-1) pkgconfig(sm) pkgconfig(wayland-client) pkgconfig(wayland-protocols) pkgconfig(xapian-core) pkgconfig(xcb-cursor) pkgconfig(xcb-ewmh) pkgconfig(xcb-keysyms) pkgconfig(xcb-util) pkgconfig(xfixes) pkgconfig(xrender) python shared-mime-info texinfo systemd-devel @@ pkg/mageia/unknown bison boost cmake docbook-style-xsl docbook-utils flex gcc gcc-c++ gettext gettext-devel giflib git gperf intltool lib64lmdb-devel make perl(IO::Socket::SSL) perl(IPC::Cmd) perl(JSON::PP) perl(URI) perl(YAML::LibYAML) pkgconfig(dbus-1) pkgconfig(gl) pkgconfig(gstreamer-1.0) pkgconfig(libattr) pkgconfig(libnm) pkgconfig(libpng) pkgconfig(libqrencode) pkgconfig(libxml-2.0) pkgconfig(libxslt) pkgconfig(ModemManager) pkgconfig(openssl) pkgconfig(polkit-gobject-1) pkgconfig(sm) pkgconfig(wayland-client) pkgconfig(xcb-keysyms) pkgconfig(xrender) python shared-mime-info @@ pkg/gentoo/unknown dev-util/cmake dev-lang/perl @@ pkg/arch/unknown perl-json perl-yaml-libyaml perl-io-socket-ssl cmake gcc make qt5-base doxygen @@ pkg/alpine/unknown alpine-sdk attr-dev autoconf automake bison boost-dev cmake doxygen eudev-dev flex giflib-dev gperf gpgme-dev grantlee-dev gstreamer-dev gst-plugins-base-dev libdmtx-dev libepoxy-dev libgcrypt-dev libinput-dev libqrencode-dev libxkbfile-dev libxrender-dev libxtst-dev linux-pam-dev lmdb-dev networkmanager-dev perl perl-io-socket-ssl perl-uri perl-yaml-libyaml polkit-elogind-dev qt5-qtbase-dev qt5-qtdeclarative-dev qt5-qtquickcontrols2-dev qt5-qtscript-dev qt5-qtsensors-dev qt5-qtsvg-dev qt5-qttools-dev qt5-qttools-static qt5-qtwayland-dev qt5-qtx11extras-dev texinfo wayland-protocols xapian-core-dev xcb-util-cursor-dev xcb-util-image-dev xcb-util-keysyms-dev xcb-util-wm-dev @@ cmd/install/debian/unknown apt-get -q -y --no-install-recommends install @@ cmd/install/opensuse/unknown zypper install -y --no-recommends @@ cmd/install/arch/unknown pacman -Syu --noconfirm --needed @@ cmd/install/fedora/unknown dnf -y install @@ cmd/install/alpine/unknown apk add @@ sample-rc # This file controls options to apply when configuring/building modules, and # controls which modules are built in the first place. # List of all options: https://go.kde.org/u/ksboptions global # Paths kdedir ~/kde/usr # Where to install KF5-based software qtdir ~/kde/qt5 # Where to find Qt5 source-dir ~/kde/src # Where sources are downloaded build-dir ~/kde/build # Where the source build is run ignore-kde-structure true # Use flat structure # Will pull in KDE-based dependencies only, to save you the trouble of # listing them all below include-dependencies true cmake-options -DCMAKE_BUILD_TYPE=RelWithDebInfo make-options -j%{num_cpus} end global # With base options set, the remainder of the file is used to define modules to build, in the # desired order, and set any module-specific options. # # Modules may be grouped into sets, and this is the normal practice. # # You can include other files inline using the "include" command. We do this here # to include files which are updated with kdesrc-build. # Qt and some Qt-using middleware libraries include %{base_dir}/qt5-build-include include %{base_dir}/custom-qt5-libs-build-include # KF5 and Plasma :) include %{base_dir}/kf5-qt5-build-include # To change options for modules that have already been defined, use an # 'options' block options kcoreaddons make-options -j4 end options