First stab at using rvm-installer to download the source
[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
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
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 %prep
44 %setup -q
45
46 %build
47
48 %install
49 rm -rf %{buildroot}
50
51 # Clean the env
52 for i in `env | grep ^rvm_ | cut -d"=" -f1`; do
53   unset $i;
54 done
55
56 # Install everything into one directory
57 export rvm_ignore_rvmrc=1 \
58   rvm_user_install_flag=0 \
59   rvm_path="%{buildroot}%{rvm_dir}" \
60   rvm_bin_path="%{buildroot}%{_bindir}" \
61   rvm_man_path="%{buildroot}%{_mandir}" \
62   HOME=%{buildroot}
63
64 \curl -L https://get.rvm.io | bash -s stable --version %{release}
65   #./install
66
67 # So members of the rvm group can write to it
68 find %{buildroot}%{rvm_dir} -exec chmod ug+w {} \;
69 find %{buildroot}%{rvm_dir} -type d -exec chmod g+s {} \;
70
71 mkdir -p %{buildroot}%{_sysconfdir}
72
73 # We use selfcontained so binaries end up in rvm/bin
74 cat > %{buildroot}%{_sysconfdir}/rvmrc <<END_OF_RVMRC
75 # Setup default configuration for rvm.
76 # If an rvm install exists in the home directory, don't load this.'
77 if [[ ! -s "\${HOME}/.rvm/scripts/rvm" ]]; then
78
79   # Only users in the rvm group need the umask modification
80   for i in \$(id -G -n); do
81     if [ \$i = "rvm" ]; then
82       umask g+w
83       break
84     fi
85   done
86
87   export rvm_user_install_flag=1
88   export rvm_path="%{rvm_dir}"
89 fi
90 END_OF_RVMRC
91
92 mkdir -p %{buildroot}%{_sysconfdir}/profile.d
93
94 cat > %{buildroot}%{_sysconfdir}/profile.d/rvm.sh <<END_OF_RVMSH
95 # rvm loading hook
96 #
97 if [ -s "\${HOME}/.rvm/scripts/rvm" ]; then
98   source "\${HOME}/.rvm/scripts/rvm"
99 elif [ -s "%{rvm_dir}/scripts/rvm" ]; then
100   source "%{rvm_dir}/scripts/rvm"
101 fi
102 END_OF_RVMSH
103
104 chmod 755 %{buildroot}%{_sysconfdir}/profile.d/rvm.sh
105
106 #mv %{buildroot}%{_bindir}/rake %{buildroot}%{_bindir}/rvm-rake
107
108
109 # At this point, install of RVM is finished
110 # Now install some rubies
111
112 # Run this in a subshell so the rvm loading does not infect our current shell.
113 (
114 export rvm_ignore_rvmrc=1
115 export rvm_user_install_flag=0
116 export rvm_path="%{buildroot}%{rvm_dir}"
117 export rvm_bin_path="%{buildroot}%{_bindir}"
118 export rvm_man_path="%{buildroot}%{_mandir}"
119 source ${rvm_path}/scripts/rvm
120 gemi='gem install --no-ri --no-rdoc'
121
122 #touch $rvm_path/RELEASE
123 ruby_tag=ruby-1.9.3-p286
124 rvm install $ruby_tag
125 rvm use $ruby_tag
126 #$gemi bundler
127
128 #ruby_tag=ruby-1.8.7-p352
129 #rvm install $ruby_tag
130 #rvm use $ruby_tag
131 )
132
133 export br=%{buildroot}
134
135 # Remove sources
136 rm -rf $br/usr/lib/rvm/src
137
138 # Strip binaries
139 #find $br -type f -print0 |xargs -0 file --no-dereference --no-pad |grep 'not stripped' |cut -f1 -d: |xargs -r strip
140
141 # Strip and Fix bad paths in generated files
142 # That is not optimized, but that is not supposed to be done often
143 for f in `find $br -type f -print0 |xargs -0 file --no-dereference --no-pad |grep ': ELF' |cut -f1 -d:`; do
144   strip $f
145   grep "$br" $f || continue
146   line=`chrpath -l $f` || continue
147   echo $line |grep "$br" || continue
148   chrpath -r `echo $line |cut -f2 -d= |sed "s,$br,,"` $f
149 done
150
151 # Replace bad paths in text files
152 find $br -type f \( -name \*.log -o -name \*.la \) -print0 |xargs -0 -r sed -i "s,$br,,g"
153 find $br -type f -print0 |xargs -0 file --no-dereference --no-pad |grep ': .* text' |cut -f1 -d: |xargs -r sed -i "s,$br,,g"
154
155 # Strip object files in ar archives from bad path strings
156 for f in `find $br -type f -name \*.a`; do
157   td=`mktemp -d`
158   pushd $td
159   ar x $f
160
161   for g in `find . -type f -print0 |xargs -0 file --no-dereference --no-pad |grep ': ELF' |cut -f1 -d:`; do
162     strip $g
163     grep "$br" $g || continue
164
165     # Replace the bad path with the good one, padded by nulls
166     ruby -p -i -e '
167       $_.encode!("UTF-8", "UTF-8", :invalid => :replace).gsub!(/#{ENV["br"]}(.*?)\0/) do |s|
168       $1 + ( "\0" * ENV["br"].size ) + "\0"
169       end
170     ' $g
171   done
172
173   ar r $f *
174   popd
175   rm -rf $td
176 done
177
178 # Replace paths in libraries strings
179 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
180   grep "$br" $f || continue
181
182   # Replace the bad path with the good one, padded by nulls
183   ruby -p -i -e '
184     $_.encode!("UTF-8", "UTF-8", :invalid => :replace).gsub!(/#{ENV["br"]}(.*?)\0/) do |s|
185     $1 + ( "\0" * ENV["br"].size ) + "\0"
186     end
187   ' $f
188 done
189
190 # Fix symlinks with bad path
191 for f in `find $br -type l |grep "$br"`; do
192     ln -sfn `readlink -f $f |sed "s,$br,,"` $f
193 done
194
195 find $br -maxdepth 1 -name '.*' -exec rm -rf {} \;
196
197 %clean
198 rm -rf %{buildroot}
199
200 %pre
201 getent group %{rvm_group} >/dev/null || groupadd -r %{rvm_group}
202 exit 0
203
204 %files
205 %defattr(-,root,root)
206 %config(noreplace) /etc/rvmrc
207 %config(noreplace) /etc/profile.d/rvm.sh
208 %attr(-,root,%{rvm_group}) %{rvm_dir}
209 %{_bindir}/*
210 %{_mandir}/man1/*
211
212 %changelog
213 * Fri Mar 30 2012 Alexandre Fouche - 3.xxx
214 Add some rubies and gems to compile:
215 - 1.9.2-p290 + bundler, bluepill, whenever
216 - 1.9.3-p0 + bundler, bluepill, whenever
217
218 * Thu Mar 29 2012 Alexandre Fouche - 2.xxx
219 - Adapt <https://github.com/mdkent/rvm-rpm/blob/master/SPECS/rvm-ruby.spec> to make it work from RVM git source directly
220 - Strip binaries, libraries, ...
221
222 * Thu Mar 29 2012 Alexandre Fouche - 1.xxx
223 - Adapt <https://github.com/mdkent/rvm-rpm/blob/master/SPECS/rvm-ruby.spec> to make it work from RVM git source directly
224
225 * Tue Dec 13 2011 Matthew Kent <mkent@magoazul.com> - 1.10.0-2
226 - New upstream release
227 - Drop rvm_prefix
228 - Rename rvm_user_install to rvm_user_install_flag
229 - Rename rake wrapper to rvm-rake
230 - Add file dependency
231
232 * Thu Aug 4 2011 Matthew Kent <mkent@magoazul.com> - 1.6.32-1
233 - New upstream release
234
235 * Tue Apr 19 2011 Matthew Kent <mkent@magoazul.com> - 1.6.3-1
236 - Initial package based off Gentoo work