diff --git a/bin/dat b/bin/dat index 0fdd07a..03e5dc8 100755 --- a/bin/dat +++ b/bin/dat @@ -27,6 +27,9 @@ OptionParser.new do |opt| opt.on('--cache', 'Use cache') do |o| options.use_cache = true 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| @@ -67,6 +70,7 @@ when :pkginstall when :execute puts "Ececuting: #{options.name}" require 'execute' + puts "Arguments: #{options}" Execute.file(options) when :goto Dir.chdir(ENV["DAT_ROOT"]) diff --git a/lib/execute.rb b/lib/execute.rb index 09e614d..782885a 100644 --- a/lib/execute.rb +++ b/lib/execute.rb @@ -15,14 +15,21 @@ require 'ostruct' # dat command service zulip module Execute + attr_accessor :options + + def context(new_value = nil) + @options = new_value + end + class ServiceInstallContext - attr_accessor :bin_dir, :data_dir, :version, :user_name + attr_accessor :bin_dir, :data_dir, :version, :user_name, :forced - def initialize(bin_dir, data_dir, user_name, version) + def initialize(bin_dir, data_dir, user_name, version, forced = false) @bin_dir = bin_dir @data_dir = data_dir @user_name = user_name @version = version + @forced = forced end end @@ -73,7 +80,7 @@ module Execute bin_dir = pdata.get_prefix data_dir = "/data/#{pdata.name}/#{pdata.version.split(".").first}" service_install_context = ServiceInstallContext.new( - bin_dir, data_dir, name, pdata.version + bin_dir, data_dir, name, pdata.version, @options.forced ) case name @@ -130,6 +137,7 @@ module Execute def self.file(options) dsl = Object.new dsl.extend(Execute) + dsl.options = options # Configfile path = File.join(Dir.pwd, options.name || "./Configfile") diff --git a/lib/make.rb b/lib/make.rb index e5ba949..b066638 100644 --- a/lib/make.rb +++ b/lib/make.rb @@ -29,13 +29,14 @@ module Make class Context 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) @target = options.target || :user @name = options.name @use_cache = options.use_cache || false + @forced = options.forced || false #System.detect_os # rbenv: brew install rbenv && rbenv install 3.0.0 diff --git a/lib/setup/postgresql.rb b/lib/setup/postgresql.rb index 4e23e57..8feb8db 100644 --- a/lib/setup/postgresql.rb +++ b/lib/setup/postgresql.rb @@ -14,7 +14,21 @@ module Setup # attr_accessor :te 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 def self.install(context) @@ -34,6 +48,8 @@ module Setup user_context = Execute::UserInstallContext.new(context.user_name, :service) User.install(user_context) + init_db(context) + setup_systemd(context) end end end