#!/bin/bash mode=$1 target=$2 source=$3 wget="wget -q -t0" arch=$(uname -m) usage() { exec >&2 && echo "usage: $(basename $0) [source]" && echo && echo "This script is for installing Arch Linux after manually partitioning and" && echo "network configuration." && exit 1 } [ "$mode" == "" ] || [ "$target" == "" ] && usage [ "$mode" == "ftp" ] || [ "$mode" == "cd" ] || usage [ "$UID" != "0" ] && echo "run as root, please." >&2 && exit 1 [ $(echo $target | egrep ^/) ] || target=$(pwd)/$target [ -d "$target" ] || mkdir -p $target [ "$source" == "" ] && source=ftp://ftp.archlinux.org/current/os/$arch || arch=$(basename $source) [ -f /etc/arch-release ] && on_arch=true cache=$target/var/cache/pacman/pkg [ $on_arch ] && { mkdir -p $(dirname $cache) ln -s /var/cache/pacman/pkg $cache } || { mkdir -p $cache } [ "$mode" == "ftp" ] && { install() { cd $cache echo " · $1" exec 2>/dev/null # seems to catch not only 2 package=$(ls $1*.tar.gz | tail -1) [ -f "$package" ] && { tar xzf $package -C $target || exit 1 } || { $wget $source/$1*.tar.gz && tar xzf $1*.tar.gz -C $target || exit 1 } } } [ "$mode" == "cd" ] && { install() { exit 1 } } [ $on_arch ] || { echo · downloading and installing bash. for package in glibc ncurses readline bash; do install $package done } echo · downloading and installing pacman. for package in libdownload libarchive acl attr zlib bzip2 pacman; do install $package done echo · installing base. cd $target cp /etc/resolv.conf etc/resolv.conf mkdir sys proc dev 2> /dev/null [ $on_arch ] && { pacman --noconfirm -r $target -Sfy base } || { mount -o bind /dev dev mount -t proc none proc mount -t sysfs none sys chroot $target /bin/bash <