#emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
#ex: set sts=4 ts=4 sw=4 et:
+# Depends: apt, python, wget
+# Recommends: netselect
+
# play safe
set -e
set -u
nd_aptenable_version=0.1
nd_key_id=0x2649A5A9
+nd_config_url=https://raw.githubusercontent.com/neurodebian/neurodebian/master/neurodebian.cfg
nd_config_file=/etc/neurodebian/neurodebian.cfg
nd_mirror_origin=http://neuro.debian.net/debian
nd_mirror_default=$nd_mirror_origin # or may be AWS?
Comma separated list of components to enable among:
software -- primary software repository
data -- data packages
- devel -- "overlay" of development versions (like Debian "experimental").
+ devel -- "overlay" of development versions (like Debians' "experimental").
Not sufficient on its own and available only from the main site
If not specified -- "software,data"
-m, --mirror=NAME|URL
Which mirror to use. Could be a mirror code-name (as specified in
- /etc/neurodebian/neurodebian.cfg), or a URL (TODO).
+ /etc/neurodebian/neurodebian.cfg), or a URL.
--overwrite,
If apt file already present, it would not be overriden (by default).
multiple repositories
--sources, --no-sources
- Either to enable deb-src lines. If not specified -- deduced based on ??? TODO
+ Either to enable deb-src lines. If none specified -- would be enabled if
+ sources for a core package (apt) are available.
-n, --dry-run
Do not perform any changes -- generated configurations and commands will
# 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"
- wget -c -q -O$cfgfile_temp https://raw.githubusercontent.com/neurodebian/neurodebian/master/neurodebian.cfg \
+ wget --no-check-certificate -c -q -O$cfgfile_temp \
+ $nd_config_url \
&& { echo $cfgfile_temp; } \
- || { [ -e "$nd_config_file" ] && return "$nd_config_file"; }
- # if not -- should blow up
+ || { [ -e "$nd_config_file" ] \
+ && echo "$nd_config_file" \
+ || error 10 "Neither could fetch $nd_config_url, nor found $nd_config_file"; }
+}
+
+query_cfg_section()
+{
+ config_file="$1"
+ section="$2"
+ print_verbose 3 "Querying config $config_file section $section"
+ python -c "from ConfigParser import SafeConfigParser as SP; cfg = SP(); cfg.read('$config_file'); print('\n'.join([' '.join(x) for x in cfg.items('$section')]))"
}
get_mirrors()
{
-# echo "TODO: fetch uptodate neurodebian.cfg"
nd_config=`get_neurodebian_cfg`
- $exe_dir/nd_querycfg --config-file="$nd_config" "mirrors" \
- | sed -e 's,=, ,'g \
+# $exe_dir/nd_querycfg -F" " --config-file="$nd_config" "mirrors" \
+ 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 "netselect (apt-get install netselect) needed to select the 'best' mirror was not found"
print_verbose 1 "Selecting the default repository: $nd_mirror_default"
echo $nd_mirror_default
+ else
+ get_mirrors | awk '{print $2;}' | $ae_sudo xargs netselect -D -s 1 | awk '{print $2;}'
fi
- get_mirrors | awk '{print $2;}' | $ae_sudo xargs netselect -D -s 1 | awk '{print $2;}'
}
get_mirror_url() {
-r|--release) shift; ae_release="$1"; shift;;
-f|--flavor) shift; ae_flavor="$1"; shift;;
-c|--components) shift; ae_components="$1"; shift;;
- # TODO
-m|--mirror) shift; ae_mirror="$1"; shift;;
- # TODO
--print-mirrors) get_mirrors; exit 0;;
--print-best-mirror) netselect_mirror; exit 0;;
-n|--dry-run) ae_dry_run=1; shift;;
# Determine which mirror to use
#
-# TODO -- determine mirror URL
-# Not necessary for -devel available only from the main site
+# knowing mirror is not necessary for -devel available only from the main site
if include_component software || include_component data; then
# for now just use default
if [ -z "$ae_mirror" ]; then # none specified
ae_mirror_url=$nd_mirror_origin
else
if ! [[ "$ae_mirror" =~ ".*://.*" ]]; then
- # TODO -- determine from the abbreviation
case "$ae_mirror" in
best) ae_mirror_url=$(netselect_mirror);;
default) ae_mirror_url=$nd_mirror_default;;
*) error 5 "Unknown value of flavor $apt_flavor. Must be full or libre"
esac
-if [ -z "$ae_sources" ] || [ $ae_sources -eq 0 ]; then
+if [ -z "$ae_sources" ]; then
+ apt-cache showsrc apt >&/dev/null && ae_sources=1 || ae_sources=0
+fi
+
+if [ $ae_sources -eq 0 ]; then
sources_comment="#"
else
sources_comment=""
fi
if [ -e "$ae_output_file" ] && [ -z "$ae_overwrite" ]; then
- # error 3
- print_verbose 1 "File $ae_output_file already exists, containing:\n\n`cat \"$ae_output_file\"`\n\nI: Use --overwrite option to regenerate with:\n\n$apt_list"
- if get_apt_policy NeuroDebian >/dev/null; then
- print_verbose 1 "NeuroDebian repositories are already available, thus skipping the rest."
- print_verbose 1 "Rerun with --overwrite if you would like to reconfigure."
+ if diff "$ae_output_file" <(echo "$apt_list") | grep -q .; then
+ # error 3
+ print_verbose 1 "File $ae_output_file already exists, containing:\n`cat \"$ae_output_file\"`\n\nI: New configuration is different:\n$apt_list"
+ if get_apt_policy NeuroDebian >/dev/null; then
+ print_verbose 1 "NeuroDebian repositories are already available, thus skipping the rest."
+ print_verbose 1 "Rerun with --overwrite if you would like to reconfigure."
+ exit 0
+ else
+ print_verbose 1 "NeuroDebian configuration is found but not yet available -- continuing with new configuration."
+ fi
+ else
+ print_verbose 1 "New configuration is identical to existing and NeuroDebian repository is already enabled."
+ print_verbose 1 "Skiping the rest. Rerun with --overwrite if you would like to reconfigure."
exit 0
fi
else
print_verbose 1 "Generating $ae_output_file"
if [ -z "$ae_dry_run" ]; then
- echo "$apt_list" >| "$ae_output_file"
+ echo "$apt_list" | $ae_sudo bash -c "cat - >| '$ae_output_file'"
else
echo "DRY:"
echo "$apt_list"
print_verbose 1 "Updating APT listings, might take a few minutes"
if [ -z "$ae_dry_run" ]; then
- apt_logfile=$(ae_tempdir)/apt.log
+ apt_logfile="$ae_tempdir/apt.log"
$ae_sudo apt-get update 1>"$apt_logfile" 2>&1 \
&& rm -f "$apt_logfile" \
|| {