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.
=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
{
my $baseDir = shift;
my $os = ksb::OSSupport->new;
my %shellRcMap = (
'bash' => '.bashrc',
'zsh' => '.zshrc',
);
my $envShell = $ENV{'SHELL'} // '/bin/bash';
my $envShell = $ENV{'SHELL'} // 'undefined';
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);
_setupShellRcFile($shellName);
};
if (had_an_exception($@)) {
......@@ -155,75 +161,79 @@ sub _getNumCoresForLowMemory
sub _setupBaseConfiguration
{
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);
b[-] You b[y[already have a configuration file].
b[*] You already have a configuration file: b[y[$locatedFile].
DONE
} else {
print colorize(<<DONE);
b[-] Installing b[sample configuration file]...
return;
}
print colorize(<<DONE);
b[*] Creating b[sample configuration file]: b[y["$ENV{HOME}/.kdesrc-buildrc"]...
DONE
my $sampleRc = $packages{'sample-rc'} or
_throw("Embedded sample file missing!");
my $sampleRc = $packages{'sample-rc'} or
_throw("Embedded sample file missing!");
my $numCores = `nproc 2>/dev/null` || 4;
my $numCoresLow = _getNumCoresForLowMemory($numCores);
my $numCores = `nproc 2>/dev/null` || 4;
my $numCoresLow = _getNumCoresForLowMemory($numCores);
$sampleRc =~ s/%\{num_cores}/$numCores/g;
$sampleRc =~ s/%\{num_cores_low}/$numCoresLow/g;
$sampleRc =~ s/%\{base_dir}/$baseDir/g;
$sampleRc =~ s/%\{num_cores}/$numCores/g;
$sampleRc =~ s/%\{num_cores_low}/$numCoresLow/g;
$sampleRc =~ s/%\{base_dir}/$baseDir/g;
open my $sampleFh, '>', "$ENV{HOME}/.kdesrc-buildrc"
or _throw("Couldn't open new ~/.kdesrc-buildrc: $!");
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: $!");
print $sampleFh $sampleRc
or _throw("Couldn't write to ~/.kdesrc-buildrc: $!");
close $sampleFh
or _throw("Error closing ~/.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(<<DONE);
b[-] Amending your ~/$rc
b[-] Add b[y[kdesrc-build] directory into PATH
b[-] Create b[y[kdesrc-run] alias
DONE
open(my $rcFh, '>>', "$rcFilepath") or _throw("Couldn't open ~/$rc: $!");
my $shellName = shift;
my $rcFilepath = undef;
my $isAuto = 1;
if ($shellName eq 'bash') {
$rcFilepath = "$ENV{'HOME'}/.bashrc";
} elsif ($shellName eq 'zsh') {
if (defined $ENV{'ZDOTDIR'}) {
$rcFilepath = "$ENV{'ZDOTDIR'}/.zshrc";
} else {
$rcFilepath = "$ENV{'HOME'}/.zshrc";
}
} else {
say colorize(" b[*] Updating rc-file for shell 'y[b[$shellName]' is not supported.");
$isAuto = 0;
}
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/$@"';
say $rcFh '}';
$rcModified = 1;
if (defined $rcFilepath) {
$isAuto = ksb::Util::yesNoPrompt(colorize(" b[*] Update your b[y[$rcFilepath]?"));
}
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);
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
} else {
say '';
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
say SHELL_RC_SNIPPET;
}
}
......@@ -313,13 +323,13 @@ intltool
libboost_headers-devel
libqt5-qtbase-common-devel
libqt5-qtbase-private-headers-devel
libqt5-qtimageformats-devel
libqt5-qtimageformats-devel
libQt5Core-private-headers-devel
libQt5DesignerComponents5
libQt5DesignerComponents5
libxml2-tools
lmdb-devel
make
perl
perl
perl(IO::Socket::SSL)
perl(JSON)
perl(URI)
......@@ -347,7 +357,7 @@ pkgconfig(Qt5X11Extras)
pkgconfig(Qt5XmlPatterns)
pkgconfig(sm)
pkgconfig(wayland-server)
pkgconfig(xcb-keysyms)
pkgconfig(xcb-keysyms)
pkgconfig(xrender)
polkit-devel
shared-mime-info
......@@ -377,9 +387,9 @@ perl(IPC::Cmd)
perl(JSON::PP)
perl(URI)
perl(YAML::LibYAML)
pkgconfig(dbus-1)
pkgconfig(dbus-1)
pkgconfig(gbm)
pkgconfig(gl)
pkgconfig(gl)
pkgconfig(gstreamer-1.0)
pkgconfig(libassuan)
pkgconfig(libattr)
......@@ -425,13 +435,13 @@ gperf
intltool
lib64lmdb-devel
make
perl(IO::Socket::SSL)
perl(IO::Socket::SSL)
perl(IPC::Cmd)
perl(JSON::PP)
perl(JSON::PP)
perl(URI)
perl(YAML::LibYAML)
perl(YAML::LibYAML)
pkgconfig(dbus-1)
pkgconfig(gl)
pkgconfig(gl)
pkgconfig(gstreamer-1.0)
pkgconfig(libattr)
pkgconfig(libnm)
......
......@@ -676,8 +676,8 @@ sub is_dir_empty
return 1;
}
# Takes in a string and returns 1 if that string exists somewhere in the
# path variable.
# Takes in a string and returns 1 if that string exists somewhere in the
# path variable.
sub isInPath
{
if (index($ENV{'PATH'}, $_[0]) != -1) {
......@@ -701,4 +701,13 @@ sub fileHasLine
return 0;
}
sub yesNoPrompt {
my $msg = shift;
local $| = 1;
print "$msg (y/N) ";
chomp(my $answer = <STDIN>);
return lc($answer) eq 'y';
}
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