Skip to content

Commit

Permalink
Use HOME directory when non-root
Browse files Browse the repository at this point in the history
  • Loading branch information
j8r committed Aug 19, 2018
1 parent 45af0c7 commit 523ef39
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ To list [available packages](https://github.com/DFabric/package-sources) (applic
A typical installation can be:

```sh
# add a new application to the system (default: /opt/dppm)
# add a new application to the system
dppm p add [application]

# start the service and auto start the service at boot
Expand Down
7 changes: 3 additions & 4 deletions src/dppm/cli.cr
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require "clicr"

# Global constant variables
CONFIG_FILE = "./config.ini"
PREFIX = "/opt/dppm"
PREFIX = Owner.root? ? "/opt/dppm" : ENV["HOME"] + "/dppm"

module CLI
extend self
include Clicr
# Global constant variables
VERSION = "2018-alpha"

def run
create(
Expand Down Expand Up @@ -226,7 +225,7 @@ module CLI
)
rescue ex : Help
puts ex; exit 0
rescue ex : ArgumentRequired | UnknownCommandOrVariable | UnknownOption
rescue ex : ArgumentRequired | UnknownCommand | UnknownOption | UnknownVariable
abort ex
rescue ex
Log.error ex.to_s
Expand Down
5 changes: 3 additions & 2 deletions src/dppm/cmd.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "exec"

module Cmd
def self.find_bin(pkgdir, cmd)
path = "#{pkgdir}/bin/#{cmd}"
Expand Down Expand Up @@ -194,10 +196,9 @@ module Cmd
when "untar_gz" then execute "/bin/tar", ["zxf", cmd[1], "-C", cmd[2]]; "gzip archive extracted"
when "untar_lz" then execute "/bin/tar", ["axf", cmd[1], "-C", cmd[2]]; "lz archive extracted"
when "untar_xz" then execute "/bin/tar", ["Jxf", cmd[1], "-C", cmd[2]]; "xz archive extracted"
when "exit" then puts "exit called, exiting."; exit 1
when "true" then "true"
when "false" then "false"
when "exit"
puts "exit called, exiting."; exit 1
# System executable
when .starts_with? '/' then execute cmd[0], cmd[1..-1]
else
Expand Down
1 change: 0 additions & 1 deletion src/dppm/localhost.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "socket"
require "exec"

struct Localhost
class_getter proc_ver : Array(String) = File.read("/proc/version").split(' ')
Expand Down
24 changes: 10 additions & 14 deletions src/dppm/package/add.cr
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,21 @@ struct Package::Add
owner_id = Owner.available_id.to_s
if uid = @vars["uid"]?
@vars["user"] = Owner.to_user uid
elsif user = @vars["user"]?
@vars["uid"] = Owner.to_user user
else
if user = @vars["user"]?
@vars["uid"] = Owner.to_user user
else
@vars["user"] = @name
@vars["uid"] = owner_id
@add_user = true
end
@vars["user"] = @name
@vars["uid"] = owner_id
@add_user = true
end
if gid = @vars["gid"]?
@vars["group"] = Owner.to_group gid
elsif group = @vars["group"]?
@vars["gid"] = Owner.to_group group
else
if group = @vars["group"]?
@vars["gid"] = Owner.to_group group
else
@vars["group"] = @name
@vars["gid"] = owner_id
@add_group = true
end
@vars["group"] = @name
@vars["gid"] = owner_id
@add_group = true
end
else
@vars["group"], @vars["gid"] = Owner.current_uid_gid.map &.to_s
Expand Down

0 comments on commit 523ef39

Please sign in to comment.