Skip to content

Instantly share code, notes, and snippets.

@tur-nr
Created April 24, 2014 21:03
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 tur-nr/11269443 to your computer and use it in GitHub Desktop.
Save tur-nr/11269443 to your computer and use it in GitHub Desktop.
Node.js Raspbian Installer
#!/usr/bin/env bash
# Node.js, Raspbian Installer
#
# Author: Chistopher Turner (@tur_nr)
# Site : http://tur-nr.github.io
# var defaults
version="0.10.26" # node.js version
destination="/usr/local/dist/node" # destination location
path="/usr/local/bin" # install path
url="http://nodejs.org/dist/v*/" # download Url
file="node-v*-linux-arm-pi.tar.gz" # package file name
# output details
function detail {
printf "%-15s: %s\n" $1 $2
}
# fail and exit
function fail {
tput setf 4;
tput bold;
echo -n "ERROR: "
tput sgr0;
echo $1
exit
}
# options
while getopts d:v:p opt; do
case $opt in
d) destination=$OPTARG;; # set destination
v) version=$OPTARG;; # set version
esac
done
# shift options out of arguments
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
# installation path
if [ $1 ]; then
path=$1
fi
# installation vars
file=${file/\*/$version}
url=${url/\*/$version}$file
# start
echo "Node.js"
echo "Raspbian Installer"
echo
# installation details
detail "Version" $version
detail "Package" $file
detail "Destination" $destination
detail "Path" $path
echo
# confirm
read -p "Are you sure you wish to continue? [Y/n]: " confirm
# check confirmation
if [[ -n $confirm && $confirm != "y" ]]; then
exit
fi
# download package
# exists
if ! curl -Isfo /dev/null $url; then
fail "Version ($version) does not exist."
fi
echo
tput setf 6; echo $url; tput sgr0;
if ! curl -#fo /tmp/$file $url || [ ! -f /tmp/$file ]; then
fail "Download failed!"
fi
# extract
echo "Extracting package..."
mkdir -p $destination
tar zxf /tmp/$file --strip-components=1 -C $destination
# install
echo "Installing..."
mkdir -p $path
ln -s $destination/bin/node $path/node
ln -s $destination/bin/npm $path/npm
# clean up
rm /tmp/$file
# complete script
tput setf 2; tput bold; echo "Installation complete."; tput sgr0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment