X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=lfbs;h=c0cc9d4d1413938052794c3820689c5d7dab57d8;hb=9a8c40c7ddc266b58139e37712e4905fbba582c1;hp=b4be2ec6f2de22bc8f7ef86f64c8bb58a745a677;hpb=faf58aaca1cd7f386c8fa49c8c9fa65b10b64a96;p=alterlinux%2FLFBS.git diff --git a/lfbs b/lfbs index b4be2ec..c0cc9d4 100755 --- a/lfbs +++ b/lfbs @@ -22,8 +22,10 @@ codename="32" os_name="Fedora" iso_name="Fedora" language="ja_JP.UTF-8" +channel_name="lxde" +cache_dir="${script_path}/cache" -arch=x86_64 +arch="x86_64" out_dir="${script_path}/out" iso_label="${os_name}_${codename}_${arch}" @@ -31,8 +33,8 @@ iso_publisher='Fascode Network ' iso_application="${os_name} Live/Rescue CD" iso_version="${codename}-$(date +%Y.%m.%d)" iso_filename="${iso_name}-${iso_version}-${arch}.iso" -liveuser_name=fedora -liveuser_password=fedora +liveuser_name="fedora" +liveuser_password="fedora" liveuser_shell="/usr/bin/zsh" #-- language config --# @@ -107,9 +109,7 @@ umount_chroot () { local mount for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do - if [[ "${mount}" == "${work_dir}/airootfs" ]]; then - : - else + if [[ ! "${mount}" == "${work_dir}/airootfs" ]]; then _msg_info "Unmounting ${mount}" umount -fl "${mount}" fi @@ -151,19 +151,18 @@ run_cmd() { fi done - chroot "${work_dir}/airootfs" "${@}" + unshare --fork --pid chroot "${work_dir}/airootfs" "${@}" for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do - if [[ "${mount}" == "${work_dir}/airootfs" ]]; then - : - else + if [[ ! "${mount}" == "${work_dir}/airootfs" ]]; then umount -fl "${mount}" fi done } -_dnf_install() { - run_cmd dnf install -y ${@} +_dnf_install() { + mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache" + run_cmd dnf -c /dnf_conf install -y ${@} } # rm helper @@ -195,8 +194,6 @@ _usage () { echo echo " -a | --arch Set architecture" echo " Default: ${arch}" - echo " -c | --codename Set ubuntu codename" - echo " Default: ${codename}" echo " -l | --lang Specifies the default language for the live environment" echo " Default: ${locale_name}" echo " -m | --mirror Set apt mirror server." @@ -205,6 +202,8 @@ _usage () { echo " Default: ${out_dir}" echo " -w | --work Set the working directory" echo " Default: ${work_dir}" + echo " -c | --cache Set the cache directory" + echo " Default: ${cache_dir}" echo echo " -d | --debug " echo " -h | --help This help message and exit" @@ -253,16 +252,28 @@ _usage () { done } - +dnfstrap() { + if [[ ! -d "${cache_dir}" ]]; then + mkdir -p "${cache_dir}" + fi + cp -rf "${script_path}/system/dnfconf.conf" "${work_dir}/airootfs/dnf_conf" + if [[ ! -d "${work_dir}/airootfs/dnf_cache" ]]; then + mkdir -p "${work_dir}/airootfs/dnf_cache" + fi + mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache" + dnf -c "${work_dir}/airootfs/dnf_conf" --installroot="${work_dir}/airootfs" $(${script_path}/system/repository-json-parser.py ${script_path}/system/repository.json) install ${@} -y + umount -fl "${work_dir}/airootfs/dnf_cache" +} make_basefs() { _msg_info "Installing Fedora to '${work_dir}/airootfs'..." - dnf --installroot="${work_dir}/airootfs" $(${script_path}/system/repository-json-parser.py ${script_path}/system/repository.json) install @Core -y + dnfstrap @Core yamad-repo _msg_info "${codename} installed successfully!" echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}' > "${work_dir}/airootfs/etc/bash.bashrc" - run_cmd dnf update -y - run_cmd dnf -y remove $(run_cmd dnf repoquery --installonly --latest-limit=-1 -q) + mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache" + run_cmd dnf -c /dnf_conf update -y + run_cmd dnf -c /dnf_conf -y remove $(run_cmd dnf -c /dnf_conf repoquery --installonly --latest-limit=-1 -q) # run_cmd apt-get upgrade } @@ -299,30 +310,25 @@ parse_files() { locale_time="${_locale_config_line[3]}" locale_fullname="${_locale_config_line[4]}" } + prepare_build() { if [[ ${EUID} -ne 0 ]]; then _msg_error "This script must be run as root." 1 fi umount_chroot_airootfs # Check codename - if [[ -z $(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename}) ]]; then + if [[ -z "$(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename})" ]]; then _msg_error "This codename (${channel_name}) is not supported on this channel (${codename})." fi - if [[ -d "${work_dir}/squashfsroot/LiveOS/" ]]; then - : - else + if [[ ! -d "${work_dir}/squashfsroot/LiveOS/" ]]; then mkdir -p "${work_dir}/squashfsroot/LiveOS/" mkdir -p "${work_dir}/airootfs/" _msg_info "Make rootfs image..." - truncate -s 5G "${work_dir}/squashfsroot/LiveOS/rootfs.img" + truncate -s 6G "${work_dir}/squashfsroot/LiveOS/rootfs.img" _msg_info "Format rootfs image..." mkfs.ext4 -F "${work_dir}/squashfsroot/LiveOS/rootfs.img" fi - if [[ -d "${out_dir}" ]]; then - : - else - mkdir -p "${out_dir}" - fi + mkdir -p "${out_dir}" _msg_info "Mount rootfs image..." mount -o loop,rw,sync "${work_dir}/squashfsroot/LiveOS/rootfs.img" "${work_dir}/airootfs" @@ -331,9 +337,7 @@ prepare_build() { make_systemd() { _dnf_install dbus-tools run_cmd dbus-uuidgen --ensure=/etc/machine-id - if [[ -d "${work_dir}/airootfs/var/lib/dbus" ]]; then - : - else + if [[ ! -d "${work_dir}/airootfs/var/lib/dbus" ]]; then run_cmd mkdir /var/lib/dbus fi run_cmd ln -sf /etc/machine-id /var/lib/dbus/machine-id @@ -359,7 +363,8 @@ make_dnf_packages() { fi if [[ -s "${work_dir}/airootfs/dnfpkglist" ]]; then - run_cmd env -i bash -c 'dnf -y --nogpgcheck install $(echo $( "${work_dir}/airootfs/etc/locale.conf" - run_cmd truncate -s 0 /etc/machine-id - run_cmd passwd -u -f root + _run_script "/root/customize_airootfs.sh" "/root/customize_airootfs_${channel_name}.sh" } + make_clean() { - run_cmd dnf -y remove $(run_cmd dnf repoquery --installonly --latest-limit=-1 -q) - run_cmd dnf clean all + mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache" + run_cmd dnf -c /dnf_conf -y remove $(run_cmd dnf -c /dnf_conf repoquery --installonly --latest-limit=-1 -q) } make_squashfs() { # prepare - [[ -d "${bootfiles_dir}" ]] && rm -r "${bootfiles_dir}" + remove "${bootfiles_dir}" + if [[ -d "${work_dir}/airootfs/dnf_cache" ]]; then + rm -rf "${work_dir}/airootfs/dnf_cache" + fi mkdir -p "${bootfiles_dir}"/{grub,LiveOS,boot,isolinux} #generate initrd _msg_info "make initrd..." @@ -439,7 +438,7 @@ make_squashfs() { #cp isolinux cp "${nfb_dir}"/isolinux/* "${bootfiles_dir}/isolinux/" # make squashfs - rm -rf "${work_dir}/airootfs/boot" + remove "${work_dir}/airootfs/boot" umount "${work_dir}/airootfs" _msg_info "Minimize rootfs..." resize2fs -M "${work_dir}/squashfsroot/LiveOS/rootfs.img" @@ -480,7 +479,7 @@ make_efi() { cp "${bootfiles_dir}/grub/bootia32.efi" "${bootfiles_dir}/mnt/efi/boot" cp "${bootfiles_dir}/grub/bootx64.efi" "${bootfiles_dir}/mnt/efi/boot" umount -d "${bootfiles_dir}/mnt" - rm -r "${bootfiles_dir}/mnt" + remove "${bootfiles_dir}/mnt" } make_iso() { cd "${bootfiles_dir}" @@ -544,21 +543,11 @@ eval set -- "${OPT}" while :; do case ${1} in -a | --arch) - if [[ -z ${2} ]]; then - _msg_error "Please specify the architecture." - exit 1 - else - arch="${2}" - fi + arch="${2}" shift 2 ;; - -c | --codename) - if [[ -z ${2} ]]; then - _msg_error "Please specify the codename." - exit 1 - else - codename="${2}" - fi + -c | --cache) + cache_dir="${2}" shift 2 ;; -d | --debug) @@ -570,13 +559,7 @@ while :; do exit 0 ;; -m | --mirror) - if [[ -z ${2} ]]; then - _msg_error "Please specify the mirror server." - exit 1 - else - mirror="${2}" - fi - + mirror="${2}" shift 2 ;; -l | --lang) @@ -584,23 +567,11 @@ while :; do shift 2 ;; -o | --out) - if [[ -z ${2} ]]; then - _msg_error "Please specify the out dir." - exit 1 - else - out_dir="${2}" - fi - + out_dir="${2}" shift 2 ;; -w | --work) - if [[ -z ${2} ]]; then - _msg_error "Please specify the out dir." - exit 1 - else - work_dir="${2}" - fi - + work_dir="${2}" shift 2 ;; --cache-only) @@ -619,7 +590,7 @@ while :; do done bootfiles_dir="${work_dir}/bootfiles" -trap umount_chroot 0 2 15 +trap umount_chroot_airootfs 0 2 15 if [[ -n "${1}" ]]; then channel_name="${1}" @@ -630,7 +601,7 @@ if [[ -n "${1}" ]]; then if [[ "${channel_name}" = "clean" ]]; then umount_chroot_airootfs _msg_info "deleting work dir..." - rm -rf "${work_dir}" + remove "${work_dir}" exit 0 fi check_channel() { @@ -639,7 +610,7 @@ if [[ -n "${1}" ]]; then channel_list=() for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do - if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then + if [[ -n "$(ls "${channels_dir}/${_channel}")" ]] && [[ ! "${_channel}" = "share" ]]; then channel_list+=( "${_channel}" ) fi done @@ -655,7 +626,7 @@ if [[ -n "${1}" ]]; then return 1 } - if [[ $(check_channel ${channel_name}) = false ]]; then + if [[ "$(check_channel ${channel_name})" = false ]]; then _msg_error "Invalid channel ${channel_name}" exit 1 fi @@ -664,8 +635,9 @@ iso_filename="${iso_name}-${codename}-${channel_name}-${locale_name}-$(date +%Y. umount_chroot_airootfs if [[ -d "${work_dir}" ]]; then _msg_info "deleting work dir..." - rm -rf "${work_dir}" + remove "${work_dir}" fi + prepare_build parse_files run_once make_basefs