]>
Commit | Line | Data |
---|---|---|
453b82a3 | 1 | #include <config.h> |
b9179170 | 2 | |
453b82a3 | 3 | #include <apt-pkg/cmndline.h> |
b9179170 | 4 | #include <apt-pkg/configuration.h> |
e7e10e47 | 5 | #include <apt-pkg/fileutl.h> |
ae2a6be8 | 6 | #include <apt-pkg/strutl.h> |
453b82a3 DK |
7 | |
8 | #include <apt-private/private-main.h> | |
9 | ||
10 | #include <iostream> | |
8b79c94a DK |
11 | #include <locale> |
12 | ||
453b82a3 DK |
13 | #include <string.h> |
14 | #include <unistd.h> | |
3163087b | 15 | #include <signal.h> |
b9179170 MV |
16 | |
17 | #include <apti18n.h> | |
18 | ||
3163087b | 19 | |
570ec96d | 20 | void InitLocale(APT_CMD const binary) /*{{{*/ |
e7e10e47 | 21 | { |
62600666 DK |
22 | try { |
23 | std::locale::global(std::locale("")); | |
24 | } catch (...) { | |
25 | setlocale(LC_ALL, ""); | |
26 | } | |
570ec96d DK |
27 | switch(binary) |
28 | { | |
29 | case APT_CMD::APT: | |
30 | case APT_CMD::APT_CACHE: | |
31 | case APT_CMD::APT_CDROM: | |
32 | case APT_CMD::APT_CONFIG: | |
ab07af70 | 33 | case APT_CMD::APT_DUMP_SOLVER: |
570ec96d DK |
34 | case APT_CMD::APT_HELPER: |
35 | case APT_CMD::APT_GET: | |
36 | case APT_CMD::APT_MARK: | |
37 | textdomain("apt"); | |
38 | break; | |
39 | case APT_CMD::APT_EXTRACTTEMPLATES: | |
40 | case APT_CMD::APT_FTPARCHIVE: | |
8e99b22c | 41 | case APT_CMD::APT_INTERNAL_PLANNER: |
570ec96d DK |
42 | case APT_CMD::APT_INTERNAL_SOLVER: |
43 | case APT_CMD::APT_SORTPKG: | |
44 | textdomain("apt-utils"); | |
45 | break; | |
46 | } | |
e7e10e47 | 47 | } |
570ec96d | 48 | void InitLocale() {} |
e7e10e47 DK |
49 | /*}}}*/ |
50 | void InitSignals() /*{{{*/ | |
3163087b | 51 | { |
3163087b MV |
52 | signal(SIGPIPE,SIG_IGN); |
53 | } | |
e7e10e47 DK |
54 | /*}}}*/ |
55 | void CheckIfSimulateMode(CommandLine &CmdL) /*{{{*/ | |
b9179170 | 56 | { |
0d5b9da9 DK |
57 | // disable locking in simulation, but show the message only for users |
58 | // as root hasn't the same problems like unreadable files which can heavily | |
59 | // distort the simulation. | |
60 | if (_config->FindB("APT::Get::Simulate") == true && | |
b9179170 MV |
61 | (CmdL.FileSize() == 0 || |
62 | (strcmp(CmdL.FileList[0], "source") != 0 && strcmp(CmdL.FileList[0], "download") != 0 && | |
63 | strcmp(CmdL.FileList[0], "changelog") != 0))) | |
64 | { | |
0d5b9da9 | 65 | if (getuid() != 0 && _config->FindB("APT::Get::Show-User-Simulation-Note",true) == true) |
ae2a6be8 DK |
66 | // TRANSLATORS: placeholder is a binary name like apt or apt-get |
67 | ioprintf(std::cout, _("NOTE: This is only a simulation!\n" | |
68 | " %s needs root privileges for real execution.\n" | |
b9179170 | 69 | " Keep also in mind that locking is deactivated,\n" |
ae2a6be8 DK |
70 | " so don't depend on the relevance to the real current situation!\n"), |
71 | _config->Find("Binary").c_str()); | |
b9179170 MV |
72 | _config->Set("Debug::NoLocking",true); |
73 | } | |
74 | } | |
e7e10e47 DK |
75 | /*}}}*/ |
76 | void CheckIfCalledByScript(int argc, const char *argv[]) /*{{{*/ | |
77 | { | |
78 | if (unlikely(argc < 1)) return; | |
79 | ||
80 | if(!isatty(STDOUT_FILENO) && | |
81 | _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false) | |
82 | { | |
83 | std::cerr << std::endl | |
84 | << "WARNING: " << flNotDir(argv[0]) << " " | |
85 | << "does not have a stable CLI interface. " | |
86 | << "Use with caution in scripts." | |
87 | << std::endl | |
88 | << std::endl; | |
89 | } | |
90 | } | |
91 | /*}}}*/ |