You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.9 KiB
Python
98 lines
2.9 KiB
Python
2 years ago
|
import os
|
||
|
import time
|
||
2 years ago
|
import logging
|
||
2 years ago
|
import subprocess
|
||
2 years ago
|
|
||
2 years ago
|
from sugar_cubes.utils import checks
|
||
|
from sugar_cubes.utils.apt import Apt
|
||
|
from sugar_cubes.utils.flatpak import Flatpak
|
||
|
from sugar_cubes.utils.snap import Snap
|
||
2 years ago
|
|
||
|
|
||
2 years ago
|
logger = logging.getLogger("SugarCubes::Configurator")
|
||
2 years ago
|
|
||
2 years ago
|
|
||
2 years ago
|
class Configurator:
|
||
|
|
||
2 years ago
|
def __init__(self, config: 'Config', fake: bool = False):
|
||
2 years ago
|
self.config = config
|
||
2 years ago
|
self.fake = fake
|
||
2 years ago
|
|
||
|
def apply(self):
|
||
|
self.__enable_snap() if self.config.snap else self.__disable_snap()
|
||
|
self.__enable_flatpak() if self.config.flatpak else self.__disable_flatpak()
|
||
|
self.__enable_apport() if self.config.apport else self.__disable_apport()
|
||
2 years ago
|
if self.config.distrobox:
|
||
|
self.__enable_distrobox()
|
||
2 years ago
|
|
||
2 years ago
|
def __fake(self, msg: str):
|
||
|
time.sleep(1)
|
||
|
logger.info(f"Fake: {msg}")
|
||
|
|
||
2 years ago
|
def __enable_snap(self):
|
||
2 years ago
|
if self.fake:
|
||
2 years ago
|
return self.__fake("Fake: Snap enabled")
|
||
2 years ago
|
|
||
2 years ago
|
if not checks.is_snap_installed():
|
||
2 years ago
|
Apt.install(['snapd', 'gnome-software-plugin-snap'])
|
||
|
Apt.update()
|
||
2 years ago
|
|
||
|
if not self.config.flatpak:
|
||
|
Snap.install(['snap-store'])
|
||
2 years ago
|
|
||
2 years ago
|
def __disable_snap(self):
|
||
2 years ago
|
if self.fake:
|
||
2 years ago
|
return self.__fake("Fake: Snap disabled")
|
||
2 years ago
|
|
||
2 years ago
|
if checks.is_snap_installed():
|
||
|
Apt.purge(['snapd'])
|
||
2 years ago
|
|
||
2 years ago
|
def __enable_flatpak(self):
|
||
2 years ago
|
if self.fake:
|
||
2 years ago
|
return self.__fake("Fake: Flatpak enabled")
|
||
2 years ago
|
|
||
2 years ago
|
if not checks.is_flatpak_installed():
|
||
|
Apt.install(['flatpak'])
|
||
2 years ago
|
Apt.update()
|
||
2 years ago
|
Flatpak.add_repo("https://flathub.org/repo/flathub.flatpakrepo")
|
||
|
|
||
|
def __disable_flatpak(self):
|
||
2 years ago
|
if self.fake:
|
||
2 years ago
|
return self.__fake("Fake: Flatpak disabled")
|
||
2 years ago
|
|
||
2 years ago
|
if checks.is_flatpak_installed():
|
||
|
Apt.purge(['flatpak'])
|
||
2 years ago
|
|
||
|
def __enable_apport(self):
|
||
|
if self.fake:
|
||
2 years ago
|
return self.__fake("Fake: Apport enabled")
|
||
2 years ago
|
|
||
|
if not checks.is_apport_installed():
|
||
|
Apt.install(['apport'])
|
||
2 years ago
|
Apt.update()
|
||
2 years ago
|
|
||
|
def __disable_apport(self):
|
||
|
if self.fake:
|
||
2 years ago
|
return self.__fake("Fake: Apport disabled")
|
||
2 years ago
|
|
||
|
if checks.is_apport_installed():
|
||
|
Apt.purge(['apport'])
|
||
2 years ago
|
|
||
|
def __enable_distrobox(self):
|
||
|
if self.fake:
|
||
|
return self.__fake("Fake: Distrobox enabled")
|
||
|
|
||
|
Apt.install(['curl', 'podman'])
|
||
|
Apt.update()
|
||
|
|
||
|
proc = subprocess.run(['curl', '-s', 'https://raw.githubusercontent.com/89luca89/distrobox/main/install'], stdout=subprocess.PIPE)
|
||
|
proc = subprocess.run(['sudo', 'sh'], input=proc.stdout, stdout=subprocess.PIPE)
|
||
2 years ago
|
|
||
|
def __disable_on_startup(self):
|
||
|
if self.fake:
|
||
|
return self.__fake("Fake: Disable on startup")
|
||
|
|
||
2 years ago
|
autostart_file = os.path.expanduser("~/.config/autostart/sugar-cubes.desktop")
|
||
2 years ago
|
if os.path.exists(autostart_file):
|
||
|
os.remove(autostart_file)
|