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}")
def add_fish_hook(hook: Hook, name: str, file: str, copy=False): print_line(f"Adding {name} to Fish {hook.value} hooks") if copy: copyfile(file, FISH_HOOKS_DIR.joinpath(hook.value, name + ".fish")) else: link_file(file, FISH_HOOKS_DIR.joinpath(hook.value, name + ".fish"))
def add_fish_func(name: str, file: str, copy=False): print_line(f"Adding {name} to Fish functions") if copy: copyfile(file, FISH_FUNCS_DIR.joinpath(name + ".fish")) else: link_file(file, FISH_FUNCS_DIR.joinpath(name + ".fish"))
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)
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, )
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)}")
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")
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}")
def link_files(self): print_line("Linking VSCode Settings", color=Color.MAGENTA) os.makedirs(SETTINGS_PATH, exist_ok=True) link_file( SCRIPT_DIR.joinpath("settings.json"), SETTINGS_PATH.joinpath("settings.json"), ) link_file( SCRIPT_DIR.joinpath("keybindings.json"), SETTINGS_PATH.joinpath("keybindings.json"), ) if dir_exists(SETTINGS_PATH.joinpath("snippets")): os.rmdir(SETTINGS_PATH.joinpath("snippets")) link_file(SCRIPT_DIR.joinpath("snippets"), SETTINGS_PATH.joinpath("snippets"))
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)
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")
def install_code(self): if command_exists(EXE_NAME): print_line( "VSCode already installed, update through the package manager", color=Color.MAGENTA, ) return if platform.is_arch: if EXE_NAME == "code": install_pkg("visual-studio-code-bin") else: install_pkg("vscodium-bin") elif platform.is_mac or platform.is_linux: print_line("Please install VSCodium first") raise InstallException() else: print_line("Unsupported distribution") raise InstallException()
def remove_fish_hook(hook: Hook, name: str): print_line(f"Removing {name} from Fish {hook.value} hooks") os.remove(FISH_HOOKS_DIR.joinpath(hook.value, name + ".fish"))
def remove_fish_func(name: str): print_line(f"Removing Fish function {name}") os.remove(FISH_FUNCS_DIR.joinpath(name + ".fish"))
def remove_zsh_hook(hook: Hook, name: str): print_line(f"Removing {name} from ZSH {hook.value} hooks") os.remove(ZSH_HOOKS_DIR.joinpath(hook.value, name + ".zsh"))