source: projects/emacsen-common/trunk/scripts/emacs-install.rb @ 7244

Revision 7244, 2.8 KB checked in by daisuke, 11 years ago (diff)
  • fix emacs-install.rb/emacs-package-install.rb to work with ruby-1.9
Line 
1#!/usr/bin/ruby
2
3#prefix = "/home/xtakei/cvs/emacsen-common/apel-sample"
4 prefix ="/"
5
6
7if $DEBUG
8  ENV["PRIORITY"]="20"
9  def system(string)
10    print string
11    print "\n"
12  end
13end
14
15
16
17# variables
18
19#   installed emacs
20flavors = ARGV[0]
21
22#   installed elisp package 
23elpackages = Array.new
24
25lib_dir = prefix+"/usr/lib/emacsen-common"
26var_dir = prefix+"/var/lib/emacsen-common"
27
28
29$action = "install"
30
31if $0 =~ /remove/
32then 
33 $action = "remove" 
34end
35
36#print "actionscript:"+actionscript+"\n"
37
38
39def getflavors(var_dir = "/")
40   return open(var_dir+"/installed-flavors").readlines
41end
42def getelisp(var_dir = "/")
43   return open(var_dir+"/installed-elisp").readlines
44end
45
46def install_alternatives(flavor)
47
48  if flavor =~/^xemacs/
49    comand_options="/sbin/update-alternatives --install /usr/b\in/xemacs xemacs /usr/bin/#{flavor} #{ENV['PRIORITY'].to_i} ;"
50  else
51    comand_options=""
52  end
53 
54
55  comand_options=comand_options+"/sbin/update-alternatives --install /usr/bin/emacs emacs /usr/bin/#{flavor} #{ENV['PRIORITY'].to_i} "
56   
57
58  open("/var/lib/emacs/alternative-filelist","r").each{  |src|
59    unless src =~/\/usr\/bin\/emacs$/ then
60      src.chomp!
61      file=src.dup
62#      if src =~/\/man\/man[0-9]/ then
63#         file.gsub!(/([^\/^\.]+)\.([0-9])\.gz/){
64#         "#{$1}.#{flavor.to_s}.#{$2}"
65#         }
66#      else
67        file+="."+flavor
68#      end
69      comand_options=comand_options+" --slave "+src+" "+File.basename(src) +" "+file
70    end
71
72  }
73 
74  system(comand_options)
75end
76
77
78def change_flavor(flavors) 
79  @number = ""
80  alternatives_config = open("|/sbin/update-alternatives --config emacs")
81  alternatives_config.each{ |line|
82    if line=~/.#{flavor}/ then
83      line.scan(/^[\*\+ ]+([1-9]+)/){
84        @number = $1.to_s
85      }
86      break
87    end 
88   
89  }
90  alternatives.close
91  system("echo #{@number} | /sbin/update-alternatives --config emacs")
92end
93def reverse_flavor
94  system("/sbin/update-alternatives --auto emacs")
95end
96def remove_flavor(flavor)
97  system("/sbin/update-alternatives --remove emacs /usr/bin/#{flavor}")
98  if flavor =~/xemacs/
99    system("/sbin/update-alternatives --remove xemacs /usr/bin/#{flavor} ")
100  end
101
102end 
103def update_flavor(flavor)
104  system("/sbin/update-alternatives --auto emacs ")
105    if flavor =~/xemacs/
106     system("/sbin/update-alternatives --auto xemacs ")
107   end
108end
109
110
111
112
113elisp = getelisp(var_dir)
114
115if $action =~/remove/
116then
117  elisp.reverse!
118  remove_flavor(flavors)
119else
120  install_alternatives(flavors)
121 
122end
123update_flavor(flavors)
124
125#system2("#{lib_dir}/change-temporary-flavor #{flavors}")
126
127#change_flavor(flavors)
128
129elisp.each{ |el|
130  el.chomp!
131  actionscript = lib_dir+"/packages/"+$action+"/"+el
132  _eprefix=ENV["EPREFIX"]
133  ENV["EPREFIX"]=prefix
134  system("#{actionscript} #{flavors}\n")
135  ENV["EPREFIX"]=_eprefix
136}
137#system2("#{lib_dir}/reverse-default-flavor")
138#reverse_flavor
Note: See TracBrowser for help on using the repository browser.