From 4aa851c5a8c981c49b2e05f443372dcb405ac02b Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 10 Oct 2010 16:38:01 +0200 Subject: [PATCH 1/8] Ignore stgit files all over the place --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 537c0fae2..67221f5e4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .DS_Store .idea .rvmrc +.stgit* *.swap *.swo *.swp @@ -19,4 +20,4 @@ gpg/*/random_seed public/uploads/* public/source.tar tmp/**/* -capybara-*.html \ No newline at end of file +capybara-*.html From 4d58a3964787e10ad93c808107da81a485d827d8 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 10 Oct 2010 16:38:01 +0200 Subject: [PATCH 2/8] Add a global tmp directory, according to rails spec. The rails specification mandates that there should be a tmp directory, add this. --- tmp/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tmp/.gitkeep diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 000000000..e69de29bb From 0c30f544d9901a88a7fdba8abca1601e61f36afe Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 10 Oct 2010 16:38:01 +0200 Subject: [PATCH 3/8] Fallback to static version data if git unavailable. Uses the file config/gitversion if git is unavailable. This is to support deployment without git (which will be necessary). Installation script will generate the file config/gitversion when app is shipped. --- config/initializers/git_info.rb | 20 +++++++++++++++++++- pkg/fedora/README.md | 3 --- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config/initializers/git_info.rb b/config/initializers/git_info.rb index e7aaffdda..09b540703 100644 --- a/config/initializers/git_info.rb +++ b/config/initializers/git_info.rb @@ -2,4 +2,22 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -GIT_INFO = `git show --name-only` +s = `git show --name-only 2>/dev/null || :` +if (s.nil? or s.empty?) + path = File.expand_path("config/gitversion") + begin + if (File.exists?( path)) + s = '' + f = File.open( path) + f.each_line do |line| + s += line + end + f.close + end + rescue + s = "" + end +end +GIT_INFO = s +# What's the scope of this s? Leave to GC just in case... +s = nil diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index 96c9c47d9..2dade7700 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -65,9 +65,6 @@ The topmost comment's version is patched to reflect the complete version of current specfile by 'make-dist source'. WRite the comment in this directory, copy-paste previous version nr. It will be updated. -rpmlint shows many errors, most of which related to that the server -won't start if the .git directories are not included. Needs investigation. - 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. From 97f7b4d2ad7743428dda03b98ee39b32ad46f44a Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 10 Oct 2010 16:38:01 +0200 Subject: [PATCH 4/8] Symlink tmp-dir to /var/lib,leaving other files to root. Turns the overall installation to being write-protected. --- pkg/fedora/README.md | 26 ++++++++------------- pkg/fedora/diaspora.spec | 7 +++++- pkg/fedora/make-dist.sh | 50 ++++++++++++++++++++-------------------- 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index 2dade7700..f58f6206d 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -68,15 +68,6 @@ 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. -#### Bugs - -As of now, diaspora fails if it not owns all file under /usr/share/diaspora. -I guess this means diaspora writes some stuff somewhere. In the long run, -this should be located and symlinked to /var,leaving the rest of the files -owned by root. FTM, all files in /usr/share/diaspore are owned by -diaspora - - #### Implementation 'make-dist.sh source' script checks out latest version of diaspora into the @@ -89,17 +80,18 @@ patches, the content of diaspora-bundle. Here is also support for running the diaspora websocket service as a system service through /sbin/service and some install scripts. -Diaspora files are stored in /usr/share/diaspora, and owned by diaspora. The +Diaspora files are stored in /usr/share/diaspora, and owned by root. The bundle, containing some C extensions, is architecture-dependent and lives in /usr/lib[64]/diaspora. Log files are in /var/log/diaspora. Symlinks in -/usr/share diaspora makes log and bundle available as expected by diaspora app. -This is more or less as mandated by LSB and Fedora packaging rules. - - find /usr/share/diaspora/ -type l -exec ls -l {} \; | awk '{print $9, $10, $11}' - /usr/share/diaspora/master/public/uploads -> /var/lib/diaspora/uploads - /usr/share/diaspora/master/log -> /var/log/diaspora - /usr/share/diaspora/master/vendor/bundle -> /usr/lib/diaspora-bundle/master/vendor/bundle +/usr/share diaspora makes log, bundle and tmp dir available as expected by +diaspora app. This is more or less as mandated by LSB and Fedora packaging rules. + find . -type l -exec ls -l {} \; | awk '{print $9, $10, $11}' + ./public/uploads -> /var/lib/diaspora/uploads + ./log -> /var/log/diaspora + ./tmp -> /var/lib/diaspora/tmp + ./vendor/bundle -> /usr/lib/diaspora-bundle/master/vendor/bundle + #### Discussion diff --git a/pkg/fedora/diaspora.spec b/pkg/fedora/diaspora.spec index 533f170d3..bb45bac67 100644 --- a/pkg/fedora/diaspora.spec +++ b/pkg/fedora/diaspora.spec @@ -53,6 +53,7 @@ cp -ar master $RPM_BUILD_ROOT/%{_datadir}/diaspora cp -ar master/.gitignore master/.bundle $RPM_BUILD_ROOT/%{_datadir}/diaspora/master cp diaspora-setup $RPM_BUILD_ROOT/%{_datadir}/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' @@ -67,6 +68,7 @@ sed -i -e '\|.*/master/config.ru"$|d' \ 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 || : @@ -74,6 +76,8 @@ 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 || : %preun @@ -86,12 +90,13 @@ fi [ "$RPM_BUILD_ROOT" != "/" ] && rm -fr $RPM_BUILD_ROOT %files -f files -%defattr(-, diaspora, diaspora, 0755) +%defattr(-, root, root, 0755) %doc README.md GNU-AGPL-3.0 %attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/config.ru %attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/config/environment.rb %attr(-, diaspora, diaspora) %{_localstatedir}/log/diaspora %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 diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index d8407ab9d..19e52feb8 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -22,9 +22,9 @@ function git_id file="" dir=$file_or_dir else - file=$(basename $file_or_dir) + file=$(basename $file_or_dir) dir=$(dirname $file_or_dir) - fi + fi export LANG=C ( @@ -59,14 +59,14 @@ function fix_alphatag() else { gsub( "1[.].*", "") - printf( "%s%s-1.%s%s\n", + printf( "%s%s-1.%s%s\n", $0, version, release,dist) done = 1 } next } { print }' \ - < $1 > $1.tmp && mv -f $1.tmp $1 + < $1 > $1.tmp && mv -f $1.tmp $1 } function fix_bundle_deps @@ -81,7 +81,7 @@ function fix_bundle_deps next } { print}' \ - < $1 > $1.tmp && mv -f $1.tmp $1 + < $1 > $1.tmp && mv -f $1.tmp $1 } function patch() @@ -90,7 +90,7 @@ function patch() { sed -e "/^%define/s|HEAD|$2|" \ -e '/^Version:/s|.*|Version: '$1'|' \ - dist/diaspora.spec + dist/diaspora.spec fix_alphatag dist/diaspora.spec $1 $2 bundle_id=$(git_id dist/diaspora/Gemfile) dist_tag=$(rpm --eval %dist) @@ -98,7 +98,7 @@ function patch() sed -e "/^%define/s|HEAD|$bundle_id|" \ -e '/^Version:/s|.*|Version: '$1'|' \ < diaspora-bundle.spec > dist/diaspora-bundle.spec - + cp dist/diaspora.spec dist/diaspora/diaspora.spec } @@ -106,12 +106,12 @@ function checkout() # Checkout last version of diaspora unless it's already there. # Usage: checkout [commit id, defaults to HEAD] # Returns: commit for current branch's HEAD. -{ +{ mkdir dist >/dev/null 2>&1 || : ( - cd dist + cd dist test -d diaspora || { - git clone --quiet $GIT_REPO; + git clone --quiet $GIT_REPO; ( cd diaspora; git remote add upstream \ @@ -121,11 +121,11 @@ function checkout() done ) } - cd diaspora; - git fetch --quiet upstream + cd diaspora; + git fetch --quiet upstream git merge --quiet upstream/master git checkout --quiet ${1:-'HEAD'} - git_id -n + git_id -n ) } @@ -136,10 +136,10 @@ function make_dist { commit=$(checkout ${1:-'HEAD'}) echo "Creating source tarball for $commit" - patch $VERSION $commit + patch $VERSION $commit RELEASE_DIR="diaspora-$VERSION-$commit" - rm -rf dist/${RELEASE_DIR} + rm -rf dist/${RELEASE_DIR} mkdir dist/${RELEASE_DIR} cp diaspora-ws diaspora-setup diaspora.logconf dist/${RELEASE_DIR} cd dist @@ -173,7 +173,7 @@ function make_bundle() test -e "dist/$bundle_name.tar.gz" || { echo "Creating bundle $bundle_name" cd dist - rm -rf $bundle_name + rm -rf $bundle_name mkdir -p $bundle_name/bundle pushd diaspora > /dev/null bundle install --deployment \ @@ -186,7 +186,7 @@ function make_bundle() tar czf $bundle_name.tar.gz $bundle_name cd .. } - echo + echo echo "Bundle: dist/$bundle_name.tar.gz" } @@ -201,7 +201,7 @@ function make_links() echo "Linking sources to $dest" src_commit="${1:-$( checkout)}" - + src="dist/diaspora-$VERSION-$src_commit.tar.gz" ln -sf $PWD/$src $dest @@ -227,7 +227,7 @@ function usage() dist Build a diaspora application tarball. bundle Build a bundler(1) bundle for diaspora. links Symlink bundle and source tarballs to rpm source dir. - + All results are stored in dist/ EOF } @@ -246,10 +246,10 @@ test "$1" = "-c" && { commit="$2" shift; shift } - - + + case $1 in - + "bundle") make_bundle $commit ;; @@ -262,11 +262,11 @@ case $1 in "fix_gemfile") fix_gemfile ;; - + *) usage exit 1 ;; esac - - + + From 0b305a03e977caae6297934262cc9efe42fab393 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 10 Oct 2010 16:38:01 +0200 Subject: [PATCH 5/8] Pack static version info and w tarball, remove Fedora stuff. make-dist now packs config/gitversion info and public/source.tar. with the tarball. All Fedora specific files moved out of the tarball's install area. 'links' command warns for non-existing targets. Minor bugfixes. Overall, at this point the application could be seen as "packageable". The two main problem has been the included git files, and that root could not own the files. These are now resolved. In other words, the overall structure in comptatible with Fedora, and thus also with most other repos like Ubuntu et al. The bundle package is another issue. It's a long way before it can be accepted into Fedora. First step would be to use already packaged gems instead of providing our own copy for each and every gem. --- pkg/fedora/.gitignore | 1 + pkg/fedora/README.md | 32 ++++++++-------- pkg/fedora/SOURCES | 1 + .../{add-bundle.patch => add-bundle.diff} | 0 pkg/fedora/diaspora.spec | 35 ++++++++--------- pkg/fedora/make-dist.sh | 38 ++++++++++++------- 6 files changed, 60 insertions(+), 47 deletions(-) rename pkg/fedora/{add-bundle.patch => add-bundle.diff} (100%) diff --git a/pkg/fedora/.gitignore b/pkg/fedora/.gitignore index 3fab5f9c0..bedbdc760 100644 --- a/pkg/fedora/.gitignore +++ b/pkg/fedora/.gitignore @@ -1,2 +1,3 @@ TODO dist +.stgit* diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index f58f6206d..331580962 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -1,8 +1,8 @@ ## Diaspora RPM tools -Creates RPM packages from diaspora git repository. +Creates RPM packages from diaspora git repository. -An alternative to the capistrano system, providing classic, binary RPM +An alternative to the capistrano system, providing classic, binary RPM packages for deployment on Fedora 13. @@ -12,7 +12,7 @@ packages for deployment on Fedora 13. http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora or http://github.com/diaspora/diaspora/wiki/Installing-on-CentOS-Fedora -Create source tarballs like dist/diaspora-0.0-1010041233_fade4231.tar.gz +Create source tarballs like dist/diaspora-0.0-1010041233_fade4231.tar.gz and dist/diaspora-bundle-0.0-1010041233_fade4231.tar.gz: % ./make-dist.sh source % ./make-dist.sh bundle @@ -28,7 +28,7 @@ Install (as root): rpm -U ~/rmpbuild/rpms/i686/diaspora-bundle-0.0-1.1010042345_4343fade43.fc13.i686 rpm -U ~/rmpbuild/rpms/noarch/diaspora-0.0-1.1010042345_4343fade43.fc13.noarch -Initiate (as root). +Initiate (as root). /usr/share/diaspora/diaspora-setup Start development server: @@ -37,7 +37,7 @@ Start development server: cd /usr/share/diaspora/master ./script/server -See http://github.com/diaspora/diaspora/wiki/Using-apache for +See http://github.com/diaspora/diaspora/wiki/Using-apache for apache/passenger setup. After configuration, start with: /sbin/service diaspora-ws start /sbin/service httpd restart @@ -57,15 +57,15 @@ source from git. The spec-files in dist/ are patched by ./make-dist.sh source to reference correct versions of diaspora and diaspora-bundle. The diaspora-bundle -is only updated if Gemfile is updated, upgrading diaspora doesn't +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. 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 +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. #### Implementation @@ -74,16 +74,16 @@ the thin webserver and apache passenger, and on 32/64 bit systems. dist/diaspora directory. This content is, after some patches, the diaspora package. 'make-dir.sh bundle' makes a 'bundle install --deployment' in the diaspora dir. -The resulting bundle is stored in vendor/bundle. This is, after some more +The resulting bundle is stored in vendor/bundle. This is, after some more patches, the content of diaspora-bundle. -Here is also support for running the diaspora websocket service as a system +Here is also support for running the diaspora websocket service as a system service through /sbin/service and some install scripts. - + Diaspora files are stored in /usr/share/diaspora, and owned by root. The bundle, containing some C extensions, is architecture-dependent and lives in /usr/lib[64]/diaspora. Log files are in /var/log/diaspora. Symlinks in -/usr/share diaspora makes log, bundle and tmp dir available as expected by +/usr/share diaspora makes log, bundle and tmp dir available as expected by diaspora app. This is more or less as mandated by LSB and Fedora packaging rules. find . -type l -exec ls -l {} \; | awk '{print $9, $10, $11}' @@ -91,7 +91,7 @@ diaspora app. This is more or less as mandated by LSB and Fedora packaging rule ./log -> /var/log/diaspora ./tmp -> /var/lib/diaspora/tmp ./vendor/bundle -> /usr/lib/diaspora-bundle/master/vendor/bundle - + #### Discussion @@ -108,11 +108,11 @@ original README.md: not 777. - Splitting in two packages makes sense IMHO. The bundle is not changed that often, - but is quite bug: ~18M without test packages (the default) or ~55M with test - packages. The application is just ~7.5M, and is fast to deploy even with these + but is quite big: ~30M without test packages (the default) or ~55M with test + packages. The application is just ~3M, and is fast to deploy even with these tools (yes, I know, capistrano is much faster...) - Many, roughly 50% of the packages in the bundle are already packaged for Fedora i. e., they could be removed from the bundle and added as dependencies instead. - This is likely to make things more stable in the long run. + This is likely to make things more stable in the long run. diaspora.spec has a list. diff --git a/pkg/fedora/SOURCES b/pkg/fedora/SOURCES index 4f85fc9c7..a6f24b8ce 100644 --- a/pkg/fedora/SOURCES +++ b/pkg/fedora/SOURCES @@ -1,3 +1,4 @@ # These files will be linked to %_sourcedir by 'make-dist links' diaspora-setup diaspora-ws +diaspora.logconf diff --git a/pkg/fedora/add-bundle.patch b/pkg/fedora/add-bundle.diff similarity index 100% rename from pkg/fedora/add-bundle.patch rename to pkg/fedora/add-bundle.diff diff --git a/pkg/fedora/diaspora.spec b/pkg/fedora/diaspora.spec index bb45bac67..97486c3bc 100644 --- a/pkg/fedora/diaspora.spec +++ b/pkg/fedora/diaspora.spec @@ -1,17 +1,18 @@ -%global debug_package %{nil} +%global debug_package %{nil} %define git_release HEAD Summary: A social network server Name: diaspora Version: 0.0.1 Release: 1.%{git_release}%{?dist} -License: AGPLv3 +License: AGPLv3 Group: Applications/Communications URL: http://www.joindiaspora.com/ Vendor: joindiaspora.com Source: %{name}-%{version}-%{git_release}.tar.gz Source1: diaspora-ws Source2: diaspora-setup +Source3: diaspora.logconf BuildArch: noarch Requires: mongodb-server @@ -32,26 +33,26 @@ find . -perm /u+x -type f -exec \ %build rm -rf master/vendor/bundle mkdir master/tmp || : -pushd master - tar cf public/source.tar --exclude='source.tar' -X .gitignore * -popd %install -[ "$RPM_BUILD_ROOT" != "/" ] && rm -fr $RPM_BUILD_ROOT -mkdir -p $RPM_BUILD_ROOT/%{_datadir}/diaspora -cp master/README.md . -mv master/GNU-AGPL-3.0 . +rm -fr $RPM_BUILD_ROOT + +cp master/GNU-AGPL-3.0 master/COPYRIGHT master/README.md master/AUTHORS . +cp master/pkg/fedora/README.md README-Fedora.md -mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/log/diaspora mkdir -p $RPM_BUILD_ROOT/etc/init.d -sed -i '/^cd /s|.*|cd %{_datadir}/diaspora/master|' diaspora-ws -cp diaspora-ws $RPM_BUILD_ROOT/etc/init.d -mkdir -p $RPM_BUILD_ROOT/etc/logrotate.d -cp diaspora.logconf $RPM_BUILD_ROOT/%{_sysconfdir}/logrotate.d/diaspora +cp %SOURCE1 $RPM_BUILD_ROOT/etc/init.d +sed -i '/^cd /s|.*|cd %{_datadir}/diaspora/master|' \ + $RPM_BUILD_ROOT/etc/init.d/diaspora-ws + +mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/logrotate.d +cp %SOURCE3 $RPM_BUILD_ROOT/%{_sysconfdir}/logrotate.d/diaspora + mkdir -p $RPM_BUILD_ROOT/%{_datadir}/diaspora cp -ar master $RPM_BUILD_ROOT/%{_datadir}/diaspora -cp -ar master/.gitignore master/.bundle $RPM_BUILD_ROOT/%{_datadir}/diaspora/master -cp diaspora-setup $RPM_BUILD_ROOT/%{_datadir}/diaspora +cp %SOURCE2 $RPM_BUILD_ROOT/%{_datadir}/diaspora + +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 @@ -91,7 +92,7 @@ fi %files -f files %defattr(-, root, root, 0755) -%doc README.md GNU-AGPL-3.0 +%doc AUTHORS README.md GNU-AGPL-3.0 COPYRIGHT README-Fedora.md %attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/config.ru %attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/config/environment.rb %attr(-, diaspora, diaspora) %{_localstatedir}/log/diaspora diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index 19e52feb8..a5a0f85c6 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -118,7 +118,7 @@ function checkout() git://github.com/diaspora/diaspora.git for p in ../../*.patch; do git apply --whitespace=fix $p > /dev/null - done + done &>/dev/null || : ) } cd diaspora; @@ -141,17 +141,18 @@ function make_dist RELEASE_DIR="diaspora-$VERSION-$commit" rm -rf dist/${RELEASE_DIR} mkdir dist/${RELEASE_DIR} - cp diaspora-ws diaspora-setup diaspora.logconf dist/${RELEASE_DIR} cd dist mkdir ${RELEASE_DIR}/master cp -ar diaspora/* diaspora/.git* ${RELEASE_DIR}/master mv ${RELEASE_DIR}/master/diaspora.spec ${RELEASE_DIR} ( - cd ${RELEASE_DIR}; - find . -name .gitkeep -delete - cd master + cd ${RELEASE_DIR}/master + git show --name-only > config/gitversion + tar cf public/source.tar \ + --exclude='source.tar' -X .gitignore * + find $PWD -name .git\* | xargs rm -rf rm -rf .bundle - git apply ../../../add-bundle.patch + /usr/bin/patch -p1 <../../../add-bundle.diff ) tar czf ${RELEASE_DIR}.tar.gz ${RELEASE_DIR} && \ rm -rf ${RELEASE_DIR} @@ -198,23 +199,36 @@ function make_links() echo "Can't find RPM source directory, giving up." exit 2 } - echo "Linking sources to $dest" src_commit="${1:-$( checkout)}" + echo "Linking sources for $src_commit to $dest" src="dist/diaspora-$VERSION-$src_commit.tar.gz" + test -e $src || + cat <<- EOF + Warning: $src does not exist + (last version not built?) + EOF ln -sf $PWD/$src $dest bundle_commit=$(git_id dist/diaspora/Gemfile) bundle="dist/diaspora-bundle-$VERSION-$bundle_commit.tar.gz" + test -e $bundle || + cat <<- EOF + Warning: $bundle does not exist + (last version not built?) + EOF ln -sf $PWD/$bundle $dest for file in $( grep -v '^#' SOURCES); do - ln -sf $PWD/$file $dest/$file + if [ -e "$file" ]; then + ln -sf $PWD/$file $dest/$file + else + echo "Warning: $file (listed in SOURCES) does not exist" + fi done - cd $dest - find . -type l -not -readable -exec rm {} \; + ( cd $dest; find . -type l -not -readable -exec rm {} \;) } function usage() @@ -259,10 +273,6 @@ case $1 in 'links') make_links $commit ;; - "fix_gemfile") - fix_gemfile - ;; - *) usage exit 1 ;; From 075a39cfcef7cd6726febc714c9ccfea42bcd1ea Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 10 Oct 2010 16:38:01 +0200 Subject: [PATCH 6/8] A little discipline: locals, better redirect etc. --- pkg/fedora/make-dist.sh | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index a5a0f85c6..856c2d664 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -14,16 +14,16 @@ function git_id # Usage: git_id [-n] [file or directory] # { - nl="\n" - file_or_dir="$PWD" + local nl="\n" + local file_or_dir="$PWD" test "$1" = '-n' && { nl=""; shift; } test -n "$1" && file_or_dir="$1" if [ -d $file_or_dir ]; then - file="" - dir=$file_or_dir + local file="" + local dir=$file_or_dir else - file=$(basename $file_or_dir) - dir=$(dirname $file_or_dir) + local file=$(basename $file_or_dir) + local dir=$(dirname $file_or_dir) fi export LANG=C @@ -51,7 +51,7 @@ function fix_alphatag() # Patches:\ # * Fri Sep 24 2010 name surname 1.20100925_faf23207 { - dist=$(rpm --eval %dist) + local dist=$(rpm --eval %dist) awk -v dist="$dist" -v version="$2" -v release="$3" \ ' BEGIN { done = 0 } /^[*]/ { if (done) @@ -92,8 +92,8 @@ function patch() -e '/^Version:/s|.*|Version: '$1'|' \ dist/diaspora.spec fix_alphatag dist/diaspora.spec $1 $2 - bundle_id=$(git_id dist/diaspora/Gemfile) - dist_tag=$(rpm --eval %dist) + 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" sed -e "/^%define/s|HEAD|$bundle_id|" \ -e '/^Version:/s|.*|Version: '$1'|' \ @@ -107,7 +107,7 @@ function checkout() # Usage: checkout [commit id, defaults to HEAD] # Returns: commit for current branch's HEAD. { - mkdir dist >/dev/null 2>&1 || : + mkdir dist &>/dev/null || : ( cd dist test -d diaspora || { @@ -194,13 +194,13 @@ function make_bundle() function make_links() # Usage: make_links [source commit] { - dest=$(rpm --eval %_sourcedir) + local dest=$(rpm --eval %_sourcedir) test -z "$dest" && { echo "Can't find RPM source directory, giving up." exit 2 } - src_commit="${1:-$( checkout)}" + local src_commit="${1:-$( checkout)}" echo "Linking sources for $src_commit to $dest" src="dist/diaspora-$VERSION-$src_commit.tar.gz" @@ -211,8 +211,8 @@ function make_links() EOF ln -sf $PWD/$src $dest - bundle_commit=$(git_id dist/diaspora/Gemfile) - bundle="dist/diaspora-bundle-$VERSION-$bundle_commit.tar.gz" + local bundle_commit=$(git_id dist/diaspora/Gemfile) + local bundle="dist/diaspora-bundle-$VERSION-$bundle_commit.tar.gz" test -e $bundle || cat <<- EOF Warning: $bundle does not exist @@ -220,6 +220,7 @@ function make_links() EOF ln -sf $PWD/$bundle $dest + local file for file in $( grep -v '^#' SOURCES); do if [ -e "$file" ]; then ln -sf $PWD/$file $dest/$file From 1c00fc232e409f07f363526b900237400f63440f Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 10 Oct 2010 16:38:01 +0200 Subject: [PATCH 7/8] 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 --- pkg/fedora/README.md | 66 ++++++-- pkg/fedora/SOURCES | 2 +- pkg/fedora/diaspora-bundle.spec | 31 ++-- pkg/fedora/diaspora-reset | 9 +- pkg/fedora/diaspora-setup | 15 +- pkg/fedora/{diaspora-ws => diaspora-wsd} | 22 +-- pkg/fedora/diaspora.logconf | 2 +- pkg/fedora/diaspora.spec | 51 +++--- pkg/fedora/make-dist.sh | 201 ++++++++++++++--------- 9 files changed, 242 insertions(+), 157 deletions(-) rename pkg/fedora/{diaspora-ws => diaspora-wsd} (81%) diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index 331580962..c0b29d3d2 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -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 diff --git a/pkg/fedora/SOURCES b/pkg/fedora/SOURCES index a6f24b8ce..644de6f6c 100644 --- a/pkg/fedora/SOURCES +++ b/pkg/fedora/SOURCES @@ -1,4 +1,4 @@ # These files will be linked to %_sourcedir by 'make-dist links' diaspora-setup -diaspora-ws +diaspora-wsd diaspora.logconf diff --git a/pkg/fedora/diaspora-bundle.spec b/pkg/fedora/diaspora-bundle.spec index 49d1e714f..6f04cff2f 100644 --- a/pkg/fedora/diaspora-bundle.spec +++ b/pkg/fedora/diaspora-bundle.spec @@ -4,22 +4,22 @@ %define __jar_repack %{nil} # Turn off the brp-python-bytecompile script, *pyc/pyo causes problems -%global __os_install_post %(echo '%{__os_install_post}' | +%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g') Summary: Rubygem bundle for diaspora Name: diaspora-bundle Version: 0.0 Release: 1.%{git_release}%{?dist} -License: AGPLv3 +License: AGPLv3 Group: Applications/Communications 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 {} \; @@ -64,12 +66,12 @@ pushd bundle/ruby/1.8/ sed -i -e '/^#!/d' $f chmod 0644 $f done > /dev/null 2>&1 - find . -perm /u+x -type f -print0 | + find . -perm /u+x -type f -print0 | xargs --null sed -i 's|^#!/usr/local/bin/ruby|#!/usr/bin/ruby|' chmod 755 gems/thin-1.2.7/example/async_chat.ru chmod 755 gems/thin-1.2.7/example/async_tailer.ru - chmod 644 gems/i18n-0.4.1/MIT-LICENSE + chmod 644 gems/i18n-0.4.1/MIT-LICENSE chmod 755 gems/abstract-1.0.0/abstract.gemspec chmod 644 gems/mini_magick-2.1/MIT-LICENSE chmod 755 gems/thin-1.2.7/lib/thin/controllers/service.sh.erb @@ -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 @@ -118,7 +120,7 @@ pushd bundle/ruby/1.8/ ln -s ../cbson/cbson.so . popd - # In repo (0.10.4) + # In repo (0.10.4) pushd gems/ruby-debug-base-0.10.3/lib rm ruby_debug.so ln -s ../ext/ruby_debug.so . @@ -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,18 +202,18 @@ 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 \ - -type f -not -regex '.*[.]c$|.*[.]h$|.*[.]cpp$|.*Makefile$' \ + -type f -not -regex '.*[.]c$|.*[.]h$|.*[.]cpp$|.*Makefile$' \ -fprintf files '"%%p"\n' -find %{buildroot}/%{_libdir}/diaspora-bundle -regextype posix-awk \ - -type f -regex '.*[.]c$|.*[.]h$|.*[.]cpp$|.*Makefile$' \ - -fprintf dev-files '"%%p"\n' +find %{buildroot}/%{_libdir}/diaspora-bundle -regextype posix-awk \ + -type f -regex '.*[.]c$|.*[.]h$|.*[.]cpp$|.*Makefile$' \ + -fprintf dev-files '"%%p"\n' sed -i -e 's|%{buildroot}||' -e 's|//|/|' files dev-files dirs -cat files >> dirs && cp dirs files +cat files >> dirs && cp dirs files %clean [ "$RPM_BUILD_ROOT" != "/" ] && rm -fr $RPM_BUILD_ROOT @@ -224,5 +227,5 @@ cat files >> dirs && cp dirs files %doc COPYRIGHT AUTHORS GNU-AGPL-3.0 %changelog -* Sat Oct 02 2010 Alec Leamas 1.1009271539_08b9aa8 +* Sat Oct 02 2010 Alec Leamas 0.0-1.1009271539_08b9aa8 - Initial attempt to create a spec file diff --git a/pkg/fedora/diaspora-reset b/pkg/fedora/diaspora-reset index 5557a645c..33c49e893 100755 --- a/pkg/fedora/diaspora-reset +++ b/pkg/fedora/diaspora-reset @@ -1,14 +1,13 @@ #!/bin/sh # -# Try to revert to pristine state, deleting all users and -# configuration +# 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 - - diff --git a/pkg/fedora/diaspora-setup b/pkg/fedora/diaspora-setup index 23eb420d5..eaa9192c0 100755 --- a/pkg/fedora/diaspora-setup +++ b/pkg/fedora/diaspora-setup @@ -1,21 +1,23 @@ #!/bin/bash # -# Do what's needed to initiate diaspora. +# 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 - diff --git a/pkg/fedora/diaspora-ws b/pkg/fedora/diaspora-wsd similarity index 81% rename from pkg/fedora/diaspora-ws rename to pkg/fedora/diaspora-wsd index 90dc28f8f..6f0c7593f 100755 --- a/pkg/fedora/diaspora-ws +++ b/pkg/fedora/diaspora-wsd @@ -1,30 +1,30 @@ #!/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 # Should-Stop: $remote_fs -# Default-Start: +# Default-Start: # Default-Stop: 0 1 2 3 4 5 6 # Short-Description: start and stop Diaspora websocket server # Description: The websocket server provides websocket services for -# diaspora. +# diaspora. ### END INIT INFO # 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" diff --git a/pkg/fedora/diaspora.logconf b/pkg/fedora/diaspora.logconf index 767c2d7a2..bc8b078d1 100644 --- a/pkg/fedora/diaspora.logconf +++ b/pkg/fedora/diaspora.logconf @@ -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 } diff --git a/pkg/fedora/diaspora.spec b/pkg/fedora/diaspora.spec index 97486c3bc..2b2da12fd 100644 --- a/pkg/fedora/diaspora.spec +++ b/pkg/fedora/diaspora.spec @@ -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 @@ -27,12 +28,11 @@ open source social network server. %prep %setup -q -n %{name}-%{version}-%{git_release} -find . -perm /u+x -type f -exec \ +find . -perm /u+x -type f -exec \ sed -i 's|^#!/usr/local/bin/ruby|#!/usr/bin/ruby|' {} \; > /dev/null %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 0.0-1.1009280542_859ec2d diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index 856c2d664..3a24635ed 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -6,6 +6,8 @@ # GIT_REPO='http://github.com/diaspora/diaspora.git' VERSION='0.0' +RELEASE='1' + function git_id # @@ -26,51 +28,53 @@ 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 = "" } - /^commit/ { if ( commit == "") commit = $2 } - /^Date:/ { 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], - commit, nl) - }' + awk -v nl="$nl" \ + ' BEGIN { commit = ""; d[1] = "" } + /^commit/ { if ( commit == "") commit = $2 } + /^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], + commit, nl) + }' ) } function fix_alphatag() # Patch version on top comment first id line: -# Usage: fix_alphatag +# Usage: fix_alphatag # Patches:\ # * Fri Sep 24 2010 name surname 1.20100925_faf23207 { local dist=$(rpm --eval %dist) - awk -v dist="$dist" -v version="$2" -v release="$3" \ - ' BEGIN { done = 0 } - /^[*]/ { if (done) - print - else - { - gsub( "1[.].*", "") - printf( "%s%s-1.%s%s\n", - $0, version, release,dist) - done = 1 - } - next - } - { print }' \ - < $1 > $1.tmp && mv -f $1.tmp $1 + awk -v dist="$dist" -v version="$2" -v commit="$3" -v release="$4" \ + ' BEGIN { done = 0 } + /^[*]/ { if (done) + print + else + { + 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 } + function fix_bundle_deps -# usage: fix_bundle_deps +# usage: fix_bundle_deps # Patches: Requires: diaspora-bundle = 0.0-20101021-aefsf323148 { awk -v vers="$2-$3" \ @@ -79,22 +83,23 @@ function fix_bundle_deps else print next - } - { print}' \ + } + { print}' \ < $1 > $1.tmp && mv -f $1.tmp $1 } + function patch() # Patch spec-files with current version-release -# Usage: patch VERSION RELEASE +# Usage: patch { sed -e "/^%define/s|HEAD|$2|" \ -e '/^Version:/s|.*|Version: '$1'|' \ 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,18 +115,26 @@ 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; - ( - cd diaspora; - git remote add upstream \ - git://github.com/diaspora/diaspora.git - for p in ../../*.patch; do - git apply --whitespace=fix $p > /dev/null - done &>/dev/null || : - ) + git clone --quiet $GIT_REPO; + ( + cd diaspora; + git remote add upstream \ + git://github.com/diaspora/diaspora.git + for p in ../../*.patch; do + git apply --whitespace=fix $p > /dev/null + 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 { + 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,24 +167,23 @@ 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" + echo "Source: dist/${RELEASE_DIR}.tar.gz" + echo "Required bundle: $(git_id dist/diaspora/Gemfile)" } + function make_bundle() # Create the bundle tarball # Usage: make_bundle [ commit, defaults to HEAD] # { checkout ${1:-'HEAD'} >/dev/null - bundle_id=$(git_id dist/diaspora/Gemfile) + bundle_id=$( git_id dist/diaspora/Gemfile) bundle_name="diaspora-bundle-$VERSION-$bundle_id" test -e "dist/$bundle_name.tar.gz" || { echo "Creating bundle $bundle_name" @@ -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 @@ -211,7 +230,7 @@ function make_links() EOF ln -sf $PWD/$src $dest - local bundle_commit=$(git_id dist/diaspora/Gemfile) + local bundle_commit=$( git_id dist/diaspora/Gemfile) local bundle="dist/diaspora-bundle-$VERSION-$bundle_commit.tar.gz" test -e $bundle || cat <<- EOF @@ -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] + Usage: make-dist [options] - -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 && { +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)) + +typeset -r GIT_REPO RELEASE +export LANG=C + +test $# -gt 1 -o $# -eq 0 && { usage; - exit 0 + exit 2; } -test "$1" = "-c" && { - test -z "$2" && { - usage; - exit 1 - } - 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 ;; From 30b24a1079b87fee9d0c8f1603f35b010a499808 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Sun, 10 Oct 2010 16:38:02 +0200 Subject: [PATCH 8/8] Use make_relative_symlink scripts to avoid %post ln commands. Patching .bundle/config to use /usr/lib/diaspora-bundle, to avoid inter-package linking from diaspora to diaspora-bundle. This also leaves the content under vendor/bundle untouched. Uses kitchen script to create relative links within diaspora package. --- pkg/fedora/SOURCES | 1 + pkg/fedora/diaspora.spec | 34 +++++++++++++--------- pkg/fedora/make_rel_symlink.py | 52 ++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 14 deletions(-) create mode 100755 pkg/fedora/make_rel_symlink.py diff --git a/pkg/fedora/SOURCES b/pkg/fedora/SOURCES index 644de6f6c..eb326e9f6 100644 --- a/pkg/fedora/SOURCES +++ b/pkg/fedora/SOURCES @@ -2,3 +2,4 @@ diaspora-setup diaspora-wsd diaspora.logconf +make_rel_symlink.py diff --git a/pkg/fedora/diaspora.spec b/pkg/fedora/diaspora.spec index 2b2da12fd..0d07ddb43 100644 --- a/pkg/fedora/diaspora.spec +++ b/pkg/fedora/diaspora.spec @@ -13,6 +13,7 @@ Source: %{name}-%{version}-%{git_release}.tar.gz Source1: diaspora-wsd Source2: diaspora-setup Source3: diaspora.logconf +Source4: make_rel_symlink.py BuildArch: noarch BuildRoot: %{_rmpdir}/not-used-in-fedora/ @@ -37,6 +38,10 @@ rm -rf master/vendor/bundle %install rm -fr $RPM_BUILD_ROOT +sed -i \ + '/BUNDLE_PATH/s|:.*|: %{_libdir}/diaspora-bundle/master/vendor/bundle|' \ + master/.bundle/config + cp master/GNU-AGPL-3.0 master/COPYRIGHT master/README.md master/AUTHORS . cp master/pkg/fedora/README.md README-Fedora.md @@ -56,10 +61,12 @@ 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 -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 +%{SOURCE4} $RPM_BUILD_ROOT/%{_localstatedir}/log/diaspora \ + $RPM_BUILD_ROOT/%{_datadir}/diaspora/master/log +%{SOURCE4} $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/uploads \ + $RPM_BUILD_ROOT/%{_datadir}/diaspora/master/public/uploads +%{SOURCE4} $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/tmp \ + $RPM_BUILD_ROOT/%{_datadir}/diaspora/master/tmp find $RPM_BUILD_ROOT/%{_datadir}/diaspora -type d \ -fprintf dirs '%%%dir "%%p"\n' @@ -71,26 +78,22 @@ sed -i -e '\|.*/master/config.ru"$|d' \ -e 's|%{buildroot}||' -e 's|//|/|' -e '/""/d' \ files -%post -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 || : +%post /sbin/chkconfig --add diaspora-wsd + + %preun if [ $1 -eq 0 ] ; then - service diaspora-wsd stop >/dev/null 2>&1 || : + service diaspora-wsd stop &>/dev/null || : /sbin/chkconfig --del diaspora-wsd fi + %clean rm -fr $RPM_BUILD_ROOT + %files -f files %defattr(-, root, root, 0755) %doc AUTHORS README.md GNU-AGPL-3.0 COPYRIGHT README-Fedora.md @@ -99,6 +102,9 @@ rm -fr $RPM_BUILD_ROOT %attr(-, diaspora, diaspora) %{_localstatedir}/log/diaspora %attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/uploads %attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/tmp +%{_datadir}/diaspora/master/tmp +%{_datadir}/diaspora/master/public/uploads +%{_datadir}/diaspora/master/log %config(noreplace) %{_sysconfdir}/logrotate.d/diaspora %{_sysconfdir}/init.d/diaspora-wsd diff --git a/pkg/fedora/make_rel_symlink.py b/pkg/fedora/make_rel_symlink.py new file mode 100755 index 000000000..5c893056f --- /dev/null +++ b/pkg/fedora/make_rel_symlink.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +import os +import os.path +import sys +import pdb +import shutil + +def relative_ln_s( from_, to_ ): + """ + + This is just so dirty & boring: create a relative symlink, making the + to_ path relative to from_. No errorchecks. Both arguments must be + files, a destination directory doesn't work (I think). An existing + file in to_ will be removed. + + """ + prefix = os.path.commonprefix( [ to_, from_ ] ) + if prefix == '': + prefix = '/' + source = from_.split( prefix )[ 1 ] + dest = to_.split( prefix )[ 1 ] + level = len( dest.split( '/' ) ) - 1 + path = ( '../' * level ) + source + return path + +USAGE = 'Usage: make_rel_symlink [-p] ' + +just_print = False; +if sys.argv[1] == "-p": + just_print = True; + sys.argv = sys.argv[ 1:] + +if len( sys.argv ) != 3: + print USAGE + sys.exit( 1 ) + +if os.path.isdir( sys.argv[2] ): + print "Removing link target dir:" + sys.argv[2] + shutil.rmtree( sys.argv[2]) + +link_path = relative_ln_s( sys.argv[1], sys.argv[2] ) +if just_print: + print link_path +else: + os.chdir( os.path.dirname( sys.argv[2])) + target = os.path.basename( sys.argv[2]) + if os.path.exists( target ): + os.unlink( target) + os.symlink( link_path, target) + +