Skip to content

Instantly share code, notes, and snippets.

@clsource
Created March 2, 2024 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clsource/6684a86a9cd4cce924592451a0c44796 to your computer and use it in GitHub Desktop.
Save clsource/6684a86a9cd4cce924592451a0c44796 to your computer and use it in GitHub Desktop.
Fetch Website from Github
<?php
/*
* This function copy $source directory and all files
* and sub directories to $destination folder
* https://gist.github.com/gserrano/4c9648ec9eb293b9377b
*/
function recursive_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recursive_copy($src .'/'. $file, $dst .'/'. $file);
}
else {
copy($src .'/'. $file,$dst .'/'. $file);
}
}
}
closedir($dir);
}
// https://stackoverflow.com/a/3352564
function removedir($dir = "./tmp") {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $fileinfo) {
$todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
$todo($fileinfo->getRealPath());
}
rmdir($dir);
}
// Download latest version from Github
function download() {
$url = "https://github.com/<my-repo>/main.zip";
$filename = basename($url);
$downloaded = file_put_contents($filename, file_get_contents($url));
if (!$downloaded) {
die("Error downloading from " . $url);
}
$zip = new ZipArchive;
$zip->open($filename);
$zip->extractTo("./tmp");
$zip->close();
unlink($filename);
}
function main() {
download();
recursive_copy("./tmp/my-repo-main/docs/", "./");
removedir();
}
main();
echo "OK";
?>
#!sh
# Update Website with
# The latest Github Version
echo "Updating <url>"
curl <url>/update.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment