#!/bin/bash

manifestWrite()
{
    local app_name="$1"
    local app_dir="$containers_dir$app_name"
    local manifest_path="$app_dir/.libreportal-manifest.json"

    if [[ ! -d "$app_dir" ]]; then
        isError "Cannot write manifest — $app_dir does not exist"
        return 1
    fi

    local manifest
    manifest=$(manifestCollect "$app_name")
    echo "$manifest" | runFileWrite "$manifest_path" >/dev/null
    runFileOp chown "$docker_install_user":"$docker_install_user" "$manifest_path"
    runFileOp chmod 0644 "$manifest_path"

    local sha
    sha=$(echo "$manifest" | sha256sum | cut -c1-12)
    echo "$sha"
}

manifestRemove()
{
    local app_name="$1"
    local manifest_path="$containers_dir$app_name/.libreportal-manifest.json"
    [[ -f "$manifest_path" ]] && runFileOp rm -f "$manifest_path"
}
