archboot/usr/share/archboot/installer/quickinst

240 lines
7.7 KiB
Text
Raw Normal View History

2011-02-04 18:11:11 +01:00
#! /bin/bash
2011-02-04 18:08:56 +01:00
MODE=${1}
DESTDIR=${2}
PKGARG=${3}
PACMAN="pacman --root ${DESTDIR} --config /tmp/pacman.conf --noconfirm --noprogressbar"
# name of the kernel image
2011-07-30 09:47:11 +02:00
VMLINUZ="vmlinuz-linux"
2011-02-04 18:11:11 +01:00
[[ "$(cat /proc/cmdline | grep -w BOOT_IMAGE=.*lts)" ]] && VMLINUZ="vmlinuz26-lts"
# name of kernel package
2011-07-30 09:47:11 +02:00
KERNELPKG="linux"
2011-02-04 18:11:11 +01:00
[[ "$(cat /proc/cmdline | grep -w BOOT_IMAGE=.*lts)" ]] && KERNELPKG="kernel26-lts"
2008-10-20 22:39:25 +02:00
usage() {
2009-02-11 21:34:04 +01:00
echo "quickinst <install_mode> <destdir> <package_directory|server_url>"
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 make sure you have all your filesystems mounted under <destdir>."
echo "e.g. mount -t iso9660 /dev/cdrom /src "
2009-02-11 21:34:04 +01:00
echo "Then run this script to install all base packages to <destdir>."
echo
2011-02-04 18:11:11 +01:00
if [[ -e /usr/bin/wget ]]; then
echo "<install_mode> must be either 'net' or 'media'"
2009-02-11 21:34:04 +01:00
else
echo "<install_mode> must be 'media'"
fi
echo
echo "Examples:"
2011-02-04 18:11:11 +01:00
if [[ -e /usr/bin/wget ]]; then
if [[ "$(uname -m)" = "x86_64" ]]; then
echo " quickinst net /mnt ftp://ftp.archlinux.org/core/os/x86_64"
echo " quickinst net /mnt http://ftp.archlinux.org/core/os/x86_64"
2009-02-11 21:34:04 +01:00
else
echo " quickinst net /mnt ftp://ftp.archlinux.org/core/os/i686"
echo " quickinst net /mnt http://ftp.archlinux.org/core/os/i686"
2009-02-11 21:34:04 +01:00
fi
fi
2008-10-20 22:39:25 +02:00
2009-02-11 21:34:04 +01:00
echo " quickinst media /mnt /src/core-$(uname -m)/pkg"
echo ""
exit 0
2008-10-20 22:39:25 +02:00
}
# pacman_conf()
# creates temporary pacman.conf file
pacman_conf() {
2011-02-04 18:11:11 +01:00
if [[ "${MODE}" = "media" ]]; then
2010-02-10 17:41:24 +01:00
serverurl="file://${PKGARG}"
2011-02-04 18:11:11 +01:00
elif [[ "${MODE}" = "net" ]]; then
2010-02-10 17:41:24 +01:00
serverurl="${PKGARG}"
fi
# Setup a pacman.conf in /tmp
cat << EOF > /tmp/pacman.conf
[options]
Architecture = auto
CacheDir = ${DESTDIR}/var/cache/pacman/pkg
CacheDir = /src/core-$(uname -m)/pkg
CacheDir = /src/core-any/pkg
2008-10-20 22:39:25 +02:00
[core]
Server = ${serverurl}
EOF
}
2008-12-17 12:32:58 +01:00
# pacman_conf_extra()
# adds extra repository for net installation mode
pacman_conf_extra() {
2010-02-10 17:41:24 +01:00
serverurl="${PKGARG}"
# Setup a pacman.conf in /tmp
echo "[extra]" >> /tmp/pacman.conf
echo "Server = ${serverurl}" >> /tmp/pacman.conf
}
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()
{
2011-02-04 18:11:11 +01:00
[[ -e "${DESTDIR}/sys" ]] || mkdir "${DESTDIR}/sys"
[[ -e "${DESTDIR}/proc" ]] || mkdir "${DESTDIR}/proc"
[[ -e "${DESTDIR}/dev" ]] || mkdir "${DESTDIR}/dev"
mount -t sysfs sysfs "${DESTDIR}/sys"
mount -t proc proc "${DESTDIR}/proc"
mount -o bind /dev "${DESTDIR}/dev"
}
# chroot_umount()
# tears down chroot in target system
#
chroot_umount()
{
2011-02-04 18:08:56 +01:00
umount ${DESTDIR}/proc
umount ${DESTDIR}/sys
umount ${DESTDIR}/dev
}
# package_installation
2010-02-22 07:40:53 +01:00
install_packages() {
2011-02-04 18:11:11 +01:00
if [[ "${MODE}" = "media" ]]; then
PKGFILE=/tmp/.pkglist
2011-02-04 18:08:56 +01:00
cp ${PKGARG}/packages.txt ${PKGFILE}
2011-02-04 18:11:11 +01:00
if [[ ! -f ${PKGFILE} ]]; then
2011-02-04 18:08:56 +01:00
echo "error: Could not find package list: ${PKGFILE}"
exit 1
fi
PACKAGES=
# fix pacman list!
2011-02-04 18:08:56 +01:00
sed -i -e 's/-i686//g' -e 's/-x86_64//g' -e 's/-any//g' -e 's/"//g' ${PKGFILE}
for pkg in $(cat ${PKGFILE} | grep 'base/' | cut -d/ -f2); do
pkgname=${pkg%-*-*}
2011-02-04 18:08:56 +01:00
PACKAGES="${PACKAGES} ${pkgname}"
done
else
2011-02-19 17:25:31 +01:00
PACKAGES="$(pacman -Sg base | awk '{print $2}')"
fi
# Add packages which are not in core repository
2011-02-04 18:11:11 +01:00
if [[ "$(grep -w uvesafb /proc/cmdline)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w v86d)" ]] && PACKAGES="${PACKAGES} v86d"
fi
2011-02-04 18:11:11 +01:00
if [[ "$(blkid -c /dev/null -o value -s TYPE | grep ntfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w ntfs-3g)" ]] && PACKAGES="${PACKAGES} ntfs-3g"
fi
2011-02-19 17:27:44 +01:00
if [[ "$(blkid -c /dev/null -o value -s TYPE | grep ntfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w ntfs-3g)" ]] && PACKAGES="${PACKAGES} ntfs-3g"
fi
2011-02-04 18:11:11 +01:00
if [[ "$(blkid -c /dev/null -o value -s TYPE | grep btrfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w btrfs-progs-unstable)" ]] && PACKAGES="${PACKAGES} btrfs-progs-unstable"
2010-08-02 21:34:30 +02:00
fi
2011-02-04 18:11:11 +01:00
if [[ "$(blkid -c /dev/null -o value -s TYPE | grep nilfs2)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w nilfs-utils)" ]] && PACKAGES="${PACKAGES} nilfs-utils"
2010-08-02 21:34:30 +02:00
fi
2011-02-19 17:27:44 +01:00
if [[ "$(blkid -c /dev/null -o value -s TYPE | grep ext)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w e2fsprogs)" ]] && PACKAGES="${PACKAGES} e2fsprogs"
fi
if [[ "$(blkid -c /dev/null -o value -s TYPE | grep reiserfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w reiserfsprogs)" ]] && PACKAGES="${PACKAGES} reiserfsprogs"
fi
if [[ "$(blkid -c /dev/null -o value -s TYPE | grep xfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w xfsprogs)" ]] && PACKAGES="${PACKAGES} xfsprogs"
fi
if [[ "$(blkid -c /dev/null -o value -s TYPE | grep jfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w jfsutils)" ]] && PACKAGES="${PACKAGES} jfsutils"
fi
if [[ "$(blkid -c /dev/null -o value -s TYPE | grep vfat)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w dosfstools)" ]] && PACKAGES="${PACKAGES} dosfstools"
fi
2011-02-04 18:11:11 +01:00
if [[ -e /var/state/dhcp/dhclient.leases ]]; then
! [[ "$(echo ${PACKAGES} | grep -w dhclient)" ]] && PACKAGES="${PACKAGES} dhclient"
fi
2010-08-02 21:34:30 +02:00
# Only install the booted kernel image!
2011-07-30 09:47:11 +02:00
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ linux\ # #g" -e "s#\ kernel26-lts\ # #g")"
2011-02-04 18:08:56 +01:00
PACKAGES="${KERNELPKG} ${PACKAGES}"
${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
pacman_conf
2011-02-04 18:11:11 +01:00
if [[ "${INSTMODE}" = "net" ]]; then
pacman_conf_extra
2008-10-20 22:39:25 +02:00
fi
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
# 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 "For GRUB:"
echo " # install-grub /dev/sda /dev/sdaX (replace with your boot partition)"
echo " (or install manually by invoking the GRUB shell)"
2009-02-11 21:34:04 +01:00
echo "HINT XFS FILESYSTEM:"
2008-10-20 22:39:25 +02:00
echo "If you have created xfs filesystems, freeze them before and unfreeze them after"
echo "installing grub (outside the chroot):"
echo "- freeze:"
2011-02-04 18:08:56 +01:00
echo " # xfs_freeze -f ${DESTDIR}/boot"
echo " # xfs_freeze -f ${DESTDIR}/"
2008-10-20 22:39:25 +02:00
echo "- unfreeze:"
2011-02-04 18:08:56 +01:00
echo " # xfs_freeze -u ${DESTDIR}/boot"
echo " # xfs_freeze -u ${DESTDIR}/"
2009-02-11 21:34:04 +01:00
echo
2008-10-20 22:39:25 +02:00
echo "For LILO:"
echo " # lilo"
echo
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
2011-02-04 18:08:56 +01:00
echo "Then exit your chroot shell, edit ${DESTDIR}/etc/fstab and"
echo "${DESTDIR}/etc/rc.conf, 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: