Skip to content

Commit 5346a36

Browse files
authored
Merge pull request #37 from cslant/tools
create a command to update permission/owner for config files in Linux
2 parents b591cdd + 9ebb75a commit 5346a36

File tree

3 files changed

+95
-17
lines changed

3 files changed

+95
-17
lines changed

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ and manage customization through messages and buttons on Telegram.
88
[![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)
99
![Test Status](https://img.shields.io/github/actions/workflow/status/cslant/laravel-telegram-git-notifier/setup_test.yml?label=tests&branch=main)
1010
![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)
11-
[![StyleCI](https://styleci.io/repos/656960426/shield)](https://styleci.io/repos/656960426)
11+
[![StyleCI](https://styleci.io/repos/683727144/shield)](https://styleci.io/repos/683727144)
1212
[![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)
1313
[![Maintainability](https://api.codeclimate.com/v1/badges/7ccaccebe9cd58ff3df5/maintainability)](https://codeclimate.com/github/cslant/laravel-telegram-git-notifier/maintainability)
1414

@@ -36,3 +36,21 @@ Publication of configuration files:
3636
```bash
3737
php artisan vendor:publish --provider="CSlant\LaravelTelegramGitNotifier\Providers\TelegramGitNotifierServiceProvider" --tag="config_jsons"
3838
```
39+
40+
## Fixing Permissions (for Linux)
41+
42+
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`).
43+
44+
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.
45+
46+
```bash
47+
sudo php artisan config-json:change-owner www-data www-data
48+
```
49+
50+
> Note:
51+
> - `www-data` is the user and group of the web server, you can change it to your own user and group.
52+
> - 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)
53+
54+
## 📖 Documentation
55+
56+
...In construction...
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace CSlant\LaravelTelegramGitNotifier\Commands;
4+
5+
use Illuminate\Console\Command;
6+
7+
class ChangeOwnerConfigJson extends Command
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'config-json:change-owner
15+
{user : The user to change owner}
16+
{group? : The group to change owner}';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'config-json';
24+
25+
/**
26+
* Execute the console command.
27+
*
28+
* @return void
29+
*/
30+
public function handle(): void
31+
{
32+
$user = $this->argument('user');
33+
$group = $this->argument('group') ?? $user;
34+
35+
$jsonsPath = config('telegram-git-notifier.data_file.storage_folder');
36+
if (is_string($jsonsPath) && file_exists($jsonsPath)) {
37+
exec("chown -R $user:$group $jsonsPath");
38+
}
39+
}
40+
}

src/Providers/TelegramGitNotifierServiceProvider.php

+36-16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CSlant\LaravelTelegramGitNotifier\Providers;
44

5+
use CSlant\LaravelTelegramGitNotifier\Commands\ChangeOwnerConfigJson;
56
use Illuminate\Support\ServiceProvider;
67

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

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

28-
$configPath = __DIR__.'/../../config/telegram-git-notifier.php';
29-
$this->publishes([
30-
$configPath => config_path('telegram-git-notifier.php'),
31-
], 'config');
32-
33-
$this->publishes([
34-
__DIR__.'/../../resources/views' => config('telegram-git-notifier.defaults.paths.views'),
35-
], 'views');
36-
37-
$this->publishes([
38-
__DIR__.'/../../lang' => resource_path('lang/vendor/tg-notifier'),
39-
], 'lang');
29+
$this->registerCommands();
4030

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

4734
/**
@@ -64,4 +51,37 @@ public function provides(): ?array
6451
{
6552
return ['telegram-git-notifier'];
6653
}
54+
55+
/**
56+
* @return void
57+
*/
58+
protected function registerCommands(): void
59+
{
60+
$this->commands([
61+
ChangeOwnerConfigJson::class,
62+
]);
63+
}
64+
65+
/**
66+
* @return void
67+
*/
68+
protected function registerAssetPublishing(): void
69+
{
70+
$configPath = __DIR__.'/../../config/telegram-git-notifier.php';
71+
$this->publishes([
72+
$configPath => config_path('telegram-git-notifier.php'),
73+
], 'config');
74+
75+
$this->publishes([
76+
__DIR__.'/../../resources/views' => config('telegram-git-notifier.defaults.paths.views'),
77+
], 'views');
78+
79+
$this->publishes([
80+
__DIR__.'/../../lang' => resource_path('lang/vendor/tg-notifier'),
81+
], 'lang');
82+
83+
$this->publishes([
84+
__DIR__.'/../../../telegram-git-notifier/config/jsons' => config('telegram-git-notifier.data_file.storage_folder'),
85+
], 'config_jsons');
86+
}
6787
}

0 commit comments

Comments
 (0)