From df8bcdf66393e0706d8b0a327d32aa2de82d710e Mon Sep 17 00:00:00 2001
From: Alec Leamas <leamas.alec@gmail.com>
Date: Thu, 21 Oct 2010 05:35:02 +0200
Subject: [PATCH] Establish proper workflow w bundle package + bundle install.

make-dist now creates the bundle using 'bundle package', the
rpm files for Fedora ande install scripts for ubuntu installs
using 'bundle install'. This is the way bundler is intended to
work.
---
 pkg/fedora/diaspora-bundle.spec    | 126 ++++++++++++++---------------
 pkg/fedora/diaspora-setup          |   3 +-
 pkg/fedora/make-dist.sh            |  59 +++++++++++---
 pkg/ubuntu/diaspora-bundle-install |  11 ++-
 pkg/ubuntu/diaspora-install        |   4 +-
 pkg/ubuntu/diaspora-setup          |   1 -
 6 files changed, 123 insertions(+), 81 deletions(-)

diff --git a/pkg/fedora/diaspora-bundle.spec b/pkg/fedora/diaspora-bundle.spec
index a4ab0e6eff..dee189a260 100644
--- a/pkg/fedora/diaspora-bundle.spec
+++ b/pkg/fedora/diaspora-bundle.spec
@@ -1,6 +1,6 @@
 %define         git_release     HEAD
 
-# Turn off java repack, this is in in /usr/lib[64] anyway
+# Turn off java repack, this is in /usr/lib[64] anyway
 %define         __jar_repack    %{nil}
 
 # Turn off the brp-python-bytecompile script, *pyc/pyo causes problems
@@ -11,20 +11,20 @@ Summary:        Rubygem bundle for diaspora
 Name:           diaspora-bundle
 Version:        0.0
 Release:        1.%{git_release}%{?dist}
-License:        AGPLv3
+License:        Ruby
 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/
+BuildRoot:      %{_tmpdir}/not-used-since-F13/
 
 Requires(pre):  shadow-utils
 Requires:       ruby(abi) = 1.8
 
 %description
 The ruby apps bundled with diaspora, as provided by
-bundle install --deployment and patched for Fedora use.
+bundle install --package and patched for Fedora use.
 
 %package devel
 Summary:   Development files (i. e., sources) for diaspora-bundle
@@ -37,53 +37,15 @@ 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 {} \;
-    find . -name \*.treetop -exec  chmod 644 {} \;
-    find . -name \*.rdoc -exec  chmod 644 {} \;
-    chmod 644 gems/term-ansicolor-1.0.5/CHANGES || :
-    chmod 755 gems/cucumber-rails-0.3.2/templates/install/script/cucumber || :
-    chmod 755 gems/ruby-debug-base-0.10.3/Rakefile || :
-    chmod 644 gems/cucumber-rails-0.3.2/History.txt || :
-    chmod 644 gems/cucumber-rails-0.3.2/templates/install/step_definitions/capybara_steps.rb.erb || :
-    chmod 644 gems/rack-1.2.1/test/cgi/lighttpd.conf || :
-    chmod 644 gems/term-ansicolor-1.0.5/VERSION || :
-    chmod 644 gems/mini_magick-2.1/Rakefile || :
-    chmod 755 gems/linecache-0.43/Rakefile || :
-    chmod 644 gems/ffi-0.6.3/ext/ffi_c/libffi/ltmain.sh || :
-    chmod 644 gems/term-ansicolor-1.0.5/README || :
-    chmod 755 gems/mini_magick-2.1/test/not_an_image.php || :
-    chmod 755 gems/rake-0.8.7/test/data/statusreturn/Rakefile || :
-    chmod 755 gems/ruby-debug-0.10.3/Rakefile || :
-    chmod 644 gems/gherkin-2.2.4/tasks/compile.rake || :
-    chmod 755 gems/rake-0.8.7/test/data/file_creation_task/Rakefile  || :
-    chmod 644 gems/term-ansicolor-1.0.5/Rakefile || :
-    chmod 755 gems/mime-types-1.16/Rakefile || :
-    for f in $(find . -name \*.rb); do
-      sed -i -e '/^#!/d' $f
-      chmod 0644 $f
-    done > /dev/null 2>&1
-    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 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
-    chmod 644 gems/treetop-1.4.8/spec/compiler/test_grammar.tt
-popd
-
 %build
+mkdir -p vendor/cache
+mv *.gem vendor/cache
+bundle install --local --deployment --without ri rdoc
 
