archboot/usr/bin/archboot-quickinst.sh

187 lines
6.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2021-09-27 10:02:51 +02:00
DESTDIR="${1}"
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
2011-02-04 18:11:11 +01:00
[[ ! -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"
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
2013-07-17 10:09:24 +02:00
if [[ "$(lsblk -rnpo FSTYPE | grep ntfs)" ]]; then
2011-02-04 18:11:11 +01:00
! [[ "$(echo ${PACKAGES} | grep -w ntfs-3g)" ]] && PACKAGES="${PACKAGES} ntfs-3g"
fi
2013-07-17 10:09:24 +02:00
if [[ "$(lsblk -rnpo FSTYPE | grep btrfs)" ]]; then
2012-01-20 18:24:16 +01:00
! [[ "$(echo ${PACKAGES} | grep -w btrfs-progs)" ]] && PACKAGES="${PACKAGES} btrfs-progs"
2010-08-02 21:34:30 +02:00
fi
2013-07-17 10:09:24 +02:00
if [[ "$(lsblk -rnpo FSTYPE | grep nilfs2)" ]]; then
2011-02-04 18:11:11 +01:00
! [[ "$(echo ${PACKAGES} | grep -w nilfs-utils)" ]] && PACKAGES="${PACKAGES} nilfs-utils"
2010-08-02 21:34:30 +02:00
fi
2013-07-17 10:09:24 +02:00
if [[ "$(lsblk -rnpo FSTYPE | grep ext)" ]]; then
2011-02-19 17:27:44 +01:00
! [[ "$(echo ${PACKAGES} | grep -w e2fsprogs)" ]] && PACKAGES="${PACKAGES} e2fsprogs"
fi
2013-07-17 10:09:24 +02:00
if [[ "$(lsblk -rnpo FSTYPE | grep reiserfs)" ]]; then
2011-02-19 17:27:44 +01:00
! [[ "$(echo ${PACKAGES} | grep -w reiserfsprogs)" ]] && PACKAGES="${PACKAGES} reiserfsprogs"
fi
2013-07-17 10:09:24 +02:00
if [[ "$(lsblk -rnpo FSTYPE | grep xfs)" ]]; then
2011-02-19 17:27:44 +01:00
! [[ "$(echo ${PACKAGES} | grep -w xfsprogs)" ]] && PACKAGES="${PACKAGES} xfsprogs"
fi
2013-07-17 10:09:24 +02:00
if [[ "$(lsblk -rnpo FSTYPE | grep jfs)" ]]; then
2011-02-19 17:27:44 +01:00
! [[ "$(echo ${PACKAGES} | grep -w jfsutils)" ]] && PACKAGES="${PACKAGES} jfsutils"
fi
2014-01-14 18:01:01 +01:00
if [[ "$(lsblk -rnpo FSTYPE | grep f2fs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w f2fs-tools)" ]] && PACKAGES="${PACKAGES} f2fs-tools"
fi
2013-07-17 10:09:24 +02:00
if [[ "$(lsblk -rnpo FSTYPE | grep vfat)" ]]; then
2011-02-19 17:27:44 +01:00
! [[ "$(echo ${PACKAGES} | grep -w dosfstools)" ]] && PACKAGES="${PACKAGES} dosfstools"
fi
2012-09-13 12:26:34 +02:00
if [[ -n "$(pgrep dhclient)" ]]; then
2011-02-04 18:11:11 +01:00
! [[ "$(echo ${PACKAGES} | grep -w dhclient)" ]] && PACKAGES="${PACKAGES} dhclient"
fi
### HACK:
# always add systemd-sysvcompat components
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ systemd-sysvcompat\ # #g")"
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
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ intel-ucode\ # #g")"
PACKAGES="${PACKAGES} intel-ucode"
# always add amd-ucode
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ amd-ucode\ # #g")"
PACKAGES="${PACKAGES} amd-ucode"
### HACK:
# always add netctl with optdepends
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ netctl\ # #g")"
PACKAGES="${PACKAGES} netctl"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ dhcpd\ # #g")"
PACKAGES="${PACKAGES} dhcpcd"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ wpa_supplicant\ # #g")"
PACKAGES="${PACKAGES} wpa_supplicant"
### HACK:
# always add lvm2, cryptsetup and mdadm
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ lvm2\ # #g")"
PACKAGES="${PACKAGES} lvm2"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ cryptsetup\ # #g")"
PACKAGES="${PACKAGES} cryptsetup"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ mdadm\ # #g")"
PACKAGES="${PACKAGES} mdadm"
### HACK: circular depends are possible in base, install filesystem first!
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ filesystem\ # #g")"
PACKAGES="filesystem ${PACKAGES}"
2011-02-04 18:08:56 +01:00
${PACMAN} -S ${PACKAGES}
}
2010-01-15 20:36:43 +01:00
2011-02-04 18:11:11 +01:00
if [[ "${PKGARG}" = "" ]]; 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
prepare_pacman
2011-02-04 18:11:11 +01:00
if [[ $? -ne 0 ]]; then
echo "Pacman preparation FAILED!"
return 1
2008-10-20 22:39:25 +02:00
fi
# mount proc/sysfs first, so mkinitcpio can use auto-detection if it wants
chroot_mount
# install packages
2010-02-22 07:40:53 +01:00
install_packages
2011-02-04 18:11:11 +01:00
if [[ $? -gt 0 ]]; then
2009-02-11 21:34:04 +01:00
echo
echo "Package installation FAILED."
echo
chroot_umount
2009-02-11 21:34:04 +01:00
exit 1
2008-10-20 22:39:25 +02:00
fi
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!
! [[ $(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
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: