[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[E-devel] E17 installer script.



Hi,

I've written a small script that downloads e17 from CVS and builds it.

It's written in Ruby. Sorry if you don't like that :). You'll need Ruby installed.

It also does a few trivial checks for a few things (cvs, make, automake, autoconf, gettext, libtoolize, pkg-config, autoheader).

It's output is rather clean as it logs the command's output to a log file.


There's a configuration file (which is written in ruby as well) that you can modify.

The source is commented and so's the config file.
If anyone finds this useful, or interesting or has patches or whatever, drop me a line.

Make it executable and run ./my_e or just run it with 'ruby my_e'

In the future, I will modify the script to stop when something doesn't build properly (or prompt the user or whatever). Right now it doesn't but a simple ^C will stop it.

Hope this is useful. Cheers.
Eugen.
#!/usr/bin/ruby
# This is My E script.
# It is released under the BSD license
# Written by Eugen Minciu <minciue@gmail.com>
require 'fileutils'
require 'my_e.conf'

# trap INT to exit more gracefully then the default backtrace
Signal.trap("INT") do
  puts ""
  puts "* Exiting ..."
  exit
end

# Execute a command. 
# We fork before we execute so we can catch SIGINT while
# the process is still running.
def exec_cmd(cmd)
  fork { exec("#{cmd} >> #{LOG_FILE} 2>> #{LOG_FILE}") }
  Process.wait
  if $?.exitstatus == 0 then
    return true 
  else
    return false
  end
end

# The base package class. This implements common procedures for a 
# package, wether it is a library, application, misc package or a module
class Package
  attr_accessor :name
  # We initialize the packages class variable with whatever we got from
  # the config file
  def Package.init
    @@packages = []

    LIBRARIES.each do |item|
      @@packages << Library.new(item)
    end 

    APPLICATIONS.each do |item|
      @@packages << Application.new(item)
    end 
    
    MISC.each do |item|
      @@packages << Misc.new(item)
    end 
    
    MODULES.each do |item|
      @@packages << EModule.new(item)
    end
  end

  def initialize(name, options={})
    @name=name
    @dir=options[:dir]
  end

  # Execute an action.
  # Writes a nice little output, calls exec_cmd and prints out the result of
  # the operation accordingly
  def item_cmd(action,cmd)
    begin 
      FileUtils.cd(@dir)
    rescue
      puts "The source directory for #{@name} cannot be found on your system."
      puts "Perhaps you should run '#{$0} checkout' first."
      exit 0
    end

    print "  * #{action} #{@name} ... "

    if exec_cmd(cmd) then
      puts " [ok]"
    else
      puts " [failed]"
    end
    FileUtils.cd(CVS_PATH)
  end

  # Execute an action as root.
  # This one's a bit trickier. 
  # If we're not root it uses SUDO_CMD to ask for a password
  # SUDO_CMD needn't be 'sudo', it can be 'su -c'
  # You'll just be typing your root password and you'll be typing it a bit more
  def root_item_cmd(action,cmd)
    if Process.euid!=0 then
      cmd="#{SUDO_CMD} make install"
    end
    item_cmd(action,cmd)
  end

  # Cleanup a package
  def clean
    item_cmd("Cleaning","make distclean")
  end 
  
  # Update a package from CVS
  def update
    item_cmd("Updating","cvs -z3 -d#{CVS_SERVER} update")
  end 
  
  # Configure a package (actually runs ./autogen.sh)
  def configure
    item_cmd("Configuring","./autogen.sh --prefix=#{INSTALL_PATH}")
  end 

  # Compile a package
  def compile
    item_cmd("Compiling", "make")
  end 

  # Generate documentation
  def gendocs
    item_cmd("Generating docs for","./gendoc")
  end 
  
  # Install a package
  def install
    root_item_cmd("Installing","make install")
  end 
  
  # Uninstall a package
  def uninstall
    root_item_cmd("Unstalling","make uninstall")
  end  

  # Register libraries with ldconfig
  def register
    root_item_cmd("Registering","ldconfig")
  end

  # Checkout the CVS modules
  def Package.checkout
    puts("* Checking out ...")
    wd=Dir.pwd
    
    begin
      FileUtils.cd("#{CVS_PATH}")
    rescue
      FileUtils.cd(wd) 
    end 
    
    for i in ["e17","misc", "e_modules"] do
      print(" * Checking out #{i} ...")
      exec_cmd("cvs -q -d#{CVS_SERVER} co #{i}")
      sleep 10
      puts("[ok]");
    end 
    
    FileUtils.cd(wd)
    puts("* Checkout complete.")
  end 
  
  # Build all the items in @@packages
  def Package.do_build
    puts"* Building Enlightenment" 
    @@packages.each do |p|
      puts " * Building #{p.name}"
      p.clean
      p.update
      p.configure
      p.compile
      p.gendocs
      p.install
      p.register
    end
  end 

  # Uninstall all the items in @@packages
  def Package.do_uninstall
    puts "*Uninstalling Enlightenment"
    @@packages.each do |p|
      p.uninstall
    end
  end

  # Check if a program is available on a given machine
  def Package.check_item(item,cmd)
    puts " * Checking for #{item}"
    item_exists=exec_cmd(cmd)
    if (!item_exists) then
      puts " * #{item} is not installed on your system."
      puts "   #{item} is required by this script."
      puts "   Will now exit..."
      exit
    end
  end

  # Check for some required programs
  def Package.check_stuff
    puts "* Checking required items"
    for item in %w{ cvs make automake autoconf autoheader libtoolize gettext pkg-config}
      check_item(item,"#{item} --version")
    end
  end
