Skip to content

Instantly share code, notes, and snippets.

@0racle
Last active April 11, 2017 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0racle/3d157c4ff7777cbeb2cce74dcdcee130 to your computer and use it in GitHub Desktop.
Save 0racle/3d157c4ff7777cbeb2cce74dcdcee130 to your computer and use it in GitHub Desktop.
Perl 6 Install Script
#!/usr/bin/env sh
set -e
INSTALL_DIR=$HOME/rakudo
LATEST_TAR="rakudo-star-latest.tar.gz"
URL="http://rakudo.org/downloads/star"
echo "\033[1;33m
This script will install Rakudo Star
A useful, usable Perl 6 production distribution
MINIMAL REQUIREMENTS FOR INSTALLATION
* 2GB RAM or 1GB RAM + 1024MB swap
* Build tools (ie. gcc, make)
* Perl v5.10.1 or greater
\033[0m"
Oops() {
echo -n "\033[1;31mOOPS: \033[0m"
echo >&2 $1
exit 1;
}
Note() {
echo "\033[0;33m"
echo $1
echo "\033[0m"
}
perl -e 'use v5.10.1' || {
Oops "Please install perl v5.10.1 or greater and try again."
}
command -v make 2>&1 >/dev/null || {
Oops "The 'make' command is required. Please install it and try again."
}
for BIN in 'curl' 'wget'; do
echo -n "Checking for $BIN... "
command -v $BIN 2>&1 >/dev/null && {
echo "$BIN installed"
DOWNLOAD_CMD=$BIN
break
}
echo "$BIN not installed"
done
if [ "$DOWNLOAD_CMD" = "curl" ]; then
DOWNLOAD_CMD="curl -L -O $URL/$LATEST_TAR -o $LATEST_TAR"
elif [ "$DOWNLOAD_CMD" = "wget" ]; then
DOWNLOAD_CMD="wget $URL/$LATEST_TAR -O $LATEST_TAR"
else
Oops "Either 'curl' or 'wget' is required. Please install one and try again."
fi
Note "# Downloading latest Rakudo release"
$DOWNLOAD_CMD || {
Oops "Download failed. Please check your internet connection and try again."
}
tar -xzf $LATEST_TAR || {
Oops "Could not extract achive. It may have been corrupted. Please try again."
}
test -d $INSTALL_DIR || mkdir $INSTALL_DIR
RELEASE=$(tar -tf $LATEST_TAR | head -n 1 | awk -F/ '{print $1}')
Note "# Installing release: $RELEASE"
cd $RELEASE
perl Configure.pl --gen-moar --backends=moar --prefix=$INSTALL_DIR
make
make install
cd ..
echo "export PATH=$INSTALL_DIR/bin:$INSTALL_DIR/share/perl6/site/bin:$PATH" > ~/rakudo/setpath.sh
grep -q rakudo/setpath.sh ~/.profile || echo ". ~/rakudo/setpath.sh" >> ~/.profile
Note "# Removing installation files"
test -d $RELEASE && rm -r $RELEASE
test -e $LATEST_TAR && rm $LATEST_TAR
echo "\033[1;33m
INSTALLATION COMPLETE!
\033[0m"
@MasterDuke17
Copy link

Shouldn't the perl -e 'use v5.10.1' line also have an '|| { Oops ... }'?

@0racle
Copy link
Author

0racle commented Sep 16, 2016

Hmm yeah... My logic was... set -e forces a shell script to exit if you don't handle exit codes. Hence, running this script on a system with perl v5.8.8 will exit the script with the last output being perl's error message Perl v5.10.1 required--this is only v5.8.8 but I'm assuming a linux world where almost everyone has perl. I forgot to account for users who might have no perl. I will amend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment