Add a command line option to specify custom mirror(s)

This commit is contained in:
Timothy Redaelli 2015-06-30 17:02:29 +02:00
parent b461fdecc3
commit bcf8cda4be

View file

@ -13,10 +13,6 @@
# GNU General Public License at <http://www.gnu.org/licenses/> for # GNU General Public License at <http://www.gnu.org/licenses/> for
# more details. # more details.
: ${ARCH_MIRRORS="http://mirror.rackspace.com/archlinux http://dgix.ru/mirrors/archlinux"}
# You don't need to edit anything below this comment
set -e set -e
# Gathering informations about actual environment. # Gathering informations about actual environment.
@ -31,10 +27,12 @@ fi
cpu_type=$(uname -m) cpu_type=$(uname -m)
is_openvz() { [ -d /proc/vz -a ! -d /proc/bc ]; }
download() { download() {
local path="$1" x= local path="$1" x=
shift shift
for x in $ARCH_MIRRORS; do for x in $mirrors; do
_download "$x/$path" && return 0 _download "$x/$path" && return 0
done done
return 1 return 1
@ -65,7 +63,7 @@ chroot_exec() {
configure_chroot() { configure_chroot() {
local m local m
for m in $ARCH_MIRRORS; do for m in $mirrors; do
echo 'Server = '"$m"'/$repo/os/$arch' echo 'Server = '"$m"'/$repo/os/$arch'
done >> "/root.$cpu_type/etc/pacman.d/mirrorlist" done >> "/root.$cpu_type/etc/pacman.d/mirrorlist"
# Install and initialize haveged if needed # Install and initialize haveged if needed
@ -194,6 +192,38 @@ finalize() {
EOF EOF
} }
mirrors=
while getopts ":m:h" opt; do
case $opt in
m)
mirrors="${mirrors:+$mirrors }$OPTARG"
;;
h)
cat <<-EOF
usage: ${0##*/} [options]
Options:
-m mirror Use the provided mirror (you can specify this option more than once).
-h Print this help message
EOF
exit 0
;;
:)
printf "%s: option requires an argument -- '%s'\n" "${0##*/}" "$OPTARG" >&2
exit 1
;;
?)
printf "%s: invalid option -- '%s'\n" "${0##*/}" "$OPTARG" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
: ${mirrors:="http://mirror.rackspace.com/archlinux http://dgix.ru/mirrors/archlinux"}
cd / cd /
download_and_extract_bootstrap download_and_extract_bootstrap
configure_chroot configure_chroot