Esempio n. 1
0
def chmod(fname, permissions):
    current = sc("stat -c %a {fname}")
    if current == permissions:
        print(lf("{fname}: OK"))
        return False
    else:
        if el.HOST is not None:
            scb("chmod {permissions} {fname}")
        else:
            cmd = sudo(lf("chmod {permissions} {fname}"), fname)
            bash(cmd)
        return True
Esempio n. 2
0
def systemctl_start(service):
    if not el.scb("systemctl is-active {service} || true") == "active\n":
        el.bash(lf("systemctl start {service}"))
        return True
    else:
        print(lf("{service}: OK"))
        return False
Esempio n. 3
0
def install_root_cert(certfile, certname=None):
    """Install root certificate to certificate trust store of applications using NSS"""
    install_package("libnss3-tools")
    name_crt = el.file_name_nondirectory(certfile) if certname is None else certname
    # Firefox and Chromium
    if not el.file_exists_p("/tmp/cert9.db.done"):
        dbs = el.sc_l("find ~/ -name cert9.db 2>/dev/null || true")
        for db in dbs:
            certdir = el.file_name_directory(db)
            el.scb("certutil -A -n '{name_crt}' -t 'TCu,Cu,Tu' -i {certfile} -d sql:{certdir}")
        el.barf("/tmp/cert9.db.done", "")
    # curl
    cp_cmd = cp_host if el.HOST else cp
    fname_crt = lf("/usr/local/share/ca-certificates/{name_crt}")
    cp_cmd(certfile, fname_crt)
    chmod(fname_crt, "644")
    name_pem = el.file_name_sans_extension(name_crt) + ".pem"
    fname_pem = lf("/etc/ssl/certs/{name_pem}")
    make(fname_pem, sudo("update-ca-certificates"))
    # wget
    install_package("ca-certificates")
    patch("/etc/wgetrc", ["+ca_directory=/etc/ssl/certs"])
Esempio n. 4
0
def apt_add_repository(url, categories, gpg_key=None):
    if gpg_key is None:
        distro = scb("lsb_release -cs")
        line = f"deb {url} {distro} {categories}"
        cmd = f"sudo apt-add-repository '{line}'"
    else:
        gpg_key_url = repo_url + gpg_key
        gpg_key_file = "/usr/share/keyrings/" + gpg_key
        make(gpg_key_file, f"wget -O $1 {gpg_key_url}")
        line = f"deb [signed-by={gpg_key_file}] {repo_url} {categories}"
        cmd = f"echo 'line' | sudo tee {fname}"
    fname = "/etc/apt/sources.list"
    if line in el.slurp_lines(fname):
        print(fname + ": OK")
    else:
        bash(cmd)
Esempio n. 5
0
def install_go(version="1.17.1"):
    existing_exe = shutil.which("go")
    if existing_exe:
        existing_version = el.re_find("go([0-9]+\\.[0-9]+\\.[0-9]+)", scb(f"{existing_exe} version"))
        print("Found go: ", existing_version)
        if existing_version == version:
            print("Versions match. Exit")
            return
        bash("sudo rm -rf /usr/local/go /usr/local/bin/go")

    tar_file = f"go{version}.linux-amd64.tar.gz"
    tar_file_full = el.expand_file_name(tar_file, "/tmp/")
    url = f"https://golang.org/dl/go{version}.linux-amd64.tar.gz"
    fname = wget(url, "~/Software/")
    make("/usr/local/go", [
        "sudo rm -rf '/usr/local/go'",
        f"cat {fname} | sudo tar -xz -C /usr/local"])
    make("/usr/local/bin/go", [
        "sudo ln -sf /usr/local/go/bin/go $@"])
Esempio n. 6
0
def package_installed_p_yum(package):
    res = scb("yum list installed '{package}' || true")
    return "Error: No matching Packages to list" not in res
Esempio n. 7
0
def package_installed_p_rpm(package):
    res = scb("rpm -q '{package}' || true")
    return "is not installed" not in res