# Unmount chroot dir
umount_chroot () {
local mount
- for mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir})); do
- _msg_info "Unmounting ${mount}"
+ for mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir}) | sort -r); do
+ [[ "${1}" == debug ]] && _msg_debug "Unmounting ${mount}" || _msg_info "Unmounting ${mount}"
umount -fl "${mount}"
done
}
}
run_cmd() {
- arch-chroot "${work_dir}/airootfs" "${@}"
+ for mount in "dev" "dev/pts" "proc" "sys" "run/systemd/resolve/stub-resolv.conf"; do
+ _msg_debug "Mounting ${work_dir}/airootfs/${mount}"
+ [[ "${mount}" == "run/systemd/resolve/stub-resolv.conf" ]] && mount --bind /etc/resolv.conf "${work_dir}/airootfs/${mount}" || mount --bind /${mount} "${work_dir}/airootfs/${mount}"
+ done
+
+ chroot "${work_dir}/airootfs" "${@}"
+ umount_chroot debug
}
run_bootfiles() {
[[ ! -d "${work_dir}" ]] && mkdir -p "${work_dir}"
[[ ! -d "${out_dir}" ]] && mkdir -p "${out_dir}"
- local mount
- for mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir}) | sort -r); do
- _msg_info "Unmounting ${mount}"
- umount "${mount}"
- done
+ umount_chroot
# Check codename
if [[ -z $(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename}) ]]; then
_apt_install gnupg
for repo in $(find ${channels_dir}/*/repo -name *.list); do
- key="$(dirname $repo)/$(basename $repo | sed "s/list/key/")"
+ key="$(dirname ${repo})/$(basename ${repo} | sed "s/list/key/")"
- if [[ -f "$key" ]]; then
- if $(file $key | grep -q "PGP/GPG key"); then
- cp $key ${work_dir}/airootfs/$(basename $key)
+ if [[ -f "${key}" ]]; then
+ if $(file ${key} | grep -q "PGP/GPG key"); then
+ cp ${key} ${work_dir}/airootfs/$(basename ${key})
else
- wget -q -O ${work_dir}/airootfs/$(basename $key) $(cat $key)
+ wget -q -O ${work_dir}/airootfs/$(basename ${key}) $(cat ${key})
fi
- run_cmd apt-key add $(basename $key)
- rm ${work_dir}/airootfs/$(basename $key)
- cp $repo ${work_dir}/airootfs/etc/apt/sources.list.d
+ run_cmd apt-key add $(basename ${key})
+ rm ${work_dir}/airootfs/$(basename ${key})
+ cp ${repo} ${work_dir}/airootfs/etc/apt/sources.list.d
fi
done
grep -h -v ^'#' "${channels_dir}/${channel_name}/snap-packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/snappkglist"
fi
if [[ -n "$(echo $(<"${work_dir}/airootfs/snappkglist"))" ]]; then
+ _apt_install snapd
run_cmd env -i bash -c 'snap install $(echo $(<snappkglist))'
fi
remove "${work_dir}/airootfs/snappkglist"
}
make_bootfiles() {
- run_cmd update-initramfs -c -k all
+ run_cmd env -i bash -c 'update-initramfs -c -k all'
_apt_install memtest86+
[[ -d "${bootfiles_dir}" ]] && rm -r "${bootfiles_dir}"
mkdir -p ${bootfiles_dir}/{casper,isolinux,install}
--modules="linux16 linux normal iso9660 biosdisk search" \
--locales="" \
--fonts="" \
+ --themes="" \
"boot/grub/grub.cfg=isolinux/grub.cfg"
cat /usr/lib/grub/i386-pc/cdboot.img isolinux/core.img > isolinux/bios.img
}
done
bootfiles_dir="${work_dir}/bootfiles"
+trap umount_chroot 0 2 15
+
+if [[ -n "${1}" ]]; then
+ channel_name="${1}"
+
+ check_channel() {
+ local channel_list
+ local i
+ channel_list=()
+ for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
+ if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then
+ channel_list="${channel_list[@]} ${_channel}"
+ fi
+ done
+ for i in ${channel_list[@]}; do
+ if [[ "${i}" = "${channel_name}" ]]; then
+ echo -n "true"
+ return 0
+ fi
+ done
+ echo -n "false"
+ return 1
+ }
+
+ if [[ $(check_channel ${channel_name}) = false ]]; then
+ _msg_error "Invalid channel ${channel_name}"
+ exit 1
+ fi
+fi
prepare_build
run_once make_sourcelist
run_once make_systemd
run_once make_apt_packages
-# run_once make_snap_packages
+#run_once make_snap_packages
run_once make_config
run_once make_customize_airootfs
run_once make_clean