Added setup script

This commit is contained in:
Alexey Berezhok
2026-05-01 18:11:49 +03:00
parent dae9aca295
commit f64f034b7b
4 changed files with 546 additions and 5 deletions

View File

@@ -13,6 +13,29 @@ class BunkerwebWorker < Kernel::ModuleCoreWorker
}
end
def enable
log_file = get_log
f_inst_pp = get_module_paydata("bunkerweb_installer.yml")
if !check
inf = info
log("Req error, needed #{inf[:REQ]}")
"Req error, needed #{inf[:REQ]}"
else
begin
log("install packages for bunkerweb support: /usr/bin/ansible-playbook -vv #{f_inst_pp}")
result_action = `LC_ALL=C.UTF-8 /usr/bin/ansible-playbook -vv "#{f_inst_pp}" 2>&1`
ex_status = $?.exitstatus
if ex_status.to_i == 0 || ex_status.to_i == 2
log(result_action)
super
end
rescue => e
log("module installation error #{e.message} #{e.backtrace.first}")
"module installation error. See log #{log_file}"
end
end
end
def command(args)
return log_return("Not enough arguments. Needed command") if args.length < 1
log_file = get_log
@@ -92,13 +115,57 @@ class BunkerwebWorker < Kernel::ModuleCoreWorker
puts output
ACTION_OK
end
when "passwd"
format = (args[1].nil? ? "shell" : args[1].strip)
cred = {}
api_file = "/etc/bunkerweb/api.env"
if File.exist?(api_file)
File.readlines(api_file).each do |line|
line.strip!
next if line.empty? || line.start_with?('#')
key, value = line.split('=', 2)
if %w[API_USERNAME API_PASSWORD].include?(key)
cred[key] = value
end
end
else
cred["API_USERNAME"] = nil
cred["API_PASSWORD"] = nil
end
cred["API_USERNAME"] ||= nil
cred["API_PASSWORD"] ||= nil
ui_file = "/etc/bunkerweb/ui.env"
if File.exist?(ui_file)
File.readlines(ui_file).each do |line|
line.strip!
next if line.empty? || line.start_with?('#')
key, value = line.split('=', 2)
if %w[ADMIN_USERNAME ADMIN_PASSWORD].include?(key)
cred[key] = value
end
end
else
cred["ADMIN_USERNAME"] = nil
cred["ADMIN_PASSWORD"] = nil
end
cred["ADMIN_USERNAME"] ||= nil
cred["ADMIN_PASSWORD"] ||= nil
result = []
result << cred
hestia_print_array_of_hashes(result, format, "API_USERNAME,API_PASSWORD,ADMIN_USERNAME,ADMIN_PASSWORD")
ACTION_OK
when "configure"
when "help"
puts "#{$0} bunkerweb_module COMMAND [OPTIONS] [json|csv|plain]"
puts "COMMANDS:"
puts " add - add domain to bunkerweb"
puts " delete - delete domain from bunkerweb"
puts " addssl [path_to_cert] [path_to_key] - add existsing certificate to bunkerweb domain"
puts " updssl [path_to_cert] [path_to_key] - update existsing certificate to bunkerweb domain"
puts " add domain - add domain to bunkerweb"
puts " delete domain - delete domain from bunkerweb"
puts " addssl domain [path_to_cert] [path_to_key] - add existsing certificate to bunkerweb domain"
puts " updssl domain [path_to_cert] [path_to_key] - update existsing certificate to bunkerweb domain"
puts " passwd - get ui and api passwd"
puts " configure [path_to_cert] [path_to_key] - start initial setup of bunkerweb should do only once"
puts " help - help"
ACTION_OK
else

View File

@@ -0,0 +1,14 @@
---
- name: Install Bunkerweb on localhost
hosts: localhost
connection: local
become: true
gather_facts: false
environment:
LANG: en_US.UTF-8
LC_ALL: en_US.UTF-8
tasks:
- name: Install bunkerweb
ansible.builtin.dnf:
name: bunkerweb
state: present