forked from dell/dell-recovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dell-restore-system
100 lines (94 loc) · 4.44 KB
/
dell-restore-system
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
#! /usr/bin/python3
# -*- coding: utf-8 -*-
#
# Dell Recovery Restore system command line
#
# Copyright (C) 2017 Dell Inc,
# Author: Mario Limonciello/Jude Hung
#
# This 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.
#
# This program 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 this application; if not, write to the Free Software Foundation, Inc., 51
# Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##################################################################################
from Dell.recovery_common import (find_partition, check_version, DBUS_INTERFACE_NAME,
DBUS_BUS_NAME, dbus_sync_call_signal_wrapper,
PermissionDeniedByPolicy, check_recovery_dhc)
import optparse
import os
import subprocess
import sys
#Translation support
from gettext import gettext as _
usage = '%prog [options]'
parser = optparse.OptionParser(usage=usage)
parser.set_defaults(
version=''
)
parser.add_option('-c', '--check-version', dest='checkversion', action='store_true',
help='Show the version information.')
parser.add_option('-y', '--yes', dest='yes', action='store_true',
help="Restore the system without user's confirmation.")
parser.add_option('-d', '--dhc', dest='dhc', action='store_true',
help="Restore the system with Dell Hybrid Client without user's confirmation")
(options, args) = parser.parse_args()
if __name__ == '__main__':
if options.checkversion:
print("%s %s" % (_("Version:"), check_version()))
else:
if not options.yes:
confirm = input(_("Would you want to restore the system? (y/n)"))
if not confirm.lower() == 'yes' and not confirm.lower()=='y':
sys.stdout.write("%s\n" % _("Aborted."))
sys.exit(0)
import dbus.mainloop.glib
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
recovery = find_partition()
#If we don't find an RP, throw error.
if not recovery:
sys.stderr.write("%s\n" %_("ERR: No recovery partition could be found to restore the system."))
sys.exit(1)
#don't ever autostart again
autostart=os.path.expanduser("~/.config/autostart/dell-recovery.desktop")
reminder = os.path.expanduser("~/.config/dell-recovery/reminder")
for item in (autostart, reminder):
if os.path.exists(item):
os.remove(item)
#Add option '-d' to support restore os with Dell Hybrid Client for some platforms
#invoke dbus to restore the system
try:
bus = dbus.SystemBus()
dbus_iface = dbus.Interface(bus.get_object(DBUS_BUS_NAME,
'/RecoveryMedia'),
DBUS_INTERFACE_NAME)
if options.dhc:
if check_recovery_dhc():
dbus_sync_call_signal_wrapper(dbus_iface,
"enable_boot_to_restore_dhc",
{},
True)
else:
print("Sorry, you machine is not support the '-d' option, because your machine model is not belong to install Dell Hybrid Client series, you can try 'dell-restore-system -y' to restore os, thanks.")
else:
dbus_sync_call_signal_wrapper(dbus_iface,
"enable_boot_to_restore",
{},
True)
except dbus.DBusException as ex:
if ex.get_dbus_name() == 'org.freedesktop.DBus.Error.FileNotFound':
text = _("Cannot connect to dbus")
if ex.get_dbus_name() == PermissionDeniedByPolicy._dbus_error_name:
text = _("Permission Denied")
else:
text = ex.get_dbus_message()
sys.stderr.write("%s\n" % text)
sys.exit(1)