util-iso-chroot: use local vars for params

This commit is contained in:
udeved 2017-05-09 22:21:28 +02:00
parent 8046b1f4b1
commit bb34a7f6d0

View file

@ -10,28 +10,31 @@
# GNU General Public License for more details. # GNU General Public License for more details.
copy_overlay(){ copy_overlay(){
if [[ -e $1 ]];then local src="$1" dest="$2"
msg2 "Copying [%s] ..." "${1##*/}" if [[ -e $src ]];then
if [[ -L $1 ]];then msg2 "Copying [%s] ..." "${src##*/}"
cp -a --no-preserve=ownership $1/* $2 if [[ -L $src ]];then
cp -a --no-preserve=ownership $src/* $dest
else else
cp -LR $1/* $2 cp -LR $src/* $dest
fi fi
fi fi
} }
add_svc_rc(){ add_svc_rc(){
if [[ -f $1/etc/init.d/$2 ]];then local mnt="$1" name="$1"
msg2 "Setting %s ..." "$2" if [[ -f $mnt/etc/init.d/$name ]];then
chroot $1 rc-update add $2 default &>/dev/null msg2 "Setting %s ..." "$name"
chroot $mnt rc-update add $name default &>/dev/null
fi fi
} }
add_svc_sd(){ add_svc_sd(){
if [[ -f $1/etc/systemd/system/$2.service ]] || \ local mnt="$1" name="$1"
[[ -f $1/usr/lib/systemd/system/$2.service ]];then if [[ -f $mnt/etc/systemd/system/$name.service ]] || \
msg2 "Setting %s ..." "$2" [[ -f $mnt/usr/lib/systemd/system/$name.service ]];then
chroot $1 systemctl enable $2 &>/dev/null msg2 "Setting %s ..." "$name"
chroot $mnt systemctl enable $name &>/dev/null
fi fi
} }
@ -106,23 +109,24 @@ configure_journald(){
} }
configure_services(){ configure_services(){
local mnt="$1"
info "Configuring [%s]" "${initsys}" info "Configuring [%s]" "${initsys}"
case ${initsys} in case ${initsys} in
'openrc') 'openrc')
for svc in ${enable_openrc[@]}; do for svc in ${enable_openrc[@]}; do
[[ $svc == "xdm" ]] && set_xdm "$1" [[ $svc == "xdm" ]] && set_xdm "$mnt"
add_svc_rc "$1" "$svc" add_svc_rc "$mnt" "$svc"
done done
for svc in ${enable_openrc_live[@]}; do for svc in ${enable_openrc_live[@]}; do
add_svc_rc "$1" "$svc" add_svc_rc "$mnt" "$svc"
done done
;; ;;
'systemd') 'systemd')
for svc in ${enable_systemd[@]}; do for svc in ${enable_systemd[@]}; do
add_svc_sd "$1" "$svc" add_svc_sd "$mnt" "$svc"
done done
for svc in ${enable_systemd_live[@]}; do for svc in ${enable_systemd_live[@]}; do
add_svc_sd "$1" "$svc" add_svc_sd "$mnt" "$svc"
done done
;; ;;
esac esac
@ -158,10 +162,11 @@ write_live_session_conf(){
} }
configure_system(){ configure_system(){
local mnt="$1"
case ${initsys} in case ${initsys} in
'systemd') 'systemd')
configure_logind "$1" "systemd" configure_logind "$mnt" "systemd"
configure_journald "$1" configure_journald "$mnt"
# Prevent some services to be started in the livecd # Prevent some services to be started in the livecd
echo 'File created by manjaro-tools. See systemd-update-done.service(8).' \ echo 'File created by manjaro-tools. See systemd-update-done.service(8).' \
@ -171,96 +176,96 @@ configure_system(){
ln -sf /dev/null "${path}/usr/lib/systemd/system-generators/systemd-gpt-auto-generator" ln -sf /dev/null "${path}/usr/lib/systemd/system-generators/systemd-gpt-auto-generator"
;; ;;
'openrc') 'openrc')
configure_logind "$1" "elogind" configure_logind "$mnt" "elogind"
# local hn='hostname="'${hostname}'"'
# sed -i -e "s|^.*hostname=.*|${hn}|" $1/etc/conf.d/hostname
;; ;;
esac esac
echo ${hostname} > $1/etc/hostname echo ${hostname} > $mnt/etc/hostname
} }
make_repo(){ make_repo(){
cp ${DATADIR}/pacman-mhwd.conf $1/opt local dest="$1"
repo-add $1${mhwd_repo}/mhwd.db.tar.gz $1${mhwd_repo}/*pkg*z cp ${DATADIR}/pacman-mhwd.conf $dest/opt
repo-add $dest${mhwd_repo}/mhwd.db.tar.gz $dest${mhwd_repo}/*pkg*z
} }
clean_iso_root(){ clean_iso_root(){
msg2 "Deleting isoroot [%s] ..." "${1##*/}" local dest="$1"
rm -rf --one-file-system "$1" msg2 "Deleting isoroot [%s] ..." "${dest##*/}"
rm -rf --one-file-system "$dest"
} }
clean_up_image(){ clean_up_image(){
msg2 "Cleaning [%s]" "${1##*/}"
local path local path mnt="$1"
msg2 "Cleaning [%s]" "${mnt##*/}"
if [[ ${1##*/} == 'mhwdfs' ]];then if [[ ${1##*/} == 'mhwdfs' ]];then
path=$1/var path=$mnt/var
if [[ -d $path ]];then if [[ -d $path ]];then
find "$path" -mindepth 0 -delete &> /dev/null find "$path" -mindepth 0 -delete &> /dev/null
fi fi
path=$1/etc path=$mnt/etc
if [[ -d $path ]];then if [[ -d $path ]];then
find "$path" -mindepth 0 -delete &> /dev/null find "$path" -mindepth 0 -delete &> /dev/null
fi fi
else else
[[ -f "$1/etc/locale.gen.bak" ]] && mv "$1/etc/locale.gen.bak" "$1/etc/locale.gen" [[ -f "$mnt/etc/locale.gen.bak" ]] && mv "$mnt/etc/locale.gen.bak" "$mnt/etc/locale.gen"
[[ -f "$1/etc/locale.conf.bak" ]] && mv "$1/etc/locale.conf.bak" "$1/etc/locale.conf" [[ -f "$mnt/etc/locale.conf.bak" ]] && mv "$mnt/etc/locale.conf.bak" "$mnt/etc/locale.conf"
path=$1/boot path=$mnt/boot
if [[ -d "$path" ]]; then if [[ -d "$path" ]]; then
find "$path" -name 'initramfs*.img' -delete &> /dev/null find "$path" -name 'initramfs*.img' -delete &> /dev/null
fi fi
path=$1/var/lib/pacman/sync path=$mnt/var/lib/pacman/sync
if [[ -d $path ]];then if [[ -d $path ]];then
find "$path" -type f -delete &> /dev/null find "$path" -type f -delete &> /dev/null
fi fi
path=$1/var/cache/pacman/pkg path=$mnt/var/cache/pacman/pkg
if [[ -d $path ]]; then if [[ -d $path ]]; then
find "$path" -type f -delete &> /dev/null find "$path" -type f -delete &> /dev/null
fi fi
path=$1/var/log path=$mnt/var/log
if [[ -d $path ]]; then if [[ -d $path ]]; then
find "$path" -type f -delete &> /dev/null find "$path" -type f -delete &> /dev/null
fi fi
path=$1/var/tmp path=$mnt/var/tmp
if [[ -d $path ]];then if [[ -d $path ]];then
find "$path" -mindepth 1 -delete &> /dev/null find "$path" -mindepth 1 -delete &> /dev/null
fi fi
path=$1/tmp path=$mnt/tmp
if [[ -d $path ]];then if [[ -d $path ]];then
find "$path" -mindepth 1 -delete &> /dev/null find "$path" -mindepth 1 -delete &> /dev/null
fi fi
if [[ ${1##*/} == 'livefs' ]];then if [[ ${$mnt##*/} == 'livefs' ]];then
rm -rf "$1/etc/pacman.d/gnupg" rm -rf "$mnt/etc/pacman.d/gnupg"
fi fi
fi fi
find "$1" -name *.pacnew -name *.pacsave -name *.pacorig -delete find "$mnt" -name *.pacnew -name *.pacsave -name *.pacorig -delete
file=$1/boot/grub/grub.cfg file=$mnt/boot/grub/grub.cfg
if [[ -f "$file" ]]; then if [[ -f "$file" ]]; then
rm $file rm $file
fi fi
} }
copy_from_cache(){ copy_from_cache(){
local list="${tmp_dir}"/mhwd-cache.list local list="${tmp_dir}"/mhwd-cache.list mnt="$1"
chroot-run \ chroot-run \
-r "${bindmounts_ro[*]}" \ -r "${bindmounts_ro[*]}" \
-w "${bindmounts_rw[*]}" \ -w "${bindmounts_rw[*]}" \
-B "${build_mirror}/${target_branch}" \ -B "${build_mirror}/${target_branch}" \
"$1" \ "$mnt" \
pacman -v -Syw $2 --noconfirm || return 1 pacman -v -Syw $2 --noconfirm || return 1
chroot-run \ chroot-run \
-r "${bindmounts_ro[*]}" \ -r "${bindmounts_ro[*]}" \
-w "${bindmounts_rw[*]}" \ -w "${bindmounts_rw[*]}" \
-B "${build_mirror}/${target_branch}" \ -B "${build_mirror}/${target_branch}" \
"$1" \ "$mnt" \
pacman -v -Sp $2 --noconfirm > "$list" pacman -v -Sp $2 --noconfirm > "$list"
sed -ni '/.pkg.tar.xz/p' "$list" sed -ni '/.pkg.tar.xz/p' "$list"
sed -i "s/.*\///" "$list" sed -i "s/.*\///" "$list"
msg2 "Copying mhwd package cache ..." msg2 "Copying mhwd package cache ..."
rsync -v --files-from="$list" /var/cache/pacman/pkg "$1${mhwd_repo}" rsync -v --files-from="$list" /var/cache/pacman/pkg "$mnt${mhwd_repo}"
} }
chroot_clean(){ chroot_clean(){
@ -279,19 +284,21 @@ chroot_clean(){
prepare_initcpio(){ prepare_initcpio(){
msg2 "Copying initcpio ..." msg2 "Copying initcpio ..."
cp /etc/initcpio/hooks/miso* $1/etc/initcpio/hooks local dest="$1"
cp /etc/initcpio/install/miso* $1/etc/initcpio/install cp /etc/initcpio/hooks/miso* $dest/etc/initcpio/hooks
cp /etc/initcpio/miso_shutdown $1/etc/initcpio cp /etc/initcpio/install/miso* $dest/etc/initcpio/install
cp /etc/initcpio/miso_shutdown $dest/etc/initcpio
} }
prepare_initramfs(){ prepare_initramfs(){
cp ${DATADIR}/mkinitcpio.conf $1/etc/mkinitcpio-${iso_name}.conf local mnt="$1"
local _kernver=$(cat $1/usr/lib/modules/*/version) cp ${DATADIR}/mkinitcpio.conf $mnt/etc/mkinitcpio-${iso_name}.conf
local _kernver=$(cat $mnt/usr/lib/modules/*/version)
if [[ -n ${gpgkey} ]]; then if [[ -n ${gpgkey} ]]; then
su ${OWNER} -c "gpg --export ${gpgkey} >${MT_USERCONFDIR}/gpgkey" su ${OWNER} -c "gpg --export ${gpgkey} >${MT_USERCONFDIR}/gpgkey"
exec 17<>${MT_USERCONFDIR}/gpgkey exec 17<>${MT_USERCONFDIR}/gpgkey
fi fi
MISO_GNUPG_FD=${gpgkey:+17} chroot-run $1 \ MISO_GNUPG_FD=${gpgkey:+17} chroot-run $mnt \
/usr/bin/mkinitcpio -k ${_kernver} \ /usr/bin/mkinitcpio -k ${_kernver} \
-c /etc/mkinitcpio-${iso_name}.conf \ -c /etc/mkinitcpio-${iso_name}.conf \
-g /boot/initramfs.img -g /boot/initramfs.img
@ -305,10 +312,11 @@ prepare_initramfs(){
} }
prepare_boot_extras(){ prepare_boot_extras(){
cp $1/boot/intel-ucode.img $2/intel_ucode.img local src="$1" dest="$2"
cp $1/usr/share/licenses/intel-ucode/LICENSE $2/intel_ucode.LICENSE cp $src/boot/intel-ucode.img $dest/intel_ucode.img
cp $1/boot/memtest86+/memtest.bin $2/memtest cp $src/usr/share/licenses/intel-ucode/LICENSE $dest/intel_ucode.LICENSE
cp $1/usr/share/licenses/common/GPL2/license.txt $2/memtest.COPYING cp $src/boot/memtest86+/memtest.bin $dest/memtest
cp $src/usr/share/licenses/common/GPL2/license.txt $dest/memtest.COPYING
} }
prepare_grub(){ prepare_grub(){