big code cleanup

This commit is contained in:
Tobias Powalowski 2022-01-21 14:16:33 +01:00
parent 140bb4a656
commit bef4cc2c79
2 changed files with 40 additions and 51 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
DESTDIR="${1}"
PACMAN="pacman --root "${DESTDIR}" --cachedir "${DESTDIR}"/var/cache/pacman/pkg --noconfirm"
PACMAN="pacman --root ${DESTDIR} --cachedir ${DESTDIR}/var/cache/pacman/pkg --noconfirm"
# name of kernel package
KERNELPKG="linux"
@ -31,8 +31,8 @@ usage() {
# returns: 1 on error
prepare_pacman() {
# Set up the necessary directories for pacman use
[[ ! -d "${DESTDIR}/var/cache/pacman/pkg" ]] && mkdir -m 755 -p "${DESTDIR}/var/cache/pacman/pkg"
[[ ! -d "${DESTDIR}/var/lib/pacman" ]] && mkdir -m 755 -p "${DESTDIR}/var/lib/pacman"
[[ ! -d "${DESTDIR}/var/cache/pacman/pkg" ]] && mkdir -p "${DESTDIR}/var/cache/pacman/pkg"
[[ ! -d "${DESTDIR}/var/lib/pacman" ]] && mkdir -p "${DESTDIR}/var/lib/pacman"
${PACMAN} -Sy
}
@ -66,69 +66,69 @@ install_packages() {
PACKAGES="base linux linux-firmware"
# Add packages which are not in core repository
if [[ "$(lsblk -rnpo FSTYPE | grep ntfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w ntfs-3g)" ]] && PACKAGES="${PACKAGES} ntfs-3g"
if lsblk -rnpo FSTYPE | grep -q ntfs; then
! echo "${PACKAGES}" | grep -qw ntfs-3g && PACKAGES="${PACKAGES} ntfs-3g"
fi
if [[ "$(lsblk -rnpo FSTYPE | grep btrfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w btrfs-progs)" ]] && PACKAGES="${PACKAGES} btrfs-progs"
if lsblk -rnpo FSTYPE | grep -q btrfs; then
! echo "${PACKAGES}" | grep -qw btrfs-progs && PACKAGES="${PACKAGES} btrfs-progs"
fi
if [[ "$(lsblk -rnpo FSTYPE | grep nilfs2)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w nilfs-utils)" ]] && PACKAGES="${PACKAGES} nilfs-utils"
if lsblk -rnpo FSTYPE | grep -q nilfs2; then
! echo "${PACKAGES}" | grep -qw nilfs-utils && PACKAGES="${PACKAGES} nilfs-utils"
fi
if [[ "$(lsblk -rnpo FSTYPE | grep ext)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w e2fsprogs)" ]] && PACKAGES="${PACKAGES} e2fsprogs"
if lsblk -rnpo FSTYPE | grep -q ext; then
! echo "${PACKAGES}" | grep -qw e2fsprogs && PACKAGES="${PACKAGES} e2fsprogs"
fi
if [[ "$(lsblk -rnpo FSTYPE | grep reiserfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w reiserfsprogs)" ]] && PACKAGES="${PACKAGES} reiserfsprogs"
if lsblk -rnpo FSTYPE | grep -q reiserfs; then
! echo "${PACKAGES}" | grep -qw reiserfsprogs && PACKAGES="${PACKAGES} reiserfsprogs"
fi
if [[ "$(lsblk -rnpo FSTYPE | grep xfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w xfsprogs)" ]] && PACKAGES="${PACKAGES} xfsprogs"
if lsblk -rnpo FSTYPE | grep -q xfs; then
! echo "${PACKAGES}" | grep -qw xfsprogs && PACKAGES="${PACKAGES} xfsprogs"
fi
if [[ "$(lsblk -rnpo FSTYPE | grep jfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w jfsutils)" ]] && PACKAGES="${PACKAGES} jfsutils"
if lsblk -rnpo FSTYPE | grep -q jfs; then
! echo "${PACKAGES}" | grep -qw jfsutils && PACKAGES="${PACKAGES} jfsutils"
fi
if [[ "$(lsblk -rnpo FSTYPE | grep f2fs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w f2fs-tools)" ]] && PACKAGES="${PACKAGES} f2fs-tools"
if lsblk -rnpo FSTYPE | grep -q f2fs; then
! echo "${PACKAGES}" | grep -qw f2fs-tools && PACKAGES="${PACKAGES} f2fs-tools"
fi
if [[ "$(lsblk -rnpo FSTYPE | grep vfat)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w dosfstools)" ]] && PACKAGES="${PACKAGES} dosfstools"
if lsblk -rnpo FSTYPE | grep -q vfat; then
! echo "${PACKAGES}" | grep -qw dosfstools && PACKAGES="${PACKAGES} dosfstools"
fi
if [[ -n "$(pgrep dhclient)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w dhclient)" ]] && PACKAGES="${PACKAGES} dhclient"
! echo "${PACKAGES}" | grep -qw dhclient && PACKAGES="${PACKAGES} dhclient"
fi
### HACK:
# always add systemd-sysvcompat components
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ systemd-sysvcompat\ # #g")"
PACKAGES="${PACKAGES//\ systemd-sysvcompat\ / }"
PACKAGES="${PACKAGES} systemd-sysvcompat"
### HACK:
# always add intel-ucode
if [[ "$(uname -m)" == "x86_64" ]]; then
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ intel-ucode\ # #g")"
PACKAGES="${PACKAGES//\ intel-ucode\ / }"
PACKAGES="${PACKAGES} intel-ucode"
fi
# always add amd-ucode
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ amd-ucode\ # #g")"
PACKAGES="${PACKAGES//\ amd-ucode\ / }"
PACKAGES="${PACKAGES} amd-ucode"
### HACK:
# always add netctl with optdepends
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ netctl\ # #g")"
PACKAGES="${PACKAGES//\ netctl\ / }"
PACKAGES="${PACKAGES} netctl"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ dhcpd\ # #g")"
PACKAGES="${PACKAGES//\ dhcpd\ / }"
PACKAGES="${PACKAGES} dhcpcd"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ wpa_supplicant\ # #g")"
PACKAGES="${PACKAGES//\ wpa_supplicant\ / }"
PACKAGES="${PACKAGES} wpa_supplicant"
### HACK:
# always add lvm2, cryptsetup and mdadm
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ lvm2\ # #g")"
PACKAGES="${PACKAGES//\ lvm2\ / }"
PACKAGES="${PACKAGES} lvm2"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ cryptsetup\ # #g")"
PACKAGES="${PACKAGES//\ cryptsetup\ / }"
PACKAGES="${PACKAGES} cryptsetup"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ mdadm\ # #g")"
PACKAGES="${PACKAGES//\ mdadm\ / }"
PACKAGES="${PACKAGES} mdadm"
### HACK: circular depends are possible in base, install filesystem first!
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ filesystem\ # #g")"
PACKAGES="${PACKAGES//\ filesystem\ / }"
PACKAGES="filesystem ${PACKAGES}"
${PACMAN} -S ${PACKAGES}
"${PACMAN}" -S "${PACKAGES}"
}
if [[ -z "${1}" ]]; then
@ -138,29 +138,18 @@ fi
! [[ -d /tmp ]] && mkdir /tmp
# prepare pacman
prepare_pacman
if [[ $? -ne 0 ]]; then
echo "Pacman preparation FAILED!"
return 1
fi
prepare_pacman || (echo "Pacman preparation FAILED!"; return 1)
# mount proc/sysfs first, so mkinitcpio can use auto-detection if it wants
chroot_mount
# install packages
install_packages
if [[ $? -gt 0 ]]; then
echo
echo "Package installation FAILED."
echo
chroot_umount
exit 1
fi
install_packages || (echo "Package installation FAILED."; chroot_umount; exit 1)
# /etc/locale.gen
# enable at least en_US.UTF8 if nothing was changed, else weird things happen on reboot!
! [[ $(grep -q ^[a-z] ${DESTDIR}/etc/locale.gen) ]] && sed -i -e 's:^#en_US.UTF-8:en_US.UTF-8:g' ${DESTDIR}/etc/locale.gen
chroot ${DESTDIR} locale-gen >/dev/null 2>&1
! grep -q "^[a-z]" "${DESTDIR}/etc/locale.gen" && sed -i -e 's:^#en_US.UTF-8:en_US.UTF-8:g' "${DESTDIR}/etc/locale.gen"
chroot "${DESTDIR}" locale-gen >/dev/null 2>&1
# umount chroot
chroot_umount

View file

@ -10,15 +10,15 @@ build ()
echo "Consoles:" >> "${MOTD}"
echo " - Virtual consoles 1-6 are active." >> "${MOTD}"
echo " - To change virtual console use ALT + F(1-6)" >> "${MOTD}"
if grep -q archboot_keymap "${HOOKS[@]}"; then
if echo "${HOOKS[@]}" | grep -q archboot_keymap ; then
echo "Change keymap and console font:" >> "${MOTD}"
echo " - To change to a non-US keymap, type 'km' at the console." >> "${MOTD}"
fi
if grep -q archboot_tz "${HOOKS[@]}"; then
if echo "${HOOKS[@]}" | grep -q archboot_tz; then
echo "Change time and date:" >> "${MOTD}"
echo " - To change your time and date, type 'tz' at the console." >> "${MOTD}"
fi
if grep -q archboot_installer "${HOOKS[@]}"; then
if echo "${HOOKS[@]}" | grep -q archboot_installer; then
echo "Normal Setup:" >> "${MOTD}"
echo " - On first login setup is launched automatically." >> "${MOTD}"
echo " - Please run 'setup' again to install Arch Linux if you left setup." >> "${MOTD}"