master
artoo 3 years ago committed by Gitea
parent 7b831d8867
commit 974df38738
  1. 92
      bin/iso/buildiso.in
  2. 2
      initcpio/hooks/artix
  3. 39
      lib/iso/chrootcfg.sh
  4. 18
      lib/iso/iso.sh
  5. 4
      lib/iso/mount.sh
  6. 74
      lib/iso/util.sh

@ -75,6 +75,44 @@ display_settings(){
show_profile
}
mk_squash(){
local timer=$(get_timer)
make_sfs "${work_dir}/rootfs"
[[ -d "${work_dir}/livefs" ]] && make_sfs "${work_dir}/livefs"
show_elapsed_time "${FUNCNAME}" "${timer}"
}
mk_iso(){
touch "${iso_root}/.artix"
msg "Making bootable image"
# Sanity checks
[[ ! -d "${iso_root}" ]] && return 1
if [[ -f "${iso_dir}/${iso_file}" ]]; then
msg2 "Removing existing bootable image..."
rm -rf "${iso_dir}/${iso_file}"
fi
assemble_iso
chown -R "${OWNER}:$(id --group ${OWNER})" "${iso_dir}"
}
mk_boot(){
local timer=$(get_timer)
run_safe "make_bootfs"
run_safe "make_grub"
show_elapsed_time "${FUNCNAME}" "${timer}"
}
mk_chroots(){
local timer=$(get_timer)
load_pkgs "${ROOT_LIST}" "${INITSYS}"
run_safe "make_rootfs"
if [[ -n ${LIVE_LIST} ]]; then
load_pkgs "${LIVE_LIST}" "${INITSYS}"
run_safe "make_livefs"
fi
show_elapsed_time "${FUNCNAME}" "${timer}"
}
build(){
msg "Start building [%s]" "${PROFILE}"
if ${clean_first};then
@ -95,29 +133,45 @@ build(){
rm -rf --one-file-system "${iso_root}"
fi
if ${iso_only}; then
[[ ! -d ${work_dir} ]] && die "Create images: %s -p %s -x" "${cmd}" "${PROFILE}"
compress_images
exit 1
fi
if ${images_only}; then
prepare_images
warning "Continue compress: %s -p %s -zc ..." "${cmd}" "${PROFILE}"
exit 1
else
prepare_images
compress_images
fi
case true in
${chroot_only})
mk_chroots
warning "Continue squash: %s -p %s -sc ..." "${cmd}" "${PROFILE}"
exit 1
;;
${boot_only})
mk_boot
warning "Continue boot: %s -p %s -zc ..." "${cmd}" "${PROFILE}"
exit 1
;;
${squash_only})
mk_squash
warning "Continue boot: %s -p %s -bc ..." "${cmd}" "${PROFILE}"
exit 1
;;
${iso_only})
[[ ! -d ${work_dir} ]] && die "Create chroot: %s -p %s -x" "${cmd}" "${PROFILE}"
mk_iso
;;
*)
mk_chroots
mk_squash
mk_boot
mk_iso
;;
esac
msg "Finished building [%s]" "${PROFILE}"
show_elapsed_time "${FUNCNAME}" "${timer_start}"
}
clean_first=true
pretend=false
images_only=false
chroot_only=false
iso_only=false
persist=false
use_dracut=false
squash_only=false
boot_only=false
basestrap_args=(-GMc)
cmd=${0##*/}
@ -137,7 +191,9 @@ usage() {
echo " [default: ${GPG_KEY}]"
echo ' -m Set SquashFS image mode to persistence'
echo ' -c Disable clean work dir'
echo ' -x Build images only'
echo ' -x Build chroot only'
echo ' -s Squash chroot only'
echo ' -b Generate iso boot only'
echo ' -z Generate iso only'
echo ' Requires pre built images (-x)'
echo ' -d Use dracut instead of mkinitcpio for iso initramfs'
@ -150,7 +206,7 @@ usage() {
orig_argv=("$0" "$@")
opts='p:r:t:i:g:czxmdqh'
opts='p:r:t:i:g:czsbxmdqh'
while getopts "${opts}" arg; do
case "${arg}" in
@ -160,8 +216,10 @@ while getopts "${opts}" arg; do
i) INITSYS="$OPTARG" ;;
g) GPG_KEY="$OPTARG" ;;
c) clean_first=false ;;
x) images_only=true ;;
x) chroot_only=true ;;
z) iso_only=true ;;
s) squash_only=true ;;
b) boot_only=true ;;
m) persist=true ;;
d) use_dracut=true ;;
q) pretend=true ;;

