diff --git a/bin/dat b/bin/dat index 274d5fa..0fdd07a 100755 --- a/bin/dat +++ b/bin/dat @@ -56,6 +56,14 @@ when :make puts "making..." require 'make' Make.command(options) +when :pkgmake + puts "Making package #{options.name}" + require 'make' + Make.create_package(options) +when :pkginstall + require 'make' + # TODO: wrong naming it is not name, but path + Make.install_package(options.name) when :execute puts "Ececuting: #{options.name}" require 'execute' diff --git a/lib/data/templates/postgresql/postgresql.service b/lib/data/templates/postgresql/postgresql.service new file mode 100644 index 0000000..3976e51 --- /dev/null +++ b/lib/data/templates/postgresql/postgresql.service @@ -0,0 +1,29 @@ +[Unit] +Description=PostgreSQL <%= version %> database server +After=network.target + +[Service] +Type=notify + +User=postgres +Group=services + +ExecStart=<%= prefix %>/bin/postgres -D <%= database_path %>/data +ExecReload=/bin/kill -HUP $MAINPID +KillMode=mixed +TimeoutSec=300 +Restart=on-failure +NotifyAccess=all + +# Security +ProtectSystem=full +ProtectHome=true +PrivateTmp=true +NoNewPrivileges=true + +# Resource Limits +LimitNOFILE=65536 + +[Install] +WantedBy=multi-user.target + diff --git a/lib/execute.rb b/lib/execute.rb index d91d6ef..fd495d4 100644 --- a/lib/execute.rb +++ b/lib/execute.rb @@ -10,6 +10,9 @@ require 'ostruct' # dat execute progress # dat execute < default Configfile +# dat execute --dry-run +# Execute single command +# dat command service zulip module Execute def dependency(name) @@ -59,6 +62,9 @@ module Execute end def self.file(options) + require 'make' + puts Make.context("postgresql") + puts "options: #{options}" dsl = Object.new dsl.extend(Execute) diff --git a/lib/make.rb b/lib/make.rb index 3a324d7..e5ba949 100644 --- a/lib/make.rb +++ b/lib/make.rb @@ -29,7 +29,7 @@ module Make class Context attr_accessor :name, :use_cache, :environment, :steps, :packages, :repository - attr_accessor :target, :archive, :source_type + attr_accessor :target, :archive, :source_type, :version def initialize(options: OpenStruct.new) @target = options.target || :user @@ -55,15 +55,21 @@ module Make @packages = makefile["packages"] || [] project_sources = { - repository: makefile["repository"] != nil, - archive: makefile["archive"] != nil + repository: makefile["repository"], + archive: makefile["archive"] }.select { |_, v| v } if project_sources.size == 1 + source_data = project_sources.values.first @source_type = project_sources.keys.first + @version = source_data["version"] || source_data["branch"] + + raise "No version provided" if @version == nil + @version = @version.to_s else raise "Exactly one type of source: 'repository' or 'archive'" end + puts @source_type @repository = Make.rostruct(makefile["repository"] || OpenStruct.new) @@ -97,7 +103,7 @@ module Make when :user "#{ENV["HOME"]}/.local" when :package - "#{sys_prefix}/pkg/#{@name}/#{@repository.branch}" + "#{sys_prefix}/pkg/#{@name}/#{@version}" when :system "#{sys_prefix}/" else @@ -227,13 +233,45 @@ module Make def install System.install(context.packages) end + + def create_package(options) + puts "Creating packahge for options: #{options}" + puts @context + puts "Prefix #{@context.get_prefix}" + system("tar --zstd -Pcf #{@context.name}-#{@context.version}.pkg #{@context.get_prefix}") + end end # dat make -t pkg --cache --name dry-run # dat make --name dry-run def self.command(options) - context = Context.new(options: options) - builder = Builder.new(context) - builder.build + context = Context.new(options: options) + builder = Builder.new(context) + builder.build end + + # dat pkginstall {file-path} + # an example `dat pkginstall postgresql-17.5.pkg` + def self.install_package(path) + puts "Installing package: #{path}" + system("sudo tar --zstd -xf #{path} -C /") + end + + # dat pkgmake {name} + def self.create_package(options) + options["target"] = :package if options["target"] == nil + context = Context.new(options: options) + builder = Builder.new(context) + builder.create_package(options) + end + + # TODO: better name, it is just to obtain information + # about the package + def self.context(package_name, target = :package) + options = OpenStruct.new + options["target"] = target + options["name"] = package_name + Context.new(options: options) + end + end diff --git a/lib/setup/postgresql.rb b/lib/setup/postgresql.rb index 0b12a8a..98652b1 100644 --- a/lib/setup/postgresql.rb +++ b/lib/setup/postgresql.rb @@ -5,14 +5,25 @@ module Setup module PostgreSQL extend Templates + + # attr_accessor :te - + def self.init_db + system(" -D /opt/pgsql/16/data") + end def self.make_config pg_hba = render("pg_hba.conf") - test = render("test", te: "This is a test string") + # test = render("test", te: "This is a test string") + posgresql_conf = render("postgresql") + service = render( + "postgresql.service", + prefix: "/pkg/postgresql/REL_17_5/", + version: "16.5", + data_url: "/data/postgresql/16/" + ) puts test end diff --git a/recipes/postgresql/debian.yml b/recipes/postgresql/debian.yml index 1d0e951..fa0d991 100644 --- a/recipes/postgresql/debian.yml +++ b/recipes/postgresql/debian.yml @@ -14,8 +14,10 @@ packages: repository: url: https://github.com/postgres/postgres.git branch: REL_17_5 + version: 17.5 steps: - ./configure --prefix=$PREFIX - make -j$CPUS - - make install + - $SUDO mkdir -p $PREFIX + - $SUDO make install