-pushd bundle/ruby/1.8/
+pushd vendor/bundle/ruby/1.8/gems
     # In repo (2.2.4)
-    test -d gems/gherkin-*/ext && {
-    pushd gems/gherkin-*/ext
+    test -d gherkin-*/ext && {
+    pushd gherkin-*/ext
     # Recompile all shared libraries using -O2 flag
     for lexer_dir in */ ; do
         pushd $lexer_dir
@@ -102,32 +64,32 @@ pushd bundle/ruby/1.8/
     popd
     }
 
-    test -d gems/ffi-0.6.3/lib && {
-    pushd  gems/ffi-0.6.3/lib
+    test -d ffi-0.6.3/lib && {
+    pushd  ffi-0.6.3/lib
         rm ffi_c.so
         ln -s ../ext/ffi_c/ffi_c.so .
     popd
     }
 
     # In repo as 1.2.5, rawhide 1.2.7
-    pushd  gems/thin-1.2.7/lib
+    pushd  thin-1.2.7/lib
         rm thin_parser.so
         ln -s ../ext/thin_parser/thin_parser.so .
     popd
 
-    pushd gems/bson_ext-1.1/ext/bson_ext
+    pushd bson_ext-1.1/ext/bson_ext
         rm cbson.so
         ln -s ../cbson/cbson.so .
     popd
 
     # In repo (0.10.4)
-    pushd gems/ruby-debug-base-0.10.3/lib
+    pushd ruby-debug-base-0.10.3/lib
         rm ruby_debug.so
         ln -s ../ext/ruby_debug.so .
     popd
 
     #in repo
-    pushd gems/eventmachine-0.12.10/lib
+    pushd eventmachine-0.12.10/lib
        rm rubyeventmachine.so
        rm fastfilereaderext.so
        ln -s ../ext/rubyeventmachine.so .
@@ -135,19 +97,19 @@ pushd bundle/ruby/1.8/
     popd
 
     # In repo
-    pushd gems/bcrypt-ruby-2.1.2/lib
+    pushd bcrypt-ruby-2.1.2/lib
         rm bcrypt_ext.so
         ln -s ../ext/mri/bcrypt_ext.so .
     popd
 
     # in repo
-    pushd gems/nokogiri-1.4.3.1/lib/nokogiri
+    pushd nokogiri-1.4.3.1/lib/nokogiri
         rm nokogiri.so
         ln -sf ../../ext/nokogiri/nokogiri.so .
     popd
 
     # in repo (rawhide)
-    pushd gems/json-1.4.6/ext/json/ext/json/ext
+    pushd json-1.4.6/ext/json/ext/json/ext
         rm generator.so
         ln -s ../../generator/generator.so
         rm parser.so
@@ -155,19 +117,55 @@ pushd bundle/ruby/1.8/
     popd
 
     #in repo
-    pushd gems/linecache-0.43/lib/
+    pushd linecache-0.43/lib/
         rm trace_nums.so
         ln -s ../ext/trace_nums.so .
     popd
 
-    pushd bundler/gems/em-http-request-*/lib
+    pushd ../bundler/gems/em-http-request*/lib
         rm em_buffer.so
         ln -s ../ext/buffer/em_buffer.so .
         rm http11_client.so
         ln -s ../ext/http11_client/http11_client.so .
     popd
-popd
 
+    find . -name \*.css -print       | xargs chmod 644
+    find . -name \*.js  -print       | xargs chmod 644
+    find . -name \*.treetop -print   | xargs chmod 644
+    find . -name \*.rdoc -print      | xargs chmod 644
+
+    for f in $(find . -name \*.rb); do
+      sed -i -e '/^#!/d' $f
+      chmod 0644 $f
+    done &> /dev/null
+    find .  -perm /u+x  -type f -print0 |
+        xargs --null sed -i 's|^#!/usr/local/bin/ruby|#!/usr/bin/ruby|'
+
+    chmod 755 abstract-1.0.0/abstract.gemspec  || :
+    chmod 755 cucumber-rails-0.3.2/templates/install/script/cucumber || :
+    chmod 644 cucumber-rails-0.3.2/History.txt || :
+    chmod 644 cucumber-rails-0.3.2/templates/install/step_definitions/capybara_steps.rb.erb || :
+    chmod 644 ffi-0.6.3/ext/ffi_c/libffi/ltmain.sh || :
+    chmod 644 gherkin-2.2.4/tasks/compile.rake || :
+    chmod 644 i18n-0.4.1/MIT-LICENSE
+    chmod 755 linecache-0.43/Rakefile || :
+    chmod 755 mime-types-1.16/Rakefile || :
+    chmod 755 mini_magick-2.1/test/not_an_image.php || :
+    chmod 644 mini_magick-2.1/Rakefile || :
+    chmod 644 mini_magick-2.1/MIT-LICENSE || :
+    chmod 644 rack-1.2.1/test/cgi/lighttpd.conf || :
+    chmod 755 rake-0.8.7/test/data/file_creation_task/Rakefile  || :
+    chmod 755 rake-0.8.7/test/data/statusreturn/Rakefile || :
+    chmod 755 ruby-debug-0.10.3/Rakefile || :
+    chmod 755 ruby-debug-base-0.10.3/Rakefile || :
+    for file in CHANGES VERSION README Rakefile; do
+        chmod 644 term-ansicolor-1.0.5/$file || :
+    done
+    chmod 755 thin-1.2.7/lib/thin/controllers/service.sh.erb
+    chmod 755 thin-1.2.7/example/async_chat.ru  || :
+    chmod 755 thin-1.2.7/example/async_tailer.ru  || :
+    chmod 644 treetop-1.4.8/spec/compiler/test_grammar.tt  || :
+popd
 
 
 %pre
@@ -186,8 +184,8 @@ find . -name .git | xargs rm -rf
 find . -name .gitignore -delete
 find . -name \*.o -delete  || :
 
-test -d bundle/ruby/1.8/gems/selenium-webdriver-0.0.28 && {
-pushd bundle/ruby/1.8/gems/selenium-webdriver-0.0.28/lib/selenium/webdriver/
+test -d vendor/bundle/ruby/1.8//gems/selenium-webdriver-0.0.* && {
+pushd  vendor/bundle//ruby/1.8/gems/selenium-webdriver-0.0.*/lib/selenium/webdriver/
 %ifarch  %ix86 x86_64
 %ifarch %ix86
    rm -rf firefox/native/linux/amd64
@@ -201,8 +199,8 @@ pushd bundle/ruby/1.8/gems/selenium-webdriver-0.0.28/lib/selenium/webdriver/
 popd
 }
 
-mkdir -p $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle/
-cp -ar  bundle $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle/
+mkdir -p $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle
+cp -ar  vendor/bundle  $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle
 
 find  %{buildroot}/%{_libdir}/diaspora-bundle  \
     -type d  -fprintf dirs '%%%dir "%%p"\n'
diff --git a/pkg/fedora/diaspora-setup b/pkg/fedora/diaspora-setup
index 0214e419aa..b3e2eac694 100755
--- a/pkg/fedora/diaspora-setup
+++ b/pkg/fedora/diaspora-setup
@@ -31,12 +31,11 @@ else
     cat <<- EOF
 
 	Database config failed. You might want to remove all db files with
-	'rm -rf /var/lib/mongodb/*' and/or resetting the config file by
+	'rm -rf /var/lib/mongodb/*' and/or reset the config file by
 	'cp config/app_config.yml.example config/app_config.yml' before
 	making a new try. Also, make sure the mongodb server is running
 	e. g., using '/sbin/service mongod status'.
 	EOF
-    exit 1
 fi
 
 chown -R diaspora /var/log/diaspora
diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh
index ce450a3a71..3da2ab6e39 100755
--- a/pkg/fedora/make-dist.sh
+++ b/pkg/fedora/make-dist.sh
@@ -175,6 +175,43 @@ function make_src
     echo "Required bundle:     $(git_id dist/diaspora/Gemfile)"
 }
 
+function get_git_repos()
+{
+    grep -A 2 GIT $1 |
+        awk   ' /remote:/   { repo = $2 }
+                /revision:/ { printf "%s=%s\n",repo, $2}'
+}
+
+
+function package_git_gems()
+{
+    gemfile="$1"
+    dest="$2"
+
+    rm -rf git-tmp
+    mkdir git-tmp
+    cd git-tmp
+        for repo in $( get_git_repos $1); do
+            url=${repo%%=*}
+            rev=${repo##*=}
+
+            name=${url##*/}
+            name="${name%.git}"
+
+            rm -rf "$name"
+            git clone "$url" "$name"
+            cd $name
+                git reset --hard  $rev
+                sed -i '/s.date/s/Date.today/"2010-09-25"/' *.gemspec
+                gem build *.gemspec
+                cp *.gem $dest
+                echo "Built GIT gem $name (*.gem)"
+                echo "Where: $dest"
+            cd ..
+        done
+    cd ..
+}
+
 
 function make_bundle()
 # Create the bundle tarball
@@ -188,26 +225,28 @@ function make_bundle()
         echo "Creating bundle $bundle_name"
         cd dist
             rm -rf $bundle_name
-            mkdir -p $bundle_name/bundle
-            pushd diaspora > /dev/null
+            cd diaspora
                 if [ "$BUNDLE_FIX" = 'yes' ]; then
                     rm -f Gemfile.lock
                     rm -rf .bundle
                     bundle update
                 fi
-                bundle install --deployment                      \
-                               --path="../$bundle_name/bundle"   \
-                               --without=test rdoc
-
+                bundle install --deployment
+                bundle package
+                package_git_gems "$PWD/Gemfile.lock" "$PWD/vendor/cache"
                 cp -ar AUTHORS Gemfile Gemfile.lock GNU-AGPL-3.0 COPYRIGHT \
-                       "../$bundle_name"
-            popd > /dev/null
-            tar czf $bundle_name.tar.gz $bundle_name
-            rm -rf  $bundle_name
+                       vendor/cache
+                cd vendor
+                    mv cache $bundle_name
+                    tar czf ../../$bundle_name.tar.gz $bundle_name
+                    mv $bundle_name cache
+                cd ..
+            cd ..
         cd ..
     }
     echo
     echo "Bundle: dist/$bundle_name.tar.gz"
+    echo "Current dir:$PWD"
 }
 
 
diff --git a/pkg/ubuntu/diaspora-bundle-install b/pkg/ubuntu/diaspora-bundle-install
index caf95d4e8b..88924b9309 100755
--- a/pkg/ubuntu/diaspora-bundle-install
+++ b/pkg/ubuntu/diaspora-bundle-install
@@ -16,11 +16,18 @@ test -r "$1" || {
 }
 
 rm -rf /usr/lib/diaspora-bundle
-tar xf $1 -C /usr/lib
+tar xzf $1 -C /usr/lib
 
 cd /usr/lib
 mv $(basename $1 .tar.gz) diaspora-bundle
+
 mkdir -p /usr/share/doc/diaspora-bundle || :
 cd /usr/lib/diaspora-bundle
+cp AUTHORS GNU-AGPL-3.0 COPYRIGHT Gemfile Gemfile.lock \
+     /usr/share/doc/diaspora-bundle
+
+mkdir -p vendor/cache
+mv *.gem vendor/cache
+
+bundle install --local --deployment --without ri rdoc
 
-cp  AUTHORS GNU-AGPL-3.0 COPYRIGHT /usr/share/doc/diaspora-bundle
diff --git a/pkg/ubuntu/diaspora-install b/pkg/ubuntu/diaspora-install
index 7f7fd8c232..4679c9f2b0 100755
--- a/pkg/ubuntu/diaspora-install
+++ b/pkg/ubuntu/diaspora-install
@@ -25,7 +25,7 @@ cd /usr/share/diaspora
 find . -perm /u+x -type f -exec \
     sed -i 's|^#!/usr/local/bin/ruby|#!/usr/bin/ruby|' {} \; > /dev/null
 rm -rf master/vendor/bundle  master/public/uploads master/tmp master/log
-sed -i '/BUNDLE_PATH/s|:.*|: /usr/lib/diaspora-bundle/bundle|' \
+sed -i '/BUNDLE_PATH/s|:.*|: /usr/lib/diaspora-bundle/vendor/bundle|' \
          master/.bundle/config
 
 cp master/GNU-AGPL-3.0 master/COPYRIGHT master/README.md master/AUTHORS .
@@ -48,7 +48,7 @@ cp master/config/app_config.yml.example /etc/diaspora/app_config.yml
 ln -sf /etc/diaspora/app_config.yml master/config/app_config.yml
 ln -sf /var/lib/diaspora/uploads master/public/
 ln -sf /var/lib/diaspora/tmp master
-ln -sf /usr/lib/diaspora-bundle/bundle master/vendor
+ln -sf /usr/lib/diaspora-bundle/vendor/bundle master/vendor
 
 rm -rf /usr/share/doc/diaspora
 mkdir -p /usr/share/doc/diaspora
diff --git a/pkg/ubuntu/diaspora-setup b/pkg/ubuntu/diaspora-setup
index 32293a2d27..5796645970 100755
--- a/pkg/ubuntu/diaspora-setup
+++ b/pkg/ubuntu/diaspora-setup
@@ -40,7 +40,6 @@ else
 	Also, make sure the mongodb server is running e. g., using
 	'service mongod status'.
 	EOF
-    exit 1
 fi
 
 chown -R diaspora /var/log/diaspora
-- 
GitLab