def install_osx(): if not host.Which("brew"): io.Print("Installing Homebrew") url = "https://raw.githubusercontent.com/Homebrew/install/master/install" host.ShellCommand( 'yes | /usr/bin/ruby -e "$(curl -fsSL {url})"'.format( **vars())) host.ShellCommand("brew doctor")
def install_ubuntu(cls): # Install build dependencies: apt.Apt().install_package("build-essential") apt.Apt().install_package("curl") apt.Apt().install_package("file") apt.Apt().install_package("git") apt.Apt().install_package("python-setuptools") if not os.path.exists("/home/linuxbrew/.linuxbrew/bin/brew"): url = ("https://raw.githubusercontent.com/" "Linuxbrew/install/master/install.sh") host.ShellCommand( 'yes | sh -c "$(curl -fsSL {url})"'.format(url=url)) host.ShellCommand("{brew} update".format(brew=cls.BREW_BINARY))
def upgrade_package(self, package): """ upgrade package, return True if upgraded """ if self.package_is_outdated(package): io.Print("brew upgrade {package}".format(**vars())) host.ShellCommand( "{self.BREW_BINARY} upgrade {package}".format(**vars())) return True
def install_package(self, package): """ install a package using homebrew, return True if installed """ if not self.package_is_installed(package): io.Print("brew install " + package) host.ShellCommand( "{self.BREW_BINARY} install {package}".format(**vars())) return True
def package_is_installed(self, package): """ return True if package is installed """ if not os.path.isfile(self.PKG_LIST): host.ShellCommand( "{self.BREW_BINARY} list > {self.PKG_LIST}".format(**vars())) return host.CheckShellCommand( "grep '^{package}$' <{self.PKG_LIST}".format(**vars()))
def upgrade_cask(self, cask): """ upgrade a homebrew cask. does nothing if cask not installed """ if self.cask_is_outdated(cask): io.Print("brew cask upgrade {cask}".format(**vars())) host.ShellCommand( "{self.BREW_BINARY} cask upgrade {cask}".format(**vars())) return True
def install_cask(self, cask): """ install a homebrew cask, return True if installed """ if not self.cask_is_installed(cask): io.Print("brew cask install " + cask) host.ShellCommand( "{self.BREW_BINARY} cask install {cask}".format(**vars())) return True
def __call__(self, ctx): package = self.package brew = Homebrew() brew.install() if brew.install_package(package): host.ShellCommand( "{brew.BREW_BINARY} link {package} --force".format( brew=brew, package=package))
def cask_is_installed(self, cask): """ return True if cask is installed """ if not os.path.isfile(self.CASK_LIST): host.ShellCommand( "{self.BREW_BINARY} cask list > {self.CASK_LIST}".format( **vars())) cask_stump = cask.split("/")[-1] return host.CheckShellCommand( "grep '^{cask_stump}$' <{self.CASK_LIST}".format(**vars()))
def package_is_outdated(self, package): """ returns True if package is outdated """ if not self.package_is_installed(package): raise task.InvalidTaskError( "homebrew package '{package}' cannot be upgraded " "as it is not installed".format(**vars())) if not os.path.isfile(self.OUTDATED_PKG_LIST): host.ShellCommand( "{self.BREW_BINARY} outdated | awk '{{print $1}}' >{self.OUTDATED_PKG_LIST}" .format(**vars())) package_stump = package.split("/")[-1] return host.CheckShellCommand( "grep '^{package_stump}$' <{self.OUTDATED_PKG_LIST}".format( **vars()))
def cask_is_outdated(self, cask): """ returns True if cask is outdated """ if not self.cask_is_installed(cask): raise task.InvalidTaskError( "homebrew cask '{package}' cannot be upgraded as it is not installed" .format(**vars())) if not os.path.isfile(self.OUTDATED_CASK_LIST): host.ShellCommand( "{self.BREW_BINARY} cask outdated ".format(**vars()) + "| awk '{{print $1}}' >{self.OUTDATED_CASK_LIST}".format( **vars())) cask_stump = cask.split("/")[-1] return host.CheckShellCommand( "grep '^{cask_stump}$' <{self.OUTDATED_CASK_LIST}".format( **vars()))
def uninstall_cask(self, cask): """ remove a homebrew cask, return True if uninstalled """ if self.cask_is_installed(cask): io.Print("brew cask remove " + cask) host.ShellCommand("{self.BREW_BINARY} cask remove " + cask) return True