Skip to content

Instantly share code, notes, and snippets.

@chatrjr
Created December 13, 2013 15:48
Show Gist options
  • Select an option

  • Save chatrjr/7946277 to your computer and use it in GitHub Desktop.

Select an option

Save chatrjr/7946277 to your computer and use it in GitHub Desktop.
Probably overcomplicated, but I wanted to try my hand at creating a procedural script.
# !/bin/bash
# A Bash script to download and install Nodejs updates
init() {
echo "Welcome to my simple script to install (from stable source) and update Node.js on Ubuntu distros."
echo "'Cause that's a pain in the ass."
echo "Yeah, yeah. Chris Lea's PPA would be even easier."
echo "This just makes it easy to have a custom install. No muss. No fuss. Let's begin."
helper_separator
setup
echo "Had to get you back home first: "$HOME""
helper_separator
fetch_files
helper_separator
echo "Node install has been fetched and extracted. Next, move into install directory."
cd ~/node-install
compile
clean
}
setup() {
cd ~
}
query_source() {
read -p "What version of Node do you want to fetch? (Ex: 'v0.10.23') | " NODE_VERSION
echo
echo "Brilliant. Just a sec."
helper_separator
}
fetch_files() {
query_source
wget http://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION.tar.gz
tar -xzf node-$NODE_VERSION.tar.gz
mv ~/node-$NODE_VERSION ~/node-install
}
query_custom_dir() {
read -p "Did you want to install Node in a particular directory? (Y/N) | " RESPONSE
case $RESPONSE in
[Yy]* )
echo
read -p "Go ahead and enter a directory then. (Ex. 'usr/local/bin') | " CUSTOM_DIR
echo
./configure --prefix=$CUSTOM_DIR
break ;;
[Nn]* )
echo
echo "In that case, Make will be configured with the default path."
echo
./configure
break ;;
esac
echo "Alright, boss. Make has been configured."
helper_separator
}
compile() {
query_custom_dir
echo "Let's unpack Node and install npm, too."
make
make install
curl http://npmjs.org/install.sh | sudo sh
helper_separator
echo "Source unpacked and installed. Just doing some housecleaning."
helper_separator
}
clean() {
setup
rm -rf node-$NODE_VERSION.tar.gz node-install
helper_separator
echo "Should be all set. Make sure you run 'which node' and 'which npm' to check."
helper_separator
}
helper_separator() {
echo
echo "============================================="
echo
}
init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment