Created
June 6, 2015 11:14
-
-
Save haselwarter/f687946e89f970061240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
function usage () { | |
echo "Usage: update-andromeda.sh [option]" | |
echo " Update Andromeda to the latest available version (default)" | |
echo " --dev Update the development version of Andromeda" | |
} | |
if [ "$1" = '--dev' ]; then | |
f=upgrade_dev | |
elif [ "$#" = 0 ]; then | |
f=upgrade_query | |
else | |
usage | |
exit 1 | |
fi | |
opam update | |
PINNED="$(opam pin list | grep andromeda || true)" | |
function upgrade_dev () { | |
if [ "x$PINNED" = "x" ]; then | |
DEV_VERSION="$(opam info andromeda | \ | |
sed -rn \ | |
'/available-versions/s/.*[[:space:]]([^[:space:]]+~dev).*/\1/p')" | |
if ! [ "$DEV_VERSION" ]; then | |
echo 'No development version of Andromeda available.' | |
exit 1 | |
fi | |
echo "Switching to development version $DEV_VERSION" | |
opam pin -y -k version add andromeda "$DEV_VERSION" | |
fi | |
} | |
function upgrade_query () { | |
if [ "$PINNED" ]; then | |
RELEASE_AVAILABLE=$(opam upgrade --dry-run --verbose andromeda | \ | |
sed -nr 's/.*andromeda\.([^[:space:]]+) is not available.*/\1/p') | |
if ! [ "x$RELEASE_AVAILABLE" = "x" ]; then | |
echo "" | |
echo "You are currently following the development version." | |
echo 'Run `update-andromeda.sh --dev'"'"' to skip this question.' | |
echo "Andromeda version $RELEASE_AVAILABLE has been released." | |
echo "Do you want to switch to the available release?" | |
until echo "$ANSWER" | grep -q -x -e 'y' -e 'yes' -e 'n' -e 'no'; do | |
echo -n "[y/n]: " | |
read ANSWER | |
done | |
if echo "$ANSWER" | grep -q -x -e 'y' -e 'yes'; then | |
opam pin remove andromeda | |
fi | |
fi | |
fi | |
} | |
$f | |
opam upgrade andromeda |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment