Skip to content

Commit 4a11b06

Browse files
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>
1 parent 925c71e commit 4a11b06

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

registry/djarbz/modules/copyparty/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This module installs Copyparty, an alternative to Filebrowser.
1717
module "copyparty" {
1818
count = data.coder_workspace.me.start_count
1919
source = "registry.coder.com/djarbz/copyparty/coder"
20-
version = "1.0.0"
20+
version = "1.0.1"
2121
}
2222
```
2323

@@ -35,7 +35,7 @@ Some basic command line options:
3535
module "copyparty" {
3636
count = data.coder_workspace.me.start_count
3737
source = "registry.coder.com/djarbz/copyparty/coder"
38-
version = "1.0.0"
38+
version = "1.0.1"
3939
agent_id = coder_agent.example.id
4040
arguments = [
4141
"-v", "/home/coder/:/home:r", # Share home directory (read-only)
@@ -51,14 +51,14 @@ module "copyparty" {
5151
module "copyparty" {
5252
count = data.coder_workspace.me.start_count
5353
source = "registry.coder.com/djarbz/copyparty/coder"
54-
version = "1.0.0"
54+
version = "1.0.1"
5555
agent_id = coder_agent.example.id
5656
subdomain = true
5757
arguments = [
5858
"-v", "/tmp:/tmp:r", # Share tmp directory (read-only)
5959
"-v", "/home/coder/:/home:rw", # Share home directory (read-write)
6060
"-v", "${local.root_dir}:/work:A:c,dotsrch", # Share work directory (All Perms)
61-
"-e2dsa", # Enables general file indexing"
61+
"-e2dsa", # Enables general file indexing
6262
"--re-maxage", "900", # Rescan filesystem for changes every SEC
6363
"--see-dots", # Show dotfiles by default if user has correct permissions on volume
6464
"--xff-src=lan", # List of trusted reverse-proxy CIDRs (comma-separated) or `lan` for private IPs.

registry/djarbz/modules/copyparty/copyparty.tftest.hcl

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ run "test_defaults" {
8080
}
8181

8282
assert {
83-
condition = strcontains(coder_script.copyparty.script, "IFS=',' read -r -a ARGUMENTS \u003c\u003c\u003c \"\"")
83+
condition = strcontains(coder_script.copyparty.script, "ARGUMENTS=()")
8484
error_message = "Script content does not reflect default empty arguments"
8585
}
8686
}
@@ -138,7 +138,7 @@ run "test_custom_values" {
138138
}
139139

140140
assert {
141-
condition = strcontains(coder_script.copyparty.script, "IFS=',' read -r -a ARGUMENTS \u003c\u003c\u003c \"--verbose,-v\"")
141+
condition = strcontains(coder_script.copyparty.script, "ARGUMENTS=(\"--verbose\" \"-v\")")
142142
error_message = "Script content does not reflect custom arguments"
143143
}
144144

@@ -179,3 +179,26 @@ run "test_invalid_share" {
179179
var.share,
180180
]
181181
}
182+
183+
# --- Test Case 7: Comma in Arguments [Readme Example 2] ---
184+
run "test_comma_args" {
185+
# Arguments containing commas
186+
variables {
187+
agent_id = "example-agent-id"
188+
arguments = [
189+
"-v", "/tmp:/tmp:r", # Share tmp directory (read-only)
190+
"-v", "/home/coder/:/home:rw", # Share home directory (read-write)
191+
"-v", "/work:/work:A:c,dotsrch", # Share work directory (All Perms)
192+
"-e2dsa", # Enables general file indexing
193+
"--re-maxage", "900", # Rescan filesystem for changes every SEC
194+
"--see-dots", # Show dotfiles by default if user has correct permissions on volume
195+
"--xff-src=lan", # List of trusted reverse-proxy CIDRs (comma-separated) or `lan` for private IPs.
196+
"--rproxy", "1", # Which ip to associate clients with, index of X-FWD IP.
197+
]
198+
}
199+
200+
assert {
201+
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\")")
202+
error_message = "Script content does not reflect Readme Example #2 arguments with commas"
203+
}
204+
}

registry/djarbz/modules/copyparty/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ resource "coder_script" "copyparty" {
129129
LOG_PATH : var.log_path,
130130
PORT : var.port,
131131
PINNED_VERSION : var.pinned_version,
132-
ARGUMENTS : join(",", var.arguments),
132+
ARGUMENTS : join(" ", formatlist("\"%s\"", var.arguments)),
133133
})
134134
run_on_start = true
135135
run_on_stop = false

registry/djarbz/modules/copyparty/run.sh

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@ LOG_PATH="${LOG_PATH}"
99
PORT="${PORT}"
1010
# Pinned version (e.g., v1.19.16); overrides latest release discovery if set
1111
PINNED_VERSION="${PINNED_VERSION}"
12-
# Custom CLI Arguments# The variable from Terraform is a single, comma-separated string.
13-
# We need to split it into a proper bash array using the comma (,) as the delimiter.
14-
IFS=',' read -r -a ARGUMENTS <<< "${ARGUMENTS}"
12+
# Custom CLI Arguments
13+
# The variable from Terraform is a series of quoted and space separated strings.
14+
# We need to parse it into a proper bash array.
15+
ARGUMENTS=(${ARGUMENTS})
1516

1617
# VARIABLE appears unused. Verify use (or export if used externally).
1718
# shellcheck disable=SC2034
1819
MODULE_NAME="Copyparty"
1920

20-
# VARIABLE appears unused. Verify use (or export if used externally).
21-
# shellcheck disable=SC2034
22-
BOLD='\033[0;1m'
23-
24-
printf '%sInstalling %s ...\n\n' "$${BOLD}" "$${MODULE_NAME}"
21+
printf '\e[1mInstalling %s ...\e[0m\n' "$${MODULE_NAME}"
2522

2623
# Add code here
2724
# Use variables from the templatefile function in main.tf
@@ -32,7 +29,7 @@ if ! command -v python3 &> /dev/null; then
3229
printf "❌ Python3 could not be found. Please install it to continue.\n"
3330
exit 1
3431
fi
35-
printf "✅ Python3 is installed.\n\n"
32+
printf "✅ Python3 is installed.\n"
3633

3734
RELEASE_TO_INSTALL=""
3835
# 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
4441
exit 1
4542
fi
4643
RELEASE_TO_INSTALL="$${PINNED_VERSION}"
47-
printf "✅ Using pinned version %s.\n\n" "$${RELEASE_TO_INSTALL}"
44+
printf "✅ Using pinned version %s.\n" "$${RELEASE_TO_INSTALL}"
4845
else
4946
printf "🔎 Discovering latest release from GitHub...\n"
5047
# Use curl to get the latest release tag from the GitHub API and sed to parse it
@@ -54,11 +51,11 @@ else
5451
exit 1
5552
fi
5653
RELEASE_TO_INSTALL="$${LATEST_RELEASE}"
57-
printf "🏷️ Latest release is %s.\n\n" "$${RELEASE_TO_INSTALL}"
54+
printf "🏷️ Latest release is %s.\n" "$${RELEASE_TO_INSTALL}"
5855
fi
5956

6057
# Download appropriate release version assets: `copyparty-sfx.py` and `helptext.html`.
61-
printf "🚀 Downloading copyparty v%s...\n" "$${RELEASE_TO_INSTALL}"
58+
printf "🚀 Downloading copyparty %s...\n" "$${RELEASE_TO_INSTALL}"
6259
DOWNLOAD_URL="https://github.com/9001/copyparty/releases/download/$${RELEASE_TO_INSTALL}"
6360

6461
printf "⏬ Downloading copyparty-sfx.py...\n"
@@ -74,9 +71,9 @@ if ! curl -fsSL -o /tmp/helptext.html "$${DOWNLOAD_URL}/helptext.html"; then
7471
fi
7572

7673
chmod +x /tmp/copyparty-sfx.py
77-
printf "✅ Download complete.\n\n"
74+
printf "✅ Download complete.\n"
7875

79-
printf "🥳 Installation complete!\n\n"
76+
printf "🥳 Installation complete!\n"
8077

8178
# Build a clean, quoted string of the command for logging purposes only.
8279
log_command="python3 /tmp/copyparty-sfx.py -p '$${PORT}'"
@@ -85,16 +82,16 @@ for arg in "$${ARGUMENTS[@]}"; do
8582
log_command+=" '$${arg}'"
8683
done
8784

88-
# Clear the log file and write the header and command string using printf.
85+
# Dump the executing command to a tmp file for diagnostic review.
8986
{
9087
printf "=== Starting copyparty at %s ===\n" "$(date)"
9188
printf "EXECUTING: %s\n" "$${log_command}"
92-
} > "$${LOG_PATH}"
89+
} > "/tmp/copyparty.cmd"
9390

94-
printf "👷 Starting %s in background...\n\n" "$${MODULE_NAME}"
91+
printf "👷 Starting %s in background...\n" "$${MODULE_NAME}"
9592

9693
# Execute the actual command using the robust array expansion.
97-
# Then, append its output (stdout and stderr) to the log file.
98-
python3 /tmp/copyparty-sfx.py -p "$${PORT}" "$${ARGUMENTS[@]}" >> "$${LOG_PATH}" 2>&1 &
94+
# Then, capture its output (stdout and stderr) to the log file.
95+
python3 /tmp/copyparty-sfx.py -p "$${PORT}" "$${ARGUMENTS[@]}" > "$${LOG_PATH}" 2>&1 &
9996

100-
printf "✅ Service started. Check logs at %s\n\n" "$${LOG_PATH}"
97+
printf "✅ Service started. Check logs at %s\n" "$${LOG_PATH}"

0 commit comments

Comments
 (0)