Last active
August 29, 2015 14:05
-
-
Save JoeyEremondi/6e2aed53838cc08b2738 to your computer and use it in GitHub Desktop.
Elm installation script
This file contains hidden or 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 | |
echo "************** Elm Installer version 0.0.1 **************" | |
PLATFORM=`uname -m` | |
BINARY_URL_PREFIX="http://JoeyEremondi.github.io/elm-linux-binaries/$PLATFORM" | |
INSTALL_DIR= ~/.elm-install | |
#Default values for version: latest | |
VERSION="latest" | |
if [ $VERSION == "latest" ] | |
then | |
VERSION=`wget -O - -o /dev/null http://eremondi.com/elm-linux-binaries/latest | cat` | |
fi | |
#Default value for action: install | |
ACTION="install" | |
#By default, try to install to global location | |
GLOBALINSTALL="true" | |
#TODO | |
VERSION_FILE_PATH="" | |
#TODO | |
GLOBAL_BINARY_PATH="/usr/bin" | |
#All the different binaries to install | |
PREFIXES="elm elm-server elm-get elm-doc elm-repl" | |
#Make the install directory if it doesn't exist | |
if [ ! -d "./$INSTALL_DIR" ]; then | |
cd ~ | |
mkdir ./$INSTALL_DIR | |
fi | |
cd "$INSTALL_DIR" | |
#Options: | |
# -v VERSION | |
# the version to install or uninstall, default is "latest" | |
# -i | |
# install the given version | |
# -u | |
# uninstall the given version | |
# -s | |
# set the current version as the default, global version. Incompatible with -l | |
# -l | |
# local installation only, do not attempt to add binaries to /usr/share/bin | |
while getopts "v:iuls" opt; do | |
case $opt in | |
u) | |
echo "Uninstalling..." | |
ACTION="uninstall" | |
;; | |
l) | |
echo "Skipping global installation, installing for one user only" | |
GLOBALINSTALL="false" | |
;; | |
v) | |
echo "Selected version $OPTARG" | |
VERSION="$OPTARG" | |
;; | |
s) | |
echo "Updating default version" | |
ACTION="setversion" | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
#Now we either install or uninstall, depending on argument | |
if [ "$ACTION" == "install" ] ; then | |
#TODO | |
echo "Installing" | |
if [ ! -d "./version-$VERSION" ] | |
then | |
echo "Making directory" "./version-$VERSION" | |
mkdir "./version-$VERSION" | |
fi | |
for PREFIX in $PREFIXES | |
do | |
echo "Adding file" "./version-$VERSION/$PREFIX" | |
wget "$BINARY_URL_PREFIX/$PREFIX" -O "./version-$VERSION/$PREFIX" | |
done | |
elif [ "$ACTION" == "uninstall" ] ; then | |
echo "Uninstalling" | |
rm -rf ./version-$VERSION | |
elif [ "$ACTION" == "setversion" ] ; then | |
#Modify version file | |
echo $VERSION > "$VERSION_FILE_PATH" | |
fi | |
#Then, if the flag is set, put wrapper scripts in /usr/bin | |
if [ "$GLOBALINSTALL" == "true" ] | |
then | |
#If the global elm binaries don't exist, create them | |
#These are just bash scripts which modify the $PATH | |
#then point to the current version | |
for PREFIX in $PREFIXES | |
do | |
echo "Adding file" "$GLOBAL_BINARY_PATH/$PREFIX" | |
wget "$BINARY_URL_PREFIX/$PREFIX.sh" -O "$GLOBAL_BINARY_PATH/$PREFIX" | |
chmod +x "$GLOBAL_BINARY_PATH/$PREFIX" | |
done | |
fi | |
#End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment