#!/usr/bin/ruby1.8 require 'lib/aids' def main(argv) svc = AIDS::Service.new(argv[1]) if argv[1] case argv[0] when 'enable' usage unless svc svc.enable! when 'disable' usage unless svc svc.disable! when 'list' if svc display_status(svc) else AIDS.get_all_services.sort_by{|s|s.name}.each{|s|display_status(s)} end else usage end end def display_status(svc) print "#{svc.name[0..14]}:#{' ' * (16 - svc.name[0..14].length)}" status = svc.status AIDS::RUNLEVEL_ALL.each do |r| case status[r] when :start prettystatus = 'on' when :stop prettystatus = 'off' when :none prettystatus = 'none' else next end print "#{r}: #{prettystatus + ' ' * (8 - prettystatus.length)}" end puts end def usage $stderr.puts <<-EOF AIDS - Assistant for Initialisation of Debian Services Usage: #{$0} command [service] Command may be one of: - enable Enables the service. - disable Disables the service. - list Lists the current status of the service, or of all services if none is provided. EOF exit 1 end main(ARGV) if $0 == __FILE__