diff --git a/contrib/README.md b/contrib/README.md index 38b0899..c0241ce 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -1,6 +1,12 @@ # 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. +The configuration adapts according to the OS. +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, type: + + install \ No newline at end of file diff --git a/contrib/gitbucket.conf b/contrib/gitbucket.conf new file mode 100644 index 0000000..d747b45 --- /dev/null +++ b/contrib/gitbucket.conf @@ -0,0 +1,52 @@ +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 +} + +# 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 + +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..a578494 --- /dev/null +++ b/contrib/gitbucket.init @@ -0,0 +1,137 @@ +#!/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 +} + + +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..136fbcd --- /dev/null +++ b/contrib/install @@ -0,0 +1,64 @@ +#!/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 +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 $GITBUCKET_SERVICE defaults + 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 e8a5e3d..0000000 --- a/contrib/redhat/gitbucket.conf +++ /dev/null @@ -1,30 +0,0 @@ -# Bind host -GITBUCKET_HOST=0.0.0.0 - -# Other Java option -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 deleted file mode 100644 index d811850..0000000 --- a/contrib/redhat/gitbucket.init +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash -# -# RedHat: /etc/rc.d/init.d/gitbucket -# Ubuntu: /etc/init.d/gitbucket -# -# Starts the GitBucket server -# -# chkconfig: 345 60 40 -# description: Run GitBucket server -# processname: java - -[ -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 ] && 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=$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: " - - 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 -} - - -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. diff --git a/contrib/redhat/install b/contrib/redhat/install deleted file mode 100755 index 87690a4..0000000 --- a/contrib/redhat/install +++ /dev/null @@ -1,49 +0,0 @@ -#!/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