Skip to content

Commit

Permalink
osctld: distconfig: set both local and fqdn name in hosts file
Browse files Browse the repository at this point in the history
  • Loading branch information
aither64 committed Nov 15, 2018
1 parent 8da728a commit e9b2d1c
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .build_id
@@ -1 +1 @@
18.09.0.build20181114183007
18.09.0.build20181115124313
2 changes: 1 addition & 1 deletion os/packages/osctl/Gemfile
@@ -1,2 +1,2 @@
source 'https://rubygems.vpsfree.cz'
gem 'osctl', '18.09.0.build20181114183007'
gem 'osctl', '18.09.0.build20181115124313'
8 changes: 4 additions & 4 deletions os/packages/osctl/Gemfile.lock
Expand Up @@ -6,15 +6,15 @@ GEM
highline (1.7.10)
ipaddress (0.8.3)
json (2.1.0)
libosctl (18.09.0.build20181114183007)
libosctl (18.09.0.build20181115124313)
require_all (~> 2.0.0)
osctl (18.09.0.build20181114183007)
osctl (18.09.0.build20181115124313)
curses
gli (~> 2.17.1)
highline (~> 1.7.10)
ipaddress (~> 0.8.3)
json
libosctl (= 18.09.0.build20181114183007)
libosctl (= 18.09.0.build20181115124313)
rainbow (~> 3.0.0)
require_all (~> 2.0.0)
ruby-progressbar (~> 1.9.0)
Expand All @@ -26,7 +26,7 @@ PLATFORMS
ruby

DEPENDENCIES
osctl (= 18.09.0.build20181114183007)
osctl (= 18.09.0.build20181115124313)

