2023-01-17 17:12:22 +08:00

65 lines
1.6 KiB
Ruby

#
# Cookbook Name:: kosmos-mastodon
# Recipe:: libretranslate
#
build_essential
include_recipe "git"
version = "1.3.8"
%w{ python3 python3-pip python3-setuptools python3-dev }.each do |pkg|
apt_package pkg
end
user "libretranslate" do
shell '/bin/bash'
home "/opt/libretranslate"
manage_home true
end
bash "install_libretranslate" do
code "sudo -u libretranslate pip3 install --user --prefer-binary libretranslate==#{version}"
action :run
not_if { `sudo -u libretranslate pip3 list |grep libretranslate`.split(' ')[1] == version rescue false }
notifies :restart, "service[libretranslate]", :delayed
end
languages = `sudo -u libretranslate /opt/libretranslate/.local/bin/argospm search`
languages.each_line do |line|
lang = line.split(':').first
bash "install_lt_#{lang}" do
code "sudo -u libretranslate /opt/libretranslate/.local/bin/argospm install #{lang}"
action :nothing
end
end
systemd_unit "libretranslate.service" do
content({
Unit: {
Description: "LibreTranslate",
Documentation: ["https://github.com/LibreTranslate/LibreTranslate"],
After: "network.target"
},
Service: {
Type: "simple",
User: "libretranslate",
Group: "libretranslate",
WorkingDirectory: "/opt/libretranslate/",
ExecStart: "/opt/libretranslate/.local/bin/libretranslate --host 127.0.0.1 --port 5000 --disable-files-translation",
Restart: "always"
},
Install: {
WantedBy: "multi-user.target"
}
})
verify false
triggers_reload true
action [:create, :enable]
end
service "libretranslate" do
action [:enable, :start]
end