summaryrefslogtreecommitdiff
path: root/src/UnattendedUpgrades.php
blob: 2322cef479c29cb0b177bc3d14696c54f5431ea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

namespace Dweipert\DevOps\UnattendedUpgrades;

use PHPIAC\Modules\AptModule;
use PHPIAC\Modules\TemplateModule;
use PHPIAC\Role\RoleInterface;
use PHPIAC\Task;

class UnattendedUpgrades implements RoleInterface
{
    public function __invoke(array $config = []): array
    {
        $config = array_replace_recursive(
            include dirname(__DIR__) . '/files/config.php',
            $config
        );

        return [
            (new Task())->setModule(new AptModule([
                'package' => 'unattended-upgrades',
                'updateCache' => true,
            ])),
            (new Task())->setModule(new TemplateModule([
                'src' => dirname(__DIR__) . '/files/auto-upgrades.twig',
                'dest' => '/etc/apt/apt.conf.d/20auto-upgrades',
                'vars' => $config,
                'owner' => 'root',
                'group' => 'root',
                'mode' => 0644,
                'force' => true,
            ])),
            (new Task())->setModule(new TemplateModule([
                'src' => dirname(__DIR__) . '/files/unattended-upgrades.twig',
                'dest' => '/etc/apt/apt.conf.d/50unattended-upgrades',
                'vars' => $config,
                'owner' => 'root',
                'group' => 'root',
                'mode' => 0644,
                'force' => true,
            ])),
        ];
    }
}