tower-of-babel-public/tasks/croc.py
2023-02-22 00:01:21 -03:00

28 lines
1,005 B
Python

from packaging import version
from pyinfra.operations import apk, server, files
from pyinfra.facts.server import LinuxName
from pyinfra.api import deploy
from pyinfra import host
CROC_ALPINE_VERSION = version.parse("3.14")
@deploy("install croc")
def install_croc():
# alpine provides croc in-repo as of 3.14
if host.get_fact(LinuxName) == "Alpine":
host_alpine_version = version.parse(host.data.alpine_version)
if host_alpine_version >= CROC_ALPINE_VERSION:
apk.packages(name="install croc via apk", packages=["croc"])
return
# for everyone else, install manually
files.directory("/opt/croc")
files.download(
"https://github.com/schollz/croc/releases/download/v9.6.3/croc_9.6.3_Linux-64bit.tar.gz",
"/opt/croc/croc.tar.gz",
md5sum="5550b0bfb50d0541cba790562c180bd7",
)
server.shell("tar xvf /opt/croc/croc.tar.gz", _chdir="/opt/croc")
server.shell("mv /opt/croc/croc /usr/bin/croc", _chdir="/opt/croc")