summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe <joe@joelightning.com>2011-02-24 13:58:31 +0000
committerJoe <joe@joelightning.com>2011-02-24 13:58:31 +0000
commit4c2c1fa3582e88eb2a6c606d56f8f1fede38edf7 (patch)
tree7ba4b8660ca7de910f863d706a98e7561c43bad1
parenta77cfac44a0a70038c6e591dd9eeb1071adcf5b5 (diff)
Made it automatically detect the URL of the mirrorlist by parsing a repo index
page.
-rwxr-xr-xarch2parabola41
1 files changed, 34 insertions, 7 deletions
diff --git a/arch2parabola b/arch2parabola
index e2e9118..1acddd4 100755
--- a/arch2parabola
+++ b/arch2parabola
@@ -2,6 +2,7 @@
# (C) Joshua Ismael Haase Hernández 2010
# Copyright © 2011 Joseph Graham
+
# This script is free software! You can do what you want with it, as long as
# you don't convert it into proprietary software and if you redistribute it
# either vertabim or modified you must do so under the same licence.
@@ -9,14 +10,24 @@
# Set this to the URL of the blacklist.
blacklist_url="http://repo.parabolagnulinux.org/docs/blacklist.txt"
+# Set this to the url of the index page which will be parsed to find out the
+# url of the mirrorlist.
+repo_index_page="http://repo.parabolagnulinux.org/core/os/any/"
+
+# Set this to the package name of Parabola's mirrorlist (excluding the version
+# number).
+parabola_mirrorlist_package_name="pacman-mirrorlist-libre"
+
+# Set this to the package name of Arch's default kernel (excluding the version
+# number).
+arch_default_kernel_package_name="kernel26"
+
# Make a temporary directory.
tempdir=$(mktemp -d)
# This will be the name of the log file.
logname="$(pwd)/arch2parabola$(date +%Y%m%d).log"
-mirror=""
-
# These are the dependencies of the script.
dependancies=(which date pacman wget seq sed wget test)
@@ -75,12 +86,21 @@ function if_cancelled
fi
}
+# This is an SGML parser function. It reads tags in the same way that `read'
+# reads lines. The element is assigned to var `element' and the content is
+# assigned to var `content'.
+function rdom
+{
+ local IFS=\>
+ read -d \< element content
+}
+
section=" ---------- Sanity Check ----------"
declare issues=0
# If the user is not root then error and exit.
-(( EUID )) && { echo "This script should be run as root user" ; exit 1 ; }
+(( EUID )) && { echo "This script should be run as root user." ; exit 1 ; }
# Check if the dependencies are available. This won't be needed if this
# script is packaged.
@@ -94,7 +114,7 @@ do
done
# Check if the system is running a custom kernel.
-if ! pacman -Q kernel26 >/dev/null 2>/dev/null
+if ! pacman -Q ${arch_default_kernel_package_name} >/dev/null 2>/dev/null
then
issues="1"
cat >> ${logname} << EOF
@@ -167,10 +187,17 @@ then
abort
fi
-################################################################################
-########################## The mirror var is not set! ##########################
-################################################################################
+# This piece of code automatically detects the url of the mirrorlist and puts
+# it in the var `mirror'.
+while rdom
+do
+ if [[ ${element%%[[:space:]]*} == "a" ]]
+ then mirror="$(echo ${element##*[[:space:]]} | cut -d\" -f 2 | grep \
+ "${parabola_mirrorlist_package_name}-")"
+ fi
+done <<< "$(curl "${repo_index_page}")"
+# Install the mirrorlist.
if ! pacman -U --noconfirm ${mirror} >> ${logname} 2>> ${logname}
then
cat >> ${logname} << EOF