Skip to content

Commit

Permalink
Revamp khan-dotfiles to do a full install.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
csilvers committed May 1, 2013
1 parent 1ea0bf6 commit 0a8818f
Show file tree
Hide file tree
Showing 12 changed files with 535 additions and 224 deletions.
13 changes: 0 additions & 13 deletions .bashrc

This file was deleted.

23 changes: 23 additions & 0 deletions .bashrc.khan
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion .gitconfig → .gitconfig.khan
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
renames = copies

[init]
templatedir = ~/.git_template
templatedir = ~/.git_template
7 changes: 2 additions & 5 deletions .hgrc → .hgrc.khan
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
# 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}"
Expand All @@ -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 =
Expand Down
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
43 changes: 31 additions & 12 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,37 +1,56 @@
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)

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!
7 changes: 7 additions & 0 deletions bashrc.default
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions gitconfig.default
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions hgrc.default
Original file line number Diff line number Diff line change
@@ -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>
83 changes: 83 additions & 0 deletions linux-setup.sh
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 0a8818f

Please sign in to comment.