|
发表于 2005-10-28 22:33:36
|
显示全部楼层
没试过这样安装,不过你可以试下下面的脚本。在gentoo下通过网络安装archlinux到任意一个分区。
archbootscript /mnt/hda_newsys http://debian.okey.net/archlinux
[PHP]#!/bin/bash
#########################################################################
# archbootstrap #
# #
# archbootstrap is to archlinux what debootstrap is to Debian. #
# #
# #
# archbootstrap is public domain though i wouldn't mind getting credit. #
# #
# by David Leinh鋟ser (archlinux@calavera.de) #
# Tarbuild mode and misc cleanups by butters (jsaretsk@andrew.cmu.edu) #
# (minor tweak by dma174) #
#########################################################################
########################
# Tarbuild Mode Switch #
########################
TARMODE=0
KBUILD=0
WCACHE=0
UBUILD=0
if [ "$1" == "-tb" ]; then
INTERACTIVE=0
TARMODE=1
NUMPARAMS=0
shift
if [ "$1" == "--keep-build" ] ||
[ "$2" == "--keep-build" ] ||
[ "$3" == "--keep-build" ]; then
KBUILD=1
NUMPARAMS=$(( ${NUMPARAMS} + 1 ))
fi
if [ "$1" == "--with-cache" ] ||
[ "$2" == "--with-cache" ] ||
[ "$3" == "--with-cache" ]; then
WCACHE=1
NUMPARAMS=$(( ${NUMPARAMS} + 1 ))
fi
if [ "$1" == "--use-build" ] ||
[ "$2" == "--use-build" ] ||
[ "$3" == "--use-build" ]; then
UBUILD=1
NUMPARAMS=$(( ${NUMPARAMS} + 1 ))
fi
shift ${NUMPARAMS}
fi
####################
# Default Settings #
####################
MYVERSION="0.4" # Version number of this script.
GETCMD="${GETCMD:-wget --passive-ftp -c -q}" # What we use to download files.
PREINSTALL="${PREINSTALL:-glibc iputils}" # Packages to install before using
# pacman to fetch the rest.
IGNORE="${IGNORE:-}" # Packages not to be installed.
TARGET="${1:---help}" # Where to bootstrap to
SERVER="${2:-ftp://ftp.archlinux.org}" # Where to fetch all the files.
INTERACTIVE="${INTERACTIVE:-1}" # Interactive mode or batch mode
REPOS="current" # Which repository to use.
EXTRADIR="os/i686"
PKG_PACMAN="setup/pacman.pkg.tar.gz" # Where to find pacman.
PKGLIST="setup/packages.txt" # Where to find the packages list.
PKG_PREFIX="base" # Install pkgs with this prefix.
####################
# Helper Functions #
####################
PREV_DIR="$(pwd)" # remember current directory so we can chdir back later.
# Print an error message to stderr and quit.
function error() {
echo "Error: $*" >&2
cd "${PREV_DIR}"
exit 1;
}
# Simply exit the script.
function quit() {
cd "${PREV_DIR}"
exit 0;
}
# Wrapper around cd for lazy people like me.
function chngdir() {
cd "$@" || error "chdir failed."
}
#Wrapper around mkdir for lazy people like me.
function makedir() {
mkdir -p "$@" || error "mkdir failed."
}
#Fetch given URLs into current dir.
function fetch() {
while [ -n "${1}" ]; do
if [ -z "${1##file://*}" ]; then
F="${1#file://}"
echo "Copying ${F}."
cp "${1#file://}" . || error "Error copying ${F}."
else
echo "Fetching ${1}."
${GETCMD} "${1}" || error "Error fetching ${1}."
fi
shift
done
}
#Read the package list
PACKAGES=()
function read_pkglist() {
while read -s; do
PACKAGES=("${PACKAGES[@]}" "${REPLY}")
done <"${BOOTSTRAP}/${PKGLIST##*/}"
}
#Return 1 if the first argument does not equal any of the other arguments.
function match() {
PATTERN="${1}"
shift
while [ -n "${1}" ]; do
[ "${PATTERN}" == "${1}" ] && return 0
shift
done
return 1
}
######################
# Sanity checks etc. #
######################
case "${TARGET}" in
--help|-h)
echo "Usage: archbootstrap <dir> [server]"
echo "Usage: archbootstrap -tb [--keep-build] [--use-build] [--with-cache] <dir> [server]"
quit;
;;
--version)
echo "archbootstrap ${MYVERSION}";
quit;
;;
esac
[ "$UID" == "0" ] || error "You need to be root."
echo "archbootstrap $MYVERSION"
# This is an easy way to get an useful absolute path.
chngdir "${TARGET}"
TARGET="$(pwd)"
# Create working directory.
TEMP="${TARGET}/tmp"
makedir -m 1777 -p "${TEMP}"
BOOTSTRAP="${TEMP}/bootstrap"
PKG_CACHE="${TARGET}/var/cache/pacman/pkg"
makedir -m 0755 -p "${BOOTSTRAP}"
makedir -m 0755 -p "${PKG_CACHE}"
if [ -d "${TARGET}/pkg" ]; then
echo "Using existing pkg cache..."
mv -f ${TARGET}/pkg/* "${PKG_CACHE}"
elif [ -n "$(ls ${PKG_CACHE})" ]; then
echo "Using existing pkg cache..."
else
echo "No pkg cache found, fetching all pkg files..."
fi
chngdir "${BOOTSTRAP}"
########################################
# Stuff we need for our staged install #
########################################
function set_stage() {
STAGE="${1}"
}
STAGE="start"
if [ "${TARMODE}" == "1" ] && [ "${UBUILD}" == "1" ]; then
STAGE="cleanup"
fi
##################
# pacman wrapper #
##################
PACMAN=("$(which chroot)" "${TARGET}" "${BOOTSTRAP#${TARGET}}/usr/bin/pacman.static")
function add_pkgs() {
PKGS=()
while [ -n "${1}" ]; do
PKGS=("${PKGS[@]}" "${1#${TARGET}}")
shift
done
"${PACMAN[@]}" -A "${PKGS[@]}" || error "Could not add a package."
}
function sync_pkgs() {
if [ "${INTERACTIVE}" == "1" ]; then
"${PACMAN[@]}" -Syf "${@}" || error "Could not sync a package."
else
echo y | "${PACMAN[@]}" -Syf "${@}" || \
error "Could not sync a package."
fi
}
#############
# Main loop #
#############
PREV_STAGE=""
FURL="${SERVER}/${REPOS}/${EXTRADIR}"
until [ "${PREV_STAGE}" == "${STAGE}" ]; do
PREV_STAGE="${STAGE}"
case "${STAGE}" in
start)
chngdir "${BOOTSTRAP}"
fetch "${FURL}/${PKG_PACMAN}" "${FURL}/${PKGLIST}"
tar xfz ${PKG_PACMAN##*/} || \
error "Could not untar ${BOOTSTRAP}${PKG_PACMAN##*/}."
makedir "${TARGET}/etc"
{ echo "[${REPOS}]";
echo "Server = ${FURL}"; } >"${TARGET}/etc/pacman.conf" || \
error "Could not create ${TARGET}/etc/pacman.conf."
cp -f "/etc/resolv.conf" "${TARGET}/etc/resolv.conf" || \
error "Could not copy /etc/resolv.conf."
set_stage "pre_packages"
;;
pre_packages)
chngdir "${PKG_CACHE}"
[ "${#PACKAGES[@]}" == "0" ] && read_pkglist;
for I in "${PACKAGES[@]}"; do
PKGPREFIX="${I%%/*}"
PKGFILE="${I##*/}"
PKGNAME="${PKGFILE%-*-*.pkg.tar.gz}"
if match "${PKGNAME}" ${PREINSTALL}; then
fetch "${FURL}/${PKGFILE}"
add_pkgs "${PKG_CACHE}/${PKGFILE}"
fi
done
set_stage "packages"
;;
packages)
chngdir "${BOOTSTRAP}"
PKGS=()
[ "${#PACKAGES[@]}" == "0" ] && read_pkglist;
for I in "${PACKAGES[@]}"; do
PKGPREFIX="${I%%/*}"
PKGFILE="${I##*/}"
PKGNAME="${PKGFILE%-*-*.pkg.tar.gz}"
[ "${PKGPREFIX}" == "${PKG_PREFIX}" ] || continue
match "${PKGNAME}" ${IGNORE} ${PREINSTALL} && continue
PKGS=("${PKGS[@]}" "${PKGNAME}")
done
sync_pkgs "${PKGS[@]}"
set_stage "cleanup"
;;
cleanup)
echo "Cleaning up..."
chngdir "${TARGET}"
rm -Rf "${BOOTSTRAP}" || error "Could not remove ${BOOTSTRAP}."
[ "${TARMODE}" == "0" ] && quit
set_stage "tarbuild"
;;
tarbuild)
echo "Building tarball..."
chngdir "${TARGET}"
if [ "${KBUILD}" == "0" ]; then
TAROPTS="--remove-files --exclude ./pkg*"
if [ "${WCACHE}" == "0" ]; then
makedir "${TARGET}/pkg"
mv -f ${PKG_CACHE}/* "${TARGET}/pkg"
fi
elif [ "${WCACHE}" == "0" ]; then
TAROPTS="--exclude ./var/cache/pacman/pkg/* --exclude ./pkg*"
else
TAROPTS="--exclude ./pkg*"
fi
TARFILE="arch-base-`date +%Y%m%d`.tar.bz2"
tar --create --bzip2 --preserve-permissions ${TAROPTS} --file="${TARGET}/${TARFILE}" ./*
if [ "${KBUILD}" == "0" ]; then
for NODE in *; do
[ -f "${NODE}" ] && continue
[ "${NODE}" == "pkg" ] && continue
rm -r "${NODE}"
done
fi
quit
;;
esac
done[/PHP] |
|