blob: 901b5cf226a0a9230f6f3a054e39b437446e62ad [file] [log] [blame]
Meng-Huan Yua7758562019-11-28 18:40:24 +08001#!/usr/bin/env python2
2#
3# Copyright 2020 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Factory toolkit uninstaller.
8
9Remove all factory toolkit related files on CrOS device.
10"""
11
12from __future__ import print_function
13
14import argparse
15import os
16import sys
17
18from six.moves import input
19
Meng-Huan Yua7758562019-11-28 18:40:24 +080020from cros.factory.test.env import paths
21from cros.factory.tools import install_symlinks
22from cros.factory.utils import file_utils
23from cros.factory.utils import log_utils
24from cros.factory.utils import process_utils
25from cros.factory.utils import sys_utils
26
27HELP_HEADER = """
28Uninstall the factory toolkit on a CrOS device.
29"""
30
Meng-Huan Yuf68f7892020-03-06 19:59:27 +080031FACTORY_PATHS = [
32 '/var/factory', '/run/factory', paths.FACTORY_DIR,
33 '/var/log/factory-init.log', '/var/log/factory-session.log',
34 '/var/log/factory.log'
35]
Meng-Huan Yua7758562019-11-28 18:40:24 +080036
37
38def AssertEnvironment():
39 if not sys_utils.InCrOSDevice():
40 raise Exception(
41 "ERROR: You're not on a CrOS device (for more details, please "
42 'check sys_utils.py:InCrOSDevice). The uninstaller only works on '
43 'CrOS device.')
44 if os.getuid() != 0:
45 raise Exception('You must be root to uninstall the factory toolkit on a '
46 'CrOS device.')
47
48
49def MakeWarningMessage():
50 ret = file_utils.ReadFile(paths.FACTORY_TOOLKIT_VERSION_PATH)
51 ret += (
52 '\n'
53 '\n'
54 '*** You are about to uninstall the factory toolkit at:\n')
55
Meng-Huan Yuf68f7892020-03-06 19:59:27 +080056 for p in FACTORY_PATHS:
Meng-Huan Yua7758562019-11-28 18:40:24 +080057 ret += '*** %s\n' % p
58
59 ret += '***'
60
61 return ret
62
63
64def Main():
65 log_utils.InitLogging()
66
67 parser = argparse.ArgumentParser(
68 description=HELP_HEADER,
69 formatter_class=argparse.RawDescriptionHelpFormatter)
70 parser.add_argument('--yes', '-y', action='store_true',
71 help="Don't ask for confirmation")
72
73 args = parser.parse_args()
74
75 AssertEnvironment()
76
77 print(MakeWarningMessage())
78 if not args.yes:
79 answer = input('*** Continue? [y/N] ')
80 if not answer or answer[0] not in 'yY':
81 sys.exit('Aborting.')
82
83 # To recover the symlinks under /usr/local/bin. We need to re-create the links
84 # to factory-mini.par.
85 install_symlinks.UninstallSymlinks('/usr/local/bin',
86 install_symlinks.MODE_FULL)
87 install_symlinks.InstallSymlinks('../factory-mini/factory-mini.par',
88 '/usr/local/bin', install_symlinks.MODE_MINI)
89
90 # Delete all factory related files.
Meng-Huan Yuf68f7892020-03-06 19:59:27 +080091 for p in FACTORY_PATHS:
Meng-Huan Yua7758562019-11-28 18:40:24 +080092 process_utils.Spawn(['rm', '-rf', p], check_call=True, log=True)
93
94
95if __name__ == '__main__':
96 Main()