2020-03-07 23:11:32 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
2020-12-29 21:21:17 +01:00
|
|
|
# This file is part of scripts.
|
|
|
|
|
|
|
|
# scripts is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2021-03-29 13:02:30 +02:00
|
|
|
# the Free Software Foundation, version 3.
|
2020-12-29 21:21:17 +01:00
|
|
|
|
|
|
|
# scripts is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with scripts. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2021-04-18 02:02:15 +02:00
|
|
|
# Original author: Maciej Barć <xgqt@riseup.net>
|
2020-12-22 01:52:05 +01:00
|
|
|
# Copyright (c) 2020, src_prepare group
|
2020-12-29 21:21:17 +01:00
|
|
|
# Licensed under the GNU GPL v3 License
|
2020-12-22 01:52:05 +01:00
|
|
|
|
2020-03-07 23:11:32 +01:00
|
|
|
# Source this to enter the Eprefix environment
|
|
|
|
# Like this for example:
|
|
|
|
# $ source $HOME/gentoo/eprefix-activate
|
|
|
|
|
|
|
|
|
|
|
|
# >>> Set eprefix
|
|
|
|
|
|
|
|
EPREFIX=${EPREFIX:-${HOME}/gentoo}
|
|
|
|
export EPREFIX
|
|
|
|
|
|
|
|
|
|
|
|
# >>> Funcion definitions
|
|
|
|
|
|
|
|
command_exists() {
|
2020-09-12 17:50:24 +02:00
|
|
|
if command -v "${1}" >/dev/null
|
2020-03-07 23:11:32 +01:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
2021-06-04 10:21:00 +02:00
|
|
|
return 1
|
2020-03-07 23:11:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if command_exists tput
|
|
|
|
then
|
|
|
|
eprefix_good="$(tput bold)$(tput setaf 2)*$(tput sgr0)"
|
|
|
|
eprefix_bad="$(tput bold)$(tput setaf 1)*$(tput sgr0)"
|
|
|
|
eprefix_warn="$(tput bold)$(tput setaf 3)*$(tput sgr0)"
|
|
|
|
else
|
|
|
|
eprefix_good="*"
|
|
|
|
eprefix_bad="*"
|
|
|
|
eprefix_warn="*"
|
|
|
|
fi
|
|
|
|
|
|
|
|
eprefix_addpath() {
|
|
|
|
if [ -d "${1}" ]
|
|
|
|
then
|
|
|
|
PATH=${1}:${PATH}
|
|
|
|
export PATH
|
|
|
|
else
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "%s\n" "${eprefix_warn} ${1} not found" >> /dev/stderr
|
2020-03-07 23:11:32 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
eprefix_addman() {
|
|
|
|
if [ -d "${1}" ]
|
|
|
|
then
|
|
|
|
MANPATH=${1}:${MANPATH}
|
|
|
|
export MANPATH
|
|
|
|
else
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "%s\n" "${eprefix_warn} ${1} not found" >> /dev/stderr
|
2020-03-07 23:11:32 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
eprefix_packages() {
|
|
|
|
if [ -d "${EPREFIX}/var/db/pkg" ]
|
|
|
|
then
|
|
|
|
find "${EPREFIX}"/var/db/pkg/*/* -type d | wc -l
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
eprefix_world() {
|
|
|
|
if [ -f "${EPREFIX}/var/lib/portage/world" ]
|
|
|
|
then
|
|
|
|
wc -l < "${EPREFIX}/var/lib/portage/world"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# >>> Checks
|
|
|
|
|
2020-09-12 17:50:24 +02:00
|
|
|
# Exit if script is not sourced
|
2020-12-21 23:51:51 +01:00
|
|
|
case ${-} in
|
|
|
|
*i* )
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
* )
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "%s\n" \
|
|
|
|
"${eprefix_bad} Error: not a login shell" \
|
|
|
|
"${eprefix_bad} Run: source ${0}" \
|
|
|
|
">>> Exiting the shell" >> /dev/stderr
|
2020-12-21 23:51:51 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2020-09-12 17:50:24 +02:00
|
|
|
|
2020-03-07 23:11:32 +01:00
|
|
|
# Exit if eprefix does not exist
|
|
|
|
if [ ! -d "${EPREFIX}" ]
|
|
|
|
then
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "%s\n" \
|
|
|
|
"${eprefix_bad} No ${EPREFIX} found!" \
|
|
|
|
">>> Exiting the shell" >> /dev/stderr
|
2020-03-07 23:11:32 +01:00
|
|
|
sleep 3
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# >>> PATH setup
|
|
|
|
|
|
|
|
# Add directories to PATH
|
|
|
|
eprefix_addpath "${EPREFIX}/bin"
|
|
|
|
eprefix_addpath "${EPREFIX}/opt/bin"
|
|
|
|
eprefix_addpath "${EPREFIX}/sbin"
|
|
|
|
eprefix_addpath "${EPREFIX}/tmp/bin"
|
|
|
|
eprefix_addpath "${EPREFIX}/tmp/usr/bin"
|
|
|
|
eprefix_addpath "${EPREFIX}/usr/bin"
|
|
|
|
eprefix_addpath "${EPREFIX}/usr/local/bin"
|
|
|
|
eprefix_addpath "${EPREFIX}/usr/local/sbin"
|
|
|
|
eprefix_addpath "${EPREFIX}/usr/sbin"
|
|
|
|
|
|
|
|
# Add manpages
|
|
|
|
eprefix_addman "${EPREFIX}/usr/local/share/man"
|
|
|
|
eprefix_addman "${EPREFIX}/usr/share/binutils-data/x86_64-pc-linux-gnu/2.34/man"
|
|
|
|
eprefix_addman "${EPREFIX}/usr/share/man"
|
|
|
|
|
|
|
|
|
|
|
|
# >>> General env setup
|
|
|
|
|
|
|
|
# Process .sh files
|
|
|
|
for sh in "${EPREFIX}"/etc/profile.d/*.sh
|
|
|
|
do
|
2020-04-12 14:33:57 +02:00
|
|
|
# shellcheck disable=SC1090 disable=SC1091
|
|
|
|
[ -r "${sh}" ] && source "${sh}"
|
2020-03-07 23:11:32 +01:00
|
|
|
done
|
|
|
|
unset sh
|
|
|
|
|
|
|
|
# Set Portage shell
|
|
|
|
CONFIG_SHELL="${EPREFIX}/bin/bash"
|
|
|
|
export CONFIG_SHELL
|
|
|
|
|
|
|
|
# Misc env vars
|
2020-09-12 17:50:24 +02:00
|
|
|
CONFIG_PROTECT_MASK="${CONFIG_PROTECT_MASK} ${EPREFIX}/etc/ca-certificates.conf"
|
|
|
|
CONFIG_PROTECT_MASK="${CONFIG_PROTECT_MASK} ${EPREFIX}/etc/gentoo-release"
|
|
|
|
CONFIG_PROTECT_MASK="${CONFIG_PROTECT_MASK} ${EPREFIX}/etc/sandbox.d"
|
|
|
|
CONFIG_PROTECT_MASK="${CONFIG_PROTECT_MASK} ${EPREFIX}/etc/terminfo"
|
2020-03-07 23:11:32 +01:00
|
|
|
GCC_SPECS=""
|
|
|
|
LANG="en_US.utf8"
|
|
|
|
export CONFIG_PROTECT_MASK
|
|
|
|
export GCC_SPECS
|
|
|
|
export LANG
|
|
|
|
|
|
|
|
# Set umask
|
|
|
|
umask 022
|
|
|
|
|
|
|
|
|
|
|
|
# >>> Use Eprefix's tools
|
|
|
|
|
|
|
|
# We just use "which" because we put Eprefix's PATHs first
|
|
|
|
# before the system ones
|
|
|
|
EDITOR="$(command -v nano)"
|
|
|
|
PAGER="$(command -v less)"
|
|
|
|
export EDITOR
|
|
|
|
export PAGER
|
|
|
|
|
|
|
|
|
|
|
|
# >>> Emerge options
|
|
|
|
|
|
|
|
# Sandbox does not work well on Prefix
|
|
|
|
# Bug: 490246
|
|
|
|
FEATURES="${FEATURES} -usersandbox -sandbox"
|
|
|
|
export FEATURES
|
|
|
|
|
2020-03-08 13:31:02 +01:00
|
|
|
# Check if we are on a prefix profile
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "\n"
|
2020-03-08 13:31:02 +01:00
|
|
|
if command_exists eselect
|
|
|
|
then
|
|
|
|
eprofile="$(eselect profile show)"
|
|
|
|
|
2020-03-08 13:34:04 +01:00
|
|
|
if [[ "${eprofile}" == *prefix* ]]
|
2020-03-08 13:31:02 +01:00
|
|
|
then
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "%s\n" "${eprefix_good} ${eprofile}"
|
2020-03-08 13:31:02 +01:00
|
|
|
else
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "%s\n" "${eprefix_bad} You are not on a prefix profile" >> /dev/stderr
|
2020-03-08 13:31:02 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
unset eprofile
|
|
|
|
else
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "%s\n" "${eprefix_bad} Could not determine running profile" >> /dev/stderr
|
2020-03-08 13:31:02 +01:00
|
|
|
fi
|
|
|
|
|
2020-03-07 23:11:32 +01:00
|
|
|
|
|
|
|
# >>> Finish
|
|
|
|
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "\n%s\n" \
|
|
|
|
">>> Sourced the eprefix script\n" \
|
|
|
|
"${eprefix_good} Prefix: ${EPREFIX}" \
|
|
|
|
"${eprefix_good} Packages: $(eprefix_packages)" \
|
|
|
|
"${eprefix_good} In World: $(eprefix_world)" \
|
|
|
|
"${eprefix_good} Have fun! ;-)"
|
2020-03-07 23:11:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
if command_exists emerge
|
|
|
|
then
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "\n%s\n" ">>> Environment ready"
|
2020-03-07 23:11:32 +01:00
|
|
|
else
|
2021-06-04 10:19:26 +02:00
|
|
|
printf "\n%s\n" \
|
|
|
|
"${eprefix_bad} Could not locate emerge" \
|
|
|
|
"${eprefix_bad} Environment may be broken" \
|
|
|
|
">>> Continuing anyway..." >> /dev/stderr
|
2020-03-07 23:11:32 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# >>> Cleanup
|
|
|
|
unset eprefix_good
|
|
|
|
unset eprefix_bad
|
|
|
|
unset eprefix_warn
|