Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions registry/djarbz/modules/copyparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This module installs Copyparty, an alternative to Filebrowser.
module "copyparty" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/djarbz/copyparty/coder"
version = "1.0.0"
version = "1.0.1"
}
```

Expand All @@ -35,7 +35,7 @@ Some basic command line options:
module "copyparty" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/djarbz/copyparty/coder"
version = "1.0.0"
version = "1.0.1"
agent_id = coder_agent.example.id
arguments = [
"-v", "/home/coder/:/home:r", # Share home directory (read-only)
Expand All @@ -51,14 +51,14 @@ module "copyparty" {
module "copyparty" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/djarbz/copyparty/coder"
version = "1.0.0"
version = "1.0.1"
agent_id = coder_agent.example.id
subdomain = true
arguments = [
"-v", "/tmp:/tmp:r", # Share tmp directory (read-only)
"-v", "/home/coder/:/home:rw", # Share home directory (read-write)
"-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
"--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.
Expand Down
27 changes: 25 additions & 2 deletions registry/djarbz/modules/copyparty/copyparty.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ run "test_defaults" {
}

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"
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ run "test_custom_values" {
}

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"
}

Expand Down Expand Up @@ -179,3 +179,26 @@ run "test_invalid_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"
}
}
2 changes: 1 addition & 1 deletion registry/djarbz/modules/copyparty/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ resource "coder_script" "copyparty" {
LOG_PATH : var.log_path,
PORT : var.port,
PINNED_VERSION : var.pinned_version,
ARGUMENTS : join(",", var.arguments),
ARGUMENTS : join(" ", formatlist("\"%s\"", var.arguments)),
})
run_on_start = true
run_on_stop = false
Expand Down
37 changes: 17 additions & 20 deletions registry/djarbz/modules/copyparty/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ LOG_PATH="${LOG_PATH}"
PORT="${PORT}"
# Pinned version (e.g., v1.19.16); overrides latest release discovery if set
PINNED_VERSION="${PINNED_VERSION}"
# Custom CLI Arguments# The variable from Terraform is a single, comma-separated string.
# We need to split it into a proper bash array using the comma (,) as the delimiter.
IFS=',' read -r -a ARGUMENTS <<< "${ARGUMENTS}"
# Custom CLI Arguments
# The variable from Terraform is a series of quoted and space separated strings.
# We need to parse it into a proper bash array.
ARGUMENTS=(${ARGUMENTS})

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

# VARIABLE appears unused. Verify use (or export if used externally).
# shellcheck disable=SC2034
BOLD='\033[0;1m'

printf '%sInstalling %s ...\n\n' "$${BOLD}" "$${MODULE_NAME}"
printf '\e[1mInstalling %s ...\e[0m\n' "$${MODULE_NAME}"

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

RELEASE_TO_INSTALL=""
# Install provided version to pin, otherwise discover latest github release from `https://github.com/9001/copyparty`.
Expand All @@ -44,7 +41,7 @@ if [[ -n "$${PINNED_VERSION}" ]]; then
exit 1
fi
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
printf "🔎 Discovering latest release from GitHub...\n"
# Use curl to get the latest release tag from the GitHub API and sed to parse it
Expand All @@ -54,11 +51,11 @@ else
exit 1
fi
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

# 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}"

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

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.
log_command="python3 /tmp/copyparty-sfx.py -p '$${PORT}'"
Expand All @@ -85,16 +82,16 @@ for arg in "$${ARGUMENTS[@]}"; do
log_command+=" '$${arg}'"
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 "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.
# Then, append its output (stdout and stderr) to the log file.
python3 /tmp/copyparty-sfx.py -p "$${PORT}" "$${ARGUMENTS[@]}" >> "$${LOG_PATH}" 2>&1 &
# Then, capture its output (stdout and stderr) to the log file.
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}"