Created
March 2, 2024 17:26
-
-
Save clsource/6684a86a9cd4cce924592451a0c44796 to your computer and use it in GitHub Desktop.
Fetch Website from Github
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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