Skip to content

Commit

Permalink
Add Arch Linux & Manjaro support (#36)
Browse files Browse the repository at this point in the history
* Use MESON var in Makefile

* Add ArchLinux & Manjaro support

* Skip confirm prompts in pacman

* Install Docker on Arch

* Remove old Fedora 32 workarounds

* FIx arch distro family check

* Remove nodejs asdf plugin release keyring import

This is now handled by node-build and was removed from the plugin

* Install correct nss package on Arch for mkcert
  • Loading branch information
maxfierke authored Apr 24, 2022
1 parent ad9e776 commit e8ba1e6
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 44 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ all: build
$(TARGET_BUILD_DIR)/mstrap: $(SOURCES)
@if [ ! -z "$(MESON)" ]; then \
mkdir -p $(TARGET_BUILD_DIR); \
meson setup $(MESON_FLAGS) $(TARGET_BUILD_DIR); \
meson compile -v -C $(TARGET_BUILD_DIR); \
$(MESON) setup $(MESON_FLAGS) $(TARGET_BUILD_DIR); \
$(MESON) compile -v -C $(TARGET_BUILD_DIR); \
else \
echo "FAIL: meson must be installed"; \
exit 1; \
Expand Down Expand Up @@ -112,4 +112,4 @@ release: gon.hcl bin/mstrap

.PHONY: install
install: $(TARGET_BUILD_DIR)/mstrap
meson install -C $(TARGET_BUILD_DIR) --tags runtime
$(MESON) install -C $(TARGET_BUILD_DIR) --tags runtime
40 changes: 31 additions & 9 deletions src/mstrap/platform/linux.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% skip_file unless flag?(:linux) %}

require "./linux/archlinux"
require "./linux/debian"
require "./linux/rhel"
require "./linux/*"
Expand All @@ -10,13 +11,19 @@ module MStrap

class UnsupportedDistroError < Exception; end

DISTRO_CENTOS = "centos"
DISTRO_DEBIAN = "debian"
DISTRO_FEDORA = "fedora"
DISTRO_REDHAT = "redhat"
DISTRO_UBUNTU = "ubuntu"
DISTRO_UNKNOWN = "unknown"

DISTRO_ARCHLINUX = "arch"
DISTRO_CENTOS = "centos"
DISTRO_DEBIAN = "debian"
DISTRO_FEDORA = "fedora"
DISTRO_MANJARO = "manjarolinux"
DISTRO_REDHAT = "redhat"
DISTRO_UBUNTU = "ubuntu"
DISTRO_UNKNOWN = "unknown"

ARCH_DISTROS = [
DISTRO_ARCHLINUX,
DISTRO_MANJARO,
]
DEBIAN_DISTROS = [
DISTRO_DEBIAN,
DISTRO_UBUNTU,
Expand All @@ -27,6 +34,7 @@ module MStrap
DISTRO_REDHAT,
]

DISTRO_FAMILY_ARCH = "arch"
DISTRO_FAMILY_RHEL = "rhel"
DISTRO_FAMILY_DEBIAN = "debian"

Expand All @@ -39,7 +47,9 @@ module MStrap
def distro_family
d = distro

if DEBIAN_DISTROS.includes?(d)
if ARCH_DISTROS.includes?(d)
DISTRO_FAMILY_ARCH
elsif DEBIAN_DISTROS.includes?(d)
DISTRO_FAMILY_DEBIAN
elsif RHEL_DISTROS.includes?(d)
DISTRO_FAMILY_RHEL
Expand All @@ -58,6 +68,16 @@ module MStrap
`lsb_release -sc`.strip.downcase
end

# Returns true if on ArchLinux
def archlinux?
distro == DISTRO_ARCHLINUX
end

# Returns true on ArchLinux-based distros (e.g. Arch, Manjaro)
def arch_distro?
distro_family == DISTRO_FAMILY_ARCH
end

# Returns true if on CentOS
def centos?
distro == DISTRO_CENTOS
Expand Down Expand Up @@ -100,7 +120,9 @@ module MStrap

# :nodoc:
def platform
if debian_distro?
if arch_distro?
Linux::Archlinux
elsif debian_distro?
Linux::Debian
elsif fedora?
Linux::Fedora
Expand Down
15 changes: 15 additions & 0 deletions src/mstrap/platform/linux/archlinux.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module MStrap
module Linux
module Archlinux
extend DSL