@ -146,7 +146,7 @@ run_hook() {
lower_dir=''
live_root="/run/artix"
bootmnt="/run/bootmnt"
bootmnt="${live_root}/bootmnt"
overlay_root="${live_root}/overlay_root"
cow="${live_root}/cowspace"
cp2ram="${live_root}/copytoram"

@ -167,7 +167,7 @@ configure_calamares(){
fi
}
configure_image(){
configure_chroot(){
local fs="$1"
msg "Configuring [%s]" "${fs##*/}"
configure_hosts "$fs"
@ -179,3 +179,40 @@ configure_image(){
write_live_session_conf > "$fs/etc/artools/live.conf"
msg "Done configuring [%s]" "${fs##*/}"
}
clean_up_chroot(){
local path mnt="$1"
msg2 "Cleaning [%s]" "${mnt##*/}"
path=$mnt/boot
if [[ -d "$path" ]]; then
find "$path" -name 'initramfs*.img' -delete &> /dev/null
fi
path=$mnt/var/lib/pacman/sync
if [[ -d $path ]];then
find "$path" -type f -delete &> /dev/null
fi
path=$mnt/var/cache/pacman/pkg
if [[ -d $path ]]; then
find "$path" -type f -delete &> /dev/null
fi
path=$mnt/var/log
if [[ -d $path ]]; then
find "$path" -type f -delete &> /dev/null
fi
path=$mnt/var/tmp
if [[ -d $path ]];then
find "$path" -mindepth 1 -delete &> /dev/null
fi
path=$mnt/tmp
if [[ -d $path ]];then
find "$path" -mindepth 1 -delete &> /dev/null
fi
find "$mnt" -name *.pacnew -name *.pacsave -name *.pacorig -delete
if [[ -f "$mnt/boot/grub/grub.cfg" ]]; then
rm $mnt/boot/grub/grub.cfg
fi
if [[ -f "$mnt/etc/machine-id" ]]; then
rm $mnt/etc/machine-id
fi
}

@ -72,7 +72,6 @@ make_sfs() {
error "The path %s does not exist" "${sfs_in}"
retrun 1
fi
local timer=$(get_timer)
mkdir -p ${iso_root}${live_dir}
@ -108,7 +107,6 @@ make_sfs() {
fi
${persist} && rm -r "${work_dir}/embed"
fi
show_elapsed_time "${FUNCNAME}" "${timer_start}"
}
get_disturl(){
@ -146,19 +144,3 @@ assemble_iso(){
${iso_root}/
}
make_iso() {
msg "Start [Build ISO]"
touch "${iso_root}/.artix"
make_sfs "${work_dir}/rootfs"
[[ -d "${work_dir}/livefs" ]] && make_sfs "${work_dir}/livefs"
msg "Making bootable image"
# Sanity checks
[[ ! -d "${iso_root}" ]] && return 1
if [[ -f "${iso_dir}/${iso_file}" ]]; then
msg2 "Removing existing bootable image..."
rm -rf "${iso_dir}/${iso_file}"
fi
assemble_iso
msg "Done [Build ISO]"
}

@ -37,7 +37,7 @@ track_fs() {
mount "$@" && FS_ACTIVE_MOUNTS=("$5" "${FS_ACTIVE_MOUNTS[@]}")
}
mount_overlay(){
mount_overlayfs(){
FS_ACTIVE_MOUNTS=()
local lower= upper="$1" work="$2"
mkdir -p "${mnt_dir}/work"
@ -52,7 +52,7 @@ mount_overlay(){
track_fs -t overlay overlay -olowerdir="$lower",upperdir="$upper",workdir="${mnt_dir}/work" "$upper"
}
umount_overlay(){
umount_overlayfs(){
if [[ -n ${FS_ACTIVE_MOUNTS[@]} ]];then
info "overlayfs umount: [%s]" "${FS_ACTIVE_MOUNTS[@]}"
umount "${FS_ACTIVE_MOUNTS[@]}"

@ -62,43 +62,6 @@ copy_overlay(){
fi
}
clean_up_image(){
local path mnt="$1"
msg2 "Cleaning [%s]" "${mnt##*/}"
path=$mnt/boot
if [[ -d "$path" ]]; then
find "$path" -name 'initramfs*.img' -delete &> /dev/null
fi
path=$mnt/var/lib/pacman/sync
if [[ -d $path ]];then
find "$path" -type f -delete &> /dev/null
fi
path=$mnt/var/cache/pacman/pkg
if [[ -d $path ]]; then
find "$path" -type f -delete &> /dev/null
fi
path=$mnt/var/log
if [[ -d $path ]]; then
find "$path" -type f -delete &> /dev/null
fi
path=$mnt/var/tmp
if [[ -d $path ]];then
find "$path" -mindepth 1 -delete &> /dev/null
fi
path=$mnt/tmp
if [[ -d $path ]];then
find "$path" -mindepth 1 -delete &> /dev/null
fi
find "$mnt" -name *.pacnew -name *.pacsave -name *.pacorig -delete
if [[ -f "$mnt/boot/grub/grub.cfg" ]]; then
rm $mnt/boot/grub/grub.cfg
fi
if [[ -f "$mnt/etc/machine-id" ]]; then
rm $mnt/etc/machine-id
fi
}
make_rootfs() {
if [[ ! -e ${work_dir}/rootfs.lock ]]; then
msg "Prepare [Base installation] (rootfs)"
@ -110,9 +73,9 @@ make_rootfs() {
copy_overlay "${ROOT_OVERLAY}" "${rootfs}"
[[ -z ${LIVE_LIST} ]] && configure_image "${rootfs}"
[[ -z ${LIVE_LIST} ]] && configure_chroot "${rootfs}"
clean_up_image "${rootfs}"
clean_up_chroot "${rootfs}"
: > ${work_dir}/rootfs.lock
@ -127,17 +90,17 @@ make_livefs() {
prepare_dir "${livefs}"
mount_overlay "${livefs}" "${work_dir}"
mount_overlayfs "${livefs}" "${work_dir}"
basestrap "${basestrap_args[@]}" "${livefs}" "${packages[@]}"
copy_overlay "${LIVE_OVERLAY}" "${livefs}"
configure_image "${livefs}"
configure_chroot "${livefs}"
umount_overlay
umount_overlayfs
clean_up_image "${livefs}"
clean_up_chroot "${livefs}"
: > ${work_dir}/livefs.lock
@ -155,7 +118,7 @@ make_bootfs() {
local bootfs="${work_dir}/bootfs"
mount_overlay "${bootfs}" "${work_dir}"
mount_overlayfs "${bootfs}" "${work_dir}"
if ${use_dracut}; then
prepare_initramfs_dracut "${bootfs}"
@ -163,7 +126,7 @@ make_bootfs() {
prepare_initramfs "${bootfs}"
fi
umount_overlay
umount_overlayfs
rm -R ${bootfs}
: > ${work_dir}/bootfs.lock
@ -190,24 +153,3 @@ make_grub(){
msg "Done [/iso/boot/grub]"
fi
}
compress_images(){
local timer=$(get_timer)
run_safe "make_iso"
chown -R "${OWNER}:$(id --group ${OWNER})" "${iso_dir}"
show_elapsed_time "${FUNCNAME}" "${timer}"
}
prepare_images(){
local timer=$(get_timer)
load_pkgs "${ROOT_LIST}" "${INITSYS}"
run_safe "make_rootfs"
if [[ -n ${LIVE_LIST} ]]; then
load_pkgs "${LIVE_LIST}" "${INITSYS}"
run_safe "make_livefs"
fi
run_safe "make_bootfs"
run_safe "make_grub"
show_elapsed_time "${FUNCNAME}" "${timer}"
}

Loading…
Cancel
Save