LibrePortal/scripts/function/file/copy_resource.sh
librelad 33107c4f27 refactor(de-sudo): rework generic file/folder helpers to path-aware ownership
The old copy/move helpers ran 'sudo cp/mv X Y; sudo chown $user_name Y' (root +
arbitrary chown). Rework them to write AS the destination's owner — no root, no
chown — classifying by dest path like createTouch: /docker/containers/<app> ->
runFileOp (docker install user), manager-owned control plane -> runInstallOp.
The $user_name arg is now advisory (the path decides). Covers copyFile/copyFiles/
copyFolder/copyFolders/moveFile; copyResource is always containers -> runFileOp;
createFolders' non-container branch -> runInstallOp; updateFileOwnership (an
arbitrary user1:user2 chown) -> runSystem. Confirmed by callers (containers vs
$docker_dir/backup_install_dir/configs dests). Removes a class of root data ops
+ arbitrary-chown from the runtime.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-24 17:24:44 +01:00

31 lines
962 B
Bash
Executable File

#!/bin/bash
copyResource()
{
local app_name="$1"
local file_name="$2"
local save_path="$3"
local app_dir=$install_containers_dir$app_name
# Check if the app_name folder was found
if [ -z "$app_dir" ]; then
echo "App folder '$app_name' not found in '$install_containers_dir'."
fi
local destination_dir="$containers_dir$app_name"
if [ -n "$save_path" ]; then
local destination_dir="$destination_dir/$save_path"
if [ ! -d "$destination_dir" ]; then
local result=$(createFolders "loud" $docker_install_user "$destination_dir")
checkSuccess "Creating $save_path folder(s) for $app_name"
fi
fi
# Destination is always /docker/containers/<app> -> write as the docker
# install user (runFileOp); no root, no chown.
local result=$(runFileOp cp "$app_dir/resources/$file_name" "$destination_dir/")
checkSuccess "Copying $file_name to $destination_dir"
}