Skip to content

Instantly share code, notes, and snippets.

@pdemarti
Created September 27, 2019 02:53
Show Gist options
  • Save pdemarti/645dc753e0f585a9638925c691d22dbb to your computer and use it in GitHub Desktop.
Save pdemarti/645dc753e0f585a9638925c691d22dbb to your computer and use it in GitHub Desktop.
Download the latest (or any specified version) of Anaconda3 installer script.
#!/bin/sh
# PD 2018-05-01
# Get the latest Anaconda installer (or a specified version). If already present, skip downloading.
OPTIND=1
output_dir="."
show_help() {
echo "usage: $0 [-v version] [-d output_dir]"
echo "description:"
echo " Look for the latest Anaconda installer for the current platform (or for a version if specified)."
echo " If the installer is already installed in \$output_dir/, then download is skipped."
echo " A symlink '\$output_dir/installer.sh' is created to point to the installer (the latest, or the specified version)."
}
while getopts "h?v:d:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
v) version=$OPTARG
;;
d) output_dir=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
if [ ! -z $@ ]; then
echo "Ignoring trailing argument(s): $@"
fi
if [ -z "$version" ]; then
echo "no version specified, looking for the latest"
version='[\d.]+'
else
echo "Looking for version $version"
fi
echo "Output directory is $output_dir"
if [ ! -d $output_dir ]; then
echo "mkdir $output_dir"
mkdir -p "$output_dir"
fi
case "$(uname -s)" in
Darwin)
osname="MacOSX"
;;
Linux)
osname="Linux"
;;
CYGWIN*|MINGW32*|MSYS*)
osname='Windows'
;;
*)
echo 'Unrecognized OS:' $(uname -s)
exit 1
;;
esac
anaconda_url=https://repo.continuum.io/archive
anaconda_filename=$(curl -sL $anaconda_url | perl -ne 'BEGIN {$osname="'$osname'"; $version=qr{'$version'}; $arch=qx{uname -m}; chomp $arch; $suffix="${osname}-${arch}"; } die "could not find a suitable version for $version" if eof; next unless /<a href="(Anaconda3-${version}-${suffix}.sh)">/; print "$1\n"; last')
echo "Latest version found is: '$anaconda_filename'"
target="$output_dir/$anaconda_filename"
target_link="$output_dir/anaconda-installer.sh"
if [ -f "$target" ]; then
echo "Already installed"
else
echo "Downloading..."
installer_remote="$anaconda_url/$anaconda_filename"
curl -L $installer_remote > "$target"
fi
chmod a+rx "$target"
ln -sf "$target" "$target_link"
echo "$anaconda_filename downloaded and linked as '$target_link'."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment