Created
September 19, 2017 19:25
-
-
Save hardyoyo/4752db1439cb8c97b3deba2119828c56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# local-bootstrap.sh.example is an example of a local bootstrap shell povisioner for Vagrant-DSpace. If you copy this file to local-bootstrap.sh, and modify it to match your needs, it will be run whenever you run vagrant-up. | |
# local-bootstrap.sh is a hacky little solution to customizing your own DSpace clone from github. You can use it to do such things as set an upstream remote, configure fetching of pull requests from upstream, and much more | |
# it is also a handy stop-gap measure for providing needed functionality for Vagrant-DSpace (such as AIP auto-loading) without having to do a lot of puppet scripting. This works. | |
# WORD of WARNING: don't forget this script will run as root, so be careful about files you create. Git config lines will need to be run either as the vagrant user. | |
# function for calling apt-get | |
function aptget { | |
# to prevent encoding problem | |
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \ | |
-o Dpkg::Options::="--force-confdef" \ | |
-o Dpkg::Options::="--force-confold" \ | |
$@ | |
} | |
# You may have configured a different admin eperson in local.yaml, if so, you should use that admin user for the WHO variable below: | |
WHO="[email protected]" | |
CONTENT="/vagrant/content/aips" | |
HOME="/home/vagrant" | |
DSPACE_HOME="$HOME/dspace" | |
DSPACECMD="$DSPACE_HOME/bin/dspace" | |
DSPACESRC="$DSPACE_HOME-src" | |
# add extra packages here | |
aptget install ack-grep | |
aptget install ctags | |
aptget install ddate | |
aptget install fortune | |
aptget install vim | |
aptget install vim-gnome | |
aptget install tmux | |
aptget install libnotify-bin | |
aptget install notify-osd-icons | |
aptget install humanity-icon-theme | |
aptget install ansible | |
aptget install beep | |
aptget install libxml2-utils | |
aptget install xsltproc | |
aptget install nodejs | |
aptget install npm | |
aptget install stow | |
aptget install rbenv | |
aptget install ruby-build | |
## Let's use a current version of Maven, shall we? | |
# source: https://launchpad.net/~andrei-pozolotin/+archive/ubuntu/maven3 | |
# found via: http://stackoverflow.com/questions/15630055/how-to-install-maven-3-on-ubuntu-15-10-15-04-14-10-14-04-lts-13-10-13-04-12-10-1 | |
# aptget purge maven maven2 maven3 | |
# sudo apt-add-repository ppa:andrei-pozolotin/maven3 | |
# aptget update | |
# aptget install maven3 | |
# sudo ln -s /usr/share/maven3/bin/mvn /usr/bin/mvn | |
# and just to be sure, let's just upgrade everything | |
aptget upgrade | |
## START OFF BY CUSTOMIZING THE GIT CLONE ## | |
cd $DSPACESRC | |
# add the fingerprint for github | |
echo "Adding the fingerprint for github.com, shouldn't be necessary, but we don't want to get nagged later..." | |
ssh -T -oStrictHostKeyChecking=no [email protected] | |
# set git to allways rebase when we pull | |
#git config --global --bool pull.rebase true | |
# set git to always use pretty colors | |
#git config --global color.ui always | |
# and don't even try to get smart about converting line endings, that's just plain rude | |
#git config --global core.autocrlf input | |
# and I don't need merge backups, really, I don't | |
#git config --global --bool merge.keepbackups false | |
echo "and now setting up my preferences for my working copy... adding an upstream remote, PR refs..." | |
# add an upstreamdspace remote | |
cd $DSPACESRC && git remote add upstreamdspace [email protected]:DSpace/DSpace.git | |
# add an upstreamucla remote | |
cd $DSPACESRC && git remote add upstreamucla [email protected]:UCLALibrary/DSpace.git | |
# set up local branches from usptreamucla | |
cd $DSPACESRC && git fetch upstreamucla ucla-dr-6_x:ucla-dr-6_x | |
cd $DSPACESRC && git fetch upstreamucla ucla-vsim-6_x:ucla-vsim-6_x | |
# set up local branches from upstreamdspace | |
cd $DSPACESRC && git fetch upstreamdspace dspace-6_x:dspace-6_x | |
# enable fetching of pull requests from upstream (this may or may not be common practice, but it's handy, why not try it out?) | |
cd $DSPACESRC && git config --add remote.upstreamdspace.fetch +refs/pull/*/head:refs/remotes/upstreamdspace/pr/* | |
# now fetch everything so we're ready to go offline | |
echo "getting ready for offline coding..." | |
cd $DSPACESRC && git fetch --all | |
# run mvn install so our maven cache in ~/.m2/repository is current | |
cd $DSPACESRC && mvn install | |
# Git-smart is super helpful, especially for git newbies, and is worth installing just for smart-log | |
echo "installing git-smart gem" | |
sudo gem install git-smart | |
# Travis-CI has a nice CLI script that is handy for validating the .travis.yml file before you commit it | |
echo "installing travis gem" | |
sudo gem install travis | |
# notes is a nice little way to find TODO and FIXME notes, so you can work on them | |
echo "installing notes gem" | |
sudo gem install notes | |
#git config --global alias.n '!git ls-files | xargs notes' | |
# If we have a local.cfg file for the new commons-style configuration, let's use it | |
if [ -f "/vagrant/config/dotfiles/local.cfg" ]; then | |
echo "setting up the local.cfg for commons configuration" | |
cp /vagrant/config/dotfiles/local.cfg /home/vagrant/dspace-src/config/ | |
fi | |
# If we have a pgpass file for storing the PostgreSQL password, let's use it | |
if [ -f "/vagrant/config/dotfiles/pgpass" ]; then | |
echo "setting up the .pgpass file for faster psql CLI client access" | |
cp /vagrant/config/dotfiles/pgpass /home/vagrant/.pgpass | |
chmod 600 /home/vagrant/.pgpass | |
fi | |
# If we have a psqlrc file for storing our PostgreSQL preferences, let's use it | |
if [ -f "/vagrant/config/dotfiles/psqlrc" ]; then | |
echo "setting up the .pgpass file for faster psql CLI client access" | |
cp /vagrant/config/dotfiles/psqlrc /home/vagrant/.psqlrc | |
chmod 600 /home/vagrant/.psqlrc | |
fi | |
# If we have a dspace.properties file for ant configuration, let's use it | |
if [ -f "/vagrant/config/dotfiles/dspace.properties" ]; then | |
echo "setting up the .dspace.properties file for ant" | |
cp /vagrant/config/dotfiles/dspace.properties /home/vagrant/.dspace.properties | |
fi | |
# If we have a vagrant-mospace.properties file, let's copy that over | |
if [ -f "/vagrant/config/dotfiles/vagrant-mospace.properties" ]; then | |
echo "copying vagrant-mospace.properties" | |
cp /vagrant/config/dotfiles/vagrant-mospace.properties /home/vagrant/dspace-src/vagrant-mospace.properties | |
fi | |
# BASH history transplant (curse these lazy fingers) | |
if [ -f "/vagrant/config/dotfiles/bash_history" ]; then | |
echo "transplanting BASH history file" | |
cp /vagrant/config/dotfiles/bash_history /home/vagrant/.bash_history | |
fi | |
# # BASH inputrc customization | |
if [ -f "/vagrant/config/dotfiles/inputrc" ]; then | |
echo "setting up BASH inputrc file" | |
cp /vagrant/config/dotfiles/inputrc /home/vagrant/.inputrc | |
fi | |
# BASH aliases customization | |
if [ -f "/vagrant/config/dotfiles/bash_aliases" ]; then | |
echo "setting up .bash_aliases file" | |
cp /vagrant/config/dotfiles/bash_aliases /home/vagrant/.bash_aliases | |
fi | |
# Vim customization | |
# first install exuberant-ctags (required by my vimrc file) | |
aptget install exuberant-ctags | |
# copy vimrc if it exists | |
# if [ -f "/vagrant/config/dotfiles/vimrc" ]; then | |
# echo "setting up .vimrc file" | |
# cp /vagrant/config/dotfiles/vimrc /home/vagrant/.vimrc | |
# fi | |
# copy vim folder and its contents if they exists | |
# if [ -d "/vagrant/config/dotfiles/vim" ]; then | |
# echo "copying .vim settings folder" | |
# cp -r /vagrant/config/dotfiles/vim /home/vagrant/.vim | |
# echo "creating .vimbackups folder" | |
# mkdir /home/vagrant/.vimbackups | |
# fi | |
# clone my dotfiles repository | |
cd /home/vagrant && git clone [email protected]:hardyoyo/dotfiles.git dotfiles | |
cd /home/vagrant/dotfiles && git checkout hardyoyo-preferences | |
cd /home/vagrant/dotfiles && stow git | |
cd /home/vagrant/dotfiles && stow shell | |
cd /home/vagrant/dotfiles && stow tmux | |
cd /home/vagrant/dotfiles && stow vim | |
cd /home/vagrant/dotfiles && stow bin | |
# set up Vundle | |
git clone https://github.com/VundleVim/Vundle.vim.git /home/vagrant/.vim/bundle/Vundle.vim | |
# clone my vim config | |
# cd /home/vagrant && git clone [email protected]:hardyoyo/vimrc.git .vim | |
# cd /home/vagrant/.vim && git checkout hardyoyo-preferences | |
# cd /home/vagrant && ln -s .vim/.vimrc ./.vimrc | |
# install Vundle | |
#cd /home/vagrant/.vim && git clone https://github.com/gmarik/Vundle.vim.git bundle/Vundle.vim | |
# and let's make sure Vim is our default editor | |
echo "export EDITOR=\"/usr/bin/vim --servername vim\"" >> /home/vagrant/.profile | |
# and let's run Vundle Install disabled... this hangs up every time, skip it | |
#vim +PluginInstall +qall -q /dev/null | |
# and let's initialize ctags if the tags file doesn't already exist | |
if [ ! -f "/home/vagrant/dspace-src/tags" ]; then | |
ctags -R /home/vagrant/dspace-src -f /home/vagrant/dspace-src/tags --exclude *target* | |
fi | |
# MORE dotfiles | |
# copy bin folder if it's around | |
#if [ -d "/vagrant/config/dotfiles/bin" ]; then | |
# echo "copying bin folder and scripts..." | |
# cp -r /vagrant/config/dotfiles/bin /home/vagrant/bin | |
#fi | |
# copy GPG keys and trust files if they exist | |
if [ -d "/vagrant/config/dotfiles/gnupg" ]; then | |
echo "copying GPG keys and trust files..." | |
cp -r /vagrant/config/dotfiles/gnupg /home/vagrant/.gnupg | |
fi | |
# copy maven settings.xml if it exists | |
if [ -f "/vagrant/config/dotfiles/maven_settings.xml" ]; then | |
echo "copying Maven settings.xml file..." | |
cp /vagrant/config/dotfiles/maven_settings.xml /home/vagrant/.m2/settings.xml | |
fi | |
# install dependencies for hacking on Mirage2 | |
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags` | |
/home/vagrant/.nvm/install.sh | |
source /home/vagrant/.bashrc | |
nvm install 5.4.0 | |
nvm alias default 5.4.0 | |
npm install -g bower | |
npm install -g grunt | |
npm install -g grunt-cli | |
sudo gem install compass | |
# install AWS tool for Amazon S3 testing | |
aptget install awscli | |
#aptget install python-pip | |
#sudo pip install --upgrade pip | |
#sudo pip install --upgrade virtualenv | |
#sudo pip install aws-cli | |
# copy AWS config if it exists | |
if [ -d "/vagrant/config/dotfiles/aws" ]; then | |
echo "copying AWS credentials..." | |
cp -r /vagrant/config/dotfiles/aws /home/vagrant/.aws && chmod -R 600 /home/vagrant/.aws && chmod 700 /home/vagrant/.aws | |
fi | |
# NOTE: if you want more dotfiles installed, you'll need to specifically copy them, following | |
# the examples above. We do this so that we only install files with intention, and don't | |
# blindly install a config file. We recommend being cautious and only attempt to copy | |
# files and directories if they exist (use the -f and -d tests). | |
## set up Maven Notifications ## | |
# add the Maven lib/ext folder if it doesn't already exist | |
if [ ! -d "/usr/share/maven/lib/ext" ]; then | |
echo "creating the maven lib/ext folder..." | |
sudo mkdir /usr/share/maven/lib/ext | |
fi | |
# copy the Maven Notifier jar file | |
if [ -f "/vagrant/config/maven-notifier-1.10.2-SNAPSHOT.jar" ]; then | |
echo "copying the Maven Notifier jar file..." | |
sudo cp /vagrant/config/maven-notifier-1.10.2-SNAPSHOT.jar /usr/share/maven/lib/ext/maven-notifier-1.10.2-SNAPSHOT.jar | |
fi | |
# copy the Maven Notifier config file to all three locations the jar seems to want to find it | |
if [ -f "/vagrant/config/maven-notifier.properties" ]; then | |
echo "copying the Maven Notifier config file..." | |
sudo cp /vagrant/config/maven-notifier.properties /usr/share/maven/lib/ext/maven-notifier.properties | |
cp /vagrant/config/maven-notifier.properties /home/vagrant/.m2/maven-notifier.properties | |
cp /vagrant/config/maven-notifier.properties /home/vagrant/.send-notification | |
fi | |
## now add content ## | |
# NOTE: this will only work if the SITE AIP file is named the same as the handle prefix | |
# configured for this Vagrant-DSpace workspace (check vagrant.properties in dspace-src). By | |
# default it's the same prefix as the demo.dspace.org server, as DSpace Committers have | |
# ready access to the AIP files used to populate demo.dspace.org, and we can use | |
# Vagrant-DSpace to create more such AIPs. Demo's handle prefix is 10673. | |
SITE=`echo $CONTENT/SITE@* | cut -f1 -d' '` | |
if [ -n "$SITE" ]; then | |
echo "Recursively installing content from AIPs at $CONTENT (starting with $SITE AIP)" | |
# let's get the handle from this site AIP | |
SHFN="${SITE##*/}" | |
SH=`echo $SHFN | cut -f2 -d'@'` | |
SH=${SH/-/\/} | |
SH=`echo $SH | cut -f1 -d'.'` | |
# -------------------------------------- | |
# Stop Tomcat | |
# -------------------------------------- | |
sudo service tomcat7 stop | |
echo "" | |
cd $HOME | |
$DSPACECMD packager -u -r -a -f -t AIP -e $WHO -i $SH -o skipIfParentMissing=true -o createMetadataFields=true $SITE | |
# -------------------------------------- | |
# Import random metadata if the file exists | |
# -------------------------------------- | |
if [ -f "/vagrant/content/random_metadata_1K.csv" ]; then | |
cd $HOME | |
$DSPACECMD metadata-import -s -e $WHO -f /vagrant/content/random_metadata_1K.csv | |
fi | |
# ---------------------------------------------- | |
# Re-index content -- only necessary for DSpace 3.x and earlier | |
# ---------------------------------------------- | |
#echo "Reindexing all content in DSpace..." | |
#/home/vagrant/dspace/bin/dspace index-init | |
#echo "" | |
# -------------------------------------- | |
# Start up Tomcat | |
# -------------------------------------- | |
sudo service tomcat7 start | |
echo "" | |
# -------------------------------------- | |
# Step 8 : Update Discovery indexes | |
# -------------------------------------- | |
echo "Rebuilding Discovery (Solr) Indexes..." | |
# Note: the '-f' option tells Discovery to force a reindex of everything and remove docs which no longer exist | |
/home/vagrant/dspace/bin/dspace index-discovery -f | |
echo "Rebuilding OAI (Solr) Indexes..." | |
/home/vagrant/dspace/bin/dspace oai import -c | |
echo "" | |
echo "" | |
echo "SUCCESS! batch load of AIP content is now complete!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment