dc6b8af32b8fa854779d7a7e327cecc81a3aca1d
[rvm-ruby.git] / rpm / rvm-ruby.spec
1 %global rvm_dir /usr/lib/rvm
2 %global rvm_group rvm
3
4 # RVM can not be sourced with default /bin/sh
5 %define _buildshell /bin/bash
6
7 Name: rvm-ruby
8 Summary: Ruby Version Manager
9 Version: 3  # Version will be appended the commit date
10 Release: 1.20.9
11 License: ASL 2.0
12 URL: http://rvm.beginrescueend.com/
13 Group: Applications/System
14 #Source: %{name}-%{version}.tar
15 #BuildArch: noarch
16 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
17
18 BuildRequires: bash curl git
19 BuildRequires: gcc-c++ patch chrpath readline readline-devel zlib-devel libyaml-devel libffi-devel openssl-devel
20 BuildRequires: sed grep tar gzip bzip2 make file ruby
21
22 Requires(pre): shadow-utils
23 # For rvm
24 Requires: bash curl git
25 # Basics for building ruby 1.8/1.9
26 #Requires: gcc-c++ patch readline readline-devel zlib-devel libyaml-devel libffi-devel openssl-devel
27 # Used by the scripts
28 Requires: sed grep tar gzip bzip2 make file
29
30 %description
31 RVM is the Ruby Version Manager (rvm). It manages Ruby interpreter environments
32 and switching between them.
33
34 This package is meant for use by multiple users maintaining a shared copy of
35 RVM. Users added to the '%{rvm_group}' group will be able to modify all aspects
36 of RVM. These users will also have their default umask modified ("g+w") to allow
37 group write permission (usually resulting in a umask of "0002") in order to
38 ensure correct permissions for the shared RVM content.
39
40 RVM is activated for all logins by default. To disable remove
41 %{_sysconfdir}/profile.d/rvm.sh and source rvm from each users shell.
42
43 %build
44
45 %install
46 rm -rf %{buildroot}
47
48 # Clean the env
49 for i in `env | grep ^rvm_ | cut -d"=" -f1`; do
50   unset $i;
51 done
52
53 (
54 # Install everything into one directory
55 export rvm_ignore_rvmrc=1 \
56   rvm_user_install_flag=0 \
57   rvm_path="%{buildroot}%{rvm_dir}" \
58   rvm_man_path="%{buildroot}%{_mandir}" \
59   HOME=%{buildroot}
60 \curl -L https://get.rvm.io | bash -s stable --version %{release}
61   #./install
62 )
63
64 # So members of the rvm group can write to it
65 find %{buildroot}%{rvm_dir} -exec chmod ug+w {} \;
66 find %{buildroot}%{rvm_dir} -type d -exec chmod g+s {} \;
67
68 mkdir -p %{buildroot}%{_sysconfdir}
69
70 # We use selfcontained so binaries end up in rvm/bin
71 cat > %{buildroot}%{_sysconfdir}/rvmrc <<END_OF_RVMRC
72 # Setup default configuration for rvm.
73 # If an rvm install exists in the home directory, don't load this.'
74 if [[ ! -s "\${HOME}/.rvm/scripts/rvm" ]]; then
75
76   # Only users in the rvm group need the umask modification
77   for i in \$(id -G -n); do
78     if [ \$i = "rvm" ]; then
79       umask g+w
80       break
81     fi
82   done
83
84   export rvm_user_install_flag=1
85   export rvm_path="%{rvm_dir}"
86 fi
87 END_OF_RVMRC
88
89 mkdir -p %{buildroot}%{_sysconfdir}/profile.d
90
91 cat > %{buildroot}%{_sysconfdir}/profile.d/rvm.sh <<END_OF_RVMSH
92 # rvm loading hook
93 #
94 if [ -s "\${HOME}/.rvm/scripts/rvm" ]; then
95   source "\${HOME}/.rvm/scripts/rvm"
96 elif [ -s "%{rvm_dir}/scripts/rvm" ]; then
97   source "%{rvm_dir}/scripts/rvm"
98 fi
99 END_OF_RVMSH
100
101 chmod 755 %{buildroot}%{_sysconfdir}/profile.d/rvm.sh
102
103 #mv %{buildroot}%{_bindir}/rake %{buildroot}%{_bindir}/rvm-rake
104
105
106 # At this point, install of RVM is finished
107 # Now install some rubies
108
109 # Run this in a subshell so the rvm loading does not infect our current shell.
110 (
111 export rvm_ignore_rvmrc=1
112 export rvm_user_install_flag=0
113 export rvm_path="%{buildroot}%{rvm_dir}"
114 export rvm_man_path="%{buildroot}%{_mandir}"
115 source ${rvm_path}/scripts/rvm
116 gemi='gem install --no-ri --no-rdoc'
117
118 #touch $rvm_path/RELEASE
119 ruby_tag=ruby-1.9.3-p286
120 rvm install $ruby_tag
121 rvm use $ruby_tag
122 #$gemi bundler
123
124 #ruby_tag=ruby-1.8.7-p352
125 #rvm install $ruby_tag
126 #rvm use $ruby_tag
127 )
128
129 export br=%{buildroot}
130
131 # Remove sources
132 rm -rf $br/usr/lib/rvm/src
133 # Remove logs
134 rm -rf $br/usr/lib/rvm/log/*
135
136 # Strip binaries
137 #find $br -type f -print0 |xargs -0 file --no-dereference --no-pad |grep 'not stripped' |cut -f1 -d: |xargs -r strip
138
139 # Strip and Fix bad paths in generated files
140 # That is not optimized, but that is not supposed to be done often
141 for f in `find $br -type f -print0 |xargs -0 file --no-dereference --no-pad |grep ': ELF' |cut -f1 -d:`; do
142   strip $f
143   grep "$br" $f || continue
144   line=`chrpath -l $f` || continue
145   echo $line |grep "$br" || continue
146   chrpath -r `echo $line |cut -f2 -d= |sed "s,$br,,"` $f
147 done
148
149 # Replace bad paths in text files
150 find $br -type f \( -name \*.log -o -name \*.la \) -print0 |xargs -0 -r sed -i "s,$br,,g"
151 find $br -type f -print0 |xargs -0 file --no-dereference --no-pad |grep ': .* text' |cut -f1 -d: |xargs -r sed -i "s,$br,,g"
152
153 # some Ruby code to replace library paths in binary files
154 # should work with Ruby 1.9 and 1.8
155 ! read -d '' fixpath <<"EOF"
156 if String.method_defined?(:encode)
157   $_.encode!("UTF-8", "UTF-8", :invalid => :replace)
158 end
159 $_.gsub!(/#{ENV["br"]}(.*?)\0/) do |s|
160   $1 + ( "\0" * ENV["br"].size ) + "\0"
161 end
162 EOF
163
164 # Strip object files in ar archives from bad path strings
165 for f in `find $br -type f -name \*.a`; do
166   td=`mktemp -d`
167   pushd $td
168   ar x $f
169
170   for g in `find . -type f -print0 |xargs -0 file --no-dereference --no-pad |grep ': ELF' |cut -f1 -d:`; do
171     strip $g
172     grep "$br" $g || continue
173
174     # Replace the bad path with the good one, padded by nulls
175     ruby -p -i -e "$fixpath" $g
176   done
177
178   ar r $f *
179   popd
180   rm -rf $td
181 done
182
183 # Replace paths in libraries strings
184 for f in `find $br/usr/lib/rvm/rubies -type f -print0 |xargs -0 file --no-dereference --no-pad |grep ': ELF' |cut -f1 -d:`; do
185   grep "$br" $f || continue
186
187   # Replace the bad path with the good one, padded by nulls
188   ruby -p -i -e "$fixpath" $f
189 done
190
191 # Fix symlinks with bad path
192 for f in `find $br -type l |grep "$br"`; do
193     ln -sfn `readlink -f $f |sed "s,$br,,"` $f
194 done
195
196 find $br -maxdepth 1 -name '.*' -exec rm -rf {} \;
197 rm $br/usr/share/man/man1/rvm.1.gz
198
199 %clean
200 rm -rf %{buildroot}
201
202 %pre
203 getent group %{rvm_group} >/dev/null || groupadd -r %{rvm_group}
204 exit 0
205
206 %files
207 %defattr(-,root,root)
208 %config(noreplace) /etc/rvmrc
209 %config(noreplace) /etc/profile.d/rvm.sh
210 %attr(-,root,%{rvm_group}) %{rvm_dir}
211 %{_mandir}/man1/*
212
213 %changelog
214 * Fri Mar 30 2012 Alexandre Fouche - 3.xxx
215 Add some rubies and gems to compile:
216 - 1.9.2-p290 + bundler, bluepill, whenever
217 - 1.9.3-p0 + bundler, bluepill, whenever
218
219 * Thu Mar 29 2012 Alexandre Fouche - 2.xxx
220 - Adapt <https://github.com/mdkent/rvm-rpm/blob/master/SPECS/rvm-ruby.spec> to make it work from RVM git source directly
221 - Strip binaries, libraries, ...
222
223 * Thu Mar 29 2012 Alexandre Fouche - 1.xxx
224 - Adapt <https://github.com/mdkent/rvm-rpm/blob/master/SPECS/rvm-ruby.spec> to make it work from RVM git source directly
225
226 * Tue Dec 13 2011 Matthew Kent <mkent@magoazul.com> - 1.10.0-2
227 - New upstream release
228 - Drop rvm_prefix
229 - Rename rvm_user_install to rvm_user_install_flag
230 - Rename rake wrapper to rvm-rake
231 - Add file dependency
232
233 * Thu Aug 4 2011 Matthew Kent <mkent@magoazul.com> - 1.6.32-1
234 - New upstream release
235
236 * Tue Apr 19 2011 Matthew Kent <mkent@magoazul.com> - 1.6.3-1
237 - Initial package based off Gentoo work