Skip to content

Instantly share code, notes, and snippets.

@piaoger
Last active November 13, 2016 13:21
Show Gist options
  • Select an option

  • Save piaoger/b6da9366ef28a065f152 to your computer and use it in GitHub Desktop.

Select an option

Save piaoger/b6da9366ef28a065f152 to your computer and use it in GitHub Desktop.
bootstrap.sh
#!/bin/bash
###########################################################
# how to use
# curl -f -L https://gist.githubusercontent.com/piaoger/b6da9366ef28a065f152/raw/c06e66e7b4ff22fbb7295fd8a30899cd7d11936c/bootstrap.sh -O
# sh bootstrap.sh
###########################################################
echo off
OS=$(uname)
export SMCP_WORKSPACE_ROOT=~/w
export SMCP_WORKSPACE_BIN=$SMCP_WORKSPACE_ROOT/bin
mkdir $SMCP_WORKSPACE_ROOT/temp
## -----------------------------------------
## basic tools
## -----------------------------------------
if [ "$OS" = "Linux" ]; then
sudo apt-get update
sudo apt-get install git curl wget
else
fi
## -----------------------------------------
## node.js
## ~/w/bin/nodejs/node-v5.0.0-darwin-x64/bin
## -----------------------------------------
cd $SMCP_WORKSPACE_BIN
mkdir nodejs
cd nodejs
export NODEJS_VERSION=v4.2.2
if [ "$OS" = "Darwin" ]; then
export NODEJS_PKG_NAME=node-$NODEJS_VERSION-darwin-x64.tar.gz
export NODEJS_ROOT_NAME=node-$NODEJS_VERSION-darwin-x64
else
export NODEJS_PKG_NAME=node-$NODEJS_VERSION-linux-x64.tar.gz
export NODEJS_ROOT_NAME=node-$NODEJS_VERSION-linux-x64
fi
wget --no-check-certificate https://nodejs.org/dist/$NODEJS_VERSION/$NODEJS_PKG_NAME
tar -vxf $NODEJS_PKG_NAME
rm $NODEJS_PKG_NAME
export PATH=$SMCP_WORKSPACE_BIN/nodejs/$NODEJS_ROOT_NAME/bin:$PATH:
export NODE_PATH=$NODE_PATH:$SMCP_WORKSPACE_BIN/nodejs/$NODEJS_ROOT_NAME/lib/node_modules
node --version
# npm install gulp -g
# npm install request -g
# npm install aws-sdk -g
## -----------------------------------------
## rust
## -----------------------------------------
# curl -f -L https://static.rust-lang.org/rustup.sh -O
# sudo sh rustup.sh --channel=nightly
rm $SMCP_WORKSPACE_ROOT/temp/crontab.tmp
cat >> $SMCP_WORKSPACE_ROOT/temp/crontab.tmp <<EOF
#!bin/bash
#------------------------------------------------------------------
# AUTO-GENERATED BY PIAOGER GONG. PLEASE DO NOT CHANGE!!!
# You can use an asterisk (*) character to match any value.
# We use 29 for the 30-minute mark and 0 for 12 a.m.
# because the minute, hour and weekday values start at 0.
# Note that the day and month values start at 1 instead of 0.
# http://www.howtogeek.com/101288/how-to-schedule-tasks-on-linux-an-introduction-to-crontab-files/
# http://www.tecmint.com/11-cron-scheduling-task-examples-in-linux/
# minute(0-59) hour(0-23) day(1-31) month(1-12) weekday(0-6) command
#--------------------------------------------------------------------
# sync content at 15 minute every hour
14 * * * * cd ~/w/ && node server.js
EOF
# Crontab with -r parameter will remove complete scheduled jobs without confirmation from crontab.
# Use -i option before deleting user’s crontab.
# crontab -r
crontab -l > $SMCP_WORKSPACE_ROOT/temp/crontab.bak
cat $SMCP_WORKSPACE_ROOT/temp/crontab.tmp | crontab
echo "NEW CRONTAB:"
crontab -l
echo "OLD CRONTAB: Backed up to ~/w/temp/crontab.bak"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment