File size: 1,065 Bytes
fbf3c28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
id: apt
title: Apt Package Manager (unsafe)
author: admin
description: Install/remove packages via apt-get.
version: 0.1.0
license: Proprietary
"""

import subprocess


def _run(cmd: str) -> dict:
    p = subprocess.run(["bash", "-lc", cmd], capture_output=True, text=True)
    return {
        "cmd": cmd,
        "stdout": p.stdout,
        "stderr": p.stderr,
        "exit_code": p.returncode,
    }


class Tools:
    def update(self) -> dict:
        """apt-get update."""
        return _run("apt-get update -y")

    def install(self, package: str) -> dict:
        """apt-get install <package>."""
        return _run(f"apt-get install -y {package}")

    def remove(self, package: str) -> dict:
        """apt-get remove <package>."""
        return _run(f"apt-get remove -y {package}")

    def purge(self, package: str) -> dict:
        """apt-get purge <package>."""
        return _run(f"apt-get purge -y {package}")

    def autoremove(self) -> dict:
        """apt-get autoremove --purge."""
        return _run("apt-get autoremove --purge -y")