diff --git a/.gitignore b/.gitignore index a3dd9f3b..c6ec3f9f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ npm-debug.log .ep_initialized *.crt *.key +bin/etherpad-1.deb diff --git a/bin/buildDebian.sh b/bin/buildDebian.sh new file mode 100755 index 00000000..cc3353c2 --- /dev/null +++ b/bin/buildDebian.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# IMPORTANT +# Protect agaisnt mispelling a var and rm -rf / +set -u +set -e + +SRC=/tmp/etherpad-deb-src +DIST=/tmp/etherpad-deb-dist +SYSROOT=${SRC}/sysroot +DEBIAN=${SRC}/DEBIAN + +rm -rf ${DIST} +mkdir -p ${DIST}/ + +rm -rf ${SRC} +rsync -a bin/deb-src/ ${SRC}/ +mkdir -p ${SYSROOT}/opt/ + +rsync --exclude '.git' -a . ${SYSROOT}/opt/etherpad/ --delete +mkdir -p ${SYSROOT}/usr/share/doc +cp README.md ${SYSROOT}/usr/share/doc/etherpad +find ${SRC}/ -type d -exec chmod 0755 {} \; +find ${SRC}/ -type f -exec chmod go-w {} \; +chown -R root:root ${SRC}/ + +let SIZE=`du -s ${SYSROOT} | sed s'/\s\+.*//'`+8 +pushd ${SYSROOT}/ +tar czf ${DIST}/data.tar.gz [a-z]* +popd +sed s"/SIZE/${SIZE}/" -i ${DEBIAN}/control +pushd ${DEBIAN} +tar czf ${DIST}/control.tar.gz * +popd + +pushd ${DIST}/ +echo 2.0 > ./debian-binary + +find ${DIST}/ -type d -exec chmod 0755 {} \; +find ${DIST}/ -type f -exec chmod go-w {} \; +chown -R root:root ${DIST}/ +ar r ${DIST}/etherpad-1.deb debian-binary control.tar.gz data.tar.gz +popd +rsync -a ${DIST}/etherpad-1.deb ./ diff --git a/bin/deb-src/DEBIAN/control b/bin/deb-src/DEBIAN/control new file mode 100644 index 00000000..a516dc6d --- /dev/null +++ b/bin/deb-src/DEBIAN/control @@ -0,0 +1,9 @@ +Package: etherpad +Version: 1.3 +Section: base +Priority: optional +Architecture: i386 +Installed-Size: SIZE +Depends: +Maintainer: John McLear +Description: Etherpad is a collaborative editor. diff --git a/bin/deb-src/DEBIAN/postinst b/bin/deb-src/DEBIAN/postinst new file mode 100755 index 00000000..2f483f7e --- /dev/null +++ b/bin/deb-src/DEBIAN/postinst @@ -0,0 +1,7 @@ +#!/bin/bash +# Start the services! + +service etherpad start +echo "Give Etherpad about 3 minutes to install dependencies then visit http://localhost:9001 in your web browser" +echo "To stop etherpad type 'service etherpad stop', To restart type 'service etherpad restart'". +rm -f /tmp/etherpad.log /tmp/etherpad.err diff --git a/bin/deb-src/DEBIAN/preinst b/bin/deb-src/DEBIAN/preinst new file mode 100755 index 00000000..e5b5e0b7 --- /dev/null +++ b/bin/deb-src/DEBIAN/preinst @@ -0,0 +1,26 @@ +#!/bin/bash + +# Installs node if it isn't already installed +# +# Don't steamroll over a previously installed node version +# TODO provide a local version of node? + +VER="0.10.4" +ARCH="x86" +if [ `arch | grep 64` ] +then + ARCH="x64" +fi + +# TODO test version +if [ ! -f /usr/local/bin/node ] +then + pushd /tmp + wget -c "http://nodejs.org/dist/v${VER}/node-v${VER}-linux-${ARCH}.tar.gz" + rm -rf /tmp/node-v${VER}-linux-${ARCH} + tar xf node-v${VER}-linux-${ARCH}.tar.gz -C /tmp/ + cp -a /tmp/node-v${VER}-linux-${ARCH}/* /usr/local/ +fi + +# Create Etherpad user +adduser --system etherpad diff --git a/bin/deb-src/DEBIAN/prerm b/bin/deb-src/DEBIAN/prerm new file mode 100755 index 00000000..5e3d0f8a --- /dev/null +++ b/bin/deb-src/DEBIAN/prerm @@ -0,0 +1,4 @@ +#!/bin/bash + +# Stop the appserver: +service etherpad stop || true diff --git a/bin/deb-src/sysroot/etc/init/etherpad.conf b/bin/deb-src/sysroot/etc/init/etherpad.conf new file mode 100644 index 00000000..cd6f4541 --- /dev/null +++ b/bin/deb-src/sysroot/etc/init/etherpad.conf @@ -0,0 +1,28 @@ +description "etherpad" + +start on started networking +stop on runlevel [!2345] + +env EPHOME=/opt/etherpad +env EPLOGS=/var/log/etherpad +env EPUSER=etherpad + +respawn + +pre-start script + cd $EPHOME + mkdir $EPLOGS ||true + chown $EPUSER $EPLOGS ||true + chmod 0755 $EPLOGS ||true + chown -R $EPUSER $EPHOME/var ||true + $EPHOME/bin/installDeps.sh >> $EPLOGS/error.log || { stop; exit 1; } +end script + +script + cd $EPHOME/ + exec su -s /bin/sh -c 'exec "$0" "$@"' $EPUSER -- node node_modules/ep_etherpad-lite/node/server.js \ + >> $EPLOGS/access.log \ + 2>> $EPLOGS/error.log + echo "Etherpad is running on http://localhost:9001 - To change settings edit /opt/etherpad/settings.json" + +end script