X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=tools%2Fnd-aptenable;h=d2c2c9d8aaa463fedc748655c4b6fd57c6bf5911;hb=397a940b6025de234818eb4d4f67b02438f4efa6;hp=0bf694836dcb72a3d65e4e214948d5afb99b70d0;hpb=155e0b4c8045a03ce3ecfc7d797667018114b323;p=neurodebian.git diff --git a/tools/nd-aptenable b/tools/nd-aptenable index 0bf6948..d2c2c9d 100755 --- a/tools/nd-aptenable +++ b/tools/nd-aptenable @@ -31,6 +31,7 @@ ae_verbose=${ND_AE_VERBOSE:-1} 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" @@ -41,9 +42,16 @@ exe_dir=$(dirname $0) # - 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() { @@ -107,6 +115,9 @@ Options: 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. @@ -125,6 +136,9 @@ Options: 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. @@ -183,13 +197,17 @@ EOT 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"; } @@ -208,13 +226,31 @@ get_mirrors() { 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 } @@ -244,8 +280,13 @@ netselect_mirror() { 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 + if [ -z "$best_mirror" ]; then + print_verbose 1 "Failed to select mirror using netselect. Selecting default one ($nd_mirror_default)" + echo "$nd_mirror_default" + else + print_verbose 2 "Best mirror: $best_mirror" + echo $best_mirror + fi fi } @@ -291,7 +332,7 @@ assure_command_from_package() # if absent -- check availability of the package apt_cache=$(LANG=C apt-cache policy "$pkg" 2>&1) - if [[ "$apt_cache" =~ "Unable to locate package" ]] || [[ "$apt_cache" =~ "Candidate: (none)" ]]; then + if [[ "$apt_cache" =~ Unable\ to\ locate\ package ]] || [[ "$apt_cache" =~ Candidate:\ (none) ]]; then print_verbose 1 "Package $pkg providing command $cmd is N/A. Skipping" return 10; fi @@ -321,7 +362,7 @@ assure_command_from_package() # 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..." @@ -342,9 +383,11 @@ while true ; do -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;; @@ -379,7 +422,7 @@ if [ -z "$ae_release" ]; then fi if [ -z "$ae_flavor" ]; then - ae_flavor=$(echo "$apt_policy" | grep -e ",n=$ae_release," | grep -qe 'c=\(non-free\|restricted\)' && echo "full" || echo "libre") + ae_flavor=$(echo "$apt_policy" | grep -e ",n=$ae_release," | grep -qe 'c=\(non-free\|multiverse\)' && echo "full" || echo "libre") fi # @@ -392,7 +435,7 @@ if is_component_included software || is_component_included data; then if [ -z "$ae_mirror" ]; then # none specified ae_mirror_url=$nd_mirror_origin else - if ! [[ "$ae_mirror" =~ ".*://.*" ]]; then + if ! [[ "$ae_mirror" =~ .*://.* ]]; then case "$ae_mirror" in best) ae_mirror_url=$(netselect_mirror);; default) ae_mirror_url=$nd_mirror_default;; @@ -494,22 +537,26 @@ fi # 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)." - } +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 else - eval_dry apt-get update + print_verbose 1 "apt-get update was not run. Please run to take an effect of changes" fi if [ "$ae_verbose" -ge 2 ]; then