PHP to grab and untar code from a mercurial repository?
I have a private repository setup on bitbucket that has code for a website project that I am working on. The website sits on a web server with another company and has a password protected directory within it (eg. playground
) which I use for testing before making things live.
Now I k开发者_开发百科now I can set up a bitbucket service that can make HTTP POST requests and I have also been told I can set up a PHP on the webserver that will go and grab the repository from bitbucket and untar it into the specified directory.
As you have rightly guessed, I am looking for some pointers on this PHP script that will do just this. Any example code/tutorial/articles would be most helpful.
Thanks!
You just need to have your PHP get a URL like this:
https://bitbucket.org/adium/adium/get/tip.tar.gz
using a library like these:
- http://scripts.incutio.com/httpclient/
- http://php.net/manual/en/book.curl.php
substituting your username and repository name for both adiums. That will get you the .tar.gz and then you can open it up using either a shell command or a combination of http://php.net/manual/en/book.zlib.php and something like this: http://www.devshed.com/c/a/PHP/TAR-File-Management-With-PHP-Archive-Tar/
Here's another library that does the same thing: http://www.techrepublic.com/article/create-and-edit-tar-archives-dynamically-with-php-and-pear/6161314
You can use shell command directly in php. Use this:
shell_exec(<shell_command>);
For example you want to delete some file, in UNIX server you can call it this way:
shell_exec('rm test.txt')';
If you are running on Windows, you can use MS-DOS command, tho I am not really familiar with it aside of dir, lol.
Hope this helps.
精彩评论