Skip to content

Instantly share code, notes, and snippets.

@RandomArray
Last active February 12, 2018 15:56
Show Gist options
  • Save RandomArray/e5ff2f2cd410562c52e7 to your computer and use it in GitHub Desktop.
Save RandomArray/e5ff2f2cd410562c52e7 to your computer and use it in GitHub Desktop.
A BASH script for easy installation of io.js on a Raspberry Pi
#!/bin/bash
# ---------------------------------------------------------------------------------------
# install_iorpi.sh - A BASH shell script for Easy installation of io.js on a Rasberry Pi
# ---------------------------------------------------------------------------------------
PROGNAME=${0##*/}
VERSION="0.1.1"
clean_up() { # Perform pre-exit housekeeping
return
}
error_exit() {
echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
clean_up
exit 1
}
graceful_exit() {
clean_up
exit
}
signal_exit() { # Handle trapped signals
case $1 in
INT)
error_exit "Program interrupted by user" ;;
TERM)
echo -e "\n$PROGNAME: Program terminated" >&2
graceful_exit ;;
*)
error_exit "$PROGNAME: Terminating on unknown signal" ;;
esac
}
usage() {
echo -e "Usage: $PROGNAME [-h|--help]"
}
help_message() {
cat <<- _EOF_
$PROGNAME ver. $VERSION
Easy installation of io.js on a Rasberry Pi
$(usage)
Options:
-h, --help Display this help message and exit.
NOTE: You must be the superuser to run this script.
_EOF_
return
}
# Trap signals
trap "signal_exit TERM" TERM HUP
trap "signal_exit INT" INT
# Check for root UID
if [[ $(id -u) != 0 ]]; then
error_exit "You must be the superuser to run this script."
fi
# Parse command-line
while [[ -n $1 ]]; do
case $1 in
-h | --help)
help_message; graceful_exit ;;
-* | --*)
usage
error_exit "Unknown option $1" ;;
*)
echo "Argument $1 to process..." ;;
esac
shift
done
# Main logic
read -p "$(printf '\n\n**************************************************\n\nEasy Install of io.js on Raspberry Pi.\n\nCAUTION: This script will upgrade your Debian Release from Wheezy to Jessie.\n\n** PROCEED AT YOUR OWN RISK. **\n\nAre you sure you want to continue? \n\n**************************************[yes/no]**** ')" prompt
if ! [[ $prompt =~ [yY](es)* ]]
then
exit 0
else
time1=$(date +"%s")
now=$(date)
printf "Starting at $now\n"
printf "Disabled Wheezy in /etc/apt/source.list. Backup at /etc/apt/source.list.old\n\n"
sudo sed -i.old '/ wheezy /s/^/#/' /etc/apt/sources.list
printf "Enabling Debian 'jessie' Release\n\n"
sudo sed -i '1s;^;deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi\n;' /etc/apt/sources.list
printf "Updating and Upgrading System...\n\n"
sudo apt-get -y update && sudo apt-get -y upgrade && sudo apt-get -y autoremove
printf "Installing NVM - Node Version Manager...\n\n"
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.26.1/install.sh | bash
printf "Installing io.js - JavaScript I/O...\n\n"
nvm install iojs
now=$(date)
time2=$(date +"%s")
totaltime=$(($time2-$time1))
printf "Completed at $now\n"
printf "Total Runtime: $(($totaltime / 60)) minutes, $(($totaltime % 60)) seconds.\n"
fi
graceful_exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment