# # Cookbook:: esh_archivebox # Recipe:: init # # Copyright:: 2022, https://easyself.host # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. apt_package %w(systemd-container expect) service 'archivebox' do action :stop not_if { ::File.exist?("/var/lib/#{node['hostname']}-data/index.sqlite3")} end file '/tmp/archivebox-init.expect' do content <<~EOT #!/usr/bin/expect -f set timeout -1 spawn systemd-nspawn --oci-bundle=/var/lib/machines/archivebox/ --machine archivebox --hostname archivebox --bind /var/lib/#{node['hostname']}-data:/data --capability=CAP_CHOWN -- /app/bin/docker_entrypoint.sh init --setup expect "Username (leave blank to use 'root'):" send -- "#{node['esh']['archivebox']['username']}\\r" expect "Email address:" send -- "#{node['esh']['archivebox']['email']}\\r" expect "Password:" send -- "#{node['esh']['archivebox']['password']}\\r" expect "Password (again):" send -- "#{node['esh']['archivebox']['password']}\\r" expect eof EOT owner 'root' group 'root' mode '0400' not_if { ::File.exist?("/var/lib/#{node['hostname']}-data/index.sqlite3")} notifies :run, 'execute[init archivebox configuration]', :immediately action :create end execute 'init archivebox configuration' do command 'expect -f /tmp/archivebox-init.expect' live_stream true action :nothing notifies :start, 'service[archivebox]', :immediately end