- initial import of revision 374 from cnc
[apt.git] / contrib / apt-groupinstall / apt-groupinstall.lua
1 -- Lua script to allow installing package groups as defined in comps.xml
2 -- Licensed under the GPL, by pmatilai@welho.com / 2003
3 -- This script must be plugged into the APT script slots
4 -- Scripts::AptGet::Command and Scripts::AptCache::Command
5 --
6
7 helper = confget("Dir::Bin::scripts/f").."/"..confget("Scripts::Groupinstall::Backend")
8 helperopts = "-t"
9 if confget("Scripts::Groupinstall::Recursive", "false") == "true" then
10         helperopts = helperopts.." -r"
11 end
12 if confget("Scripts::Groupinstall::Show-Hidden", "false") == "true" then
13         helperopts = helperopts.." -h"
14 end
15 if confget("Scripts::Groupinstall::All-Packages", "false") == "true" then
16         helperopts = helperopts.." -a"
17 end
18 if confexists("Scripts::Groupinstall::DataPath") then
19         helperopts = helperopts.." -p "..confget("Scripts::Groupinstall::DataPath")
20 end
21
22 if script_slot == "Scripts::AptCache::Help::Command" then
23         print(_("   groupnames - Show available groups"))
24         print(_("   showgroup <group> - Show group contents"))
25 elseif script_slot == "Scripts::AptGet::Help::Command" then
26         print(_("   groupinstall <group> - Install packages in <group>"))
27         print(_("   groupremove <group> - Remove packages in <group>"))
28 elseif script_slot == "Scripts::AptCache::Command" then
29         if command_args[1] == "groupnames" then
30                 command_consume = 1
31                 os.execute(helper.." "..helperopts.." --list-tasks")
32         elseif command_args[1] == "showgroup" then
33                 command_consume=1
34                 numgroups = table.getn(command_args) - 1
35                 if numgroups < 1 then
36                         apterror(_("No groupname given."))
37                         return
38                 end
39                 cmd = ""
40                 for i = 1, numgroups do
41                         cmd = cmd.." --task-desc "..command_args[i+1]
42                 end
43                 os.execute(helper.." "..helperopts.." "..cmd)
44         end
45
46 elseif script_slot == "Scripts::AptGet::Command" then
47         if command_args[1] == "groupinstall" then
48         oper = markinstall
49                 command_consume = 1
50         elseif command_args[1] == "groupremove" then
51                 oper = markremove
52                 command_consume = 1
53         else
54                 return
55         end
56         
57         numgroups = table.getn(command_args) - 1
58         if numgroups < 1 then
59                 apterror(_("No groupname given."))
60                 return
61         end
62         cmd = ""
63         group = ""
64         for i = 1, numgroups do
65                 cmd = cmd.." --task-packages "..command_args[i+1]
66                 group = group.." "..command_args[i+1]
67         end
68
69     print(_("Finding packages belonging to group(s) "..group.."..."))
70     pkgs = io.popen(helper.." "..helperopts.." "..cmd)
71     for name in pkgs:lines() do
72                 pkg = pkgfind(name)
73                 if pkg then
74                         oper(pkg)
75                 end
76         end
77 end
78
79 -- vim:ts=4:sw=4