Created
August 13, 2018 15:31
-
-
Save nado/44b392b50c0b71a7e22b98d6909bfa72 to your computer and use it in GitHub Desktop.
Gentoo profile explorer (mainly for learning purpose)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# TODO: short desc | |
# DEPS: portageq, realpath (portage, coreutils) | |
TMPFOUNDPACKAGES=".found-packages" | |
EXPLOREDPACKAGES="explored-packages" | |
# recursive function exploring files of inherited profiles | |
# $1 = current profile from which to start (important as parent contain relative path) | |
# $2 = inherited profile to explore (content of parent file) | |
function explore { | |
if [ "$#" -lt "1" ] || [ "$#" -gt "2" ]; then | |
echo "[-] Error, wrong number of arguments passed to explore" | |
exit | |
fi | |
local cur="${1}" | |
if [ "$#" -eq "2" ]; then | |
cur="${cur}/${2}" | |
fi | |
cur="$(realpath ${cur})" | |
# Get packages files | |
if [ -e "${cur}/packages" ]; then | |
echo "${cur}/packages" >> "$TMPFOUNDPACKAGES" | |
echo >> "$EXPLOREDPACKAGES" | |
echo "${cur}/packages" >> "$EXPLOREDPACKAGES" | |
cat "${cur}/packages" >> "$EXPLOREDPACKAGES" | |
fi | |
# TODO: might be directories in EAPI=7 | |
# package.mask | |
# package.use | |
# use.* | |
# package.use.* | |
# package.mask | |
# package.use | |
# use.* | |
# package.use.* | |
if [ -e "${cur}/parent" ]; then | |
while read -r line || [[ -n "${line}" ]]; do | |
explore "${cur}" "${line}" | |
done < "${cur}/parent" | |
fi | |
} | |
function report { | |
echo "[+] EROOT : ${EROOT}" | |
echo "[+] PORTDIR : ${PORTDIR}" | |
echo "[+] CURPROFILE: ${PROFILEDIR#${PORTDIR}/profiles/}" | |
echo "[+] EAPI : ${EAPI}" | |
echo | |
if [ -e "$TMPFOUNDPACKAGES" ]; then | |
echo "[+] packages (@system)" | |
echo "$(<$TMPFOUNDPACKAGES)" | |
else | |
echo "[-] No packages file found, which means NO @SYSTEM SET" | |
fi | |
} | |
function clean { | |
rm -f \ | |
$TMPFOUNDPACKAGES \ | |
$EXPLOREDPACKAGES | |
} | |
EROOT="$(portageq envvar EROOT)" | |
PORTDIR="$(portageq get_repo_path ${EROOT} gentoo)" | |
if [ "$#" -eq "1" ]; then | |
# TODO: check if arg begins with '/' to support both abspath and profile name | |
PROFILEDIR="$(realpath ${PORTDIR}/profiles/${1})" | |
else | |
PROFILEDIR="$(realpath ${EROOT}/etc/portage/make.profile)" | |
fi | |
EAPI="0" | |
if [ -e "${PROFILEDIR}/eapi" ] | |
then | |
EAPI=$(<"${PROFILEDIR}/eapi") | |
fi | |
# TODO: | |
# Deprecated file : print reason + recommended new profile | |
clean | |
explore "${PROFILEDIR}" | |
report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment