From: Mike D. Lowis Date: Mon, 11 Jun 2012 15:52:02 +0000 (-0400) Subject: Updated to support self installation and quick editing of config files. Also fleshed... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=40da8670389a7ad71790d9727a98bdefe9f0c881;p=archive%2Fbci.git Updated to support self installation and quick editing of config files. Also fleshed out the build and update procedures a bit more --- diff --git a/README.md b/README.md index e49f15c..5cacd30 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,19 @@ BCI About This Project ---------------------------------------------- -A distributed continuous integration script written in bash script. +A distributed continuous integration script written in the bash scripting +language. Installation ---------------------------------------------- BCI can be installed on any machine that has Bash and basic unix utilities by -executing the following commands: +executing the following command: - $ BCI_HOME="$HOME/.bci" - $ mkdir -p "$BCI_HOME" + $ chmod +x bci + $ ./bci install ~/.bci -BCI scripts will install to $BCI\_HOME/bin which should then be added to your +BCI scripts will install to $BCI\_HOME/bin which you should then add to your $PATH variable Using BCI @@ -25,13 +26,13 @@ Using BCI The following command will add a project to the BCI projects directory. - $ bci add some_project git@github.com:some_user/some_project.git + $ bci add some_project https://github.com/some_user/some_project.git -### Deleting a Project +### Removing a Project -The following command will delete a project from the BCI projects directory. +The following command will remove a project from the BCI projects directory. - $ bci del some_project + $ bci rm some_project ### Listing Projects diff --git a/bci b/bci index 9a7531b..2a9b392 100644 --- a/bci +++ b/bci @@ -1,17 +1,27 @@ #!/bin/env bash -BCI_HOME=$HOME/.bci +# If $BCI_HOME is not defined then set it to ~/.bci +if [ -z "${VAR}" ]; then + BCI_HOME=$HOME/.bci +fi +#------------------------------------------------------------------------------ +# Main BCI Functions +#------------------------------------------------------------------------------ + +# Define our usage message for command line arguments function bci-usage(){ cat << EOF Usage: bci [command] [options] Valid commands: - add Adds a project to bci - del Deletes a project from bci - ls Lists all projects - update Force a pull on the specified project - build Force a build on the specified project + add Adds a project to bci + config Opens the configuration file for a bci project + rm Removes a project from bci + install Installs bci to the desired location + ls Lists all projects + update Force a pull on the specified project + build Force a build on the specified project EOF exit 1 } @@ -22,21 +32,67 @@ function bci-add(){ local proj_url=$3 : ${proj_name:?"No project url provided."} local PROJ_HOME="$BCI_HOME/projects/$proj_name" - mkdir -p "$PROJ_HOME" + + # Create the directories mkdir -p "$PROJ_HOME/data" - git clone $proj_url $PROJ_HOME/repo + mkdir -p "$PROJ_HOME/logs" + + # Configure the new project echo "# put any project specific bci configuration options in this file" >> "$PROJ_HOME/config" read -p"how should the project be built? " BUILDCMD echo "build_command='$BUILDCMD'" >> "$PROJ_HOME/config" + read -p"which branch should we build? " BRANCH + echo "vcs_branch='$BRANCH'" >> "$PROJ_HOME/config" + source $PROJ_HOME/config + + # Checkout from VCS + git clone $proj_url $PROJ_HOME/repo + pushd $PROJ_HOME/repo + git checkout $vcs_branch + git submodule init + git submodule update + + # Done echo "project successfully created at $PROJ_HOME" + popd } -function bci-del(){ +function bci-config(){ + local proj_name=$2 + : ${proj_name:?"No project name provided."} + local config_file="$BCI_HOME/projects/$proj_name/config" + if [[ -f "$config_file" ]]; then + if [[ -z "$EDITOR" ]]; then + vim "$config_file" + else + $EDITOR "$config_file" + fi + else + echo "Could not find configuration file for project '$proj_name'" + exit 1 + fi +} + +function bci-rm(){ local proj_name=$2 : ${proj_name:?"No project name provided."} rm -rf "$BCI_HOME/projects/$proj_name" } +function bci-install(){ + local install_dir=$2 + : ${install_dir:?"No install directory provided"} + if [[ -d "$install_dir" ]]; then + echo -n "Install directory already exists. " + echo "Please remove the directory before installing." + else + mkdir -p $install_dir/projects + mkdir -p $install_dir/bin + cat bci | sed -e "s|\(\s\s*BCI_HOME=\).*|\1'$install_dir'|" > $install_dir/bin/bci + echo "Installation complete. Please add '$install_dir/bin' to your PATH variable" + fi +} + function bci-ls(){ ls "$BCI_HOME/projects" } @@ -45,7 +101,13 @@ function bci-update(){ local proj_name=$2 : ${proj_name:?"No project name provided."} pushd "$BCI_HOME/projects/$proj_name/repo" + source "$BCI_HOME/projects/$proj_name/config" #this must contain build_command=... + : ${build_command:?"don't know how to build this project"} + : ${vcs_branch:?"don't know which branch to build"} + git checkout $vcs_branch git pull + git submodule init + git submodule update popd } @@ -59,13 +121,36 @@ function bci-build(){ popd } +#------------------------------------------------------------------------------ +# Helper Functions +#------------------------------------------------------------------------------ + +function logrotate(){ + local logfile=$1 + : ${logfile:?"No log file provided."} + if [ -f $logfile ]; then + local timestamp=`date +%Y%m%d` + local newlogfile=$logfile.$timestamp + cp $logfile $newlogfile + cat /dev/null > $logfile + gzip -f -9 $newlogfile + fi +} + +#------------------------------------------------------------------------------ +# Main Routing Section +#------------------------------------------------------------------------------ + +# Route our commands to the corresponding function case "$1" in - add) bci-add $* ;; - del) bci-del $* ;; - ls) bci-ls $* ;; - update) bci-update $* ;; - build) bci-build $* ;; - - help) bci-usage ;; - '') bci-usage ;; + add) bci-add $* ;; + config) bci-config $* ;; + build) bci-build $* ;; + help) bci-usage $* ;; + install) bci-install $*;; + ls) bci-ls $* ;; + rm) bci-rm $* ;; + update) bci-update $* ;; + *) bci-usage $* ;; esac +