forked from apachesep/QuipuForJoomla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.php
executable file
·87 lines (70 loc) · 2.3 KB
/
deploy.php
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/php -q
<?php
$deploy_dir = 'target';
$versions_dir = 'updates';
$updates_file = "$versions_dir/quipu-update.xml";
$src_dir = 'src';
$prod_name = 'quipu';
$dist_file_pref = 'com_quipu-';
$dist_file_suf = '.zip';
if(!is_dir($versions_dir)){
mkdir($versions_dir);
}
echo "Delete and recreate $deploy_dir...\n";
echo shell_exec("rm -rf $deploy_dir");
mkdir($deploy_dir);
echo "Copy $src_dir to $deploy_dir...\n";
echo shell_exec("rsync -a --exclude-from 'deploy-excludes.txt' $src_dir/* $deploy_dir/");
$descriptor = "$deploy_dir/$prod_name.xml";
$version = getVersion($descriptor);
echo "Version number detected: $version\n";
$filename = str_replace(' ', '-', $dist_file_pref.$version.$dist_file_suf);
if(is_file("$versions_dir/$filename")){
die("\nERROR: $versions_dir/$filename exists. Change version number or delete old file.\n");
}
$res = shell_exec("cd $deploy_dir; zip -r ../$versions_dir/$filename ./*;cd ..;");
echo "$res\n";
echo "$filename generated successfully.\n";
echo "Updating updates file...\n";
$xml = file_get_contents($updates_file);
$info = generateUpdateInfo($version,$filename);
$xml = str_replace('</updates>',"\n$info\n</updates>",$xml);
file_put_contents($updates_file,$xml);
echo "DONE :-)\n";
/**
* Adds update info to update xml file
**/
function generateUpdateInfo($version,$filename){
$xml = "
<update>
<name>COM_QUIPU</name>
<description>Quipu ERP</description>
<element>com_quipu</element>
<type>component</type>
<version>$version</version>
<infourl title=\"Quipu ERP\">https://github.com/NachoBrito/QuipuForJoomla</infourl>
<downloads>
<downloadurl type=\"full\" format=\"zip\">http://deploy.local/quipu/updates/$filename</downloadurl>
</downloads>
<tags>
<tag>Alpha</tag>
</tags>
<maintainer>Nacho Brito</maintainer>
<maintainerurl>http://www.nachobrito.com</maintainerurl>
<section>some-section</section>
<targetplatform name=\"joomla\" version=\"2.5\" />
</update>
";
return $xml;
}
/**
* reads product version from descriptor
*/
function getVersion($descriptor){
echo "Reading version from file $descriptor\n";
$file = file_get_contents($descriptor);
$i = strpos($file,'<version>') + 9;
$j = strpos($file,'</version>');
$v = substr($file,$i,($j - $i));
return $v;
}