Skip to content

Instantly share code, notes, and snippets.

@nickvergessen
Last active March 7, 2017 13:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickvergessen/e78eac9c84cc0e0d91d50723f3e43166 to your computer and use it in GitHub Desktop.
Save nickvergessen/e78eac9c84cc0e0d91d50723f3e43166 to your computer and use it in GitHub Desktop.
A little php script that creates sym links for the latest daily builds within a directory
<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2016 Joas Schilling
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
$dir = '/home/nickv/Schreibtisch/test';
$directory = new \DirectoryIterator($dir);
$latest = [];
$latestStable = 0;
echo 'Starting to scan: ' . $dir . "\n";
foreach ($directory as $file) {
if (strpos($file->getFilename(), 'latest') === 0) {
// Delete old latest links
unlink($dir . '/' . $file->getFilename());
continue;
}
if (!preg_match('/^nextcloud\-(\d+|master)\-daily\-(\d{4}-\d{2}-\d{2})\.zip\.md5$/i', $file->getFilename(), $matches)) {
continue;
}
list($file, $branch, $date) = $matches;
echo 'Found version: ' . $branch . ' - ' . $date . "\n";
if ($branch !== 'master') {
$branch = (int) $branch;
$latestStable = (int) max($latestStable, $branch);
}
if (!isset($latest[$branch]) || $latest[$branch] < $date) {
$latest[$branch] = $date;
}
}
// Files to create symlinks for
$symlinks = [
'.tar.bz2', '.tar.bz2.asc',
'.zip', '.zip.asc',
];
$copyPaste = [
'.tar.bz2.md5', '.tar.bz2.sha256', '.tar.bz2.sha512',
'.zip.md5', '.zip.sha256', '.zip.sha512',
];
foreach ($latest as $branch => $date) {
$versionName = 'nextcloud-' . $branch . '-daily-' . $date;
$latestName = $branch === 'master' ? 'latest-' . $branch : 'latest-stable' . $branch;
foreach ($symlinks as $suffix) {
// latest-stable*.zip to latest daily of the specific branch.
symlink($dir . '/' . $versionName . $suffix, $dir . '/' . $latestName . $suffix);
}
foreach ($copyPaste as $suffix) {
// latest-stable*.zip.md5 to latest daily of the specific branch.
$content = file_get_contents($dir . '/' . $versionName . $suffix);
$content = str_replace(' ' . $versionName . '.', ' ' . $latestName . '.', $content);
file_put_contents($dir . '/' . $latestName . $suffix, $content);
}
if ($branch === $latestStable) {
$latestName = 'latest';
// latest.zip to latest daily of the latest branch.
foreach ($symlinks as $suffix) {
symlink($dir . '/' . $versionName . $suffix, $dir . '/' . $latestName . $suffix);
}
foreach ($copyPaste as $suffix) {
// latest.zip.md5 to latest daily of the latest branch.
$content = file_get_contents($dir . '/' . $versionName . $suffix);
$content = str_replace(' ' . $versionName . '.', ' ' . $latestName . '.', $content);
file_put_contents($dir . '/' . $latestName . $suffix, $content);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment