implement adding users
This commit is contained in:
parent
0f9f1a84f9
commit
bc0f9db31d
4 changed files with 34 additions and 5 deletions
4
bin/dat
4
bin/dat
|
@ -27,6 +27,9 @@ OptionParser.new do |opt|
|
||||||
opt.on('--cache', 'Use cache') do |o|
|
opt.on('--cache', 'Use cache') do |o|
|
||||||
options.use_cache = true
|
options.use_cache = true
|
||||||
end
|
end
|
||||||
|
opt.on('--forced', "if case of existing data, delete and recreate") do |o|
|
||||||
|
options.forced = true
|
||||||
|
end
|
||||||
|
|
||||||
opt.on('-t', '--target TARGET', ['user', 'usr', 'package', 'pkg', 'system', 'sys'], 'Target type (user, package, system)') do |target|
|
opt.on('-t', '--target TARGET', ['user', 'usr', 'package', 'pkg', 'system', 'sys'], 'Target type (user, package, system)') do |target|
|
||||||
|
|
||||||
|
@ -67,6 +70,7 @@ when :pkginstall
|
||||||
when :execute
|
when :execute
|
||||||
puts "Ececuting: #{options.name}"
|
puts "Ececuting: #{options.name}"
|
||||||
require 'execute'
|
require 'execute'
|
||||||
|
puts "Arguments: #{options}"
|
||||||
Execute.file(options)
|
Execute.file(options)
|
||||||
when :goto
|
when :goto
|
||||||
Dir.chdir(ENV["DAT_ROOT"])
|
Dir.chdir(ENV["DAT_ROOT"])
|
||||||
|
|
|
@ -15,14 +15,21 @@ require 'ostruct'
|
||||||
# dat command service zulip
|
# dat command service zulip
|
||||||
|
|
||||||
module Execute
|
module Execute
|
||||||
class ServiceInstallContext
|
attr_accessor :options
|
||||||
attr_accessor :bin_dir, :data_dir, :version, :user_name
|
|
||||||
|
|
||||||
def initialize(bin_dir, data_dir, user_name, version)
|
def context(new_value = nil)
|
||||||
|
@options = new_value
|
||||||
|
end
|
||||||
|
|
||||||
|
class ServiceInstallContext
|
||||||
|
attr_accessor :bin_dir, :data_dir, :version, :user_name, :forced
|
||||||
|
|
||||||
|
def initialize(bin_dir, data_dir, user_name, version, forced = false)
|
||||||
@bin_dir = bin_dir
|
@bin_dir = bin_dir
|
||||||
@data_dir = data_dir
|
@data_dir = data_dir
|
||||||
@user_name = user_name
|
@user_name = user_name
|
||||||
@version = version
|
@version = version
|
||||||
|
@forced = forced
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -73,7 +80,7 @@ module Execute
|
||||||
bin_dir = pdata.get_prefix
|
bin_dir = pdata.get_prefix
|
||||||
data_dir = "/data/#{pdata.name}/#{pdata.version.split(".").first}"
|
data_dir = "/data/#{pdata.name}/#{pdata.version.split(".").first}"
|
||||||
service_install_context = ServiceInstallContext.new(
|
service_install_context = ServiceInstallContext.new(
|
||||||
bin_dir, data_dir, name, pdata.version
|
bin_dir, data_dir, name, pdata.version, @options.forced
|
||||||
)
|
)
|
||||||
|
|
||||||
case name
|
case name
|
||||||
|
@ -130,6 +137,7 @@ module Execute
|
||||||
def self.file(options)
|
def self.file(options)
|
||||||
dsl = Object.new
|
dsl = Object.new
|
||||||
dsl.extend(Execute)
|
dsl.extend(Execute)
|
||||||
|
dsl.options = options
|
||||||
|
|
||||||
# Configfile
|
# Configfile
|
||||||
path = File.join(Dir.pwd, options.name || "./Configfile")
|
path = File.join(Dir.pwd, options.name || "./Configfile")
|
||||||
|
|
|
@ -29,13 +29,14 @@ module Make
|
||||||
|
|
||||||
class Context
|
class Context
|
||||||
attr_accessor :name, :use_cache, :environment, :steps, :packages, :repository
|
attr_accessor :name, :use_cache, :environment, :steps, :packages, :repository
|
||||||
attr_accessor :target, :archive, :source_type, :version
|
attr_accessor :target, :archive, :source_type, :version, :forced
|
||||||
|
|
||||||
def initialize(options: OpenStruct.new)
|
def initialize(options: OpenStruct.new)
|
||||||
@target = options.target || :user
|
@target = options.target || :user
|
||||||
|
|
||||||
@name = options.name
|
@name = options.name
|
||||||
@use_cache = options.use_cache || false
|
@use_cache = options.use_cache || false
|
||||||
|
@forced = options.forced || false
|
||||||
|
|
||||||
#System.detect_os
|
#System.detect_os
|
||||||
# rbenv: brew install rbenv && rbenv install 3.0.0
|
# rbenv: brew install rbenv && rbenv install 3.0.0
|
||||||
|
|
|
@ -14,7 +14,21 @@ module Setup
|
||||||
# attr_accessor :te
|
# attr_accessor :te
|
||||||
|
|
||||||
def self.init_db(context)
|
def self.init_db(context)
|
||||||
system(" -D /opt/pgsql/16/data")
|
puts "Mode, isForced #{context.forced}"
|
||||||
|
if Dir.exist?(context.data_dir)
|
||||||
|
if context.forced
|
||||||
|
puts("sudo rm -rf #{context.data_dir}")
|
||||||
|
else
|
||||||
|
raise "PostgreSQL data already exists"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
system("sudo mkdir -p #{context.data_dir}")
|
||||||
|
system("sudo chown #{context.user_name}:services #{context.data_dir}")
|
||||||
|
system("sudo -u postgresql #{File.join(context.bin_dir, "/bin/initdb")} -D #{context.data_dir}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.setup_systemd(context)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.install(context)
|
def self.install(context)
|
||||||
|
@ -34,6 +48,8 @@ module Setup
|
||||||
|
|
||||||
user_context = Execute::UserInstallContext.new(context.user_name, :service)
|
user_context = Execute::UserInstallContext.new(context.user_name, :service)
|
||||||
User.install(user_context)
|
User.install(user_context)
|
||||||
|
init_db(context)
|
||||||
|
setup_systemd(context)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue