Allow make-dist.sh to use an alternative repo.

Adds the -u switch, allowing use of another repository than
http://github.com/diaspora/diaspora.git. This is a dogfood patch.
Renames diaspora-ws->diaspora-wsd; this is indeed a daemon.
Moves all Fedora-related stuff in make-dist.sh to subcommand
'prepare'. The source tarballs are now usable on any OS
This commit is contained in:
Alec Leamas 2010-10-10 16:38:01 +02:00
parent 075a39cfce
commit 1c00fc232e
9 changed files with 242 additions and 157 deletions

View file

@ -1,12 +1,13 @@
## Diaspora RPM tools
Creates RPM packages from diaspora git repository.
Creates diaspora source tarballs and RPM packages
An alternative to the capistrano system, providing classic, binary RPM
packages for deployment on Fedora 13.
packages for deployment on Fedora 13 and OS-independent source tarballs
aimed for packaging purposes.
#### Synopsis:
#### Fedora RPM synopsis
*Prerequisites*: ruby-1.8, rubygem and other packages as described in
http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora
@ -17,8 +18,8 @@ and dist/diaspora-bundle-0.0-1010041233_fade4231.tar.gz:
% ./make-dist.sh source
% ./make-dist.sh bundle
Setup links to tarballs from RPM source directory:
% ./make-dist.sh links
Setup links to tarballs from RPM source directory and create spec files:
% ./make-dist.sh prepare
Build rpms:
rpmbuild -ba dist/diaspora.spec
@ -39,34 +40,73 @@ Start development server:
See http://github.com/diaspora/diaspora/wiki/Using-apache for
apache/passenger setup. After configuration, start with:
/sbin/service diaspora-ws start
/sbin/service diaspora-wsd start
/sbin/service httpd restart
#### Generic source synopsis
Generate source tarball:
% ./make-dist.sh source
Using repo: http://github.com/diaspora/diaspora.git
Commit id: 1010092232_b313272
Source: dist/diaspora-0.0-1010092232_b313272.tar.gz
Required bundle: 1010081636_d1a4ee0
%
The source tarball could be used as-is, by unpacking add making a
*bundle install*. An alternative is to generate a canned bundle like:
% ./make-dist.sh bundle
[ lot's of output...]
Bundle: dist/diaspora-bundle-0.0-1010081636_d1a4ee0.tar.gz
%
This file can be installed anywhere. To use it, add a symlink from vendor/bundle
to the bundle's master directory. Reasonable defaults are to install
diaspora in /var/diaspora and bundle in /usr/lib/diaspora-bundle. With these,
the link is
% rm -rf /var/diaspora/master/vendor/bundle
% ln -sf /usr/lib/diaspora-bundle/master/bundle \
> /var/diaspora/master/vendor
%
The directories tmp, log, and public/uploads needs to be writable. If using
apache passenger, read the docs on uid used and file ownership.
Note that the bundle version required is printed each time a new source
is generated.
#### Notes
The source tarball is as retrieved from diaspora with following differences:
- The .git directories are removed (freeing more than 50% of the size).
- A new file /master/config/gitversion is created.
- The file public/source.tar is generated.
- The file .bundle/config is patched. Remove before doing
*bundle install*
Routines uses last available version from master branch at github. The
version contains a time stamp and an abbreviated git commit id. If listed
in filename order, like ls does, latest version will be the last one.
version contains a time stamp and an abbreviated git commit id.
Using -c, a specific commit can be used for source build.
*make-dist links* creates links also for all files listed in SOURCES.
*make-dist prepare* creates links also for all files listed in SOURCES.
Typically, this is secondary sources. *make-dist.sh sources*
applies all patches named *.patch in this directory after checking out
source from git.
The spec-files in dist/ are patched by ./make-dist.sh source to reference
The spec-files in dist/ are patched by *./make-dist.sh prepare* to reference
correct versions of diaspora and diaspora-bundle. The diaspora-bundle
is only updated if Gemfile is updated, upgrading diaspora doesn't
always require a new diaspora-bundle. Editing spec files should be done
in this directory, changes in dist/ are lost when doing ./make-dist source.
in this directory, changes in dist/ are lost when doing *./make-dist prepare*.
The topmost comment's version is patched to reflect the complete version
of current specfile by 'make-dist source'. WRite the comment in this
of current specfile by *make-dist source*. Write the comment in this
directory, copy-paste previous version nr. It will be updated.
This has been confirmed to start up and provide basic functionality both using
the thin webserver and apache passenger, and on 32/64 bit systems.
the thin webserver and apache passenger, on 32/64 bit systems and in the
mock build environment.
#### Implementation

View file

@ -1,4 +1,4 @@
# These files will be linked to %_sourcedir by 'make-dist links'
diaspora-setup
diaspora-ws
diaspora-wsd
diaspora.logconf

View file

@ -17,9 +17,9 @@ URL: http://www.joindiaspora.com/
Vendor: joindiaspora.com
Source: %{name}-%{version}-%{git_release}.tar.gz
Prefix: %{_prefix}
BuildRoot: %{_rmpdir}/not-used-in-fedora/
Requires(pre): shadow-utils
BuildRequires: git
Requires: ruby(abi) = 1.8
%description
@ -37,6 +37,8 @@ Source file usede to compile native libraries in diaspora-bundle.
%prep
%setup -q -n %{name}-%{version}-%{git_release}
find . -name .git* -print | xargs rm -rf
pushd bundle/ruby/1.8/
find . -name \*.css -exec chmod 644 {} \;
find . -name \*.js -exec chmod 644 {} \;
@ -82,7 +84,7 @@ pushd bundle/ruby/1.8/
# In repo (2.2.4)
test -d gems/gherkin-*/ext && {
pushd gems/gherkin-*/ext
# Recompile all shared libraries using -O2 optimalization flagcd
# Recompile all shared libraries using -O2 flag
for lexer_dir in */ ; do
pushd $lexer_dir
sed -i 's/ -O0 / -O2 /' extconf.rb
@ -144,6 +146,7 @@ pushd bundle/ruby/1.8/
ln -sf ../../ext/nokogiri/nokogiri.so .
popd
# in repo (rawhide)
pushd gems/json-1.4.6/ext/json/ext/json/ext
rm generator.so
ln -s ../../generator/generator.so
@ -199,8 +202,8 @@ popd
}
mkdir -p $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle/master/vendor
cp -ar bundle $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle/master/vendor
find %{buildroot}/%{_libdir}/diaspora-bundle \
-type d -fprintf dirs '%%%dir "%%p"\n'
find -L %{buildroot}/%{_libdir}/diaspora-bundle -regextype posix-awk \
@ -224,5 +227,5 @@ cat files >> dirs && cp dirs files
%doc COPYRIGHT AUTHORS GNU-AGPL-3.0
%changelog
* Sat Oct 02 2010 Alec Leamas <leamas.alec@gmail.com> 1.1009271539_08b9aa8
* Sat Oct 02 2010 Alec Leamas <leamas.alec@gmail.com> 0.0-1.1009271539_08b9aa8
- Initial attempt to create a spec file

View file

@ -2,13 +2,12 @@
#
# Try to revert to pristine state, deleting all users and
# configuration
#
set -x
service mongod stop
service diaspora-ws stop
service diaspora-wsd stop
rm -rf /var/lib/mongodb/*
cp /usr/share/diaspora/master/config/app_config.yml.example \
/usr/share/diaspora/master/config/app_config.yml
service mongod start

View file

@ -2,20 +2,22 @@
#
# Do what's needed to initiate diaspora.
#
# See http://github.com/diaspora/diaspora/issues/issue/395
#
# Note: This is really sort of prototyping. This should be done in ruby,
# on a web page.
test $UID = "0" || {
echo "You need to be root to do this, giving up"
exit 2
}
cd /usr/share/diaspora/master
services=$( netstat -nl | grep '[^:]:3000[ \t]')
test -n "$services" && {
echo "Warning: something is already using port 3000"
echo " $services"
}
/sbin/service mongod start || :
cd /usr/share/diaspora/master
test -e config/app_config.yml ||
cp config/app_config.yml.example config/app_config.yml
@ -49,4 +51,3 @@ while : ; do
break
}
done

View file

@ -1,14 +1,14 @@
#!/bin/bash
#
# /etc/rc.d/init.d/diaspora-ws
# /etc/rc.d/init.d/diaspora-wsd
#
# Starts the diaspora websocket server
# Starts the diaspora websocket daemon
#
# chkconfig: - 80 80
# description: Diaspora websocket server
# description: Diaspora websocket daemon
### BEGIN INIT INFO
# Provides: diaspora-ws
# Provides: diaspora-wsd
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Should-Start: $remote_fs
@ -23,8 +23,8 @@
# Source function library.
. /etc/init.d/functions
if [ -f /etc/sysconfig/diaspora-ws -a $UID -eq 0 ]; then
. /etc/sysconfig/diaspora-ws
if [ -f /etc/sysconfig/diaspora-wsd -a $UID -eq 0 ]; then
. /etc/sysconfig/diaspora-wsd
fi
# Note: this line is patched by installation scripts.
@ -33,9 +33,9 @@ cd /usr/share/diaspora
RETVAL=0
prog="Diaspora websocket server"
exec="script/websocket_server.rb"
pidfile="/var/run/diaspora-ws"
lockfile="/var/lock/subsys/diaspora-ws"
logfile=/var/log/diaspora-ws.log
pidfile="/var/run/diaspora-wsd"
lockfile="/var/lock/subsys/diaspora-wsd"
logfile=/var/log/diaspora-wsd.log
[ -n "$OPTIONS" ] && OPTIONS=" $OPTIONS"
ruby_cmd="ruby -C $PWD $exec$OPTIONS"

View file

@ -8,6 +8,6 @@
notifempty
missingok
postrotate
( /sbin/service diaspora-ws condrestart ) >/dev/null 2>&1
( /sbin/service diaspora-wsd condrestart ) >/dev/null 2>&1
endscript
}

View file

@ -10,10 +10,11 @@ Group: Applications/Communications
URL: http://www.joindiaspora.com/
Vendor: joindiaspora.com
Source: %{name}-%{version}-%{git_release}.tar.gz
Source1: diaspora-ws
Source1: diaspora-wsd
Source2: diaspora-setup
Source3: diaspora.logconf
BuildArch: noarch
BuildRoot: %{_rmpdir}/not-used-in-fedora/
Requires: mongodb-server
Requires: ruby(abi) = 1.8
@ -32,7 +33,6 @@ find . -perm /u+x -type f -exec \
%build
rm -rf master/vendor/bundle
mkdir master/tmp || :
%install
rm -fr $RPM_BUILD_ROOT
@ -43,7 +43,7 @@ cp master/pkg/fedora/README.md README-Fedora.md
mkdir -p $RPM_BUILD_ROOT/etc/init.d
cp %SOURCE1 $RPM_BUILD_ROOT/etc/init.d
sed -i '/^cd /s|.*|cd %{_datadir}/diaspora/master|' \
$RPM_BUILD_ROOT/etc/init.d/diaspora-ws
$RPM_BUILD_ROOT/etc/init.d/diaspora-wsd
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/logrotate.d
cp %SOURCE3 $RPM_BUILD_ROOT/%{_sysconfdir}/logrotate.d/diaspora
@ -56,39 +56,40 @@ mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/log/diaspora
mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/uploads
mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/tmp
find $RPM_BUILD_ROOT/%{_datadir}/diaspora -type d -fprintf dirs '%%%dir "%%p"\n'
find -L $RPM_BUILD_ROOT/%{_datadir}/diaspora -type f -fprintf files '"%%p"\n'
rm -rf $RPM_BUILD_ROOT/%{_datadir}/diaspora/master/vendor/bundle
rm -rf $RPM_BUILD_ROOT/%{_datadir}/diaspora/master/log
rm -rf $RPM_BUILD_ROOT/%{_datadir}/diaspora/master/public/uploads
rm -rf $RPM_BUILD_ROOT/%{_datadir}/diaspora/master/tmp
find $RPM_BUILD_ROOT/%{_datadir}/diaspora -type d \
-fprintf dirs '%%%dir "%%p"\n'
find -L $RPM_BUILD_ROOT/%{_datadir}/diaspora -type f \
-fprintf files '"%%p"\n'
cat files >> dirs && mv -f dirs files
sed -i -e '\|.*/master/config.ru"$|d' \
-e '\|.*/master/config/environment.rb"$|d' \
-e 's|%{buildroot}||' -e 's|//|/|' -e '/""/d' \
files
%post
rm -f %{_datadir}/diaspora/master/vendor/bundle
rm -f %{_datadir}/diaspora/master/log
rm -f %{_datadir}/diaspora/master/public/uploads
rm -rf %{_datadir}/diaspora/master/tmp
ln -s %{_localstatedir}/log/diaspora \
%{_datadir}/diaspora/master/log || :
ln -s %{_libdir}/diaspora-bundle/master/vendor/bundle \
%{_datadir}/diaspora/master/vendor || :
ln -s %{_localstatedir}/lib/diaspora/uploads \
%{_datadir}/diaspora/master/public/uploads || :
ln -s %{_localstatedir}/lib/diaspora/tmp \
%{_datadir}/diaspora/master/tmp || :
/sbin/chkconfig --add diaspora-ws || :
ln -sf %{_localstatedir}/log/diaspora \
%{_datadir}/diaspora/master/log &>/dev/null || :
ln -sf %{_libdir}/diaspora-bundle/master/vendor/bundle \
.%{_datadir}/diaspora/master/vendor &>/dev/null || :
ln -sf %{_localstatedir}/lib/diaspora/uploads \
%{_datadir}/diaspora/master/public/uploads &>/dev/null || :
ln -sf %{_localstatedir}/lib/diaspora/tmp \
%{_datadir}/diaspora/master/tmp &>/dev/null || :
/sbin/chkconfig --add diaspora-wsd
%preun
if [ $1 -eq 0 ] ; then
service diaspora-ws stop >/dev/null 2>&1 || :
/sbin/chkconfig --del diaspora-ws
service diaspora-wsd stop >/dev/null 2>&1 || :
/sbin/chkconfig --del diaspora-wsd
fi
%clean
[ "$RPM_BUILD_ROOT" != "/" ] && rm -fr $RPM_BUILD_ROOT
rm -fr $RPM_BUILD_ROOT
%files -f files
%defattr(-, root, root, 0755)
@ -99,7 +100,7 @@ fi
%attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/uploads
%attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/tmp
%config(noreplace) %{_sysconfdir}/logrotate.d/diaspora
%{_sysconfdir}/init.d/diaspora-ws
%{_sysconfdir}/init.d/diaspora-wsd
%changelog
* Fri Sep 24 2010 Alec Leamas <leamas.alec@gmail.com> 0.0-1.1009280542_859ec2d

View file

@ -6,6 +6,8 @@
#
GIT_REPO='http://github.com/diaspora/diaspora.git'
VERSION='0.0'
RELEASE='1'
function git_id
#
@ -26,16 +28,17 @@ function git_id
local dir=$(dirname $file_or_dir)
fi
export LANG=C
(
cd $dir
git log -1 --abbrev-commit --date=iso $file |
awk -v nl="$nl" \
' BEGIN { commit = "" }
' BEGIN { commit = ""; d[1] = "" }
/^commit/ { if ( commit == "") commit = $2 }
/^Date:/ { split( $2, d, "-")
/^Date:/ { if (d[1] == "") {
split( $2, d, "-")
split( $3, t, ":")
}
}
END { printf( "%s%s%s%s%s_%s%s",
substr( d[1],3), d[2], d[3],
t[1], t[2],
@ -47,30 +50,31 @@ function git_id
function fix_alphatag()
# Patch version on top comment first id line:
# Usage: fix_alphatag <file> <version> <commit_id>
# Usage: fix_alphatag <file> <version> <commit_id> <release>
# Patches:\
# * Fri Sep 24 2010 name surname <email@com> 1.20100925_faf23207
{
local dist=$(rpm --eval %dist)
awk -v dist="$dist" -v version="$2" -v release="$3" \
awk -v dist="$dist" -v version="$2" -v commit="$3" -v release="$4" \
' BEGIN { done = 0 }
/^[*]/ { if (done)
print
else
{
gsub( "1[.].*", "")
printf( "%s%s-1.%s%s\n",
$0, version, release,dist)
s = sprintf( "-%s.%s%s\n", release, commit, dist)
gsub( "-[0-9][.][^ ]*$", s)
done = 1
# add new gsub for version...
print
}
next
}
{ print }' \
< $1 > $1.tmp && mv -f $1.tmp $1
{ print }' < $1 > $1.tmp && mv -f $1.tmp $1
}
function fix_bundle_deps
# usage: fix_bundle_deps <specfile> <version> <release>
# usage: fix_bundle_deps <specfile> <version> <commit>
# Patches: Requires: diaspora-bundle = 0.0-20101021-aefsf323148
{
awk -v vers="$2-$3" \
@ -84,17 +88,18 @@ function fix_bundle_deps
< $1 > $1.tmp && mv -f $1.tmp $1
}
function patch()
# Patch spec-files with current version-release
# Usage: patch VERSION RELEASE
# Usage: patch <version> <commit> <release>
{
sed -e "/^%define/s|HEAD|$2|" \
-e '/^Version:/s|.*|Version: '$1'|' \
<diaspora.spec >dist/diaspora.spec
fix_alphatag dist/diaspora.spec $1 $2
fix_alphatag dist/diaspora.spec $1 $2 $3
local bundle_id=$(git_id dist/diaspora/Gemfile)
local dist_tag=$(rpm --eval %dist)
fix_bundle_deps dist/diaspora.spec $1 "1.${bundle_id}$dist_tag"
fix_bundle_deps dist/diaspora.spec $1 "$RELEASE.${bundle_id}$dist_tag"
sed -e "/^%define/s|HEAD|$bundle_id|" \
-e '/^Version:/s|.*|Version: '$1'|' \
< diaspora-bundle.spec > dist/diaspora-bundle.spec
@ -102,6 +107,7 @@ function patch()
cp dist/diaspora.spec dist/diaspora/diaspora.spec
}
function checkout()
# Checkout last version of diaspora unless it's already there.
# Usage: checkout [commit id, defaults to HEAD]
@ -109,7 +115,13 @@ function checkout()
{
mkdir dist &>/dev/null || :
(
local last_repo=''
cd dist
test -e '.last-repo' &&
last_repo=$( cat '.last-repo')
test "$last_repo" != $GIT_REPO &&
rm -rf diaspora
test -d diaspora || {
git clone --quiet $GIT_REPO;
(
@ -121,6 +133,8 @@ function checkout()
done &> /dev/null || :
)
}
echo -n "$GIT_REPO" > '.last-repo'
cd diaspora;
git fetch --quiet upstream
git merge --quiet upstream/master
@ -130,13 +144,14 @@ function checkout()
}
function make_dist
function make_src
# Create a distribution tarball
# Usage: make dist [ commit, defaults to HEAD]
# Usage: make src <commit>
{
echo "Using repo: $GIT_REPO"
commit=$(checkout ${1:-'HEAD'})
echo "Creating source tarball for $commit"
patch $VERSION $commit
echo "Commit id: $commit"
RELEASE_DIR="diaspora-$VERSION-$commit"
rm -rf dist/${RELEASE_DIR}
@ -152,17 +167,16 @@ function make_dist
--exclude='source.tar' -X .gitignore *
find $PWD -name .git\* | xargs rm -rf
rm -rf .bundle
/usr/bin/patch -p1 <../../../add-bundle.diff
/usr/bin/patch -p1 -s <../../../add-bundle.diff
)
tar czf ${RELEASE_DIR}.tar.gz ${RELEASE_DIR} && \
rm -rf ${RELEASE_DIR}
cd ..
echo "Source: dist/${RELEASE_DIR}.tar.gz"
echo "Required bundle: $(git_id dist/diaspora/Gemfile)"
echo "Source specfile: dist/diaspora.spec"
echo "Bundle specfile: dist/diaspora-bundle.spec"
}
function make_bundle()
# Create the bundle tarball
# Usage: make_bundle [ commit, defaults to HEAD]
@ -185,14 +199,16 @@ function make_bundle()
"../$bundle_name"
popd > /dev/null
tar czf $bundle_name.tar.gz $bundle_name
rm -rf $bundle_name
cd ..
}
echo
echo "Bundle: dist/$bundle_name.tar.gz"
}
function make_links()
# Usage: make_links [source commit]
function prepare_rpm()
# Usage: prepare_rpm < commit>
{
local dest=$(rpm --eval %_sourcedir)
test -z "$dest" && {
@ -200,10 +216,13 @@ function make_links()
exit 2
}
local src_commit="${1:-$( checkout)}"
echo "Linking sources for $src_commit to $dest"
local commit=$( checkout $1)
echo "Release: $RELEASE.$commit"
echo "Rpm source dir: $dest"
src="dist/diaspora-$VERSION-$src_commit.tar.gz"
patch $VERSION $commit $RELEASE
local src="dist/diaspora-$VERSION-$commit.tar.gz"
test -e $src ||
cat <<- EOF
Warning: $src does not exist
@ -230,50 +249,72 @@ function make_links()
done
( cd $dest; find . -type l -not -readable -exec rm {} \;)
echo "Source specfile: dist/diaspora.spec"
echo "Bundle specfile: dist/diaspora-bundle.spec"
}
function usage()
{
cat <<- EOF
Usage: make-dist [-c commit] <dist|bundle|links>
Usage: make-dist [options] <dist|bundle|prepare>
-c Use a given commit, defaults to last checked in.
dist Build a diaspora application tarball.
Options:
-h Print this message.
-c commit Use a given commit, defaults to last checked in.
-r release Mark with specified release, defaults to 1.
-u uri Git repository URI, defaults to
$GIT_REPO.
source Build a diaspora application tarball.
bundle Build a bundler(1) bundle for diaspora.
links Symlink bundle and source tarballs to rpm source dir.
prepare Symlink bundle and source tarballs to rpm source dir,
create patched rpm spec files.
All results are stored in dist/
EOF
}
test "$1" = "-h" -o $# = 0 && {
usage;
commit='HEAD'
while getopts ":r:c:h" opt
do
case $opt in
u) GIT_REPO="$OPTARG"
;;
c) commit="${OPTARG:0:7}"
;;
r) RELEASE="$OPTARG:"
;;
h) usage
exit 0
}
;;
*) usage
exit 2
;;
esac
done
shift $(($OPTIND - 1))
test "$1" = "-c" && {
test -z "$2" && {
typeset -r GIT_REPO RELEASE
export LANG=C
test $# -gt 1 -o $# -eq 0 && {
usage;
exit 1
exit 2;
}
commit="$2"
shift; shift
}
case $1 in
"bundle") make_bundle $commit
;;
'source') make_dist $commit
'source') make_src $commit
;;
'links') make_links $commit
'prepare') prepare_rpm $commit $release
;;
*) usage
exit 1
;;