Skip to content

Instantly share code, notes, and snippets.

@shabin-slr
Forked from mslinn/installActivator.sh
Created March 14, 2017 13:59
Show Gist options
  • Save shabin-slr/e4cd9336d96dd7f7f01276b321a124f0 to your computer and use it in GitHub Desktop.
Save shabin-slr/e4cd9336d96dd7f7f01276b321a124f0 to your computer and use it in GitHub Desktop.
Installs Lightbend Activator on Ubuntu and Cygwin
#!/bin/bash
# From ScalaCourses.com Introduction to Play Framework with Scala course
# https://www.scalacourses.com/student/showLecture/158
set -eo pipefail
function help {
echo "Download or update Typesafe Activator on Linux and Cygwin"
echo "Usage: $(basename $0) [options]"
echo "Options are:"
echo " -m Download minimal version (wgithout prepackaged dependencies)"
exit -1
}
# This installs Activator into /opt/activator-x.yy. You can change the root of the installation directory by modifying the next line:
DEST=/opt
QUIET="-q"
OS="$(expr substr $(uname -s) 1 6)"
MINMAX=maximum
if [ "$1" == "-m" ]; then
MINMAX=minimal
shift
echo "Fetching minimal version of Activator (without prepackaged dependencies)"
fi
if [ "$1" ]; then help; fi
function GET_VERSION {
# Typical return value: 1.2.10
echo "$(echo "$1" | sed -re 's^.*?/([0-9.]+)/.*?^\1^')"
}
function SETUP {
if [ "$MINMAX" == minimal ]; then
# Typesafe maintains the current version information for Activator at this URL:
DL="$(wget --no-check-certificate -qO - https://activator-prod.herokuapp.com/latest | grep -Po 'https://.*?.zip' | head -n1)"
# Typical value for DL is https://downloads.typesafe.com/typesafe-activator/1.2.10/typesafe-activator-1.2.10.zip
AVER="$(GET_VERSION $DL)"
ADIR=activator-dist-$AVER-minimal
AFILE=activator-$AVER-minimal
else
DL="$(wget --no-check-certificate -qO - https://activator-prod.herokuapp.com/latest | grep -Po 'https://.*?.zip' | head -n2 | tail -n1)"
# Typical value for DL is https://downloads.typesafe.com/typesafe-activator/1.2.10/typesafe-activator-1.2.10-minimal.zip
AVER="$(GET_VERSION $DL)"
ADIR=activator-dist-$AVER
AFILE=activator-$AVER
fi
AZIP="typesafe-$AFILE.zip"
}
# Creates typesafe-activator-1.2.10
function UNZIP {
if [ $OS == CYGWIN ]; then
cd "$HOMEDRIVE$HOMEPATH/Downloads"
elif [ -d ~/Downloads ]; then
cd ~/Downloads
fi
if [ -f "$AZIP" ]; then
echo "$PWD/$AZIP already exists, not downloading it again."
else
wget -O $AZIP https://downloads.typesafe.com/typesafe-activator/$AVER/$AZIP
fi
if [ -d "$ADIR" ]; then
echo "$PWD/$ADIR already exists, not unzipping again."
else
unzip -o $QUIET $AZIP
#rm $AZIP
fi
}
SETUP
DESTPATH="$DEST/activator-$AVER"
if [ -d "$DESTPATH" ]; then
echo "Activator $AVER not unzipped because $DESTPATH already exists"
echo "$DESTPATH already exists, not moved into place"
else
UNZIP
if [ $OS == CYGWIN ]; then
mv "$HOMEDRIVE$HOMEPATH/Downloads/$ADIR" $DESTPATH
else
sudo mv ~/Downloads/$ADIR $DESTPATH
fi
#rm -rf activator-$AVER
fi
mkdir -p ~/.activator
ACFG=~/.activator/activatorconfig.txt
if [ -f "$ACFG" ]; then
if [ -z "$(grep 'Dhttp.nonProxyHost' $ACFG)" ]; then
echo '-Dhttp.nonProxyHost="localhost|127.0.0.1"' >> "$ACFG"
fi
else
echo '-Dhttp.nonProxyHost="localhost|127.0.0.1"' >> "$ACFG"
fi
# If activator is not on the path, create link to /usr/local/bin/activator (and the jar that actually contains Activator) so you can simply type 'activator' to run it
if [ -z "$(which activator)" ]; then
ln "$DESTPATH/activator" /usr/local/bin/activator
ln "$DESTPATH/activator-launch-$AVER.jar" /usr/local/bin/activator-launch-$AVER.jar
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment