diff --git a/contrib/README.md b/contrib/README.md new file mode 100644 index 0000000..1121a22 --- /dev/null +++ b/contrib/README.md @@ -0,0 +1,13 @@ +# Contrib Notes # + +The configuration script adapts according to the OS. +The `linux` directory contains scripts for Ubuntu and RedHat. +The Mac scripts have been folded in as well. +Common scripts are in this directory. + +This version of scripts has so far only been tested on Ubuntu and Mac. Someone else will have to test on RedHat. + +To run: +1. Edit `gitbucket.conf` to suit. +2. Type: `install` + diff --git a/contrib/gitbucket.conf b/contrib/gitbucket.conf new file mode 100644 index 0000000..ead3331 --- /dev/null +++ b/contrib/gitbucket.conf @@ -0,0 +1,62 @@ +# Configuration section is below. Ignore this part + +function isUbuntu { + if [ -f /etc/lsb-release ]; then + grep -i ubuntu /etc/lsb-release | head -n 1 | cut -d \ -f 1 | cut -d = -f 2 + fi +} + +function isRedHat { + if [ -d "/etc/rc.d/init.d" ]; then echo yes; fi +} + +function isMac { + if [[ "$(uname -a | cut -d \ -f 1 )" == "Darwin" ]]; then echo yes; fi +} + +# +# Configuration section start +# + +# Bind host +GITBUCKET_HOST=0.0.0.0 + +# Other Java option +GITBUCKET_JVM_OPTS=-Dmail.smtp.starttls.enable=true + +# 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 + +# GitBucket version to fetch when installing +GITBUCKET_VERSION=2.1 + +# +# End of configuration section. Ignore this part +# +if [ `isUbuntu` ]; then + GITBUCKET_SERVICE=/etc/init.d/gitbucket +elif [ `isRedHat` ]; then + GITBUCKET_SERVICE=/etc/rc.d/init.d +elif [ `isMac` ]; then + GITBUCKET_SERVICE=/Library/StartupItems/GitBucket/GitBucket +else + echo "Don't know how to install onto this OS" + exit -2 +fi + diff --git a/contrib/gitbucket.init b/contrib/gitbucket.init new file mode 100644 index 0000000..0675646 --- /dev/null +++ b/contrib/gitbucket.init @@ -0,0 +1,138 @@ +#!/bin/bash +# +# RedHat: /etc/rc.d/init.d/gitbucket +# Ubuntu: /etc/init.d/gitbucket +# Mac OS/X: /Library/StartupItems/GitBucket +# +# Starts the GitBucket server +# +# chkconfig: 345 60 40 +# description: Run GitBucket server +# processname: java + +set -e + +[ -f /etc/rc.d/init.d/functions ] && source /etc/rc.d/init.d/functions # RedHat +[ -f /etc/rc.common ] && source /etc/rc.common # Mac OS/X + +# Default values +GITBUCKET_HOME=/var/lib/gitbucket +GITBUCKET_WAR_FILE=/usr/share/gitbucket/lib/gitbucket.war + +# Pull in cq settings +[ -f /etc/sysconfig/gitbucket ] && source /etc/sysconfig/gitbucket # RedHat +[ -f gitbucket.conf ] && source gitbucket.conf # For all systems + +# Location of the log and PID file +LOG_FILE=$GITBUCKET_LOG_DIR/run.log +PID_FILE=/var/run/gitbucket.pid + +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 + +RETVAL=0 + +start() { + echo -n $"Starting GitBucket server: " + + START_OPTS= + if [ $GITBUCKET_PORT ]; then + START_OPTS="${START_OPTS} --port=${GITBUCKET_PORT}" + fi + if [ $GITBUCKET_PREFIX ]; then + START_OPTS="${START_OPTS} --prefix=${GITBUCKET_PREFIX}" + fi + if [ $GITBUCKET_HOST ]; then + START_OPTS="${START_OPTS} --host=${GITBUCKET_HOST}" + fi + + GITBUCKET_HOME="${GITBUCKET_HOME}" java $GITBUCKET_JVM_OPTS -jar $GITBUCKET_WAR_FILE $START_OPTS >>$LOG_FILE 2>&1 & + RETVAL=$? + + echo $! > $PID_FILE + + if [ $RETVAL -eq 0 ] ; then + success "Success" + else + failure "Exit code $RETVAL" + fi + + echo + return $RETVAL +} + + +stop() { + echo -n $"Stopping GitBucket server: " + + # Run the Java process + kill $(cat $PID_FILE 2>/dev/null) >>$LOG_FILE 2>&1 + RETVAL=$? + + if [ $RETVAL -eq 0 ] ; then + rm -f $PID_FILE + success "GitBucket stopping" + else + failure "GitBucket stopping" + fi + + echo + return $RETVAL +} + + +restart() { + stop + start +} + +## MacOS proxies for System V service hooks: +StartService() { + start +} + +StopService() { + stop +} + +RestartService() { + restart +} + + +if [ `isMac` ]; then + RunService "$1" +else + case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + status) + status -p $PID_FILE java + RETVAL=$? + ;; + *) + echo $"Usage: $0 [start|stop|restart|status]" + RETVAL=2 + esac + exit $RETVAL +fi + diff --git a/contrib/install b/contrib/install new file mode 100755 index 0000000..860b02f --- /dev/null +++ b/contrib/install @@ -0,0 +1,69 @@ +#!/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 + +set -e + +GITBUCKET_VERSION=2.1 + +if [ ! -f gitbucket.conf ]; then + echo "gitbucket.conf not found, aborting" + exit -3 +fi +source gitbucket.conf + +function createDir { + if [ ! -d "$1" ]; then + echo "Making $1 directory." + sudo mkdir -p "$1" + fi +} + +if [ "$(which iptables)" ]; then + echo "Opening port $GITBUCKET_PORT in firewall." + sudo iptables -A INPUT -p tcp --dport $GITBUCKET_PORT -j ACCEPT + echo "Please use iptables-persistent:" + echo " sudo apt-get install iptables-persistent" + echo "After installed, you can save/reload iptables rules anytime:" + echo " sudo /etc/init.d/iptables-persistent save" + echo " sudo /etc/init.d/iptables-persistent reload" +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 + +sudo rm -f "$GITBUCKET_LOG_DIR/run.log" + +echo "Copying gitbucket.conf to $GITBUCKET_DIR" +sudo cp gitbucket.conf $GITBUCKET_DIR +if [ `isUbuntu` ] || [ `isRedHat` ]; then + sudo cp gitbucket.init "$GITBUCKET_SERVICE" + # Install gitbucket as a service that starts when system boots + sudo chown root:root $GITBUCKET_SERVICE + sudo chmod 755 $GITBUCKET_SERVICE + sudo update-rc.d "$(basename $GITBUCKET_SERVICE)" defaults 98 02 + echo "Starting GitBucket service" + sudo $GITBUCKET_SERVICE start +elif [ `isMac` ]; then + sudo macosx/makePlist + echo "Starting GitBucket service" + sudo cp gitbucket.conf "$GITBUCKET_SERVICE" + sudo cp gitbucket.init "$GITBUCKET_SERVICE" + sudo chmod a+x "$GITBUCKET_SERVICE" + sudo "$GITBUCKET_SERVICE" start +else + echo "Don't know how to install this OS" + exit -2 +fi + +if [ $? != 0 ]; then + less "$GITBUCKET_LOG_DIR/run.log" +fi diff --git a/contrib/linux/redhat/gitbucket.spec b/contrib/linux/redhat/gitbucket.spec new file mode 100644 index 0000000..ec8bdd5 --- /dev/null +++ b/contrib/linux/redhat/gitbucket.spec @@ -0,0 +1,47 @@ +Name: gitbucket +Summary: GitHub clone written with Scala. +Version: 1.7 +Release: 1%{?dist} +License: Apache +URL: https://github.com/takezoe/gitbucket +Group: System/Servers +Source0: %{name}.war +Source1: %{name}.init +Source2: %{name}.conf +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root +BuildArch: noarch +Requires: java >= 1.7 + + +%description + +GitBucket is the easily installable GitHub clone written with Scala. + + +%install +[ "%{buildroot}" != / ] && %{__rm} -rf "%{buildroot}" +%{__mkdir_p} %{buildroot}{%{_sysconfdir}/{init.d,sysconfig},%{_datarootdir}/%{name}/lib,%{_sharedstatedir}/%{name},%{_localstatedir}/log/%{name}} +%{__install} -m 0644 %{SOURCE0} %{buildroot}%{_datarootdir}/%{name}/lib +%{__install} -m 0755 %{SOURCE1} %{buildroot}%{_sysconfdir}/init.d/%{name} +%{__install} -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/%{name} +touch %{buildroot}%{_localstatedir}/log/%{name}/run.log + + +%clean +[ "%{buildroot}" != / ] && %{__rm} -rf "%{buildroot}" + + +%files +%defattr(-,root,root,-) +%{_datarootdir}/%{name}/lib/%{name}.war +%{_sysconfdir}/init.d/%{name} +%config %{_sysconfdir}/sysconfig/%{name} +%{_localstatedir}/log/%{name}/run.log + + +%changelog +* Mon Oct 28 2013 Jiri Tyr +- Version bump to v1.7. + +* Thu Oct 17 2013 Jiri Tyr +- First build. diff --git a/contrib/macosx/gitbucket.plist b/contrib/macosx/gitbucket.plist deleted file mode 100644 index 827c15a..0000000 --- a/contrib/macosx/gitbucket.plist +++ /dev/null @@ -1,20 +0,0 @@ - - - - - Label - gitbucket - ProgramArguments - - /usr/bin/java - -Dmail.smtp.starttls.enable=true - -jar - gitbucket.war - --host=127.0.0.1 - --port=8080 - --https=true - - RunAtLoad - - - diff --git a/contrib/macosx/makePlist b/contrib/macosx/makePlist new file mode 100755 index 0000000..3f874ef --- /dev/null +++ b/contrib/macosx/makePlist @@ -0,0 +1,28 @@ +#!/bin/bash + +# From http://docstore.mik.ua/orelly/unix3/mac/ch02_02.htm +source gitbucket.conf +GITBUCKET_SERVICE_DIR=`dirname "$GITBUCKET_SERVICE"` +mkdir -p "$GITBUCKET_SERVICE_DIR" +cat << EOF > "$GITBUCKET_SERVICE_DIR/gitbucket.plist" + + + + + Label + gitbucket + ProgramArguments + + /usr/bin/java + $GITBUCKET_JVM_OPTS + -jar + gitbucket.war + --host=$GITBUCKET_HOST + --port=$GITBUCKET_PORT + --https=true + + RunAtLoad + + + +EOF \ No newline at end of file diff --git a/contrib/redhat/gitbucket.conf b/contrib/redhat/gitbucket.conf deleted file mode 100644 index 103778e..0000000 --- a/contrib/redhat/gitbucket.conf +++ /dev/null @@ -1,17 +0,0 @@ -# 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= - -# Other Java option -#GITBUCKET_JVM_OPTS= diff --git a/contrib/redhat/gitbucket.init b/contrib/redhat/gitbucket.init deleted file mode 100644 index 43e29e3..0000000 --- a/contrib/redhat/gitbucket.init +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash -# -# /etc/rc.d/init.d/gitbucket -# -# Starts the GitBucket server -# -# chkconfig: 345 60 40 -# description: Run GitBucket server -# processname: java - -# Source function library -. /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 - -# Location of the log and PID file -LOG_FILE=/var/log/gitbucket/run.log -PID_FILE=/var/run/gitbucket.pid - -# Default return value -RETVAL=0 - - -start() { - echo -n $"Starting GitBucket server: " - - # Compile statup parameters - if [ $GITBUCKET_PORT ]; then - START_OPTS="${START_OPTS} --port=${GITBUCKET_PORT}" - fi - if [ $GITBUCKET_PREFIX ]; then - START_OPTS="${START_OPTS} --prefix=${GITBUCKET_PREFIX}" - fi - if [ $GITBUCKET_HOST ]; then - 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" - else - failure "GitBucket startup" - fi - - echo - return $RETVAL -} - - -stop() { - echo -n $"Stopping GitBucket server: " - - # Run the Java process - kill $(cat $PID_FILE 2>/dev/null) >>$LOG_FILE 2>&1 - RETVAL=$? - - if [ $RETVAL -eq 0 ] ; then - rm -f $PID_FILE - success "GitBucket stopping" - else - failure "GitBucket stopping" - fi - - echo - return $RETVAL -} - - -restart() { - stop - start -} - - -case "$1" in -start) - start - ;; -stop) - stop - ;; -restart) - restart - ;; -status) - status -p $PID_FILE java - RETVAL=$? - ;; -*) - echo $"Usage: $0 [start|stop|restart|status]" - RETVAL=2 -esac - - -exit $RETVAL diff --git a/contrib/redhat/gitbucket.spec b/contrib/redhat/gitbucket.spec deleted file mode 100644 index ec8bdd5..0000000 --- a/contrib/redhat/gitbucket.spec +++ /dev/null @@ -1,47 +0,0 @@ -Name: gitbucket -Summary: GitHub clone written with Scala. -Version: 1.7 -Release: 1%{?dist} -License: Apache -URL: https://github.com/takezoe/gitbucket -Group: System/Servers -Source0: %{name}.war -Source1: %{name}.init -Source2: %{name}.conf -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root -BuildArch: noarch -Requires: java >= 1.7 - - -%description - -GitBucket is the easily installable GitHub clone written with Scala. - - -%install -[ "%{buildroot}" != / ] && %{__rm} -rf "%{buildroot}" -%{__mkdir_p} %{buildroot}{%{_sysconfdir}/{init.d,sysconfig},%{_datarootdir}/%{name}/lib,%{_sharedstatedir}/%{name},%{_localstatedir}/log/%{name}} -%{__install} -m 0644 %{SOURCE0} %{buildroot}%{_datarootdir}/%{name}/lib -%{__install} -m 0755 %{SOURCE1} %{buildroot}%{_sysconfdir}/init.d/%{name} -%{__install} -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/%{name} -touch %{buildroot}%{_localstatedir}/log/%{name}/run.log - - -%clean -[ "%{buildroot}" != / ] && %{__rm} -rf "%{buildroot}" - - -%files -%defattr(-,root,root,-) -%{_datarootdir}/%{name}/lib/%{name}.war -%{_sysconfdir}/init.d/%{name} -%config %{_sysconfdir}/sysconfig/%{name} -%{_localstatedir}/log/%{name}/run.log - - -%changelog -* Mon Oct 28 2013 Jiri Tyr -- Version bump to v1.7. - -* Thu Oct 17 2013 Jiri Tyr -- First build.