def self.install_packages!(packages : Array(String))
cmd("pacman", ["-Sy", "--noconfirm", "--needed"] + packages, sudo: true)
end

def self.package_installed?(package_name : String)
cmd("pacman", ["-Qi", package_name], quiet: true)
end
end
end
end
6 changes: 0 additions & 6 deletions src/mstrap/runtime.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ module MStrap
language_name
end

# :nodoc:
def asdf_pre_version_install
end

# :nodoc:
def asdf_version_env_var
@asdf_version_env_var ||= "ASDF_#{asdf_plugin_name.upcase}_VERSION"
Expand Down Expand Up @@ -125,8 +121,6 @@ module MStrap

with_dir_version(Dir.current) do
if current_version && current_version != "" && !has_version?(current_version)
asdf_pre_version_install

log "--> Installing #{language_name} #{current_version} via asdf-#{asdf_plugin_name}: "
unless cmd("asdf install #{asdf_plugin_name} #{current_version}", quiet: true)
logc "There was an error installing the #{language_name} via asdf. Check #{MStrap::Paths::LOG_FILE} or run again with --debug"
Expand Down
8 changes: 0 additions & 8 deletions src/mstrap/runtimes/node.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ module MStrap
"node"
end

def asdf_pre_version_install
log "--> Ensure node.js release team keyring is up-to-date: "
unless cmd "bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring", quiet: true
logc "There was an error updating the node.js release team keyring. Check #{MStrap::Paths::LOG_FILE} or run again with --debug"
end
success "OK"
end

def bootstrap
if File.exists?("yarn.lock")
cmd "brew install yarn", quiet: true
Expand Down
32 changes: 15 additions & 17 deletions src/mstrap/supports/docker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ module MStrap
require_reboot = false

success =
if MStrap::Linux.debian_distro?
if MStrap::Linux.arch_distro?
install_docker_archlinux!
elsif MStrap::Linux.debian_distro?
install_docker_debian!
elsif MStrap::Linux.rhel_distro?
install_docker_rhel!
Expand Down Expand Up @@ -160,6 +162,11 @@ module MStrap
success
end

private def install_docker_archlinux!
logn "Installing Docker from ArchLinux repos"
MStrap::Platform.install_packages!(["docker", "docker-compose"])
end

private def install_docker_centos!
# https://docs.docker.com/engine/install/centos/#installation-methods
logn "Installing Docker from Official Docker Repos"
Expand Down Expand Up @@ -201,23 +208,14 @@ module MStrap
private def install_docker_fedora!
distro_version = MStrap::Linux.distro_version

if distro_version == "32"
logn "Installing Docker from Fedora repos"

success = cmd("sudo dnf -y install moby-engine grubby") &&
fedora_disable_cgroups_v2!
# https://docs.docker.com/engine/install/fedora/#installation-methods
logn "Installing Docker from Official Docker Repos"
success = cmd("sudo dnf -y install dnf-plugins-core grubby") &&
cmd("sudo dnf config-manager -y --add-repo https://download.docker.com/linux/fedora/docker-ce.repo") &&
cmd("sudo dnf install -y docker-ce docker-ce-cli containerd.io") &&
fedora_disable_cgroups_v2!

success
else
# https://docs.docker.com/engine/install/fedora/#installation-methods
logn "Installing Docker from Official Docker Repos"
success = cmd("sudo dnf -y install dnf-plugins-core grubby") &&
cmd("sudo dnf config-manager -y --add-repo https://download.docker.com/linux/fedora/docker-ce.repo") &&
cmd("sudo dnf install -y docker-ce docker-ce-cli containerd.io") &&
fedora_disable_cgroups_v2!

success
end
success
end

private def install_docker_rhel!
Expand Down
8 changes: 7 additions & 1 deletion src/mstrap/supports/mkcert.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ module MStrap
private def install_dependencies! : Nil
nss_package_name =
{% if flag?(:linux) %}
MStrap::Linux.debian_distro? ? "libnss3-tools" : "nss-tools"
if MStrap::Linux.arch_distro?
"nss"
elsif MStrap::Linux.debian_distro?
"libnss3-tools"
else
"nss-tools"
end
{% elsif flag?(:darwin) %}
"nss"
{% else %}
Expand Down

0 comments on commit e8ba1e6

Please sign in to comment.