From f194cdaff724e081611fd3cdfff458f1ca2d9c75 Mon Sep 17 00:00:00 2001 From: sakaki Date: Wed, 11 Nov 2015 18:45:24 +0000 Subject: [PATCH] Fix check_gcc_config_and_reset_if_necessary fn Previously tried to run gcc to get version number, which fails when the gcc config is invalid... --- buildkernel | 26 +++++++++++++++++++++++--- buildkernel.8 | 2 +- buildkernel.conf.5 | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/buildkernel b/buildkernel index 8665f0d..f7742d4 100755 --- a/buildkernel +++ b/buildkernel @@ -31,7 +31,7 @@ shopt -s nullglob # ********************** variables ********************* PROGNAME="$(basename "${0}")" CONFFILE="/etc/${PROGNAME}.conf" -VERSION="1.0.12" +VERSION="1.0.13" ETCPROFILE="/etc/profile" DEFAULTEFIBOOTFILE="bootx64.efi" EFIBOOTFILE="${DEFAULTEFIBOOTFILE}" @@ -116,6 +116,7 @@ USE_PLYMOUTH=true VERBOSITYFLAG="" ASKFLAG="" ALERTFLAG="" +PORTAGEINFO="" # following array variables set by find_all_gpg_keyfile_partitions function declare -a GPGUUIDS GPGPARTNAMES GPGDEVNAMES GPGPARTNUMS # following array variables set by find_all_luks_partitions function @@ -249,14 +250,33 @@ check_file_exists() { die "File '${1}' does not exist" fi } +read_portage_info_if_necessary() { + if [ -z "${PORTAGEINFO}" ]; then + show "Checking Portage configuration, please wait..." + PORTAGEINFO="$(emerge --info)" + fi +} check_gcc_config_and_reset_if_necessary() { # check if gcc-config exists with an error - if it does, then # attempt to set one based on the current gcc version number if ! gcc-config --get-current-profile >/dev/null 2>&1; then # unset or invalid, attempt to force this to the current gcc # version - local GCC_VERSION="$(gcc --version | head -n 1 | sed 's/^.* //')" - if gcc-config "${GCC_VERSION}"; then + read_portage_info_if_necessary + local CHOST="$(grep '^CHOST=.*' <<<"${PORTAGEINFO}")" + CHOST="$(cut -d\" -f2 <<< ${CHOST})" + local GCC_VERSION="" + # can't be sure we have eix installed + if eix --version >/dev/null 2>&1; then + # we do, so can cleanly check latest installed gcc version + GCC_VERSION="$(eix --installed --exact sys-devel/gcc --format '' --versionsort | tail -n 1)" + GCC_VERSION="${GCC_VERSION##*gcc-}" + else + # we don't, have to hack the most recent gcc version + GCC_VERSION="$(ls -1v "/usr/${CHOST}/gcc-bin" | tail -n 1)" + fi + local FULL_GCC_ID="${CHOST}-${GCC_VERSION}" + if gcc-config "${FULL_GCC_ID}"; then warning "gcc configuration was reset" if [ -s "${ETCPROFILE}" ]; then set +e diff --git a/buildkernel.8 b/buildkernel.8 index 545b154..dc89ea2 100644 --- a/buildkernel.8 +++ b/buildkernel.8 @@ -1,4 +1,4 @@ -.TH BUILDKERNEL 8 "Version 1.0.12: August 2015" +.TH BUILDKERNEL 8 "Version 1.0.13: November 2015" .SH NAME buildkernel \- build secure boot kernel, save to EFI system partition .SH SYNOPSIS diff --git a/buildkernel.conf.5 b/buildkernel.conf.5 index 10342d4..5cced04 100644 --- a/buildkernel.conf.5 +++ b/buildkernel.conf.5 @@ -1,4 +1,4 @@ -.TH BUILDKERNEL 5 "Version 1.0.12: August 2015" +.TH BUILDKERNEL 5 "Version 1.0.13: November 2015" .SH NAME buildkernel.conf \- a configuration file for \fBbuildkernel\fR(8) .SH SYNOPSIS