2024-10-24 06:12:12 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Function that setups and builds an LFS system
|
|
|
|
# First parameter is mandatory and it is the new LFS system's root mount point
|
|
|
|
_build_lfs()
|
|
|
|
{
|
|
|
|
# Check if the lfs mount point folder is specified as the first argument
|
|
|
|
if [ -z "$1" ] ; then
|
|
|
|
echo "Please specify the lfs mount point folder as the first argument!" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
local dir_lfs="$(realpath "$1")"
|
2024-10-24 06:12:12 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# First include the needed external script files
|
|
|
|
local current_dir="$(dirname "$0")"
|
|
|
|
source $current_dir/libs/func_general.sh
|
|
|
|
source $current_dir/libs/func_kernel.sh
|
|
|
|
source $current_dir/libs/func_network.sh
|
|
|
|
source $current_dir/libs/func_fstab.sh
|
|
|
|
source $current_dir/libs/func_grub.sh
|
2024-10-24 06:12:12 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Create folder structure and get LFS and BLFS sources
|
|
|
|
_create_folders_and_get_sources "$dir_lfs" || return 1
|
2024-10-24 06:12:12 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Patch the LFS book's packages.ent with latest kernel
|
2024-12-01 01:58:52 +08:00
|
|
|
_update_lfs_with_latest_kernel "$dir_lfs" || return 1
|
2024-10-31 06:39:38 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Check for the kernel config and try to create it based on a previous one if not found
|
|
|
|
_create_kernel_config_if_needed "$dir_lfs" || return 1
|
2024-10-24 06:12:12 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Check for possible needed firmwares defined in kernel config
|
|
|
|
_check_and_copy_needed_firmwares "$dir_lfs" || return 1
|
2024-11-14 16:42:37 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Patch jhalfs sources
|
|
|
|
_patch_jhalfs_sources "$dir_lfs" "$2" || return 1
|
2024-11-02 23:02:44 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Enter to setup folder and start installer
|
|
|
|
cd "$dir_lfs/setup" || return 1
|
|
|
|
yes "yes" | ./jhalfs run
|
|
|
|
if [[ $? -gt 0 ]] ; then return 1; fi
|
2024-11-02 23:02:44 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Patch network script
|
2024-11-28 00:39:37 +08:00
|
|
|
_patch_network_scripts "$dir_lfs" "$2" || return 1
|
2024-11-10 03:08:10 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Patch fstab script
|
2024-12-01 01:58:52 +08:00
|
|
|
_patch_fstab "$dir_lfs" || return 1
|
2024-11-14 07:08:02 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Patch LFS kernel script to keep build folder and add new user
|
|
|
|
_patch_kernel_script "$dir_lfs" || return 1
|
2024-11-18 03:38:12 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Patch grub script
|
|
|
|
_patch_grub_script "$dir_lfs" || return 1
|
2024-11-18 03:38:12 +08:00
|
|
|
|
2024-11-27 08:47:00 +08:00
|
|
|
# Enter to jhalfs folder and start the build
|
|
|
|
cd "$dir_lfs/jhalfs" || return 1
|
|
|
|
make || return 1
|
2024-11-28 03:12:44 +08:00
|
|
|
|
|
|
|
# Finalize the lfs build
|
|
|
|
_finalize_lfs_build "$1"
|
2024-11-27 08:47:00 +08:00
|
|
|
}
|
2024-11-18 03:38:12 +08:00
|
|
|
|
2024-11-28 03:12:44 +08:00
|
|
|
_build_lfs "$1" "$2" || exit 1
|