Commit c5f6e021 authored by Michael Pyne's avatar Michael Pyne

Merge branch 'kogiokka/kdesrc-build-first-run' into master

Closes !55, which has diverged from master since I've been able to
approve it.
parents f627779e f1bb8066
Pipeline #29239 passed with stage
in 2 minutes and 13 seconds
...@@ -29,27 +29,33 @@ environments as fielded in "minimal Docker container" forms of popular distros. ...@@ -29,27 +29,33 @@ environments as fielded in "minimal Docker container" forms of popular distros.
=cut =cut
use constant {
SHELL_RC_SNIPPET => <<'RC'
# kdesrc-build ##################################################
## Add kdesrc-build to PATH
export PATH="$HOME/kde/src/kdesrc-build:$PATH"
## Run projects built with kdesrc-build
function kdesrc-run
{
source "$HOME/kde/build/$1/prefix.sh" && "$HOME/kde/usr/bin/$@"
}
#################################################################
RC
};
sub setupUserSystem sub setupUserSystem
{ {
my $baseDir = shift; my $baseDir = shift;
my $os = ksb::OSSupport->new; my $os = ksb::OSSupport->new;
my %shellRcMap = ( my $envShell = $ENV{'SHELL'} // 'undefined';
'bash' => '.bashrc',
'zsh' => '.zshrc',
);
my $envShell = $ENV{'SHELL'} // '/bin/bash';
my $shellName = (split '/', $envShell)[-1]; 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 { eval {
_installSystemPackages($os); _installSystemPackages($os);
_setupBaseConfiguration($baseDir); _setupBaseConfiguration($baseDir);
_setupShellRcFile($rcName); _setupShellRcFile($shellName);
}; };
if (had_an_exception($@)) { if (had_an_exception($@)) {
...@@ -155,75 +161,79 @@ sub _getNumCoresForLowMemory ...@@ -155,75 +161,79 @@ sub _getNumCoresForLowMemory
sub _setupBaseConfiguration sub _setupBaseConfiguration
{ {
my $baseDir = shift; my $baseDir = shift;
my @knownLocations = ("$ENV{PWD}/kdesrc-buildrc", "$ENV{HOME}/.kdesrc-buildrc");
my $locatedFile = first { -e $_ } @knownLocations;
if (-e "kdesrc-buildrc" || -e "$ENV{HOME}/.kdesrc-buildrc") { if (defined $locatedFile) {
print colorize(<<DONE); print colorize(<<DONE);
b[-] You b[y[already have a configuration file]. b[*] You already have a configuration file: b[y[$locatedFile].
DONE DONE
} else { return;
print colorize(<<DONE); }
b[-] Installing b[sample configuration file]...
print colorize(<<DONE);
b[*] Creating b[sample configuration file]: b[y["$ENV{HOME}/.kdesrc-buildrc"]...
DONE DONE
my $sampleRc = $packages{'sample-rc'} or my $sampleRc = $packages{'sample-rc'} or
_throw("Embedded sample file missing!"); _throw("Embedded sample file missing!");
my $numCores = `nproc 2>/dev/null` || 4; my $numCores = `nproc 2>/dev/null` || 4;
my $numCoresLow = _getNumCoresForLowMemory($numCores); my $numCoresLow = _getNumCoresForLowMemory($numCores);
$sampleRc =~ s/%\{num_cores}/$numCores/g; $sampleRc =~ s/%\{num_cores}/$numCores/g;
$sampleRc =~ s/%\{num_cores_low}/$numCoresLow/g; $sampleRc =~ s/%\{num_cores_low}/$numCoresLow/g;
$sampleRc =~ s/%\{base_dir}/$baseDir/g; $sampleRc =~ s/%\{base_dir}/$baseDir/g;
open my $sampleFh, '>', "$ENV{HOME}/.kdesrc-buildrc" open my $sampleFh, '>', "$ENV{HOME}/.kdesrc-buildrc"
or _throw("Couldn't open new ~/.kdesrc-buildrc: $!"); or _throw("Couldn't open new ~/.kdesrc-buildrc: $!");
print $sampleFh $sampleRc print $sampleFh $sampleRc
or _throw("Couldn't write to ~/.kdesrc-buildrc: $!"); or _throw("Couldn't write to ~/.kdesrc-buildrc: $!");
close $sampleFh close $sampleFh
or _throw("Error closing ~/.kdesrc-buildrc: $!"); or _throw("Error closing ~/.kdesrc-buildrc: $!");
}
} }
sub _setupShellRcFile sub _setupShellRcFile
{ {
my $rc = shift; my $shellName = shift;
my $rcFilepath = "$ENV{HOME}/$rc"; my $rcFilepath = undef;
my $rcModified = 0; my $isAuto = 1;
my $tag = '# auto-generated by kdesrc-build initial setup: do not remove!';
if ($shellName eq 'bash') {
# Add kdesrc-build path to PATH if not already in there $rcFilepath = "$ENV{'HOME'}/.bashrc";
# Create kdesrc-run alias for more convenient program execution } elsif ($shellName eq 'zsh') {
if (!ksb::Util::fileHasLine($rcFilepath, $tag)) { if (defined $ENV{'ZDOTDIR'}) {
say colorize(<<DONE); $rcFilepath = "$ENV{'ZDOTDIR'}/.zshrc";
b[-] Amending your ~/$rc } else {
b[-] Add b[y[kdesrc-build] directory into PATH $rcFilepath = "$ENV{'HOME'}/.zshrc";
b[-] Create b[y[kdesrc-run] alias }
DONE } else {
open(my $rcFh, '>>', "$rcFilepath") or _throw("Couldn't open ~/$rc: $!"); say colorize(" b[*] Updating rc-file for shell 'y[b[$shellName]' is not supported.");
$isAuto = 0;
}
say $rcFh ''; if (defined $rcFilepath) {
say $rcFh "$tag"; $isAuto = ksb::Util::yesNoPrompt(colorize(" b[*] Update your b[y[$rcFilepath]?"));
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/$@"';
say $rcFh '}';
$rcModified = 1;
} }
if ($rcModified) { if ($isAuto) {
open(my $rcFh, '>>', "$rcFilepath") or _throw("Couldn't open $rcFilepath: $!");
say $rcFh '';
say $rcFh SHELL_RC_SNIPPET;
close($rcFh);
say colorize(<<DONE); say colorize(<<DONE);
b[-] Your b[y[~/$rc has been successfully setup]. - Added b[y[kdesrc-build] directory into PATH
- Added b[y[kdesrc-run] shell function
b[*] b[g[Shell rc-file is successfully setup].
DONE DONE
} else { } else {
say '';
say colorize(<<DONE); say colorize(<<DONE);
b[-] Your b[y[~/$rc is already setup]. b[*] You can manually configure your shell rc-file with the snippet below:
DONE DONE
say SHELL_RC_SNIPPET;
} }
} }
...@@ -313,13 +323,13 @@ intltool ...@@ -313,13 +323,13 @@ intltool
libboost_headers-devel libboost_headers-devel
libqt5-qtbase-common-devel libqt5-qtbase-common-devel
libqt5-qtbase-private-headers-devel libqt5-qtbase-private-headers-devel
libqt5-qtimageformats-devel libqt5-qtimageformats-devel
libQt5Core-private-headers-devel libQt5Core-private-headers-devel
libQt5DesignerComponents5 libQt5DesignerComponents5
libxml2-tools libxml2-tools
lmdb-devel lmdb-devel
make make
perl perl
perl(IO::Socket::SSL) perl(IO::Socket::SSL)
perl(JSON) perl(JSON)
perl(URI) perl(URI)
...@@ -347,7 +357,7 @@ pkgconfig(Qt5X11Extras) ...@@ -347,7 +357,7 @@ pkgconfig(Qt5X11Extras)
pkgconfig(Qt5XmlPatterns) pkgconfig(Qt5XmlPatterns)
pkgconfig(sm) pkgconfig(sm)
pkgconfig(wayland-server) pkgconfig(wayland-server)
pkgconfig(xcb-keysyms) pkgconfig(xcb-keysyms)
pkgconfig(xrender) pkgconfig(xrender)
polkit-devel polkit-devel
shared-mime-info shared-mime-info
...@@ -377,9 +387,9 @@ perl(IPC::Cmd) ...@@ -377,9 +387,9 @@ perl(IPC::Cmd)
perl(JSON::PP) perl(JSON::PP)
perl(URI) perl(URI)
perl(YAML::LibYAML) perl(YAML::LibYAML)
pkgconfig(dbus-1) pkgconfig(dbus-1)
pkgconfig(gbm) pkgconfig(gbm)
pkgconfig(gl) pkgconfig(gl)
pkgconfig(gstreamer-1.0) pkgconfig(gstreamer-1.0)
pkgconfig(libassuan) pkgconfig(libassuan)
pkgconfig(libattr) pkgconfig(libattr)
...@@ -425,13 +435,13 @@ gperf ...@@ -425,13 +435,13 @@ gperf
intltool intltool
lib64lmdb-devel lib64lmdb-devel
make make
perl(IO::Socket::SSL) perl(IO::Socket::SSL)
perl(IPC::Cmd) perl(IPC::Cmd)
perl(JSON::PP) perl(JSON::PP)
perl(URI) perl(URI)
perl(YAML::LibYAML) perl(YAML::LibYAML)
pkgconfig(dbus-1) pkgconfig(dbus-1)
pkgconfig(gl) pkgconfig(gl)
pkgconfig(gstreamer-1.0) pkgconfig(gstreamer-1.0)
pkgconfig(libattr) pkgconfig(libattr)
pkgconfig(libnm) pkgconfig(libnm)
......
...@@ -676,8 +676,8 @@ sub is_dir_empty ...@@ -676,8 +676,8 @@ sub is_dir_empty
return 1; return 1;
} }
# Takes in a string and returns 1 if that string exists somewhere in the # Takes in a string and returns 1 if that string exists somewhere in the
# path variable. # path variable.
sub isInPath sub isInPath
{ {
if (index($ENV{'PATH'}, $_[0]) != -1) { if (index($ENV{'PATH'}, $_[0]) != -1) {
...@@ -701,4 +701,13 @@ sub fileHasLine ...@@ -701,4 +701,13 @@ sub fileHasLine
return 0; return 0;
} }
sub yesNoPrompt {
my $msg = shift;
local $| = 1;
print "$msg (y/N) ";
chomp(my $answer = <STDIN>);
return lc($answer) eq 'y';
}
1; 1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment