Exemple #1
0
 def run(self):
     print_header("Setting up Vim")
     if not "plugged" in self.args:
         self.check_nvim_installed()
         self.link_config()
     self.download_vim_plugged()
     run_command("nvim +PlugInstall +qall")
Exemple #2
0
    def run(self):
        if not platform.is_arch:
            return

        print_header("Setting up VNC")

        install_pkg("tigervnc", "lxde-gtk3")

        if file_exists("/etc/pam.d/tigervnc.pacnew"):
            move("/etc/pam.d/tigervnc.pacnew", "/etc/pam.d/tigervnc")

        link_files([
            [
                SCRIPT_DIR.joinpath("vncserver.users"),
                Path("/etc/tigervnc/vncserver.users"),
                True,
            ],
            [
                SCRIPT_DIR.joinpath("config"),
                Path.home().joinpath(".vnc", "config"),
                True,
            ],
        ])

        run_command("sudo systemctl enable vncserver@:1")
        run_command("sudo systemctl start vncserver@:1")
Exemple #3
0
def install_zsh_plugin(plugin, remote):
    print_line(f"Installing plugin {plugin}")
    plugin_dir = zsh_plugin_dir.joinpath(plugin)

    if not dir_exists(plugin_dir):
        run_command(f"git clone '{remote}' '{plugin_dir}'")

    run_command("git pull", cwd=plugin_dir)
Exemple #4
0
def install_homebrew(force=False):
    if not platform.is_mac or (not force and command_exists("brew")):
        return

    print_line("Installing Homebrew")
    run_command(
        '/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"',
        shell=True,
    )
Exemple #5
0
    def run(self):
        if not platform.is_mac:
            return

        print_header("Setting up macOS Finder")
        # Setup Finder to show all files
        run_command("defaults write com.apple.finder AppleShowAllFiles YES", shell=True)
        run_command(
            "killall Finder /System/Library/CoreServices/Finder.app", shell=True
        )
Exemple #6
0
    def run(self):
        print_header("Setting up Minicom")
        for file in ["dfl", "fast"]:
            link_file(
                Path(__file__).parent.joinpath(f".minirc.{file}"),
                Path.home().joinpath(f".minirc.{file}"),
            )
        install_pkg("minicom")

        if platform.is_linux:
            run_command("sudo usermod -a -G dialout $(whoami)", shell=True)
Exemple #7
0
    def run(self):
        if not platform.is_arch:
            return

        print_header("Setting up Pacman")
        link_file(SCRIPT_DIR.joinpath("pacman.conf"),
                  Path("/etc/pacman.conf"),
                  sudo=True)

        install_pkg("reflector", "arch-audit", "kernel-modules-hook")

        # Enable kernel module cleanup job
        run_command("sudo systemctl daemon-reload")
        run_command("sudo systemctl enable linux-modules-cleanup")

        # Hooks are symlinked individually to allow local hooks that are
        # not managed by this installer.
        with os.scandir(SCRIPT_DIR.joinpath("hooks")) as hooks:
            hook_dir = "/etc/pacman.d/hooks/"
            for item in hooks:
                link_file(item.path, Path(hook_dir + item.name), sudo=True)

        link_file(
            SCRIPT_DIR.joinpath("reflector.conf"),
            Path("/etc/xdg/reflector/reflector.conf"),
            sudo=True,
        )

        run_command("sudo systemctl enable reflector.timer")
        run_command("sudo systemctl start reflector.timer")
Exemple #8
0
    def run(self):
        print_header("Install fonts")
        os.makedirs(FONT_LIBRARY, exist_ok=True)

        reload_font = False
        for font in settings["fonts"]:
            reload_font = (
                install_font(font["remote"], FONT_LIBRARY.joinpath(font["name"]))
                or reload_font
            )

        if reload_font:
            print_line("Rescanning font caches")
            run_command("fc-cache -r")
Exemple #9
0
    def run(self):
        print_header("Setting up GPG")

        add_zsh_hook(Hook.POST, "10-gpg", SCRIPT_DIR.joinpath("setuphook.zsh"))
        add_fish_hook(Hook.POST, "10-gpg",
                      SCRIPT_DIR.joinpath("setuphook.fish"))

        if file_exists(INSTALLED_CANARY) and "force" not in self.args:
            print_line("GPG already setup")
            return

        # Use macOS binary location for consistancy
        if not file_exists("/usr/local/bin/gpg2"):
            link_file("/usr/bin/gpg2", "/usr/local/bin/gpg2", sudo=True)

        self.install_pkgs()

        os.makedirs(GNUPG_DIR, exist_ok=True)
        link_file(SCRIPT_DIR.joinpath("gpg.conf"),
                  GNUPG_DIR.joinpath("gpg.conf"))

        if platform.is_mac:
            link_file(
                SCRIPT_DIR.joinpath("gpg-agent.conf"),
                GNUPG_DIR.joinpath("gpg-agent.conf"),
            )
        else:
            remove(GNUPG_DIR.joinpath("gpg-agent.conf"))

        run_command_no_out(f"chmod -R og-rwx {str(GNUPG_DIR)}")

        gpg_key = settings["gpg"]["key"]
        print_line(f"GPG Key: {gpg_key}")

        # Import my public key and trust it ultimately
        if "nokey" not in self.args:
            run_command(f"gpg2 --recv-keys {gpg_key}")
            trust_key = f"{gpg_key}:6:"
            run_command(f"echo '{trust_key}' | gpg2 --import-ownertrust",
                        shell=True)

        if platform.is_fedora and file_exists(
                "/etc/xdg/autostart/gnome-keyring-ssh.desktop"):
            run_command(
                "sudo mv -f /etc/xdg/autostart/gnome-keyring-ssh.desktop /etc/xdg/autostart/gnome-keyring-ssh.desktop.inactive"
            )

        # Idempotency
        run_command('rm -f "$HOME/.gnupg/.dotfile-installed.*"', shell=True)
        run_command(f"touch {str(INSTALLED_CANARY)}")
Exemple #10
0
    def install_linux_pkgs(self):
        if platform.is_fedora:
            install_pkg(*self.settings["packages"]["linux"],
                        *self.settings["packages"]["fedora"])
        elif platform.is_ubuntu:
            install_pkg(*self.settings["packages"]["linux"],
                        *self.settings["packages"]["ubuntu"])
        elif platform.is_arch:
            packmgr.install_aur_helper()
            install_pkg(*self.settings["packages"]["linux"],
                        *self.settings["packages"]["arch"])

        run_command("sudo systemctl start haveged")
        run_command("sudo systemctl enable haveged")
Exemple #11
0
    def install_extensions(self):
        print_line("Installing VSCode Extensions", color=Color.MAGENTA)

        curr_exts = run_command_no_out(f"{EXE_NAME} --list-extensions")
        curr_exts = [
            s.lower() for s in curr_exts.stdout.split("\n") if s != ""
        ]

        needed_exts = [
            s.lower() for s in settings["vscode"]["extensions"]
            if s not in curr_exts
        ]

        for e in needed_exts:
            run_command(f"{EXE_NAME} --force --install-extension {e}")
Exemple #12
0
    def install_go_pkgs(self):
        print_line("Installing/updating Go packages", color=Color.MAGENTA)

        for pkg in self.settings["go"]["packages"]:
            proc = run_command(f"go get -u '{pkg}'")
            if proc.returncode == 0:
                print_line(f"Successfully downloaded {pkg}")
Exemple #13
0
    def show(self):
        """
            Reads content of blob and returns it as a pretty formated output.
        """

        level = '{0}:{1}'.format(self.rev, self.path)
        file_content = run_command(cmd='git cat-file -p {0}'.format(level), data=None, location=self.repo.location, chw=True)
        return file_content
Exemple #14
0
    def show(self):
        """
            Returns information about commit.
        """

        cmd = 'git show {0}'.format(self.sha1_hash)

        git_output = run_command(cmd=cmd, data=None, location=self.repo.location, chw=True)
        return git_output
Exemple #15
0
    def get_committer_name(self):
        """
            Returns committer name.
        """

        cmd='git log {0} -1 --format="%cn" {1}'.format(self.rev, self.sha1_hash)

        git_output = run_command(cmd=cmd, data=None, location=self.repo.location, chw=True).strip()
        return git_output
Exemple #16
0
    def get_committer_email(self):
        """
            Returns committer email.
        """

        cmd = 'git log -1 --format="%ce" {0} -- {1}'.format(self.rev, self.path)

        git_output = run_command(cmd=cmd, data=None, location=self.repo.location, chw=True).strip()
        return git_output
Exemple #17
0
    def get_subject(self):
        """
            Returns latest commit message given to this commit.
        """

        cmd='git log -1 --format="%s" {0}'.format(self.sha1_hash)

        git_output = run_command(cmd=cmd, data=None, location=self.repo.location, chw=True).strip()
        return git_output
Exemple #18
0
    def get_committer_date(self):
        """
            Returns latest commiter date for this commit in "ISO 8601-like" format and UTC timezone.
        """

        cmd='git log -1 --format="%ci" {0}'.format(self.sha1_hash)

        git_output = run_command(cmd=cmd, data=None, location=self.repo.location, chw=True)
        return time_to_utc(git_output.strip())
Exemple #19
0
def link_file(src: Path, dest: Path, sudo=False, copy=False):
    dest_dir = str(dest.parent)
    src = str(src)
    dest = str(dest)

    # Check if environment overrides copy behavior
    if os.getenv("DOT_NO_LINK"):
        copy = True

    os.makedirs(dest_dir, exist_ok=True)

    # Copy or link new file
    if copy:
        copyfile(src, dest, sudo=sudo)
    else:
        cmd = f"ln -sfn {shlex.quote(src)} {shlex.quote(dest)}"
        if sudo:
            cmd = "sudo " + cmd
        run_command(cmd)
Exemple #20
0
    def setup_cred_store(self):
        # Get current config
        docker_config = Path.home().joinpath(".docker", "config.json")
        with open(docker_config) as f:
            config = json.load(f)

        # Check if credential store is already configured
        if "credsStore" not in config:
            install_pkg("docker-credential-secretservice", "gnome-keyring")

            config["auths"] = {
            }  # Reset auths to remove any existing passwords
            config["credsStore"] = "secretservice"

            # Write out new config, make it pretty
            with open(docker_config, "w") as f:
                json.dump(config, f, indent=2)

            run_command("sudo systemctl restart docker")
Exemple #21
0
    def setup_hooks(self):
        os.makedirs(home_dir.joinpath(".local.zsh.d", "pre"), exist_ok=True)
        os.makedirs(home_dir.joinpath(".local.zsh.d", "post"), exist_ok=True)
        os.makedirs(home_dir.joinpath(".local.zsh.d", "paths"), exist_ok=True)

        # Convert old custom into new hooks system
        # Shouldn't be needed anymore, but just in case
        if file_exists(home_dir.joinpath(".local.zsh")):
            run_command(
                'mv -n "$HOME/.local.zsh" "$HOME/.local.zsh.d/post/00-old-local.zsh"',
                shell=True,
            )

        add_to_path("zsh", home_dir.joinpath("bin"))
        add_to_path("zsh", home_dir.joinpath(".scripts"))
        add_to_path("zsh", home_dir.joinpath(".local/scripts"))

        add_zsh_hook(Hook.POST, "10-vars", script_dir.joinpath("vars.zsh"))
        add_zsh_hook(Hook.POST, "10-nnn-setup",
                     script_dir.joinpath("nnn-setup.zsh"))
Exemple #22
0
    def show(self):
        """
            Reads content of blob and returns it as a pretty formated output.
        """

        level = '{0}:{1}'.format(self.rev, self.path)
        file_content = run_command(cmd='git cat-file -p {0}'.format(level),
                                   data=None,
                                   location=self.repo.location,
                                   chw=True)
        return file_content
Exemple #23
0
    def show(self):
        """
            Returns information about commit.
        """

        cmd = 'git show {0}'.format(self.sha1_hash)

        git_output = run_command(cmd=cmd,
                                 data=None,
                                 location=self.repo.location,
                                 chw=True)
        return git_output
Exemple #24
0
    def get_subject(self):
        """
            Returns latest commit message given to this commit.
        """

        cmd = 'git log -1 --format="%s" {0}'.format(self.sha1_hash)

        git_output = run_command(cmd=cmd,
                                 data=None,
                                 location=self.repo.location,
                                 chw=True).strip()
        return git_output
Exemple #25
0
    def get_committer_date(self):
        """
            Returns latest commiter date for this commit in "ISO 8601-like" format and UTC timezone.
        """

        cmd = 'git log -1 --format="%ci" {0}'.format(self.sha1_hash)

        git_output = run_command(cmd=cmd,
                                 data=None,
                                 location=self.repo.location,
                                 chw=True)
        return time_to_utc(git_output.strip())
Exemple #26
0
 def install_pkgs(self):
     if platform.is_mac:
         install_pkg("gpg2", "pidof", "pinentry-mac")
     elif platform.is_ubuntu:
         install_pkg(
             "gnupg-agent",
             "gnupg2",
             "pinentry-gtk2",
             "scdaemon",
             "libccid",
             "pcscd",
             "libpcsclite1",
             "gpgsm",
         )
     elif platform.is_fedora:
         install_pkg("ykpers", "libyubikey", "gnupg", "gnupg2-smime")
     elif platform.is_arch:
         install_pkg("gnupg", "pinentry", "ccid", "pcsclite")
         run_command("sudo systemctl enable pcscd.service")
         run_command("sudo systemctl start pcscd.service")
     else:
         print_line("Unsupported distribution")
Exemple #27
0
    def get_committer_email(self):
        """
            Returns committer email.
        """

        cmd = 'git log -1 --format="%ce" {0} -- {1}'.format(
            self.rev, self.path)

        git_output = run_command(cmd=cmd,
                                 data=None,
                                 location=self.repo.location,
                                 chw=True).strip()
        return git_output
Exemple #28
0
    def get_committer_name(self):
        """
            Returns committer name.
        """

        cmd = 'git log {0} -1 --format="%cn" {1}'.format(
            self.rev, self.sha1_hash)

        git_output = run_command(cmd=cmd,
                                 data=None,
                                 location=self.repo.location,
                                 chw=True).strip()
        return git_output
Exemple #29
0
def install_aur_helper(force=False):
    if not platform.is_arch or (not force and command_exists("yay")):
        return

    yay_path = Path.home().joinpath("code", "yay")

    if yay_path.is_dir():
        run_command("git fetch", cwd=yay_path)
    else:
        makedirs(yay_path.parent, exist_ok=True)
        run_command(
            f"git clone 'https://aur.archlinux.org/yay-bin.git' {yay_path}")

    run_command("makepkg -Acs", cwd=yay_path)
    run_command("sudo pacman -U *.pkg.tar", cwd=yay_path, shell=True)
Exemple #30
0
    def show(self):
        """
            Returns content of tree object which may be other trees or blobs.
        """

        level = '{0}:{1}'.format(self.rev, self.path)
        cmd = 'git ls-tree --full-tree {0}'.format(level)
        git_output = run_command(cmd=cmd, data=None, location=self.repo.location, chw=True).split('\n')[:-1]

        tree_contents = []
        for item in git_output:
            kind, path = item.split()[1], '{0}/{1}'.format(self.path, item.split()[3])
            if kind == GIT_BLOB_OBJECT:
                tree_contents.append(GitBlob(repo=self.repo, path=path, rev=self.rev))
            elif kind == GIT_TREE_OBJECT:
                tree_contents.append(GitTree(repo=self.repo, path=path, rev=self.rev))
        return tree_contents