BUNDLED WITH
1.16.3
8 changes: 4 additions & 4 deletions os/packages/osctl/gemset.nix
Expand Up @@ -43,19 +43,19 @@
dependencies = ["require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "1dsbw1in295jra4bgllklgsf7gvgppr37l7kj6gfhvnvnjdkm09s";
sha256 = "0ibqm6hs74gh2dn23ir0aqs3l25rssh5wjqbvbjvsnvcbki2lnkj";
type = "gem";
};
version = "18.09.0.build20181114183007";
version = "18.09.0.build20181115124313";
};
osctl = {
dependencies = ["curses" "gli" "highline" "ipaddress" "json" "libosctl" "rainbow" "require_all" "ruby-progressbar"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "10mf07cl29l1x6yqrf12m8l70js36qi43wysf6xlyassr9jcphfb";
sha256 = "1wb7c70bcqvrvr8x85x6iyx7lkl716sbh0k1b72iy3icyzinzil3";
type = "gem";
};
version = "18.09.0.build20181114183007";
version = "18.09.0.build20181115124313";
};
rainbow = {
source = {
Expand Down
2 changes: 1 addition & 1 deletion os/packages/osctld/Gemfile
@@ -1,2 +1,2 @@
source 'https://rubygems.vpsfree.cz'
gem 'osctld', '18.09.0.build20181114183007'
gem 'osctld', '18.09.0.build20181115124313'
20 changes: 10 additions & 10 deletions os/packages/osctld/Gemfile.lock
Expand Up @@ -6,29 +6,29 @@ GEM
gli (2.17.2)
ipaddress (0.8.3)
json (2.1.0)
libosctl (18.09.0.build20181114183007)
libosctl (18.09.0.build20181115124313)
require_all (~> 2.0.0)
netlinkrb (0.18.vpsadminos.0)
osctl-repo (18.09.0.build20181114183007)
osctl-repo (18.09.0.build20181115124313)
filelock
gli (~> 2.17.1)
json
libosctl (= 18.09.0.build20181114183007)
libosctl (= 18.09.0.build20181115124313)
require_all (~> 2.0.0)
osctld (18.09.0.build20181114183007)
osctld (18.09.0.build20181115124313)
concurrent-ruby (~> 1.0.5)
ipaddress (~> 0.8.3)
json
libosctl (= 18.09.0.build20181114183007)
libosctl (= 18.09.0.build20181115124313)
netlinkrb (= 0.18.vpsadminos.0)
osctl-repo (= 18.09.0.build20181114183007)
osup (= 18.09.0.build20181114183007)
osctl-repo (= 18.09.0.build20181115124313)
osup (= 18.09.0.build20181115124313)
require_all (~> 2.0.0)
ruby-lxc (= 1.2.3)
osup (18.09.0.build20181114183007)
osup (18.09.0.build20181115124313)
gli (~> 2.17.1)
json
libosctl (= 18.09.0.build20181114183007)
libosctl (= 18.09.0.build20181115124313)
require_all (~> 2.0.0)
require_all (2.0.0)
ruby-lxc (1.2.3)
Expand All @@ -37,7 +37,7 @@ PLATFORMS
ruby

DEPENDENCIES
osctld (= 18.09.0.build20181114183007)
osctld (= 18.09.0.build20181115124313)

BUNDLED WITH
1.16.3
16 changes: 8 additions & 8 deletions os/packages/osctld/gemset.nix
Expand Up @@ -43,10 +43,10 @@
dependencies = ["require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "1dsbw1in295jra4bgllklgsf7gvgppr37l7kj6gfhvnvnjdkm09s";
sha256 = "0ibqm6hs74gh2dn23ir0aqs3l25rssh5wjqbvbjvsnvcbki2lnkj";
type = "gem";
};
version = "18.09.0.build20181114183007";
version = "18.09.0.build20181115124313";
};
netlinkrb = {
source = {
Expand All @@ -60,28 +60,28 @@
dependencies = ["filelock" "gli" "json" "libosctl" "require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "12ss03sqmn7a2rshcjwp0rbslhlvcx7pbx868azxqi4pw4my67f8";
sha256 = "1j0dz5q7hl1di2rzppfsa0fgin63l4nm3gyib4v726c5403l9dnk";
type = "gem";
};
version = "18.09.0.build20181114183007";
version = "18.09.0.build20181115124313";
};
osctld = {
dependencies = ["concurrent-ruby" "ipaddress" "json" "libosctl" "netlinkrb" "osctl-repo" "osup" "require_all" "ruby-lxc"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "0sjcvmpvxfsbsmhlqibcn98xlaj3x23ydybmxnsypfd4snh03h47";
sha256 = "00w6b0a01ckz7vr2d704j1isx6lnpcrkgn72ddasw392pqli83bi";
type = "gem";
};
version = "18.09.0.build20181114183007";
version = "18.09.0.build20181115124313";
};
osup = {
dependencies = ["gli" "json" "libosctl" "require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "04gf1nxw2i4qijddyys6xrggzkr0vca2n24yjb79f78h3dc225xw";
sha256 = "0piqri8m1drpgcp7bqpgk1kh9kbzssfybbkzvp2whfdpmnkndvm5";
type = "gem";
};
version = "18.09.0.build20181114183007";
version = "18.09.0.build20181115124313";
};
require_all = {
source = {
Expand Down
2 changes: 1 addition & 1 deletion os/packages/osup/Gemfile
@@ -1,2 +1,2 @@
source 'https://rubygems.vpsfree.cz'
gem 'osup', '18.09.0.build20181114183007'
gem 'osup', '18.09.0.build20181115124313'
8 changes: 4 additions & 4 deletions os/packages/osup/Gemfile.lock
Expand Up @@ -3,20 +3,20 @@ GEM
specs:
gli (2.17.2)
json (2.1.0)
libosctl (18.09.0.build20181114183007)
libosctl (18.09.0.build20181115124313)
require_all (~> 2.0.0)
osup (18.09.0.build20181114183007)
osup (18.09.0.build20181115124313)
gli (~> 2.17.1)
json
libosctl (= 18.09.0.build20181114183007)
libosctl (= 18.09.0.build20181115124313)
require_all (~> 2.0.0)
require_all (2.0.0)

PLATFORMS
ruby

DEPENDENCIES
osup (= 18.09.0.build20181114183007)
osup (= 18.09.0.build20181115124313)

BUNDLED WITH
1.16.3
8 changes: 4 additions & 4 deletions os/packages/osup/gemset.nix
Expand Up @@ -19,19 +19,19 @@
dependencies = ["require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "1dsbw1in295jra4bgllklgsf7gvgppr37l7kj6gfhvnvnjdkm09s";
sha256 = "0ibqm6hs74gh2dn23ir0aqs3l25rssh5wjqbvbjvsnvcbki2lnkj";
type = "gem";
};
version = "18.09.0.build20181114183007";
version = "18.09.0.build20181115124313";
};
osup = {
dependencies = ["gli" "json" "libosctl" "require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "04gf1nxw2i4qijddyys6xrggzkr0vca2n24yjb79f78h3dc225xw";
sha256 = "0piqri8m1drpgcp7bqpgk1kh9kbzssfybbkzvp2whfdpmnkndvm5";
type = "gem";
};
version = "18.09.0.build20181114183007";
version = "18.09.0.build20181115124313";
};
require_all = {
source = {
Expand Down
2 changes: 1 addition & 1 deletion os/packages/svctl/Gemfile
@@ -1,2 +1,2 @@
source 'https://rubygems.vpsfree.cz'
gem 'svctl', '18.09.0.build20181114183007'
gem 'svctl', '18.09.0.build20181115124313'
8 changes: 4 additions & 4 deletions os/packages/svctl/Gemfile.lock
Expand Up @@ -2,18 +2,18 @@ GEM
remote: https://rubygems.vpsfree.cz/
specs:
gli (2.17.2)
libosctl (18.09.0.build20181114183007)
libosctl (18.09.0.build20181115124313)
require_all (~> 2.0.0)
require_all (2.0.0)
svctl (18.09.0.build20181114183007)
svctl (18.09.0.build20181115124313)
gli (~> 2.17.1)
libosctl (= 18.09.0.build20181114183007)
libosctl (= 18.09.0.build20181115124313)

PLATFORMS
ruby

DEPENDENCIES
svctl (= 18.09.0.build20181114183007)
svctl (= 18.09.0.build20181115124313)

BUNDLED WITH
1.16.3
8 changes: 4 additions & 4 deletions os/packages/svctl/gemset.nix
Expand Up @@ -11,10 +11,10 @@
dependencies = ["require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "1dsbw1in295jra4bgllklgsf7gvgppr37l7kj6gfhvnvnjdkm09s";
sha256 = "0ibqm6hs74gh2dn23ir0aqs3l25rssh5wjqbvbjvsnvcbki2lnkj";
type = "gem";
};
version = "18.09.0.build20181114183007";
version = "18.09.0.build20181115124313";
};
require_all = {
source = {
Expand All @@ -28,9 +28,9 @@
dependencies = ["gli" "libosctl"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "00m6zqnajijpckclw6d14ypfq7y27s3pcj3a251887yapcx7rbjd";
sha256 = "1wwsf4z78wl2p9bf297rakyw0539007ky3ipjbvay6d62hdi5k7w";
type = "gem";
};
version = "18.09.0.build20181114183007";
version = "18.09.0.build20181115124313";
};
}
55 changes: 7 additions & 48 deletions osctld/lib/osctld/dist_config/base.rb
Expand Up @@ -94,59 +94,18 @@ def bin_path(_opts)
# hostname.
# @param old_hostname [OsCtl::Lib::Hostname, nil]
def update_etc_hosts(old_hostname = nil)
hosts = File.join(ct.rootfs, 'etc', 'hosts')
return unless writable?(hosts)
path = File.join(ct.rootfs, 'etc', 'hosts')
return unless writable?(path)

regenerate_file(hosts, 0644) do |new, old|
old.each_line do |line|
if (/^127\.0\.0\.1\s/ =~ line || /^::1\s/ =~ line) \
&& !includes_hostname?(line, ct.hostname)
hosts = EtcHosts.new(path)

if old_hostname && includes_hostname?(line, old_hostname)
new.puts(replace_host(line, old_hostname, ct.hostname))

else
new.puts(add_host(line.strip, ct.hostname))
end

else
new.write(line)
end
end
if old_hostname
hosts.replace(old_hostname, ct.hostname)
else
hosts.set(ct.hostname)
end
end

# Check if a line of string contains specific hostname
# @param line [String]
# @param hostname [OsCtl::Lib::Hostname]
def includes_hostname?(line, hostname)
/\s#{Regexp.escape(hostname.fqdn)}(\s|$)/ =~ line
end

# Add `hostname` to `line` from `/etc/hosts`
#
# The hostname is put into the first position.
#
# @param line [String]
# @param hostname [OsCtl::Lib::Hostname]
def add_host(line, hostname)
return if line !~ /^([^\s]+)(\s+)/

i = $~.end(2)
"#{$1}#{$2}#{hostname.fqdn} #{line[i..-1]}"
end

# Remove `hostname` from `line` read from `/etc/hosts`
#
# @param line [String]
# @param hostname [OsCtl::Lib::Hostname]
def replace_host(line, old_hostname, new_hostname)
line.sub(
/(\s)#{Regexp.escape(old_hostname.fqdn)}(\s|$)/,
"\\1#{new_hostname.fqdn}\\2"
)
end

# Check if the file at `path` si writable by its user
#
# If the file doesn't exist, we take it as writable. If a block is given,
Expand Down

0 comments on commit e9b2d1c

Please sign in to comment.