-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfpm.cpp
More file actions
49 lines (45 loc) · 1.87 KB
/
fpm.cpp
File metadata and controls
49 lines (45 loc) · 1.87 KB
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
#include "fpm.hpp"
#include <iostream>
#include <stdexcept>
#include <unistd.h>
using namespace std;
int main(int argc, char* argv[]) {
if (argc < 2) {
cerr << "Usage: " << argv[0] << " <in|out|configure|about> [args]" << endl;
return 1;
}
try {
string action = argv[1];
if (action == "in" || action == "i") {
if (argc < 3) throw invalid_argument("Missing package name for installation");
// if variable MIRRORFIND=1 then use the fastest mirror
if (getenv("MIRRORFIND") != nullptr && fpm::is_root()) {
string fastestmirror = fpm::findbestmirror();
if (system(("echo "+ fastestmirror + " > /etc/fpm/mirlink").c_str()) != 0) {
cout << "unable to write or something idk" << endl;
}
}
fpm::install_package(argv[2]);
} else if (action == "out" || action == "o") {
if (argc < 3) throw invalid_argument("Missing package name for uninstallation");
fpm::uninstall_package(argv[2]);
} else if (action == "configure" || action == "c") {
if (!fpm::is_root()) throw runtime_error("Failed to run! Are you root?");
if (argc < 4) throw invalid_argument("Invalid configure command");
string typeStr = argv[2];
int type = (typeStr == "config") ? 1 : (typeStr == "dir") ? 2 : (typeStr == "diruser") ? 3 : 0;
fpm::configure_system(type, argv[3]);
} else if (action == "about") {
fpm::print_about();
} else if (action=="fasturl"){
cout << fpm::findbestmirror() << endl;
} else {
cerr << "Invalid action: " << action << endl;
return 1;
}
} catch (const exception& e) {
cerr << "Error: " << e.what() << endl;
return 1;
}
return 0;
}