Exemple #31
0
    def run(self):
        print_header("Setting up Generic Configs")

        link_file(SCRIPT_DIR.joinpath("scripts"),
                  HOME_DIR.joinpath(".scripts"))

        with os.scandir(SCRIPT_DIR.joinpath("config")) as configs:
            config_dir = HOME_DIR.joinpath(".config")
            for item in configs:
                if item.is_dir():
                    link_file(item.path, config_dir.joinpath(item.name))

        if not platform.is_mac:
            run_command("systemctl --user daemon-reload")
            run_command("systemctl --user enable newsboat.timer")
            run_command("systemctl --user enable random_wallpaper.timer")
            if platform.is_arch:
                run_command("systemctl --user enable pacupdate.timer")

        self.exec_installer("configs/home", "home")
Exemple #32
0
    def show(self):
        """
            Returns content of tree object which may be other trees or blobs.
        """

        level = '{0}:{1}'.format(self.rev, self.path)
        cmd = 'git ls-tree --full-tree {0}'.format(level)
        git_output = run_command(cmd=cmd,
                                 data=None,
                                 location=self.repo.location,
                                 chw=True).split('\n')[:-1]

        tree_contents = []
        for item in git_output:
            kind, path = item.split()[1], '{0}/{1}'.format(
                self.path,
                item.split()[3])
            if kind == GIT_BLOB_OBJECT:
                tree_contents.append(
                    GitBlob(repo=self.repo, path=path, rev=self.rev))
            elif kind == GIT_TREE_OBJECT:
                tree_contents.append(
                    GitTree(repo=self.repo, path=path, rev=self.rev))
        return tree_contents
Exemple #33
0
    def setup_oh_my_zsh(self):
        if dir_exists(omz_dir) and not file_exists(
                omz_dir.joinpath("oh-my-zsh.sh")):
            os.rmdir(omz_dir)

        # oh-my-zsh
        if not dir_exists(omz_dir):
            print_line("Installing oh-my-zsh")
            run_command("bash " +
                        str(script_dir.joinpath("install-oh-my-zsh.sh")))

            if platform.is_mac:
                run_command(
                    'sudo dscl . -create "/Users/${USER}" UserShell /usr/local/bin/zsh',
                    shell=True,
                )

        # Update Oh My ZSH
        run_command("git pull --rebase --stat origin master", cwd=omz_dir)
Exemple #34
0
def remove(path: Path, sudo=False):
    cmd = f"rm -rf {shlex.quote(str(path))}"
    if sudo:
        cmd = "sudo " + cmd
    run_command(cmd)
Exemple #35
0
    def check_nvim_installed(self):
        if command_exists("nvim"):
            return

        if platform.is_fedora:
            install_pkg("python2-neovim", "python3-neovim")
        elif platform.is_ubuntu:
            install_apt_ppa("neovim-ppa/stable", update_lists=True)
            install_pkg("neovim", "python-dev", "python-pip", "python3-dev",
                        "python3-pip")
            run_command(
                "sudo update-alternatives --install /usr/bin/vi vi /usr/bin/nvim 60"
            )
            run_command("sudo update-alternatives --config vi")
            run_command(
                "sudo update-alternatives --install /usr/bin/vim vim /usr/bin/nvim 60"
            )
            run_command("sudo update-alternatives --config vim")
            run_command(
                "sudo update-alternatives --install /usr/bin/editor editor /usr/bin/nvim 60"
            )
            run_command("sudo update-alternatives --config editor")
Exemple #36
0
def move(src: Path, dest: Path, sudo=False):
    cmd = f"mv {shlex.quote(str(src))} {shlex.quote(str(dest))}"
    if sudo:
        cmd = "sudo " + cmd
    run_command(cmd)
Exemple #37
0
def copyfile(src, dest, sudo=False):
    if sudo:
        run_command(f"sudo cp {shlex.quote(src)} {shlex.quote(dest)}")
    else:
        copy(src, dest)