1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#!/usr/bin/python
# Copyright (c) 2005-2009 Canonical Ltd
#
# AUTHOR:
# Michael Vogt <mvo@ubuntu.com>
#
# This file is part of unattended-upgrades
#
# unattended-upgrades is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# unattended-upgrades is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with unattended-upgrades; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
import apt_inst
import apt_pkg
import sys
import os
import string
import datetime
import ConfigParser
from StringIO import StringIO
from optparse import OptionParser
from subprocess import Popen, PIPE
import warnings
warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
import apt
import logging
import subprocess
import signal
import gettext
from gettext import gettext as _
from UnattendedUpgrades.UnattendedUpgrades import UnattendedUpgrades
from UnattendedUpgrades.UI import *
if __name__ == "__main__":
localesApp="unattended-upgrades"
localesDir="/usr/share/locale"
gettext.bindtextdomain(localesApp, localesDir)
gettext.textdomain(localesApp)
if os.getuid() != 0:
print _("You need to be root to run this application")
sys.exit(1)
if not os.path.exists("/var/log/unattended-upgrades"):
os.makedirs("/var/log/unattended-upgrades")
# init the logging
logdir = apt_pkg.Config.FindDir("APT::UnattendedUpgrades::LogDir",
"/var/log/unattended-upgrades/")
logfile = logdir+apt_pkg.Config.Find("APT::UnattendedUpgrades::LogFile",
"unattended-upgrades.log")
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s',
filename=logfile)
# init the options
parser = OptionParser()
parser.add_option("-d", "--debug",
action="store_true", dest="debug", default=False,
help=_("print debug messages"))
parser.add_option("", "--dry-run",
action="store_true", default=False,
help=_("Simulation, download but do not install"))
(options, args) = parser.parse_args()
if options.debug:
ui = DebugUI()
else:
ui = LoggingUI()
# override normal logging UI with mail ui
if apt_pkg.Config.Find("Unattended-Upgrade::Mail", ""):
ui = MailUI()
# check if we are in dry-run mode
if options.dry_run:
logging.info("Option --dry-run given, *not* performing real actions")
apt_pkg.Config.Set("Debug::pkgDPkgPM","1")
# get the controller object
uu = UnattendedUpgrades(ui)
logging.info(_("Starting unattended upgrades script"))
res = uu.run()
if not res:
sys.exit(1)
|