From 9d4bd376dccce2f6c293774648acfebe47c1f485 Mon Sep 17 00:00:00 2001 From: udeved Date: Tue, 13 Jun 2017 17:58:26 +0200 Subject: [PATCH] mkchroot: simplify locale handling --- bin/mkchroot.in | 2 +- lib/util-chroot.sh | 33 +++++++++++++++++---------------- lib/util-iso-chroot.sh | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/bin/mkchroot.in b/bin/mkchroot.in index 4c0efc9..112c1c9 100644 --- a/bin/mkchroot.in +++ b/bin/mkchroot.in @@ -109,7 +109,7 @@ basestrap "${basestrap_args[@]}" "$working_dir" ${cache_dirs[@]/#/--cachedir=} " echo "$version" > "$working_dir/.manjaro-tools" -set_locale "$working_dir" +default_locale "set" "$working_dir" chroot_args=(${pacman_conf:+-C "$pacman_conf"} ${makepkg_conf:+-M "$makepkg_conf"} ${cache_dir:+-c "$cache_dir"}) ${nosetarch} && chroot_args+=(${nosetarch:+-s}) diff --git a/lib/util-chroot.sh b/lib/util-chroot.sh index ff8342d..fbd2fec 100644 --- a/lib/util-chroot.sh +++ b/lib/util-chroot.sh @@ -44,25 +44,26 @@ subvolume_delete_recursive() { return 0 } -set_locale(){ - local mnt="$1" - if [[ ! -f "$mnt/etc/locale.gen.bak" ]] && [[ ! -f "$mnt/etc/locale.conf.bak" ]];then - info "Setting locale ..." - mv "$mnt/etc/locale.gen" "$mnt/etc/locale.gen.bak" - mv "$mnt/etc/locale.conf" "$mnt/etc/locale.conf.bak" - printf '%s.UTF-8 UTF-8\n' en_US > "$mnt/etc/locale.gen" - printf 'LANG=%s.UTF-8\n' en_US > "$mnt/etc/locale.conf" - printf 'LC_MESSAGES=C\n' >> "$mnt/etc/locale.conf" +default_locale(){ + local action="$1" mnt="$2" + if [[ $action == "set" ]];then + if [[ ! -f "$mnt/etc/locale.gen.bak" ]] && [[ ! -f "$mnt/etc/locale.conf.bak" ]];then + info "Setting locale ..." + mv "$mnt/etc/locale.gen" "$mnt/etc/locale.gen.bak" + mv "$mnt/etc/locale.conf" "$mnt/etc/locale.conf.bak" + printf '%s.UTF-8 UTF-8\n' en_US > "$mnt/etc/locale.gen" + printf 'LANG=%s.UTF-8\n' en_US > "$mnt/etc/locale.conf" + printf 'LC_MESSAGES=C\n' >> "$mnt/etc/locale.conf" + fi + elif [[ $action == "reset" ]];then + if [[ -f "$mnt/etc/locale.gen.bak" ]] && [[ -f "$mnt/etc/locale.conf.bak" ]];then + info "Resetting locale ..." + mv "$mnt/etc/locale.gen.bak" "$mnt/etc/locale.gen" + mv "$mnt/etc/locale.conf.bak" "$mnt/etc/locale.conf" + fi fi } -reset_locale(){ - local mnt="$1" - info "Resetting locale ..." - [[ -f "$mnt/etc/locale.gen.bak" ]] && mv "$mnt/etc/locale.gen.bak" "$mnt/etc/locale.gen" - [[ -f "$mnt/etc/locale.conf.bak" ]] && mv "$mnt/etc/locale.conf.bak" "$mnt/etc/locale.conf" -} - create_chroot(){ local timer=$(get_timer) setarch "${target_arch}" \ diff --git a/lib/util-iso-chroot.sh b/lib/util-iso-chroot.sh index f8ce12e..2226e1d 100644 --- a/lib/util-iso-chroot.sh +++ b/lib/util-iso-chroot.sh @@ -169,7 +169,7 @@ clean_up_image(){ find "$path" -mindepth 0 -delete &> /dev/null fi else - reset_locale "$mnt" + default_locale "reset" "$mnt" path=$mnt/boot if [[ -d "$path" ]]; then find "$path" -name 'initramfs*.img' -delete &> /dev/null