Skip to content

Instantly share code, notes, and snippets.

@fsultan
Forked from fancyremarker/.bash_login.jenkins
Last active August 29, 2015 13:58
Show Gist options
  • Save fsultan/9936494 to your computer and use it in GitHub Desktop.
Save fsultan/9936494 to your computer and use it in GitHub Desktop.
#!/bin/bash
# As root ( via `sudo su -` ):
# Initialize ephemeral storage
curl https://gist.githubusercontent.com/fsultan/9936494/raw/ephemeral > /etc/init.d/ephemeral
chmod +x /etc/init.d/ephemeral
ln -s ../init.d/ephemeral /etc/rcS.d/S10ephemeral
/etc/init.d/ephemeral
ln -s /mnt/jenkins /var/jenkins
#ln -s /mnt/mongodb /var/lib/mongodb
ln -s /mnt/data /data1
ln -s /mnt/tmp /tmp
# Set logrotate to keep only one unit (day or week) of each log
for f in /etc/logrotate.d/* /etc/logrotate.conf ; do
sed -i 's/rotate [0-9]*$/rotate 1/' $f
done
apt-get update
apt-get install -y git build-essential bison openssl libreadline5 libreadline-dev curl git-core zsh zlib1g zlib1g-dev libssl-dev libreadline-dev libxml2-dev autoconf libxslt1-dev xvfb libgl1-mesa-dri xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic libyaml-dev checkinstall wget python python-setuptools python-dev libdbus-glib-1-2
sudo easy_install pip
pip install awscli
pip install virtualenv
echo "deb http://sm.repo.deb.s3-website-us-east-1.amazonaws.com/ wheezy main" > /etc/apt/sources.list.d/simulmedia.list
apt-get update
apt-get install -y --force-yes oracle-j2sdk1.7
update-alternatives --set java `update-alternatives --list java| grep oracle`
# Set up Xvfb (virtual framebuffer)
curl https://gist.githubusercontent.com/fsultan/9936494/raw/xvfb > /etc/init.d/xvfb
chmod +x /etc/init.d/xvfb
update-rc.d xvfb defaults
service xvfb start
apt-get install -y ant maven
#apt-get install -y imagemagick libmagick9-dev
# Firefox setup (install dependencies, then uninstall to downgrade)
echo "deb http://downloads.sourceforge.net/project/ubuntuzilla/mozilla/apt all main" > /etc/apt/sources.list.d/mozilla.list
apt-get update
apt-get install -y --force-yes firefox-mozilla-build
#apt-get remove -y firefox firefox-globalmenu
#wget http://releases.mozilla.org/pub/mozilla.org/firefox/releases/20.0.1/linux-x86_64/en-US/firefox-20.0.1.tar.bz2 -O #/tmp/firefox.tar.bz2
#cd /usr/local
#tar xjf /tmp/firefox.tar.bz2
#cd bin
#ln -s ../firefox/firefox .
#ln -s ../firefox/firefox-bin .
# Set up Postgreql
curl https://gist.githubusercontent.com/fsultan/9936494/raw/sources.pgdg.list >> /etc/apt/sources.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update
#apt-get upgrade
apt-get -y install postgresql-9.3 postgresql-client-9.3 postgresql-server-dev-9.3
su - postgres -c 'psql -c "CREATE ROLE jenkins login createdb"'
su - postgres -c 'psql -c "CREATE database jenkins owner jenkins"'
# Set up Redis
apt-get install -y redis-server
# Set up node
wget -N http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd node-v*
fakeroot checkinstall -y --install=no --pkgversion $(echo $(pwd) | sed -n -re's/.+node-v(.+)$/\1/p') make -j$(($(nproc)+1)) install
sudo dpkg -i node_*
curl https://www.npmjs.org/install.sh | sh
npm install -g grunt-cli
npm install -g grunt
npm install git://github.com/neoziro/bower.git#v1.2.8-patched
#npm install -g bower
npm install -g yo
npm install -g generator-angular
#npm install
#bower install --config.interactive=0
# Set up Jenkins spot instance callbacks
curl https://gist.githubusercontent.com/fsultan/9936494/raw/jenkins-spot-setup.py >> /usr/local/bin/jenkins-spot-setup.py
chmod +x /usr/local/bin/jenkins-spot-setup.py
sed -i 's/^exit 0$/sudo -i -u jenkins python \/usr\/local\/bin\/jenkins-spot-setup.py\n&/' /etc/rc.local
# User-level setup
useradd -k /etc/skel -m -s /bin/bash jenkins
mkdir /home/jenkins/.ssh
cp /home/admin/.ssh/authorized_keys /home/jenkins/.ssh/authorized_keys
chown -R jenkins:jenkins /home/jenkins/.ssh
chmod 700 /home/jenkins/.ssh
chmod 600 /home/jenkins/.ssh/authorized_keys
curl https://gist.githubusercontent.com/fsultan/9936494/raw/sudoers.wheel >> /etc/sudoers
groupadd wheel
usermod -G wheel jenkins
mkdir -p /var/jenkins/workspace
chown -R jenkins:jenkins /var/jenkins
#!/bin/bash
# As user jenkins ( via `sudo su - jenkins` ):
sudo su -l jenkins
ssh-keygen -q -t rsa -N "" -f .ssh/id_rsa
mkdir .m2
curl https://gist.githubusercontent.com/fsultan/9936494/raw/m2.settings.xml > .m2/settings.xml
curl https://gist.githubusercontent.com/fsultan/9936494/raw/bash_login.jenkins > /home/jenkins/.bash_login
mv /home/jenkins/.bashrc /home/jenkins/.bashrc~
curl https://gist.githubusercontent.com/fsultan/9936494/raw/bashrc.jenkins > /home/jenkins/.bashrc
cat /home/jenkins/.bashrc~ >> /home/jenkins/.bashrc
rm /home/jenkins/.bashrc~
# Install rbenv for managing enabling of multiple rubies.
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
exec $SHELL
# Install the ruby-build plugin for easy building of rubies.
mkdir -p ~/.rbenv/plugins
cd !$
git clone git://github.com/sstephenson/ruby-build.git
git clone git://github.com/jamis/rbenv-gemset.git
cd ~/
rbenv install 1.9.3-p484
rbenv rehash
# Enable a newly installed ruby, persistently, globally.
rbenv global 1.9.3-p484
rbenv rehash
git clone git://github.com/creationix/nvm.git ~/.nvm
source ~/.nvm/nvm.sh
nvm install v0.8.17
bower install --config.interactive=0
curl https://gist.githubusercontent.com/fsultan/9936494/raw/ssh_config >> /home/jenkins/.ssh/config
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
## [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
. ~/.nvm/nvm.sh
if [ -z "$PS1" ]; then
PATH=node_modules/.bin:$PATH
fi
#!/bin/sh
# Initialize ephemeral storage on /mnt
mkdir -p /mnt/jenkins/workspace
chown -R jenkins:jenkins /mnt/jenkins
mkdir -p /mnt/tmp
chmod 1777 /mnt/tmp
mkdir -p /mnt/data
chown -R jenkins:jenkins /mnt/data
#!/usr/bin/python
import os
import httplib
import string
import base64
conn = httplib.HTTPConnection("169.254.169.254")
conn.request("GET", "/latest/user-data")
response = conn.getresponse()
userdata = response.read()
args = string.split(userdata, "&")
jenkinsUrl = ""
jenkinsAuth = ""
slaveName = ""
for arg in args:
if arg.split("=")[0] == "JENKINS_URL":
jenkinsUrl = arg.split("=")[1]
if arg.split("=", 1)[0] == "USER_DATA":
subarg = base64.b64decode(arg.split("=", 1)[1])
if subarg.split("=")[0] == "JENKINS_AUTH":
jenkinsAuth = subarg.split("=")[1]
if arg.split("=")[0] == "SLAVE_NAME":
slaveName = arg.split("=")[1]
os.system("wget " + jenkinsUrl + "jnlpJars/slave.jar -O slave.jar")
os.system("java -jar slave.jar -jnlpCredentials " + jenkinsAuth + " -jnlpUrl " + jenkinsUrl + "computer/" + slaveName + "/slave-agent.jnlp")
<settings>
<servers>
<server>
<id>simulmedia-aws-release</id>
<username>${env.ARTIFACTS_AWS_ACCESS_KEY_ID}</username>
<password>${env.ARTIFACTS_AWS_SECRET_ACCESS_KEY}</password>
</server>
<server>
<id>simulmedia-aws-snapshot</id>
<username>${env.ARTIFACTS_AWS_ACCESS_KEY_ID}</username>
<password>${env.ARTIFACTS_AWS_SECRET_ACCESS_KEY}</password>
</server>
</servers>
</settings>
<settingsSecurity>
<master></master>
</settingsSecurity>
deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main
Host github.com
StrictHostKeyChecking no
Host heroku.com
StrictHostKeyChecking no
Host *
ServerAliveInterval 15
%wheel ALL=(ALL) NOPASSWD: ALL
#!/bin/sh
XVFB=/usr/bin/Xvfb
XVFBARGS=":99 -screen 0 1024x768x24 -fbdir /var/run -ac"
PIDFILE=/var/run/xvfb.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
;;
stop)
echo -n "Stopping virtual X frame buffer: Xvfb"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
echo "."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment