laravel-console-self-update maintained by hnhdigital-os
.__ _____ .___ __
______ ____ | |_/ ____\ __ ________ __| _/____ _/ |_ ____
/ ___// __ \| |\ __\ ______ | | \____ \ / __ |\__ \\ __\/ __ \
\___ \\ ___/| |_| | /_____/ | | / |_> > /_/ | / __ \| | \ ___/
/____ >\___ >____/__| |____/| __/\____ |(____ /__| \___ >
\/ \/ |__| \/ \/ \/
Provides a trait to provide self-updating for Laravel Zero console applications.
This package has been developed by H&H|Digital, an Australian botique developer. Visit us at hnh.digital.
Requirements
- PHP 7.1.3
- Laravel Zero 5.7
Installation
composer require hnhdigital-os/laravel-console-self-update
Implementation
This package is implemented through a trait and an interface (for the constants).
The basic implementation requires setting a base URL setUrl or providing a flysystem adapter setFlysystem before calling the runSelfUpdate method.
Binary versioning is implemented using BRANCH-TAG (eg stable-1.00) but will fallback to TAG (1.0.0) for the more common Laravel Zero version approach.
<?php
namespace App\Commands;
use HnhDigital\LaravelConsoleSelfUpdate\SelfUpdateInterface;
use HnhDigital\LaravelConsoleSelfUpdate\SelfUpdateTrait;
use LaravelZero\Framework\Commands\Command;
class SelfUpdateCommand extends Command implements SelfUpdateInterface
{
use SelfUpdateTrait;
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'self-update
{--tag=0 : Set a specific tag to install}
{--check-version : Return the version of this current binary}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Self-update this binary';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->setUrl('https://example.com');
$this->runSelfUpdate();
}
}
Latest version
The script checks /latest for the latest tag (eg it would contain 1.0.1).
Download path to binary
The download path for a specific binary version is sourced from a JSON encoded values sourced from /versions (default). You can override that by using setVersionsPath.
{
"1.0.0": "download/1.0.0/example-file",
"1.0.1": "download/1.0.1/example-file"
}
By default, the versions file is tag/path. If the versions file contains more than the path, the default path source can be overridden to a specific key using setVersionsTagKey.
For example:
{
"1.0.0": {"path": "download/1.0.0/example-file"},
"1.0.1": {"path": "download/1.0.1/example-file"}
}
...
public function handle()
{
...
$this->setVersionsTagKey('path');
...
}
...
Hash comparing
The downloaded file is hash checked (SHA256). This hash string by default is found in the same path as the download file path (download/1.0.1/sha256).
You can change the default source by overriding the setHashSource method and returning a different constant.
If there is a top level json encoded file storing the hashes, set the source to CHECKSUM_TOP_LEVEL. Specify the file path by using setHashPath.
NOTE: This array is keyed to the download path discovered through the versions file. It must match to be able to retrieve the hash.
...
public function handle()
{
...
$this->setHashSource(self::CHECKSUM_TOP_LEVEL);
$this->setHashPath('checksums');
...
}
...
{
"download/1.0.0/example-file": "...",
"download/1.0.1/example-file": "..."
}
If the hash is included in the versions file, set the source to CHECKSUM_VERSIONS. Specify the array key using setHashPath.
...
public function handle()
{
...
$this->setHashSource(self::CHECKSUM_VERSIONS);
$this->setHashPath('sha256');
...
}
...
{
"1.0.0": {"path": "download/1.0.0/example-file", "sha256": "..."},
"1.0.1": {"path": "download/1.0.1/example-file", "sha256": "..."}
}
Build scripts
Looking for a build script to help create all the necessary files?
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.