1 | #!/usr/bin/ruby |
---|
2 | |
---|
3 | #prefix = "/home/xtakei/cvs/emacsen-common/apel-sample" |
---|
4 | prefix ="/" |
---|
5 | |
---|
6 | |
---|
7 | if $DEBUG |
---|
8 | ENV["PRIORITY"]="20" |
---|
9 | def system(string) |
---|
10 | print string |
---|
11 | print "\n" |
---|
12 | end |
---|
13 | end |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | # variables |
---|
18 | |
---|
19 | # installed emacs |
---|
20 | flavors = ARGV[0] |
---|
21 | |
---|
22 | # installed elisp package |
---|
23 | elpackages = Array.new |
---|
24 | |
---|
25 | lib_dir = prefix+"/usr/lib/emacsen-common" |
---|
26 | var_dir = prefix+"/var/lib/emacsen-common" |
---|
27 | |
---|
28 | |
---|
29 | $action = "install" |
---|
30 | |
---|
31 | if $0 =~ /remove/ |
---|
32 | then |
---|
33 | $action = "remove" |
---|
34 | end |
---|
35 | |
---|
36 | #print "actionscript:"+actionscript+"\n" |
---|
37 | |
---|
38 | |
---|
39 | def getflavors(var_dir = "/") |
---|
40 | return open(var_dir+"/installed-flavors").readlines |
---|
41 | end |
---|
42 | def getelisp(var_dir = "/") |
---|
43 | return open(var_dir+"/installed-elisp").readlines |
---|
44 | end |
---|
45 | |
---|
46 | def 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) |
---|
75 | end |
---|
76 | |
---|
77 | |
---|
78 | def 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") |
---|
92 | end |
---|
93 | def reverse_flavor |
---|
94 | system("/sbin/update-alternatives --auto emacs") |
---|
95 | end |
---|
96 | def 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 | |
---|
102 | end |
---|
103 | def update_flavor(flavor) |
---|
104 | system("/sbin/update-alternatives --auto emacs ") |
---|
105 | if flavor =~/xemacs/ |
---|
106 | system("/sbin/update-alternatives --auto xemacs ") |
---|
107 | end |
---|
108 | end |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | elisp = getelisp(var_dir) |
---|
114 | |
---|
115 | if $action =~/remove/ |
---|
116 | then |
---|
117 | elisp.reverse! |
---|
118 | remove_flavor(flavors) |
---|
119 | else |
---|
120 | install_alternatives(flavors) |
---|
121 | |
---|
122 | end |
---|
123 | update_flavor(flavors) |
---|
124 | |
---|
125 | #system2("#{lib_dir}/change-temporary-flavor #{flavors}") |
---|
126 | |
---|
127 | #change_flavor(flavors) |
---|
128 | |
---|
129 | elisp.each{ |el| |
---|
130 | el.chomp! |
---|
131 | actionscript = lib_dir+"/packages/"+$action+"/"+el |
---|
132 | system("EPREFIX=#{prefix} #{actionscript} #{flavors}\n") |
---|
133 | } |
---|
134 | #system2("#{lib_dir}/reverse-default-flavor") |
---|
135 | #reverse_flavor |
---|