Skip to content

Instantly share code, notes, and snippets.

@tonyfischetti
Created October 30, 2016 23:50
Show Gist options
  • Save tonyfischetti/5efde8a04635b1efd80a32ea3327fe7a to your computer and use it in GitHub Desktop.
Save tonyfischetti/5efde8a04635b1efd80a32ea3327fe7a to your computer and use it in GitHub Desktop.
My base provisioning script for a Debian server or vagrant instance
#!/usr/bin/env bash
THE_USER="janeway"
THE_HOME="/home/$THE_USER"
apt-get update
apt-get -y upgrade
apt-get install -y --force-yes rlwrap git vim zsh build-essential silversearcher-ag automake pkg-config moreutils libevent-dev libtinfo5 libncurses5-dev apt-transport-https python-pip python-webpy ipython htop sbcl
# add recent r backport
sudo sh -c 'echo "deb http://cran.revolutionanalytics.com/bin/linux/debian jessie-cran3/" >> /etc/apt/sources.list'
apt-key adv --keyserver keys.gnupg.net --recv-key 6212B7B7931C4BB16280BA1306F90DE5381BA480
apt-get update
apt-get install -y --force-yes r-base-dev libssl-dev r-cran-rcpp libssh2-1-dev libcurl4-openssl-dev libxml2-dev
#-------------------------------------------#
# vim
git clone https://github.com/tonyfischetti/vix.git $THE_HOME/.vim
ln -s $THE_HOME/.vim/.vimrc $THE_HOME/.vimrc
git clone https://github.com/VundleVim/Vundle.vim.git $THE_HOME/.vim/bundle/Vundle.vim
echo "Dont forget to :PluginInstall"
mkdir $THE_HOME/.fonts
cp $THE_HOME/.vim/goodies/Monaco+for+Powerline+patched.otf $THE_HOME/.fonts
fc-cache -vf
#-------------------------------------------#
#-------------------------------------------#
# tmux
git clone https://github.com/tonyfischetti/tmix.git $THE_HOME/.tmux
ln -s $THE_HOME/.tmux/.tmux.conf $THE_HOME/.tmux.conf
git clone https://github.com/tonyfischetti/tmux.git $THE_HOME/tmux
cd $THE_HOME/tmux
./autogen.sh
./configure
make
make install
#-------------------------------------------#
#-------------------------------------------#
# zsh
git clone https://github.com/tonyfischetti/zix.git $THE_HOME/.zsh
ln -s $THE_HOME/.zsh/.zshrc $THE_HOME/.zshrc
chsh -s /usr/bin/zsh $THE_USER
#-------------------------------------------#
#-------------------------------------------#
# common lisp
cd /tmp/
curl -O https://beta.quicklisp.org/quicklisp.lisp
sudo -u $THE_USER -H sh -c "sbcl --load quicklisp.lisp --eval '(progn (quicklisp-quickstart:install) (quit))'"
cat <<EOF > $THE_HOME/.sbclrc
#-quicklisp
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
(user-homedir-pathname))))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
EOF
#-------------------------------------------#
#-------------------------------------------#
# R
cat <<EOF > $THE_HOME/RUN_THIS_IN_R.R
needed <- c("boot", "magrittr", "dplyr", "MASS",
"Rcpp", "inline", "devtools", "glmnet")
install.packages(needed, repos="http://cran.revolutionanalytics.com/")
devtools::install_github("jalvesaq/colorout")
devtools::install_github("ropenscilabs/assertr", ref="dev")
devtools::install_github("rmcelreath/rethinking")
getout <- '
.First <- function(){
if(interactive()){
library(utils)
# puts a timestamp in my command history
# file if R_HISTFILE is in environment
timestamp(,prefix=paste("##------ [",getwd(),"] ",sep=""))
}
}
.Last <- function(){
if(interactive()){
# saving my interactive command history
# is a life saver and saved me many hours
# of work. This will save my history to
# the file that the environment variable
# $R_HISTFILE points to, if it doesnt exist,
# use ~/.RHistory
hist_file <- Sys.getenv("R_HISTFILE")
if(hist_file=="") hist_file <- "~/.Rhistory"
try(savehistory(hist_file))
}
}
library("colorout")
options(repos="http://cran.rstudio.com/")
'
sink(paste0(Sys.getenv("HOME"), "/.Rprofile"))
cat(getout)
sink()
EOF
echo "Dont forget to R installation script!"
#-------------------------------------------#
#-------------------------------------------#
# apache
apt-get install -y apache2 libapache2-mod-wsgi
a2enmod wsgi
cat <<EOF > /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / /var/www/html/main.py/
Alias /static /var/www/html/static
<Directory /var/www/html/static>
Options Indexes FollowSymLinks Includes ExecCGI
Require all granted
</Directory>
AddType text/html .py
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EOF
service apache2 restart
#-------------------------------------------#
#-------------------------------------------#
# postgres
apt-get install -y postgresql postgresql-client postgresql-contrib
sudo -u postgres -H sh -c "psql -c \"ALTER ROLE postgres WITH ENCRYPTED PASSWORD 'SOME_PASSWORD'\";"
sudo -u postgres -H sh -c "psql -c \"CREATE USER $THE_USER WITH ENCRYPTED PASSWORD 'SOME_OTHER_PASSWORD'\";"
sudo -u postgres -H sh -c "psql -c \"CREATE DATABASE SOME_DATABASE_NAME WITH OWNER $THE_USER ENCODING 'UTF-8'\";"
cat /etc/postgresql/9.4/main/postgresql.conf | perl -pe "s/#listen_addresses = 'localhost'/listen_addresses = 'localhost'/g" | sponge /etc/postgresql/9.4/main/postgresql.conf
cat /etc/postgresql/9.4/main/pg_hba.conf | perl -pe "s/(local\s+all\s+)postgres\s+peer/\1postgres peer\n\1all md5/g" | sponge /etc/postgresql/9.4/main/pg_hba.conf
chown postgres /etc/postgresql/9.4/main/pg_hba.conf
chown postgres /etc/postgresql/9.4/main/postgresql.conf
sudo -u $THE_USER -H sh -c "psql -d THE_DATABASE_NAME -f SOME_SCHEMA_CREATION_SQL_SCRIPT.sql"
service postgresql restart
#-------------------------------------------#
chown -R $THE_USER $THE_HOME
echo "Dont forget to R installation script and ':PluginInstall' in Vim!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment