mirror of
https://github.com/anikeen-com/print-cli.git
synced 2026-03-19 08:36:06 +00:00
Add init commands
This commit is contained in:
92
app/Commands/InitCommand.php
Normal file
92
app/Commands/InitCommand.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use LaravelZero\Framework\Commands\Command;
|
||||||
|
use Smalot\Cups\Builder\Builder;
|
||||||
|
use Smalot\Cups\Manager\PrinterManager;
|
||||||
|
use Smalot\Cups\Model\Printer;
|
||||||
|
use Smalot\Cups\Transport\Client;
|
||||||
|
use Smalot\Cups\Transport\ResponseParser;
|
||||||
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
|
class InitCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'init';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Create a print-cli configuration file';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$username = getenv('USER') ?: get_current_user();
|
||||||
|
$home = getenv('HOME');
|
||||||
|
|
||||||
|
$client = new Client();
|
||||||
|
$builder = new Builder();
|
||||||
|
$responseParser = new ResponseParser();
|
||||||
|
|
||||||
|
$printerManager = new PrinterManager($builder, $client, $responseParser);
|
||||||
|
|
||||||
|
$printers = Collection::make($printerManager->getList());
|
||||||
|
|
||||||
|
if ($printers->isEmpty()) {
|
||||||
|
$this->error('We could not find any printers! Setup them first :)');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Please register printers first at:');
|
||||||
|
$this->info('https://events.anikeen.com/console/resources/printers');
|
||||||
|
|
||||||
|
$password = $this->ask('What is your password?', match ($username) {
|
||||||
|
'print-cli' => 'print-cli',
|
||||||
|
'orangepi' => 'orangepi',
|
||||||
|
default => null,
|
||||||
|
});
|
||||||
|
|
||||||
|
$filename = $home . '/print-cli.yml';
|
||||||
|
|
||||||
|
$yaml = Yaml::dump(
|
||||||
|
input: [
|
||||||
|
'base_url' => 'https://events.anikeen.com',
|
||||||
|
'printers' => $printers->map(function (Printer $printer) use ($username, $password) {
|
||||||
|
$attributes = $printer->getAttributes();
|
||||||
|
|
||||||
|
$id = $this->ask(sprintf('What is your ID for %s?', $printer->getName()));
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $id,
|
||||||
|
'name' => $printer->getName(),
|
||||||
|
'driver' => 'cups',
|
||||||
|
'address' => $attributes['printer-uri-supported'][0],
|
||||||
|
'username' => $username,
|
||||||
|
'password' => $password,
|
||||||
|
];
|
||||||
|
})->toArray(),
|
||||||
|
],
|
||||||
|
inline: 100,
|
||||||
|
indent: 2,
|
||||||
|
flags: Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK
|
||||||
|
);
|
||||||
|
|
||||||
|
file_put_contents(
|
||||||
|
filename: $filename,
|
||||||
|
data: preg_replace('/-\n\s+/', '- ', $yaml)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->info(sprintf('Created configuration at %s', $filename));
|
||||||
|
}
|
||||||
|
}
|
||||||
45
app/Commands/InitSupervisorCommand.php
Normal file
45
app/Commands/InitSupervisorCommand.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Commands;
|
||||||
|
|
||||||
|
use LaravelZero\Framework\Commands\Command;
|
||||||
|
|
||||||
|
class InitSupervisorCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'init:supervisor';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Create a supervisor configuration file';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$username = getenv('USER') ?: get_current_user();
|
||||||
|
$home = getenv('HOME');
|
||||||
|
|
||||||
|
$ini = <<<INI
|
||||||
|
[program:print-cli]
|
||||||
|
directory = $home
|
||||||
|
command = /usr/bin/php $home/.config/composer/vendor/bin/print-cli serve
|
||||||
|
autostart = true
|
||||||
|
autorestart = true
|
||||||
|
stderr_logfile = /var/log/print-cli.err.log
|
||||||
|
stdout_logfile = /var/log/print-cli.out.log
|
||||||
|
stopwaitsecs = 3600
|
||||||
|
user = $username
|
||||||
|
INI;
|
||||||
|
|
||||||
|
echo $ini;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ Recommended configuration:
|
|||||||
|
|
||||||
**Tested Printers:**
|
**Tested Printers:**
|
||||||
|
|
||||||
|
- EPSON ET-2750 Series with driver: Epson Expression ET-2750 EcoTank - CUPS+Gutenprint v5.3.3 (color)
|
||||||
- EPSON ET-2860 Series with driver: Epson Expression ET-2750 EcoTank - CUPS+Gutenprint v5.3.3 (color)
|
- EPSON ET-2860 Series with driver: Epson Expression ET-2750 EcoTank - CUPS+Gutenprint v5.3.3 (color)
|
||||||
|
|
||||||
Next, we need to install the required packages for Print-CLI to work. Run the following commands and grab a coffee while
|
Next, we need to install the required packages for Print-CLI to work. Run the following commands and grab a coffee while
|
||||||
@@ -102,23 +103,10 @@ composer global require anikeen/print-cli
|
|||||||
|
|
||||||
## Step 5: Configure Print-CLI
|
## Step 5: Configure Print-CLI
|
||||||
|
|
||||||
In this tutorial, we're using the home directory of the `print-cli` user to store the configuration file. If you're
|
With the latest version, you can automatically create your `/home/orangepi/print-cli.yml` with:
|
||||||
using a different user, make sure to replace `print-cli` with the correct username.
|
|
||||||
|
|
||||||
Next create a configuration file `~/print-cli.yml`, and add the following content:
|
```bash
|
||||||
|
print-cli init
|
||||||
> Make sure to replace the `your-printer-uuid`, `address`, `username`, and `password` with your own
|
|
||||||
> values. Also make sure to replace the `base_url` with the correct URL to our events platform.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
base_url: 'https://events.anikeen.com'
|
|
||||||
printers:
|
|
||||||
- id: 'your-printer-uuid'
|
|
||||||
name: EPSON ET 2750
|
|
||||||
driver: cups
|
|
||||||
address: 'ipp://127.0.0.1:631/printers/EPSON_ET_2720_Series'
|
|
||||||
username: 'orangepi'
|
|
||||||
password: 'orangepi'
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To test the configuration, run the following command:
|
To test the configuration, run the following command:
|
||||||
@@ -144,16 +132,8 @@ and control a number of processes on UNIX-like operating systems.
|
|||||||
|
|
||||||
Create a new configuration file `/etc/supervisor/conf.d/print-cli.conf`:
|
Create a new configuration file `/etc/supervisor/conf.d/print-cli.conf`:
|
||||||
|
|
||||||
```ini
|
```bash
|
||||||
[program:print-cli]
|
print-cli init:supervisor | sudo tee /etc/supervisor/conf.d/print-cli.conf > /dev/null
|
||||||
directory = /home/orangepi
|
|
||||||
command = /usr/bin/php /home/orangepi/.config/composer/vendor/bin/print-cli serve
|
|
||||||
autostart = true
|
|
||||||
autorestart = true
|
|
||||||
stderr_logfile = /var/log/print-cli.err.log
|
|
||||||
stdout_logfile = /var/log/print-cli.out.log
|
|
||||||
stopwaitsecs = 3600
|
|
||||||
user = print-cli
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Now, update Supervisor to read the new configuration file and start the Print-CLI service:
|
Now, update Supervisor to read the new configuration file and start the Print-CLI service:
|
||||||
@@ -167,3 +147,33 @@ sudo supervisorctl start print-cli
|
|||||||
## WLAN
|
## WLAN
|
||||||
|
|
||||||
https://www.makeuseof.com/connect-to-wifi-with-nmcli/
|
https://www.makeuseof.com/connect-to-wifi-with-nmcli/
|
||||||
|
|
||||||
|
## Printer Offsets
|
||||||
|
|
||||||
|
### EPSON ET-2750 Series (with Gutenprint @ OrangePI)
|
||||||
|
|
||||||
|
> Some other OS and drivers need other offsets.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"badge": {
|
||||||
|
"offset": {
|
||||||
|
"y": 0,
|
||||||
|
"x": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### EPSON ET-2860 Series (Unconfirmed)
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"badge": {
|
||||||
|
"offset": {
|
||||||
|
"y": 0,
|
||||||
|
"x": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
31
raspberry.md
31
raspberry.md
@@ -88,23 +88,10 @@ composer global require anikeen/print-cli
|
|||||||
|
|
||||||
## Step 5: Configure Print-CLI
|
## Step 5: Configure Print-CLI
|
||||||
|
|
||||||
In this tutorial, we're using the home directory of the `print-cli` user to store the configuration file. If you're
|
With the latest version, you can automatically create your `/home/print-cli/print-cli.yml` with:
|
||||||
using a different user, make sure to replace `print-cli` with the correct username.
|
|
||||||
|
|
||||||
Next create a configuration file `~/print-cli.yml`, and add the following content:
|
```bash
|
||||||
|
print-cli init
|
||||||
> Make sure to replace the `your-printer-uuid`, `address`, `username`, and `password` with your own
|
|
||||||
> values. Also make sure to replace the `base_url` with the correct URL to our events platform.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
base_url: 'https://events.anikeen.com'
|
|
||||||
printers:
|
|
||||||
- id: 'your-printer-uuid'
|
|
||||||
name: EPSON ET 2750
|
|
||||||
driver: cups
|
|
||||||
address: 'ipp://127.0.0.1:631/printers/EPSON_ET_2720_Series'
|
|
||||||
username: 'print-cli'
|
|
||||||
password: 'password'
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To test the configuration, run the following command:
|
To test the configuration, run the following command:
|
||||||
@@ -130,16 +117,8 @@ and control a number of processes on UNIX-like operating systems.
|
|||||||
|
|
||||||
Create a new configuration file `/etc/supervisor/conf.d/print-cli.conf`:
|
Create a new configuration file `/etc/supervisor/conf.d/print-cli.conf`:
|
||||||
|
|
||||||
```ini
|
```bash
|
||||||
[program:print-cli]
|
print-cli init:supervisor | sudo tee /etc/supervisor/conf.d/print-cli.conf > /dev/null
|
||||||
directory = /home/print-cli
|
|
||||||
command = /usr/bin/php /home/print-cli/.config/composer/vendor/bin/print-cli serve
|
|
||||||
autostart = true
|
|
||||||
autorestart = true
|
|
||||||
stderr_logfile = /var/log/print-cli.err.log
|
|
||||||
stdout_logfile = /var/log/print-cli.out.log
|
|
||||||
stopwaitsecs = 3600
|
|
||||||
user = print-cli
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Now, update Supervisor to read the new configuration file and start the Print-CLI service:
|
Now, update Supervisor to read the new configuration file and start the Print-CLI service:
|
||||||
|
|||||||
Reference in New Issue
Block a user