A build tool for BLFS Beyond Linux From Scratch
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

415 lines
9.3 KiB

#!/usr/bin/env bash
cat > /tmp/blfs_sudo << EOF
blfs ALL = NOPASSWD: /usr/bin/make install*
EOF
if [ "$(whoami)" != "blfs" ]
then
echo "Please execute this script as user blfs"
echo "# groupadd blfs"
echo "# useradd -g blfs -m blfs"
echo "# passwd blfs"
exit 1
fi
set -ueEo pipefail
# shellcheck source=/dev/null
if [ ! -e "${HOME}"/.blfsbuild_config ]
then
cat > "${HOME}"/.blfsbuild_config << EOSF
# location of local package sources
BLFS_PACKAGE_DIR=${HOME}/packages
# Number of processors to use
BLFS_NPROC=$(nproc)
# Bypass step by step validation until a breakpoint
BLFS_BREAKPOINT=1
# strip binaries or not
BLFS_STRIP_BINARIES=true
EOSF
fi
# shellcheck source=/dev/null
source "${HOME}"/.lfsbuild_config
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
BLFS_PACKAGE_DIR=${BLFS_PACKAGE_DIR:-/home/blfs/packages}
BLFS_NPROC=${BLFS_NPROC:-$(nproc)}
BLFS_BREAKPOINT=${LFS_BREAKPOINT:-1000000}
BLFS_STRIP_BINARIES=${BLFS_STRIP_BINARIES:-false}
ask_for_exit()
{
echo "----- call ask_for_exit $1"
echo "find ${SCRIPT_DIR}/build/ \( -name \"*.sh\" -or -name \"*.txt\" \) -print |sort |grep --context=1 \$(cat ${HLFSB})"
find "${SCRIPT_DIR}/build/" \( -name "*.sh" -or -name "*.txt" \) -print |sort |grep --context=1 "$(cat "${HLFSB}")"
echo "ask_for_exit : args = $* && $1 < ${BLFS_BREAKPOINT} (BLFS_BREAKPOINT) || $1 < $(cat "${HLFSB}") (HLFSB) || ${BLFS_BREAKPOINT} (BLFS_BREAKPOINT) > $(cat "${HLFSB}") (HLFSB) "
if [[ $# -eq 1 ]] && [[ $1 -ge 10000 ]] && [[ $1 -lt 10000000 ]] && [[ $1 -lt ${BLFS_BREAKPOINT} ]]
then
echo "BLFS_BREAKPOINT : validation disabled"
return 0
elif [[ $# -eq 1 ]] && [[ $1 -ge 10000 ]] && [[ $1 -lt 10000000 ]] && [[ $1 -lt $(cat "${HLFSB}") ]]
then
echo "STEP_COUNTER : already done. validation disabled"
return 0
elif [[ $# -eq 1 ]] && [[ $1 -ge 10000 ]] && [[ $1 -lt 10000000 ]] && [[ ${BLFS_BREAKPOINT} -gt $(cat "${HLFSB}") ]]
then
echo "BLFS_BREAKPOINT : validation forced"
return 0
else
USER_ANSWER="?";
while [ "${USER_ANSWER}" != "n" ] && [ "${USER_ANSWER}" != "y" ] ; do
echo -n "Continue ? [y/n]"
read -r -n 1 USER_ANSWER
echo "";
done
if [ "$USER_ANSWER" == "n" ]
then
exit 0
fi
fi
}
ask_for_execution() {
USER_ANSWER="?";
while [ "${USER_ANSWER}" != "n" ] && [ "${USER_ANSWER}" != "y" ] && [ "${USER_ANSWER}" != "q" ]
do
echo -n "Execute ? [y/n/q]"
read -r -n 1 USER_ANSWER
echo "";
done
if [ "$USER_ANSWER" == "y" ]
then
return 0
elif [ "$USER_ANSWER" == "n" ]
then
return 1
elif [ "$USER_ANSWER" == "q" ]
then
exit 0
else
exit 0
fi
}
cat > "${HOME}"/.bashrc << EOF
set +h
umask 022
export PATH=/usr/bin
export MAKEFLAGS=-j${BLFS_NPROC}
export ARCH=$(uname -m)
export LC_ALL=POSIX
export SOURCES=/sources
export SLFSB=/sources/lfs_build
EOF
# shellcheck source=/dev/null
source "${HOME}"/.bashrc
describe()
{
case $1 in
w3m)
echo "w3m is a text browser"
;;
*)
echo "Unknown package"
exit 1
;;
esac
}
check_installed()
{
chapter=$1
package=$2
check()
{
proof=$1
echo "$ find /usr -name ${proof} (${package})"
if [ ! -e "${proof}" ]
then
echo "FAILED: ${proof} not found"
describe "${package}"
exit 1
fi
}
case ${package} in
w3m)
check /usr/bin/w3m
;;
*)
echo "Unkwnown package : ${package}"
exit 1
;;
esac
}
check_sources()
{
echo "call check_sources"
while IFS= read -r line
do
echo "Line: $line"
local packagefilename=${line##*/}
echo "${packagefilename}"
[ -d "${BLFS_PACKAGE_DIR}" ] && mkdir -v "${BLFS_PACKAGE_DIR}"
pushd "${BLFS_PACKAGE_DIR}"
md5sum --check "${SCRIPT_DIR}/md5sums"
ret=$?
popd
return ${ret}
done < "${SCRIPT_DIR}/wget-list-systemd.txt"
}
check_download()
{
echo "call check_download"
wget --input-file=wget-list-systemd.txt --continue --directory-prefix="${BLFS_PACKAGE_DIR}"
ret=$?
return ${ret}
}
check_errors()
{
echo "call check_errors $1"
if [[ $# -ne 1 ]]
then
echo "bad argument in function call"
return 1
fi
logfile=$1
if grep "Permission denied" "${logfile}"
then
echo "Rights error"
exit 1
fi
# if grep "configure: error" "${logfile}"
# then
# echo "Configure Error"
# cat "${buildpath}"/config.log
# exit 1
# fi
if grep "^make: .* Error .*$" "${logfile}"
then
echo "Make Error"
exit 1
fi
}
copy_sources()
{
echo "call copy_sources"
echo cp --verbose "${BLFS_PACKAGE_DIR}"/* /sources/
if cp --verbose "${BLFS_PACKAGE_DIR}"/* /sources/
then
return 0
else
return 1
fi
}
copy_scripts()
{
echo "call copy_scripts"
echo cp --verbose "${SCRIPT_DIR}"/build/* /sources/
if cp --verbose "${SCRIPT_DIR}"/build/* /sources/
then
return 0
else
return 1
fi
}
main() {
cd "$SCRIPT_DIR"
echo "1001000" > "${SLFSB}"
echo "Chapter 1. Welcome to BLFS"
### DOWNLOAD PACKAGES ###
echo "Getting the Source Packages"
if [[ $(cat "${SLFSB}") -lt 1001010 ]]
then
if ! check_sources
then
echo "Some package are missing"
if ! download
then
echo "Some package are unavailable"
echo "Try manually"
exit 1
fi
else
echo "1001010" > "${SLFSB}"
fi
fi
if [[ $(cat "${SLFSB}") -lt 1001020 ]]
then
if ! check_sources
then
echo "Some package are unavailable"
echo "Fix it manually"
exit 1
else
echo "1001020" > "${SLFSB}"
fi
fi
ask_for_exit 1001020
### COPY SOURCES ###
echo "Copy sources"
if [[ $(cat "${SLFSB}") -lt 1001030 ]]
then
if ! copy_sources
then
echo "Copy packages to sources failed"
exit 1
else
echo "1001030" > "${SLFSB}"
fi
fi
ask_for_exit 1001030
echo "Copy scripts"
if [[ $(cat "${SLFSB}") -lt 1001040 ]]
then
if ! copy_scripts
then
echo "Copy scripts to sources failed"
exit 1
else
echo "1001040" > "${SLFSB}"
fi
fi
#########################################
### Begin to follow steps on target #####
#########################################
ask_for_exit 1000040
echo "Chapter 2. Important Information"
echo "Install strip script"
if [[ $(cat "${SLFSB}") -lt 1002010 ]]
then
if ! sudo make install-strip-all
then
echo "Copy failed"
exit 1
else
echo "1002010" > "${SLFSB}"
fi
fi
ask_for_exit 1002010
echo "Install libtool cleaning script"
if [[ $(cat "${SLFSB}") -lt 1002020 ]]
then
if ! sudo make install-remove-libtool
then
echo "Copy failed"
exit 1
else
echo "1002020" > "${SLFSB}"
fi
fi
ask_for_exit 1002020
echo "Chapter 3. After LFS Configuration Issues "
echo "The Bash Shell Startup Files"
if [[ $(cat "${SLFSB}") -lt 1003010 ]]
then
if ! sudo make install-profile
then
echo "Copy failed"
exit 1
else
echo "1003010" > "${SLFSB}"
fi
fi
ask_for_exit 1003060
echo " The /etc/vimrc and ~/.vimrc Files "
if [[ $(cat "${SLFSB}") -lt 1003100 ]]
then
if ! sudo make install-profile
then
echo "Copy failed"
exit 1
else
echo "1003100" > "${SLFSB}"
fi
fi
ask_for_exit 1003100
echo "Chapter 4. Security"
if [[ $(cat "${SLFSB}") -lt 1003030 ]]
then
if ! sudo make install-profile
then
echo "Copy failed"
exit 1
else
echo "1003030" > "${SLFSB}"
fi
fi
ask_for_exit 1003040
echo "Chapter 3. After LFS Configuration Issues "
echo "The Bash Shell Startup Files"
if [[ $(cat "${SLFSB}") -lt 1003040 ]]
then
if ! sudo make install-profile
then
echo "Copy failed"
exit 1
else
echo "1003020" > "${SLFSB}"
fi
fi
ask_for_exit 1003010
echo "Chapter 3. After LFS Configuration Issues "
echo "The Bash Shell Startup Files"
if [[ $(cat "${SLFSB}") -lt 1003020 ]]
then
if ! sudo make install-profile
then
echo "Copy failed"
exit 1
else
echo "1003020" > "${SLFSB}"
fi
fi
ask_for_exit 1003010
echo "Chapter 3. After LFS Configuration Issues "
echo "The Bash Shell Startup Files"
if [[ $(cat "${SLFSB}") -lt 1003020 ]]
then
if ! sudo make install-profile
then
echo "Copy failed"
exit 1
else
echo "1003020" > "${SLFSB}"
fi
fi
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi