-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall
executable file
·86 lines (77 loc) · 1.99 KB
/
uninstall
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
#!/usr/bin/hhvm
<?hh
// define some constants
define('MANGO_INSTALL_PATH', '/usr/lib/mango');
define('MANGO_BINARY_PATH', '/usr/bin/mango');
function printLn(string $line) : void {
printf("%s\n", $line);
}
function usage(string $message) : void {
printLn(" uninstall: $message");
printLn(" usage: uninstall [-y|--yes]");
printLn("");
printLn(" options:");
printLn(" -y|--yes: non-interactive mode");
printLn("");
exit(1);
}
function error(string $message) : void {
printLn("fatal error: $message");
exit(1);
}
function removeDirectory(string $path) : void {
if (file_exists($path)) {
$dir = scandir($path);
foreach ($dir as $f) {
if ($f != '.' && $f != '..') {
$fullPath = "$path/$f";
if (is_dir($fullPath)) {
removeDirectory($fullPath);
} else {
unlink($fullPath);
}
}
}
rmdir($path);
}
}
function proceed(string $message, bool $skip = false) : bool {
if (!$skip) {
printf("%s [Y/n] ", $message);
$stdin = fopen('php://stdin', 'r');
$input = trim(fgets($stdin));
if ($input == 'n') {
return false;
} else {
return true;
}
} else {
return true;
}
}
// parse command line arguments
$NON_INTERACTIVE_MODE = false;
$opts = getopt('y', array('yes'));
foreach (array_keys($opts) as $opt) {
if ($opt == 'y' || $opt == 'yes') {
$NON_INTERACTIVE_MODE = true;
} else {
usage("Unknown argument: $opt");
}
}
// begin uninstallation
if (!$NON_INTERACTIVE_MODE) {
printLn("====================================================================");
printLn("Mango Framework Uninstaller");
printLn("====================================================================");
printLn("This script will completely remove mango frameowrk and all installed");
printLn("libraries from your system");
printLn("");
}
if (proceed('Do you wish to proceed with the uninstallation?', $NON_INTERACTIVE_MODE)) {
printLn("* Removing mango framework and libraries...");
removeDirectory(MANGO_INSTALL_PATH);
printLn("All done!");
} else {
printLn("Aborted!");
}