diff --git a/contrib/README.md b/contrib/README.md new file mode 100644 index 0000000..38b0899 --- /dev/null +++ b/contrib/README.md @@ -0,0 +1,6 @@ +# Contrib Notes # +RedHat directory also contains scripts for Ubuntu, and the configuration adapts according to the OS. +Ideally the Mac scripts would also be folded in as well. + +This version of scripts has so far only been tested on Ubuntu. I'll test on Mac also, but someone else will have to test on RedHat. + diff --git a/contrib/redhat/gitbucket.conf b/contrib/redhat/gitbucket.conf index 103778e..e8a5e3d 100644 --- a/contrib/redhat/gitbucket.conf +++ b/contrib/redhat/gitbucket.conf @@ -1,17 +1,30 @@ # Bind host -#GITBUCKET_HOST=0.0.0.0 - -# Server port -#GITBUCKET_PORT=8080 - -# Data directory (GITBUCKET_HOME/gitbucket) -#GITBUCKET_HOME=/var/lib/gitbucket - -# Path to the WAR file -#GITBUCKET_WAR_FILE=/usr/share/gitbucket/lib/gitbucket.war - -# URL prefix for the GitBucket page (http://://) -#GITBUCKET_PREFIX= +GITBUCKET_HOST=0.0.0.0 # Other Java option -#GITBUCKET_JVM_OPTS= +GITBUCKET_JVM_OPTS= + +# Data directory, holds repositories +GITBUCKET_HOME=/var/lib/gitbucket + +GITBUCKET_LOG_DIR=/var/log/gitbucket + +# Server port +GITBUCKET_PORT=8080 + +# URL prefix for the GitBucket page (http://://) +GITBUCKET_PREFIX= + +# Directory where GitBucket is installed +# Configuration is stored here: +GITBUCKET_DIR=/usr/share/gitbucket +GITBUCKET_WAR_DIR=$GITBUCKET_DIR/lib + +# Path to the WAR file +GITBUCKET_WAR_FILE=$GITBUCKET_WAR_DIR/gitbucket.war + +# RedHat prefers /etc/rc.d/init.d +GITBUCKET_SERVICE=/etc/init.d/gitbucket + +# GitBucket version to fetch when installing +GITBUCKET_VERSION=2.1 diff --git a/contrib/redhat/gitbucket.init b/contrib/redhat/gitbucket.init index 43e29e3..d811850 100644 --- a/contrib/redhat/gitbucket.init +++ b/contrib/redhat/gitbucket.init @@ -1,6 +1,7 @@ #!/bin/bash # -# /etc/rc.d/init.d/gitbucket +# RedHat: /etc/rc.d/init.d/gitbucket +# Ubuntu: /etc/init.d/gitbucket # # Starts the GitBucket server # @@ -8,28 +9,41 @@ # description: Run GitBucket server # processname: java -# Source function library -. /etc/rc.d/init.d/functions +[ -f /etc/rc.d/init.d/functions ] && source /etc/rc.d/init.d/functions # Default values GITBUCKET_HOME=/var/lib/gitbucket GITBUCKET_WAR_FILE=/usr/share/gitbucket/lib/gitbucket.war # Pull in cq settings -[ -f /etc/sysconfig/gitbucket ] && . /etc/sysconfig/gitbucket +[ -f /etc/sysconfig/gitbucket ] && source /etc/sysconfig/gitbucket +[ -f $GITBUCKET_DIR/gitbucket.conf ] && source $GITBUCKET_DIR/gitbucket.conf # added for non-redhat systems # Location of the log and PID file -LOG_FILE=/var/log/gitbucket/run.log +LOG_FILE=$GITBUCKET_LOG_DIR/run.log PID_FILE=/var/run/gitbucket.pid # Default return value RETVAL=0 +RED='\033[1m\E[37;41m' +GREEN='\033[1m\E[37;42m' +OFF='\E[0m' + +if [ -z "$(which success)" ]; then + function success { + printf "%b\n" "$GREEN $* $OFF" + } +fi +if [ -z "$(which failure)" ]; then + function failure { + printf "%b\n" "$RED $* $OFF" + } +fi start() { echo -n $"Starting GitBucket server: " - # Compile statup parameters if [ $GITBUCKET_PORT ]; then START_OPTS="${START_OPTS} --port=${GITBUCKET_PORT}" fi @@ -40,17 +54,15 @@ START_OPTS="${START_OPTS} --host=${GITBUCKET_HOST}" fi - # Run the Java process GITBUCKET_HOME="${GITBUCKET_HOME}" java $GITBUCKET_JVM_OPTS -jar $GITBUCKET_WAR_FILE $START_OPTS >>$LOG_FILE 2>&1 & RETVAL=$? - # Store PID of the Java process into a file echo $! > $PID_FILE if [ $RETVAL -eq 0 ] ; then - success "GitBucket startup" + success "Success" else - failure "GitBucket startup" + failure "Exit code $RETVAL" fi echo diff --git a/contrib/redhat/install b/contrib/redhat/install new file mode 100755 index 0000000..87690a4 --- /dev/null +++ b/contrib/redhat/install @@ -0,0 +1,49 @@ +#!/bin/bash + +# Only tested on Ubuntu 14.04 + +# Uses information stored in GitBucket git repo on GitHub as defaults. +# Edit gitbucket.conf before running this script + +GITBUCKET_VERSION=2.1 +source gitbucket.conf + +function createDir { + if [ ! -d "$1" ]; then + echo "Making $1 directory." + sudo mkdir -p "$1" + fi +} + +if [ ! -d "/etc/init.d/" ]; then + echo "/etc/init.d/ does not exist. This script requires System V init script compatibility." + exit -1 +fi + +if [ "$(which iptables)" ]; then + echo "Opening port $GITBUCKET_PORT in firewall." + sudo iptables -A INPUT -p tcp --dport $GITBUCKET_PORT -j ACCEPT +fi + +createDir "$GITBUCKET_HOME" +createDir "$GITBUCKET_WAR_DIR" +createDir "$GITBUCKET_DIR" +createDir "$GITBUCKET_LOG_DIR" + +echo "Fetching GitBucket v$GITBUCKET_VERSION and saving as $GITBUCKET_WAR_FILE" +sudo wget -qO "$GITBUCKET_WAR_FILE" https://github.com/takezoe/gitbucket/releases/download/$GITBUCKET_VERSION/gitbucket.war + +# Install gitbucket as a service that starts when system boots +sudo cp gitbucket.init "$GITBUCKET_SERVICE" +echo "Copying gitbucket.conf to $GITBUCKET_DIR" +sudo cp gitbucket.conf $GITBUCKET_DIR +sudo chown root:root $GITBUCKET_SERVICE +sudo chmod 755 $GITBUCKET_SERVICE +sudo update-rc.d $GITBUCKET_SERVICE defaults + +echo "Starting GitBucket service" +sudo rm -f "$GITBUCKET_LOG_DIR/run.log" +sudo $GITBUCKET_SERVICE start +if [ $? != 0 ]; then + less "$GITBUCKET_LOG_DIR/run.log" +fi \ No newline at end of file