2 # -*- coding: utf-8 -*-
4 # (c) Copyright 2003-2009 Hewlett-Packard Development Company, L.P.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 __title__ = 'HPLIP Installer'
25 __mod__ = 'hplip-install'
26 __doc__ = "Installer for HPLIP tarball (called automatically after invoking the .run file)."
39 from base import utils
42 USAGE = [(__doc__, "", "name", True),
43 ("Usage: sh %s [OPTIONS]" % __mod__, "", "summary", True),
47 ("Automatic mode (chooses the most common options):", "-a or --auto", "option", False),
48 ("Dependency package installation retries:", "-r <retries> or --retries=<retries> (default is 3)", "option", False),
49 ("Assume network connection present:", "-n or --network", "option", False),
50 utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
54 ("[OPTIONS] (FOR TESTING ONLY/ADVANCED)", "", "header", False),
55 ("Force install of all dependencies:", "-x", "option", False),
56 ("Force unknown distro mode:", "-d", "option", False),
57 ("Force installation of Qt4 support:", "--qt4 (same as --enable=qt4)", "option", False),
58 ("Force disable Qt4 support:", "--no-qt4 (same as --disable=qt4", "option", False),
59 #("Force installation of Qt3 support:", "--qt3 (same as --enable=qt3)", "option", False),
60 #("Force disable Qt3 support:", "--no-qt3 (same as --disable=qt3", "option", False),
61 ("Force installation of PolicyKit support:", "--policykit (same as --enable=policykit)", "option", False),
62 ("Force disable PolicyKit support:", "--no-policykit (same as --disable=policykit)", "option", False),
63 ("Force configure enable/disable flag:", "--enable=<flag> or --disable=<flag>, where <flag> is 'fax-build', 'qt4', 'pp-build', etc. See ./configure --help for more info.", "option", False),
66 def usage(typ='text'):
68 utils.log_title(__title__, __version__)
70 utils.format_text(USAGE, typ, __title__, __mod__, __version__)
74 log.set_module(__mod__)
76 log.debug("euid = %d" % os.geteuid())
77 mode = INTERACTIVE_MODE
82 assume_network = False
84 restricted_override = False
88 if((re.search(' ',os.getcwd()))!= None):
89 log.info("Current hplip source directory path has space character in it. Please update path by removing space characters. Example: Change %s.run to %s.run" % (os.getcwd(),(os.getcwd()).replace(' ','')))
90 os.system("rm -r ../%s"%(os.getcwd()).rsplit('/').pop())
94 opts, args = getopt.getopt(sys.argv[1:], 'hl:giatxdq:nr:b',
95 ['help', 'help-rest', 'help-man', 'help-desc', 'gui', 'lang=',
96 'logging=', 'interactive', 'auto', 'text', 'qt4',
97 'network', 'retries=', 'enable=', 'disable=',
98 'no-qt4', 'policykit', 'no-policykit', 'debug'])
100 except getopt.GetoptError, e:
105 if os.getenv("HPLIP_DEBUG"):
106 log.set_level('debug')
109 if o in ('-h', '--help'):
112 elif o == '--help-rest':
115 elif o == '--help-man':
118 elif o in ('-q', '--lang'):
121 elif o == '--help-desc':
125 elif o in ('-l', '--logging'):
126 log_level = a.lower().strip()
127 if not log.set_level(log_level):
130 elif o in ('-g', '--debug'):
131 log.set_level('debug')
133 elif o in ('-i', '--interactive', '--text', '-t'):
134 mode = INTERACTIVE_MODE
136 elif o in ('-a', '--auto'):
140 log.warn("Install all depends (-x) is for TESTING ONLY")
144 log.warn("Unknown distro (-d) is for TESTING ONLY")
147 elif o in ('-n', '--network'):
148 assume_network = True
150 elif o in ('-r', '--retries'):
154 log.error("Invalid value for retries. Set to default of 3.")
158 restricted_override = True
161 if 'qt4' not in enable and 'qt4' not in disable:
164 log.error("Duplicate configuration flag: %s" % a)
167 elif o == '--no-qt4':
168 if 'qt4' not in disable and 'qt4' not in enable:
169 disable.append('qt4')
171 log.error("Duplicate configuration flag: %s" % a)
174 elif o == '--policykit':
175 if 'policykit' not in enable and 'policykit' not in disable:
176 enable.append('policykit')
178 log.error("Duplicate configuration flag: %s" % a)
181 elif o == '--no-policykit':
182 if 'policykit' not in disable and 'policykit' not in enable:
183 disable.append('policykit')
185 log.error("Duplicate configuration flag: %s" % a)
188 elif o == '--enable':
189 if a not in enable and a not in disable:
192 log.error("Duplicate configuration flag: %s" % a)
195 elif o == '--disable':
196 if a not in enable and a not in disable:
199 log.error("Duplicate configuration flag: %s" % a)
205 log.warn("hplip-install should not be run as root.")
207 log_file = os.path.normpath('./hplip-install_%s.log' % time.strftime("%a-%d-%b-%Y_%H:%M:%S"))
209 if os.path.exists(log_file):
212 log.set_logfile(log_file)
213 log.set_where(log.LOG_TO_CONSOLE_AND_FILE)
215 log.debug("Log file=%s" % log_file)
217 ac_init_pat = re.compile(r"""AC_INIT\(\[(.*?)\], *\[(.*?)\], *\[(.*?)\], *\[(.*?)\] *\)""", re.IGNORECASE)
219 config_in = open('./configure.in', 'r')
221 prop.version = 'x.x.x'
224 if c.startswith("AC_INIT"):
225 match_obj = ac_init_pat.search(c)
226 prop.version = match_obj.group(2)
231 utils.log_title(__title__, __version__, True)
233 log.info("Installer log saved in: %s" % log.bold(log_file))
238 from installer import text_install
239 log.debug("Starting text installer...")
240 text_install.start(language, auto, test_depends, test_unknown, assume_network, max_retries, enable, disable)
241 except KeyboardInterrupt:
242 log.error("User exit")