archboot/usr/bin/archboot-quickinst.sh

181 lines
5.9 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2021-09-27 10:02:51 +02:00
DESTDIR="${1}"
2022-01-21 14:16:33 +01:00
PACMAN="pacman --root ${DESTDIR} --cachedir ${DESTDIR}/var/cache/pacman/pkg --noconfirm"
# name of kernel package
2011-07-30 09:47:11 +02:00
KERNELPKG="linux"
2012-01-13 15:52:11 +01:00
# name of the kernel image
VMLINUZ="vmlinuz-${KERNELPKG}"
2008-10-20 22:39:25 +02:00
usage() {
echo "quickinst <destdir>"
2009-02-11 21:34:04 +01:00
echo
echo "This script is for users who would rather partition/mkfs/mount their target"
echo "media manually than go through the routines in the setup script."
echo
echo "First configure /etc/pacman.conf which repositories to use"
echo "and set a mirror in /etc/pacman.d/mirrorlist"
echo ""
echo "Make sure you have all your filesystems mounted under <destdir>."
2009-02-11 21:34:04 +01:00
echo "Then run this script to install all base packages to <destdir>."
echo
echo "Example:"
echo " quickinst /mnt"
2009-02-11 21:34:04 +01:00
echo ""
exit 0
2008-10-20 22:39:25 +02:00
}
2010-02-22 07:40:53 +01:00
# configures pacman and syncs db on destination system
# params: none
# returns: 1 on error
prepare_pacman() {
# Set up the necessary directories for pacman use
2022-01-21 14:16:33 +01:00
[[ ! -d "${DESTDIR}/var/cache/pacman/pkg" ]] && mkdir -p "${DESTDIR}/var/cache/pacman/pkg"
[[ ! -d "${DESTDIR}/var/lib/pacman" ]] && mkdir -p "${DESTDIR}/var/lib/pacman"
2011-02-04 18:08:56 +01:00
${PACMAN} -Sy
}
# chroot_mount()
# prepares target system as a chroot
#
chroot_mount()
{
[[ -e "${DESTDIR}/sys" ]] || mkdir -m 555 "${DESTDIR}/sys"
[[ -e "${DESTDIR}/proc" ]] || mkdir -m 555 "${DESTDIR}/proc"
2011-02-04 18:11:11 +01:00
[[ -e "${DESTDIR}/dev" ]] || mkdir "${DESTDIR}/dev"
mount -t sysfs sysfs "${DESTDIR}/sys"
mount -t proc proc "${DESTDIR}/proc"
mount -o bind /dev "${DESTDIR}/dev"
chmod 555 "${DESTDIR}/sys"
chmod 555 "${DESTDIR}/proc"
}
# chroot_umount()
# tears down chroot in target system
#
chroot_umount()
{
umount "${DESTDIR}/proc"
umount "${DESTDIR}/sys"
umount "${DESTDIR}/dev"
}
# package_installation
2010-02-22 07:40:53 +01:00
install_packages() {
PACKAGES="base linux linux-firmware"
# Add packages which are not in core repository
2022-01-21 14:16:33 +01:00
if lsblk -rnpo FSTYPE | grep -q btrfs; then
! echo "${PACKAGES}" | grep -qw btrfs-progs && PACKAGES="${PACKAGES} btrfs-progs"
2010-08-02 21:34:30 +02:00
fi
2022-01-21 14:16:33 +01:00
if lsblk -rnpo FSTYPE | grep -q nilfs2; then
! echo "${PACKAGES}" | grep -qw nilfs-utils && PACKAGES="${PACKAGES} nilfs-utils"
2010-08-02 21:34:30 +02:00
fi
2022-01-21 14:16:33 +01:00
if lsblk -rnpo FSTYPE | grep -q ext; then
! echo "${PACKAGES}" | grep -qw e2fsprogs && PACKAGES="${PACKAGES} e2fsprogs"
2011-02-19 17:27:44 +01:00
fi
2022-01-21 14:16:33 +01:00
if lsblk -rnpo FSTYPE | grep -q xfs; then
! echo "${PACKAGES}" | grep -qw xfsprogs && PACKAGES="${PACKAGES} xfsprogs"
2011-02-19 17:27:44 +01:00
fi
2022-01-21 14:16:33 +01:00
if lsblk -rnpo FSTYPE | grep -q jfs; then
! echo "${PACKAGES}" | grep -qw jfsutils && PACKAGES="${PACKAGES} jfsutils"
2011-02-19 17:27:44 +01:00
fi
2022-01-21 14:16:33 +01:00
if lsblk -rnpo FSTYPE | grep -q f2fs; then
! echo "${PACKAGES}" | grep -qw f2fs-tools && PACKAGES="${PACKAGES} f2fs-tools"
fi
2022-01-21 14:16:33 +01:00
if lsblk -rnpo FSTYPE | grep -q vfat; then
! echo "${PACKAGES}" | grep -qw dosfstools && PACKAGES="${PACKAGES} dosfstools"
2011-02-19 17:27:44 +01:00
fi
2012-09-13 12:26:34 +02:00
if [[ -n "$(pgrep dhclient)" ]]; then
2022-01-21 14:16:33 +01:00
! echo "${PACKAGES}" | grep -qw dhclient && PACKAGES="${PACKAGES} dhclient"
fi
lsmod | grep -qw wl; then
2022-03-19 08:16:12 +01:00
! echo "${PACKAGES}" | grep -qw broadcom-wl && PACKAGES="${PACKAGES} broadcom-wl"
fi
### HACK:
# always add systemd-sysvcompat components
2022-01-21 14:16:33 +01:00
PACKAGES="${PACKAGES//\ systemd-sysvcompat\ / }"
2013-02-02 09:13:17 +01:00
PACKAGES="${PACKAGES} systemd-sysvcompat"
2014-11-12 09:36:42 +01:00
### HACK:
# always add intel-ucode
2022-01-18 22:37:15 +01:00
if [[ "$(uname -m)" == "x86_64" ]]; then
2022-01-21 14:16:33 +01:00
PACKAGES="${PACKAGES//\ intel-ucode\ / }"
2022-01-06 19:06:34 +01:00
PACKAGES="${PACKAGES} intel-ucode"
fi
# always add amd-ucode
2022-01-21 14:16:33 +01:00
PACKAGES="${PACKAGES//\ amd-ucode\ / }"
PACKAGES="${PACKAGES} amd-ucode"
### HACK:
# always add netctl with optdepends
2022-01-21 14:16:33 +01:00
PACKAGES="${PACKAGES//\ netctl\ / }"
PACKAGES="${PACKAGES} netctl"
2022-01-21 14:16:33 +01:00
PACKAGES="${PACKAGES//\ dhcpd\ / }"
PACKAGES="${PACKAGES} dhcpcd"
2022-01-21 14:16:33 +01:00
PACKAGES="${PACKAGES//\ wpa_supplicant\ / }"
PACKAGES="${PACKAGES} wpa_supplicant"
### HACK:
# always add lvm2, cryptsetup and mdadm
2022-01-21 14:16:33 +01:00
PACKAGES="${PACKAGES//\ lvm2\ / }"
PACKAGES="${PACKAGES} lvm2"
2022-01-21 14:16:33 +01:00
PACKAGES="${PACKAGES//\ cryptsetup\ / }"
PACKAGES="${PACKAGES} cryptsetup"
2022-01-21 14:16:33 +01:00
PACKAGES="${PACKAGES//\ mdadm\ / }"
PACKAGES="${PACKAGES} mdadm"
### HACK
# always add nano and vi
PACKAGES="${PACKAGES//\ nano\ / }"
PACKAGES="${PACKAGES} nano"
PACKAGES="${PACKAGES//\ vi\ / }"
PACKAGES="${PACKAGES} vi"
### HACK: circular depends are possible in base, install filesystem first!
2022-01-21 14:16:33 +01:00
PACKAGES="${PACKAGES//\ filesystem\ / }"
PACKAGES="filesystem ${PACKAGES}"
2022-01-26 11:40:22 +01:00
#shellcheck disable=SC2086
2022-01-22 21:13:58 +01:00
${PACMAN} -S ${PACKAGES}
}
2010-01-15 20:36:43 +01:00
2021-09-27 10:04:52 +02:00
if [[ -z "${1}" ]]; then
2009-02-11 21:34:04 +01:00
usage
2008-10-20 22:39:25 +02:00
fi
2011-02-04 18:11:11 +01:00
! [[ -d /tmp ]] && mkdir /tmp
2008-10-20 22:39:25 +02:00
# prepare pacman
2022-01-21 14:16:33 +01:00
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
2022-01-21 14:16:33 +01:00
install_packages || (echo "Package installation FAILED."; chroot_umount; exit 1)
2008-10-20 22:39:25 +02:00
2012-08-02 12:00:49 +02:00
# /etc/locale.gen
# enable at least en_US.UTF8 if nothing was changed, else weird things happen on reboot!
2022-01-21 14:16:33 +01:00
! 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
2012-08-02 12:00:49 +02:00
# umount chroot
chroot_umount
2008-12-06 19:12:19 +01:00
2009-02-11 21:34:04 +01:00
echo
2008-10-20 22:39:25 +02:00
echo "Package installation complete."
2009-02-11 21:34:04 +01:00
echo
2008-10-20 22:39:25 +02:00
echo "Please install a bootloader. Edit the appropriate config file for"
2011-02-04 18:08:56 +01:00
echo "your loader. Please use ${VMLINUZ} as kernel image."
echo "Chroot into your system to install it into the boot sector:"
2011-02-04 18:08:56 +01:00
echo " # mount -o bind /dev ${DESTDIR}/dev"
echo " # mount -t proc none ${DESTDIR}/proc"
echo " # mount -t sysfs none ${DESTDIR}/sys"
echo " # chroot ${DESTDIR} /bin/bash"
2009-02-11 21:34:04 +01:00
echo
2008-10-20 22:39:25 +02:00
echo "Next step, initramfs setup:"
2011-02-04 18:08:56 +01:00
echo "Edit your /etc/mkinitcpio.conf and /etc/mkinitcpio.d/${KERNELPKG}-fallback.conf"
2009-02-11 21:34:04 +01:00
echo "to fit your needs. After that run:"
2011-02-04 18:08:56 +01:00
echo "# mkinitcpio -p ${KERNELPKG}"
2009-02-11 21:34:04 +01:00
echo
2013-01-21 16:33:16 +01:00
echo "Then exit your chroot shell, edit ${DESTDIR}/etc/fstab and reboot!"
2009-02-11 21:34:04 +01:00
echo
2008-10-20 22:39:25 +02:00
exit 0
2009-02-11 21:34:04 +01:00
# vim: set ts=4 sw=4 et: