diff --git a/bin/buildpkg.in b/bin/buildpkg.in index e32bc0d..cee8080 100644 --- a/bin/buildpkg.in +++ b/bin/buildpkg.in @@ -51,6 +51,7 @@ display_settings(){ msg "ARGS:" msg2 "create_first: %s" "${create_first}" + msg2 "delete_first: %s" "${delete_first}" msg2 "clean_first: %s" "${clean_first}" msg2 "update_first: %s" "${update_first}" msg2 "purge: %s" "${purge}" @@ -63,7 +64,7 @@ display_settings(){ if ${create_first};then msg "PKG:" - msg2 "base_packages: %s" "${base_packages[*]}" + msg2 "packages: %s" "${packages[*]}" fi msg "BUILD QUEUE:" @@ -77,6 +78,7 @@ load_vars "${PAC_USERCONFDIR}/makepkg.conf" || load_vars "$USER_HOME/.makepkg.co load_vars /etc/makepkg.conf create_first=false +delete_first=false clean_first=false update_first=false purge=false @@ -133,12 +135,13 @@ usage() { echo " [default: ${chroots_pkg}]" echo ' -i Install packages into the working copy of the chroot' echo ' -o Create chroot' + echo ' -d Delete chroot' echo ' -c Clean chroot copy' echo ' -u Update chroot copy' echo ' -w Clean up cache and sources' echo ' -n Install and run namcap check' echo ' -s Sign packages' - echo ' -d Udev base-devel group (no systemd)' + echo ' -x Udev base-devel group (no systemd)' echo ' -q Query settings and pretend build' echo ' -h This help' echo '' @@ -148,7 +151,7 @@ usage() { orig_argv=("$0" "$@") -opts='p:a:b:r:i:cownsudqh' +opts='p:a:b:r:i:cdownsxdqh' while getopts "${opts}" arg; do case "${arg}" in @@ -158,6 +161,7 @@ while getopts "${opts}" arg; do r) chroots_pkg="$OPTARG" ;; i) install_pkgs+=("$OPTARG"); mkchrootpkg_args+=(-I "${install_pkgs[*]}") ;; o) create_first=true ;; + d) delete_first=true ;; c) clean_first=true ; mkchrootpkg_args+=(-c) ;; u) update_first=true ; mkchrootpkg_args+=(-u) ;; w) wipe_clean=true ;; @@ -166,7 +170,7 @@ while getopts "${opts}" arg; do d) udev_root=true ;; q) pretend=true ;; h|?) usage 0 ;; - *) echo "invalid argument '${arg}'"; usage 1 ;; + *) echo "invalid argument '%s'" "${arg}"; usage 1 ;; esac done @@ -178,6 +182,8 @@ prepare_build ${pretend} && display_settings && exit -${create_first} && chroot_init "${work_dir}" +${delete_first} && delete_chroot "${work_dir}" "${work_dir}/root" + +${create_first} && create_chroot "${work_dir}/root" "${packages[@]}" run make_pkg "${build_list_pkg}" diff --git a/bin/mkchrootpkg.in b/bin/mkchrootpkg.in index b64248f..cbcf2b3 100644 --- a/bin/mkchrootpkg.in +++ b/bin/mkchrootpkg.in @@ -122,24 +122,24 @@ sync_chroot() { } # Usage: delete_chroot $copydir [$copy] -delete_chroot() { - local copydir=$1 - local copy=${1:-$2} - - stat_busy "Removing chroot copy [%s]" "$copy" - if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then - subvolume_delete_recursive "$copydir" || - die "Unable to delete subvolume %s" "$copydir" - else - # avoid change of filesystem in case of an umount failure - rm --recursive --force --one-file-system "$copydir" || - die "Unable to delete %s" "$copydir" - fi - - # remove lock file - rm -f "$copydir.lock" - stat_done -} +# delete_chroot() { +# local copydir=$1 +# local copy=${1:-$2} +# +# stat_busy "Removing chroot copy [%s]" "$copy" +# if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then +# subvolume_delete_recursive "$copydir" || +# die "Unable to delete subvolume %s" "$copydir" +# else +# # avoid change of filesystem in case of an umount failure +# rm --recursive --force --one-file-system "$copydir" || +# die "Unable to delete %s" "$copydir" +# fi +# +# # remove lock file +# rm -f "$copydir.lock" +# stat_done +# } # Usage: install_packages $copydir $pkgs... install_packages() { diff --git a/lib/util-chroot.sh b/lib/util-chroot.sh index e45406f..ebd6819 100644 --- a/lib/util-chroot.sh +++ b/lib/util-chroot.sh @@ -44,6 +44,33 @@ subvolume_delete_recursive() { return 0 } +create_chroot(){ + local timer=$(get_timer) + setarch "${target_arch}" \ + mkchroot "${mkchroot_args[@]}" "$@" || abort + + show_elapsed_time "${FUNCNAME}" "${timer}" +} + +delete_chroot() { + local copydir=$1 + local copy=${1:-$2} + + stat_busy "Removing chroot copy [%s]" "$copy" + if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then + subvolume_delete_recursive "$copydir" || + die "Unable to delete subvolume %s" "$copydir" + else + # avoid change of filesystem in case of an umount failure + rm --recursive --force --one-file-system "$copydir" || + die "Unable to delete %s" "$copydir" + fi + + # remove lock file + rm -f "$copydir.lock" + stat_done +} + # $1: chroot # kill_chroot_process(){ # # enable to have more debug info diff --git a/lib/util-iso-chroot.sh b/lib/util-iso-chroot.sh index 67f7447..00478de 100644 --- a/lib/util-iso-chroot.sh +++ b/lib/util-iso-chroot.sh @@ -254,28 +254,14 @@ copy_from_cache(){ rsync -v --files-from="$list" /var/cache/pacman/pkg "$1${mhwd_repo}" } -chroot_create(){ - [[ "${1##*/}" == "rootfs" ]] && local flag="-L" - setarch "${target_arch}" \ - mkchroot "${mkchroot_args[@]}" ${flag} $@ -} - chroot_clean(){ local dest="$1" for root in "$dest"/*; do [[ -d ${root} ]] || continue local name=${root##*/} if [[ $name != "mhwdfs" ]];then - slock 9 "%s.lock" "Locking chroot '%s'" "${root}" "${root}" - stat_busy "Deleting chroot [%s] (%s) ..." "${root}" "${root}" - - subvolume_delete_recursive "${root}" - - stat_done - lock_close 9 - - rm -rf --one-file-system "${root}" - rm -f "${root}.lock" + lock 9 "$name.lock" "Locking chroot copy [%s]" "$name" + delete_chroot "$dest" "${root}" fi done diff --git a/lib/util-iso.sh b/lib/util-iso.sh index 02e2e95..a9bd17d 100644 --- a/lib/util-iso.sh +++ b/lib/util-iso.sh @@ -280,9 +280,9 @@ make_image_root() { if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then msg "Prepare [Base installation] (rootfs)" local path="${work_dir}/rootfs" - mkdir -p ${path} +# mkdir -p ${path} - chroot_create "${path}" "${packages}" || die + create_chroot "-L" "${path}" "${packages[@]}" || die pacman -Qr "${path}" > "${path}/rootfs-pkgs.txt" copy_overlay "${profile_dir}/root-overlay" "${path}" @@ -301,11 +301,11 @@ make_image_desktop() { if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then msg "Prepare [Desktop installation] (desktopfs)" local path="${work_dir}/desktopfs" - mkdir -p ${path} +# mkdir -p ${path} mount_fs_root "${path}" - chroot_create "${path}" "${packages}" + create_chroot "${path}" "${packages[@]}" pacman -Qr "${path}" > "${path}/desktopfs-pkgs.txt" cp "${path}/desktopfs-pkgs.txt" ${iso_dir}/$(gen_iso_fn)-pkgs.txt @@ -322,7 +322,7 @@ make_image_desktop() { mount_fs_select(){ local fs="$1" - if [[ -f "${packages_desktop}" ]]; then + if [[ -f "${pkglist_desktop}" ]]; then mount_fs_desktop "$fs" else mount_fs_root "$fs" @@ -333,11 +333,11 @@ make_image_live() { if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then msg "Prepare [Live installation] (livefs)" local path="${work_dir}/livefs" - mkdir -p ${path} +# mkdir -p ${path} mount_fs_select "${path}" - chroot_create "${path}" "${packages}" + create_chroot "${path}" "${packages[@]}" pacman -Qr "${path}" > "${path}/livefs-pkgs.txt" copy_overlay "${profile_dir}/live-overlay" "${path}" @@ -365,11 +365,11 @@ make_image_mhwd() { reset_pac_conf "${path}" - copy_from_cache "${path}" "${packages}" + copy_from_cache "${path}" "${packages[@]}" - if [[ -n "${packages_cleanup}" ]]; then - for mhwd_clean in ${packages_cleanup}; do - rm ${path}${mhwd_repo}/${mhwd_clean} + if [[ -n "${packages_cleanup[@]}" ]]; then + for pkg in ${packages_cleanup[@]}; do + rm ${path}${mhwd_repo}/${pkg} done fi cp ${DATADIR}/pacman-mhwd.conf ${path}/opt @@ -395,7 +395,7 @@ make_image_boot() { local path="${work_dir}/bootfs" mkdir -p ${path} - if [[ -f "${packages_desktop}" ]]; then + if [[ -f "${pkglist_desktop}" ]]; then mount_fs_live "${path}" else mount_fs_net "${path}" @@ -480,16 +480,16 @@ prepare_images(){ local timer=$(get_timer) load_pkgs "${profile_dir}/Packages-Root" run_safe "make_image_root" - if [[ -f "${packages_desktop}" ]] ; then - load_pkgs "${packages_desktop}" + if [[ -f "${pkglist_desktop}" ]] ; then + load_pkgs "${pkglist_desktop}" run_safe "make_image_desktop" 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}" + if [[ -f ${mhwd_list} ]] ; then + load_pkgs "${mhwd_list}" run_safe "make_image_mhwd" fi run_safe "make_image_boot" diff --git a/lib/util-pkg-chroot.sh b/lib/util-pkg-chroot.sh index a86588a..a4dcf5a 100644 --- a/lib/util-pkg-chroot.sh +++ b/lib/util-pkg-chroot.sh @@ -60,13 +60,13 @@ init_base_devel(){ _multi="s|>multilib.*||g" ${is_multilib} && _multi="s|>multilib||g" - base_packages=($(sed "$_com_rm" "$file" \ + packages=($(sed "$_com_rm" "$file" \ | sed "$_space" \ | sed "$_multi" \ | sed "$_clean")) else - base_packages=('base-devel') - ${is_multilib} && base_packages+=('multilib-devel') + packages=('base-devel') + ${is_multilib} && packages+=('multilib-devel') fi } @@ -131,18 +131,6 @@ post_build(){ archive_logs "$name" } -chroot_init(){ - local timer=$(get_timer) - local dest="$1" - mkdir -p "${dest}" - setarch "${target_arch}" \ - mkchroot "${mkchroot_args[@]}" \ - "${dest}/root" \ - "${base_packages[@]}" || abort - - show_elapsed_time "${FUNCNAME}" "${timer}" -} - build_pkg(){ prepare_dir "${pkg_dir}" user_own "${pkg_dir}" diff --git a/lib/util-yaml.sh b/lib/util-yaml.sh index 0c649b4..a4bd57c 100644 --- a/lib/util-yaml.sh +++ b/lib/util-yaml.sh @@ -135,7 +135,7 @@ write_unpack_conf(){ echo " - source: \"/run/miso/bootmnt/${iso_name}/${target_arch}/rootfs.sfs\"" >> "$conf" echo " sourcefs: \"squashfs\"" >> "$conf" echo " destination: \"\"" >> "$conf" - if [[ -f "${packages_desktop}" ]] ; then + if [[ -f "${desktop_list}" ]] ; then echo " - source: \"/run/miso/bootmnt/${iso_name}/${target_arch}/desktopfs.sfs\"" >> "$conf" echo " sourcefs: \"squashfs\"" >> "$conf" echo " destination: \"\"" >> "$conf" @@ -417,8 +417,8 @@ make_profile_yaml(){ prepare_check "$1" load_pkgs "${profile_dir}/Packages-Root" write_netgroup_yaml "$1" "$(gen_fn "Packages-Root")" - if [[ -f "${packages_desktop}" ]]; then - load_pkgs "${packages_desktop}" + if [[ -f "${desktop_list}" ]]; then + load_pkgs "${desktop_list}" write_netgroup_yaml "$1" "$(gen_fn "Packages-Desktop")" fi ${calamares} && write_calamares_yaml "$1" diff --git a/lib/util.sh b/lib/util.sh index adee555..e393003 100644 --- a/lib/util.sh +++ b/lib/util.sh @@ -410,8 +410,8 @@ reset_profile(){ unset disable_openrc unset enable_systemd_live unset enable_openrc_live - unset packages_desktop - unset packages_mhwd + unset desktop_list + unset mhwd_list unset login_shell unset netinstall unset chrootcfg @@ -447,9 +447,9 @@ check_profile(){ die "Profile [%s] sanity check failed!" "$1" fi - [[ -f "$1/Packages-Desktop" ]] && packages_desktop=$1/Packages-Desktop + [[ -f "$1/Packages-Desktop" ]] && desktop_list=$1/Packages-Desktop - [[ -f "$1/Packages-Mhwd" ]] && packages_mhwd=$1/Packages-Mhwd + [[ -f "$1/Packages-Mhwd" ]] && mhwd_list=$1/Packages-Mhwd if ! ${netinstall}; then chrootcfg="false" @@ -553,7 +553,7 @@ load_pkgs(){ _purge="s|>cleanup.*||g" \ _purge_rm="s|>cleanup||g" - packages=$(sed "$_com_rm" "$1" \ + packages=($(sed "$_com_rm" "$1" \ | sed "$_space" \ | sed "$_blacklist" \ | sed "$_purge" \ @@ -573,18 +573,18 @@ load_pkgs(){ | sed "$_basic_rm" \ | sed "$_extra" \ | sed "$_extra_rm" \ - | sed "$_clean") + | sed "$_clean")) - if [[ $1 == "${packages_mhwd}" ]]; then + if [[ $1 == "${mhwd_list}" ]]; then [[ ${_used_kernel} < "42" ]] && local _amd="s|xf86-video-amdgpu||g" - packages_cleanup=$(sed "$_com_rm" "$1" \ + packages_cleanup=($(sed "$_com_rm" "$1" \ | grep cleanup \ | sed "$_purge_rm" \ | sed "$_kernel" \ | sed "$_clean" \ - | sed "$_amd") + | sed "$_amd")) fi }