manjaro-tools/lib/util-iso.sh

663 lines
20 KiB
Bash
Raw Normal View History

2014-12-08 23:50:56 +01:00
#!/bin/bash
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program 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.
2015-06-12 03:25:28 +02:00
import ${LIBDIR}/util-iso-image.sh
import ${LIBDIR}/util-iso-boot.sh
import ${LIBDIR}/util-yaml.sh
2016-02-27 00:39:58 +01:00
error_function() {
2016-09-15 23:58:18 +02:00
if [[ -p $logpipe ]]; then
rm "$logpipe"
fi
# first exit all subshells, then print the error
if (( ! BASH_SUBSHELL )); then
error "A failure occurred in %s()." "$1"
plain "Aborting..."
fi
umount_fs
umount_img
2016-09-15 23:58:18 +02:00
exit 2
2016-02-27 00:39:58 +01:00
}
# $1: function
run_log(){
2016-09-15 23:58:18 +02:00
local func="$1"
local tmpfile=${tmp_dir}/$func.ansi.log logfile=${log_dir}/$(gen_iso_fn).$func.log
logpipe=$(mktemp -u "${tmp_dir}/$func.pipe.XXXXXXXX")
mkfifo "$logpipe"
tee "$tmpfile" < "$logpipe" &
local teepid=$!
$func &> "$logpipe"
wait $teepid
rm "$logpipe"
cat $tmpfile | perl -pe 's/\e\[?.*?[\@-~]//g' > $logfile
rm "$tmpfile"
2016-02-27 00:39:58 +01:00
}
run_safe() {
2016-09-15 23:58:18 +02:00
local restoretrap func="$1"
set -e
set -E
restoretrap=$(trap -p ERR)
trap 'error_function $func' ERR
2016-02-27 00:39:58 +01:00
2018-04-14 00:07:43 +02:00
if ${verbose}; then
2016-09-15 23:58:18 +02:00
run_log "$func"
else
"$func"
fi
2016-02-27 00:39:58 +01:00
2016-09-15 23:58:18 +02:00
eval $restoretrap
set +E
set +e
2016-02-27 00:39:58 +01:00
}
2016-06-13 21:48:41 +02:00
trap_exit() {
2016-09-15 23:58:18 +02:00
local sig=$1; shift
error "$@"
umount_fs
2016-09-15 23:58:18 +02:00
trap -- "$sig"
kill "-$sig" "$$"
2016-06-13 21:48:41 +02:00
}
make_sig () {
msg2 "Creating signature file..."
cd "$1"
2017-02-15 01:18:20 +01:00
user_own "$1"
su ${OWNER} -c "gpg --detach-sign --default-key ${gpgkey} $2.sfs"
chown -R root "$1"
cd ${OLDPWD}
2016-10-19 16:01:16 +02:00
}
# $1: file
make_checksum(){
msg2 "Creating md5sum ..."
cd $1
md5sum $2.sfs > $2.md5
cd ${OLDPWD}
}
2015-05-11 12:47:02 +02:00
# $1: image path
make_sfs() {
2016-10-13 15:24:31 +02:00
local src="$1"
if [[ ! -e "${src}" ]]; then
error "The path %s does not exist" "${src}"
retrun 1
2016-09-15 23:58:18 +02:00
fi
local timer=$(get_timer) dest=${iso_root}/${iso_name}/${target_arch}
2016-09-15 23:58:18 +02:00
local name=${1##*/}
2016-10-13 15:24:31 +02:00
local sfs="${dest}/${name}.sfs"
mkdir -p ${dest}
2016-10-13 15:24:31 +02:00
msg "Generating SquashFS image for %s" "${src}"
if [[ -f "${sfs}" ]]; then
local has_changed_dir=$(find ${src} -newer ${sfs})
msg2 "Possible changes for %s ..." "${src}" >> ${tmp_dir}/buildiso.debug
2016-09-15 23:58:18 +02:00
msg2 "%s" "${has_changed_dir}" >> ${tmp_dir}/buildiso.debug
if [[ -n "${has_changed_dir}" ]]; then
2016-10-13 15:24:31 +02:00
msg2 "SquashFS image %s is not up to date, rebuilding..." "${sfs}"
rm "${sfs}"
2016-09-15 23:58:18 +02:00
else
2016-10-13 15:24:31 +02:00
msg2 "SquashFS image %s is up to date, skipping." "${sfs}"
2016-09-15 23:58:18 +02:00
return
fi
fi
2018-04-14 00:07:43 +02:00
if ${persist}; then
local size=32G
local mnt="${mnt_dir}/${name}"
msg2 "Creating ext4 image of %s ..." "${size}"
truncate -s ${size} "${src}.img"
local ext4_args=()
${verbose} && ext4_args+=(-q)
ext4_args+=(-O ^has_journal,^resize_inode -E lazy_itable_init=0 -m 0)
mkfs.ext4 ${ext4_args[@]} -F "${src}.img" &>/dev/null
tune2fs -c 0 -i 0 "${src}.img" &> /dev/null
mount_img "${work_dir}/${name}.img" "${mnt}"
msg2 "Copying %s ..." "${src}/"
cp -aT "${src}/" "${mnt}/"
umount_img "${mnt}"
fi
2016-10-13 15:24:31 +02:00
msg2 "Creating SquashFS image, this may take some time..."
local used_kernel=${kernel:5:1} mksfs_args=()
2018-04-14 00:07:43 +02:00
if ${persist}; then
mksfs_args+=(${work_dir}/${name}.img)
else
mksfs_args+=(${src})
fi
mksfs_args+=(${sfs} -noappend)
2019-11-17 10:43:33 +01:00
local highcomp
[[ "${iso_compression}" == "xz" ]] && highcomp="-b 256K -Xbcj x86"
[[ "${iso_compression}" == "zstd" ]] && highcomp="-b 256K -Xcompression-level 20" #compression level max 22 (default 15)
2019-11-17 10:43:33 +01:00
mksfs_args+=(-comp ${iso_compression} ${highcomp})
2016-09-15 23:58:18 +02:00
2018-04-14 00:07:43 +02:00
if ${verbose}; then
mksquashfs "${mksfs_args[@]}" >/dev/null
else
mksquashfs "${mksfs_args[@]}"
2016-09-15 23:58:18 +02:00
fi
2016-10-19 16:01:16 +02:00
make_checksum "${dest}" "${name}"
2016-10-13 15:24:31 +02:00
${persist} && rm "${src}.img"
2018-04-14 00:07:43 +02:00
if [[ -n ${gpgkey} ]]; then
2017-02-15 01:18:20 +01:00
make_sig "${dest}" "${name}"
fi
2016-09-15 23:58:18 +02:00
show_elapsed_time "${FUNCNAME}" "${timer_start}"
2015-05-11 12:47:02 +02:00
}
2016-02-26 16:09:34 +01:00
assemble_iso(){
2016-09-15 23:58:18 +02:00
msg "Creating ISO image..."
local iso_publisher="$(get_osname) <$(get_disturl)>" \
iso_app_id="$(get_osname) Live/Rescue CD" \
mod_date=$(date -u +%Y-%m-%d-%H-%M-%S-00 | sed -e s/-//g)
2017-03-28 16:59:02 +02:00
2016-09-15 23:58:18 +02:00
xorriso -as mkisofs \
--modification-date=${mod_date} \
--protective-msdos-label \
-volid "${iso_label}" \
-appid "${iso_app_id}" \
-publisher "${iso_publisher}" \
-preparer "Prepared by manjaro-tools/${0##*/}" \
-r -graft-points -no-pad \
--sort-weight 0 / \
--sort-weight 1 /boot \
--grub2-mbr ${iso_root}/boot/grub/i386-pc/boot_hybrid.img \
-iso_mbr_part_type 0x00 \
-partition_offset 16 \
-b boot/grub/i386-pc/eltorito.img \
-c boot.catalog \
-no-emul-boot -boot-load-size 4 -boot-info-table --grub2-boot-info \
-eltorito-alt-boot \
-append_partition 2 0xef ${iso_root}/efi.img \
-e --interval:appended_partition_2:all:: \
-no-emul-boot \
2018-11-03 08:48:20 +01:00
-full-iso9660-filenames \
2020-02-28 10:51:23 +01:00
-iso-level 3 -rock -joliet \
-o ${iso_dir}/${iso_file} \
${iso_root}/
}
# Build ISO
make_iso() {
2016-09-15 23:58:18 +02:00
msg "Start [Build ISO]"
touch "${iso_root}/.miso"
for sfs_dir in $(find "${work_dir}" -maxdepth 1 -type d); do
2016-10-13 15:24:31 +02:00
if [[ "${sfs_dir}" != "${work_dir}" ]]; then
if [[ -e "${sfs_dir}"/etc/pacman.d/gnupg ]]; then
msg2 "Removing '/etc/pacman.d/gnupg' folder from ${sfs_dir}"
rm -rf "${sfs_dir}"/etc/pacman.d/gnupg
fi
2016-10-13 15:24:31 +02:00
make_sfs "${sfs_dir}"
2016-09-15 23:58:18 +02:00
fi
done
msg "Making bootable image"
# Sanity checks
[[ ! -d "${iso_root}" ]] && return 1
2016-09-15 23:58:18 +02:00
if [[ -f "${iso_dir}/${iso_file}" ]]; then
msg2 "Removing ${iso_file} related files ..."
[[ -f "${iso_dir}/${iso_file}" ]] && rm -f "${iso_dir}/${iso_file}"
[[ -f "${iso_dir}/${iso_file}.sig" ]] && rm -f "${iso_dir}/${iso_file}.sig"
[[ -f "${iso_dir}/${iso_file}.sha1" ]] && rm -f "${iso_dir}/${iso_file}.sha1"
[[ -f "${iso_dir}/${iso_file}.sha256" ]] && rm -f "${iso_dir}/${iso_file}.sha256"
[[ -f "${iso_dir}/${iso_file}.torrent" ]] && rm -f "${iso_dir}/${iso_file}.torrent"
2016-09-15 23:58:18 +02:00
fi
assemble_iso
${permalink} && gen_permalink
2016-09-15 23:58:18 +02:00
msg "Done [Build ISO]"
}
gen_permalink(){
if [[ ${edition} == "community" ]] || [[ ${edition} == "manjaro" ]]; then
if [[ -f "${iso_dir}/${iso_file}" ]]; then
msg2 "Creating download link ..."
direct_url="https://osdn.net/dl/${edition}/${iso_file}"
[[ ${edition} == "community" ]] && direct_url="https://osdn.net/dl/manjaro-${edition}/${iso_file}"
## html permalink
html_doc="<!DOCTYPE HTML>"
html_doc+="<meta charset=\"UTF-8\">"
html_doc+="<meta http-equiv=\"refresh\" content=\"1; url=${direct_url}\">"
html_doc+="<script>window.location.href=\"${direct_url}\"</script>"
html_doc+="<title>Download Redirection</title>"
html_doc+="If you are not redirected automatically, follow the <a href=\"${direct_url}\">link to latest iso</a>"
## php permalink
2020-01-24 14:33:30 +01:00
php_doc="<?php "
php_doc+="header('Location: ' . '${direct_url}', true, 303); "
php_doc+="die(); "
php_doc+="?>"
## write files
if [[ ${extra} == "true" ]]; then
echo ${html_doc} > "${iso_dir}/.latest"
echo ${php_doc} > "${iso_dir}/.latest.php"
else
echo ${html_doc} > "${iso_dir}/.latest-minimal"
echo ${php_doc} > "${iso_dir}/.latest-minimal.php"
fi
fi
fi
}
2016-02-18 22:02:01 +01:00
gen_iso_fn(){
2016-09-15 23:58:18 +02:00
local vars=() name
vars+=("${iso_name}")
2018-04-14 00:07:43 +02:00
if ! ${chrootcfg}; then
2016-09-15 23:58:18 +02:00
[[ -n ${profile} ]] && vars+=("${profile}")
fi
vars+=("${dist_release}")
2019-09-28 11:03:57 +02:00
[[ ! ${target_branch} == "stable" ]] && vars+=("${target_branch}")
2018-03-19 17:33:26 +01:00
[[ ${extra} == 'false' ]] && vars+=("minimal")
2019-09-28 11:03:57 +02:00
vars+=("$(date +%y%m%d)")
2019-09-28 11:03:57 +02:00
vars+=("${kernel}")
2019-09-28 11:03:57 +02:00
[[ ${target_arch} == "i686" ]] && vars+=("${target_arch}")
2018-04-19 23:24:19 +02:00
for n in ${vars[@]}; do
2016-09-15 23:58:18 +02:00
name=${name:-}${name:+-}${n}
done
2016-09-15 23:58:18 +02:00
echo $name
2016-02-18 22:02:01 +01:00
}
2016-05-21 00:05:49 +02:00
reset_pac_conf(){
2016-09-15 23:58:18 +02:00
info "Restoring [%s/etc/pacman.conf] ..." "$1"
sed -e 's|^.*HoldPkg.*|HoldPkg = pacman glibc manjaro-system|' \
-e "s|^.*#CheckSpace|CheckSpace|" \
-i "$1/etc/pacman.conf"
2016-05-21 00:05:49 +02:00
}
2019-06-12 18:34:00 +02:00
# Snap support
function seed_snaps() {
local SEED_DIR="/var/lib/snapd/seed"
local SEED_CHANNEL="${snap_channel}"
2019-06-12 22:16:42 +02:00
local SEED_SNAPS="${strict_snaps} ${classic_snaps}"
2019-06-12 18:34:00 +02:00
2019-06-12 22:16:42 +02:00
if [[ -n "${strict_snaps}" ]] || [[ -n "${classic_snaps}" ]]; then
2019-06-30 09:10:11 +02:00
msg2 "Configuring snaps"
2019-06-12 18:34:00 +02:00
# Preseeded snaps should be downloaded from a versioned channel
rm -rfv "$1/${SEED_DIR}"
mkdir -p "$1/${SEED_DIR}/snaps"
mkdir -p "$1/${SEED_DIR}/assertions"
2019-06-13 21:39:47 +02:00
SEED_LIST=()
2019-06-12 18:34:00 +02:00
2019-06-13 23:54:37 +02:00
# Update SEED_LIST
2019-06-12 18:34:00 +02:00
for SEED_SNAP in ${SEED_SNAPS}; do
2019-06-20 15:54:02 +02:00
if [[ "${SEED_SNAP}" == "core" ]] || [[ "${SEED_SNAP}" == "core16" ]] || [[ "${SEED_SNAP}" == "core18" ]]; then
SEED_LIST+=(--snap=${SEED_SNAP}=stable)
else
SEED_LIST+=(--snap=${SEED_SNAP}=${SEED_CHANNEL})
fi
2019-06-12 18:34:00 +02:00
done
# Create model and account assertions
# Runs outside the container.
snap known model > /tmp/generic.model
2019-06-13 23:54:37 +02:00
snap prepare-image --arch amd64 --classic /tmp/generic.model "${SEED_LIST[@]}" "$1"
2019-06-12 22:00:36 +02:00
else
msg2 "No snaps found in profile. Skipping adding snaps"
2019-06-12 18:34:00 +02:00
fi
}
# Base installation (rootfs)
2015-01-13 04:48:04 +01:00
make_image_root() {
2016-09-15 23:58:18 +02:00
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
msg "Prepare [Base installation] (rootfs)"
local path="${work_dir}/rootfs"
2016-09-15 23:58:18 +02:00
mkdir -p ${path}
2015-06-29 04:08:45 +02:00
2016-09-15 23:58:18 +02:00
chroot_create "${path}" "${packages}" || die
2015-06-29 04:08:45 +02:00
# profide multilib usage to mhwd-script
if [[ ! -z ${multilib} ]]; then
echo 'MHWD64_IS_LIB32="'${multilib}'"' > "${path}/etc/mhwd-x86_64.conf"
fi
pacman -Qr "${path}" > "${path}/rootfs-pkgs.txt"
2016-09-15 23:58:18 +02:00
copy_overlay "${profile_dir}/root-overlay" "${path}"
2016-05-20 19:42:16 +02:00
2016-09-15 23:58:18 +02:00
reset_pac_conf "${path}"
2016-05-20 19:42:16 +02:00
configure_lsb "${path}"
2016-09-15 23:58:18 +02:00
clean_up_image "${path}"
: > ${work_dir}/build.${FUNCNAME}
msg "Done [Base installation] (rootfs)"
2016-09-15 23:58:18 +02:00
fi
2014-12-10 19:06:52 +01:00
}
2016-10-12 12:32:54 +02:00
make_image_desktop() {
2016-09-15 23:58:18 +02:00
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
2016-10-11 17:56:23 +02:00
msg "Prepare [Desktop installation] (desktopfs)"
local path="${work_dir}/desktopfs"
2016-09-15 23:58:18 +02:00
mkdir -p ${path}
2017-02-01 13:39:36 +01:00
mount_fs_root "${path}"
2016-09-15 23:58:18 +02:00
chroot_create "${path}" "${packages}"
2015-06-29 04:08:45 +02:00
2016-10-11 17:56:23 +02:00
pacman -Qr "${path}" > "${path}/desktopfs-pkgs.txt"
cp "${path}/desktopfs-pkgs.txt" ${iso_dir}/$(gen_iso_fn)-pkgs.txt
[[ -e ${profile_dir}/desktop-overlay ]] && copy_overlay "${profile_dir}/desktop-overlay" "${path}"
2022-08-26 10:27:35 +02:00
if [[ -e "${path}/usr/share/calamares/branding/manjaro/calamares-sidebar.qml" ]]; then
2019-10-10 17:27:05 +02:00
configure_branding "${path}"
msg "Done [Distribution: Release ${dist_release} Codename ${dist_codename}]"
2022-08-26 10:27:35 +02:00
elif [[ -e "${path}/usr/share/calamares/branding/manjaro/show.qml" ]]; then
configure_branding_old "${path}"
msg "Done [Distribution: Release ${dist_release} Codename ${dist_codename}]"
fi
2016-09-15 23:58:18 +02:00
reset_pac_conf "${path}"
2016-05-20 19:42:16 +02:00
seed_snaps ${path}
2021-03-29 17:17:00 +02:00
echo "Enable os-prober"
2021-03-31 09:38:48 +02:00
sed -i -e 's,.*GRUB_DISABLE_OS_PROBER=.*,GRUB_DISABLE_OS_PROBER=false,' "${path}/etc/default/grub"
2019-06-12 18:49:40 +02:00
umount_fs
2016-09-15 23:58:18 +02:00
clean_up_image "${path}"
: > ${work_dir}/build.${FUNCNAME}
2016-10-11 17:56:23 +02:00
msg "Done [Desktop installation] (desktopfs)"
2016-09-15 23:58:18 +02:00
fi
2016-02-25 15:51:25 +01:00
}
mount_fs_select(){
if [[ -f "${packages_desktop}" ]]; then
mount_fs_desktop "$1"
2016-09-15 23:58:18 +02:00
else
mount_fs_root "$1"
2016-09-15 23:58:18 +02:00
fi
2014-12-08 23:50:56 +01:00
}
2015-12-18 18:25:13 +01:00
make_image_live() {
2016-09-15 23:58:18 +02:00
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
msg "Prepare [Live installation] (livefs)"
local path="${work_dir}/livefs"
2016-09-15 23:58:18 +02:00
mkdir -p ${path}
mount_fs_select "${path}"
2016-09-15 23:58:18 +02:00
chroot_create "${path}" "${packages}"
2015-06-29 04:08:45 +02:00
pacman -Qr "${path}" > "${path}/livefs-pkgs.txt"
2016-09-15 23:58:18 +02:00
copy_overlay "${profile_dir}/live-overlay" "${path}"
configure_live_image "${path}"
2022-08-29 15:44:36 +02:00
if [[ -e "${path}/usr/share/calamares/branding/manjaro/calamares-sidebar.qml" ]]; then
configure_branding "${path}"
2022-08-29 15:44:36 +02:00
msg "Done [Distribution: Release ${dist_release} Codename ${dist_codename}]"
elif [[ -e "${path}/usr/share/calamares/branding/manjaro/show.qml" ]]; then
configure_branding_old "${path}"
msg "Done [Distribution: Release ${dist_release} Codename ${dist_codename}]"
fi
configure_polkit_user_rules "${path}"
2016-09-15 23:58:18 +02:00
reset_pac_conf "${path}"
2016-05-20 19:42:16 +02:00
umount_fs
2016-09-15 23:58:18 +02:00
clean_up_image "${path}"
: > ${work_dir}/build.${FUNCNAME}
msg "Done [Live installation] (livefs)"
2016-09-15 23:58:18 +02:00
fi
2014-12-15 23:12:04 +01:00
}
make_image_mhwd() {
2016-09-15 23:58:18 +02:00
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
msg "Prepare [drivers repository] (mhwdfs)"
local path="${work_dir}/mhwdfs"
2016-09-15 23:58:18 +02:00
mkdir -p ${path}${mhwd_repo}
mount_fs_select "${path}"
2015-06-29 04:08:45 +02:00
2016-09-15 23:58:18 +02:00
reset_pac_conf "${path}"
2016-05-20 19:42:16 +02:00
2016-09-15 23:58:18 +02:00
copy_from_cache "${path}" "${packages}"
2015-07-04 12:09:39 +02:00
2016-09-15 23:58:18 +02:00
if [[ -n "${packages_cleanup}" ]]; then
for mhwd_clean in ${packages_cleanup}; do
rm ${path}${mhwd_repo}/${mhwd_clean}
done
fi
2019-08-31 11:32:58 +02:00
cp ${DATADIR}/pacman-mhwd.conf ${path}/opt/mhwd
2016-09-15 23:58:18 +02:00
make_repo "${path}"
configure_mhwd_drivers "${path}"
umount_fs
2016-09-15 23:58:18 +02:00
clean_up_image "${path}"
: > ${work_dir}/build.${FUNCNAME}
msg "Done [drivers repository] (mhwdfs)"
2016-09-15 23:58:18 +02:00
fi
2014-12-08 23:50:56 +01:00
}
2015-01-13 04:48:04 +01:00
make_image_boot() {
2016-09-15 23:58:18 +02:00
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
msg "Prepare [/iso/boot]"
local boot="${iso_root}/boot"
2017-03-27 18:08:13 +02:00
mkdir -p ${boot}
2016-10-12 12:32:54 +02:00
cp ${work_dir}/rootfs/boot/vmlinuz* ${boot}/vmlinuz-${target_arch}
2016-10-12 12:32:54 +02:00
local path="${work_dir}/bootfs"
2016-09-15 23:58:18 +02:00
mkdir -p ${path}
2015-06-25 09:59:35 +02:00
if [[ -f "${packages_desktop}" ]]; then
mount_fs_live "${path}"
else
mount_fs_net "${path}"
fi
2015-06-25 09:59:35 +02:00
2017-02-07 20:15:59 +01:00
prepare_initcpio "${path}"
prepare_initramfs "${path}"
2015-06-29 04:08:45 +02:00
cp ${path}/boot/initramfs.img ${boot}/initramfs-${target_arch}.img
prepare_boot_extras "${path}" "${boot}"
2015-06-25 09:59:35 +02:00
umount_fs
2015-06-25 09:59:35 +02:00
2016-09-15 23:58:18 +02:00
rm -R ${path}
: > ${work_dir}/build.${FUNCNAME}
msg "Done [/iso/boot]"
2016-09-15 23:58:18 +02:00
fi
2014-12-08 23:50:56 +01:00
}
2017-03-27 18:08:13 +02:00
configure_grub(){
local default_args="misobasedir=${iso_name} misolabel=${iso_label}" \
2019-12-11 15:44:30 +01:00
boot_args=('quiet' 'systemd.show_status=1' ${custom_boot_args} ${apparmor_boot_args})
2017-03-27 18:08:13 +02:00
sed -e "s|@DIST_NAME@|${dist_name}|g" \
-e "s|@ARCH@|${target_arch}|g" \
-e "s|@DEFAULT_ARGS@|${default_args}|g" \
-e "s|@BOOT_ARGS@|${boot_args[*]}|g" \
-e "s|@PROFILE@|${profile}|g" \
-i $1
}
configure_grub_theme(){
sed -e "s|@ISO_NAME@|${iso_name}|" -i "$1"
}
make_grub(){
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
msg "Prepare [/iso/boot/grub]"
2017-03-27 18:08:13 +02:00
local path="${work_dir}/livefs"
2017-03-27 18:08:13 +02:00
prepare_grub "${path}" "${iso_root}"
2017-03-27 18:08:13 +02:00
configure_grub "${iso_root}/boot/grub/kernels.cfg"
configure_grub_theme "${iso_root}/boot/grub/variable.cfg"
2017-03-27 18:08:13 +02:00
: > ${work_dir}/build.${FUNCNAME}
msg "Done [/iso/boot/grub]"
fi
}
check_requirements(){
2017-02-16 19:39:39 +01:00
[[ -f ${run_dir}/repo_info ]] || die "%s is not a valid iso profiles directory!" "${run_dir}"
2018-04-14 00:07:43 +02:00
if ! $(is_valid_arch_iso ${target_arch}); then
2016-09-15 23:58:18 +02:00
die "%s is not a valid arch!" "${target_arch}"
fi
2018-04-14 00:07:43 +02:00
if ! $(is_valid_branch ${target_branch}); then
2016-09-15 23:58:18 +02:00
die "%s is not a valid branch!" "${target_branch}"
fi
2019-11-17 10:55:27 +01:00
if ! $(is_valid_comp ${iso_compression}); then
die "%s is not a valid compression algorithm!" "${iso_compression}"
2016-09-15 23:58:18 +02:00
fi
2019-11-17 10:55:27 +01:00
local iso_kernel=${kernel:5:1}
[[ ${iso_kernel} < "4" ]] && die "ISO kernel must be version>=4.0!"
}
2014-12-31 01:02:43 +01:00
compress_images(){
2016-09-15 23:58:18 +02:00
local timer=$(get_timer)
run_safe "make_iso"
2017-10-23 23:50:26 +02:00
user_own "${cache_dir_iso}" "-R"
2016-09-15 23:58:18 +02:00
show_elapsed_time "${FUNCNAME}" "${timer}"
2014-12-31 01:02:43 +01:00
}
2016-02-25 06:40:39 +01:00
prepare_images(){
2016-09-15 23:58:18 +02:00
local timer=$(get_timer)
load_pkgs "${profile_dir}/Packages-Root"
run_safe "make_image_root"
if [[ -f "${packages_desktop}" ]] ; then
load_pkgs "${packages_desktop}"
2016-10-12 12:32:54 +02:00
run_safe "make_image_desktop"
2016-09-15 23:58:18 +02:00
fi
if [[ -f ${profile_dir}/Packages-Live ]]; then
load_pkgs "${profile_dir}/Packages-Live"
run_safe "make_image_live"
fi
if [[ -f ${packages_mhwd} ]] ; then
load_pkgs "${packages_mhwd}"
run_safe "make_image_mhwd"
fi
run_safe "make_image_boot"
run_safe "make_grub"
2017-03-27 18:08:13 +02:00
2016-09-15 23:58:18 +02:00
show_elapsed_time "${FUNCNAME}" "${timer}"
}
archive_logs(){
local name=$(gen_iso_fn) ext=log.tar.xz src=${tmp_dir}/archives.list
find ${log_dir} -maxdepth 1 -name "$name*.log" -printf "%f\n" > $src
msg2 "Archiving log files [%s] ..." "$name.$ext"
tar -cJf ${log_dir}/$name.$ext -C ${log_dir} -T $src
msg2 "Cleaning log files ..."
find ${log_dir} -maxdepth 1 -name "$name*.log" -delete
}
make_profile(){
2016-09-15 23:58:18 +02:00
msg "Start building [%s]" "${profile}"
2018-04-14 00:07:43 +02:00
if ${clean_first}; then
chroot_clean "${chroots_iso}/${profile}/${target_arch}"
2017-03-27 18:08:13 +02:00
local unused_arch=''
case ${target_arch} in
i686) unused_arch='x86_64' ;;
x86_64) unused_arch='i686' ;;
esac
2018-04-14 00:07:43 +02:00
if [[ -d "${chroots_iso}/${profile}/${unused_arch}" ]]; then
chroot_clean "${chroots_iso}/${profile}/${unused_arch}"
fi
clean_iso_root "${iso_root}"
fi
2017-03-27 18:08:13 +02:00
2016-09-15 23:58:18 +02:00
if ${iso_only}; then
[[ ! -d ${work_dir} ]] && die "Create images: buildiso -p %s -x" "${profile}"
compress_images
${verbose} && archive_logs
exit 1
fi
if ${images_only}; then
prepare_images
${verbose} && archive_logs
warning "Continue compress: buildiso -p %s -zc ..." "${profile}"
exit 1
else
prepare_images
compress_images
${verbose} && archive_logs
fi
reset_profile
msg "Finished building [%s]" "${profile}"
show_elapsed_time "${FUNCNAME}" "${timer_start}"
}
2016-02-25 06:40:39 +01:00
2016-06-09 12:49:28 +02:00
get_pacman_conf(){
2016-09-15 23:58:18 +02:00
local user_conf=${profile_dir}/user-repos.conf pac_arch='default' conf
[[ "${target_arch}" == 'x86_64' ]] && pac_arch='multilib'
2018-04-14 00:07:43 +02:00
if [[ -f ${user_conf} ]]; then
2016-09-15 23:58:18 +02:00
info "detected: %s" "user-repos.conf"
check_user_repos_conf "${user_conf}"
conf=${tmp_dir}/custom-pacman.conf
cat ${DATADIR}/pacman-$pac_arch.conf ${user_conf} > "$conf"
else
conf="${DATADIR}/pacman-$pac_arch.conf"
fi
echo "$conf"
}
2016-02-25 06:40:39 +01:00
load_profile(){
2017-03-09 15:03:43 +01:00
conf="$1/profile.conf"
2016-09-15 23:58:18 +02:00
info "Profile: [%s]" "${profile}"
2016-02-25 06:40:39 +01:00
2016-09-15 23:58:18 +02:00
load_profile_config "$conf"
2016-02-25 06:40:39 +01:00
2016-09-15 23:58:18 +02:00
pacman_conf=$(get_pacman_conf)
2016-09-15 23:58:18 +02:00
mirrors_conf=$(get_pac_mirrors_conf "${target_branch}")
2016-06-10 11:55:41 +02:00
2016-09-15 23:58:18 +02:00
iso_file=$(gen_iso_fn).iso
2016-02-25 06:40:39 +01:00
[[ ${extra} == 'false' ]] && _edition=("m")
iso_label=$(get_iso_label "${dist_branding}_${profile}${_edition}_${dist_release//.}")
2016-09-15 23:58:18 +02:00
mkchroot_args+=(-C ${pacman_conf} -S ${mirrors_conf} -B "${build_mirror}/${target_branch}" -K)
work_dir=${chroots_iso}/${profile}/${target_arch}
2016-02-25 06:40:39 +01:00
iso_dir="${cache_dir_iso}/${edition}/${profile}/${dist_release}"
2016-02-25 06:40:39 +01:00
iso_root=${chroots_iso}/${profile}/iso
2016-10-13 15:24:31 +02:00
mnt_dir=${chroots_iso}/${profile}/mnt
prepare_dir "${mnt_dir}"
2016-09-15 23:58:18 +02:00
prepare_dir "${iso_dir}"
2017-10-23 23:50:26 +02:00
user_own "${cache_dir_iso}" "-R"
2016-02-25 06:40:39 +01:00
}
prepare_profile(){
2016-09-15 23:58:18 +02:00
profile=$1
edition=$(get_edition ${profile})
profile_dir=${run_dir}/${edition}/${profile}
2017-03-09 13:01:20 +01:00
check_profile "${profile_dir}"
2017-03-09 15:03:43 +01:00
load_profile "${profile_dir}"
2016-02-25 06:40:39 +01:00
}
build(){
2016-09-15 23:58:18 +02:00
prepare_profile "$1"
make_profile
2016-02-25 06:40:39 +01:00
}