From 0a8818f2926cce4c53400d8813d860788217e7cc Mon Sep 17 00:00:00 2001 From: Craig Silverstein Date: Wed, 1 May 2013 12:08:44 -0700 Subject: [PATCH] Revamp khan-dotfiles to do a full install. There's now an OS-specific setup step -- mac-setup.sh, linux-setup.sh -- and a non-OS setup step, setup.sh. Lots of stuff that used to be in mac-install has moved to the common setup.sh, and I added everything I could from the forge page: https://sites.google.com/a/khanacademy.org/forge/for-khan-employees/-new-employees-onboard-doc/developer-setup I also did the best I could to make setup.sh and linux-setup.sh idempotent: you can safely run them multiple times. I'm not sure about mac-setup.sh yet; I'll need to test it on a mac. I separated out the 'big 3' dotfiles -- .bashrc, .gitconfig, .hgrc -- into two parts, one owned by this repo (which we symlink to), and one that is local. I can do this because each of these files supports an 'include' functionality. By default, we put local stuff such as your email address in the 'local' version of .gitconfig/etc. Test plan: Ran sh -x ./setup.sh /tmp/setup and saw it ran successfully. Ran it again and saw it was basically a noop. Examined /tmp/setup/.bashrc and other dotfiles, and they looked reasonable to me. Also ran sh -x ./linux-setup.sh and saw it ran successfully. Ran it again and saw it was basically a noop. I haven't tested mac-setup.sh but will once I get this repo onto a mac. I also haven't tried actually *using* the .bashrc/etc that are installed. Will also do this on the mac machine, which is 'clean' right now and thus a good test case. --- .bashrc | 13 -- .bashrc.khan | 23 +++ .gitconfig => .gitconfig.khan | 2 +- .hgrc => .hgrc.khan | 7 +- Makefile | 13 +- README.markdown | 43 +++-- bashrc.default | 7 + gitconfig.default | 8 + hgrc.default | 6 + linux-setup.sh | 83 +++++++++ mac-setup.sh | 320 ++++++++++++++-------------------- setup.sh | 234 +++++++++++++++++++++++++ 12 files changed, 535 insertions(+), 224 deletions(-) delete mode 100644 .bashrc create mode 100644 .bashrc.khan rename .gitconfig => .gitconfig.khan (97%) rename .hgrc => .hgrc.khan (87%) create mode 100644 bashrc.default create mode 100644 gitconfig.default create mode 100644 hgrc.default create mode 100755 linux-setup.sh create mode 100755 setup.sh diff --git a/.bashrc b/.bashrc deleted file mode 100644 index f757e21..0000000 --- a/.bashrc +++ /dev/null @@ -1,13 +0,0 @@ - -################################################################################ -# Khan Academy specific - -# Add Phabricator bins to PATH -export PATH="$HOME/khan/devtools/arcanist/khan-bin:$HOME/khan/rbtools/bin:$PATH" - -# Activate Python2.7 virtualenv -source ~/.virtualenv/khan27/bin/activate - -# Enable autocompletion for git and hg -source ~/khan-dotfiles/git-completion.bash -source ~/khan-dotfiles/hg-completion.bash diff --git a/.bashrc.khan b/.bashrc.khan new file mode 100644 index 0000000..0f1adbc --- /dev/null +++ b/.bashrc.khan @@ -0,0 +1,23 @@ +################################################################################ +# Khan Academy specific bashrc + +# Add Phabricator bins to PATH +export PATH="$HOME/khan/devtools/arcanist/khan-bin:$PATH" + +# Activate Python2.7 virtualenv +source ~/.virtualenv/khan27/bin/activate + +# Figure out what directory we're *really* in (following symlinks). +# We need this because *-completion.bash are siblings to this script. +# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # follow symlinks + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # resolve relative symlink +done +DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +# Enable autocompletion for git and hg +source "$DIR/git-completion.bash" +source "$DIR/hg-completion.bash" diff --git a/.gitconfig b/.gitconfig.khan similarity index 97% rename from .gitconfig rename to .gitconfig.khan index b6cb239..b77def5 100644 --- a/.gitconfig +++ b/.gitconfig.khan @@ -49,4 +49,4 @@ renames = copies [init] - templatedir = ~/.git_template + templatedir = ~/.git_template diff --git a/.hgrc b/.hgrc.khan similarity index 87% rename from .hgrc rename to .hgrc.khan index c83f365..beb0eb3 100644 --- a/.hgrc +++ b/.hgrc.khan @@ -6,9 +6,6 @@ pager = LESS='FSRX' less attend = annotate, cat, diff, export, glog, log, qdiff, slog, dlog, gslog, sglog, df, nlog, outgoing, lg, lga [ui] -# TODO -username = FIRST LAST -# TODO: Clone this from https://github.com/Khan/khan-linter # Make sure $EDITOR (or $VISUAL) points to your favorite text editor or this # will make 'hg commit' fail with a cryptic error. editor = ~/khan/devtools/khan-linter/hgeditor.sh "${VISUAL-$EDITOR}" @@ -17,8 +14,8 @@ editor = ~/khan/devtools/khan-linter/hgeditor.sh "${VISUAL-$EDITOR}" ignore = ~/.hgignore_global [web] -# TODO: See http://kiln.stackexchange.com/questions/2816/mercurial-certificate-warning-certificate-not-verified-web-cacerts -cacerts = ~/hg-dummy-cert.pem +# See http://kiln.stackexchange.com/questions/2816/mercurial-certificate-warning-certificate-not-verified-web-cacerts +cacerts = ~/khan/devtools/hg-dummy-cert.pem [extensions] hgext.extdiff = diff --git a/Makefile b/Makefile index c371609..c12d910 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,8 @@ -SHELL := /bin/bash +install: os-install common-install ; -all: link +os-install: + if [ `uname -s` = Linux ]; then ./linux-setup.sh; fi + if [ `uname -s` = Darwin ]; then ./mac-setup.sh; fi -link: - ./symlink.sh - -# TODO(david): Automate other dev setup operations (install autojump, ack, -# pip install -r requirements.txt, etc.) +common-install: + ./setup.sh diff --git a/README.markdown b/README.markdown index 5689e5c..8f3bbe3 100644 --- a/README.markdown +++ b/README.markdown @@ -1,9 +1,9 @@ -Dotfiles for Khan Academy website developers. Originally extracted from [David's dotfiles](http://github.com/divad12/dotfiles), with commits and lines here and there stolen from [Jamie](http://github.com/phleet/dotfiles), [Desmond](https://github.com/dmnd), and others. - -A lot of what's here is Khan Academy-specific: +Configuration files, and setup scripts, for Khan Academy website +developers. A lot of what's here is Khan Academy-specific: - Vim filetype plugins conforming to Khan Academy's style guide -- tell ack to skip crap that the deploy script litters (eg. combined/compressed CSS/JS files) +- tell ack to skip crap that the deploy script litters + (eg. combined/compressed CSS/JS files) - Kiln authentication stuff - a [pre-commit linter](https://github.com/Khan/khan-linter) @@ -11,27 +11,46 @@ and the rest of it just contains generally useful things, such as - handy `git` aliases such as `git graph` - having `hg` pipe commands with large output to `less` -- useful Mercurial aliases and extensions such as `shelve` (similar to `git stash`) and `record` (similar to `git add -p && git commit`) +- useful Mercurial aliases and extensions such as `shelve` (similar to + `git stash`) and `record` (similar to `git add -p && git commit`) This is meant to complement [the dev setup on the Khan Academy Forge](https://sites.google.com/a/khanacademy.org/forge/for-khan-employees/-new-employees-onboard-doc/developer-setup). +The setup scripts here assume you have done the initial setup on that +Forge page (installing npm, etc) before running commands here. Setup ----- -Clone this repo into your home directory and then run `make` in the cloned directory. +Clone this repo somewhere (I recommend into a `~/khan/devtools` +directory, but it doesn't really matter), and then run `make` in +the cloned directory: - cd ~ + mkdir -p ~/khan/devtools + cd ~/khan/devtools git clone git://github.com/Khan/khan-dotfiles.git cd khan-dotfiles make -This will symlink all the dotfiles in the `khan-dotfiles` directory to your home directory. It will not overwrite any of your existing dotfiles but will emit a warning if it failed to symlink a file. +This will symlink all the dotfiles in the `khan-dotfiles` directory to +your home directory. It will not overwrite any of your existing +dotfiles but will emit a warning if it failed to symlink a file. + +It will also install a lot of Python, Node.js, and other configuration files. -To benefit from the `.ackrc` here, install `ack`, which is basically a faster, more configurable `grep -r` that ignores directories like `.git` and displays the results nicely. +This script is idempotent, so it should be safe to run it multiple times. -Also, install [autojump](https://github.com/joelthelion/autojump) if you're a frequent user of the terminal to navigate the filesystem. +To benefit from the `.ackrc` here, install `ack`, which is basically a +faster, more configurable `grep -r` that ignores directories like +`.git` and displays the results nicely. -TODO(david): Automate all this in the Makefile. +Also, install [autojump](https://github.com/joelthelion/autojump) if +you're a frequent user of the terminal to navigate the filesystem. Hello ----- -It's 3 am and I need to sleep so I can wake up and help our four interns starting later this morning to get set up, so there's a lot of stuff missing. Pull requests are welcome! +Originally extracted from [David's +dotfiles](http://github.com/divad12/dotfiles), with commits and lines +here and there stolen from [Jamie](http://github.com/phleet/dotfiles), +[Desmond](https://github.com/dmnd), and others. Non-dotfile config +files, and the setup script, written by Craig Silverstein. + +Pull requests are welcome! diff --git a/bashrc.default b/bashrc.default new file mode 100644 index 0000000..39724aa --- /dev/null +++ b/bashrc.default @@ -0,0 +1,7 @@ +################################################################################ +# Local bashrc. +# Feel free to add whatever you like after the 'bashrc.khan' line. + +if [ -s ~/.bashrc.khan ]; then + source ~/.bashrc.khan +fi diff --git a/gitconfig.default b/gitconfig.default new file mode 100644 index 0000000..ad803b9 --- /dev/null +++ b/gitconfig.default @@ -0,0 +1,8 @@ +# Feel free to include whatever personal configs you'd like after the [include] + +[include] + path = .gitconfig.khan + +[user] + name = %NAME_FIRST_LAST% + email = %EMAIL%@khanacademy.org diff --git a/hgrc.default b/hgrc.default new file mode 100644 index 0000000..4d80149 --- /dev/null +++ b/hgrc.default @@ -0,0 +1,6 @@ +# Feel free to include whatever personal configs you'd like after the %include! + +%include .hgrc.khan + +[ui] +username = %NAME_FIRST_LAST% <%EMAIL%@khanacademy.org> diff --git a/linux-setup.sh b/linux-setup.sh new file mode 100755 index 0000000..ec3478c --- /dev/null +++ b/linux-setup.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +# This installs binaries that you need to develop at Khan Academy. +# The OS-independent setup.sh assumes all this stuff has been +# installed. + +# Bail on any errors +set -e + + +install_packages() { + updated_apt_repo="" + + # native hipchat client (BETA, x86/x86_64 only) + if ! grep -q 'downloads.hipchat.com' /etc/apt/sources.list; then + sudo add-apt-repository -y \ + "deb http://downloads.hipchat.com/linux/apt stable main" + wget -O- https://www.hipchat.com/keys/hipchat-linux.key \ + | sudo apt-key add - + updated_apt_repo=yes + fi + + # To get the most recent nodejs, later. + if ! ls /etc/apt/sources.list.d/ 2>&1 | grep -q chris-lea-node_js; then + sudo add-apt-repository -y ppa:chris-lea/node.js + updated_apt_repo=yes + fi + + # To get the most recent git. + if ! ls /etc/apt/sources.list.d/ 2>&1 | grep -q git-core-ppa; then + sudo add-apt-repository -y ppa:git-core/ppa + updated_apt_repo=yes + fi + + # Register all that stuff we just did. + if [ -n "$updated_apt_repo" ]; then + sudo apt-get update -qq -y || true + fi + + # Needed to develop at Khan: git and mercurial, python, ruby, node (js). + # xslt and xml are needed by the nokogiri ruby package. + sudo apt-get install -y git git-svn mercurial \ + pychecker python-mode python-setuptools python-pip python-virtualenv \ + ruby rubygems libxslt-dev libxml2-dev \ + nodejs + + # Not technically needed to develop at Khan, but we assume you have it. + sudo apt-get install -y nginx unrar virtualbox ack-grep + + # Not needed for Khan, but useful things to have. + sudo apt-get install -y ntp abiword curl diffstat expect gimp \ + imagemagick mplayer netcat netpbm screen w3m vim + + # If you don't have the other ack installed, ack is shorter than ack-grep + sudo dpkg-divert --local --divert /usr/bin/ack --rename --add \ + /usr/bin/ack-grep + + # Native hipchat client (BETA, x86/x86_64 only). + sudo apt-get install -y hipchat + + # Needed for the AIR-based hipchat client on linux, not needed if + # you use the native client. + # sudo apt-get install -y adobeair + + # Needed to install printer drivers, and to use the printer scanner + sudo apt-get install -y apparmor-utils xsane +} + +setup_clock() { + # This shouldn't be necessary, but it seems it is. + sudo service ntp stop + sudo ntpdate 0.ubuntu.pool.ntp.org 1.ubuntu.pool.ntp.org \ + 2.ubuntu.pool.ntp.org 3.ubuntu.pool.ntp.org + sudo service ntp start +} + + +# Run sudo once at the beginning to get the necessary permissions. +echo "This setup script needs your password to install things as root." +sudo sh -c 'echo Thanks' + +install_packages +setup_clock diff --git a/mac-setup.sh b/mac-setup.sh index 9afa5f9..1ff0e5c 100755 --- a/mac-setup.sh +++ b/mac-setup.sh @@ -1,201 +1,149 @@ -#!/usr/bin/env sh +#!/bin/sh -echo "Running Khan Installation Script 1.0" -echo "Warning: This is only tested on Mac OS 10.7 (Lion)" -echo " After each statement, either something will open for you to" -echo " interact with, or a script will run for you to use" -echo " Press enter when a download/install is completed to go to" -echo " the next step (including this one)" - -read - -# get user's name/email -read -p "Enter your full name: " name -read -p "Enter your github email: " gh_email -read -p "Enter your kiln email: " hg_email +update_path() { + # Export some useful directories. + export PATH=/usr/local/sbin:$PATH -if [ -z "$name" -o -z "$gh_email" -o -z "$hg_email" ]; then - echo "You must enter names and emails" - exit 1 -fi + # Put these in .bash_profile too. + if ! grep -q "export PATH=/usr/local/sbin" ~/.bash_profile; then + echo "export PATH=/usr/local/sbin:$$PATH" >> ~/.bash_profile + fi +} -echo "Have you installed the XCode Command Line Tools package," -read -p " or do you have a working version of gcc? y/n [n] " clt_installed +register_ssh_keys() { + # Create a public key if need be. + mkdir -p ~/.ssh + if [ ! -e ~/.ssh/id_rsa ]; then + ssh-keygen -q -N "" -t rsa -f ~/.ssh/id_rsa + fi + + # Copy the public key into the OS X clipboard. + cat ~/.ssh/id_rsa.pub | pbcopy + + # Have the user copy it into kiln and github. + echo "Opening kiln and github for you to register your ssh key." + echo "We've already copied the key into the OS clipboard for you." + echo "Click 'Add SSH Key', paste into the box, and hit 'Add key'" + open "https://github.com/settings/ssh" + read -p "Press enter to continue..." + + echo "Click 'Add a New Key', paste into the box, and hit 'Save key'" + open "https://khanacademy.kilnhg.com/Keys" + read -p "Press enter to continue..." +} -if [ "$clt_installed" != "y" ]; then +install_gcc() { + if ! gcc --version >/dev/null 2>&1; then echo "Downloading Command Line Tools (log in to start the download)" # download the command line tools open "https://developer.apple.com/downloads/download.action?path=Developer_Tools/command_line_tools_for_xcode__june_2012/command_line_tools_for_xcode_june_2012.dmg" - # If this doesn't work for you, you can find the most recent version here: https://developer.apple.com/downloads + # If this doesn't work for you, you can find the most recent + # version here: https://developer.apple.com/downloads # Then plug that file into the commands below - - read + read -p "Press enter to continue..." echo "Running Command Line Tools Installer" + # Attach the disk image, install the tools, then detach the image. + hdiutil attach ~/Downloads/command_line_tools_for_xcode_june_2012.dmg \ + > /dev/null + sudo installer \ + -package "/Volumes/Command Line Tools/Command Line Tools.mpkg" \ + -target / + hdiutil detach "/Volumes/Command Line Tools/" > /dev/null + fi +} + +install_hipchat() { + # TODO(csilvers): see if hipchat is already installed before doing this. + echo "Opening Hipchat website (log in and click download to install)" + open "http://www.hipchat.com/" + read -p "Press enter to continue..." +} + +install_homebrew() { + echo "Installing Homebrew" + # If homebrew is already installed, don't do it again. + if [ ! -d /usr/local/.git ]; then + /usr/bin/ruby -e "`curl -fsSkL raw.github.com/mxcl/homebrew/go`" + fi + # Update brew. + brew update > /dev/null - # attach the disk image - hdiutil attach ~/Downloads/command_line_tools_for_xcode_june_2012.dmg > /dev/null - echo "Type your password to install:" - # install the command line tools - sudo installer -package /Volumes/Command\ Line\ Tools/Command\ Line\ Tools.mpkg -target / - # detach the disk image - hdiutil detach /Volumes/Command\ Line\ Tools/ > /dev/null -fi - -echo "Opening Hipchat website (log in and click download to install)" -# open the hipchat page -open "http://www.hipchat.com/" - -read - -echo "Installing Homebrew" -# if homebrew is already installed, don't do it again -if [ ! -d /usr/local/.git ]; then - /usr/bin/ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" -fi -# update brew -brew update > /dev/null - -# make the cellar -mkdir -p /usr/local/Cellar -# export some useful directories -export PATH=/usr/local/sbin:$PATH -# put these in .bash_profile too -echo "export PATH=/usr/local/sbin:$$PATH" >> ~/.bash_profile - -# brew doctor -brew doctor - -# setup git name/email -git config --global user.name "$name" -git config --global user.email "$gh_email" - -echo "Installing virtualenv" -# install pip -sudo easy_install --quiet pip -# install virtualenv -sudo pip install virtualenv -q - -echo "Setting up virtualenv" - -# make a virtualenv -virtualenv -q --python=/usr/bin/python2.7 ~/.virtualenv/khan27 -echo "source ~/.virtualenv/khan27/bin/activate" >> ~/.bash_profile - -# our function to activate virtualenv -virtenv() { - source ~/.virtualenv/khan27/bin/activate + # Make the cellar + mkdir -p /usr/local/Cellar + + # brew doctor + brew doctor +} + +install_nginx() { + echo "Installing nginx" + brew install nginx + + if [ ! -e /usr/local/etc/nginx/nginx.conf.old ]; then + echo "Backing up nginx.conf to nginx.conf.old" + sudo cp /usr/local/etc/nginx/nginx.conf \ + /usr/local/etc/nginx/nginx.conf.old + fi + + # Copy some default SSL certificates. If you want to make your + # own, follow the instructions found here: + # http://wiki.nginx.org/HttpSslModule + sudo cp -f stable.ka.local.crt /usr/local/etc/nginx/stable.ka.local.crt + sudo cp -f stable.ka.local.key /usr/local/etc/nginx/stable.ka.local.key + + echo "Setting up nginx" + # setup the nginx configuration file + sudo sh -c \ + "sed 's/%USER/$USER/' nginx.conf > /usr/local/etc/nginx/nginx.conf" + + # Copy the launch plist. + sudo cp -f /usr/local/Cellar/nginx/*/homebrew.mxcl.nginx.plist \ + /Library/LaunchDaemons + # Delete the username key so it is run as root + sudo /usr/libexec/PlistBuddy -c "Delete :UserName" \ + /Library/LaunchDaemons/homebrew.mxcl.nginx.plist 2>/dev/null + # Load it. + sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist +} + +install_appengine_launcher() { + echo "Setting up App Engine Launcher" + # TODO(csilvers): skip this step if it's already been done. + curl -s http://googleappengine.googlecode.com/files/GoogleAppEngineLauncher-1.7.4.dmg \ + -o ~/Downloads/GoogleAppEngineLauncher-1.7.4.dmg + hdiutil attach ~/Downloads/GoogleAppEngineLauncher-1.7.4.dmg + cp -fr /Volumes/GoogleAppEngineLauncher-*/GoogleAppEngineLauncher.app \ + /Applications/ + hdiutil detach /Volumes/GoogleAppEngineLauncher-* + + echo "Set up the Google App Engine Launcher according to the website." + open "https://sites.google.com/a/khanacademy.org/forge/for-khan-employees/-new-employees-onboard-doc/developer-setup/launching-your-test-site" + open -a GoogleAppEngineLauncher + + read -p "Press enter to continue..." } -echo "Installing mercurial in virtualenv" -virtenv -# install mercurial in virtualenv -pip -q install Mercurial -deactivate - -echo "Making khan directory" -# start building our directory -mkdir -p ~/khan/ -cd ~/khan/ - -echo "Cloning stable -- you'll need your Kiln password" -# get the stable branch -hg clone -q https://khanacademy.kilnhg.com/Code/Website/Group/stable stable 2>/dev/null || (cd stable; hg pull -q -u) - -echo "Setting up your .hgrc.local" -# make the dummy certificate -yes "" | openssl req -new -x509 -extensions v3_ca -keyout /dev/null -out dummycert.pem -days 3650 -passout pass:pass 2> /dev/null -sudo cp dummycert.pem /etc/hg-dummy-cert.pem -rm dummycert.pem -# setup the .hgrc -echo "[ui] -username = $name <$hg_email> - -[web] -cacerts = /etc/hg-dummy-cert.pem" > ~/.hgrc.local - -echo "%include ~/.hgrc.local" >> ~/.hgrc - -echo "Installing requirements" -virtenv -# install requirements into the virtualenv -pip -q install -r stable/requirements.txt -deactivate - -echo "Setting up ssh keys" - -# if there is no ssh key, make one -mkdir -p ~/.ssh -if [ ! -e ~/.ssh/id_*sa ]; then - ssh-keygen -t rsa -C "$gh_email" -f ~/.ssh/id_rsa -fi - -# copy the public key -cat ~/.ssh/id_rsa.pub | pbcopy - -echo "Opening github ssh keys" -echo "Click 'Add SSH Key', paste into the box, and hit 'Add key'" -# go to the github ssh keys site -open "https://github.com/settings/ssh" - -read - -echo "Getting development tools" -# download a bunch of developer tools -mkdir -p devtools -cd devtools -git clone -q https://github.com/Khan/kiln-review 2>/dev/null || (cd kiln-review; git pull -q) -hg clone -q https://bitbucket.org/brendan/mercurial-extensions-rdiff 2>/dev/null || (cd mercurial-extensions-rdiff; hg -q pull -u) -git clone -q https://github.com/Khan/khan-linter 2>/dev/null || (cd khan-linter; git pull -q) -git clone -q https://github.com/Khan/arcanist 2>/dev/null || (cd arcanist; git pull -q) -git clone -q https://github.com/Khan/libphutil.git 2>/dev/null || (cd libphutil; git pull -q) -curl -s https://khanacademy.kilnhg.com/Tools/Downloads/Extensions > /tmp/extensions.zip && unzip -qo /tmp/extensions.zip kiln_extensions/kilnauth.py - -cd ~/khan - -echo "Installing nginx" -# install nginx -brew install nginx - -echo "Backing up nginx.conf to nginx.conf.old" -# make a backup of nginx config -sudo cp /usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/nginx.conf.old - -# Copy some default SSL certificates. If you want to make your own, follow -# the instructions found here: http://wiki.nginx.org/HttpSslModule -curl -s https://raw.github.com/Khan/khan-dotfiles/master/stable.ka.local.crt > /usr/local/etc/nginx/stable.ka.local.crt -curl -s https://raw.github.com/Khan/khan-dotfiles/master/stable.ka.local.key > /usr/local/etc/nginx/stable.ka.local.key - -echo "Setting up nginx" -# setup the nginx configuration file -curl -s https://raw.github.com/Khan/khan-dotfiles/master/nginx.conf | sed "s/%USER/$USER/" > /usr/local/etc/nginx/nginx.conf - -# if not done before, add the new hosts to /etc/hosts -if ! grep -q "ka.local" /etc/hosts; then - echo "# KA local servers -127.0.0.1 exercises.ka.local -::1 exercises.ka.local -127.0.0.1 stable.ka.local -::1 stable.ka.local" | sudo tee -a /etc/hosts >/dev/null -fi - -# copy the launch plist -sudo cp /usr/local/Cellar/nginx/*/homebrew.mxcl.nginx.plist /Library/LaunchDaemons -# delete the username key so it is run as root -sudo /usr/libexec/PlistBuddy -c "Delete :UserName" /Library/LaunchDaemons/homebrew.mxcl.nginx.plist 2>/dev/null -# load it -sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist - -echo "Setting up App Engine Launcher" -curl -s http://googleappengine.googlecode.com/files/GoogleAppEngineLauncher-1.7.4.dmg -o ~/Downloads/GoogleAppEngineLauncher-1.7.4.dmg -hdiutil attach ~/Downloads/GoogleAppEngineLauncher-1.7.4.dmg -cp -r /Volumes/GoogleAppEngineLauncher-*/GoogleAppEngineLauncher.app /Applications/ -hdiutil detach /Volumes/GoogleAppEngineLauncher-* - -echo "Set up the Google App Engine Launcher according to the website." -open "https://sites.google.com/a/khanacademy.org/forge/for-khan-employees/-new-employees-onboard-doc/developer-setup/launching-your-test-site" -open -a GoogleAppEngineLauncher - -read + +echo "Running Khan Installation Script 1.0" +echo "Warning: This is only tested on Mac OS 10.7 (Lion)" +echo " After each statement, either something will open for you to" +echo " interact with, or a script will run for you to use" +echo " Press enter when a download/install is completed to go to" +echo " the next step (including this one)" + +read -p "Press enter to continue..." + +# Run sudo once at the beginning to get the necessary permissions. +echo "This setup script needs your password to install things as root." +sudo sh -c 'echo Thanks' + +update_path +register_ssh_keys +install_gcc +install_hipchat +install_homebrew +install_nginx +install_appengine_launcher echo "You might be done!" diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..f6f3d61 --- /dev/null +++ b/setup.sh @@ -0,0 +1,234 @@ +#!/bin/sh + +# This has files that are used by Khan Academy developers. This setup +# script is OS-agnostic; it installs things like dotfiles, python +# libraries, etc that are the same on Linux, OS X, maybe even cygwin. +# It is intended to be idempotent; you can safely run it multiple +# times. It should be run from the root of the khan-dotfiles directory. + + +# Bail on any errors +set -e + +# Install in $HOME by default, but can set an alternate destination via $1. +ROOT=${1-$HOME} +mkdir -p "$ROOT" + + +warnings="" + +add_warning() { + warnings="$warnings\nWARNING: $*" +} + +check_dependencies() { + # We need git >=1.8 for '[push] default=simple'. + # (Even without that, we'd need git >=1.7.10 or so for [include].) + if ! git --version | grep -q -e 'version 1.[89]' -e 'version 2'; then + echo "Must have git >= 1.8. See http://git-scm.com/downloads" + exit 1 + fi + + # You need to have run the setup to install binaries: node, npm/etc. + if ! npm --version >/dev/null; then + echo "You must install binaries before running $0. See" + echo " https://sites.google.com/a/khanacademy.org/forge/for-khan-employees/-new-employees-onboard-doc/developer-setup" + exit 1 + fi +} + +install_dotfiles() { + # Most dotfiles are installed as symlinks. + # (But we ignore .git which is actually part of the khan-dotfiles repo!) + for file in `find .[!.]* -name .git -prune -o -type f -print`; do + mkdir -p "$ROOT"/`dirname "$file"` + source=`pwd`/"$file" + dest="$ROOT/$file" + if [ -h "$dest" -a "`readlink $dest`" = "$source" ]; then + : + elif [ -e "$dest" ]; then + add_warning "Not symlinking to $dest because it already exists." + else + ln -sfvn "$source" "$dest" + fi + done + + # A few dotfiles are copied so the user can change them. They all + # have names like bashrc.default, which is installed as .bashrc. + # They all have the property they 'include' khan-specific code. + for file in *.default; do + dest="$ROOT/.`echo "$file" | sed s/.default$//`" # foo.default -> .foo + ka_version=.`echo "$file" | sed s/default/khan/` # .bashrc.khan + if [ ! -e "$dest" ]; then + cp -f "$file" "$dest" + elif ! fgrep -q "$ka_version" "$dest"; then + add_warning "$dest does not include $ka_version; may want to fix" + fi + done + +} + +edit_system_config() { + # This will let you visit the khan academy homepage by just typing + # www (or www/) into your browser's address bar, rather than + # having to type www.khanacademy.org. + if ! grep -q "search khanacademy.org" /etc/resolv.conf; then + sudo sh -c 'echo "search khanacademy.org" >> /etc/resolv.conf' + fi + + # This will let you use a url like exercises.ka.local + if ! grep -q "ka.local" /etc/hosts; then + # This 'sudo tee' trick is the way to redirect stdin within sudo. + sudo tee -a /etc/hosts >/dev/null < /usr/local/etc/mime.types" + else + sudo sh -c 'echo "$line" > /usr/local/etc/mime.types' + fi + + # If there is no ssh key, make one. + mkdir -p "$ROOT/.ssh" + if [ ! -e "$ROOT/.ssh/id_rsa" -a ! -e "$ROOT/.ssh/id_dsa" ]; then + ssh-keygen -q -N "" -t rsa -f "$ROOT/.ssh/id_rsa" + fi +} + +# $1: url of the repository to clone. $2: directory to put repo, under $ROOT +clone_repo() { + ( + mkdir -p "$ROOT/$2" + cd "$ROOT/$2" + if git clone "$1"; then + cd `basename $1` + git submodule update --init --recursive + else + cd `basename $1` + # This 'git init' installs any new hooks we may have created. + git init -q + fi + ) +} + +clone_repos() { + clone_repo ssh://khanacademy@khanacademy.kilnhg.com/Website/Group/webapp \ + khan/ + clone_repo git://github.com/Khan/kiln-review khan/devtools/ + clone_repo git://github.com/Khan/khan-linter khan/devtools/ + clone_repo git://github.com/Khan/libphutil khan/devtools/ + clone_repo git://github.com/Khan/arcanist khan/devtools/ + # For hg users + ( + cd "$ROOT/khan/devtools" + hg clone https://bitbucket.org/brendan/mercurial-extensions-rdiff || true + + mkdir -p kiln_extensions + if [ ! -e kiln_extensions/kilnauth.py ]; then + curl -s https://khanacademy.kilnhg.com/Tools/Downloads/Extensions \ + > /tmp/extensions.zip \ + && unzip -qo /tmp/extensions.zip kiln_extensions/kilnauth.py + fi + ) +} + +# Depends on khan-linter having been pulled first. +install_git_hooks() { + mkdir -p "$ROOT/.git_template/hooks" + ln -snfv "$ROOT/khan/devtools/khan-linter/githook.py" \ + "$ROOT/.git_template/hooks/commit-msg" +} + +install_mercurial_hooks() { + # Create a dummy certificate to quiet mercurial and kiln + mkdir -p "$ROOT/khan/devtools" + if [ ! -s "$ROOT/khan/devtools/hg-dummy-cert.pem" ]; then + yes "" | openssl req -new -x509 -extensions v3_ca -keyout /dev/null \ + -out "$ROOT/khan/devtools/hg-dummy-cert.pem" -days 3650 \ + -passout pass:pass >/dev/null 2>&1 + fi +} + +# Must have cloned the repos first. +install_python_and_npm() { + # pip is a nicer installer/package manager than easy-install. + sudo easy_install --quiet pip + + # Install non-khan-specific modules. + sudo pip install -q Mercurial + + # Install virtualenv. + # https://sites.google.com/a/khanacademy.org/forge/for-khan-employees/-new-employees-onboard-doc/developer-setup/using-virtualenv + sudo pip install -q virtualenv + if [ ! -d "$ROOT/.virtualenv/khan27" ]; then + virtualenv -q --python=/usr/bin/python2.7 --no-site-packages \ + "$ROOT/.virtualenv/khan27" + fi + # Activate the virtualenv + . ~/.virtualenv/khan27/bin/activate + + # Install all the requirements that khan and khan-exercises need. + # This also installs npm deps. + ( cd "$ROOT/khan/webapp" && make install_deps ) + ( cd "$ROOT/khan/webapp/khan-exercises" && pip install -r requirements.txt ) +} + +install_ruby() { + # These are used by khan-exercises to pack exercises. + sudo gem install --conservative -q json nokogiri uglifier therubyracer +} + +update_credentials() { + # sed -i means 'replace in-place' + if grep -q '%NAME_FIRST_LAST%' "$ROOT/.gitconfig" "$ROOT/.hgrc"; then + read -p "Enter your full name (First Last): " name + sed -i "s/%NAME_FIRST_LAST%/$name/g" "$ROOT/.gitconfig" "$ROOT/.hgrc" + fi + + if grep -q '%EMAIL%' "$ROOT/.gitconfig" "$ROOT/.hgrc"; then + read -p "Enter your KA email, without the @khanacademy.org (e.g. $USER): " email + sed -i "s/%EMAIL%/$email/g" "$ROOT/.gitconfig" "$ROOT/.hgrc" + fi +} + + +check_dependencies + +# Run sudo once at the beginning to get the necessary permissions. +echo "This setup script needs your password to install things as root." +sudo sh -c 'echo Thanks' + +install_dotfiles +edit_system_config +clone_repos +# These need the repos to exist (e.g. khan-linter), so come after that. +install_git_hooks +install_mercurial_hooks +install_python_and_npm +install_ruby +update_credentials + + +if [ -n "$warnings" ]; then + echo "-- WARNINGS:" + echo -e "$warnings" +else + echo "DONE!" +fi + +echo +echo "To finish your setup, go to" +echo " https://sites.google.com/a/khanacademy.org/forge/for-khan-employees/-new-employees-onboard-doc/developer-setup"