Fix/djarbz copyparty argcommas (#516)
## Description I discovered that if we included a comma inside an argument that bash would split it out as a separate argument. I added a test to verify. I also cleaned up some log formatting. ## Type of Change - [ ] New module - [ ] New template - [x] Bug fix - [ ] Feature/enhancement - [ ] Documentation - [ ] Other ## Module Information <!-- Delete this section if not applicable --> **Path:** `registry/djarbz/modules/copyparty` **New version:** `v1.0.1` **Breaking change:** [ ] Yes [x] No ## Testing & Validation - [N/A] Tests pass (`bun test`) - [x] Code formatted (`bun fmt`) - [x] Changes tested locally ## Related Issues None --------- Co-authored-by: DevCats <christofer@coder.com>
This commit is contained in:
parent
925c71e641
commit
4a11b06cba
@ -17,7 +17,7 @@ This module installs Copyparty, an alternative to Filebrowser.
|
|||||||
module "copyparty" {
|
module "copyparty" {
|
||||||
count = data.coder_workspace.me.start_count
|
count = data.coder_workspace.me.start_count
|
||||||
source = "registry.coder.com/djarbz/copyparty/coder"
|
source = "registry.coder.com/djarbz/copyparty/coder"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ Some basic command line options:
|
|||||||
module "copyparty" {
|
module "copyparty" {
|
||||||
count = data.coder_workspace.me.start_count
|
count = data.coder_workspace.me.start_count
|
||||||
source = "registry.coder.com/djarbz/copyparty/coder"
|
source = "registry.coder.com/djarbz/copyparty/coder"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
agent_id = coder_agent.example.id
|
agent_id = coder_agent.example.id
|
||||||
arguments = [
|
arguments = [
|
||||||
"-v", "/home/coder/:/home:r", # Share home directory (read-only)
|
"-v", "/home/coder/:/home:r", # Share home directory (read-only)
|
||||||
@ -51,14 +51,14 @@ module "copyparty" {
|
|||||||
module "copyparty" {
|
module "copyparty" {
|
||||||
count = data.coder_workspace.me.start_count
|
count = data.coder_workspace.me.start_count
|
||||||
source = "registry.coder.com/djarbz/copyparty/coder"
|
source = "registry.coder.com/djarbz/copyparty/coder"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
agent_id = coder_agent.example.id
|
agent_id = coder_agent.example.id
|
||||||
subdomain = true
|
subdomain = true
|
||||||
arguments = [
|
arguments = [
|
||||||
"-v", "/tmp:/tmp:r", # Share tmp directory (read-only)
|
"-v", "/tmp:/tmp:r", # Share tmp directory (read-only)
|
||||||
"-v", "/home/coder/:/home:rw", # Share home directory (read-write)
|
"-v", "/home/coder/:/home:rw", # Share home directory (read-write)
|
||||||
"-v", "${local.root_dir}:/work:A:c,dotsrch", # Share work directory (All Perms)
|
"-v", "${local.root_dir}:/work:A:c,dotsrch", # Share work directory (All Perms)
|
||||||
"-e2dsa", # Enables general file indexing"
|
"-e2dsa", # Enables general file indexing
|
||||||
"--re-maxage", "900", # Rescan filesystem for changes every SEC
|
"--re-maxage", "900", # Rescan filesystem for changes every SEC
|
||||||
"--see-dots", # Show dotfiles by default if user has correct permissions on volume
|
"--see-dots", # Show dotfiles by default if user has correct permissions on volume
|
||||||
"--xff-src=lan", # List of trusted reverse-proxy CIDRs (comma-separated) or `lan` for private IPs.
|
"--xff-src=lan", # List of trusted reverse-proxy CIDRs (comma-separated) or `lan` for private IPs.
|
||||||
|
|||||||
@ -80,7 +80,7 @@ run "test_defaults" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert {
|
assert {
|
||||||
condition = strcontains(coder_script.copyparty.script, "IFS=',' read -r -a ARGUMENTS \u003c\u003c\u003c \"\"")
|
condition = strcontains(coder_script.copyparty.script, "ARGUMENTS=()")
|
||||||
error_message = "Script content does not reflect default empty arguments"
|
error_message = "Script content does not reflect default empty arguments"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ run "test_custom_values" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert {
|
assert {
|
||||||
condition = strcontains(coder_script.copyparty.script, "IFS=',' read -r -a ARGUMENTS \u003c\u003c\u003c \"--verbose,-v\"")
|
condition = strcontains(coder_script.copyparty.script, "ARGUMENTS=(\"--verbose\" \"-v\")")
|
||||||
error_message = "Script content does not reflect custom arguments"
|
error_message = "Script content does not reflect custom arguments"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,3 +179,26 @@ run "test_invalid_share" {
|
|||||||
var.share,
|
var.share,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --- Test Case 7: Comma in Arguments [Readme Example 2] ---
|
||||||
|
run "test_comma_args" {
|
||||||
|
# Arguments containing commas
|
||||||
|
variables {
|
||||||
|
agent_id = "example-agent-id"
|
||||||
|
arguments = [
|
||||||
|
"-v", "/tmp:/tmp:r", # Share tmp directory (read-only)
|
||||||
|
"-v", "/home/coder/:/home:rw", # Share home directory (read-write)
|
||||||
|
"-v", "/work:/work:A:c,dotsrch", # Share work directory (All Perms)
|
||||||
|
"-e2dsa", # Enables general file indexing
|
||||||
|
"--re-maxage", "900", # Rescan filesystem for changes every SEC
|
||||||
|
"--see-dots", # Show dotfiles by default if user has correct permissions on volume
|
||||||
|
"--xff-src=lan", # List of trusted reverse-proxy CIDRs (comma-separated) or `lan` for private IPs.
|
||||||
|
"--rproxy", "1", # Which ip to associate clients with, index of X-FWD IP.
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {
|
||||||
|
condition = strcontains(coder_script.copyparty.script, "ARGUMENTS=(\"-v\" \"/tmp:/tmp:r\" \"-v\" \"/home/coder/:/home:rw\" \"-v\" \"/work:/work:A:c,dotsrch\" \"-e2dsa\" \"--re-maxage\" \"900\" \"--see-dots\" \"--xff-src=lan\" \"--rproxy\" \"1\")")
|
||||||
|
error_message = "Script content does not reflect Readme Example #2 arguments with commas"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -129,7 +129,7 @@ resource "coder_script" "copyparty" {
|
|||||||
LOG_PATH : var.log_path,
|
LOG_PATH : var.log_path,
|
||||||
PORT : var.port,
|
PORT : var.port,
|
||||||
PINNED_VERSION : var.pinned_version,
|
PINNED_VERSION : var.pinned_version,
|
||||||
ARGUMENTS : join(",", var.arguments),
|
ARGUMENTS : join(" ", formatlist("\"%s\"", var.arguments)),
|
||||||
})
|
})
|
||||||
run_on_start = true
|
run_on_start = true
|
||||||
run_on_stop = false
|
run_on_stop = false
|
||||||
|
|||||||
@ -9,19 +9,16 @@ LOG_PATH="${LOG_PATH}"
|
|||||||
PORT="${PORT}"
|
PORT="${PORT}"
|
||||||
# Pinned version (e.g., v1.19.16); overrides latest release discovery if set
|
# Pinned version (e.g., v1.19.16); overrides latest release discovery if set
|
||||||
PINNED_VERSION="${PINNED_VERSION}"
|
PINNED_VERSION="${PINNED_VERSION}"
|
||||||
# Custom CLI Arguments# The variable from Terraform is a single, comma-separated string.
|
# Custom CLI Arguments
|
||||||
# We need to split it into a proper bash array using the comma (,) as the delimiter.
|
# The variable from Terraform is a series of quoted and space separated strings.
|
||||||
IFS=',' read -r -a ARGUMENTS <<< "${ARGUMENTS}"
|
# We need to parse it into a proper bash array.
|
||||||
|
ARGUMENTS=(${ARGUMENTS})
|
||||||
|
|
||||||
# VARIABLE appears unused. Verify use (or export if used externally).
|
# VARIABLE appears unused. Verify use (or export if used externally).
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
MODULE_NAME="Copyparty"
|
MODULE_NAME="Copyparty"
|
||||||
|
|
||||||
# VARIABLE appears unused. Verify use (or export if used externally).
|
printf '\e[1mInstalling %s ...\e[0m\n' "$${MODULE_NAME}"
|
||||||
# shellcheck disable=SC2034
|
|
||||||
BOLD='\033[0;1m'
|
|
||||||
|
|
||||||
printf '%sInstalling %s ...\n\n' "$${BOLD}" "$${MODULE_NAME}"
|
|
||||||
|
|
||||||
# Add code here
|
# Add code here
|
||||||
# Use variables from the templatefile function in main.tf
|
# Use variables from the templatefile function in main.tf
|
||||||
@ -32,7 +29,7 @@ if ! command -v python3 &> /dev/null; then
|
|||||||
printf "❌ Python3 could not be found. Please install it to continue.\n"
|
printf "❌ Python3 could not be found. Please install it to continue.\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
printf "✅ Python3 is installed.\n\n"
|
printf "✅ Python3 is installed.\n"
|
||||||
|
|
||||||
RELEASE_TO_INSTALL=""
|
RELEASE_TO_INSTALL=""
|
||||||
# Install provided version to pin, otherwise discover latest github release from `https://github.com/9001/copyparty`.
|
# Install provided version to pin, otherwise discover latest github release from `https://github.com/9001/copyparty`.
|
||||||
@ -44,7 +41,7 @@ if [[ -n "$${PINNED_VERSION}" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
RELEASE_TO_INSTALL="$${PINNED_VERSION}"
|
RELEASE_TO_INSTALL="$${PINNED_VERSION}"
|
||||||
printf "✅ Using pinned version %s.\n\n" "$${RELEASE_TO_INSTALL}"
|
printf "✅ Using pinned version %s.\n" "$${RELEASE_TO_INSTALL}"
|
||||||
else
|
else
|
||||||
printf "🔎 Discovering latest release from GitHub...\n"
|
printf "🔎 Discovering latest release from GitHub...\n"
|
||||||
# Use curl to get the latest release tag from the GitHub API and sed to parse it
|
# Use curl to get the latest release tag from the GitHub API and sed to parse it
|
||||||
@ -54,11 +51,11 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
RELEASE_TO_INSTALL="$${LATEST_RELEASE}"
|
RELEASE_TO_INSTALL="$${LATEST_RELEASE}"
|
||||||
printf "🏷️ Latest release is %s.\n\n" "$${RELEASE_TO_INSTALL}"
|
printf "🏷️ Latest release is %s.\n" "$${RELEASE_TO_INSTALL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Download appropriate release version assets: `copyparty-sfx.py` and `helptext.html`.
|
# Download appropriate release version assets: `copyparty-sfx.py` and `helptext.html`.
|
||||||
printf "🚀 Downloading copyparty v%s...\n" "$${RELEASE_TO_INSTALL}"
|
printf "🚀 Downloading copyparty %s...\n" "$${RELEASE_TO_INSTALL}"
|
||||||
DOWNLOAD_URL="https://github.com/9001/copyparty/releases/download/$${RELEASE_TO_INSTALL}"
|
DOWNLOAD_URL="https://github.com/9001/copyparty/releases/download/$${RELEASE_TO_INSTALL}"
|
||||||
|
|
||||||
printf "⏬ Downloading copyparty-sfx.py...\n"
|
printf "⏬ Downloading copyparty-sfx.py...\n"
|
||||||
@ -74,9 +71,9 @@ if ! curl -fsSL -o /tmp/helptext.html "$${DOWNLOAD_URL}/helptext.html"; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
chmod +x /tmp/copyparty-sfx.py
|
chmod +x /tmp/copyparty-sfx.py
|
||||||
printf "✅ Download complete.\n\n"
|
printf "✅ Download complete.\n"
|
||||||
|
|
||||||
printf "🥳 Installation complete!\n\n"
|
printf "🥳 Installation complete!\n"
|
||||||
|
|
||||||
# Build a clean, quoted string of the command for logging purposes only.
|
# Build a clean, quoted string of the command for logging purposes only.
|
||||||
log_command="python3 /tmp/copyparty-sfx.py -p '$${PORT}'"
|
log_command="python3 /tmp/copyparty-sfx.py -p '$${PORT}'"
|
||||||
@ -85,16 +82,16 @@ for arg in "$${ARGUMENTS[@]}"; do
|
|||||||
log_command+=" '$${arg}'"
|
log_command+=" '$${arg}'"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Clear the log file and write the header and command string using printf.
|
# Dump the executing command to a tmp file for diagnostic review.
|
||||||
{
|
{
|
||||||
printf "=== Starting copyparty at %s ===\n" "$(date)"
|
printf "=== Starting copyparty at %s ===\n" "$(date)"
|
||||||
printf "EXECUTING: %s\n" "$${log_command}"
|
printf "EXECUTING: %s\n" "$${log_command}"
|
||||||
} > "$${LOG_PATH}"
|
} > "/tmp/copyparty.cmd"
|
||||||
|
|
||||||
printf "👷 Starting %s in background...\n\n" "$${MODULE_NAME}"
|
printf "👷 Starting %s in background...\n" "$${MODULE_NAME}"
|
||||||
|
|
||||||
# Execute the actual command using the robust array expansion.
|
# Execute the actual command using the robust array expansion.
|
||||||
# Then, append its output (stdout and stderr) to the log file.
|
# Then, capture its output (stdout and stderr) to the log file.
|
||||||
python3 /tmp/copyparty-sfx.py -p "$${PORT}" "$${ARGUMENTS[@]}" >> "$${LOG_PATH}" 2>&1 &
|
python3 /tmp/copyparty-sfx.py -p "$${PORT}" "$${ARGUMENTS[@]}" > "$${LOG_PATH}" 2>&1 &
|
||||||
|
|
||||||
printf "✅ Service started. Check logs at %s\n\n" "$${LOG_PATH}"
|
printf "✅ Service started. Check logs at %s\n" "$${LOG_PATH}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user