Skip to content

Commit

Permalink
Merge pull request #37 from cslant/tools
Browse files Browse the repository at this point in the history
create a command to update permission/owner for config files in Linux
  • Loading branch information
tanhongit authored Nov 24, 2023
2 parents b591cdd + 9ebb75a commit 5346a36
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 17 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and manage customization through messages and buttons on Telegram.
[![Total Downloads](https://img.shields.io/packagist/dt/cslant/laravel-telegram-git-notifier.svg?style=flat-square)](https://packagist.org/packages/cslant/laravel-telegram-git-notifier)
![Test Status](https://img.shields.io/github/actions/workflow/status/cslant/laravel-telegram-git-notifier/setup_test.yml?label=tests&branch=main)
![Code Style Status](https://img.shields.io/github/actions/workflow/status/cslant/laravel-telegram-git-notifier/php-cs-fixer.yml?label=code%20style&branch=main)
[![StyleCI](https://styleci.io/repos/656960426/shield)](https://styleci.io/repos/656960426)
[![StyleCI](https://styleci.io/repos/683727144/shield)](https://styleci.io/repos/683727144)
[![Quality Score](https://img.shields.io/scrutinizer/g/cslant/laravel-telegram-git-notifier.svg?style=flat-square)](https://scrutinizer-ci.com/g/cslant/laravel-telegram-git-notifier)
[![Maintainability](https://api.codeclimate.com/v1/badges/7ccaccebe9cd58ff3df5/maintainability)](https://codeclimate.com/github/cslant/laravel-telegram-git-notifier/maintainability)

Expand Down Expand Up @@ -36,3 +36,21 @@ Publication of configuration files:
```bash
php artisan vendor:publish --provider="CSlant\LaravelTelegramGitNotifier\Providers\TelegramGitNotifierServiceProvider" --tag="config_jsons"
```

## Fixing Permissions (for Linux)

If you are using Linux, you need to change the owner of the configuration files to the web server user and group (e.g. `www-data`).

The configuration files will be used to store the bot's settings and other information, so you need to change the owner of the configuration files to the web server user and group.

```bash
sudo php artisan config-json:change-owner www-data www-data
```

> Note:
> - `www-data` is the user and group of the web server, you can change it to your own user and group.
> - The first `www-data` is the user, and the second `www-data` is the group. (You can also use only the first `www-data` to represent both the user and the group)
## 📖 Documentation

...In construction...
40 changes: 40 additions & 0 deletions src/Commands/ChangeOwnerConfigJson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace CSlant\LaravelTelegramGitNotifier\Commands;

use Illuminate\Console\Command;

class ChangeOwnerConfigJson extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'config-json:change-owner
{user : The user to change owner}
{group? : The group to change owner}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'config-json';

/**
* Execute the console command.
*
* @return void
*/
public function handle(): void
{
$user = $this->argument('user');
$group = $this->argument('group') ?? $user;

$jsonsPath = config('telegram-git-notifier.data_file.storage_folder');
if (is_string($jsonsPath) && file_exists($jsonsPath)) {
exec("chown -R $user:$group $jsonsPath");
}
}
}
52 changes: 36 additions & 16 deletions src/Providers/TelegramGitNotifierServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CSlant\LaravelTelegramGitNotifier\Providers;

use CSlant\LaravelTelegramGitNotifier\Commands\ChangeOwnerConfigJson;
use Illuminate\Support\ServiceProvider;

class TelegramGitNotifierServiceProvider extends ServiceProvider
Expand All @@ -25,23 +26,9 @@ public function boot(): void

$this->loadTranslationsFrom(__DIR__.'/../../lang', 'tg-notifier');

$configPath = __DIR__.'/../../config/telegram-git-notifier.php';
$this->publishes([
$configPath => config_path('telegram-git-notifier.php'),
], 'config');

$this->publishes([
__DIR__.'/../../resources/views' => config('telegram-git-notifier.defaults.paths.views'),
], 'views');

$this->publishes([
__DIR__.'/../../lang' => resource_path('lang/vendor/tg-notifier'),
], 'lang');
$this->registerCommands();

// copy config jsons from core package and ensure permissions are correct
$this->publishes([
__DIR__.'/../../../telegram-git-notifier/config/jsons' => config('telegram-git-notifier.data_file.storage_folder'),
], 'config_jsons');
$this->registerAssetPublishing();
}

/**
Expand All @@ -64,4 +51,37 @@ public function provides(): ?array
{
return ['telegram-git-notifier'];
}

/**
* @return void
*/
protected function registerCommands(): void
{
$this->commands([
ChangeOwnerConfigJson::class,
]);
}

/**
* @return void
*/
protected function registerAssetPublishing(): void
{
$configPath = __DIR__.'/../../config/telegram-git-notifier.php';
$this->publishes([
$configPath => config_path('telegram-git-notifier.php'),
], 'config');

$this->publishes([
__DIR__.'/../../resources/views' => config('telegram-git-notifier.defaults.paths.views'),
], 'views');

$this->publishes([
__DIR__.'/../../lang' => resource_path('lang/vendor/tg-notifier'),
], 'lang');

$this->publishes([
__DIR__.'/../../../telegram-git-notifier/config/jsons' => config('telegram-git-notifier.data_file.storage_folder'),
], 'config_jsons');
}
}

0 comments on commit 5346a36

Please sign in to comment.