end

class Library < Package
  def initialize(name)
    super(name, :dir => "e17/libs/#{name}")
  end
end

class Application < Package
  def initialize(name)
    super(name, :dir => "e17/apps/#{name}")
  end
end

class Misc < Package
  def initialize(name)
    super(name, :dir => "misc/#{name}")
  end
end

class Proto < Package
  def initialize(name)
    super(name, :dir => "e17/proto/#{name}")
  end
end

class EModule < Package
  def initialize(name)
    super(name, :dir => "e_modules/#{name}")
  end
end

# This is where the magic happens
puts"* MyE #{MY_E_VERSION} (C) 2006 Eugen Minciu"
puts"* This script is released under the BSD License"
if ARGV[0] == "checkout" then
  Package.checkout
elsif ARGV[0] == "uninstall" then
  Package.init
  Package.do_uninstall
elsif ARGV[0] == "install" then
  Package.check_stuff
  Package.init
  Package.do_build
else
  puts "Command line usage:"
  puts " #{$0} checkout:   Checkout source from CVS"
  puts " #{$0} install:    Build and install the latest version of E17"
  puts " #{$0} uninstall:  Uninstall the currently installed version of E17"
  puts ""
  puts " Anything else:    Print this help message"
end
# This is the MyE configuration file.
# It is, in fact (surprise) a Ruby file
#
# Comments start with a '#' symbol
# Options are in fact ruby constants. 
# As such they must be written like this OPTION
# Feel free to modify this stuff.
#
# The script's version. You can label it 'Dapper Drake' for all I care ;)
MY_E_VERSION="0.2"

# The command this script uses to obtain root privileges 
# at the time of installation. 
# You can substitute this for 'su -c' if you don't have sudo set up.
SUDO_CMD="sudo"

# The path where the CVS will be downloaded. 
# USE Dir.pwd to use the current directory.
# DO NOT use .
CVS_PATH=Dir.pwd

# The CVS server and path to use for downloads
CVS_SERVER=":pserver:anonymous@anoncvs.enlightenment.org:/var/cvs/e"

# The installation path
INSTALL_PATH="/usr/local/e17"

# File to log output to
LOG_FILE = "my_e.log"

# This is where you configure what packages you want installed.
# You need to setup these options: LIBRARIES, APPLICATIONS, MISC, MODULES

# These are arrays of strings. Separate them with whitespace in between %w{ }
#
# Libraries come first, applications are next, misc items third and
# modules come last.
#
# For each of these four items, the packages are built in the order in which they are declared in the array.
LIBRARIES = %w{ eet edb evas ecore embryo imlib2 edje epeg epsilon esmart emotion ewl exml}
APPLICATIONS = %w{ entrance e e_utils eclair elicit evfs} 
MISC = %w{}
MODULES = %w{ deskshow evolume mail slideshow tclock }