Skip to content

Commit

Permalink
Install DPPM service optionally when available
Browse files Browse the repository at this point in the history
  • Loading branch information
j8r committed Sep 8, 2019
1 parent 728cec6 commit 973d99c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ steps:
path: /root/.cache
image: jrei/crystal-alpine
commands:
- crystal spec
- crystal spec -D allow_root

- name: build docs
image: jrei/crystal-alpine
Expand Down
3 changes: 2 additions & 1 deletion src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ module DPPM::CLI
app.add(
vars: {"uid" => Process.uid.to_s, "gid" => Process.gid.to_s},
shared: true,
confirmation: !no_confirm
confirmation: !no_confirm,
add_service: !!Host.service_available?
) do
no_confirm || CLI.confirm_prompt { raise "DPPM installation canceled." }
end
Expand Down
7 changes: 6 additions & 1 deletion src/host.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ struct DPPM::Host
Log.error "Unsupported architecture"; exit 1
{% end %}

def self.service_available?
Service.init? || Log.warn "services management unavailable", "DPPM is still usable. Consider OpenRC or systemd init systems"
Service.init?
end

# All system environment variables
class_getter vars : Hash(String, String) do
Service.init? || DPPM::Log.warn "services management unavailable", "DPPM is still usable. Consider OpenRC or systemd init systems"
service_available?
{
"arch" => @@arch,
"kernel" => @@kernel,
Expand Down
2 changes: 1 addition & 1 deletion src/prefix/pkg.cr
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DPPM::Prefix::Pkg
def create_global_bin_symlinks(force : Bool = false)
each_binary_with_path do |path, binary|
global_bin = Path["/usr/local/bin", binary].to_s
File.delete global_bin if File.exists? global_bin
File.delete global_bin if File.symlink?(global_bin) || File.exists?(global_bin)
File.symlink (path / binary).to_s, global_bin
end
end
Expand Down
8 changes: 5 additions & 3 deletions src/service.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ require "exec"
require "./service/*"

module Service
extend self

@@init : Systemd.class | OpenRC.class | Nil
@@initialized = false

def self.init? : Systemd.class | OpenRC.class | Nil
def init? : Systemd.class | OpenRC.class | Nil
if !@@initialized
init_system = File.basename File.real_path "/sbin/init"
if init_system == "systemd"
Expand All @@ -18,11 +20,11 @@ module Service
@@init
end

def self.init : Systemd.class | OpenRC.class
def init : Systemd.class | OpenRC.class
init? || raise "Unsupported init system"
end

def self.exec?(command : String, args : Array(String) | Tuple) : Bool
def exec?(command : String, args : Array(String) | Tuple) : Bool
success = false
Exec.new command, args, output: DPPM::Log.output, error: DPPM::Log.error do |process|
success = process.wait.success?
Expand Down

0 comments on commit 973d99c

Please sign in to comment.