Added startup task to create user script file
This commit is contained in:
parent
9b4b09efb7
commit
3203e246d8
2 changed files with 37 additions and 0 deletions
|
|
@ -33,6 +33,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
def init(state) do
|
||||
reset_executing_jobs()
|
||||
create_blank_yt_dlp_files()
|
||||
create_blank_user_script_file()
|
||||
apply_default_settings()
|
||||
|
||||
{:ok, state}
|
||||
|
|
@ -65,6 +66,18 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
end)
|
||||
end
|
||||
|
||||
defp create_blank_user_script_file do
|
||||
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
||||
filepath = Path.join([base_dir, "user-scripts", "lifecycle"])
|
||||
|
||||
if !File.exists?(filepath) do
|
||||
Logger.info("Creating blank file and making it executable: #{filepath}")
|
||||
|
||||
FilesystemUtils.write_p!(filepath, "")
|
||||
File.chmod(filepath, 0o755)
|
||||
end
|
||||
end
|
||||
|
||||
defp apply_default_settings do
|
||||
{:ok, yt_dlp_version} = yt_dlp_runner().version()
|
||||
{:ok, apprise_version} = apprise_runner().version()
|
||||
|
|
|
|||
|
|
@ -53,6 +53,30 @@ defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "create_blank_user_script_file" do
|
||||
test "creates a blank script file" do
|
||||
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
||||
filepath = Path.join([base_dir, "user-scripts", "lifecycle"])
|
||||
File.rm(filepath)
|
||||
|
||||
refute File.exists?(filepath)
|
||||
|
||||
PreJobStartupTasks.init(%{})
|
||||
|
||||
assert File.exists?(filepath)
|
||||
end
|
||||
|
||||
test "gives it 755 permissions" do
|
||||
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
||||
filepath = Path.join([base_dir, "user-scripts", "lifecycle"])
|
||||
File.rm(filepath)
|
||||
|
||||
PreJobStartupTasks.init(%{})
|
||||
|
||||
assert File.stat!(filepath).mode == 0o100755
|
||||
end
|
||||
end
|
||||
|
||||
describe "apply_default_settings" do
|
||||
test "sets yt_dlp version" do
|
||||
Settings.set(yt_dlp_version: nil)
|
||||
|
|
|
|||
Loading…
Reference in a new issue