-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
net-install
115 lines (94 loc) · 3.59 KB
/
net-install
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
if(file_exists('scarlets')){
if(file_exists('vendor/scarletsfiction/scarlets/')){
echo("Looks like Scarlets Framework already installed\n");
die("Use `php scarlets upgrade` if you want to update\n");
}
}
$opts = [
'http'=>[
'method'=>"GET",
'header'=>"User-Agent: ScarletsFramework\n"
]
];
$context = stream_context_create($opts);
$root = __DIR__;
$status = file_get_contents('https://api.travis-ci.org/ScarletsFiction/Scarlets.svg?branch=master', 0, $context);
if(strpos($status, 'fail')!==false){
echo("\nCurrently the framework is unstable");
}
echo(" - Determining archive size\n");
$status = file_get_contents('https://api.github.com/repos/ScarletsFiction/Scarlets', 0, $context);
try{
$filesize = round(json_decode($status, true)['size']);
}catch(\Exception $e){
$filesize = '?';
}
echo(" - Downloading repository ($filesize KB)\n");
file_put_contents('master.zip', file_get_contents('https://github.com/ScarletsFiction/Scarlets/archive/master.zip'));
echo(" - Extracting files\n");
$zip = new ZipArchive;
$res = $zip->open('master.zip');
if(!file_exists($root.'/vendor/scarletsfiction/'))
mkdir($root.'/vendor/scarletsfiction/', 0777, true);
deleteContent($root.'/vendor/scarletsfiction/scarlets_backup/', true);
if(file_exists($root.'/vendor/scarletsfiction/scarlets'))
rename($root.'/vendor/scarletsfiction/scarlets', $root.'/vendor/scarletsfiction/scarlets_backup');
$zip->extractTo($root.'/vendor/scarletsfiction/');
$zip->close();
rename($root.'/vendor/scarletsfiction/Scarlets-master', $root.'/vendor/scarletsfiction/scarlets');
// Check if project already exist
if(file_exists($root.'/app') && file_exists($root.'/config') && file_exists($root.'/routes') && file_exists($root.'/scarlets'))
echo " + Project already exist\n";
// Create new project
else {
echo "\nDo you want to use this directory for your project? (y/n) ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim($line) != 'y'){
echo "Please type your directory:\n";
$root = trim(fgets($handle));
if(!file_exists($root))
mkdir($root, 0777, true);
}
fclose($handle);
echo(" - Moving files\n");
$list = array_slice(scandir($root.'/vendor/scarletsfiction/scarlets/example/'), 2);
foreach($list as $path){
// Skip if already exist
if(file_exists($root.'/'.$path))
continue;
// Move files
rename($root.'/vendor/scarletsfiction/scarlets/example/'.$path, $root.'/'.$path);
}
echo(" - Changing root folder (root.php)\n");
file_put_contents($root.'/root.php', str_replace('/../require.php', '/vendor/scarletsfiction/scarlets/require.php', file_get_contents($root.'/root.php')));
}
echo(" - Delete temporary file\n");
try{
deleteContent($root.'/vendor/scarletsfiction/scarlets/example/', true);
deleteContent($root.'/vendor/scarletsfiction/scarlets/evaluate/', true);
deleteContent($root.'/vendor/scarletsfiction/scarlets/images/', true);
deleteContent($root.'/vendor/scarletsfiction/scarlets/tests/', true);
unlink('master.zip');
} catch(\Exception $e) {
echo(" - Some temporary files was not found");
}
$list = ['.gitignore', '.htaccess', '.travis.yml', 'phpunit.xml'];
foreach ($list as &$value) {
unlink($root.'/vendor/scarletsfiction/scarlets/'.$value);
}
echo("\n - Task finished\n");
function deleteContent($path, $pathAlso = true){
if(!file_exists($path) || !is_dir($path)) return;
$iterator = new DirectoryIterator($path);
foreach($iterator as $fileinfo){
if($fileinfo->isDot()) continue;
elseif($fileinfo->isDir())
deleteContent($fileinfo->getPathname(), true);
elseif($fileinfo->isFile())
@unlink($fileinfo->getPathname());
}
if($pathAlso) @rmdir($path);
return true;
}