ae_overwrite=${ND_AE_OVERWRITE:-}
ae_sources=${ND_AE_SOURCES:-}
ae_install=${ND_AE_INSTALL:-}
+ae_update=${ND_AE_UPDATE:-1}
ae_dry_run=${ND_AE_DRY_RUN:-}
ae_defun_only=${ND_AE_DEFUN_ONLY:-} # mode to source this file as a "library"
# - apt priority! (so we could avoid automagic upgrades etc)
# - multiarch setups
-ae_tempdir=$(mktemp -d)
-trap "rm -rf \"$ae_tempdir\"" TERM INT EXIT
+if [ -z "${ND_AE_TEMPDIR:-}" ]; then
+ ae_tempdir=$(mktemp -d)
+ trap "rm -rf \"$ae_tempdir\"" TERM INT EXIT
+else
+ # reuse the same directory/fetched configuration if was specified
+ ae_tempdir="${ND_AE_TEMPDIR:-}"
+fi
+
+nd_config_file_fresh="$ae_tempdir/neurodebian.cfg"
print_verbose()
{
it is deduced from the apt-cache policy output, by taking repository
of Debian or Ubuntu origin with highest priority.
+ --print-releases
+ Return a list of releases present in NeuroDebian repository.
+
-f, --flavor=full|libre
Which flavor of the repository should be enabled:
libre -- Only main component, containing only DFSG-compliant content.
Which mirror to use. Could be a mirror code-name (as specified in
/etc/neurodebian/neurodebian.cfg), or a URL.
+ --print-mirrors
+ Return a list (with abbreviation) of known NeuroDebian mirrors.
+
--overwrite,
If apt file already present, it would not be overriden (by default).
Use this option to overwrite.
get_neurodebian_cfg()
{
+ if [ -s "$nd_config_file_fresh" ]; then
+ print_verbose 3 "Config file $nd_config_file_fresh exists -- not fetching"
+ echo "$nd_config_file_fresh"
+ return 0
+ fi
# First we try to fetch the most recent version from the github
print_verbose 3 "Fetching config file from the github repository"
- cfgfile_temp="$ae_tempdir/neurodebian.cfg"
assure_command_from_package wget wget 1
- wget --no-check-certificate -c -q -O$cfgfile_temp \
+ wget --no-check-certificate -c -q -O$nd_config_file_fresh \
$nd_config_url \
- && { echo $cfgfile_temp; } \
+ && { echo "$nd_config_file_fresh"; } \
|| { [ -e "$nd_config_file" ] \
&& echo "$nd_config_file" \
|| error 10 "Neither could fetch $nd_config_url, nor found $nd_config_file"; }
{
nd_config=`get_neurodebian_cfg`
# $exe_dir/nd_querycfg -F" " --config-file="$nd_config" "mirrors" \
+ n=""
query_cfg_section "$nd_config" "mirrors" \
| while read mirror_name mirror_url; do
# verify that url is just a url
if echo "$mirror_url" | grep -v -e '^[a-z0-9:+]*://[-+_%.a-z0-9/]*$'; then
print_verbose 1 "Mirror $mirror_name has 'illegit' URL: $mirror_url. Skipping"
fi
- echo "$mirror_name $mirror_url"
+ [ -z "$n" ] || echo -ne "${ND_IFS:-\n}"; n+=1
+ echo -n "$mirror_name $mirror_url"
+ done
+}
+
+get_releases()
+{
+ nd_config=`get_neurodebian_cfg`
+ n=""
+ query_cfg_section "$nd_config" "release files" \
+ | while read release_name release_url; do
+ # verify that url is just a url
+ if [ "$release_name" = "data" ]; then
+ # skip data
+ continue
+ fi
+ [ -z "$n" ] || echo -ne "${ND_IFS:-\n}"; n+=1
+ echo -n "$release_name"
done
}
else
# squeeze version doesn't have -D yet to force output of the URL not IP, but for our mirrors ATM it shouldn't matter
netselect_opts="-s 1"
- if dpkg --compare-versions $(get_package_version netselect) ge 0.3.ds1-17; then
+ netselect_version="$(get_package_version netselect)"
+ if dpkg --compare-versions "$netselect_version" ge 0.3.ds1-17; then
netselect_opts+=" -D"
fi
+ if dpkg --compare-versions "$netselect_version" ge 0.3.ds1-15; then
+ netselect_opts+=" -I"
+ fi
best_mirror=$(get_mirrors | awk '{print $2;}' | eval $ae_sudo xargs netselect $netselect_opts | awk '{print $2;}')
print_verbose 2 "Best mirror: $best_mirror"
echo $best_mirror
# Note that we use `"$@"' to let each command-line parameter expand to a
# separate word. The quotes around `$@' are essential!
# We need CLOPTS as the `eval set --' would nuke the return value of getopt.
-CLOPTS=`getopt -o h,r:,m:,f:,c:,q,v,n --long help,version,quiet,verbose,mirror:,release:,flavor:,components:,suffix:,overwrite,sources,no-sources,install,dry-run,print-mirrors,print-best-mirror -n 'nd-aptenable' -- "$@"`
+CLOPTS=`getopt -o h,r:,m:,f:,c:,q,v,n --long help,version,quiet,verbose,mirror:,release:,flavor:,components:,suffix:,overwrite,sources,no-sources,install,dry-run,do-not-update,print-releases,print-mirrors,print-best-mirror -n 'nd-aptenable' -- "$@"`
if [ $? != 0 ] ; then
error 2 "Problem with parsing cmdline. Terminating..."
-m|--mirror) shift; ae_mirror="$1"; shift;;
--print-mirrors) get_mirrors; exit 0;;
--print-best-mirror) netselect_mirror; exit 0;;
+ --print-releases) get_releases; exit 0;;
-n|--dry-run) ae_dry_run=1; shift;;
--suffix) shift; ae_suffix="$1"; shift;;
--overwrite) ae_overwrite="$1"; shift;;
+ --do-not-update) ae_update=""; shift;;
--sources) ae_sources=1; shift;;
--no-sources) ae_sources=0; shift;;
--install) ae_install=1; shift;;
# Finalizing (apt-get update etc)
#
-print_verbose 1 "Updating APT listings, might take a few minutes"
-if [ -z "$ae_dry_run" ]; then
- apt_logfile="$ae_tempdir/apt.log"
- $ae_sudo apt-get update 1>"$apt_logfile" 2>&1 \
- && rm -f "$apt_logfile" \
- || {
- apt_log=$(cat "$apt_logfile")
- echo "$apt_log"
- if echo "$apt_log" | grep -q "Malformed line [0-9]* in source list $ae_output_file"; then
- $ae_sudo mv "${ae_output_file}" "${ae_output_file}.failed-disabled"
- error 6 "Update failed to possible errorneous APT listing file produced by this script. Generated $ae_output_file renamed to ${ae_output_file}.failed-disabled to not interfer"
- fi
- error 5 "Update failed with exit code $? (above output logged into $apt_logfile)."
- }
-else
- eval_dry apt-get update
+if [ ! -z "$ae_update" ]; then
+ print_verbose 1 "Updating APT listings, might take a few minutes"
+ if [ -z "$ae_dry_run" ]; then
+ apt_logfile="$ae_tempdir/apt.log"
+ $ae_sudo apt-get update 1>"$apt_logfile" 2>&1 \
+ && rm -f "$apt_logfile" \
+ || {
+ apt_log=$(cat "$apt_logfile")
+ echo "$apt_log"
+ if echo "$apt_log" | grep -q "Malformed line [0-9]* in source list $ae_output_file"; then
+ $ae_sudo mv "${ae_output_file}" "${ae_output_file}-failed.disabled"
+ error 6 "Update failed to possible errorneous APT listing file produced by this script. Generated $ae_output_file renamed to ${ae_output_file}-failed.disabled to not interfer"
+ fi
+ error 5 "Update failed with exit code $? (above output logged into $apt_logfile)."
+ }
+ else
+ eval_dry apt-get update
+ fi
fi
if [ "$ae_verbose" -ge 2 ]; then