Can platform agnosticism be achieved?



Hello List,

I've been asking myself this question for quite some time, as Windows
user
need to break the rules and do things that don't work out of the box
with Ruby.

I know Ruby has it's root in posix and *nix OS, where things like
drive letters don't exist and full power is just four letters away
(sudo).

Since last year, I've decided to spend more time helping great OSS
Ruby
projects to Windows users, and in doing so, I review, check and edit
a lot of projects on rubyforge, github and other esoteric places.

The thing is I'm a bit annoyed of adding regexp around things like
sudo in Rakefiles. Yeah, it's annoying, 4 letters ends up adding 20
bytes
more just to avoid typing sudo in front of the rake command
you're calling.

Take as example the following gem install rake tasks (from DataMapper
and Merb dev):

namespace :gems do
desc 'Uninstall all RubyGems for this project'
task :wipe do
sudo = RUBY_PLATFORM =~ /win32|cygwin/ ? '' : 'sudo'
sh "#{sudo} gem uninstall #{project} --all --ignore-dependencies
--executables; true"
end
end

You see a big condition for sudo there. Take out of the consideration
that the regexp don't cover mingw as valid platform, or even don't
consider mswin64 (build of ruby 1.9 with VC9 for 64bits).

So, that regexp will become obsolete with time, at least for
Windows...
and the Windows folks will be required to patch it every time.

What about remove sudo from there and leave up to the user to make
that
decision? One example:

User perform some apt-get (ubuntu) tasks that requires sudo. He enters
his password to confirm the operation.
Under the same session, a few minutes later, he fires a rake task that
uses sudo, by mistake or because is not clearly advertised what It
does, he ends up messing with his gem repository, removing gems maybe
he
is using for other projects.

So, these rake tasks are doing more than they should, taking
privileges out of user hand and automating them, hiding the problem
when looking answer to "what happened?".

Or maybe I'm wrong, someone will say shut up or a flame war will get
started...

For the time being, those Windows user that don't want to patch a lot
of rakefiles that: 1) ignores platforms like mingw and java under
Windows (dunno how to get that), or 2) clearly ignores sudo is not
usable under windows.

type sudo.bat

@ECHO OFF
REM
REM Fake sudo for Windows
REM This help avoid tools that forces usage of 'sudo' on all the
REM platforms, not just *nix ones.
REM
REM Save this file as 'sudo.bat' and place it somewhere in your PATH
REM (ruby/bin is a good place too).
REM
CALL %*

Regards,
--
Luis Lavena
.



Relevant Pages

  • Re: Clock Problem?
    ... The broken ACPI data can be source of problem as windows is more "flexible" ... $ sudo cat adjtime ... ~$ sudo ntpdate -b pool.ntp.org ... In this session SuSE started with the correct time at about 9:45 pm UTC, ...
    (alt.os.linux.suse)
  • Re: Most secure mainstream OS? (was Re: QuickTime 7.1.6: Java vulnerability Fix)
    ... the registry, affecting other programs, for all users. ... Not completely true with Vista or Windows XP. ... do an sudo xxx on the ... command line in OS X. Replace xxx with your favorite command that needs ...
    (comp.sys.mac.advocacy)
  • Re: PS3 MAME
    ... commands lide sudo this and nano that to be able to get what i want. ... which gives you root permissions. ... It is similar to the "Run as" command of Windows. ... Tired of Windows malware but fear to try out Linux? ...
    (alt.games.mame)
  • Re: Most secure mainstream OS? (was Re: QuickTime 7.1.6: Java vulnerability Fix)
    ... the registry, affecting other programs, for all users. ... Not completely true with Vista or Windows XP. ... do an sudo xxx on the ... command line in OS X. Replace xxx with your favorite command that needs ...
    (comp.sys.mac.advocacy)
  • Re: Cannot install updates for XP and Office since repairing windows.
    ... I decided to use my Dell CD to repair windows. ... I cannot install any updates from MW update. ... rem Only needed if windows updates fail to install after ... regsvr32 shdocvw.dll ...
    (uk.comp.homebuilt)